コード例 #1
0
ファイル: connections.py プロジェクト: mtorromeo/sqlantaresia
 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)
コード例 #2
0
 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)
コード例 #3
0
ファイル: popupdialogs.py プロジェクト: mdouchin/Roam
    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)
コード例 #4
0
ファイル: api.py プロジェクト: arnaldorusso/frescobaldi
 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()
コード例 #5
0
    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()
コード例 #6
0
    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()
コード例 #7
0
    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()
コード例 #8
0
    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)
コード例 #9
0
ファイル: popupdialogs.py プロジェクト: xCherry/Roam
    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)
コード例 #10
0
    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()
コード例 #11
0
ファイル: app.py プロジェクト: shimpe/frescobaldi
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]
コード例 #12
0
ファイル: app.py プロジェクト: EdwardBetts/frescobaldi
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]
コード例 #13
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())
コード例 #14
0
ファイル: treeitems.py プロジェクト: InfiniteAlpha/profitpy
    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())
コード例 #15
0
 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()
コード例 #16
0
 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
コード例 #17
0
    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
コード例 #18
0
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)
コード例 #19
0
    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()
コード例 #20
0
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)
コード例 #21
0
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)
コード例 #22
0
ファイル: utils.py プロジェクト: Jesonchang12/QGIS
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)
コード例 #23
0
ファイル: api.py プロジェクト: cognot/frescobaldi
 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()
コード例 #24
0
    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))
コード例 #25
0
    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
コード例 #26
0
ファイル: mainwindow.py プロジェクト: pol51/blink-qt
 def _NH_FileTransferNewOutgoing(self, notification):
     self.filetransfer_window.show(activate=QApplication.activeWindow() is not None)
コード例 #27
0
ファイル: mainwindow.py プロジェクト: webodf/blink-qt
 def _NH_BlinkFileTransferNewOutgoing(self, notification):
     self.filetransfer_window.show(activate=QApplication.activeWindow() is not None)
コード例 #28
0
 def show_message(self, msg):
     window = QApplication.activeWindow()
     QMessageBox.information(window, '', msg)
コード例 #29
0
ファイル: app.py プロジェクト: James-A-White/dupeguru
 def show_message(self, msg):
     window = QApplication.activeWindow()
     QMessageBox.information(window, '', msg)
コード例 #30
0
ファイル: app.py プロジェクト: James-A-White/dupeguru
 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
コード例 #31
0
 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
コード例 #32
0
 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