def __init__(self, config_file_path, help_tool): QWidget.__init__(self) layout = QVBoxLayout() toolbar = QToolBar("toolbar") save_action = toolbar.addAction(resourceIcon("ide/disk"), "Save") save_action.triggered.connect(self.save) save_as_action = toolbar.addAction(resourceIcon("ide/save_as"), "Save As") save_as_action.triggered.connect(self.saveAs) # reload_icon = toolbar.style().standardIcon(QStyle.SP_BrowserReload) # reload_action = toolbar.addAction(reload_icon, "Reload") # reload_action.triggered.connect(self.reload) toolbar.addSeparator() toolbar.addAction(help_tool.getAction()) stretchy_separator = QWidget() stretchy_separator.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) toolbar.addWidget(stretchy_separator) search = SearchBox() search.setMaximumWidth(200) search.setContentsMargins(5, 2, 5, 2) toolbar.addWidget(search) layout.addWidget(toolbar) self.ide_panel = IdePanel() layout.addWidget(self.ide_panel, 1) self.config_file_path = config_file_path with open(config_file_path) as f: config_file_text = f.read() self.highlighter = KeywordHighlighter(self.ide_panel.document()) search.filterChanged.connect(self.highlighter.setSearchString) self.parseDefines(config_file_text) self.ide_panel.document().setPlainText(config_file_text) cursor = self.ide_panel.textCursor() cursor.setPosition(0) self.ide_panel.setTextCursor(cursor) self.ide_panel.setFocus() self.setLayout(layout)
def main(): if len(sys.argv) == 1: print("Missing configuration file!") sys.exit(1) QApplication.setGraphicsSystem("raster") app = QApplication( sys.argv) #Early so that QT is initialized before other imports main_window = QMainWindow() central_widget = QWidget() main_window.setCentralWidget(central_widget) layout = QVBoxLayout() central_widget.setLayout(layout) search = SearchBox() ide = IdePanel() layout.addWidget(search) layout.addWidget(ide, 1) path = sys.argv[1] with open(path) as f: config_file = f.read() highlighter = KeywordHighlighter(ide.document()) search.filterChanged.connect(highlighter.setSearchString) ide.document().setPlainText(config_file) cursor = ide.textCursor() cursor.setPosition(0) ide.setTextCursor(cursor) ide.setFocus() main_window.show() sys.exit(app.exec_())