def confirmQuery(self, sql): if QMessageBox.question(QApplication.activeWindow(), "Query confirmation request", "%s\nAre you sure?" % sql, QMessageBox.Yes | QMessageBox.No, QMessageBox.No) == QMessageBox.Yes: db = self.connection().cursor() try: db.execute(sql) except MySQLError as (errno, errmsg): QMessageBox.critical(QApplication.activeWindow(), "Query result", errmsg)
def __init__(self, msg=None, parent=None): if parent is None: parent = QApplication.activeWindow() super(Dialogbase, self).__init__(parent, Qt.FramelessWindowHint) self.setupUi(self) self.setModal(True)
def command(self, command): """Perform one command.""" command = command.split() cmd = command[0] args = command[1:] win = QApplication.activeWindow() if win not in app.windows: if not app.windows: import mainwindow mainwindow.MainWindow().show() win = app.windows[0] if cmd == b'open': url = QUrl.fromEncoded(args[0]) win.openUrl(url, self.encoding) elif cmd == b'encoding': self.encoding = str(args[0]) elif cmd == b'activate_window': win.activateWindow() win.raise_() elif cmd == b'set_current': url = QUrl.fromEncoded(args[0]) win.setCurrentDocument(app.openUrl(url, self.encoding)) elif cmd == b'set_cursor': line, column = map(int, args) cursor = win.textCursor() pos = cursor.document().findBlockByNumber(line - 1).position() + column cursor.setPosition(pos) win.currentView().setTextCursor(cursor) elif cmd == b'bye': self.close()
def initializeInstance(self): # Remove BlissFramework application lockfile #self.guiConfiguration=qt.qApp.mainWidget().configuration if BlissFramework.get_gui_version() == "qt3": from qt import qApp self.guiConfiguration = qApp.mainWidget().configuration elif BlissFramework.get_gui_version() == "qt4": from PyQt4.QtGui import QApplication self.guiConfiguration = QApplication.activeWindow().configuration else: logging.getLogger("HWR").error('InstanceServer: % gui version not supported' % \ BlissFramework.get_gui_version()) lockfilename = os.path.join(tempfile.gettempdir(), '.%s.lock' % BlissFramework.loggingName) try: os.unlink(lockfilename) except: pass self.emit('instanceInitializing', ()) if self.isLocal(): self.startServer() else: self.connectToServer()
def initializeInstance(self): # Remove BlissFramework application lockfile #self.guiConfiguration=qt.qApp.mainWidget().configuration if BlissFramework.get_gui_version() == "qt3": from qt import qApp self.guiConfiguration = qApp.mainWidget().configuration elif BlissFramework.get_gui_version() == "qt4": from PyQt4.QtGui import QApplication self.guiConfiguration = QApplication.activeWindow().configuration else: logging.getLogger("HWR").error('InstanceServer: % gui version not supported' % \ BlissFramework.get_gui_version()) lockfilename=os.path.join(tempfile.gettempdir(), '.%s.lock' % BlissFramework.loggingName) try: os.unlink(lockfilename) except: pass self.emit('instanceInitializing', ()) if self.isLocal(): self.startServer() else: self.connectToServer()
def rmParamWidgetClose(self): aw = QApplication.activeWindow() mb = QApplication.activeModalWidget() self.assertTrue(isinstance(mb, QMessageBox)) self.text = mb.text() self.title = mb.windowTitle() QTest.mouseClick(mb.button(QMessageBox.No), Qt.LeftButton)
def __init__(self, parent=None): if parent is None: parent = QApplication.activeWindow() super(Dialogbase, self).__init__(parent, Qt.FramelessWindowHint) self.setupUi(self) self.setModal(True) self.parent().installEventFilter(self)
def paramWidgetClose(self): aw = QApplication.activeWindow() mb = QApplication.activeModalWidget() self.assertTrue(isinstance(mb, AttributeDlg)) QTest.keyClicks(mb.ui.nameLineEdit, self.aname) self.assertEqual(mb.ui.nameLineEdit.text(),self.aname) QTest.keyClicks(mb.ui.valueLineEdit, self.avalue) self.assertEqual(mb.ui.valueLineEdit.text(),self.avalue) mb.reject()
def activeWindow(): """Return the currently active MainWindow. Only returns None if there are no windows at all. """ if windows: w = QApplication.activeWindow() if w in windows: return w return windows[0]
def resetForeground(self): """ Sets the foreground brush for this item to the original. This implementation uses the palette from the active window, which produces the desired result. There might be an easier way, but using the default foreground brush from the item did not work (default foreground brush is black). @return None """ self.setForeground(QApplication.activeWindow().palette().text())
def checkMessageBox(self): aw = QApplication.activeWindow() mb = QApplication.activeModalWidget() self.assertTrue(isinstance(mb, QMessageBox)) # print mb.text() # print "AW", aw # print "mb", mb self.text = mb.text() self.title = mb.windowTitle() mb.accept() mb.close()
def getDialog(cls, name, parent=None): """ Generates a dialog for this class widget and returns it. :param parent | <QtGui.QWidget> || None :return <QtGui.QDialog> """ key = '_{0}__{1}_dialog'.format(cls.__name__, name) dlg = getattr(cls, key, None) if dlg is not None: return dlg if parent is None: parent = QApplication.activeWindow() dlg = QDialog(parent) # create widget widget = cls(dlg) dlg.__dict__['_mainwidget'] = widget widget.layout().setContentsMargins(0, 0, 0, 0) # create buttons opts = QDialogButtonBox.Save | QDialogButtonBox.Cancel buttons = QDialogButtonBox(opts, Qt.Horizontal, dlg) # create layout layout = QVBoxLayout() layout.addWidget(widget) layout.addWidget(buttons) dlg.setLayout(layout) dlg.resize(widget.minimumSize() + QSize(15, 15)) widget.resizeRequested.connect(dlg.adjustSize) # create connections buttons.accepted.connect(widget.save) buttons.rejected.connect(dlg.reject) widget.saved.connect(dlg.accept) widget.setFocus() dlg.adjustSize() if parent and parent.window(): center = parent.window().geometry().center() dlg.move(center.x() - dlg.width() / 2.0, center.y() - dlg.height() / 2.0) setattr(cls, key, dlg) return dlg
def openUrl(url): """Open Url. If there is an active MainWindow, the document is made the current document in that window. """ if app.windows: win = QApplication.activeWindow() if win not in app.windows: win = app.windows[0] doc = win.openUrl(url) if doc: win.setCurrentDocument(doc) else: app.openUrl(url)
def command(self, command): """Perform one command.""" command = command.split() cmd = command[0] args = command[1:] win = QApplication.activeWindow() if win not in app.windows: if not app.windows: import mainwindow mainwindow.MainWindow().show() win = app.windows[0] if cmd == b'open': url = QUrl.fromEncoded(args[0]) try: win.openUrl(url, self.encoding) except IOError as e: filename = url.toLocalFile() msg = _("{message}\n\n{strerror} ({errno})").format( message=_("Could not read from: {url}").format( url=filename), strerror=e.strerror, errno=e.errno) QMessageBox.critical(win, app.caption(_("Error")), msg) elif cmd == b'encoding': self.encoding = str(args[0]) elif cmd == b'activate_window': win.activateWindow() win.raise_() elif cmd == b'set_current': url = QUrl.fromEncoded(args[0]) try: win.setCurrentDocument(app.openUrl(url)) # already loaded except IOError: pass elif cmd == b'set_cursor': line, column = map(int, args) cursor = win.textCursor() pos = cursor.document().findBlockByNumber(line - 1).position() + column cursor.setPosition(pos) win.currentView().setTextCursor(cursor) elif cmd == b'bye': self.close()
def openUrl(url): """Open Url. If there is an active MainWindow, the document is made the current document in that window. If there is no MainWindow at all, it is created. """ if not app.windows: import mainwindow mainwindow.MainWindow().show() win = QApplication.activeWindow() if win not in app.windows: win = app.windows[0] doc = win.openUrl(url) if doc: win.setCurrentDocument(doc)
def showException(type, value, tb, msg, messagebar=False): if msg is None: msg = QCoreApplication.translate('Python', 'An error has occurred while executing Python code:') logmessage = '' for s in traceback.format_exception(type, value, tb): logmessage += s.decode('utf-8', 'replace') if hasattr(s, 'decode') else s title = QCoreApplication.translate('Python', 'Python error') QgsMessageLog.logMessage(logmessage, title) try: blockingdialog = QApplication.instance().activeModalWidget() window = QApplication.instance().activeWindow() except: blockingdialog = QApplication.activeModalWidget() window = QApplication.activeWindow() # Still show the normal blocking dialog in this case for now. if blockingdialog or not window or not messagebar or not iface: open_stack_dialog(type, value, tb, msg) return bar = iface.messageBar() # If it's not the main window see if we can find a message bar to report the error in if not window.objectName() == "QgisApp": widgets = window.findChildren(QgsMessageBar) if widgets: # Grab the first message bar for now bar = widgets[0] item = bar.currentItem() if item and item.property("Error") == msg: # Return of we already have a message with the same error message return widget = bar.createMessage(title, msg + " " + QCoreApplication.translate("Python", "See message log (Python Error) for more details.")) widget.setProperty("Error", msg) stackbutton = QPushButton(QCoreApplication.translate("Python", "Stack trace"), pressed=functools.partial(open_stack_dialog, type, value, tb, msg)) button = QPushButton(QCoreApplication.translate("Python", "View message log"), pressed=show_message_log) widget.layout().addWidget(stackbutton) widget.layout().addWidget(button) bar.pushWidget(widget, QgsMessageBar.WARNING)
def command(self, command): """Perform one command.""" command = command.split() cmd = command[0] args = command[1:] win = QApplication.activeWindow() if win not in app.windows: if not app.windows: import mainwindow mainwindow.MainWindow().show() win = app.windows[0] if cmd == b'open': url = QUrl.fromEncoded(args[0]) try: win.openUrl(url, self.encoding) except IOError as e: filename = url.toLocalFile() msg = _("{message}\n\n{strerror} ({errno})").format( message = _("Could not read from: {url}").format(url=filename), strerror = e.strerror, errno = e.errno) QMessageBox.critical(win, app.caption(_("Error")), msg) elif cmd == b'encoding': self.encoding = str(args[0]) elif cmd == b'activate_window': win.activateWindow() win.raise_() elif cmd == b'set_current': url = QUrl.fromEncoded(args[0]) try: win.setCurrentDocument(app.openUrl(url)) # already loaded except IOError: pass elif cmd == b'set_cursor': line, column = map(int, args) cursor = win.textCursor() pos = cursor.document().findBlockByNumber(line - 1).position() + column cursor.setPosition(pos) win.currentView().setTextCursor(cursor) elif cmd == b'bye': self.close()
def handlePackageContextAction(point): window = QApplication.activeWindow() package = window.currentPackage() menu = QMenu(parent=window) install = QAction(QIcon(':/icons/installed.png'), "&Install", window.packages) install.connect(install, SIGNAL('triggered()'), lambda: Frontend.default().install(package)) install.setEnabled(package.get('state', False) & (State.NonInstalled | State.AUR)) update = QAction(QIcon(':/icons/upgrade.png'), "&Update", window.packages) update.connect(update, SIGNAL('triggered()'), lambda: Frontend.default().install(package, update=True)) update.setEnabled(package.get('state', False) & State.Update) remove = QAction(QIcon(':/icons/stop.png'), "&Remove", window.packages) remove.connect(remove, SIGNAL('triggered()'), lambda: Frontend.default().remove(package)) remove.setEnabled(package.get('state', False) & (State.Installed | State.Update)) remove_forced = QAction(QIcon(':/icons/orphan.png'), "&Remove (force)", window.packages) remove_forced.connect(remove_forced, SIGNAL('triggered()'), lambda: Frontend.default().remove(package, force=True)) remove_forced.setEnabled(package.get('state', False) & (State.Installed | State.Update)) menu.addActions((install, update, remove, remove_forced)) menu.exec_(window.packages.mapToGlobal(point))
def showToolTip(text, point=None, anchor=None, parent=None, background=None, foreground=None, key=None, seconds=5): """ Displays a popup widget as a tooltip bubble. :param text | <str> point | <QPoint> || None anchor | <XPopupWidget.Mode.Anchor> || None parent | <QWidget> || None background | <QColor> || None foreground | <QColor> || None key | <str> || None seconds | <int> """ if point is None: point = QCursor.pos() if parent is None: parent = QApplication.activeWindow() if anchor is None and parent is None: anchor = XPopupWidget.Anchor.TopCenter # create a new tooltip widget widget = XPopupWidget(parent) widget.setToolTipMode() widget.setResizable(False) # create the tooltip label label = QLabel(text, widget) label.setOpenExternalLinks(True) label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) label.setMargin(3) label.setIndent(3) label.adjustSize() widget.setCentralWidget(label) # update the tip label.adjustSize() widget.adjustSize() palette = widget.palette() if not background: background = palette.color(palette.ToolTipBase) if not foreground: foreground = palette.color(palette.ToolTipText) palette.setColor(palette.Window, QColor(background)) palette.setColor(palette.WindowText, QColor(foreground)) widget.setPalette(palette) widget.centralWidget().setPalette(palette) if anchor is None: widget.setAutoCalculateAnchor(True) else: widget.setAnchor(anchor) widget.setAutoCloseOnFocusOut(True) widget.setAttribute(Qt.WA_DeleteOnClose) widget.popup(point) widget.startTimer(1000 * seconds) return widget
def _NH_FileTransferNewOutgoing(self, notification): self.filetransfer_window.show(activate=QApplication.activeWindow() is not None)
def _NH_BlinkFileTransferNewOutgoing(self, notification): self.filetransfer_window.show(activate=QApplication.activeWindow() is not None)
def show_message(self, msg): window = QApplication.activeWindow() QMessageBox.information(window, '', msg)
def confirm(self, title, msg, default_button=QMessageBox.Yes): active = QApplication.activeWindow() buttons = QMessageBox.Yes | QMessageBox.No answer = QMessageBox.question(active, title, msg, buttons, default_button) return answer == QMessageBox.Yes
def showToolTip( text, point = None, anchor = None, parent = None, background = None, foreground = None, key = None, seconds = 5 ): """ Displays a popup widget as a tooltip bubble. :param text | <str> point | <QPoint> || None anchor | <XPopupWidget.Mode.Anchor> || None parent | <QWidget> || None background | <QColor> || None foreground | <QColor> || None key | <str> || None seconds | <int> """ if point is None: point = QCursor.pos() if parent is None: parent = QApplication.activeWindow() if anchor is None and parent is None: anchor = XPopupWidget.Anchor.TopCenter # create a new tooltip widget widget = XPopupWidget(parent) widget.setToolTipMode() widget.setResizable(False) # create the tooltip label label = QLabel(text, widget) label.setOpenExternalLinks(True) label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) label.setMargin(3) label.setIndent(3) label.adjustSize() widget.setCentralWidget(label) # update the tip label.adjustSize() widget.adjustSize() palette = widget.palette() if not background: background = palette.color(palette.ToolTipBase) if not foreground: foreground = palette.color(palette.ToolTipText) palette.setColor(palette.Window, QColor(background)) palette.setColor(palette.WindowText, QColor(foreground)) widget.setPalette(palette) widget.centralWidget().setPalette(palette) if anchor is None: widget.setAutoCalculateAnchor(True) else: widget.setAnchor(anchor) widget.setAutoCloseOnFocusOut(True) widget.setAttribute(Qt.WA_DeleteOnClose) widget.popup(point) widget.startTimer(1000 * seconds) return widget