示例#1
0
    def _addDatasetAction(self, dataset):
        """
        Adds an action for the inputed dataset to the toolbar
        
        :param      dataset | <XChartDataset>
        """
        # create the toolbar action
        action = QAction(dataset.name(), self)
        action.setIcon(XColorIcon(dataset.color()))
        action.setCheckable(True)
        action.setChecked(True)
        action.setData(wrapVariant(dataset))
        action.toggled.connect(self.toggleDataset)

        self.uiDatasetTBAR.addAction(action)
示例#2
0
    def _addDatasetAction(self, dataset):
        """
        Adds an action for the inputed dataset to the toolbar
        
        :param      dataset | <XChartDataset>
        """
        # create the toolbar action
        action = QAction(dataset.name(), self)
        action.setIcon(XColorIcon(dataset.color()))
        action.setCheckable(True)
        action.setChecked(True)
        action.setData(wrapVariant(dataset))
        action.toggled.connect(self.toggleDataset)

        self.uiDatasetTBAR.addAction(action)
示例#3
0
    def addAction(self, action, checked=None, autoBuild=True):
        """
        Adds the inputed action to this widget's action group.  This will auto-\
        create a new group if no group is already defined.
        
        :param      action | <QAction> || <str>
        
        :return     <QAction>
        """
        # clear the holder
        actions = self._actionGroup.actions()
        if actions and actions[0].objectName() == 'place_holder':
            self._actionGroup.removeAction(actions[0])
            actions[0].deleteLater()

        # create an action from the name
        if not isinstance(action, QAction):
            action_name = nativestring(action)
            action = QAction(action_name, self)
            action.setObjectName(action_name)
            action.setCheckable(self.isCheckable())

            # auto-check the first option
            if checked or (not self._actionGroup.actions()
                           and checked is None):
                action.setChecked(True)

        elif self.isCheckable():
            action.setCheckable(True)
            if not self.currentAction():
                action.setChecked(True)

        self._actionGroup.addAction(action)

        if autoBuild:
            self.rebuild()

        return action
 def addAction( self, action ):
     """
     Adds the inputed action to this widget's action group.  This will auto-\
     create a new group if no group is already defined.
     
     :param      action | <QAction> || <str>
     
     :return     <QAction>
     """
     if not isinstance(action, QAction):
         action_name = nativestring(action)
         action = QAction(action_name, self)
         action.setObjectName(action_name)
     
     action.setCheckable(True)
     
     if ( not self._actionGroup ):
         self._actionGroup = QActionGroup(self)
         action.setChecked(True)
         
     self._actionGroup.addAction(action)
     self.reset()
     return action
示例#5
0
 def addAction(self, action, checked=None, autoBuild=True):
     """
     Adds the inputed action to this widget's action group.  This will auto-\
     create a new group if no group is already defined.
     
     :param      action | <QAction> || <str>
     
     :return     <QAction>
     """
     # clear the holder
     actions = self._actionGroup.actions()
     if actions and actions[0].objectName() == 'place_holder':
         self._actionGroup.removeAction(actions[0])
         actions[0].deleteLater()
     
     # create an action from the name
     if not isinstance(action, QAction):
         action_name = nativestring(action)
         action = QAction(action_name, self)
         action.setObjectName(action_name)
         action.setCheckable(self.isCheckable())
         
         # auto-check the first option
         if checked or (not self._actionGroup.actions() and checked is None):
             action.setChecked(True)
     
     elif self.isCheckable():
         action.setCheckable(True)
         if not self.currentAction():
             action.setChecked(True)
     
     self._actionGroup.addAction(action)
     
     if autoBuild:
         self.rebuild()
     
     return action
