-
Notifications
You must be signed in to change notification settings - Fork 27
/
generic_example.py
executable file
·152 lines (129 loc) · 5.05 KB
/
generic_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# PCEF - Python/Qt Code Editing Framework
# Copyright 2013, Colin Duquesnoy <colin.duquesnoy@gmail.com>
#
# This software is released under the LGPLv3 license.
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
""" PCEF generic editor demo """
import sys
print "OUTDATED"
sys.exit(-1)
from PySide.QtCore import Slot
from PySide.QtGui import QAction
from PySide.QtGui import QActionGroup
from PySide.QtGui import QApplication
from PySide.QtGui import QFileDialog
from PySide.QtGui import QMainWindow
from pcef import openFileInEditor
from pcef import saveFileFromEditor
from pcef import styles
from pcef.panels.misc import UserMarkersPanel
from examples.gui_integration.ui import simple_editor_ui
class SimpleEditor(QMainWindow):
"""
A simple editor window that can open/save files.
The ui has been designed in Qt Designer and use the promoted widgets system
to instantiate a GenericEditor. (self.ui.genericEditor)
"""
def __init__(self):
QMainWindow.__init__(self)
# setup ui (the pcef GenericEditor is created there using
# the promoted widgets system)
self.ui = simple_editor_ui.Ui_MainWindow()
self.ui.setupUi(self)
self.setWindowTitle("PCEF - Generic Example")
editor = self.ui.genericEditor
# open this file
try:
openFileInEditor(self.ui.genericEditor, __file__)
except:
pass
# install Panel where user can add its own markers
p = UserMarkersPanel()
editor.installPanel(p, editor.PANEL_ZONE_LEFT)
# add a fold indicator around our class and the main
editor.foldPanel.addIndicator(136, 141)
# add styles actions
allStyles = styles.getAllStyles()
allStyles.sort()
self.styleActionGroup = QActionGroup(self)
for style in allStyles:
action = QAction(unicode(style), self.ui.menuStyle)
action.setCheckable(True)
action.setChecked(style == "Default")
self.styleActionGroup.addAction(action)
self.ui.menuStyle.addAction(action)
self.styleActionGroup.triggered.connect(
self.on_styleActionGroup_triggered)
# add panels actions
allPanels = self.ui.genericEditor.panels()
allPanels.sort()
self.panels_actions = []
for panel in allPanels:
action = QAction(unicode(panel), self.ui.menuPanels)
action.setCheckable(True)
action.setChecked(panel.enabled)
self.ui.menuPanels.addAction(action)
self.panels_actions.append(action)
action.triggered.connect(self.onPanelActionTriggered)
# add panels actions
allModes = self.ui.genericEditor.modes()
allModes.sort()
self.modes_actions = []
for mode in allModes:
action = QAction(unicode(mode), self.ui.menuModes)
action.setCheckable(True)
action.setChecked(mode.enabled)
self.ui.menuModes.addAction(action)
self.modes_actions.append(action)
action.triggered.connect(self.onModeActionTriggered)
def onModeActionTriggered(self):
""" Enables/Disables a mode """
modes = self.ui.genericEditor.modes()
modes.sort()
for mode, action in zip(modes, self.modes_actions):
mode.enabled = action.isChecked()
def onPanelActionTriggered(self):
""" Enables/Disables a Panel """
panels = self.ui.genericEditor.panels()
panels.sort()
for panel, action in zip(panels, self.panels_actions):
panel.enabled = action.isChecked()
def on_styleActionGroup_triggered(self, action):
""" Change current editor style """
self.ui.genericEditor.currentStyle = styles.getStyle(action.text())
stylesheet = ""
if action.text() == "Dark":
try:
import qdarkstyle
stylesheet = qdarkstyle.load_stylesheet()
except ImportError:
print "Failed to use the qdarkstyle. Please execute <pip install qdarkstyle> to fully use this theme."
QApplication.instance().setStyleSheet(stylesheet)
@Slot()
def on_actionSave_triggered(self):
""" Save the current file """
saveFileFromEditor(self.ui.genericEditor)
@Slot()
def on_actionSave_as_triggered(self):
""" Save the current file as"""
filename = QFileDialog.getSaveFileName(self)[0]
if filename != "":
saveFileFromEditor(self.ui.genericEditor, filename)
@Slot()
def on_actionOpen_triggered(self):
""" Open a new file in the editor """
filename = QFileDialog.getOpenFileName(self)[0]
if filename != "":
openFileInEditor(self.ui.genericEditor, filename)
def main():
""" Application entry point """
app = QApplication(sys.argv)
window = SimpleEditor()
window.show()
app.exec_()
if __name__ == "__main__":
main()