Example #1
0
 def rebuild( self, gridRect ):
     """
     Rebuilds the tracker item.
     """
     scene = self.scene()
     if ( not scene ):
         return
     
     self.setVisible(gridRect.contains(self.pos()))
     self.setZValue(100)
     
     path = QPainterPath()
     path.moveTo(0, 0)
     path.lineTo(0, gridRect.height())
     
     tip             = ''
     tip_point       = None
     self._ellipses  = []
     items           = scene.collidingItems(self)
     self._basePath  = QPainterPath(path)
     
     for item in items:
         item_path = item.path()
         found = None
         for y in range(int(gridRect.top()), int(gridRect.bottom())):
             point = QPointF(self.pos().x(), y)
             if ( item_path.contains(point) ):
                 found = QPointF(0, y - self.pos().y())
                 break
         
         if ( found ):
             path.addEllipse(found, 6, 6)
             self._ellipses.append(found)
             
             # update the value information
             value     = scene.valueAt(self.mapToScene(found))
             tip_point = self.mapToScene(found)
             hruler    = scene.horizontalRuler()
             vruler    = scene.verticalRuler()
             
             x_value = hruler.formatValue(value[0])
             y_value = vruler.formatValue(value[1])
             
             tip = '<b>x:</b> %s<br/><b>y:</b> %s' % (x_value, y_value)
     
     self.setPath(path)
     self.setVisible(True)
     
     # show the popup widget
     if ( tip ):
         anchor    = XPopupWidget.Anchor.RightCenter
         widget    = self.scene().chartWidget()
         tip_point = widget.mapToGlobal(widget.mapFromScene(tip_point))
         
         XPopupWidget.showToolTip(tip, 
                                  anchor = anchor,
                                  parent = widget,
                                  point  = tip_point,
                                  foreground = QColor('blue'),
                                  background = QColor(148, 148, 255))
    def hoverMoveEvent(self, event):
        """
        Tracks whether or not this item is being hovered.
        
        :param      event | <QEvent>
        """
        point = event.pos()

        found_key = ''
        found = None
        for key, value, subpath in self._subpaths:
            if subpath.contains(point):
                found = subpath
                found_key = key
                break

        if found:
            # update the tooltip
            tip = self.keyToolTip(found_key)
            if (tip):
                widget = self.scene().chartWidget()
                anchor = XPopupWidget.Anchor.RightCenter

                # show the popup widget
                XPopupWidget.showToolTip(tip,
                                         anchor=anchor,
                                         parent=widget,
                                         foreground=self.color().darker(120),
                                         background=self.alternateColor())

            if (found != self._hoveredPath):
                self._hoveredPath = found
                self.update()
Example #3
0
 def hoverMoveEvent( self, event ):
     """
     Tracks whether or not this item is being hovered.
     
     :param      event | <QEvent>
     """
     point = event.pos()
     
     found_key = ''
     found = None
     for key, value, subpath in self._subpaths:
         if subpath.contains(point):
             found = subpath
             found_key = key
             break
     
     if found:
         # update the tooltip
         tip    = self.keyToolTip(found_key)
         if ( tip ):
             widget = self.scene().chartWidget()
             anchor = XPopupWidget.Anchor.RightCenter
             
             # show the popup widget
             XPopupWidget.showToolTip(tip, 
                                      anchor = anchor,
                                      parent = widget,
                                      foreground = self.color().darker(120),
                                      background = self.alternateColor())
         
         if ( found != self._hoveredPath ):
             self._hoveredPath = found
             self.update()
 def mousePressEvent( self, event ):
     """
     Changes the current date to the clicked on date.
     
     :param      event | <QMousePressEvent>
     """
     XPopupWidget.hideToolTip()
     
     # update the current date
     self.setCurrentDate(self.dateAt(event.scenePos()))
     
     super(XCalendarScene, self).mousePressEvent(event)
Example #5
0
 def mousePressEvent( self, event ):
     """
     Changes the current date to the clicked on date.
     
     :param      event | <QMousePressEvent>
     """
     XPopupWidget.hideToolTip()
     
     # update the current date
     self.setCurrentDate(self.dateAt(event.scenePos()))
     
     super(XCalendarScene, self).mousePressEvent(event)
Example #6
0
    def __init__(self, parent, buttons=None):
        super(XPopupButton, self).__init__(parent)

        # define custom options
        if buttons is None:
            buttons = QDialogButtonBox.Reset
            buttons |= QDialogButtonBox.Save
            buttons |= QDialogButtonBox.Cancel

        self._popupWidget = XPopupWidget(self, buttons)
        self._defaultAnchor = 0
        self._popupShown = False

        self.setEnabled(False)

        # create connections
        self.clicked.connect(self.clickAction)
        self.triggered.connect(self.togglePopupOnAction)

        self._popupWidget.accepted.connect(self.popupAccepted)
        self._popupWidget.rejected.connect(self.popupRejected)
        self._popupWidget.resetRequested.connect(self.popupReset)
 def helpEvent( self, event ):
     """
     Displays a tool tip for the given help event.
     
     :param      event | <QHelpEvent>
     """
     item  = self.itemAt(event.scenePos())
     if ( item and item and item.toolTip() ):
         parent = self.parent()
         rect   = item.path().boundingRect()
         point  = event.scenePos()
         point.setY(item.pos().y() + rect.bottom())
         
         point  = parent.mapFromScene(point)
         point  = parent.mapToGlobal(point)
         
         XPopupWidget.showToolTip(item.toolTip(),
                                  point = point,
                                  parent = parent)
         event.accept()
     else:
         super(XCalendarScene, self).helpEvent(event)