示例#6
0
    def __init__(self, parent=None):
        super(XRichTextEdit, self).__init__(parent)

        # load the user interface
        projexui.loadUi(__file__, self)

        # define custom properties

        # set default properties
        self.setFocusProxy(self.uiEditTXT)
        self.uiFindWGT.setTextEdit(self.uiEditTXT)
        self.uiFindWGT.hide()

        self.editor().setTabStopWidth(16)
        self.editor().document().setIndentWidth(24)
        self.editor().installEventFilter(self)
        self.editor().setRichTextEditEnabled(True)

        # create the font picker widget
        self._fontPickerWidget = XFontPickerWidget(self)
        self.uiFontBTN.setDefaultAnchor(XPopupWidget.Anchor.TopLeft)
        self.uiFontBTN.setCentralWidget(self._fontPickerWidget)

        popup = self.uiFontBTN.popupWidget()
        popup.setResizable(False)
        popup.setShowTitleBar(False)

        self._fontPickerWidget.accepted.connect(popup.accept)

        # generate actions for this editor based on the toolbar buttons
        self._actions = {}
        for mapping in (
            ("bold", self.uiBoldBTN, "Ctrl+B"),
            ("italic", self.uiItalicBTN, "Ctrl+I"),
            ("underline", self.uiUnderlineBTN, "Ctrl+U"),
            ("strikeOut", self.uiStrikeoutBTN, ""),
            ("unordered", self.uiUnorderedBTN, ""),
            ("ordered", self.uiOrderedBTN, ""),
            ("table", self.uiTableBTN, ""),
            ("align_left", self.uiAlignLeftBTN, ""),
            ("align_right", self.uiAlignRightBTN, ""),
            ("align_center", self.uiAlignCenterBTN, ""),
            ("align_justify", self.uiAlignJustifyBTN, ""),
            ("font_color", self.uiFontColorBTN, ""),
            ("bg_color", self.uiBackgroundColorBTN, ""),
        ):

            name, btn, shortcut = mapping

            act = QAction(self)
            act.setObjectName(name)
            act.setToolTip(btn.toolTip())
            act.setIcon(btn.icon())

            act.setShortcut(QKeySequence(shortcut))
            act.setCheckable(btn.isCheckable())
            act.setChecked(btn.isChecked())

            act.setShortcutContext(Qt.WidgetWithChildrenShortcut)

            btn.setDefaultAction(act)

            self._actions[name] = act
            self.addAction(act)

        # create the action groupings
        popup.resetRequested.connect(self.updateFontPicker)
        popup.aboutToShow.connect(self.updateFontPicker)
        popup.accepted.connect(self.assignFont)

        align_group = QActionGroup(self)
        align_group.addAction(self._actions["align_left"])
        align_group.addAction(self._actions["align_right"])
        align_group.addAction(self._actions["align_center"])
        align_group.addAction(self._actions["align_justify"])

        align_group.triggered.connect(self.assignAlignment)

        self._actions["align_left"].setChecked(True)

        # create connections
        self._actions["bold"].toggled.connect(self.setFontBold)
        self._actions["italic"].toggled.connect(self.setFontItalic)
        self._actions["underline"].toggled.connect(self.setFontUnderline)
        self._actions["strikeOut"].toggled.connect(self.setFontStrikeOut)

        self._actions["ordered"].triggered.connect(self.insertOrderedList)
        self._actions["unordered"].triggered.connect(self.insertUnorderedList)
        self._actions["table"].triggered.connect(self.insertTable)

        self._actions["font_color"].triggered.connect(self.pickTextColor)
        self._actions["bg_color"].triggered.connect(self.pickTextBackgroundColor)

        # link signals from the editor to the system
        for signal in (
            "copyAvailable",
            "currentCharFormatChanged",
            "cursorPositionChanged",
            "redoAvailable",
            "selectionChanged",
            "textChanged",
            "undoAvailable",
        ):

            from_ = getattr(self.uiEditTXT, signal)
            to_ = getattr(self, signal)

            from_.connect(to_)

        self.cursorPositionChanged.connect(self.refreshAlignmentUi)
        self.currentCharFormatChanged.connect(self.refreshUi)
