Changeset View
Changeset View
Standalone View
Standalone View
plugins/extensions/pykrita/plugin/plugins/scripter/uicontroller.py
1 | from PyQt5.QtGui import QTextCursor | 1 | from PyQt5.QtGui import QTextCursor | ||
---|---|---|---|---|---|
2 | from PyQt5.QtWidgets import (QToolBar, QMenuBar, QTabWidget, | 2 | from PyQt5.QtWidgets import (QToolBar, QMenuBar, QTabWidget, | ||
3 | QLabel, QVBoxLayout, QMessageBox) | 3 | QLabel, QVBoxLayout, QMessageBox) | ||
4 | from PyQt5.QtCore import Qt, QObject | 4 | from PyQt5.QtCore import Qt, QObject | ||
5 | from scripter.ui_scripter.syntax import syntax, syntaxstyles | 5 | from scripter.ui_scripter.syntax import syntax, syntaxstyles | ||
6 | from scripter.ui_scripter.editor import pythoneditor | 6 | from scripter.ui_scripter.editor import pythoneditor | ||
7 | from scripter import scripterdialog | ||||
7 | import os | 8 | import os | ||
8 | import importlib | 9 | import importlib | ||
9 | 10 | | |||
10 | 11 | | |||
11 | class UIController(object): | 12 | class UIController(object): | ||
12 | 13 | | |||
13 | def __init__(self, mainWidget): | 14 | def __init__(self): | ||
14 | self.mainWidget = mainWidget | 15 | self.mainWidget = scripterdialog.ScripterDialog(self) | ||
15 | self.actionToolbar = QToolBar('toolBar', self.mainWidget) | 16 | self.actionToolbar = QToolBar('toolBar', self.mainWidget) | ||
16 | self.menu_bar = QMenuBar(self.mainWidget) | 17 | self.menu_bar = QMenuBar(self.mainWidget) | ||
17 | 18 | | |||
18 | self.actionToolbar.setObjectName('toolBar') | 19 | self.actionToolbar.setObjectName('toolBar') | ||
19 | self.menu_bar.setObjectName('menuBar') | 20 | self.menu_bar.setObjectName('menuBar') | ||
20 | 21 | | |||
21 | self.actions = [] | 22 | self.actions = [] | ||
22 | 23 | | |||
23 | self.mainWidget.setWindowModality(Qt.NonModal) | 24 | self.mainWidget.setWindowModality(Qt.NonModal) | ||
24 | 25 | | |||
25 | def initialize(self, scripter): | 26 | def initialize(self, scripter): | ||
26 | self.editor = pythoneditor.CodeEditor(scripter) | 27 | self.editor = pythoneditor.CodeEditor(scripter) | ||
27 | self.tabWidget = QTabWidget() | 28 | self.tabWidget = QTabWidget() | ||
28 | self.statusBar = QLabel('untitled') | 29 | self.statusBar = QLabel('untitled') | ||
29 | self.highlight = syntax.PythonHighlighter(self.editor.document(), syntaxstyles.DefaultSyntaxStyle()) | 30 | self.highlight = syntax.PythonHighlighter(self.editor.document(), syntaxstyles.DefaultSyntaxStyle()) | ||
30 | 31 | | |||
31 | self.scripter = scripter | 32 | self.scripter = scripter | ||
32 | 33 | | |||
33 | self.loadMenus() | 34 | self.loadMenus() | ||
34 | self.loadWidgets() | 35 | self.loadWidgets() | ||
35 | self.loadActions() | 36 | self.loadActions() | ||
37 | self._readSettings() | ||||
36 | 38 | | |||
37 | vbox = QVBoxLayout(self.mainWidget) | 39 | vbox = QVBoxLayout(self.mainWidget) | ||
38 | vbox.addWidget(self.menu_bar) | 40 | vbox.addWidget(self.menu_bar) | ||
39 | vbox.addWidget(self.actionToolbar) | 41 | vbox.addWidget(self.actionToolbar) | ||
40 | vbox.addWidget(self.editor) | 42 | vbox.addWidget(self.editor) | ||
41 | vbox.addWidget(self.tabWidget) | 43 | vbox.addWidget(self.tabWidget) | ||
42 | vbox.addWidget(self.statusBar) | 44 | vbox.addWidget(self.statusBar) | ||
43 | 45 | | |||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Line(s) | |||||
136 | def clearEditor(self): | 138 | def clearEditor(self): | ||
137 | self.editor.clear() | 139 | self.editor.clear() | ||
138 | 140 | | |||
139 | def repaintDebugArea(self): | 141 | def repaintDebugArea(self): | ||
140 | self.editor.repaintDebugArea() | 142 | self.editor.repaintDebugArea() | ||
141 | 143 | | |||
142 | def closeScripter(self): | 144 | def closeScripter(self): | ||
143 | self.mainWidget.close() | 145 | self.mainWidget.close() | ||
146 | | ||||
147 | def _writeSettings(self): | ||||
148 | """ _writeSettings is a method invoked when the scripter starts, making | ||||
149 | control inversion. Actions can implement a writeSettings method to | ||||
150 | save your own settings without this method to know about it. """ | ||||
151 | | ||||
152 | self.scripter.settings.beginGroup('scripter') | ||||
153 | | ||||
154 | document = self.scripter.documentcontroller.activeDocument | ||||
155 | if document: | ||||
156 | self.scripter.settings.setValue('activeDocumentPath', document.filePath) | ||||
157 | | ||||
158 | for action in self.actions: | ||||
159 | writeSettings = getattr(action['action'], "writeSettings", None) | ||||
160 | if callable(writeSettings): | ||||
161 | writeSettings() | ||||
162 | | ||||
163 | self.scripter.settings.endGroup() | ||||
164 | | ||||
165 | | ||||
166 | def _readSettings(self): | ||||
167 | """ It's similar to _writeSettings, but reading the settings when the ScripterDialog is closed. """ | ||||
168 | | ||||
169 | self.scripter.settings.beginGroup('scripter') | ||||
170 | | ||||
171 | activeDocumentPath = self.scripter.settings.value('activeDocumentPath', '') | ||||
172 | | ||||
173 | if activeDocumentPath: | ||||
174 | document = self.scripter.documentcontroller.openDocument(activeDocumentPath) | ||||
175 | self.setStatusBar(document.filePath) | ||||
176 | self.setDocumentEditor(document) | ||||
177 | | ||||
178 | for action in self.actions: | ||||
179 | readSettings = getattr(action['action'], "readSettings", None) | ||||
180 | if callable(readSettings): | ||||
181 | readSettings() | ||||
182 | | ||||
183 | self.scripter.settings.endGroup() | ||||
184 | | ||||
185 | def _saveSettings(self): | ||||
186 | self.scripter.settings.sync() |