Exemple #1
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)
     dlgref = getattr(cls, key, None)
     
     if dlgref is not None:
         dlg = dlgref()
         if dlg:
             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, weakref.ref(dlg))
     return dlg
Exemple #2
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
Exemple #3
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