Changeset View
Changeset View
Standalone View
Standalone View
plugins/extensions/pykrita/plugin/plugins/scripter/uicontroller.py
Show All 37 Lines | 24 | def initialize(self, scripter): | |||
---|---|---|---|---|---|
38 | vbox.addWidget(self.actionToolbar) | 38 | vbox.addWidget(self.actionToolbar) | ||
39 | vbox.addWidget(self.editor) | 39 | vbox.addWidget(self.editor) | ||
40 | vbox.addWidget(self.tabWidget) | 40 | vbox.addWidget(self.tabWidget) | ||
41 | vbox.addWidget(self.statusBar) | 41 | vbox.addWidget(self.statusBar) | ||
42 | 42 | | |||
43 | self.mainWidget.resize(400, 500) | 43 | self.mainWidget.resize(400, 500) | ||
44 | self.mainWidget.setWindowTitle("Scripter") | 44 | self.mainWidget.setWindowTitle("Scripter") | ||
45 | self.mainWidget.setSizeGripEnabled(True) | 45 | self.mainWidget.setSizeGripEnabled(True) | ||
46 | self.addMenu('Edit', 'Edit') | | |||
47 | self.mainWidget.show() | 46 | self.mainWidget.show() | ||
48 | self.mainWidget.activateWindow() | 47 | self.mainWidget.activateWindow() | ||
49 | 48 | | |||
50 | def loadMenus(self): | 49 | def loadMenus(self): | ||
51 | self.addMenu('File', 'File') | 50 | self.addMenu('File', 'File') | ||
52 | 51 | | |||
53 | def addMenu(self, menuName, parentName): | 52 | def addMenu(self, menuName, parentName): | ||
54 | parent = self.menu_bar.findChild(QObject, parentName) | 53 | parent = self.menu_bar.findChild(QObject, parentName) | ||
Show All 25 Lines | 76 | for module in modules: | |||
80 | obj = action_class(self.scripter) | 79 | obj = action_class(self.scripter) | ||
81 | parent = self.mainWidget.findChild(QObject, obj.parent) | 80 | parent = self.mainWidget.findChild(QObject, obj.parent) | ||
82 | self.actions.append(dict(action=obj, parent=parent)) | 81 | self.actions.append(dict(action=obj, parent=parent)) | ||
83 | 82 | | |||
84 | for action in self.actions: | 83 | for action in self.actions: | ||
85 | action['parent'].addAction(action['action']) | 84 | action['parent'].addAction(action['action']) | ||
86 | 85 | | |||
87 | def loadWidgets(self): | 86 | def loadWidgets(self): | ||
88 | modulePath = 'scripter.ui_scripter.stackwidgets' | 87 | modulePath = 'scripter.ui_scripter.tabwidgets' | ||
89 | widgetsModule = importlib.import_module(modulePath) | 88 | widgetsModule = importlib.import_module(modulePath) | ||
90 | modules = [] | 89 | modules = [] | ||
91 | 90 | | |||
92 | for classPath in widgetsModule.widgetClasses: | 91 | for classPath in widgetsModule.widgetClasses: | ||
93 | _module, _klass = classPath.rsplit('.', maxsplit=1) | 92 | _module, _klass = classPath.rsplit('.', maxsplit=1) | ||
94 | modules.append(dict(module='{0}.{1}'.format(modulePath, _module), | 93 | modules.append(dict(module='{0}.{1}'.format(modulePath, _module), | ||
95 | klass=_klass)) | 94 | klass=_klass)) | ||
96 | 95 | | |||
97 | for module in modules: | 96 | for module in modules: | ||
98 | m = importlib.import_module(module['module']) | 97 | m = importlib.import_module(module['module']) | ||
99 | widgetClass = getattr(m, module['klass']) | 98 | widgetClass = getattr(m, module['klass']) | ||
100 | obj = widgetClass(self.scripter) | 99 | obj = widgetClass(self.scripter) | ||
101 | self.tabWidget.addTab(obj, obj.objectName()) | 100 | self.tabWidget.addTab(obj, obj.objectName()) | ||
102 | 101 | | |||
103 | def invokeAction(self, actionName): | 102 | def invokeAction(self, actionName): | ||
104 | for action in self.actions: | 103 | for action in self.actions: | ||
105 | if action['action'].objectName() == actionName: | 104 | if action['action'].objectName() == actionName: | ||
106 | method = getattr(action['action'], actionName) | 105 | method = getattr(action['action'], actionName) | ||
107 | if method: | 106 | if method: | ||
108 | return method() | 107 | return method() | ||
109 | 108 | | |||
110 | def findStackWidget(self, widgetName): | 109 | def findTabWidget(self, widgetName): | ||
111 | for index in range(self.tabWidget.count()): | 110 | for index in range(self.tabWidget.count()): | ||
112 | widget = self.tabWidget.widget(index) | 111 | widget = self.tabWidget.widget(index) | ||
113 | if widget.objectName() == widgetName: | 112 | if widget.objectName() == widgetName: | ||
114 | return widget | 113 | return widget | ||
115 | 114 | | |||
116 | def showException(self, exception): | 115 | def showException(self, exception): | ||
117 | QMessageBox.critical(self.editor, "Error running script", str(exception)) | 116 | QMessageBox.critical(self.editor, "Error running script", str(exception)) | ||
118 | 117 | | |||
119 | def setDocumentEditor(self, document): | 118 | def setDocumentEditor(self, document): | ||
120 | self.editor.clear() | 119 | self.editor.clear() | ||
121 | self.editor.moveCursor(QTextCursor.Start) | 120 | self.editor.moveCursor(QTextCursor.Start) | ||
122 | self.editor.insertPlainText(document.data) | 121 | self.editor.insertPlainText(document.data) | ||
123 | self.editor.moveCursor(QTextCursor.End) | 122 | self.editor.moveCursor(QTextCursor.End) | ||
124 | 123 | | |||
125 | def setStatusBar(self, value='untitled'): | 124 | def setStatusBar(self, value='untitled'): | ||
126 | self.statusBar.setText(value) | 125 | self.statusBar.setText(value) | ||
127 | 126 | | |||
128 | def setActiveWidget(self, widgetName): | 127 | def setActiveWidget(self, widgetName): | ||
129 | widget = self.findStackWidget(widgetName) | 128 | widget = self.findTabWidget(widgetName) | ||
130 | 129 | | |||
131 | if widget: | 130 | if widget: | ||
132 | self.tabWidget.setCurrentWidget(widget) | 131 | self.tabWidget.setCurrentWidget(widget) | ||
133 | 132 | | |||
134 | def setStepped(self, status): | 133 | def setStepped(self, status): | ||
135 | self.editor.setStepped(status) | 134 | self.editor.setStepped(status) | ||
136 | 135 | | |||
137 | def clearEditor(self): | 136 | def clearEditor(self): | ||
138 | self.editor.clear() | 137 | self.editor.clear() | ||
139 | 138 | | |||
140 | def repaintDebugArea(self): | 139 | def repaintDebugArea(self): | ||
141 | self.editor.repaintDebugArea() | 140 | self.editor.repaintDebugArea() | ||
141 | | ||||
142 | def closeScripter(self): | ||||
143 | self.mainWidget.close() |