Example #8
0
 def helpEvent( self, event ):
     """
     Displays a tool tip for the given help event.
     
     :param      event | <QHelpEvent>
     """
     item  = self.itemAt(event.scenePos())
     if ( item and item and item.toolTip() ):
         parent = self.parent()
         rect   = item.path().boundingRect()
         point  = event.scenePos()
         point.setY(item.pos().y() + rect.bottom())
         
         point  = parent.mapFromScene(point)
         point  = parent.mapToGlobal(point)
         
         XPopupWidget.showToolTip(item.toolTip(),
                                  point = point,
                                  parent = parent)
         event.accept()
     else:
         super(XCalendarScene, self).helpEvent(event)
Example #9
0
 def __init__(self, parent, buttons=None):
     super(XPopupButton, self).__init__(parent)
     
     # define custom options
     if buttons is None:
         buttons  = QDialogButtonBox.Reset
         buttons |= QDialogButtonBox.Save
         buttons |= QDialogButtonBox.Cancel
     
     self._popupWidget   = XPopupWidget(self, buttons)
     self._defaultAnchor = 0
     self._popupShown    = False
     
     self.setEnabled(False)
     
     # create connections
     self.clicked.connect(self.clickAction)
     self.triggered.connect(self.togglePopupOnAction)
     
     self._popupWidget.accepted.connect(self.popupAccepted)
     self._popupWidget.rejected.connect(self.popupRejected)
     self._popupWidget.resetRequested.connect(self.popupReset)
Example #10
0
class XPopupButton(QToolButton):
    popupAboutToShow = Signal()
    popupAccepted = Signal()
    popupRejected = Signal()
    popupReset = Signal()

    Anchor = XPopupWidget.Anchor

    def __init__(self, parent, buttons=None):
        super(XPopupButton, self).__init__(parent)

        # define custom options
        if buttons is None:
            buttons = QDialogButtonBox.Reset
            buttons |= QDialogButtonBox.Save
            buttons |= QDialogButtonBox.Cancel

        self._popupWidget = XPopupWidget(self, buttons)
        self._defaultAnchor = 0
        self._popupShown = False

        self.setEnabled(False)

        # create connections
        self.clicked.connect(self.clickAction)
        self.triggered.connect(self.togglePopupOnAction)

        self._popupWidget.accepted.connect(self.popupAccepted)
        self._popupWidget.rejected.connect(self.popupRejected)
        self._popupWidget.resetRequested.connect(self.popupReset)

    def centralWidget(self):
        """
        Returns the central widget from this tool button
        """
        return self._popupWidget.centralWidget()

    def clickAction(self):
        """
        Calls the triggered signal if there is no action for this widget.
        """
        if not self.defaultAction():
            self.triggered.emit(None)

    def defaultAnchor(self):
        """
        Returns the default anchor for this popup widget.
        
        :return     <XPopupWidget.Anchor>
        """
        return self._defaultAnchor

    def hideEvent(self, event):
        super(XPopupButton, self).hideEvent(event)

        self._popupShown = self.popupWidget().isVisible()
        if self.popupWidget().currentMode() != XPopupWidget.Mode.Dialog:
            self.popupWidget().hide()

    def popupWidget(self):
        """
        Returns the popup widget for this button.
        
        :return     <XPopupWidget>
        """
        return self._popupWidget

    def setCentralWidget(self, widget):
        """
        Sets the central widget for this button.
        
        :param      widget | <QWidget>
        """
        self.setEnabled(widget is not None)
        self._popupWidget.setCentralWidget(widget)

    def setDefaultAnchor(self, anchor):
        """
        Sets the default anchor for the popup on this button.
        
        :param      anchor | <XPopupWidget.Anchor>
        """
        self._defaultAnchor = anchor

    def showEvent(self, event):
        super(XPopupButton, self).showEvent(event)

        if self._popupShown and \
           self.popupWidget().currentMode() != XPopupWidget.Mode.Dialog:
            self.showPopup()

    def showPopupOnAction(self, action):
        """
        Shows the popup if the action is the current default action.
        
        :param      action | <QAction>
        """
        if (action == self.defaultAction()):
            self.showPopup()

    def showPopup(self):
        """
        Shows the popup for this button.
        """
        as_dialog = QApplication.keyboardModifiers()

        anchor = self.defaultAnchor()
        if anchor:
            self.popupWidget().setAnchor(anchor)
        else:
            anchor = self.popupWidget().anchor()

        if (anchor &
            (XPopupWidget.Anchor.BottomLeft | XPopupWidget.Anchor.BottomCenter
             | XPopupWidget.Anchor.BottomRight)):
            pos = QPoint(self.width() / 2, 0)
        else:
            pos = QPoint(self.width() / 2, self.height())

        pos = self.mapToGlobal(pos)

        if not self.signalsBlocked():
            self.popupAboutToShow.emit()
        self._popupWidget.popup(pos)

        if as_dialog:
            self._popupWidget.setCurrentMode(XPopupWidget.Mode.Dialog)

    def togglePopup(self):
        """
        Toggles whether or not the popup is visible.
        """
        if not self._popupWidget.isVisible():
            self.showPopup()
        elif self._popupWidget.currentMode() != self._popupWidget.Mode.Dialog:
            self._popupWidget.close()

    def togglePopupOnAction(self, action):
        """
        Toggles the popup if the action is the current default action.
        
        :param      action | <QAction>
        """
        if action in (None, self.defaultAction()):
            self.togglePopup()
