def _setupUi(self): self.resize(400, 300) self.gridLayout = QGridLayout(self) self.label = QLabel(tr("Choose a type for this tab:")) self.label.setAlignment(Qt.AlignCenter) self.gridLayout.addWidget(self.label, 0, 0, 1, 3) self.gridLayout.addItem(horizontalSpacer(), 1, 0, 1, 1) self.verticalLayout = QVBoxLayout() BUTTONS = [ ('networthButton', tr("1. Net Worth"), 'balance_sheet_16'), ('profitButton', tr("2. Profit && Loss"), 'income_statement_16'), ('transactionButton', tr("3. Transactions"), 'transaction_table_16'), ('gledgerButton', tr("4. General Ledger"), 'gledger_16'), ('scheduleButton', tr("5. Schedules"), 'schedules_16'), ('budgetButton', tr("6. Budgets"), 'budget_16'), ('docpropsButton', tr("7. Document Properties"), 'gledger_16'), ] for i, (name, label, icon) in enumerate(BUTTONS, start=1): button = QPushButton(label) if icon: button.setIcon(QIcon(QPixmap(':/{}'.format(icon)))) self.verticalLayout.addWidget(button) setattr(self, name, button) shortcut = QShortcut(self) shortcut.setKey(QKeySequence(str(i))) shortcut.setContext(Qt.WidgetShortcut) setattr(self, 'shortcut{}'.format(i), shortcut) self.gridLayout.addLayout(self.verticalLayout, 1, 1, 1, 1) self.gridLayout.addItem(horizontalSpacer(), 1, 2, 1, 1) self.gridLayout.addItem(verticalSpacer(), 2, 1, 1, 1)
class Shortcut(QObject): def __init__(self, id, name, shortcut_key, callback, widget): self._id = id self._name = name self._shortcut = QShortcut(QKeySequence(shortcut_key), widget) self._shortcut.activated.connect(callback) self._callback = callback def id(self): return self._id def name(self): return self._name def setName(self, name): self._name = name def shortcut(self): return self._shortcut def key(self): return self._shortcut.key().toString() def setKey(self, key): self._shortcut.setKey(QKeySequence(key)) def setShortcut(self, shortcut): self._shortcut = shortcut def callback(self): return self._callback
def __init__(self, items=None, parent=None, status=None): self.emits = ['patternchanged'] self.receives = [('patterns', self.setItems)] self.settingsdialog = SettingsWin QComboBox.__init__(self, parent) self._status = status status['patterns'] = self.items status['patterntext'] = lambda: str(self.currentText()) self.setEditable(True) if items: self.addItems(items) pchange = lambda text: self.patternchanged.emit(str(text)) self.editTextChanged.connect(pchange) shortcut = QShortcut(self) shortcut.setKey('F8') shortcut.setContext(Qt.ApplicationShortcut) def set_focus(): if self.hasFocus(): status['table'].setFocus() else: self.lineEdit().selectAll() self.setFocus() shortcut.activated.connect(set_focus)
class MovablePushButton(QPushButton, MovableWidget): def __init__(self, name, valueOn, shortcutKey, **kwargs): MovableWidget.__init__(self, name) QPushButton.__init__(self, name=name) self.valueOn = valueOn self.parameter = kwargs.get('parameter', None) self.module = kwargs.get('module', None) self.shortcut = QShortcut(self) self.shortcut.setKey(shortcutKey) self.shortcut.setAutoRepeat(False) self.shortcut.activated.connect(lambda: self.animateClick()) self.updateData() def getData(self): data = dict() data['widgetType'] = 'PushButton' data['name'] = self.widgetName data['valueOn'] = self.valueOn data['module'] = self.module data['parameter'] = self.parameter data['shortcut'] = self.shortcut.key().toString() return data def updateData(self): self.setText(self.widgetName + '\n' + self.valueOn)
def __init__(self, parent=None, url='', width=None, height=None, isDialog=False): super(Window, self).__init__(parent if isDialog else None) self.assets = assets assets.windows.append(self) if width is None: width = assets.manifest['width'] if height is None: height = assets.manifest['height'] windowFlags = Qt.WindowTitleHint | \ Qt.WindowSystemMenuHint | \ Qt.WindowMinimizeButtonHint | \ Qt.WindowMaximizeButtonHint | \ Qt.WindowCloseButtonHint if isDialog: windowFlags |= Qt.Dialog else: windowFlags |= Qt.CustomizeWindowHint self.dragParams = { 'type': 0, 'x': self.shadowWidth, 'y': self.shadowWidth, 'size': 5, 'draging': False } self.api = API(self) self.parent = parent self.resize(width, height) self.setMouseTracking(True) self.setWindowFlags(windowFlags) self.setAttribute(Qt.WA_QuitOnClose, True) self.setAttribute(Qt.WA_DeleteOnClose, True) self.setAttribute(Qt.WA_TranslucentBackground, True) self.setWindowTitle(assets.manifest['name']) self.setResizable(assets.manifest['resizable']) self.setFrameless(assets.manifest['frameless']) self.setWindowIcon(QIcon(assets.manifest['icon'])) self._win_id = self.winId().__int__() self.webView = WebView(self, url) self.verticalLayout.addWidget(self.webView) if assets.manifest['debug']: shortcut = QShortcut(self) shortcut.setKey(Qt.Key_F12) shortcut.activated.connect(self.showInspector) self._old_window_state = self.windowState() self._is_max_to_min = False self._maximizable = True self.setClosable(True)
def shortcuts(self): '''Create keyboard short-cuts''' disarming = QShortcut(self._widget) disarming.setKey(Qt.CTRL + Qt.Key_D) disarming.activated.connect(self.PopupMessages.emergency_disarm) shutdown = QShortcut(self._widget) shutdown.setKey(Qt.ALT + Qt.Key_F4) shutdown.activated.connect(self.shutdown_plugin)
def setup_inspector(self): ''' This code from http://agateau.com/2012/02/03/pyqtwebkit-experiments-part-2-debugging/ ''' page = self.web_view.page() page.settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True) self.web_inspector = QWebInspector(self) self.web_inspector.setPage(page) shortcut = QShortcut(self) shortcut.setKey(Qt.Key_F12) shortcut.activated.connect(self.toggle_inspector) self.web_inspector.setVisible(False)
def setup_inspector(self): """ This code from http://agateau.com/2012/02/03/pyqtwebkit-experiments-part-2-debugging/ """ page = self.web_view.page() page.settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True) self.web_inspector = QWebInspector(self) self.web_inspector.setPage(page) shortcut = QShortcut(self) shortcut.setKey(Qt.Key_F12) shortcut.activated.connect(self.toggle_inspector) self.web_inspector.setVisible(False)
class MovableSlider(DoubleSlider, MovableWidget): def __init__(self, name, minSlider, maxSlider, stepSlider, label, shortcutPlusKey, shortcutMinusKey, startValue, **kwargs): MovableWidget.__init__(self, name, label) DoubleSlider.__init__(self, Qt.Horizontal, name=name) self.parameter = kwargs.get('parameter', None) self.module = kwargs.get('module', None) self.minSlider = minSlider self.maxSlider = maxSlider self.stepSlider = stepSlider self.label = label self.shortcutPlus = QShortcut(self) self.shortcutPlus.setKey(shortcutPlusKey) self.shortcutPlus.activated.connect( lambda: self.setValue(self.value + float(self.stepSlider))) self.shortcutMinus = QShortcut(self) self.shortcutMinus.setKey(shortcutMinusKey) self.shortcutMinus.activated.connect( lambda: self.setValue(self.value - float(self.stepSlider))) self.startValue = startValue self.setTracking(False) self.updateData() def getData(self): data = dict() data['widgetType'] = 'Slider' data['name'] = self.widgetName data['minSlider'] = self.minSlider data['maxSlider'] = self.maxSlider data['stepSlider'] = self.stepSlider data['module'] = self.module data['parameter'] = self.parameter data['shortcutPlus'] = self.shortcutPlus.key().toString() data['shortcutMinus'] = self.shortcutMinus.key().toString() return data def updateData(self): self.setMinimum(float(self.minSlider)) self.setMaximum(float(self.maxSlider)) self.setTickInterval(float(self.stepSlider)) self.setPageStep(1) self.setSingleStep(1) self.setValue(float(self.startValue)) self.label.setText(self.widgetName + ': ' + str(self.startValue))
class Keybind(QObject): """Full keybind class, includes a sequence, name, category, tooltip, plus our callbacks""" COLUMNS = ("text", "keysequence") HEADER = ("Name", "Shortcut") updated = pyqtSignal(object) # emits self activated = pyqtSignal() def __init__(self, name: str, slug: str, *args, **kwargs): """Creates a keybind item Args: `name (str)`: Readable description, used in keybind editor `slug (str)`: used to save settings, and get from default list """ super().__init__(*args, **kwargs) self.name = name self.slug = slug self.sequence = self.register_key(slug) def register_key(self, slug: str) -> Union[KeySequence, None]: """Register the key sequence, makes a QShortcut out of it""" seq = KeySequence.from_profile(slug) ui = MyApp.instance().ui self.act = QShortcut(seq, ui) if seq else QShortcut(ui) self.act.activated.connect(self.activated.emit) return seq @property def data(self) -> tuple: """Returns the data for our table model""" return (self.name, self.sequence.toString()) def update(self, new: KeySequence): """Updates the keybind entry with a new keysequence and emits `updated` signal Args: `new (KeySequence)`: new keysequence """ self.sequence.swap(new) self.act.setKey(self.sequence) self.updated.emit(self) def __str__(self) -> str: return f"Key '{self.name}': {self.sequence.toString()}" def __repr__(self) -> str: return f"<{self.__class__.__name__} '{self.slug}' {self.sequence.toString()}>"
def __init__(self, parent = None, url = '', width = None, height = None, isDialog = False): super(Window, self).__init__(parent if isDialog else None) self.assets = assets assets.windows.append(self) if width is None: width = assets.manifest['width'] if height is None: height = assets.manifest['height'] windowFlags = Qt.WindowTitleHint | \ Qt.WindowSystemMenuHint | \ Qt.WindowMinimizeButtonHint | \ Qt.WindowMaximizeButtonHint | \ Qt.WindowCloseButtonHint if isDialog: windowFlags |= Qt.Dialog else: windowFlags |= Qt.CustomizeWindowHint self.dragParams = {'type': 0, 'x': self.shadowWidth, 'y': self.shadowWidth, 'size': 5, 'draging': False} self.api = API(self) self.parent = parent self.resize(width, height) self.setMouseTracking(True) self.setWindowFlags(windowFlags) self.setAttribute(Qt.WA_QuitOnClose, True) self.setAttribute(Qt.WA_DeleteOnClose, True) self.setAttribute(Qt.WA_TranslucentBackground, True) self.setWindowTitle(assets.manifest['name']) self.setResizable(assets.manifest['resizable']) self.setFrameless(assets.manifest['frameless']) self.setWindowIcon(QIcon(assets.manifest['icon'])) self._win_id = self.winId().__int__() self.webView = WebView(self, url) self.verticalLayout.addWidget(self.webView) if assets.manifest['debug']: shortcut = QShortcut(self) shortcut.setKey(Qt.Key_F12) shortcut.activated.connect(self.showInspector) self._old_window_state = self.windowState() self._is_max_to_min = False self._maximizable = True self.setClosable(True)
def createtab(self, url: str = config["startup-url"]): layout = QGridLayout() widget = QWidget() widget.setLayout(layout) bar = QLineEdit() completer = QCompleter(self.wordlist) browser = QWebEngineView() backbtn = QPushButton("←") reloadbtn = QPushButton("reload") gotocurrenturlbutton = QPushButton("go!") reloadshort = QShortcut(self) reloadshort.setKey("Ctrl+R") bar.setCompleter(completer) reloadshort.activated.connect(browser.reload) gotocurrenturlbutton.clicked.connect( lambda clicked, browser=browser: self.updatewin(browser, clicked)) reloadbtn.clicked.connect(browser.reload) bar.returnPressed.connect( lambda browser=browser: self.updatewin(browser, True)) bar.textChanged.connect(self.updatetext) browser.load(QUrl(url)) browser.page().urlChanged.connect( lambda qurl, bar=bar: self.updateurl(qurl, bar)) browser.page().loadFinished.connect( lambda arg__1, index=self.tabs.indexOf(browser), browser=browser: self.updatetab(arg__1, index, browser)) browser.page().iconChanged.connect(lambda qicon, index=self.tabs.count( ): self.updateicon(index, qicon)) browser.page().setUrlRequestInterceptor(NetworkFilter) browser.page().titleChanged.connect( lambda title=browser.page().title(): self.updatetitle(title)) backbtn.clicked.connect(browser.back) layout.addWidget(bar, 1, 3) layout.addWidget(reloadbtn, 1, 2) layout.addWidget(browser, 2, 1, 1, 5) layout.addWidget(backbtn, 1, 1) layout.addWidget(gotocurrenturlbutton, 1, 4) self.tabs.addTab(widget, browser.icon(), browser.title()) self.tabs.setCurrentIndex(self.tabs.count() - 1)
def initUi(self): layout = QGridLayout() stacked_widget = QStackedWidget() stacked_widget.addWidget(QLabel('Linux')) stacked_widget.addWidget(QLabel('Windows')) stacked_widget.addWidget(QLabel('Mac')) stacked_widget.addWidget(QLabel('Android')) layout.addWidget(stacked_widget, 0, 0) self.setLayout(layout) left_shortcut = QShortcut(self) left_shortcut.setKey('Ctrl+L') right_shortcut = QShortcut(self) right_shortcut.setKey('Ctrl+R') left_shortcut.activated.connect( lambda: self.on_shortcut_activated(left_shortcut, stacked_widget)) right_shortcut.activated.connect( lambda: self.on_shortcut_activated(right_shortcut, stacked_widget))
def _setupInspector(self): """ F12키를 누르면 "개발자 도구"가 노출됨 """ # webinspector self.settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True) self.webInspector = QWebInspector(self) self.webInspector.setPage(self.page()) # shortcut shortcut = QShortcut(self) shortcut.setContext(Qt.ApplicationShortcut) shortcut.setKey(Qt.Key_F12) shortcut.activated.connect(self._toggleInspector) # Devtools self.webInspector.setVisible(True) self.devTool = QDialog(self) self.devTool.setWindowTitle("Development Tool") self.devTool.resize(950, 400) layout = QGridLayout() layout.setContentsMargins(0,0,0,0) layout.addWidget(self.webInspector) self.devTool.setLayout(layout)
class Shortcuts(object): def __init__(self, parent): self.personal_shortcut = QShortcut(QKeySequence(options.personal_shortcut), parent) self.social_shortcut = QShortcut(QKeySequence(options.social_shortcut), parent) self.updates_shortcut = QShortcut(QKeySequence(options.updates_shortcut), parent) self.promotions_shortcut = QShortcut(QKeySequence(options.promotions_shortcut), parent) self.forums_shortcut = QShortcut(QKeySequence(options.forums_shortcut), parent) self.sent_shortcut = QShortcut(QKeySequence(options.sent_shortcut), parent) self.unread_shortcut = QShortcut(QKeySequence(options.unread_shortcut), parent) self.important_shortcut = QShortcut(QKeySequence(options.important_shortcut), parent) self.starred_shortcut = QShortcut(QKeySequence(options.starred_shortcut), parent) self.trash_shortcut = QShortcut(QKeySequence(options.trash_shortcut), parent) self.spam_shortcut = QShortcut(QKeySequence(options.spam_shortcut), parent) self.send_email_shortcut = QShortcut(QKeySequence(options.send_email_shortcut), parent) self.contacts_shortcut = QShortcut(QKeySequence(options.contacts_shortcut), parent) self.settings_shortcut = QShortcut(QKeySequence(options.settings_shortcut), parent) self.personal_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('personal')) self.social_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('social')) self.updates_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('updates')) self.promotions_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('promotions')) self.forums_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('forums')) self.sent_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('sent')) self.unread_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('unread')) self.important_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('important')) self.starred_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('starred')) self.trash_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('trash')) self.spam_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('spam')) self.send_email_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('send_email')) self.contacts_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('contacts')) self.settings_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('settings')) OptionEventChannel.subscribe( 'personal_shortcut', lambda shortcut: self.personal_shortcut.setKey(QKeySequence(shortcut))) OptionEventChannel.subscribe( 'social_shortcut', lambda shortcut: self.social_shortcut.setKey(QKeySequence(shortcut))) OptionEventChannel.subscribe( 'updates_shortcut', lambda shortcut: self.updates_shortcut.setKey(QKeySequence(shortcut))) OptionEventChannel.subscribe( 'promotions_shortcut', lambda shortcut: self.promotions_shortcut.setKey(QKeySequence(shortcut))) OptionEventChannel.subscribe( 'forums_shortcut', lambda shortcut: self.forums_shortcut.setKey(QKeySequence(shortcut))) OptionEventChannel.subscribe( 'sent_shortcut', lambda shortcut: self.sent_shortcut.setKey(QKeySequence(shortcut))) OptionEventChannel.subscribe( 'unread_shortcut', lambda shortcut: self.unread_shortcut.setKey(QKeySequence(shortcut))) OptionEventChannel.subscribe( 'important_shortcut', lambda shortcut: self.important_shortcut.setKey(QKeySequence(shortcut))) OptionEventChannel.subscribe( 'starred_shortcut', lambda shortcut: self.starred_shortcut.setKey(QKeySequence(shortcut))) OptionEventChannel.subscribe( 'trash_shortcut', lambda shortcut: self.trash_shortcut.setKey(QKeySequence(shortcut))) OptionEventChannel.subscribe( 'spam_shortcut', lambda shortcut: self.spam_shortcut.setKey(QKeySequence(shortcut))) OptionEventChannel.subscribe( 'send_email_shortcut', lambda shortcut: self.send_email_shortcut.setKey(QKeySequence(shortcut))) OptionEventChannel.subscribe( 'contacts_shortcut', lambda shortcut: self.contacts_shortcut.setKey(QKeySequence(shortcut))) OptionEventChannel.subscribe( 'settings_shortcut', lambda shortcut: self.settings_shortcut.setKey(QKeySequence(shortcut)))
class MainWindow(QMainWindow): """ the main render proccess of the browser including all updating methods and the webview """ def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.url = {} self.setWindowTitle("Bird-Browser") self.wordlist = [ "dev://", "bookmark://", "bookmarks://", "search://", "http://", "https://", "pwd://" ] self.tabs = QTabWidget() self.tabcreate = QPushButton("+") self.shortcreatetab = QShortcut(self) self.shortcreatetab.setKey("Ctrl+T") self.pwdman = pwdmanager.PwdManager( config["key"], f"{Path.home()}/.config/bird/database.db") if "style" in config: innerstyle = f""" color: {config['style']['color']}; background-color: {config['style']['background-color']}; """ self.setStyleSheet(f""" QMainWindow{ {innerstyle} } """) self.tabs.setStyleSheet(f""" QTabWidget{ {innerstyle} } """) else: self.setStyleSheet(""" background-color: rgb(50, 50, 50); color: rgb(255, 255, 255); """) self.tabs.setStyleSheet(""" background-color: rgb(50, 50, 50); color: rgb(255, 255, 255); """) self.tabs.clear() self.tabs.setTabsClosable(True) self.createtab() #connections self.shortcreatetab.activated.connect(self.createtab) self.tabcreate.clicked.connect(self.createtab) self.tabs.tabCloseRequested.connect(self.closetab) self.tabs.setCornerWidget(self.tabcreate) #show window self.setCentralWidget(self.tabs) self.show() def updatewin(self, browser: QWebEngineView, boolean=True): """ This Method updates the shown browser window to the current url of the search bar it also contains the search engine-integration, and bookmarking """ url = self.url[str(self.tabs.currentIndex)] if url.startswith("search://"): search = url.split("search://", 1)[1] url = config["search-engine"].format(search=search) elif url.startswith("bookmarks://"): try: name = url.split("bookmarks://", 1)[1] url = bmk.getBookmark(cursor, name)[name] except ValueError: url = "about:blank" elif url.startswith("bookmark://"): if not "|" in url.split("bookmark://", 1)[1]: url = "about:blank" else: parts = url.split("bookmark://", 1)[1].split("|") if parts[1] == "-": parts[1] = browser.url().toString() try: bmk.getBookmark(cursor, parts[0]) bmk.modifyBookmark(cursor, parts[0], parts[0], parts[1]) conn.commit() except: bmk.addBookmark(cursor, parts[0], parts[1]) conn.commit() elif url.startswith("file://"): path = url.split("file://", 1)[1] if path.startswith("~/"): path = f"{Path.home()}/{path.split('~/', 1)[1]}" try: with open(path, "r") as reqfile: reqcontent = reqfile.read() browser.page().setHtml(reqcontent) return except: print(f"Error on requested page: Path '{path}' doesn't exist") browser.page().loadUrl(QUrl("about:blank")) elif url.startswith("dev://"): url = url.split("dev://", 1)[1] if not url.startswith("https://") and not url.startswith( "http://"): url = "http://" + url self.tabs.addTab(devtools.DevToolWidget(url), "dev-tools") elif url.startswith("pwd://"): self.tabs.addTab(pwdmanager.PwdManagerWidget(self.pwdman), "Passwords") return elif "additional-search-engines" in config: for source in config["additional-search-engines"]: if url.startswith(source): search = url.split(source, 1)[1] url = config["additional-search-engines"][source].format( search=search) break else: pass else: if not url.startswith("https://") and not url.startswith( "http://"): url = "http://" + url elif not url.startswith("https://") and not url.startswith("http://"): url = "http://" + url browser.page().load(QUrl(url)) self.wordlist.append(url) def updatetext(self, text: str): """ This Method updates the internal text of the search bar """ self.url[str(self.tabs.currentIndex)] = text def updateurl(self, url, bar): """ This method updates the url bar to the currently displayed url. It gets triggered if the displayed page directs you to a different page """ bar.setText(url.toString()) def updatetab(self, arg_1, index, browser): if len(browser.page().title()) > 20: self.tabs.setTabText(index, browser.page().title()[0:17] + "...") else: self.tabs.setTabText(index, browser.page().title()) self.tabs.setTabIcon(index, browser.page().icon()) def updatetitle(self, title: str): self.tabs.setTabText(self.tabs.currentIndex(), title) def updateicon(self, index, icon): self.tabs.setTabIcon(index, icon) def closetab(self, index): if index == self.tabs.currentIndex(): self.tabs.setCurrentIndex(index - 1 if index != 0 else index + 1) self.tabs.removeTab(index) if self.tabs.count() == 0: sys.exit(0) @pyqtSlot() def createtab(self, url: str = config["startup-url"]): layout = QGridLayout() widget = QWidget() widget.setLayout(layout) bar = QLineEdit() completer = QCompleter(self.wordlist) browser = QWebEngineView() backbtn = QPushButton("←") reloadbtn = QPushButton("reload") gotocurrenturlbutton = QPushButton("go!") reloadshort = QShortcut(self) reloadshort.setKey("Ctrl+R") bar.setCompleter(completer) reloadshort.activated.connect(browser.reload) gotocurrenturlbutton.clicked.connect( lambda clicked, browser=browser: self.updatewin(browser, clicked)) reloadbtn.clicked.connect(browser.reload) bar.returnPressed.connect( lambda browser=browser: self.updatewin(browser, True)) bar.textChanged.connect(self.updatetext) browser.load(QUrl(url)) browser.page().urlChanged.connect( lambda qurl, bar=bar: self.updateurl(qurl, bar)) browser.page().loadFinished.connect( lambda arg__1, index=self.tabs.indexOf(browser), browser=browser: self.updatetab(arg__1, index, browser)) browser.page().iconChanged.connect(lambda qicon, index=self.tabs.count( ): self.updateicon(index, qicon)) browser.page().setUrlRequestInterceptor(NetworkFilter) browser.page().titleChanged.connect( lambda title=browser.page().title(): self.updatetitle(title)) backbtn.clicked.connect(browser.back) layout.addWidget(bar, 1, 3) layout.addWidget(reloadbtn, 1, 2) layout.addWidget(browser, 2, 1, 1, 5) layout.addWidget(backbtn, 1, 1) layout.addWidget(gotocurrenturlbutton, 1, 4) self.tabs.addTab(widget, browser.icon(), browser.title()) self.tabs.setCurrentIndex(self.tabs.count() - 1) def renderDevToolsView(self, webview): return self.tabs.setCurrentWidget( devtools.DevToolWidget(webview.page().url().toString()))
class GuiProjectView(QWidget): """This is a wrapper class holding all the elements of the project tree. The core object is the project tree itself. Most methods available are mapped through to the project tree class. """ # Signals triggered when the meta data values of items change treeItemChanged = pyqtSignal(str) novelItemChanged = pyqtSignal(str) rootFolderChanged = pyqtSignal(str) wordCountsChanged = pyqtSignal() # Signals for user interaction with the project tree selectedItemChanged = pyqtSignal(str) openDocumentRequest = pyqtSignal(str, Enum, int, str) def __init__(self, mainGui): QWidget.__init__(self, mainGui) self.mainGui = mainGui # Build GUI self.projTree = GuiProjectTree(self) self.projBar = GuiProjectToolBar(self) # Assemble self.outerBox = QVBoxLayout() self.outerBox.addWidget(self.projBar, 0) self.outerBox.addWidget(self.projTree, 1) self.outerBox.setContentsMargins(0, 0, 0, 0) self.outerBox.setSpacing(0) self.setLayout(self.outerBox) # Keyboard Shortcuts self.keyMoveUp = QShortcut(self.projTree) self.keyMoveUp.setKey("Ctrl+Up") self.keyMoveUp.setContext(Qt.WidgetShortcut) self.keyMoveUp.activated.connect( lambda: self.projTree.moveTreeItem(-1)) self.keyMoveDn = QShortcut(self.projTree) self.keyMoveDn.setKey("Ctrl+Down") self.keyMoveDn.setContext(Qt.WidgetShortcut) self.keyMoveDn.activated.connect(lambda: self.projTree.moveTreeItem(1)) self.keyUndoMv = QShortcut(self.projTree) self.keyUndoMv.setKey("Ctrl+Shift+Z") self.keyUndoMv.setContext(Qt.WidgetShortcut) self.keyUndoMv.activated.connect(lambda: self.projTree.undoLastMove()) self.keyContext = QShortcut(self.projTree) self.keyContext.setKey("Ctrl+.") self.keyContext.setContext(Qt.WidgetShortcut) self.keyContext.activated.connect( lambda: self.projTree.openContextOnSelected()) # Function Mappings self.revealNewTreeItem = self.projTree.revealNewTreeItem self.renameTreeItem = self.projTree.renameTreeItem self.getTreeFromHandle = self.projTree.getTreeFromHandle self.emptyTrash = self.projTree.emptyTrash self.deleteItem = self.projTree.deleteItem self.setTreeItemValues = self.projTree.setTreeItemValues self.propagateCount = self.projTree.propagateCount self.getSelectedHandle = self.projTree.getSelectedHandle self.setSelectedHandle = self.projTree.setSelectedHandle self.changedSince = self.projTree.changedSince return ## # Methods ## def initSettings(self): self.projTree.initSettings() return def clearProject(self): self.projTree.clearTree() return def saveProjectTree(self): self.projTree.saveTreeOrder() return def populateTree(self): self.projTree.buildTree() return def setFocus(self): """Forward the set focus call to the tree widget. """ self.projTree.setFocus() return def treeHasFocus(self): """Check if the project tree has focus. """ return self.projTree.hasFocus() ## # Public Slots ## @pyqtSlot(str, int, int, int) def updateCounts(self, tHandle, cCount, wCount, pCount): """Slot for updating the word count of a specific item. """ self.projTree.propagateCount(tHandle, wCount, countChildren=True) self.wordCountsChanged.emit() return
class UldkGugik: """QGIS Plugin Implementation.""" nazwy_warstw = { 1: "dzialki_ew_uldk", 2: "obreby_ew_uldk", 3: "gminy_uldk", 4: "powiaty_uldk", 5: "wojewodztwa_uldk" } def __init__(self, iface): """Constructor. :param iface: An interface instance that will be passed to this class which provides the hook by which you can manipulate the QGIS application at run time. :type iface: QgsInterface """ if Qgis.QGIS_VERSION_INT >= 31000: from .qgis_feed import QgisFeed self.feed = QgisFeed() self.feed.initFeed() #DialogOnTop # Save reference to the QGIS interface self.iface = iface # initialize plugin directory self.plugin_dir = os.path.dirname(__file__) # initialize locale locale = QSettings().value('locale/userLocale')[0:2] locale_path = os.path.join(self.plugin_dir, 'i18n', 'UldkGugik_{}.qm'.format(locale)) if os.path.exists(locale_path): self.translator = QTranslator() self.translator.load(locale_path) if qVersion() > '4.3.3': QCoreApplication.installTranslator(self.translator) # Declare instance attributes self.actions = [] self.menu = self.tr(u'&EnviroSolutions') #toolbar self.toolbar = self.iface.mainWindow().findChild( QToolBar, 'EnviroSolutions') if not self.toolbar: self.toolbar = self.iface.addToolBar(u'EnviroSolutions') self.toolbar.setObjectName(u'EnviroSolutions') # Check if plugin was started the first time in current QGIS session # Must be set in initGui() to survive plugin reloads self.first_start = None self.canvas = self.iface.mapCanvas() # out click tool will emit a QgsPoint on every click self.clickTool = QgsMapToolEmitPoint(self.canvas) self.clickTool.canvasClicked.connect(self.canvasClicked) self.dlg = UldkGugikDialog() # skrot klawiszowy self.shortcut = QShortcut(iface.mainWindow()) self.shortcut.setKey(QKeySequence(Qt.ALT + Qt.Key_D)) self.shortcut.activated.connect(self.shortcut_activated) # noinspection PyMethodMayBeStatic def tr(self, message): """Get the translation for a string using Qt translation API. We implement this ourselves since we do not inherit QObject. :param message: String for translation. :type message: str, QString :returns: Translated version of message. :rtype: QString """ # noinspection PyTypeChecker,PyArgumentList,PyCallByClass return QCoreApplication.translate('UldkGugik', message) def add_action(self, icon_path, text, callback, enabled_flag=True, add_to_menu=True, add_to_toolbar=True, status_tip=None, whats_this=None, parent=None): """Add a toolbar icon to the toolbar. :param icon_path: Path to the icon for this action. Can be a resource path (e.g. ':/plugins/foo/bar.png') or a normal file system path. :type icon_path: str :param text: Text that should be shown in menu items for this action. :type text: str :param callback: Function to be called when the action is triggered. :type callback: function :param enabled_flag: A flag indicating if the action should be enabled by default. Defaults to True. :type enabled_flag: bool :param add_to_menu: Flag indicating whether the action should also be added to the menu. Defaults to True. :type add_to_menu: bool :param add_to_toolbar: Flag indicating whether the action should also be added to the toolbar. Defaults to True. :type add_to_toolbar: bool :param status_tip: Optional text to show in a popup when mouse pointer hovers over the action. :type status_tip: str :param parent: Parent widget for the new action. Defaults None. :type parent: QWidget :param whats_this: Optional text to show in the status bar when the mouse pointer hovers over the action. :returns: The action that was created. Note that the action is also added to self.actions list. :rtype: QAction """ icon = QIcon(icon_path) action = QAction(icon, text, parent) action.triggered.connect(callback) action.setEnabled(enabled_flag) if status_tip is not None: action.setStatusTip(status_tip) if whats_this is not None: action.setWhatsThis(whats_this) if add_to_toolbar: # Adds plugin icon to Plugins toolbar #self.iface.addToolBarIcon(action) self.toolbar.addAction(action) if add_to_menu: self.iface.addPluginToMenu(self.menu, action) self.actions.append(action) return action def initGui(self): """Create the menu entries and toolbar icons inside the QGIS GUI.""" icon_path = ':/plugins/uldk_gugik/images/icon.png' self.add_action( icon_path, text=self.tr(u'Usługa Lokalizacji Działek Katastralnych (ULDK)'), callback=self.run, parent=self.iface.mainWindow()) # will be set False in run() self.first_start = True #self.dock = UldkGugikDialog() #self.iface.addDockWidget(Qt.RigthDockWidgetArea, self.dock) # Inicjacja grafik self.dlg.img_main.setPixmap( QPixmap(':/plugins/uldk_gugik/images/icon_uldk2.png')) self.dlg.img_tab2.setPixmap( QPixmap(':/plugins/uldk_gugik/images/coords.png')) # rozmiar okna self.dlg.setFixedSize(self.dlg.size()) # informacje o wersji self.dlg.setWindowTitle('%s %s' % (plugin_name, plugin_version)) self.dlg.lbl_pluginVersion.setText('%s %s' % (plugin_name, plugin_version)) #eventy self.dlg.btn_download_tab1.clicked.connect( self.btn_download_tab1_clicked) self.dlg.btn_download_tab2.clicked.connect( self.btn_download_tab2_clicked) self.dlg.btn_download_tab3.clicked.connect( self.btn_download_tab3_clicked) self.dlg.btn_frommap.clicked.connect(self.btn_frommap_clicked) self.dlg.btn_frommap.setToolTip("skrót: ALT + D") def unload(self): """Removes the plugin menu item and icon from QGIS GUI.""" for action in self.actions: self.iface.removePluginMenu(self.tr(u'&EnviroSolutions'), action) # self.iface.removeToolBarIcon(action) self.toolbar.removeAction(action) def run(self): """Otwarcie okna wtyczki""" # show the dialog self.dlg.show() srid = QgsProject.instance().crs().authid().split(":")[1] self.dlg.projectionWidget.setCrs( QgsCoordinateReferenceSystem( int(srid), QgsCoordinateReferenceSystem.EpsgCrsId)) def btn_download_tab1_clicked(self): """kliknięcie klawisza pobierania po numerze TERYT w oknie wtyczki""" teryt = self.dlg.edit_id.text().strip() if not teryt: self.iface.messageBar().pushMessage("Błąd formularza:", 'musisz wpisać identyfikator', level=Qgis.Warning, duration=10) elif utils.isInternetConnected(): self.performRequestTeryt(teryt=teryt) self.dlg.hide() else: self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'brak połączenia z internetem', level=Qgis.Critical, duration=10) def btn_download_tab2_clicked(self): """kliknięcie klawisza pobierania według X i Y wpisanych w oknie wtyczki""" srid = self.dlg.projectionWidget.crs().authid().split(":")[1] self.downloadByXY(srid) def btn_download_tab3_clicked(self): objRegion = self.dlg.edit_id_2.text().strip() objParcel = self.dlg.edit_id_3.text().strip() if not objRegion: self.iface.messageBar().pushMessage("Błąd formularza:", 'musisz wpisać obręb', level=Qgis.Warning, duration=10) if not objParcel: self.iface.messageBar().pushMessage("Błąd formularza:", 'musisz wpisać numer działki', level=Qgis.Warning, duration=10) elif utils.isInternetConnected(): self.performRequestParcel(region=objRegion, parcel=objParcel) self.dlg.hide() else: self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'brak połączenia z internetem', level=Qgis.Critical, duration=10) def downloadByXY(self, srid, zoomToFeature=True): """pobranie według X i Y i SRID""" objX = self.dlg.doubleSpinBoxX.text().strip() objY = self.dlg.doubleSpinBoxY.text().strip() if not objX: self.iface.messageBar().pushMessage("Błąd formularza:", 'musisz wpisać współrzędną X', level=Qgis.Warning, duration=10) if not objY: self.iface.messageBar().pushMessage("Błąd formularza:", 'musisz wpisać współrzędną Y', level=Qgis.Warning, duration=10) elif utils.isInternetConnected(): self.performRequestXY(x=objX, y=objY, srid=srid, zoomToFeature=zoomToFeature) self.dlg.hide() else: self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'brak połączenia z internetem', level=Qgis.Critical, duration=10) def shortcut_activated(self): """zdarzenie aktywowania klawisza skrótu wskazania działki na mapie""" self.canvas.setMapTool(self.clickTool) def btn_frommap_clicked(self): """zdarzenie wciśnięcia w oknie wtyczki klawisza wskazania działki na mapie""" self.canvas.setMapTool(self.clickTool) self.dlg.hide() def canvasClicked(self, point): """kliknięcie na mapie""" self.canvas.unsetMapTool(self.clickTool) self.dlg.doubleSpinBoxX.setValue(point.x()) self.dlg.doubleSpinBoxY.setValue(point.y()) coords = "{}, {}".format(point.x(), point.y()) QgsMessageLog.logMessage(str(coords), 'ULDK') srid = QgsProject.instance().crs().authid().split(":")[1] self.downloadByXY(srid, zoomToFeature=False) def performRequestParcel(self, region, parcel): objectType = self.checkedFeatureType() self.crs = QgsProject.instance().crs().authid().split(":")[1] name = region + ' ' + parcel result = uldk_parcel.getParcelById(name, self.crs) if result is None: self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło obiektu dla id %s' % name, level=Qgis.Critical, duration=10) return res = result.split("|") if res[0] == '': self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło geometrii dla id %s' % name, level=Qgis.Critical, duration=10) return wkt = res[0] teryt = res[1] parcel = res[2] region = res[3] commune = res[4] county = res[5] voivodeship = res[6] # print(teryt, parcel, region, commune, county, voivodeship) # layer nazwa = self.nazwy_warstw[objectType] layers = QgsProject.instance().mapLayersByName(nazwa) geom = QgsGeometry().fromWkt(wkt) feat = QgsFeature() feat.setGeometry(geom) canvas = self.iface.mapCanvas() if layers: # jezeli istnieje to dodaj obiekt do warstwy layer = layers[0] else: # jezeli nie istnieje to stworz warstwe epsg = "Polygon?crs=EPSG:" + self.crs layer = QgsVectorLayer(epsg, nazwa, "memory") QgsProject.instance().addMapLayer(layer) box = feat.geometry().boundingBox() canvas.setExtent(box) provider = layer.dataProvider() provider.addFeature(feat) layer.updateExtents() canvas.refresh() counter = layer.featureCount() # add attributes if not layers: identyfikatorField = QgsField('identyfikator', QVariant.String, len=30) provider.addAttributes([identyfikatorField]) voivField = QgsField('województwo', QVariant.String, len=30) provider.addAttributes([voivField]) conField = QgsField('powiat', QVariant.String, len=30) provider.addAttributes([conField]) comField = QgsField('gmina', QVariant.String, len=30) provider.addAttributes([comField]) regField = QgsField('obręb', QVariant.String, len=30) provider.addAttributes([regField]) layer.updateFields() parField = QgsField('numer', QVariant.String, len=30) provider.addAttributes([parField]) layer.updateFields() layer.updateFields() counter = 1 idx = layer.fields().indexFromName('identyfikator') attrMap = {counter: {idx: teryt}} provider.changeAttributeValues(attrMap) voiv = layer.fields().indexFromName('województwo') attrMap = {counter: {voiv: voivodeship}} provider.changeAttributeValues(attrMap) if parcel is not None: par = layer.fields().indexFromName('numer') attrMap = {counter: {par: parcel}} provider.changeAttributeValues(attrMap) if region is not None: reg = layer.fields().indexFromName('obręb') attrMap = {counter: {reg: region}} provider.changeAttributeValues(attrMap) if commune is not None: com = layer.fields().indexFromName('gmina') attrMap = {counter: {com: commune}} provider.changeAttributeValues(attrMap) if county is not None: con = layer.fields().indexFromName('powiat') attrMap = {counter: {con: county}} provider.changeAttributeValues(attrMap) self.iface.messageBar().pushMessage("Sukces:", 'pobrano obrys obiektu %s' % (name), level=Qgis.Success, duration=10) def performRequestTeryt(self, teryt): """wykonanie zapytania pobierającego obiekt na podstawie kodu TERYT""" object_type = self.checkedFeatureType() if object_type == 1: resp = uldk_api.getParcelById(teryt, '2180') if not resp: self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło obiektu dla id %s' % teryt, level=Qgis.Critical, duration=10) return res = resp.split("|") if res[0] == '': self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło geometrii dla id %s' % teryt, level=Qgis.Critical, duration=10) return wkt = res[0] teryt = res[1] parcel = res[2] region = res[3] commune = res[4] county = res[5] voivodeship = res[6] # print(teryt, parcel, region, commune, county, voivodeship) elif object_type == 2: resp = uldk_api.getRegionById(teryt, '2180') if not resp: self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło obiektu dla id %s' % teryt, level=Qgis.Critical, duration=10) return res = resp.split("|") if res[0] == '': self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło geometrii dla id %s' % teryt, level=Qgis.Critical, duration=10) return wkt = res[0] teryt = res[1] parcel = None region = res[2] commune = res[3] county = res[4] voivodeship = res[5] # print(teryt, region, commune, county, voivodeship) elif object_type == 3: resp = uldk_api.getCommuneById(teryt, '2180') if not resp: self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło obiektu dla id %s' % teryt, level=Qgis.Critical, duration=10) return res = resp.split("|") if res[0] == '': self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło geometrii dla id %s' % teryt, level=Qgis.Critical, duration=10) return wkt = res[0] teryt = res[1] parcel = None region = None commune = res[2] county = res[3] voivodeship = res[4] # print(teryt, commune, county, voivodeship) elif object_type == 4: resp = uldk_api.getCountyById(teryt, '2180') if not resp: self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło obiektu dla id %s' % teryt, level=Qgis.Critical, duration=10) return res = resp.split("|") if res[0] == '': self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło geometrii dla id %s' % teryt, level=Qgis.Critical, duration=10) return wkt = res[0] teryt = res[1] parcel = None region = None commune = None county = res[2] voivodeship = res[3] # print(teryt, county, voivodeship) elif object_type == 5: resp = uldk_api.getVoivodeshipById(teryt, '2180') if not resp: self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło obiektu dla id %s' % teryt, level=Qgis.Critical, duration=10) return res = resp.split("|") if res[0] == '': self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło geometrii dla id %s' % teryt, level=Qgis.Critical, duration=10) return wkt = res[0] teryt = res[1] parcel = None region = None commune = None county = None voivodeship = res[2] # print(teryt, voivodeship) self.addResultsToLayer(objectType=object_type, wkt=wkt, teryt=teryt, parcel=parcel, region=region, commune=commune, county=county, voivodeship=voivodeship) self.iface.messageBar().pushMessage("Sukces:", 'pobrano obrys obiektu %s' % (teryt), level=Qgis.Success, duration=10) def performRequestXY(self, x, y, srid, zoomToFeature=True): """wykonanie zapytania pobierającego obiekt na podstawie współrzędnych""" objectType = self.checkedFeatureType() x = float(x.replace(",", ".")) y = float(y.replace(",", ".")) requestPoint = QgsPoint(x, y) QgsMessageLog.logMessage(str(srid), 'ULDK') if srid != '2180': sourceCrs = QgsCoordinateReferenceSystem.fromEpsgId(int(srid)) destCrs = QgsCoordinateReferenceSystem.fromEpsgId(2180) tr = QgsCoordinateTransform(sourceCrs, destCrs, QgsProject.instance()) requestPoint.transform(tr) pid = str(requestPoint.x()) + "," + str(requestPoint.y()) if objectType == 1: # działka resp = uldk_xy.getParcelByXY(xy=pid, srid='2180') if not resp: self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło obiektu dla współrzędnych %s' % pid, level=Qgis.Critical, duration=10) return res = resp.split("|") wkt = res[0] teryt = res[1] parcel = res[2] region = res[3] commune = res[4] county = res[5] voivodeship = res[6] print(teryt, parcel, region, commune, county, voivodeship) elif objectType == 2: resp = uldk_xy.getRegionByXY(xy=pid, srid='2180') if not resp: self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło obiektu dla dla współrzędnych %s' % pid, level=Qgis.Critical, duration=10) return res = resp.split("|") wkt = res[0] teryt = res[1] parcel = None region = res[2] commune = res[3] county = res[4] voivodeship = res[5] print(teryt, region, commune, county, voivodeship) elif objectType == 3: resp = uldk_xy.getCommuneByXY(xy=pid, srid='2180') if not resp: self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło obiektu dla współrzędnych %s' % pid, level=Qgis.Critical, duration=10) return res = resp.split("|") wkt = res[0] teryt = res[1] parcel = None region = None commune = res[2] county = res[3] voivodeship = res[4] print(teryt, commune, county, voivodeship) elif objectType == 4: resp = uldk_xy.getCountyByXY(xy=pid, srid='2180') if not resp: self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło obiektu dla współrzędnych %s' % pid, level=Qgis.Critical, duration=10) return res = resp.split("|") wkt = res[0] teryt = res[1] parcel = None region = None commune = None county = res[2] voivodeship = res[3] print(teryt, county, voivodeship) elif objectType == 5: resp = uldk_xy.getVoivodeshipByXY(xy=pid, srid='2180') if not resp: self.iface.messageBar().pushMessage( "Nie udało się pobrać obiektu:", 'API nie zwróciło obiektu dla współrzędnych %s' % pid, level=Qgis.Critical, duration=10) return res = resp.split("|") wkt = res[0] teryt = res[1] parcel = None region = None commune = None county = None voivodeship = res[2] print(teryt, voivodeship) self.addResultsToLayer(objectType=objectType, wkt=wkt, teryt=teryt, parcel=parcel, region=region, commune=commune, county=county, voivodeship=voivodeship, zoomToFeature=zoomToFeature) self.iface.messageBar().pushMessage("Sukces:", 'pobrano obrys obiektu %s' % teryt, level=Qgis.Success, duration=10) def addResultsToLayer(self, objectType, wkt, teryt, parcel, region, commune, county, voivodeship, zoomToFeature=True): """dodaje wyniki (odpowiedź z serwera) do mapy jako warstwę z atrybutami i geometrią""" feat = QgsFeature() feat.setGeometry(QgsGeometry().fromWkt(wkt)) # layer nazwa = self.nazwy_warstw[objectType] layers = QgsProject.instance().mapLayersByName(nazwa) # usuwanie pustych warstw z projektu for layer in layers: if layer.featureCount() == 0: QgsProject.instance().removeMapLayer(layer) layers.remove(layer) # layers = list(filter(lambda layer: isinstance(layer,QgsVectorLayer), layers)) if layers: # jezeli istnieje to dodaj obiekt do warstwy layer = layers[0] featId = layer.featureCount() + 1 provider = layer.dataProvider() provider.addFeature(feat) else: # jezeli nie istnieje to stworz warstwe layer = QgsVectorLayer("Polygon?crs=EPSG:2180", nazwa, "memory") QgsProject.instance().addMapLayer(layer) provider = layer.dataProvider() provider.addFeature(feat) identyfikatorField = QgsField('identyfikator', QVariant.String, len=30) provider.addAttributes([identyfikatorField]) voivField = QgsField('województwo', QVariant.String, len=30) provider.addAttributes([voivField]) if objectType == 4 or objectType == 3 or objectType == 2 or objectType == 1: conField = QgsField('powiat', QVariant.String, len=30) provider.addAttributes([conField]) if objectType == 3 or objectType == 2 or objectType == 1: comField = QgsField('gmina', QVariant.String, len=30) provider.addAttributes([comField]) if objectType == 2 or objectType == 1: regField = QgsField('obręb', QVariant.String, len=30) provider.addAttributes([regField]) if objectType == 1: parField = QgsField('numer', QVariant.String, len=30) provider.addAttributes([parField]) layer.updateFields() featId = 1 idx = layer.fields().indexFromName('identyfikator') voiv = layer.fields().indexFromName('województwo') attrMap = {featId: {idx: teryt, voiv: voivodeship}} provider.changeAttributeValues(attrMap) if parcel: par = layer.fields().indexFromName('numer') attrMap = {featId: {par: parcel}} provider.changeAttributeValues(attrMap) if region: reg = layer.fields().indexFromName('obręb') attrMap = {featId: {reg: region}} provider.changeAttributeValues(attrMap) if commune: com = layer.fields().indexFromName('gmina') attrMap = {featId: {com: commune}} provider.changeAttributeValues(attrMap) if county: con = layer.fields().indexFromName('powiat') attrMap = {featId: {con: county}} provider.changeAttributeValues(attrMap) if zoomToFeature: projectCrs = QgsProject.instance().crs().authid().split(":")[1] if projectCrs != '2180': sourceCrs = QgsCoordinateReferenceSystem.fromEpsgId(2180) destCrs = QgsCoordinateReferenceSystem.fromEpsgId( int(projectCrs)) tr = QgsCoordinateTransform(sourceCrs, destCrs, QgsProject.instance()) box = tr.transform(feat.geometry().boundingBox()) else: box = feat.geometry().boundingBox() self.canvas.setExtent(box) self.canvas.refresh() else: layer.triggerRepaint() def checkedFeatureType(self): """ Fukncja pomocnicza sprawdzająca jaki typ obiektu jest zaznaczony w oknie wtyczki @returns: 1 - działka ewidencyjna 2 - obręb ewidencyjny 3 - gmina 4 - powiat 5 - województwo 0 - niezdefiniowany """ dlg = self.dlg if dlg.rdb_dz.isChecked(): return 1 elif dlg.rdb_ob.isChecked(): return 2 elif dlg.rdb_gm.isChecked(): return 3 elif dlg.rdb_pw.isChecked(): return 4 elif dlg.rdb_wo.isChecked(): return 5 else: return 0
def __init__(self): QMainWindow.__init__(self) logger.debug("Initialising GUI ...") self.setObjectName("GuiMain") self.mainConf = nw.CONFIG self.threadPool = QThreadPool() # System Info # =========== logger.info("OS: %s" % self.mainConf.osType) logger.info("Kernel: %s" % self.mainConf.kernelVer) logger.info("Host: %s" % self.mainConf.hostName) logger.info("Qt5 Version: %s (%d)" % ( self.mainConf.verQtString, self.mainConf.verQtValue) ) logger.info("PyQt5 Version: %s (%d)" % ( self.mainConf.verPyQtString, self.mainConf.verPyQtValue) ) logger.info("Python Version: %s (0x%x)" % ( self.mainConf.verPyString, self.mainConf.verPyHexVal) ) # Core Classes # ============ # Core Classes and Settings self.theTheme = GuiTheme(self) self.theProject = NWProject(self) self.theIndex = NWIndex(self.theProject, self) self.hasProject = False self.isFocusMode = False # Prepare Main Window self.resize(*self.mainConf.getWinSize()) self._updateWindowTitle() self.setWindowIcon(QIcon(self.mainConf.appIcon)) # Build the GUI # ============= # Main GUI Elements self.statusBar = GuiMainStatus(self) self.treeView = GuiProjectTree(self) self.docEditor = GuiDocEditor(self) self.viewMeta = GuiDocViewDetails(self) self.docViewer = GuiDocViewer(self) self.treeMeta = GuiItemDetails(self) self.projView = GuiOutline(self) self.projMeta = GuiOutlineDetails(self) self.mainMenu = GuiMainMenu(self) # Minor Gui Elements self.statusIcons = [] self.importIcons = [] # Project Tree View self.treePane = QWidget() self.treeBox = QVBoxLayout() self.treeBox.setContentsMargins(0, 0, 0, 0) self.treeBox.addWidget(self.treeView) self.treeBox.addWidget(self.treeMeta) self.treePane.setLayout(self.treeBox) # Splitter : Document Viewer / Document Meta self.splitView = QSplitter(Qt.Vertical) self.splitView.addWidget(self.docViewer) self.splitView.addWidget(self.viewMeta) self.splitView.setSizes(self.mainConf.getViewPanePos()) # Splitter : Document Editor / Document Viewer self.splitDocs = QSplitter(Qt.Horizontal) self.splitDocs.addWidget(self.docEditor) self.splitDocs.addWidget(self.splitView) # Splitter : Project Outlie / Outline Details self.splitOutline = QSplitter(Qt.Vertical) self.splitOutline.addWidget(self.projView) self.splitOutline.addWidget(self.projMeta) self.splitOutline.setSizes(self.mainConf.getOutlinePanePos()) # Main Tabs : Edirot / Outline self.tabWidget = QTabWidget() self.tabWidget.setTabPosition(QTabWidget.East) self.tabWidget.setStyleSheet("QTabWidget::pane {border: 0;}") self.tabWidget.addTab(self.splitDocs, "Editor") self.tabWidget.addTab(self.splitOutline, "Outline") self.tabWidget.currentChanged.connect(self._mainTabChanged) # Splitter : Project Tree / Main Tabs xCM = self.mainConf.pxInt(4) self.splitMain = QSplitter(Qt.Horizontal) self.splitMain.setContentsMargins(xCM, xCM, xCM, xCM) self.splitMain.addWidget(self.treePane) self.splitMain.addWidget(self.tabWidget) self.splitMain.setSizes(self.mainConf.getMainPanePos()) # Indices of All Splitter Widgets self.idxTree = self.splitMain.indexOf(self.treePane) self.idxMain = self.splitMain.indexOf(self.tabWidget) self.idxEditor = self.splitDocs.indexOf(self.docEditor) self.idxViewer = self.splitDocs.indexOf(self.splitView) self.idxViewDoc = self.splitView.indexOf(self.docViewer) self.idxViewMeta = self.splitView.indexOf(self.viewMeta) self.idxTabEdit = self.tabWidget.indexOf(self.splitDocs) self.idxTabProj = self.tabWidget.indexOf(self.splitOutline) # Splitter Behaviour self.splitMain.setCollapsible(self.idxTree, False) self.splitMain.setCollapsible(self.idxMain, False) self.splitDocs.setCollapsible(self.idxEditor, False) self.splitDocs.setCollapsible(self.idxViewer, True) self.splitView.setCollapsible(self.idxViewDoc, False) self.splitView.setCollapsible(self.idxViewMeta, False) # Editor / Viewer Default State self.splitView.setVisible(False) self.docEditor.closeSearch() # Initialise the Project Tree self.treeView.itemSelectionChanged.connect(self._treeSingleClick) self.treeView.itemDoubleClicked.connect(self._treeDoubleClick) self.rebuildTree() # Set Main Window Elements self.setMenuBar(self.mainMenu) self.setCentralWidget(self.splitMain) self.setStatusBar(self.statusBar) # Finalise Initialisation # ======================= # Set Up Auto-Save Project Timer self.asProjTimer = QTimer() self.asProjTimer.timeout.connect(self._autoSaveProject) # Set Up Auto-Save Document Timer self.asDocTimer = QTimer() self.asDocTimer.timeout.connect(self._autoSaveDocument) # Shortcuts and Actions self._connectMenuActions() keyReturn = QShortcut(self.treeView) keyReturn.setKey(QKeySequence(Qt.Key_Return)) keyReturn.activated.connect(self._treeKeyPressReturn) keyEscape = QShortcut(self) keyEscape.setKey(QKeySequence(Qt.Key_Escape)) keyEscape.activated.connect(self._keyPressEscape) # Forward Functions self.setStatus = self.statusBar.setStatus self.setProjectStatus = self.statusBar.setProjectStatus # Force a show of the GUI self.show() # Check that config loaded fine self.reportConfErr() # Initialise Main GUI self.initMain() self.asProjTimer.start() self.asDocTimer.start() self.statusBar.clearStatus() # Handle Windows Mode self.showNormal() if self.mainConf.isFullScreen: self.toggleFullScreenMode() logger.debug("GUI initialisation complete") # Check if a project path was provided at command line, and if # not, open the project manager instead. if self.mainConf.cmdOpen is not None: logger.debug("Opening project from additional command line option") self.openProject(self.mainConf.cmdOpen) else: if self.mainConf.showGUI: self.showProjectLoadDialog() # Show the latest release notes, if they haven't been shown before if hexToInt(self.mainConf.lastNotes) < hexToInt(nw.__hexversion__): if self.mainConf.showGUI: self.showAboutNWDialog(showNotes=True) self.mainConf.lastNotes = nw.__hexversion__ logger.debug("novelWriter is ready ...") self.setStatus("novelWriter is ready ...") return
def __init__(self, theParent): QDialog.__init__(self, theParent) logger.debug("Initialising GuiProjectLoad ...") self.setObjectName("GuiProjectLoad") self.mainConf = nw.CONFIG self.theParent = theParent self.theTheme = theParent.theTheme self.openState = self.NONE_STATE self.openPath = None sPx = self.mainConf.pxInt(16) nPx = self.mainConf.pxInt(96) iPx = self.theTheme.baseIconSize self.outerBox = QVBoxLayout() self.innerBox = QHBoxLayout() self.outerBox.setSpacing(sPx) self.innerBox.setSpacing(sPx) self.setWindowTitle(self.tr("Open Project")) self.setMinimumWidth(self.mainConf.pxInt(650)) self.setMinimumHeight(self.mainConf.pxInt(400)) self.setModal(True) self.nwIcon = QLabel() self.nwIcon.setPixmap(self.theParent.theTheme.getPixmap("novelwriter", (nPx, nPx))) self.innerBox.addWidget(self.nwIcon, 0, Qt.AlignTop) self.projectForm = QGridLayout() self.projectForm.setContentsMargins(0, 0, 0, 0) self.listBox = QTreeWidget() self.listBox.setSelectionMode(QAbstractItemView.SingleSelection) self.listBox.setDragDropMode(QAbstractItemView.NoDragDrop) self.listBox.setColumnCount(3) self.listBox.setHeaderLabels([ self.tr("Working Title"), self.tr("Words"), self.tr("Last Opened"), ]) self.listBox.setRootIsDecorated(False) self.listBox.itemSelectionChanged.connect(self._doSelectRecent) self.listBox.itemDoubleClicked.connect(self._doOpenRecent) self.listBox.setIconSize(QSize(iPx, iPx)) treeHead = self.listBox.headerItem() treeHead.setTextAlignment(self.C_COUNT, Qt.AlignRight) treeHead.setTextAlignment(self.C_TIME, Qt.AlignRight) self.lblRecent = QLabel("<b>%s</b>" % self.tr("Recently Opened Projects")) self.lblPath = QLabel("<b>%s</b>" % self.tr("Path")) self.selPath = QLineEdit("") self.selPath.setReadOnly(True) self.browseButton = QPushButton("...") self.browseButton.setMaximumWidth(int(2.5*self.theTheme.getTextWidth("..."))) self.browseButton.clicked.connect(self._doBrowse) self.projectForm.addWidget(self.lblRecent, 0, 0, 1, 3) self.projectForm.addWidget(self.listBox, 1, 0, 1, 3) self.projectForm.addWidget(self.lblPath, 2, 0, 1, 1) self.projectForm.addWidget(self.selPath, 2, 1, 1, 1) self.projectForm.addWidget(self.browseButton, 2, 2, 1, 1) self.projectForm.setColumnStretch(0, 0) self.projectForm.setColumnStretch(1, 1) self.projectForm.setColumnStretch(2, 0) self.projectForm.setVerticalSpacing(self.mainConf.pxInt(4)) self.projectForm.setHorizontalSpacing(self.mainConf.pxInt(8)) self.innerBox.addLayout(self.projectForm) self.buttonBox = QDialogButtonBox(QDialogButtonBox.Open | QDialogButtonBox.Cancel) self.buttonBox.accepted.connect(self._doOpenRecent) self.buttonBox.rejected.connect(self._doCancel) self.newButton = self.buttonBox.addButton(self.tr("New"), QDialogButtonBox.ActionRole) self.newButton.clicked.connect(self._doNewProject) self.delButton = self.buttonBox.addButton(self.tr("Remove"), QDialogButtonBox.ActionRole) self.delButton.clicked.connect(self._doDeleteRecent) self.outerBox.addLayout(self.innerBox) self.outerBox.addWidget(self.buttonBox) self.setLayout(self.outerBox) self._populateList() self._doSelectRecent() keyDelete = QShortcut(self.listBox) keyDelete.setKey(QKeySequence(Qt.Key_Delete)) keyDelete.activated.connect(self._doDeleteRecent) logger.debug("GuiProjectLoad initialisation complete") return
class Lookup(QWidget): MODEL_CLASS = None def __init__(self, parent, model): QWidget.__init__(self, parent, Qt.Window) self.model = model self.model.view = self self._setupUi() self.searchEdit.searchChanged.connect(self.searchChanged) self.searchEdit.returnPressed.connect(self.returnPressed) self.namesList.currentRowChanged.connect(self.currentRowChanged) self.namesList.itemDoubleClicked.connect(self.itemDoubleClicked) self._shortcutUp.activated.connect(self.upPressed) self._shortcutDown.activated.connect(self.downPressed) def _setupUi(self): self.setWindowTitle(tr("Lookup")) self.resize(314, 331) self.verticalLayout = QVBoxLayout(self) self.searchEdit = SearchEdit(self) self.verticalLayout.addWidget(self.searchEdit) self.namesList = QListWidget(self) self.namesList.setEditTriggers(QAbstractItemView.NoEditTriggers) self.namesList.setSelectionBehavior(QAbstractItemView.SelectRows) self.namesList.setUniformItemSizes(True) self.namesList.setSelectionRectVisible(True) self.verticalLayout.addWidget(self.namesList) self.searchEdit.immediate = True self._shortcutUp = QShortcut(self.searchEdit) self._shortcutUp.setKey(QKeySequence(Qt.Key_Up)) self._shortcutUp.setContext(Qt.WidgetShortcut) self._shortcutDown = QShortcut(self.searchEdit) self._shortcutDown.setKey(QKeySequence(Qt.Key_Down)) self._shortcutDown.setContext(Qt.WidgetShortcut) def _restoreSelection(self): self.namesList.setCurrentRow(self.model.selected_index) # --- Event Handlers def returnPressed(self): self.model.go() def searchChanged(self): self.model.search_query = str(self.searchEdit.text()) def currentRowChanged(self, row): if row >= 0: self.model.selected_index = row def itemDoubleClicked(self, item): self.model.go() def upPressed(self): if self.namesList.currentRow() > 0: self.namesList.setCurrentRow(self.namesList.currentRow() - 1) def downPressed(self): if self.namesList.currentRow() < self.namesList.count() - 1: self.namesList.setCurrentRow(self.namesList.currentRow() + 1) # --- model --> view def refresh(self): self.namesList.clear() self.namesList.addItems(self.model.names) self._restoreSelection() self.searchEdit.setText(self.model.search_query) def show(self): QWidget.show(self) self.searchEdit.setFocus() # see csv_options self.raise_() def hide(self): QWidget.hide(self)
class _s_Actions(QObject): """This class is like the Sauron's Ring: One ring to rule them all, One ring to find them, One ring to bring them all and in the darkness bind them. This Class knows all the containers, and its know by all the containers, but the containers don't need to know between each other, in this way we can keep a better api without the need to tie the behaviour between the widgets, and let them just consume the 'actions' they need.""" fileExecuted = pyqtSignal(str) projectExecuted = pyqtSignal(str) def __init__(self): super(_s_Actions, self).__init__() #Definition Locator self._locator = locator.Locator() self.__codeBack = [] self.__codeForward = [] self.__bookmarksFile = '' self.__bookmarksPos = -1 self.__breakpointsFile = '' self.__breakpointsPos = -1 self.__operations = { 0: self._navigate_code_jumps, 1: self._navigate_bookmarks, 2: self._navigate_breakpoints} def install_shortcuts(self, ide): """Install the shortcuts to the IDE.""" self.ide = ide short = resources.get_shortcut self.shortChangeTab = QShortcut(short("Change-Tab"), self.ide) self.shortChangeTabReverse = QShortcut( short("Change-Tab-Reverse"), self.ide) self.shortMoveTabToRight = QShortcut( short("Move-Tab-to-right"), self.ide) self.shortMoveTabToLeft = QShortcut( short("Move-Tab-to-left"), self.ide) self.shortDuplicate = QShortcut(short("Duplicate"), self.ide) self.shortRemove = QShortcut(short("Remove-line"), self.ide) self.shortMoveUp = QShortcut(short("Move-up"), self.ide) self.shortMoveDown = QShortcut(short("Move-down"), self.ide) self.shortCloseTab = QShortcut(short("Close-tab"), self.ide) self.shortNew = QShortcut(short("New-file"), self.ide) self.shortNewProject = QShortcut(short("New-project"), self.ide) self.shortOpen = QShortcut(short("Open-file"), self.ide) self.shortOpenProject = QShortcut(short("Open-project"), self.ide) self.shortSave = QShortcut(short("Save-file"), self.ide) self.shortSaveProject = QShortcut(short("Save-project"), self.ide) self.shortPrint = QShortcut(short("Print-file"), self.ide) self.shortRedo = QShortcut(short("Redo"), self.ide) self.shortAddBookmark = QShortcut(short("Add-Bookmark-or-Breakpoint"), self.ide) self.shortComment = QShortcut(short("Comment"), self.ide) self.shortUncomment = QShortcut(short("Uncomment"), self.ide) self.shortHorizontalLine = QShortcut(short("Horizontal-line"), self.ide) self.shortTitleComment = QShortcut(short("Title-comment"), self.ide) self.shortIndentLess = QShortcut(short("Indent-less"), self.ide) self.shortHideMisc = QShortcut(short("Hide-misc"), self.ide) self.shortHideEditor = QShortcut(short("Hide-editor"), self.ide) self.shortHideExplorer = QShortcut(short("Hide-explorer"), self.ide) self.shortRunFile = QShortcut(short("Run-file"), self.ide) self.shortRunProject = QShortcut(short("Run-project"), self.ide) self.shortSwitchFocus = QShortcut(short("Switch-Focus"), self.ide) self.shortStopExecution = QShortcut(short("Stop-execution"), self.ide) self.shortHideAll = QShortcut(short("Hide-all"), self.ide) self.shortFullscreen = QShortcut(short("Full-screen"), self.ide) self.shortFind = QShortcut(short("Find"), self.ide) self.shortFindNext = QShortcut(short("Find-next"), self.ide) self.shortFindPrevious = QShortcut(short("Find-previous"), self.ide) self.shortFindReplace = QShortcut(short("Find-replace"), self.ide) self.shortFindWithWord = QShortcut(short("Find-with-word"), self.ide) self.shortHelp = QShortcut(short("Help"), self.ide) self.shortSplitHorizontal = QShortcut(short("Split-horizontal"), self.ide) self.shortSplitVertical = QShortcut(short("Split-vertical"), self.ide) self.shortFollowMode = QShortcut(short("Follow-mode"), self.ide) self.shortReloadFile = QShortcut(short("Reload-file"), self.ide) self.shortFindInFiles = QShortcut(short("Find-in-files"), self.ide) self.shortImport = QShortcut(short("Import"), self.ide) self.shortGoToDefinition = QShortcut(short("Go-to-definition"), self.ide) self.shortCompleteDeclarations = QShortcut( short("Complete-Declarations"), self.ide) self.shortCodeLocator = QShortcut(short("Code-locator"), self.ide) self.shortFileOpener = QShortcut(short("File-Opener"), self.ide) self.shortNavigateBack = QShortcut(short("Navigate-back"), self.ide) self.shortNavigateForward = QShortcut(short("Navigate-forward"), self.ide) self.shortOpenLastTabOpened = QShortcut(short("Open-recent-closed"), self.ide) self.shortShowCodeNav = QShortcut(short("Show-Code-Nav"), self.ide) self.shortShowPasteHistory = QShortcut(short("Show-Paste-History"), self.ide) self.shortPasteHistory = QShortcut(short("History-Paste"), self.ide) self.shortCopyHistory = QShortcut(short("History-Copy"), self.ide) self.shortHighlightWord = QShortcut(short("Highlight-Word"), self.ide) self.shortChangeSplitFocus = QShortcut(short("change-split-focus"), self.ide) self.shortMoveTabSplit = QShortcut(short("move-tab-to-next-split"), self.ide) self.shortChangeTabVisibility = QShortcut( short("change-tab-visibility"), self.ide) #Connect Shortcuts Signals self.shortNavigateBack.activated.connect(lambda: self.__navigate_with_keyboard(False)) self.shortNavigateForward.activated.connect(lambda: self.__navigate_with_keyboard(True)) self.shortCodeLocator.activated.connect(self.ide.status.show_locator) self.shortFileOpener.activated.connect(self.ide.status.show_file_opener) self.shortGoToDefinition.activated.connect(self.editor_go_to_definition) self.shortCompleteDeclarations.activated.connect(self.editor_complete_declaration) self.shortRedo.activated.connect(self.editor_redo) self.shortHorizontalLine.activated.connect(self.editor_insert_horizontal_line) self.shortTitleComment.activated.connect(self.editor_insert_title_comment) self.shortFollowMode.activated.connect(self.ide.mainContainer.show_follow_mode) self.shortReloadFile.activated.connect(self.ide.mainContainer.reload_file) self.shortSplitHorizontal.activated.connect(lambda: self.ide.mainContainer.split_tab(True)) self.shortSplitVertical.activated.connect(lambda: self.ide.mainContainer.split_tab(False)) self.shortNew.activated.connect(self.ide.mainContainer.add_editor) self.shortNewProject.activated.connect(self.ide.explorer.create_new_project) self.shortHideMisc.activated.connect(self.view_misc_visibility) self.shortHideEditor.activated.connect(self.view_main_visibility) self.shortHideExplorer.activated.connect(self.view_explorer_visibility) self.shortHideAll.activated.connect(self.hide_all) self.shortFullscreen.activated.connect(self.fullscreen_mode) self.shortOpen.activated.connect(self.ide.mainContainer.open_file) self.shortOpenProject.activated.connect(self.open_project) self.shortCloseTab.activated.connect(self.ide.mainContainer.close_tab) self.shortSave.activated.connect(self.ide.mainContainer.save_file) self.shortSaveProject.activated.connect(self.save_project) self.shortPrint.activated.connect(self.print_file) self.shortFind.activated.connect(self.ide.status.show) self.shortFindPrevious.activated.connect(self.ide.status._searchWidget.find_previous) self.shortFindNext.activated.connect(self.ide.status._searchWidget.find_next) self.shortFindWithWord.activated.connect(self.ide.status.show_with_word) self.shortFindReplace.activated.connect(self.ide.status.show_replace) self.shortRunFile.activated.connect(self.execute_file) self.shortRunProject.activated.connect(self.execute_project) self.shortSwitchFocus.activated.connect(self.switch_focus) self.shortStopExecution.activated.connect(self.kill_execution) self.shortIndentLess.activated.connect(self.editor_indent_less) self.shortComment.activated.connect(self.editor_comment) self.shortUncomment.activated.connect(self.editor_uncomment) self.shortHelp.activated.connect(self.ide.mainContainer.show_python_doc) self.shortImport.activated.connect(self.import_from_everywhere) self.shortFindInFiles.activated.connect(self.ide.misc.show_find_in_files_widget) self.shortMoveUp.activated.connect(self.editor_move_up) self.shortMoveDown.activated.connect(self.editor_move_down) self.shortRemove.activated.connect(self.editor_remove_line) self.shortDuplicate.activated.connect(self.editor_duplicate) self.shortOpenLastTabOpened.activated.connect(self.reopen_last_tab) self.shortChangeTab.activated.connect(self.ide.mainContainer.change_tab) self.shortChangeTabReverse.activated.connect(self.ide.mainContainer.change_tab_reverse) self.shortMoveTabToRight.activated.connect(self.move_tab) self.shortMoveTabToLeft.activated.connect(lambda: self.move_tab(next=False)) self.shortShowCodeNav.activated.connect(self.ide.mainContainer.show_navigation_buttons) self.shortAddBookmark.activated.connect(self._add_bookmark_breakpoint) self.shortShowPasteHistory.activated.connect(self.ide.central.lateralPanel.combo.showPopup) self.shortCopyHistory.activated.connect(self._copy_history) self.shortPasteHistory.activated.connect(self._paste_history) self.shortHighlightWord.activated.connect(self.editor_highlight_word) self.shortChangeSplitFocus.activated.connect(self.ide.mainContainer.change_split_focus) self.shortMoveTabSplit.activated.connect(self.move_tab_to_next_split) self.shortChangeTabVisibility.activated.connect(self.ide.mainContainer.change_tabs_visibility) key = Qt.Key_1 for i in range(10): if sys.platform == "darwin": short = TabShortcuts( QKeySequence(Qt.CTRL + Qt.ALT + key), self.ide, i) else: short = TabShortcuts(QKeySequence(Qt.ALT + key), self.ide, i) key += 1 short.activated.connect(self._change_tab_index) short = TabShortcuts(QKeySequence(Qt.ALT + Qt.Key_0), self.ide, 10) short.activated.connect(self._change_tab_index) #Connect SIGNALs from other objects self.ide.mainContainer._tabMain.runFile.connect(self.execute_file) self.ide.mainContainer._tabSecondary.runFile.connect(self.execute_file) self.ide.mainContainer._tabMain.addToProject[str].connect(self._add_file_to_project) self.ide.mainContainer._tabSecondary.addToProject[str].connect(self._add_file_to_project) self.ide.mainContainer.openProject[str].connect(self.open_project) # Not Configurable Shortcuts self._shortEscStatus = QShortcut(QKeySequence(Qt.Key_Escape), self.ide.status) self._shortEscMisc = QShortcut(QKeySequence(Qt.Key_Escape), self.ide.misc) self._shortEscStatus.activated.connect(self.ide.status.hide_status) self._shortEscMisc.activated.connect(self.ide.misc.hide) def update_shortcuts(self): """If the user update the key binded to any shortcut, update them.""" resources.load_shortcuts() short = resources.get_shortcut self.shortDuplicate.setKey(short("Duplicate")) self.shortRemove.setKey(short("Remove-line")) self.shortMoveUp.setKey(short("Move-up")) self.shortMoveDown.setKey(short("Move-down")) self.shortCloseTab.setKey(short("Close-tab")) self.shortNew.setKey(short("New-file")) self.shortNewProject.setKey(short("New-project")) self.shortOpen.setKey(short("Open-file")) self.shortOpenProject.setKey(short("Open-project")) self.shortSave.setKey(short("Save-file")) self.shortSaveProject.setKey(short("Save-project")) self.shortPrint.setKey(short("Print-file")) self.shortRedo.setKey(short("Redo")) self.shortComment.setKey(short("Comment")) self.shortUncomment.setKey(short("Uncomment")) self.shortHorizontalLine.setKey(short("Horizontal-line")) self.shortTitleComment.setKey(short("Title-comment")) self.shortIndentLess.setKey(short("Indent-less")) self.shortHideMisc.setKey(short("Hide-misc")) self.shortHideEditor.setKey(short("Hide-editor")) self.shortHideExplorer.setKey(short("Hide-explorer")) self.shortRunFile.setKey(short("Run-file")) self.shortRunProject.setKey(short("Run-project")) self.shortSwitchFocus.setKey(short("Switch-Focus")) self.shortStopExecution.setKey(short("Stop-execution")) self.shortHideAll.setKey(short("Hide-all")) self.shortFullscreen.setKey(short("Full-screen")) self.shortFind.setKey(short("Find")) self.shortFindNext.setKey(short("Find-next")) self.shortFindPrevious.setKey(short("Find-previous")) self.shortFindReplace.setKey(short("Find-replace")) self.shortFindWithWord.setKey(short("Find-with-word")) self.shortHelp.setKey(short("Help")) self.shortSplitHorizontal.setKey(short("Split-horizontal")) self.shortSplitVertical.setKey(short("Split-vertical")) self.shortFollowMode.setKey(short("Follow-mode")) self.shortReloadFile.setKey(short("Reload-file")) self.shortFindInFiles.setKey(short("Find-in-files")) self.shortImport.setKey(short("Import")) self.shortGoToDefinition.setKey(short("Go-to-definition")) self.shortCompleteDeclarations.setKey(short("Complete-Declarations")) self.shortCodeLocator.setKey(short("Code-locator")) self.shortFileOpener.setKey(short("File-Opener")) self.shortNavigateBack.setKey(short("Navigate-back")) self.shortNavigateForward.setKey(short("Navigate-forward")) self.shortOpenLastTabOpened.setKey(short("Open-recent-closed")) self.shortChangeTab.setKey(short("Change-Tab")) self.shortChangeTabReverse.setKey(short("Change-Tab-Reverse")) self.shortMoveTabToRight.setKey(short("Move-Tab-to-right")) self.shortMoveTabToLeft.setKey(short("Move-Tab-to-left")) self.shortAddBookmark.setKey(short("Add-Bookmark-or-Breakpoint")) self.shortShowCodeNav.setKey(short("Show-Code-Nav")) self.shortShowPasteHistory.setKey(short("Show-Paste-History")) self.shortPasteHistory.setKey(short("History-Paste")) self.shortCopyHistory.setKey(short("History-Copy")) self.shortHighlightWord.setKey(short("Highlight-Word")) self.shortChangeSplitFocus.setKey(short("change-split-focus")) self.shortMoveTabSplit.setKey(short("move-tab-to-next-split")) self.shortChangeTabVisibility.setKey(short("change-tab-visibility")) def move_tab_to_next_split(self): self.ide.mainContainer.move_tab_to_next_split( self.ide.mainContainer.actualTab) def switch_focus(self): widget = QApplication.focusWidget() if widget: if widget in (self.ide.mainContainer.actualTab, self.ide.mainContainer.actualTab.currentWidget()): self.ide.explorer.currentWidget().setFocus() elif widget in (self.ide.explorer, self.ide.explorer.currentWidget()): if self.ide.misc.isVisible(): self.ide.misc.stack.currentWidget().setFocus() else: self.ide.mainContainer.actualTab.currentWidget().setFocus() elif widget.parent() is self.ide.misc.stack: self.ide.mainContainer.actualTab.currentWidget().setFocus() def _change_tab_index(self): editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): container = self.ide.mainContainer.actualTab else: container = self.ide.explorer obj = self.sender() if obj.index < container.count(): container.setCurrentIndex(obj.index) def _copy_history(self): """Copy the selected text into the copy/paste history.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): cursor = editorWidget.textCursor() copy = cursor.selectedText() self.ide.central.lateralPanel.add_new_copy(copy) def _paste_history(self): """Paste the text from the copy/paste history.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): cursor = editorWidget.textCursor() paste = self.ide.central.lateralPanel.get_paste() cursor.insertText(paste) def _add_bookmark_breakpoint(self): """Add a bookmark or breakpoint to the current file in the editor.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): if self.ide.mainContainer.actualTab.navigator.operation == 1: editorWidget._sidebarWidget.set_bookmark( editorWidget.textCursor().blockNumber()) elif self.ide.mainContainer.actualTab.navigator.operation == 2: editorWidget._sidebarWidget.set_breakpoint( editorWidget.textCursor().blockNumber()) def __navigate_with_keyboard(self, val): """Navigate between the positions in the jump history stack.""" op = self.ide.mainContainer._tabMain.navigator.operation self.navigate_code_history(val, op) def _add_file_to_project(self, path): """Add the file for 'path' in the project the user choose here.""" pathProject = [self.ide.explorer.get_actual_project()] addToProject = ui_tools.AddToProject(pathProject, self.ide) addToProject.exec_() if not addToProject.pathSelected: return editorWidget = self.ide.mainContainer.get_actual_editor() if not editorWidget.ID: name = QInputDialog.getText(None, _translate("_s_Actions", "Add File To Project"), _translate("_s_Actions", "File Name:"))[0] if not name: QMessageBox.information(None, _translate("_s_Actions", "Invalid Name"), _translate("_s_Actions", "The file name is empty, please enter a name")) return else: name = file_manager.get_basename(editorWidget.ID) path = file_manager.create_path(addToProject.pathSelected, name) try: path = file_manager.store_file_content( path, editorWidget.get_text(), newFile=True) self.ide.mainContainer._file_watcher.allow_kill = False if path != editorWidget.ID: self.ide.mainContainer.remove_standalone_watcher( editorWidget.ID) editorWidget.ID = path self.ide.mainContainer.add_standalone_watcher(path) self.ide.mainContainer._file_watcher.allow_kill = True self.ide.explorer.add_existing_file(path) self.ide.change_window_title(path) name = file_manager.get_basename(path) self.ide.mainContainer.actualTab.setTabText( self.ide.mainContainer.actualTab.currentIndex(), name) editorWidget._file_saved() except file_manager.NinjaFileExistsException as ex: QMessageBox.information(None, _translate("_s_Actions", "File Already Exists"), (_translate("_s_Actions", "Invalid Path: the file '%s' already exists.") % ex.filename)) def add_project_to_console(self, projectFolder): """Add the namespace of the project received into the ninja-console.""" self.ide.misc._console.load_project_into_console(projectFolder) def remove_project_from_console(self, projectFolder): """Remove the namespace of the project received from the console.""" self.ide.misc._console.unload_project_from_console(projectFolder) def import_from_everywhere(self): """Show the dialog to insert an import from any place in the editor.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget: text = editorWidget.get_text() froms = re.findall('^from (.*)', text, re.MULTILINE) fromSection = list(set([f.split(' import')[0] for f in froms])) dialog = from_import_dialog.FromImportDialog(fromSection, editorWidget, self.ide) dialog.show() def open_project(self, path=''): """Open a Project and load the symbols in the Code Locator.""" self.ide.explorer.open_project_folder(path) def open_project_properties(self): """Open a Project and load the symbols in the Code Locator.""" self.ide.explorer.open_project_properties() def create_profile(self): """Create a profile binding files and projects to a key.""" profileInfo = QInputDialog.getText(None, _translate("_s_Actions", "Create Profile"), _translate("_s_Actions", "The Current Files and Projects will " "be associated to this profile.\n" "Profile Name:")) if profileInfo[1]: profileName = profileInfo[0] if not profileName or profileName in settings.PROFILES: QMessageBox.information(None, _translate("_s_Actions", "Profile Name Invalid"), _translate("_s_Actions", "The Profile name is invalid or already exists.")) return self.save_profile(profileName) return profileName def save_profile(self, profileName): """Save the updates from a profile.""" projects_obj = self.ide.explorer.get_opened_projects() projects = [p.path for p in projects_obj] files = self.ide.mainContainer.get_opened_documents() files = files[0] + files[1] settings.PROFILES[profileName] = [files, projects] qsettings = QSettings(resources.SETTINGS_PATH, QSettings.IniFormat) qsettings.setValue('ide/profiles', settings.PROFILES) def activate_profile(self): """Show the Profile Manager dialog.""" profilesLoader = ui_tools.ProfilesLoader(self._load_profile_data, self.create_profile, self.save_profile, settings.PROFILES, self.ide) profilesLoader.show() def deactivate_profile(self): """Close the Profile Session.""" self.ide.Profile = None def _load_profile_data(self, key): """Activate the selected profile, closing the current files/projects""" self.ide.explorer.close_opened_projects() self.ide.mainContainer.open_files(settings.PROFILES[key][0]) self.ide.explorer.open_session_projects(settings.PROFILES[key][1]) def close_files_from_project(self, project): """Close the files related to this project.""" if project: tabMain = self.ide.mainContainer._tabMain for tabIndex in reversed(list(range(tabMain.count()))): if file_manager.belongs_to_folder( project, tabMain.widget(tabIndex).ID): tabMain.removeTab(tabIndex) tabSecondary = self.ide.mainContainer._tabSecondary for tabIndex in reversed(list(range(tabSecondary.count()))): if file_manager.belongs_to_folder( project, tabSecondary.widget(tabIndex).ID): tabSecondary.removeTab(tabIndex) self.ide.profile = None def count_file_code_lines(self): """Count the lines of code in the current file.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget: block_count = editorWidget.blockCount() blanks = re.findall('(^\n)|(^(\s+)?#)|(^( +)?($|\n))', editorWidget.get_text(), re.M) blanks_count = len(blanks) resume = _translate("_s_Actions", "Lines code: %s\n") % (block_count - blanks_count) resume += (_translate("_s_Actions", "Blanks and commented lines: %s\n\n") % blanks_count) resume += _translate("_s_Actions", "Total lines: %s") % block_count msgBox = QMessageBox(QMessageBox.Information, _translate("_s_Actions", "Summary of lines"), resume, QMessageBox.Ok, editorWidget) msgBox.exec_() def execute_file(self): """Execute the current file.""" editorWidget = self.ide.mainContainer.get_actual_editor() #emit a signal for plugin! if editorWidget: self.fileExecuted.emit(editorWidget.ID)# moved here. Reason: case editorWidget == None self.ide.mainContainer.save_file(editorWidget) ext = file_manager.get_file_extension(editorWidget.ID) #TODO: Remove the IF statment with polymorphism using Handler if ext == 'py': self.ide.misc.run_application(editorWidget.ID) elif ext == 'html': self.ide.misc.render_web_page(editorWidget.ID) def execute_project(self): """Execute the project marked as Main Project.""" mainFile = self.ide.explorer.get_project_main_file() if not mainFile and self.ide.explorer._treeProjects and \ self.ide.explorer._treeProjects._actualProject: self.ide.explorer._treeProjects.open_project_properties() elif mainFile: self.save_project() path = self.ide.explorer.get_actual_project() #emit a signal for plugin! self.projectExecuted.emit(path) # load our jutsus! project = json_manager.read_ninja_project(path) python_exec = project.get('venv', False) if not python_exec: python_exec = project.get('pythonPath', 'python') PYTHONPATH = project.get('PYTHONPATH', None) params = project.get('programParams', '') preExec = project.get('preExecScript', '') postExec = project.get('postExecScript', '') mainFile = file_manager.create_path(path, mainFile) self.ide.misc.run_application(mainFile, pythonPath=python_exec, PYTHONPATH=PYTHONPATH, programParams=params, preExec=preExec, postExec=postExec) def kill_execution(self): """Kill the execution of the current file or project.""" self.ide.misc.kill_application() def fullscreen_mode(self): """Change to fullscreen mode.""" if self.ide.isFullScreen(): self.ide.showMaximized() else: self.ide.showFullScreen() def editor_redo(self): """Execute the redo action in the current editor.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): editorWidget.redo() def editor_indent_less(self): """Indent 1 position to the left for the current line or selection.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): editorWidget.indent_less() def editor_indent_more(self): """Indent 1 position to the right for the current line or selection.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): editorWidget.indent_more() def editor_insert_debugging_prints(self): """Insert a print statement in each selected line.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget: helpers.insert_debugging_prints(editorWidget) def editor_insert_pdb(self): """Insert a pdb.set_trace() statement in tjhe current line.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget: helpers.insert_pdb(editorWidget) def editor_comment(self): """Mark the current line or selection as a comment.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): helpers.comment(editorWidget) def editor_uncomment(self): """Uncomment the current line or selection.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): helpers.uncomment(editorWidget) def editor_insert_horizontal_line(self): """Insert an horizontal lines of comment symbols.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): helpers.insert_horizontal_line(editorWidget) def editor_insert_title_comment(self): """Insert a Title surrounded by comment symbols.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): helpers.insert_title_comment(editorWidget) def editor_remove_trailing_spaces(self): """Remove the trailing spaces in the current editor.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget: helpers.remove_trailing_spaces(editorWidget) def editor_replace_tabs_with_spaces(self): """Replace the Tabs with Spaces in the current editor.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget: helpers.replace_tabs_with_spaces(editorWidget) def editor_move_up(self): """Move the current line or selection one position up.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): helpers.move_up(editorWidget) def editor_move_down(self): """Move the current line or selection one position down.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): helpers.move_down(editorWidget) def editor_remove_line(self): """Remove the current line or selection.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): helpers.remove_line(editorWidget) def editor_duplicate(self): """Duplicate the current line or selection.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): helpers.duplicate(editorWidget) def editor_go_to_definition(self): """Search the definition of the method or variable under the cursor. If more than one method or variable is found with the same name, shows a table with the results and let the user decide where to go.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): editorWidget.go_to_definition() def editor_highlight_word(self): """Highlight the occurrences of the current word in the editor.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): editorWidget.highlight_selected_word() def editor_complete_declaration(self): """Do the opposite action that Complete Declaration expect.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget and editorWidget.hasFocus(): editorWidget.complete_declaration() def editor_go_to_line(self, line): """Jump to the specified line in the current editor.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget: editorWidget.jump_to_line(line) def reset_editor_flags(self): """Reset the Flags for all the opened editors.""" self.ide.mainContainer.reset_editor_flags() def call_editors_function(self, call_function, *args, **kwargs): self.ide.mainContainer.call_editors_function( call_function, args, kwargs) def preview_in_browser(self): """Load the current html file in the default browser.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget: if not editorWidget.ID: self.ide.mainContainer.save_file() ext = file_manager.get_file_extension(editorWidget.ID) if ext == 'html': webbrowser.open(editorWidget.ID) def hide_all(self): """Hide/Show all the containers except the editor.""" if self.ide.menuBar().isVisible(): self.ide.central.lateralPanel.hide() self.ide.misc.hide() self.ide.toolbar.hide() self.ide.menuBar().hide() else: self.ide.central.lateralPanel.show() self.ide.toolbar.show() self.ide.menuBar().show() self.ide._menuView.hideAllAction.setChecked( self.ide.menuBar().isVisible()) self.ide._menuView.hideConsoleAction.setChecked( self.ide.central.misc.isVisible()) self.ide._menuView.hideEditorAction.setChecked( self.ide.central.mainContainer.isVisible()) self.ide._menuView.hideExplorerAction.setChecked( self.ide.central.lateralPanel.isVisible()) self.ide._menuView.hideToolbarAction.setChecked( self.ide.toolbar.isVisible()) def view_misc_visibility(self): self.ide.central.change_misc_visibility() self.ide._menuView.hideConsoleAction.setChecked( self.ide.central.misc.isVisible()) def view_main_visibility(self): self.ide.central.change_main_visibility() self.ide._menuView.hideEditorAction.setChecked( self.ide.central.mainContainer.isVisible()) def view_explorer_visibility(self): self.ide.central.change_explorer_visibility() self.ide._menuView.hideExplorerAction.setChecked( self.ide.central.lateralPanel.isVisible()) def save_project(self): """Save all the opened files that belongs to the actual project.""" path = self.ide.explorer.get_actual_project() if path: self.ide.mainContainer.save_project(path) def save_all(self): """Save all the opened files.""" self.ide.mainContainer.save_all() def print_file(self): """Call the print of ui_tool Call print of ui_tool depending on the focus of the application""" #TODO: Add funtionality for proyect tab and methods tab editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget is not None: fileName = "newDocument.pdf" if editorWidget.ID: fileName = file_manager.get_basename( editorWidget.ID) fileName = fileName[:fileName.rfind('.')] + '.pdf' ui_tools.print_file(fileName, editorWidget.print_) def locate_function(self, function, filePath, isVariable): """Move the cursor to the proper position in the navigate stack.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget: self.__codeBack.append((editorWidget.ID, editorWidget.textCursor().position())) self.__codeForward = [] self._locator.navigate_to(function, filePath, isVariable) def update_explorer(self): """Update the symbols in the Symbol Explorer when a file is saved.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget: ext = file_manager.get_file_extension(editorWidget.ID) #obtain a symbols handler for this file extension symbols_handler = settings.get_symbols_handler(ext) if symbols_handler: source = editorWidget.toPlainText() if editorWidget.encoding is not None: source = source.encode(editorWidget.encoding) if ext == 'py': args = (source, True) else: args = (source,) symbols = symbols_handler.obtain_symbols(*args) self.ide.explorer.update_symbols(symbols, editorWidget.ID) #TODO: Should we change the code below similar to the code above? exts = settings.SYNTAX.get('python')['extension'] if ext in exts or editorWidget.newDocument: self.ide.explorer.update_errors( editorWidget.errors, editorWidget.pep8) def update_migration_tips(self): """Update the migration tips in the Explorer.""" # This should be refactored with the new definition of singals in # the MainContainer editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget: self.ide.explorer.update_migration(editorWidget.migration) def navigate_code_history(self, val, op): """Navigate the code history.""" self.__operations[op](val) def _navigate_code_jumps(self, val): """Navigate between the jump points.""" node = None if not val and self.__codeBack: node = self.__codeBack.pop() editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget: self.__codeForward.append((editorWidget.ID, editorWidget.textCursor().position())) elif val and self.__codeForward: node = self.__codeForward.pop() editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget: self.__codeBack.append((editorWidget.ID, editorWidget.textCursor().position())) if node: self.ide.mainContainer.open_file(node[0], node[1]) def _navigate_breakpoints(self, val): """Navigate between the breakpoints.""" breakList = list(settings.BREAKPOINTS.keys()) breakList.sort() if not breakList: return if self.__breakpointsFile not in breakList: self.__breakpointsFile = breakList[0] index = breakList.index(self.__breakpointsFile) breaks = settings.BREAKPOINTS.get(self.__breakpointsFile, []) lineNumber = 0 #val == True: forward if val: if (len(breaks) - 1) > self.__breakpointsPos: self.__breakpointsPos += 1 lineNumber = breaks[self.__breakpointsPos] elif len(breaks) > 0: if index < (len(breakList) - 1): self.__breakpointsFile = breakList[index + 1] else: self.__breakpointsFile = breakList[0] self.__breakpointsPos = 0 breaks = settings.BREAKPOINTS[self.__breakpointsFile] lineNumber = breaks[0] else: if self.__breakpointsPos > 0: self.__breakpointsPos -= 1 lineNumber = breaks[self.__breakpointsPos] elif len(breaks) > 0: self.__breakpointsFile = breakList[index - 1] breaks = settings.BREAKPOINTS[self.__breakpointsFile] self.__breakpointsPos = len(breaks) - 1 lineNumber = breaks[self.__breakpointsPos] if file_manager.file_exists(self.__breakpointsFile): self.ide.mainContainer.open_file(self.__breakpointsFile, lineNumber, None, True) else: settings.BREAKPOINTS.pop(self.__breakpointsFile) def _navigate_bookmarks(self, val): """Navigate between the bookmarks.""" bookList = list(settings.BOOKMARKS.keys()) bookList.sort() if not bookList: return if self.__bookmarksFile not in bookList: self.__bookmarksFile = bookList[0] index = bookList.index(self.__bookmarksFile) bookms = settings.BOOKMARKS.get(self.__bookmarksFile, []) lineNumber = 0 #val == True: forward if val: if (len(bookms) - 1) > self.__bookmarksPos: self.__bookmarksPos += 1 lineNumber = bookms[self.__bookmarksPos] elif len(bookms) > 0: if index < (len(bookList) - 1): self.__bookmarksFile = bookList[index + 1] else: self.__bookmarksFile = bookList[0] self.__bookmarksPos = 0 bookms = settings.BOOKMARKS[self.__bookmarksFile] lineNumber = bookms[0] else: if self.__bookmarksPos > 0: self.__bookmarksPos -= 1 lineNumber = bookms[self.__bookmarksPos] elif len(bookms) > 0: self.__bookmarksFile = bookList[index - 1] bookms = settings.BOOKMARKS[self.__bookmarksFile] self.__bookmarksPos = len(bookms) - 1 lineNumber = bookms[self.__bookmarksPos] if file_manager.file_exists(self.__bookmarksFile): self.ide.mainContainer.open_file(self.__bookmarksFile, lineNumber, None, True) else: settings.BOOKMARKS.pop(self.__bookmarksFile) def add_back_item_navigation(self): """Add an item to the back stack and reset the forward stack.""" editorWidget = self.ide.mainContainer.get_actual_editor() if editorWidget: self.__codeBack.append((editorWidget.ID, editorWidget.textCursor().position())) self.__codeForward = [] def group_tabs_together(self): """Group files that belongs to the same project together.""" if self.ide.explorer._treeProjects is None: return projects_obj = self.ide.explorer.get_opened_projects() projects = [p.path for p in projects_obj] for project in projects: projectName = self.ide.explorer.get_project_name(project) if not projectName: projectName = file_manager.get_basename(project) tabGroup = tab_group.TabGroup(project, projectName, self) for index in reversed(list(range( self.ide.mainContainer._tabMain.count()))): widget = self.ide.mainContainer._tabMain.widget(index) if type(widget) is editor.Editor and \ file_manager.belongs_to_folder(project, widget.ID): tabGroup.add_widget(widget) self.ide.mainContainer._tabMain.removeTab(index) if tabGroup.tabs: self.ide.mainContainer._tabMain.add_tab(tabGroup, projectName) def deactivate_tabs_groups(self): """Deactivate tab grouping based in the project they belong.""" for index in reversed(list(range( self.ide.mainContainer._tabMain.count()))): widget = self.ide.mainContainer._tabMain.widget(index) if type(widget) is tab_group.TabGroup: widget.only_expand() def reopen_last_tab(self): """Reopen the last closed tab.""" self.ide.mainContainer.actualTab._reopen_last_tab() def open_class_diagram(self): """Open the Class Diagram Generator.""" diagram = class_diagram.ClassDiagram(self) self.ide.mainContainer.add_tab(diagram, _translate("_s_Actions", "Class Diagram v.0.1")) def reload_toolbar(self): """Reload the Toolbar.""" self.ide.load_toolbar() def move_tab(self, next=True, widget=None): actualTab = self.ide.mainContainer.actualTab if widget is None: widget = actualTab.currentWidget() if widget is not None: old_widget_index = actualTab.indexOf(widget) if next and old_widget_index < actualTab.count() - 1: new_widget_index = old_widget_index + 1 elif old_widget_index > 0 and not next: new_widget_index = old_widget_index - 1 else: return tabName = actualTab.tabText(old_widget_index) actualTab.insertTab(new_widget_index, widget, tabName) actualTab.setCurrentIndex(new_widget_index)
def __init__(self, parent=None, choose=False): super(ShowPresets, self).__init__(parent) self.original_presets_file = utils.find_presets_file( config.presets_file_name, config.presets_lookup_dirs, config.presets_lookup_virtenv) self.current_presets_file = config.presets_file self.presQLW = QListWidget() labelQL = QLabel(self.tr('Preset label')) self.labelQLE = QLineEdit() self.labelQLE.setReadOnly(True) commandQL = QLabel(self.tr('Preset command line parameters')) self.commandQLE = QLineEdit() self.commandQLE.setReadOnly(True) extQL = QLabel(self.tr('Output file extension')) self.extQLE = QLineEdit() self.extQLE.setReadOnly(True) addQPB = QPushButton(self.tr('Add')) self.deleteQPB = QPushButton(self.tr('Delete')) self.delete_allQPB = QPushButton(self.tr('Delete all')) self.editQPB = QPushButton(self.tr('Edit')) searchQL = QLabel(self.tr('Search')) self.searchQLE = QLineEdit() okQPB = QPushButton(self.tr('OK')) okQPB.setDefault(True) spc1 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) spc2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) spc3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) grid = utils.add_to_grid([self.delete_allQPB, addQPB, spc1], [self.deleteQPB, self.editQPB, spc2]) hlayout = utils.add_to_layout('h', searchQL, self.searchQLE, None, okQPB) final_layout = utils.add_to_layout('v', self.presQLW, labelQL, self.labelQLE, commandQL, self.commandQLE, extQL, self.extQLE, grid, spc3, hlayout) self.setLayout(final_layout) okQPB.clicked.connect(self.accept) self.presQLW.currentRowChanged.connect(self.show_preset) addQPB.clicked.connect(self.add_preset) self.deleteQPB.clicked.connect(self.delete_preset) self.delete_allQPB.clicked.connect(self.delete_all_presets) self.editQPB.clicked.connect(self.edit_preset) self.searchQLE.textEdited.connect(self.search) if choose: self.presQLW.doubleClicked.connect(okQPB.click) del_shortcut = QShortcut(self) del_shortcut.setKey(Qt.Key_Delete) del_shortcut.activated.connect(self.delete_preset) self.resize(430, 480) self.setWindowTitle(self.tr('Edit Presets')) QTimer.singleShot(0, self.load_xml) QTimer.singleShot(0, self.fill_presQLW)
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.fnames = [] # list of file names to be converted self.office_listener_started = False self.parse_cla() addQPB = QPushButton(self.tr('Add')) delQPB = QPushButton(self.tr('Delete')) clearQPB = QPushButton(self.tr('Clear')) vlayout1 = utils.add_to_layout('v', addQPB, delQPB, clearQPB, None) self.filesList = utils.FilesList() self.filesList.setSelectionMode(QAbstractItemView.ExtendedSelection) hlayout1 = utils.add_to_layout('h', self.filesList, vlayout1) outputQL = QLabel(self.tr('Output folder:')) self.toQLE = QLineEdit() self.toQLE.setReadOnly(True) self.toQTB = QToolButton() self.toQTB.setText('...') hlayout2 = utils.add_to_layout('h', outputQL, self.toQLE, self.toQTB) self.audiovideo_tab = AudioVideoTab(self) self.image_tab = ImageTab(self) self.document_tab = DocumentTab(self) self.tabs = [self.audiovideo_tab, self.image_tab, self.document_tab] tab_names = [ self.tr('Audio/Video'), self.tr('Images'), self.tr('Documents') ] self.tabWidget = QTabWidget() for num, tab in enumerate(tab_names): self.tabWidget.addTab(self.tabs[num], tab) self.tabWidget.setCurrentIndex(0) self.origQCB = QCheckBox( self.tr('Save each file in the same\nfolder as input file')) self.deleteQCB = QCheckBox(self.tr('Delete original')) convertQPB = QPushButton(self.tr('&Convert')) hlayout3 = utils.add_to_layout('h', self.origQCB, self.deleteQCB, None) hlayout4 = utils.add_to_layout('h', None, convertQPB) final_layout = utils.add_to_layout('v', hlayout1, self.tabWidget, hlayout2, hlayout3, hlayout4) self.dependenciesQL = QLabel() self.statusBar().addPermanentWidget(self.dependenciesQL, stretch=1) widget = QWidget() widget.setLayout(final_layout) self.setCentralWidget(widget) openAction = utils.create_action(self, self.tr('Open'), QKeySequence.Open, None, self.tr('Open a file'), self.filesList_add) convertAction = utils.create_action(self, self.tr('Convert'), 'Ctrl+C', None, self.tr('Convert files'), self.start_conversion) quitAction = utils.create_action(self, self.tr('Quit'), 'Ctrl+Q', None, self.tr('Quit'), self.close) edit_presetsAction = utils.create_action(self, self.tr('Edit Presets'), 'Ctrl+P', None, self.tr('Edit Presets'), self.open_dialog_presets) importAction = utils.create_action(self, self.tr('Import'), None, None, self.tr('Import presets'), self.import_presets) exportAction = utils.create_action(self, self.tr('Export'), None, None, self.tr('Export presets'), self.export_presets) resetAction = utils.create_action(self, self.tr('Reset'), None, None, self.tr('Reset presets'), self.reset_presets) syncAction = utils.create_action(self, self.tr('Synchronize'), None, None, self.tr('Synchronize presets'), self.sync_presets) removeoldAction = utils.create_action(self, self.tr('Remove old'), None, None, self.tr('Remove old presets'), self.removeold_presets) clearallAction = utils.create_action(self, self.tr('Clear All'), None, None, self.tr('Clear form'), self.clear_all) preferencesAction = utils.create_action(self, self.tr('Preferences'), 'Alt+Ctrl+P', None, self.tr('Preferences'), self.open_dialog_preferences) trackerAction = utils.create_action( self, 'Issue tracker', None, None, None, lambda: webbrowser.open( "https://github.com/Ilias95/FF-Multi-Converter/issues")) wikiAction = utils.create_action( self, 'Wiki', None, None, None, lambda: webbrowser.open( "https://github.com/Ilias95/FF-Multi-Converter/wiki")) ffmpegdocAction = utils.create_action( self, 'FFmpeg ' + self.tr('documentation'), None, None, None, lambda: webbrowser.open("https://www.ffmpeg.org/documentation.html" )) imagemagickdocAction = utils.create_action( self, 'ImageMagick ' + self.tr('documentation'), None, None, None, lambda: webbrowser.open( "http://www.imagemagick.org/script/convert.php")) aboutAction = utils.create_action(self, self.tr('About'), 'Ctrl+?', None, self.tr('About'), self.open_dialog_about) fileMenu = self.menuBar().addMenu(self.tr('File')) editMenu = self.menuBar().addMenu(self.tr('Edit')) presetsMenu = self.menuBar().addMenu(self.tr('Presets')) helpMenu = self.menuBar().addMenu(self.tr('Help')) utils.add_actions(fileMenu, [openAction, convertAction, None, quitAction]) utils.add_actions(presetsMenu, [ edit_presetsAction, importAction, exportAction, resetAction, None, syncAction, removeoldAction ]) utils.add_actions(editMenu, [clearallAction, None, preferencesAction]) utils.add_actions(helpMenu, [ trackerAction, wikiAction, None, ffmpegdocAction, imagemagickdocAction, None, aboutAction ]) self.filesList.dropped.connect(self.filesList_add_dragged) addQPB.clicked.connect(self.filesList_add) delQPB.clicked.connect(self.filesList_delete) clearQPB.clicked.connect(self.filesList_clear) self.tabWidget.currentChanged.connect( lambda: self.tabs[0].moreQPB.setChecked(False)) self.origQCB.toggled.connect( lambda: self.toQLE.setEnabled(not self.origQCB.isChecked())) self.toQTB.clicked.connect(self.get_output_folder) convertQPB.clicked.connect(convertAction.triggered) del_shortcut = QShortcut(self) del_shortcut.setKey(Qt.Key_Delete) del_shortcut.activated.connect(self.filesList_delete) self.setWindowTitle('FF Multi Converter') self.load_settings() self.check_for_dependencies() self.audiovideo_tab.set_default_command() self.image_tab.set_default_command() self.toQLE.setText(self.default_output) self.filesList_update()
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.fnames = [] # list of file names to be converted self.office_listener_started = False self.parse_cla() addQPB = QPushButton(self.tr('Add')) delQPB = QPushButton(self.tr('Delete')) clearQPB = QPushButton(self.tr('Clear')) vlayout1 = utils.add_to_layout('v', addQPB, delQPB, clearQPB, None) self.filesList = utils.FilesList() self.filesList.setSelectionMode(QAbstractItemView.ExtendedSelection) hlayout1 = utils.add_to_layout('h', self.filesList, vlayout1) outputQL = QLabel(self.tr('Output folder:')) self.toQLE = QLineEdit() self.toQLE.setReadOnly(True) self.toQTB = QToolButton() self.toQTB.setText('...') hlayout2 = utils.add_to_layout('h', outputQL, self.toQLE, self.toQTB) self.audiovideo_tab = AudioVideoTab(self) self.image_tab = ImageTab(self) self.document_tab = DocumentTab(self) self.tabs = [self.audiovideo_tab, self.image_tab, self.document_tab] tab_names = [self.tr('Audio/Video'), self.tr('Images'), self.tr('Documents')] self.tabWidget = QTabWidget() for num, tab in enumerate(tab_names): self.tabWidget.addTab(self.tabs[num], tab) self.tabWidget.setCurrentIndex(0) self.origQCB = QCheckBox( self.tr('Save each file in the same\nfolder as input file')) self.deleteQCB = QCheckBox(self.tr('Delete original')) convertQPB = QPushButton(self.tr('&Convert')) hlayout3 = utils.add_to_layout('h', self.origQCB, self.deleteQCB, None) hlayout4 = utils.add_to_layout('h', None, convertQPB) final_layout = utils.add_to_layout( 'v', hlayout1, self.tabWidget, hlayout2, hlayout3, hlayout4) self.dependenciesQL = QLabel() self.statusBar().addPermanentWidget(self.dependenciesQL, stretch=1) widget = QWidget() widget.setLayout(final_layout) self.setCentralWidget(widget) openAction = utils.create_action( self, self.tr('Open'), QKeySequence.Open, None, self.tr('Open a file'), self.filesList_add ) convertAction = utils.create_action( self, self.tr('Convert'), 'Ctrl+C', None, self.tr('Convert files'), self.start_conversion ) quitAction = utils.create_action( self, self.tr('Quit'), 'Ctrl+Q', None, self.tr('Quit'), self.close ) edit_presetsAction = utils.create_action( self, self.tr('Edit Presets'), 'Ctrl+P', None, self.tr('Edit Presets'), self.open_dialog_presets ) importAction = utils.create_action( self, self.tr('Import'), None, None, self.tr('Import presets'), self.import_presets ) exportAction = utils.create_action( self, self.tr('Export'), None, None, self.tr('Export presets'), self.export_presets ) resetAction = utils.create_action( self, self.tr('Reset'), None, None, self.tr('Reset presets'), self.reset_presets ) syncAction = utils.create_action( self, self.tr('Synchronize'), None, None, self.tr('Synchronize presets'), self.sync_presets ) removeoldAction = utils.create_action( self, self.tr('Remove old'), None, None, self.tr('Remove old presets'), self.removeold_presets ) clearallAction = utils.create_action( self, self.tr('Clear All'), None, None, self.tr('Clear form'), self.clear_all ) preferencesAction = utils.create_action( self, self.tr('Preferences'), 'Alt+Ctrl+P', None, self.tr('Preferences'), self.open_dialog_preferences ) trackerAction = utils.create_action( self, 'Issue tracker', None, None, None, lambda: webbrowser.open( "https://github.com/Ilias95/FF-Multi-Converter/issues") ) wikiAction = utils.create_action( self, 'Wiki', None, None, None, lambda: webbrowser.open( "https://github.com/Ilias95/FF-Multi-Converter/wiki") ) ffmpegdocAction = utils.create_action( self, 'FFmpeg ' + self.tr('documentation'), None, None, None, lambda: webbrowser.open( "https://www.ffmpeg.org/documentation.html") ) imagemagickdocAction = utils.create_action( self, 'ImageMagick ' + self.tr('documentation'), None, None, None, lambda: webbrowser.open( "http://www.imagemagick.org/script/convert.php") ) aboutAction = utils.create_action( self, self.tr('About'), 'Ctrl+?', None, self.tr('About'), self.open_dialog_about ) fileMenu = self.menuBar().addMenu(self.tr('File')) editMenu = self.menuBar().addMenu(self.tr('Edit')) presetsMenu = self.menuBar().addMenu(self.tr('Presets')) helpMenu = self.menuBar().addMenu(self.tr('Help')) utils.add_actions( fileMenu, [openAction, convertAction, None, quitAction]) utils.add_actions( presetsMenu, [edit_presetsAction, importAction, exportAction, resetAction, None, syncAction, removeoldAction] ) utils.add_actions(editMenu, [clearallAction, None, preferencesAction]) utils.add_actions( helpMenu, [trackerAction, wikiAction, None, ffmpegdocAction, imagemagickdocAction, None, aboutAction] ) self.filesList.dropped.connect(self.filesList_add_dragged) addQPB.clicked.connect(self.filesList_add) delQPB.clicked.connect(self.filesList_delete) clearQPB.clicked.connect(self.filesList_clear) self.tabWidget.currentChanged.connect( lambda: self.tabs[0].moreQPB.setChecked(False)) self.origQCB.toggled.connect( lambda: self.toQLE.setEnabled(not self.origQCB.isChecked())) self.toQTB.clicked.connect(self.get_output_folder) convertQPB.clicked.connect(convertAction.triggered) del_shortcut = QShortcut(self) del_shortcut.setKey(Qt.Key_Delete) del_shortcut.activated.connect(self.filesList_delete) self.setWindowTitle('FF Multi Converter') self.load_settings() self.check_for_dependencies() self.audiovideo_tab.set_default_command() self.image_tab.set_default_command() self.toQLE.setText(self.default_output) self.filesList_update()
class MainWindow(mainwindow[0], mainwindow[1]): def __init__(self): super().__init__() self.setupUi(self) self.rubric_dialog = None self.correcion: Correction = Correction() self.current_file: File = None self.save_changes_when_quit = False self.loaded_path = None self.saved_label = QLabel() self.saved_label.setText("No hay archivo abierto") self.save_shorcut = QShortcut(self) self.quit_shorcut = QShortcut(self) self.run_shorcut = QShortcut(self) self.move_left_shorcut = QShortcut(self) self.move_left_student = QShortcut(self) self.move_right_shorcut = QShortcut(self) self.move_right_student = QShortcut(self) self.focus_spin = QShortcut(self) self.lose_focus = QShortcut(self) self.focus_in_run = QShortcut(self) self.focus_in_comment = QShortcut(self) self.focus_in_stdin = QShortcut(self) self.check_save_run = QShortcut(self) self.save_shorcut.setKey(Qt.CTRL + Qt.Key_S) self.quit_shorcut.setKey(Qt.CTRL + Qt.Key_Q) self.run_shorcut.setKey(Qt.CTRL + Qt.Key_R) self.move_left_shorcut.setKey(Qt.CTRL + Qt.Key_Left) self.move_right_shorcut.setKey(Qt.CTRL + Qt.Key_Right) self.focus_in_run.setKey(Qt.CTRL + Qt.SHIFT + Qt.Key_R) self.focus_in_comment.setKey(Qt.CTRL + Qt.SHIFT + Qt.Key_P) self.check_save_run.setKey(Qt.CTRL + Qt.Key_G) self.lose_focus.setKey(Qt.Key_Escape) self.move_left_student.setKey(Qt.CTRL + Qt.SHIFT + Qt.Key_Left) self.move_right_student.setKey(Qt.CTRL + Qt.SHIFT + Qt.Key_Right) self.focus_spin.setKey(Qt.CTRL + Qt.SHIFT + Qt.Key_S) self.focus_in_stdin.setKey(Qt.CTRL + Qt.Key_D) self.save_shorcut.activated.connect(self.save) self.quit_shorcut.activated.connect(self.quit) self.run_shorcut.activated.connect(self.new_run) self.move_left_shorcut.activated.connect( lambda: move_combo('left', self.sItemCombo)) self.move_right_shorcut.activated.connect( lambda: move_combo('right', self.sItemCombo)) self.move_left_student.activated.connect( lambda: move_combo('left', self.alumnoCombo)) self.move_right_student.activated.connect( lambda: move_combo('right', self.alumnoCombo)) self.focus_in_run.activated.connect( lambda: self.scriptTestingDescTedit.setFocus()) self.focus_in_comment.activated.connect( lambda: self.sItemTEdit.setFocus()) self.check_save_run.activated.connect(lambda: self.scriptTestingSaveBox.setChecked(False) if self.scriptTestingSaveBox.isChecked() else self.scriptTestingSaveBox.setChecked(True)) self.lose_focus.activated.connect( lambda: self.remove_focus()) self.focus_spin.activated.connect( lambda: self.scoreSpin.setFocus() ) self.focus_in_stdin.activated.connect( lambda: self.scriptTestingStdinTEdit.setFocus() ) self.statusbar.addWidget(self.saved_label) self.actionCargar_Correccion.triggered.connect(self.cargar_correccion) self.actionEditar_Rubrica.triggered.connect(self.edit_rubrica) self.actionNueva_Correccion.triggered.connect(self.new_correcion) self.actionEditar_Rubrica.setDisabled(True) self.actionGuardar.triggered.connect(self.save) self.actionGuardar_Como.triggered.connect(self.save_as) self.actionCerrar_Correccion.triggered.connect(self.cerrar_correccion) self.actionExportar_Correccion.triggered.connect(self.export) self.actionSalir.triggered.connect(self.quit) # NEXT AND PREVIOUS BUTTONS CONFIG self.sItemNextBtn.clicked.connect( lambda: move_combo('right', self.sItemCombo)) self.sItemPreviousBtn.clicked.connect( lambda: move_combo('left', self.sItemCombo)) self.alumnoNextBtn.clicked.connect( lambda: move_combo('right', self.alumnoCombo)) self.alumnoPreviousBtn.clicked.connect( lambda: move_combo('left', self.alumnoCombo)) self.runsNextBtn.clicked.connect( lambda: move_combo('right', self.runsCombo)) self.runsPreviousBtn.clicked.connect( lambda: move_combo('left', self.runsCombo)) self.rubNextBtn.clicked.connect( lambda: move_combo('right', self.rubCombo)) self.rubPreviousBtn.clicked.connect( lambda: move_combo('left', self.rubCombo)) self.connect_widgets() def remove_focus(self): try: QApplication.focusWidget().clearFocus() except AttributeError: pass def connect_widgets(self): self.alumnoCombo.currentIndexChanged.connect(self.load_student) self.runsCombo.currentIndexChanged.connect(self.load_run) self.rubCombo.currentIndexChanged.connect(self.load_rubrica_item) self.sItemCombo.currentIndexChanged.connect(self.load_alumno_eval_item) self.scoreSpin.valueChanged.connect(self.calculate_score) self.scoreSpin.editingFinished.connect(self.update_eval_score) self.sItemTEdit.textChanged.connect(self.change_s_item_comment) self.alumnoCommentTEdit.textChanged.connect( self.change_student_comment) self.viewFBtn.clicked.connect(self.see_file) self.scriptTestingRunBtn.clicked.connect(self.new_run) self.scriptTestingRunBtn_2.clicked.connect(new_console) self.filePushButton.clicked.connect(self.load_sample) self.fExplorerIncludeEd.clicked.connect(self.allow_edit_include) self.fExplorerInclude.clicked.connect(self.disable_edit_include) self.fExplorerNotInclude.clicked.connect(self.disable_edit_not_include) def disconnect_widgets(self): self.alumnoCombo.currentIndexChanged.disconnect() self.runsCombo.currentIndexChanged.disconnect() self.rubCombo.currentIndexChanged.disconnect() self.sItemCombo.currentIndexChanged.disconnect() self.scoreSpin.valueChanged.disconnect() self.scoreSpin.editingFinished.disconnect() self.sItemTEdit.textChanged.disconnect() self.alumnoCommentTEdit.textChanged.disconnect() self.viewFBtn.clicked.disconnect() self.scriptTestingRunBtn.clicked.disconnect() self.scriptTestingRunBtn_2.clicked.disconnect() self.filePushButton.clicked.disconnect() self.fExplorerIncludeEd.clicked.disconnect() self.fExplorerInclude.clicked.disconnect() self.fExplorerNotInclude.clicked.disconnect() def change_s_item_comment(self): student = self.correcion.get_student(self.alumnoCombo.currentText()) index = self.sItemCombo.currentIndex() student.evaluacion[index].comment = self.sItemTEdit.toPlainText() self.rename_to_not_save() def change_student_comment(self): student = self.correcion.students[self.alumnoCombo.currentIndex()] student.evaluacion.general_comments = self.alumnoCommentTEdit.toPlainText() self.rename_to_not_save() def quit(self): self.cerrar_correccion() sys.exit() def check_changes(self): print('called') if len(self.correcion.students) > 0: if self.loaded_path: with open(self.loaded_path, encoding='utf-8') as file: file_saved = file.read() try: with open('EVAL_DELETE_ME.txt', 'w', encoding='utf-8') as file: self.correcion.save(file) except PermissionError: sleep(0.0005) value = self.check_changes() return value with open('EVAL_DELETE_ME.txt', 'r', encoding='utf-8') as file: boolean = file.read() == file_saved os.remove('EVAL_DELETE_ME.txt') return not boolean else: print('ERROR: CALLING WITHOUT STUDENTS') return False def rename_to_not_save(self): changed = self.check_changes() if changed: if self.saved_label.text()[-1] != '*': self.saved_label.setText(self.saved_label.text() + '*') self.setWindowTitle(self.windowTitle() + '*') def save(self): if self.actionGuardar.isEnabled(): if not self.loaded_path: self.save_as() else: with open(self.loaded_path, 'w', encoding='utf-8') as file: self.correcion.save(file) if self.saved_label.text()[-1] == '*': self.saved_label.setText(self.saved_label.text()[:-1]) self.setWindowTitle(self.windowTitle()[:-1]) def save_as(self): if self.actionGuardar.isEnabled(): path = QFileDialog.getSaveFileName(caption='Seleccione dónde desea guardar el archivo', filter='Correccion(*.crcn)') with open(path[0], 'w', encoding='utf-8') as file: self.loaded_path = path[0] self.correcion.save(file) previous = self.saved_label.text() self.saved_label.setText("Archivo guardado.") sleep(3) self.saved_label.setText(previous) self.rename_to_not_save() def update_eval_score(self): eval_item = self.correcion.students[self.alumnoCombo.currentIndex( )].evaluacion[self.sItemCombo.currentIndex()] eval_item.answer = self.scoreSpin.value() self.calculate_score() def calculate_score(self): r_item = self.correcion.rubrica[self.sItemCombo.currentIndex()] eval_item = self.correcion.students[self.alumnoCombo.currentIndex( )].evaluacion[self.sItemCombo.currentIndex()] self.scoreLineEdit.clear() self.scoreLineEdit.setText( str(Decimal(eval_item.answer * r_item.multiplier / 3))) self.rename_to_not_save() def refresh(self): if self.rubric_dialog.saved: self.correcion = self.rubric_dialog.correction_copy self.rubric_dialog.destroy() self.load_students() self.load_student() self.load_rubrica_items() self.rename_to_not_save() def edit_rubrica(self): self.rubric_dialog = RubricDialog() self.rubric_dialog.load_correcion(self.correcion) self.rubric_dialog.rejected.connect(self.refresh) self.rubric_dialog.accepted.connect(self.refresh) self.rubric_dialog.show() def get_current_student(self, student_numero): for student in self.correcion.students: if student.numero == student_numero: return student def enable_all(self, boolean=False): self.alumnoGroup.setEnabled(boolean) self.runsGroup.setEnabled(boolean) self.rubGroup.setEnabled(boolean) self.scriptTestingGroup.setEnabled(boolean) self.runsDescGroup.setEnabled(boolean) self.runsStdinGroup.setEnabled(boolean) self.runsStdoutGroup.setEnabled(boolean) self.runsStderrGroup.setEnabled(boolean) self.runsDescTEdit.setEnabled(boolean) self.runsStdinTBrowser.setEnabled(boolean) self.runsStdoutTBrowser.setEnabled(boolean) self.runsStderrTBrowser.setEnabled(boolean) self.fExplorerGroup.setEnabled(boolean) def clear_and_disable_all(self): self.disconnect_widgets() self.alumnoCombo.clear() self.sItemCombo.clear() self.sfName.setText('--') self.scoreSpin.setValue(1) self.scoreLineEdit.setText('0') self.sItemTEdit.setPlainText('') self.alumnoCommentTEdit.setPlainText('') self.runsCombo.clear() self.runsDescTEdit.setPlainText('') self.runsStdinTBrowser.setText('') self.runsStdoutTBrowser.setText('') self.runsStderrTBrowser.setText('') self.rubCombo.clear() self.rubObjective.setText('--') self.rubDescTEdit.setPlainText('') self.rubComTEdit.setPlainText('') self.fileLineEdit.setText('') self.fExplorerTEdit.setPlainText('') self.fExplorerTEdit.setReadOnly(True) self.fExplorerTEdit.setStyleSheet('background:rgb(234, 234, 234)') self.fExplorerIncludeEd.setDown(False) self.fExplorerNotInclude.setDown(True) self.fExplorerInclude.setDown(False) self.scriptTestingName.setText('') self.scriptTestingSaveBox.setDown(False) self.scriptTestingDescTedit.setPlainText('') self.scriptTestingStdinTEdit.setPlainText('') self.scriptTestingStdoutTEdit.setPlainText('') self.scriptTestingStderrTEdit.setPlainText('') self.connect_widgets() self.enable_all(False) def set_save(self, boolean): self.save_changes_when_quit = boolean def cerrar_correccion(self): self.actionGuardar.setDisabled(True) self.actionGuardar_Como.setDisabled(True) self.actionEditar_Rubrica.setDisabled(True) show = self.check_changes() if show or (not self.loaded_path and len(self.correcion.students) > 0): quit_no_save = QMessageBox() quit_no_save.setIcon(QMessageBox.Warning) quit_no_save.setWindowTitle('Advertencia!') quit_no_save.setText('Desea guardar antes de salir?') quit_no_save.setStandardButtons(QMessageBox.Ok | QMessageBox.No) quit_no_save.buttonClicked.connect( lambda x: self.set_save(True) if x.text() == 'Ok' else self.set_save(False)) quit_no_save.exec_() if self.save_changes_when_quit: self.save() self.actionCerrar_Correccion.setDisabled(True) self.correcion: Correction = Correction() self.clear_and_disable_all() def new_correcion(self): def refresh(): self.load_students() self.alumnoCombo.setCurrentIndex(0) self.load_rubrica_items() self.load_runs(self.correcion.students[0]) self.actionEditar_Rubrica.setDisabled(False) new_dialog = NewDialog(self.correcion) new_dialog.accepted.connect(refresh) new_dialog.exec_() if new_dialog.loaded_correctly: self.actionGuardar.setDisabled(False) self.actionGuardar_Como.setDisabled(False) self.enable_all(True) show = new_dialog.path.split(inverted[os.sep])[-1] self.saved_label.setText(f'Editando archivo {show}') self.setWindowTitle(show) self.hide() self.showMaximized() def cargar_correccion(self): archivo = QFileDialog.getOpenFileName( self, "Seleccione la partida existente", filter='Correccion(*.crcn)') if len(archivo[0]) <= 0: return self.loaded_path = archivo[0] self.correcion: Correction = Correction() with open(archivo[0], 'r', encoding='utf-8') as file: self.correcion.load(file) self.load_students() self.load_student() self.load_rubrica_items() self.load_rubrica_item() self.load_alumno_eval_item() self.load_runs(self.correcion.students[0]) self.actionEditar_Rubrica.setDisabled(False) self.actionGuardar.setDisabled(False) self.actionGuardar_Como.setDisabled(False) self.enable_all(True) show = self.loaded_path.split(inverted[os.sep])[-1] self.saved_label.setText(f'Editando archivo {show}') self.setWindowTitle(show) self.hide() self.showMaximized() return True def load_sample(self): archivo = QFileDialog.getOpenFileName( self, "Seleccione archivo", filter='Archivos de Texto(*.txt)') if len(archivo[0]) == 0: return with open(archivo[0], 'r', encoding='utf-8') as file: nombre = archivo[0].split(inverted[os.sep])[-1] self.current_file = File(nombre, file.read()) self.fileLineEdit.setText( '...' + os.sep + self.current_file.nombre.split(inverted[os.sep])[-1]) with open(archivo[0], 'r', encoding='utf-8') as file: self.fExplorerTEdit.setPlainText(file.read()) def load_students(self): self.alumnoCombo.clear() self.disconnect_widgets() self.alumnoCombo.addItems( student.numero for student in self.correcion.students) self.connect_widgets() self.alumnoCombo.setCurrentIndex(0) self.load_student() def load_student(self): item_n = self.alumnoCombo.currentIndex() current_student = self.correcion.students[item_n] self.sfName.setText(current_student.nombre_archivo) self.disconnect_widgets() self.sItemCombo.clear() self.sItemCombo.addItems(item.combo_item() for item in current_student.evaluacion) self.connect_widgets() self.alumnoCommentTEdit.setPlainText( current_student.evaluacion.general_comments) self.load_runs(current_student) self.load_alumno_eval_item() def load_alumno_eval_item(self): item_n = self.sItemCombo.currentIndex() eval_item = self.correcion.students[self.alumnoCombo.currentIndex( )].evaluacion[item_n] self.rubCombo.setCurrentIndex(item_n) self.load_rubrica_item() self.scoreSpin.setValue(eval_item.answer) self.calculate_score() self.sItemTEdit.setPlainText(eval_item.comment) def load_rubrica_items(self): self.disconnect_widgets() self.rubCombo.clear() self.rubCombo.addItems(item.combo_item() for item in self.correcion.rubrica) self.connect_widgets() self.rubCombo.setCurrentIndex(0) def load_rubrica_item(self): item_n = self.rubCombo.currentIndex() self.rubObjective.setText(self.correcion.rubrica[item_n].objective) self.rubDescTEdit.setPlainText( self.correcion.rubrica[item_n].description) self.rubComTEdit.setPlainText(self.correcion.rubrica[item_n].comment) def load_runs(self, student: Student): self.disconnect_widgets() index = self.runsCombo.currentIndex() if index == -1: index = 0 self.runsCombo.clear() self.runsDescTEdit.setPlainText('') self.runsStdinTBrowser.setText('') self.runsStdoutTBrowser.setText('') self.runsStderrTBrowser.setText('') self.runsCombo.addItems(run.run_name for run in student.runs) self.runsCombo.setCurrentIndex(index) self.connect_widgets() if self.runsCombo.count() > 0: self.load_run() def load_run(self): student = self.get_current_student(str(self.alumnoCombo.currentText())) set_run = student.runs[self.runsCombo.currentIndex()] self.runsDescTEdit.setPlainText(set_run.run_description) self.runsStdinTBrowser.setText(set_run.stdin) self.runsStdoutTBrowser.setText(set_run.stdout) self.runsStderrTBrowser.setText(set_run.stderr) def see_file(self): file_dialog = FileDialog(self.get_current_student( self.alumnoCombo.currentText())) file_dialog.load() file_dialog.exec_() def allow_edit_include(self): self.fExplorerTEdit.setStyleSheet('') self.fExplorerCheckLabel_2.setText('[MODO EDICION] Para volver al original, cambiar de opcion a incluir o no ' 'incluir') self.fExplorerTEdit.setReadOnly(False) def disable_edit_include(self): self.fExplorerTEdit.setStyleSheet('background:rgb(234, 234, 234)') self.fExplorerCheckLabel_2.setText('') self.fExplorerTEdit.setReadOnly(True) def disable_edit_not_include(self): self.fExplorerTEdit.setStyleSheet('background:rgb(234, 234, 234)') self.fExplorerCheckLabel_2.setText('') self.fExplorerTEdit.setReadOnly(True) def export(self): dialog = QFileDialog.getSaveFileName(caption='Seleccione donde desea cuardar la exportacion', filter='CSV (*.csv)') with open(dialog[0], 'w', encoding='utf-8') as file: for student in self.correcion.students: multipliers = self.correcion.rubrica.get_multipliers() student_values = student.evaluacion.get_values() calc_values = ','.join(f'{str(Decimal(multiplier*answer/3))}' for multiplier, answer in zip(multipliers, student_values)) file.write( f'{student.numero},{calc_values},{student.evaluacion}\n') def new_run(self): if self.scriptTestingGroup.isEnabled(): student = self.get_current_student(self.alumnoCombo.currentText()) nombre = str(self.scriptTestingName.text()) archivo = student.file guardar = self.scriptTestingSaveBox.isChecked() descripcion = str(self.scriptTestingDescTedit.toPlainText()) stdin = StringIO() stdin.write(str(self.scriptTestingStdinTEdit.toPlainText())) kwargs = {'save': guardar, 'file': archivo, 'stdin': stdin} if len(nombre) > 0: kwargs['run_name'] = nombre if len(descripcion) > 0: kwargs['run_description'] = descripcion if self.fExplorerInclude.isChecked(): if len(self.fileLineEdit.text()) > 0: kwargs['extra_file'] = self.current_file elif self.fExplorerIncludeEd.isChecked(): if len(self.fileLineEdit.text()) > 0: kwargs['extra_file'] = self.current_file self.current_file.archivo = self.fExplorerTEdit.toPlainText() stdout, stderr = student.runs.new_run(**kwargs) self.scriptTestingStdoutTEdit.clear() self.scriptTestingStderrTEdit.clear() self.scriptTestingStdoutTEdit.setPlainText(stdout) self.scriptTestingStderrTEdit.setPlainText(stderr) self.scriptTestingSaveBox.setChecked(False) if guardar: self.load_runs(student) self.rename_to_not_save() else: print('CALLING WITHOUT FILE') def closeEvent(self, event): self.quit()
class PlaylistView(QTableView): def __init__(self, listplayer, status_bar: QStatusBar, play_ctrls, parent=None): super().__init__(parent=parent) self.player = listplayer self.status_bar = status_bar self.play_ctrls = play_ctrls self.setSelectionBehavior(self.SelectRows) self.setDragDropMode(self.InternalMove) self.setDragDropOverwriteMode(False) self.setEditTriggers(QTableView.NoEditTriggers) self.setAlternatingRowColors(True) self.setDropIndicatorShown(True) self.setHorizontalHeader(PlaylistViewHeader(parent=self)) self.setContextMenuPolicy(Qt.CustomContextMenu) # Create shortcuts self.rem_selected_items_shortcut = QShortcut(self) self.rem_selected_items_shortcut.setKey(QKeySequence.Delete) self.rem_selected_items_shortcut.setContext(Qt.WidgetWithChildrenShortcut) self.rem_selected_items_shortcut.activated.connect(self.remove_selected_items) self.play_selected_item_shortcut = QShortcut(self) self.play_selected_item_shortcut.setKey(Qt.Key_Return) self.play_selected_item_shortcut.setContext(Qt.WidgetWithChildrenShortcut) self.play_selected_item_shortcut.activated.connect(self.play_selected_item) self.setModel(PlaylistModel()) # Setup signals self.customContextMenuRequested.connect(self.show_context_menu) self.doubleClicked.connect(self.on_doubleClicked) self.selectionModel().selectionChanged.connect(self.on_selectionChanged) def showEvent(self, e): if self.model().rowCount(): if not self.selectionModel().hasSelection(): self.setCurrentIndex(self.model().item(0).index()) self.setFocus() @pyqtSlot() def play_selected_item(self): self.player.load_media(index=self.currentIndex()) self.player.mp.play() def mousePressEvent(self, e): """Clear both row and current index selections when clicking away from items.""" clicked_index = self.indexAt(e.pos()) if clicked_index.isValid(): item = self.model().item(clicked_index.row()) status_tip = item.data(role=Qt.DisplayRole) self.status_bar.showMessage(status_tip) else: self.selectionModel().clear() return super().mousePressEvent(e) def on_selectionChanged(self, selected, deselected): if not selected: self.selectionModel().clear() @pyqtSlot(QModelIndex) def on_doubleClicked(self, index): self.player.load_media(index=index) self.player.mp.play() def dropEvent(self, e): dragged_index = self.currentIndex() dropped_index = self.indexAt(e.pos()) log.debug( f"dragged_index={dragged_index.row(), dragged_index.column()} dropped_index={dropped_index.row(), dropped_index.column()} action={e.dropAction()} source={e.source()}" ) if dropped_index.row() == -1: return None model = self.model() item = model.takeRow(dragged_index.row()) model.insertRow(dropped_index.row(), item) self.setCurrentIndex(dropped_index) e.ignore() @pyqtSlot(int) def on_model_rowCountChanged(self, count): """Enable/disable GUI elements when media is added or removed""" if count: self.play_ctrls.setEnabled(True) else: self.play_ctrls.setEnabled(False) def setModel(self, model): # Disconnect previous model if self.model(): self.model().rowCountChanged.disconnect() # Connect this model model.rowCountChanged.connect(self.on_model_rowCountChanged) model.rowCountChanged.connect(self.player.on_playlist_rowCountChanged) super().setModel(model) def selected_items(self): items = [] for i in self.selectionModel().selectedRows(): items.append(self.model().itemFromIndex(i)) return items def show_context_menu(self, pos: QPoint): selected_items = self.selected_items() if len(selected_items) <= 1: rem_selected_text = f"Remove '{selected_items[0].data(Qt.DisplayRole)}'" else: rem_selected_text = f"Remove {len(selected_items)} items" menu = QMenu(self) menu.addAction( icons.get("file_remove"), rem_selected_text, self.remove_selected_items, self.rem_selected_items_shortcut.key(), ) menu.exec_(self.mapToGlobal(pos)) @pyqtSlot() def remove_selected_items(self): indexes = self.selectionModel().selectedRows() items = [self.model().itemFromIndex(i) for i in indexes] self.remove_items(items) def remove_items(self, items): # Create a status message if len(items) == 1: status_msg = f"Removed '{items[0].data(Qt.DisplayRole)}'" else: status_msg = f"Removed {len(items)} items" # Unload from player self.player.unload_media(items=items) # Remove from model start_row = self.model().indexFromItem(items[0]).row() num_rows = len(items) self.model().removeRows(start_row, num_rows) # Push status message self.status_bar.showMessage(status_msg)
def __init__(self, parent=None, choose=False): super(ShowPresets, self).__init__(parent) self.original_presets_file = utils.find_presets_file( config.presets_file_name, config.presets_lookup_dirs, config.presets_lookup_virtenv ) self.current_presets_file = config.presets_file self.presQLW = QListWidget() labelQL = QLabel(self.tr('Preset label')) self.labelQLE = QLineEdit() self.labelQLE.setReadOnly(True) commandQL = QLabel(self.tr('Preset command line parameters')) self.commandQLE = QLineEdit() self.commandQLE.setReadOnly(True) extQL = QLabel(self.tr('Output file extension')) self.extQLE = QLineEdit() self.extQLE.setReadOnly(True) addQPB = QPushButton(self.tr('Add')) self.deleteQPB = QPushButton(self.tr('Delete')) self.delete_allQPB = QPushButton(self.tr('Delete all')) self.editQPB = QPushButton(self.tr('Edit')) searchQL = QLabel(self.tr('Search')) self.searchQLE = QLineEdit() okQPB = QPushButton(self.tr('OK')) okQPB.setDefault(True) spc1 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) spc2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) spc3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) grid = utils.add_to_grid( [self.delete_allQPB, addQPB, spc1], [self.deleteQPB, self.editQPB, spc2] ) hlayout = utils.add_to_layout( 'h', searchQL, self.searchQLE, None, okQPB) final_layout = utils.add_to_layout( 'v', self.presQLW, labelQL, self.labelQLE, commandQL, self.commandQLE, extQL, self.extQLE, grid, spc3, hlayout ) self.setLayout(final_layout) okQPB.clicked.connect(self.accept) self.presQLW.currentRowChanged.connect(self.show_preset) addQPB.clicked.connect(self.add_preset) self.deleteQPB.clicked.connect(self.delete_preset) self.delete_allQPB.clicked.connect(self.delete_all_presets) self.editQPB.clicked.connect(self.edit_preset) self.searchQLE.textEdited.connect(self.search) if choose: self.presQLW.doubleClicked.connect(okQPB.click) del_shortcut = QShortcut(self) del_shortcut.setKey(Qt.Key_Delete) del_shortcut.activated.connect(self.delete_preset) self.resize(430, 480) self.setWindowTitle(self.tr('Edit Presets')) QTimer.singleShot(0, self.load_xml) QTimer.singleShot(0, self.fill_presQLW)
class Lookup(QWidget): MODEL_CLASS = None def __init__(self, parent, model): QWidget.__init__(self, parent, Qt.Window) self.model = model self.model.view = self self._setupUi() self.searchEdit.searchChanged.connect(self.searchChanged) self.searchEdit.returnPressed.connect(self.returnPressed) self.namesList.currentRowChanged.connect(self.currentRowChanged) self.namesList.itemDoubleClicked.connect(self.itemDoubleClicked) self._shortcutUp.activated.connect(self.upPressed) self._shortcutDown.activated.connect(self.downPressed) def _setupUi(self): self.setWindowTitle(tr("Lookup")) self.resize(314, 331) self.verticalLayout = QVBoxLayout(self) self.searchEdit = SearchEdit(self) self.verticalLayout.addWidget(self.searchEdit) self.namesList = QListWidget(self) self.namesList.setEditTriggers(QAbstractItemView.NoEditTriggers) self.namesList.setSelectionBehavior(QAbstractItemView.SelectRows) self.namesList.setUniformItemSizes(True) self.namesList.setSelectionRectVisible(True) self.verticalLayout.addWidget(self.namesList) self.searchEdit.immediate = True self._shortcutUp = QShortcut(self.searchEdit) self._shortcutUp.setKey(QKeySequence(Qt.Key_Up)) self._shortcutUp.setContext(Qt.WidgetShortcut) self._shortcutDown = QShortcut(self.searchEdit) self._shortcutDown.setKey(QKeySequence(Qt.Key_Down)) self._shortcutDown.setContext(Qt.WidgetShortcut) def _restoreSelection(self): self.namesList.setCurrentRow(self.model.selected_index) #--- Event Handlers def returnPressed(self): self.model.go() def searchChanged(self): self.model.search_query = str(self.searchEdit.text()) def currentRowChanged(self, row): if row >= 0: self.model.selected_index = row def itemDoubleClicked(self, item): self.model.go() def upPressed(self): if self.namesList.currentRow() > 0: self.namesList.setCurrentRow(self.namesList.currentRow()-1) def downPressed(self): if self.namesList.currentRow() < self.namesList.count()-1: self.namesList.setCurrentRow(self.namesList.currentRow()+1) #--- model --> view def refresh(self): self.namesList.clear() self.namesList.addItems(self.model.names) self._restoreSelection() self.searchEdit.setText(self.model.search_query) def show(self): QWidget.show(self) self.searchEdit.setFocus() # see csv_options self.raise_() def hide(self): QWidget.hide(self)
def make_shortcut(self, key, fxn): qs = QShortcut(self) qs.setKey(key) qs.activated.connect(fxn)
def initUI(self): self.setGeometry(300, 300, 1200, 600) self.setWindowTitle('CrossCobra - Python IDE') # splitters splitter1 = QSplitter(Qt.Vertical) splitter2 = QSplitter(Qt.Horizontal) # widgets self.notebook = TabWidget(self) self.codeView = CodeView(self, self.notebook) self.notebook.newTab(codeView=self.codeView) self.textPad = self.notebook.textPad self.fileBrowser = FileBrowser(self, self.textPad, self.notebook, self.codeView) self.textPad.fileBrowser = self.fileBrowser # add widgets to splitters splitter1.addWidget(self.fileBrowser) splitter1.addWidget(self.codeView) w = splitter1.width() splitter1.setSizes([w//2, w//2]) splitter2.addWidget(splitter1) splitter2.addWidget(self.notebook) hbox = QHBoxLayout() hbox.addWidget(splitter2) splitter1.setStretchFactor(1, 1) splitter2.setStretchFactor(1, 10) self.setCentralWidget(splitter2) # actions newAction = QAction(QIcon(self.HOME + 'images/new.png'), 'New', self) newAction.setShortcut('Ctrl+N') newAction.triggered.connect(self.new) openAction = QAction(QIcon(self.HOME + 'images/open.png'), 'Open', self) openAction.setShortcut('Ctrl+O') openAction.triggered.connect(self.open) saveAction = QAction(QIcon(self.HOME + 'images/save.png'), 'Save', self) saveAction.setShortcut('Ctrl+S') saveAction.triggered.connect(self.save) saveAsAction = QAction(QIcon(self.HOME + 'images/saveAs.png'), 'Save As', self) saveAsAction.setShortcut('Ctrl+Shift+S') saveAsAction.triggered.connect(self.saveAs) printAction = QAction(QIcon(self.HOME + 'images/print.png'), 'Print', self) printAction.setShortcut('Ctrl+P') printAction.triggered.connect(self.onPrint) undoAction = QAction(QIcon(self.HOME + 'images/undo.png'), 'Undo', self) undoAction.setShortcut('Ctrl+Z') undoAction.triggered.connect(self.undo) redoAction = QAction(QIcon(self.HOME + 'images/redo.png'), 'Redo', self) redoAction.setShortcut('Ctrl+Shift+Z') redoAction.triggered.connect(self.redo) zoomInAction = QAction(QIcon(self.HOME + 'images/zoomIn.png'), 'ZoomIn', self) zoomInAction.setShortcut('Ctrl++') zoomInAction.triggered.connect(self.zoomIn) zoomOutAction = QAction(QIcon(self.HOME + 'images/zoomOut.png'), 'ZoomOut', self) zoomOutAction.setShortcut('Ctrl+-') zoomOutAction.triggered.connect(self.zoomOut) settingsAction = QAction(QIcon(self.HOME + 'images/settings.png'), 'Settings', self) settingsAction.setShortcut('F9') settingsAction.triggered.connect(self.showSettings) interpreterAction = QAction(QIcon(self.HOME + 'images/interpreter.png'), 'Start Python Interpreter', self) interpreterAction.setShortcut('F10') interpreterAction.triggered.connect(self.interpreter) terminalAction = QAction(QIcon(self.HOME + 'images/terminal.png'), 'Start Terminal', self) terminalAction.setShortcut('F11') terminalAction.triggered.connect(self.terminal) runAction = QAction(QIcon(self.HOME + 'images/run.png'), 'Run File', self) runAction.setShortcut('F12') runAction.triggered.connect(self.run) searchShortcut = QShortcut(self) searchShortcut.setKey('Ctrl+F') searchShortcut.activated.connect(self.onSearch) spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) # make toolbar self.toolbar = QToolBar() self.toolbar.setStyleSheet(''' QToolButton::hover { background-color: darkgreen;} ''') self.toolbar.setContextMenuPolicy(Qt.PreventContextMenu) self.addToolBar(Qt.RightToolBarArea, self.toolbar) self.toolbar.addSeparator() self.toolbar.addAction(newAction) self.toolbar.addSeparator() self.toolbar.addAction(openAction) self.toolbar.addSeparator() self.toolbar.addAction(saveAction) self.toolbar.addSeparator() self.toolbar.addAction(saveAsAction) self.toolbar.addSeparator() self.toolbar.addAction(printAction) self.toolbar.addSeparator() self.toolbar.addAction(undoAction) self.toolbar.addSeparator() self.toolbar.addAction(redoAction) self.toolbar.addSeparator() self.toolbar.addAction(zoomInAction) self.toolbar.addSeparator() self.toolbar.addAction(zoomOutAction) self.toolbar.addSeparator() self.toolbar.addAction(settingsAction) self.toolbar.addSeparator() self.toolbar.addWidget(spacer) self.toolbar.addAction(interpreterAction) self.toolbar.addSeparator() self.toolbar.addAction(terminalAction) self.toolbar.addSeparator() self.toolbar.addAction(runAction) # make statusbar self.statusBar = QStatusBar() self.searchEdit = QLineEdit() spacer2 = QWidget() self.searchEdit.setStyleSheet( ''' background-color: white; color: black; ''') self.searchEdit.returnPressed.connect(self.onSearch) self.searchButton = QPushButton(QIcon(self.HOME + 'images/search.png'), 'Search', self) self.searchButton.setStyleSheet( ''' QPushButton::hover { background-color: darkgreen;} ''') self.searchButton.clicked.connect(self.onSearch) self.statusBar.addPermanentWidget(spacer2) self.statusBar.addPermanentWidget(self.searchEdit) self.statusBar.addPermanentWidget(self.searchButton) self.setStatusBar(self.statusBar) # show all self.textPad.setFocus() self.show()
def __init__(self): QMainWindow.__init__(self) logger.info("Starting %s" % nw.__package__) logger.debug("Initialising GUI ...") self.mainConf = nw.CONFIG self.theTheme = GuiTheme(self) self.theProject = NWProject(self) self.theIndex = NWIndex(self.theProject, self) self.hasProject = False self.isZenMode = False logger.info("OS: %s" % ( self.mainConf.osType) ) logger.info("Qt5 Version: %s (%d)" % ( self.mainConf.verQtString, self.mainConf.verQtValue) ) logger.info("PyQt5 Version: %s (%d)" % ( self.mainConf.verPyQtString, self.mainConf.verPyQtValue) ) logger.info("Python Version: %s (0x%x)" % ( self.mainConf.verPyString, self.mainConf.verPyHexVal) ) self.resize(*self.mainConf.winGeometry) self._setWindowTitle() self.setWindowIcon(QIcon(path.join(self.mainConf.appIcon))) # Main GUI Elements self.statusBar = GuiMainStatus(self) self.noticeBar = GuiNoticeBar(self) self.docEditor = GuiDocEditor(self, self.theProject) self.docViewer = GuiDocViewer(self, self.theProject) self.viewMeta = GuiDocViewDetails(self, self.theProject) self.searchBar = GuiSearchBar(self) self.treeMeta = GuiDocDetails(self, self.theProject) self.treeView = GuiDocTree(self, self.theProject) self.mainMenu = GuiMainMenu(self, self.theProject) # Minor Gui Elements self.statusIcons = [] self.importIcons = [] # Assemble Main Window self.treePane = QFrame() self.treeBox = QVBoxLayout() self.treeBox.setContentsMargins(0,0,0,0) self.treeBox.addWidget(self.treeView) self.treeBox.addWidget(self.treeMeta) self.treePane.setLayout(self.treeBox) self.editPane = QFrame() self.docEdit = QVBoxLayout() self.docEdit.setContentsMargins(0,0,0,0) self.docEdit.addWidget(self.searchBar) self.docEdit.addWidget(self.noticeBar) self.docEdit.addWidget(self.docEditor) self.editPane.setLayout(self.docEdit) self.viewPane = QFrame() self.docView = QVBoxLayout() self.docView.setContentsMargins(0,0,0,0) self.docView.addWidget(self.docViewer) self.docView.addWidget(self.viewMeta) self.docView.setStretch(0, 1) self.viewPane.setLayout(self.docView) self.splitView = QSplitter(Qt.Horizontal) self.splitView.setOpaqueResize(False) self.splitView.addWidget(self.editPane) self.splitView.addWidget(self.viewPane) self.splitMain = QSplitter(Qt.Horizontal) self.splitMain.setContentsMargins(4,4,4,4) self.splitMain.setOpaqueResize(False) self.splitMain.addWidget(self.treePane) self.splitMain.addWidget(self.splitView) self.splitMain.setSizes(self.mainConf.mainPanePos) self.setCentralWidget(self.splitMain) self.idxTree = self.splitMain.indexOf(self.treePane) self.idxMain = self.splitMain.indexOf(self.splitView) self.idxEditor = self.splitView.indexOf(self.editPane) self.idxViewer = self.splitView.indexOf(self.viewPane) self.splitMain.setCollapsible(self.idxTree, False) self.splitMain.setCollapsible(self.idxMain, False) self.splitView.setCollapsible(self.idxEditor, False) self.splitView.setCollapsible(self.idxViewer, True) self.viewPane.setVisible(False) self.searchBar.setVisible(False) # Build The Tree View self.treeView.itemSelectionChanged.connect(self._treeSingleClick) self.treeView.itemDoubleClicked.connect(self._treeDoubleClick) self.rebuildTree() # Set Main Window Elements self.setMenuBar(self.mainMenu) self.setStatusBar(self.statusBar) self.statusBar.setStatus("Ready") # Set Up Autosaving Project Timer self.asProjTimer = QTimer() self.asProjTimer.timeout.connect(self._autoSaveProject) # Set Up Autosaving Document Timer self.asDocTimer = QTimer() self.asDocTimer.timeout.connect(self._autoSaveDocument) # Shortcuts and Actions self._connectMenuActions() keyReturn = QShortcut(self.treeView) keyReturn.setKey(QKeySequence(Qt.Key_Return)) keyReturn.activated.connect(self._treeKeyPressReturn) keyEscape = QShortcut(self) keyEscape.setKey(QKeySequence(Qt.Key_Escape)) keyEscape.activated.connect(self._keyPressEscape) # Forward Functions self.setStatus = self.statusBar.setStatus self.setProjectStatus = self.statusBar.setProjectStatus if self.mainConf.showGUI: self.show() self.initMain() self.asProjTimer.start() self.asDocTimer.start() self.statusBar.clearStatus() self.showNormal() if self.mainConf.isFullScreen: self.toggleFullScreenMode() logger.debug("GUI initialisation complete") if self.mainConf.cmdOpen is not None: logger.debug("Opening project from additional command line option") self.openProject(self.mainConf.cmdOpen) return
def add_shortcut(self, action, desc, func, key=None): sc = QShortcut(self.guppy_window) self.combos[action] = (sc, desc) sc.activated.connect(func) if key: sc.setKey(key)
def __init__( self, options=None, styles=None, stencils=tuple(), auto_load=True, parent=None, ): """ :param qmxgraph.configuration.GraphOptions|None options: Features enabled in graph drawing widget. If none given, uses defaults. :param qmxgraph.configuration.GraphStyles|None styles: Additional styles made available for graph drawing widget besides mxGraph's default ones. If none given only mxGraph defaults are available. :param iterable[str] stencils: A sequence of XMLs available in Qt resource collections. Each XML must respect format defined by mxGraph (see https://jgraph.github.io/mxgraph/docs/js-api/files/shape/mxStencil-js.html#mxStencil and https://jgraph.github.io/mxgraph/javascript/examples/stencils.xml for reference). :param bool auto_load: If should load page as soon as widget is initialized. :param QWidget|None parent: Parent widget. """ QWidget.__init__(self, parent) self._own_path = ':/qmxgraph' self._mxgraph_path = ':/mxgraph' if options is None: options = GraphOptions() self._options = options if styles is None: styles = GraphStyles(styles={}) self._styles = styles self._stencils = stencils # Web view fills whole widget area self._layout = QGridLayout(self) self._layout.setContentsMargins(0, 0, 0, 0) # no margin to web view self._web_view = QWebViewWithDragDrop() self._web_view.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) # Starts disabled, only enable once finished loading page (as user # interaction before that would be unsafe) # TODO: widget remain with disabled appearance even after enabled # self.setEnabled(False) self._layout.addWidget(self._web_view, 0, 0, 1, 1) self._error_bridge = None self._events_bridge = None self._drag_drop_handler = None # Similar to a browser, QmxGraph widget is going to allow inspection by # typing F12 self._inspector_dialog = None inspector_shortcut = QShortcut(self) inspector_shortcut.setKey("F12") inspector_shortcut.activated.connect(self.toggle_inspector) self._execute_on_load_finished() self._api = QmxGraphApi(graph=self) self._web_view.on_drag_enter_event.connect(self._on_drag_enter) self._web_view.on_drag_move_event.connect(self._on_drag_move) self._web_view.on_drop_event.connect(self._on_drop) self._double_click_bridge = _DoubleClickBridge() self._popup_menu_bridge = _PopupMenuBridge() if auto_load: self._load_graph_page()