示例#7
0
    def __init__(self, parent=None):
        super(XRichTextEdit, self).__init__(parent)

        # load the user interface
        projexui.loadUi(__file__, self)

        # define custom properties

        # set default properties
        self.setFocusProxy(self.uiEditTXT)
        self.uiFindWGT.setTextEdit(self.uiEditTXT)
        self.uiFindWGT.hide()

        self.editor().setTabStopWidth(16)
        self.editor().document().setIndentWidth(24)
        self.editor().installEventFilter(self)
        self.editor().setRichTextEditEnabled(True)

        # create the font picker widget
        self._fontPickerWidget = XFontPickerWidget(self)
        self.uiFontBTN.setDefaultAnchor(XPopupWidget.Anchor.TopLeft)
        self.uiFontBTN.setCentralWidget(self._fontPickerWidget)

        popup = self.uiFontBTN.popupWidget()
        popup.setResizable(False)
        popup.setShowTitleBar(False)

        self._fontPickerWidget.accepted.connect(popup.accept)

        # generate actions for this editor based on the toolbar buttons
        self._actions = {}
        for mapping in (('bold', self.uiBoldBTN,
                         'Ctrl+B'), ('italic', self.uiItalicBTN, 'Ctrl+I'),
                        ('underline', self.uiUnderlineBTN,
                         'Ctrl+U'), ('strikeOut', self.uiStrikeoutBTN, ''),
                        ('unordered', self.uiUnorderedBTN,
                         ''), ('ordered', self.uiOrderedBTN,
                               ''), ('table', self.uiTableBTN, ''),
                        ('align_left', self.uiAlignLeftBTN,
                         ''), ('align_right', self.uiAlignRightBTN, ''),
                        ('align_center', self.uiAlignCenterBTN,
                         ''), ('align_justify', self.uiAlignJustifyBTN,
                               ''), ('font_color', self.uiFontColorBTN, ''),
                        ('bg_color', self.uiBackgroundColorBTN, '')):

            name, btn, shortcut = mapping

            act = QAction(self)
            act.setObjectName(name)
            act.setToolTip(btn.toolTip())
            act.setIcon(btn.icon())

            act.setShortcut(QKeySequence(shortcut))
            act.setCheckable(btn.isCheckable())
            act.setChecked(btn.isChecked())

            act.setShortcutContext(Qt.WidgetWithChildrenShortcut)

            btn.setDefaultAction(act)

            self._actions[name] = act
            self.addAction(act)

        # create the action groupings
        popup.resetRequested.connect(self.updateFontPicker)
        popup.aboutToShow.connect(self.updateFontPicker)
        popup.accepted.connect(self.assignFont)

        align_group = QActionGroup(self)
        align_group.addAction(self._actions['align_left'])
        align_group.addAction(self._actions['align_right'])
        align_group.addAction(self._actions['align_center'])
        align_group.addAction(self._actions['align_justify'])

        align_group.triggered.connect(self.assignAlignment)

        self._actions['align_left'].setChecked(True)

        # create connections
        self._actions['bold'].toggled.connect(self.setFontBold)
        self._actions['italic'].toggled.connect(self.setFontItalic)
        self._actions['underline'].toggled.connect(self.setFontUnderline)
        self._actions['strikeOut'].toggled.connect(self.setFontStrikeOut)

        self._actions['ordered'].triggered.connect(self.insertOrderedList)
        self._actions['unordered'].triggered.connect(self.insertUnorderedList)
        self._actions['table'].triggered.connect(self.insertTable)

        self._actions['font_color'].triggered.connect(self.pickTextColor)
        self._actions['bg_color'].triggered.connect(
            self.pickTextBackgroundColor)

        # link signals from the editor to the system
        for signal in ('copyAvailable', 'currentCharFormatChanged',
                       'cursorPositionChanged', 'redoAvailable',
                       'selectionChanged', 'textChanged', 'undoAvailable'):

            from_ = getattr(self.uiEditTXT, signal)
            to_ = getattr(self, signal)

            from_.connect(to_)

        self.cursorPositionChanged.connect(self.refreshAlignmentUi)
        self.currentCharFormatChanged.connect(self.refreshUi)