Example #11
0
class XPopupButton(QToolButton):
    popupAboutToShow = Signal()
    popupAccepted    = Signal()
    popupRejected    = Signal()
    popupReset       = Signal()
    
    Anchor = XPopupWidget.Anchor
    
    def __init__(self, parent, buttons=None):
        super(XPopupButton, self).__init__(parent)
        
        # define custom options
        if buttons is None:
            buttons  = QDialogButtonBox.Reset
            buttons |= QDialogButtonBox.Save
            buttons |= QDialogButtonBox.Cancel
        
        self._popupWidget   = XPopupWidget(self, buttons)
        self._defaultAnchor = 0
        self._popupShown    = False
        
        self.setEnabled(False)
        
        # create connections
        self.clicked.connect(self.clickAction)
        self.triggered.connect(self.togglePopupOnAction)
        
        self._popupWidget.accepted.connect(self.popupAccepted)
        self._popupWidget.rejected.connect(self.popupRejected)
        self._popupWidget.resetRequested.connect(self.popupReset)
    
    def centralWidget(self):
        """
        Returns the central widget from this tool button
        """
        return self._popupWidget.centralWidget()
    
    def clickAction(self):
        """
        Calls the triggered signal if there is no action for this widget.
        """
        if not self.defaultAction():
            self.triggered.emit(None)
    
    def defaultAnchor(self):
        """
        Returns the default anchor for this popup widget.
        
        :return     <XPopupWidget.Anchor>
        """
        return self._defaultAnchor
    
    def hideEvent(self, event):
        super(XPopupButton, self).hideEvent(event)
        
        self._popupShown = self.popupWidget().isVisible()
        if self.popupWidget().currentMode() != XPopupWidget.Mode.Dialog:
            self.popupWidget().hide()
    
    def popupWidget(self):
        """
        Returns the popup widget for this button.
        
        :return     <XPopupWidget>
        """
        return self._popupWidget
    
    def setCentralWidget(self, widget):
        """
        Sets the central widget for this button.
        
        :param      widget | <QWidget>
        """
        self.setEnabled(widget is not None)
        self._popupWidget.setCentralWidget(widget)
    
    def setDefaultAnchor(self, anchor):
        """
        Sets the default anchor for the popup on this button.
        
        :param      anchor | <XPopupWidget.Anchor>
        """
        self._defaultAnchor = anchor
    
    def showEvent(self, event):
        super(XPopupButton, self).showEvent(event)
        
        if self._popupShown and \
           self.popupWidget().currentMode() != XPopupWidget.Mode.Dialog:
            self.showPopup()
    
    def showPopupOnAction(self, action):
        """
        Shows the popup if the action is the current default action.
        
        :param      action | <QAction>
        """
        if ( action == self.defaultAction() ):
            self.showPopup()
    
    def showPopup(self):
        """
        Shows the popup for this button.
        """
        as_dialog = QApplication.keyboardModifiers()
        
        anchor = self.defaultAnchor()
        if anchor:
            self.popupWidget().setAnchor(anchor)
        else:
            anchor = self.popupWidget().anchor()
        
        if ( anchor & (XPopupWidget.Anchor.BottomLeft |
                       XPopupWidget.Anchor.BottomCenter |
                       XPopupWidget.Anchor.BottomRight) ):
            pos = QPoint(self.width() / 2, 0)
        else:
            pos = QPoint(self.width() / 2, self.height())
        
        pos = self.mapToGlobal(pos)
        
        if not self.signalsBlocked():
            self.popupAboutToShow.emit()
        self._popupWidget.popup(pos)
        
        if as_dialog:
            self._popupWidget.setCurrentMode(XPopupWidget.Mode.Dialog)
    
    def togglePopup(self):
        """
        Toggles whether or not the popup is visible.
        """
        if not self._popupWidget.isVisible():
            self.showPopup()
        elif self._popupWidget.currentMode() != self._popupWidget.Mode.Dialog:
            self._popupWidget.close()
    
    def togglePopupOnAction( self, action ):
        """
        Toggles the popup if the action is the current default action.
        
        :param      action | <QAction>
        """
        if action in (None, self.defaultAction()):
            self.togglePopup()