def checkMessageBox(self): # self.assertEqual(QApplication.activeWindow(),None) mb = QApplication.activeModalWidget() self.assertTrue(isinstance(mb, QMessageBox)) self.text = mb.text() self.title = mb.windowTitle() mb.close()
def eventFilter( self, obj, event ): """ Event filter to catch ESC application wide; Pass focus explicitly on broken window managers when the app is activated """ try: eventType = event.type() if eventType == KEY_PRESS: if event.key() == Qt.Key_Escape: if self.mainWindow: self.mainWindow.hideTooltips() elif eventType == APP_ACTIVATE: lastFocus, \ beforeMenuBar = self.__areWidgetsAlive( self.__lastFocus, self.__beforeMenuBar ) if lastFocus: if isinstance( self.__lastFocus, QMenuBar ): if beforeMenuBar: self.__beforeMenuBar.setFocus() self.__lastFocus = None if self.mainWindow: self.mainWindow.checkOutsideFileChanges() elif eventType == APP_DEACTIVATE: if QApplication.activeModalWidget() is not None: self.__lastFocus = None else: self.__lastFocus = QApplication.focusWidget() except: pass return False
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 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 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 addWindow(self, window, target): parent = QApplication.activeModalWidget() if not parent: parent = self dialog = QDialog(parent) dialog.setWindowTitle(_('Wizard')) dialog.setModal(True) layout = QHBoxLayout(dialog) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(window) window.setParent(dialog) self.connect(window, SIGNAL('closed()'), dialog.accept) window.show() dialog.exec_()
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 eventFilter( self, obj, event ): """ Event filter to catch ESC application wide; Pass focus explicitly on broken window managers when the app is activated; Catch Ctrl+1 and Ctrl+2 application wide; """ try: eventType = event.type() if eventType == KEY_PRESS: key = event.key() modifiers = int( event.modifiers() ) if key == Qt.Key_Escape: if self.mainWindow: self.mainWindow.hideTooltips() if modifiers == int( Qt.ControlModifier ): if key == Qt.Key_1: if self.mainWindow: return self.mainWindow.passFocusToEditor() elif key == Qt.Key_2: if self.mainWindow: return self.mainWindow.passFocusToFlow() elif eventType == APP_ACTIVATE: lastFocus, \ beforeMenuBar = self.__areWidgetsAlive( self.__lastFocus, self.__beforeMenuBar ) if lastFocus: if isinstance( self.__lastFocus, QMenuBar ): if beforeMenuBar: self.__beforeMenuBar.setFocus() self.__lastFocus = None if self.mainWindow: self.mainWindow.checkOutsideFileChanges() elif eventType == APP_DEACTIVATE: if QApplication.activeModalWidget() is not None: self.__lastFocus = None else: self.__lastFocus = QApplication.focusWidget() except: pass return False
def eventFilter(self, obj, event): """ Event filter to catch ESC application wide; Pass focus explicitly on broken window managers when the app is activated; Catch Ctrl+1 and Ctrl+2 application wide; """ try: eventType = event.type() if eventType == KEY_PRESS: key = event.key() modifiers = int(event.modifiers()) if key == Qt.Key_Escape: if self.mainWindow: self.mainWindow.hideTooltips() if modifiers == int(Qt.ControlModifier): if key == Qt.Key_1: if self.mainWindow: return self.mainWindow.passFocusToEditor() elif key == Qt.Key_2: if self.mainWindow: return self.mainWindow.passFocusToFlow() elif eventType == APP_ACTIVATE: lastFocus, \ beforeMenuBar = self.__areWidgetsAlive( self.__lastFocus, self.__beforeMenuBar ) if lastFocus: if isinstance(self.__lastFocus, QMenuBar): if beforeMenuBar: self.__beforeMenuBar.setFocus() self.__lastFocus = None if self.mainWindow: self.mainWindow.checkOutsideFileChanges() elif eventType == APP_DEACTIVATE: if QApplication.activeModalWidget() is not None: self.__lastFocus = None else: self.__lastFocus = QApplication.focusWidget() except: pass return False