예제 #1
0
    def createMenu(self, parent):
        """
        Creates a new menu for the inputed parent item.
        
        :param      parent | <QMenu>
        """
        menu = QtGui.QMenu(parent)
        menu.setTitle('&View')

        act = menu.addAction('&Lock/Unlock Layout')
        act.setIcon(QtGui.QIcon(projexui.resources.find('img/view/lock.png')))
        act.triggered.connect(self.toggleLocked)

        menu.addSeparator()
        act = menu.addAction('&Export Layout as...')
        act.setIcon(QtGui.QIcon(
            projexui.resources.find('img/view/export.png')))
        act.triggered.connect(self.exportProfile)

        act = menu.addAction('&Import Layout from...')
        act.setIcon(QtGui.QIcon(
            projexui.resources.find('img/view/import.png')))
        act.triggered.connect(self.importProfile)

        menu.addSeparator()

        act = menu.addAction('&Clear Layout')
        act.setIcon(QtGui.QIcon(
            projexui.resources.find('img/view/remove.png')))
        act.triggered.connect(self.resetForced)

        return menu
예제 #2
0
    def initGroupStyle(self, useIcons=True, columnCount=None):
        """
        Initialzes this item with a grouping style option.
        """
        flags      = self.flags()
        if flags & QtCore.Qt.ItemIsSelectable:
            flags ^= QtCore.Qt.ItemIsSelectable
            self.setFlags(flags)
        
        if useIcons:
            ico        = QtGui.QIcon(resources.find('img/treeview/triangle_right.png'))
            expand_ico = QtGui.QIcon(resources.find('img/treeview/triangle_down.png'))
            
            self.setIcon(0, ico)
            self.setExpandedIcon(0, expand_ico)
        
        palette = QtGui.QApplication.palette()
        
        line_clr = palette.color(palette.Mid)
        base_clr = palette.color(palette.Button)
        text_clr = palette.color(palette.ButtonText)
        
        gradient = QtGui.QLinearGradient()
        
        gradient.setColorAt(0.00, line_clr)
        gradient.setColorAt(0.03, line_clr)
        gradient.setColorAt(0.04, base_clr.lighter(105))
        gradient.setColorAt(0.25, base_clr)
        gradient.setColorAt(0.96, base_clr.darker(105))
        gradient.setColorAt(0.97, line_clr)
        gradient.setColorAt(1.00, line_clr)
        
        h = self._fixedHeight
        if not h:
            h = self.sizeHint(0).height()
        if not h:
            h = 18
        
        gradient.setStart(0.0, 0.0)
        gradient.setFinalStop(0.0, h)
        
        brush = QtGui.QBrush(gradient)
        
        tree = self.treeWidget()
        columnCount = columnCount or (tree.columnCount() if tree else self.columnCount())

        for i in range(columnCount):
            self.setForeground(i, text_clr)
            self.setBackground(i, brush)
예제 #3
0
 def _updateFrame(self):
     """
     Updates the frame for the given sender.
     """
     mov = self.movie()
     if mov:
         self.setIcon(QtGui.QIcon(mov.currentPixmap()))
예제 #4
0
    def __init__(self, parent=None):
        super(XOverlayWidget, self).__init__(parent)

        # define custom properties
        self._centralWidget = None
        self._result = None
        self._closable = True
        self._closeAlignment = QtCore.Qt.AlignTop | QtCore.Qt.AlignRight
        self._closeButton = XToolButton(self)
        self._closeButton.setShadowed(True)
        self._closeButton.setIcon(
            QtGui.QIcon(resources.find('img/overlay/close.png')))
        self._closeButton.setIconSize(QtCore.QSize(24, 24))
        self._closeButton.setToolTip('Close')

        # create the coloring for the overlay
        palette = self.palette()
        clr = QtGui.QColor('#222222')
        clr.setAlpha(210)
        palette.setColor(palette.Window, clr)
        self.setPalette(palette)
        self.setAutoFillBackground(True)

        # listen to the parents event filter
        parent.installEventFilter(self)

        # initialize the widget
        self.hide()
        self.move(0, 0)
        self.resize(parent.size())
        self._closeButton.clicked.connect(self.reject)
예제 #5
0
    def __init__(self, parent):
        super(XListGroupItem, self).__init__(parent)

        # define the text property
        self._text = ''
        self._expanded = True
        self._children = set()

        # define the widget for this item
        lwidget = self.listWidget()

        btn = QtGui.QToolButton(lwidget)
        btn.setAutoRaise(True)
        btn.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
        btn.setSizePolicy(QtGui.QSizePolicy.Expanding,
                          QtGui.QSizePolicy.Preferred)

        ico = 'img/treeview/triangle_down.png'
        btn.setIcon(QtGui.QIcon(resources.find(ico)))

        font = btn.font()
        font.setBold(True)
        btn.setFont(font)

        lwidget.setItemWidget(self, btn)

        # create connections
        btn.clicked.connect(self.toggle)
예제 #6
0
 def setUnlockIcon(self, icon):
     """
     Sets the unlock icon for this button.
     
     :param      icon | <str> || <QtGui.QIcon>
     """
     self._unlockIcon = QtGui.QIcon(icon)
예제 #7
0
    def setMovie(self, column, movie):
        """
        Sets the movie that will play for the given column.
        
        :param      column | <int>
                    movie  | <QtGui.QMovie> || None
        """
        curr = self._movies.get(column)
        if curr == movie:
            return True
        else:
            try:
                curr.frameChanged.disconnect(self._updateFrame)
            except StandardError:
                pass
        
        if movie is not None:
            self.requireCleanup()

            self._movies[column] = movie
            self.setIcon(column, QtGui.QIcon(movie.currentPixmap()))
            
            try:
                movie.frameChanged.connect(self._updateFrame,
                                           QtCore.Qt.UniqueConnection)
            except StandardError:
                pass
        else:
            self._movies.pop(column, None)
예제 #8
0
 def setExpandedIcon( self, column, icon ):
     """
     Sets the icon to be used when the item is expanded.
     
     :param      column | <int>
                 icon   | <QtGui.QIcon> || None
     """
     self._expandedIcon[column] = QtGui.QIcon(icon)
예제 #9
0
 def setHoverIcon( self, column, icon ):
     """
     Returns the icon to use when coloring when the user hovers over
     the item for the given column.
     
     :param      column | <int>
                 icon   | <QtGui.QIcon)
     """
     self._hoverIcon[column] = QtGui.QIcon(icon)
예제 #10
0
 def setIconOverlay(self, column, icon):
     """
     Sets the icon overlay for this item at the inputed column to the
     given icon.
     
     :param      column | <int>
                 icon   | <str> || <QtGui.QIcon>
     """
     self._iconOverlays[column] = QtGui.QIcon(icon)
예제 #11
0
    def __init__(self, parent=None):
        super(XSearchEdit, self).__init__(parent)

        # setup default properties
        self.setHint('enter search')
        self.setIcon(QtGui.QIcon(resources.find('img/search.png')))
        self.setCornerRadius(8)

        # setup custom properties
        self._cancelButton = XToolButton(self)
        self._cancelButton.setIcon(
            QtGui.QIcon(resources.find('img/remove_dark.png')))
        self._cancelButton.setToolTip('Clear Search Text')
        self._cancelButton.setShadowed(True)
        self._cancelButton.hide()
        self.addButton(self._cancelButton, QtCore.Qt.AlignRight)

        # create connections
        self._cancelButton.clicked.connect(self.clear)
        self.textChanged.connect(self.toggleCancelButton)
예제 #12
0
    def updateUi(self):
        if self.uiRecordBTN.isChecked():
            ico = resources.find('img/debug/break.png')
            clr = QtGui.QColor('red')
            self.uiRecordBTN.blink(True)
        else:
            ico = resources.find('img/debug/continue.png')
            clr = QtGui.QColor('blue')
            self.uiRecordBTN.blink(False)

        self.uiRecordBTN.setIcon(QtGui.QIcon(ico))
        palette = self.uiRecordBTN.palette()
        palette.setColor(palette.Shadow, clr)
        self.uiRecordBTN.setPalette(palette)
예제 #13
0
    def addEntry(self, key='', value=''):
        """
        Creates a new entry item for this widget.
        
        :param      key     | <str>
                    value   | <variant>
        """
        img = resources.find('img/close.png')
        new_item = XTreeWidgetItem()
        new_item.setText(1, nativestring(key))
        new_item.setText(2, nativestring(value))
        new_item.setIcon(0, QtGui.QIcon(img))
        new_item.setFixedHeight(22)
        self.insertTopLevelItem(self.topLevelItemCount() - 1, new_item)

        return new_item
예제 #14
0
    def setMovie(self, movie):
        """
        Sets the movie that will play for the given column.
        
        :param      movie  | <QtGui.QMovie> || None
        """
        mov = self.movie()
        if mov is not None:
            mov.frameChanged.disconnect(self._updateFrame)

        if movie is not None:
            self._movie = movie
            self.setIcon(QtGui.QIcon(movie.currentPixmap()))

            movie.frameChanged.connect(self._updateFrame)

            widget = self.listWidget()
            widget.destroyed.connect(self.cleanup)
        else:
            self._movie = None
예제 #15
0
    def setExpanded(self, state):
        """
        Expands this group item to the inputed state.
        
        :param      state | <bool>
        """
        if state == self._expanded:
            return

        self._expanded = state

        # update the button
        btn = self.widget()
        if btn:
            if state:
                ico = 'img/treeview/triangle_down.png'
            else:
                ico = 'img/treeview/triangle_right.png'
            btn.setIcon(QtGui.QIcon(resources.find(ico)))

        # update the children
        for child in self.children():
            child.setHidden(not state)
예제 #16
0
    def paint(self, painter, opt, index):
        """
        Overloads the paint method to draw the grid and other options for \
        this delegate.
        
        :param      painter | <QtGui.QPainter>
                    opt     | <QtGui.QStyleOptionItem>
                    index   | <QtGui.QModelIndex>
        """
        # prepare the painter
        painter.save()
        painter.resetTransform()

        # extract data from the tree
        tree = self.parent()
        column = index.column()
        item = tree.itemFromIndex(index)
        is_xtreeitem = isinstance(item, XTreeWidgetItem)
        hovered = False
        font = item.font(index.column())
        opt.font = font
        palette = tree.palette()

        painter.translate(opt.rect.x(), opt.rect.y())
        rect_w = opt.rect.width()
        rect_h = opt.rect.height()

        painter.setClipRect(0, 0, rect_w, rect_h)

        # grab the check information
        checkState = None
        size = opt.decorationSize
        value = unwrapVariant(index.data(QtCore.Qt.CheckStateRole))

        if value is not None:
            checkState = item.checkState(index.column())
            check_size = min(size.width(), size.height())
            check_size = min(14, check_size)
            checkRect = QtCore.QRect(2, (rect_h - check_size) / 2.0,
                                     check_size, check_size)
        else:
            checkRect = QtCore.QRect()

        # determine hovering options
        if tree.hoverMode() != xtreewidget.XTreeWidget.HoverMode.NoHover and \
           item.flags() & XTreeWidgetItem.ItemIsHoverable:

            # hover particular columns
            if tree.hoverMode() == xtreewidget.XTreeWidget.HoverMode.HoverItems and \
               item == tree.hoveredItem() and \
               column == tree.hoveredColumn():
                hovered = True

            # hover particular items
            elif tree.hoverMode() == xtreewidget.XTreeWidget.HoverMode.HoverRows and \
                 id(item) == id(tree.hoveredItem()):
                hovered = True

        # setup the decoration information
        if item.isExpanded() and is_xtreeitem and item.expandedIcon(column):
            icon = item.expandedIcon(column)

        elif hovered and tree.hoveredColumn() == column and \
             is_xtreeitem and \
             item.hoverIcon(column):
            icon = item.hoverIcon(column)

        else:
            icon = item.icon(column)

        if icon and not icon.isNull():
            size = icon.actualSize(opt.decorationSize)
            pixmap = icon.pixmap(size)

            if checkRect:
                x = checkRect.right() + 2
            else:
                x = 0

            y = 0
            w = opt.decorationSize.width()
            h = opt.decorationSize.height()

            x += 2
            y += (rect_h - size.height()) / 2.0

            decorationRect = QtCore.QRect(x, y, w, h)
        else:
            pixmap = QtGui.QPixmap()
            overlay = QtGui.QIcon()
            decorationRect = QtCore.QRect()

        if is_xtreeitem:
            overlay = item.iconOverlay(column)
            dec_w = decorationRect.width()
            dec_h = decorationRect.height()
            over_w = int(dec_w / 1.7)
            over_h = int(dec_h / 1.7)
            overlayRect = QtCore.QRect(decorationRect.right() - over_w,
                                       decorationRect.bottom() - over_h,
                                       over_w, over_h)
        else:
            overlay = QtGui.QPixmap()
            overlayRect = QtCore.QRect()

        # setup the coloring information
        bg = None
        fg = None

        if self.showHighlights() and tree.selectionModel().isSelected(index):
            palette = tree.palette()
            bg = QtGui.QBrush(palette.color(palette.Highlight))
            fg = QtGui.QBrush(palette.color(palette.HighlightedText))

        elif hovered:
            bg = tree.hoverBackground()
            fg = tree.hoverForeground()

            if is_xtreeitem:
                bg = item.hoverBackground(column, bg)
                fg = item.hoverForeground(column, fg)

        if not bg:
            bg_role = unwrapVariant(item.data(column,
                                              QtCore.Qt.BackgroundRole))
            if bg_role is not None:
                bg = item.background(column)
            else:
                bg = self.background(column)

        if not fg:
            fg_role = unwrapVariant(item.data(column,
                                              QtCore.Qt.ForegroundRole))
            if fg_role is not None:
                fg = item.foreground(column)
            else:
                fg = self.foreground(column)

        if not fg:
            fg = QtGui.QBrush(palette.color(palette.Text))

        # draw custom text
        mapper = self.displayMapper(column)
        if mapper:
            text = mapper(unwrapVariant(index.data(), ''))

        # draw specific type text
        else:
            data = unwrapVariant(index.data(QtCore.Qt.EditRole), None)

            # map the data to python
            if type(data) in (QtCore.QDate, QtCore.QDateTime, QtCore.QTime):
                data = data.toPython()

            # render a standard date format
            if type(data) == datetime.date:
                text = data.strftime(self.dateFormat())

            # render a standard datetime format
            elif type(data) == datetime.time:
                text = data.strftime(self.timeFormat())

            # render a standard datetime format
            elif type(data) == datetime.datetime:
                text = data.strftime(self.datetimeFormat())

            # draw standard text
            else:
                text = unwrapVariant(index.data(QtCore.Qt.DisplayRole), '')

        # display hint information
        if not text:
            hint = unwrapVariant(index.data(XTreeWidgetItem.HintRole))
            if hint:
                text = hint
                fg = QtGui.QBrush(palette.color(palette.Disabled,
                                                palette.Text))

        opt.displayAlignment = QtCore.Qt.Alignment(
            item.textAlignment(index.column()))
        if not opt.displayAlignment & (QtCore.Qt.AlignVCenter | \
                                       QtCore.Qt.AlignTop | QtCore.Qt.AlignBottom):
            opt.displayAlignment |= QtCore.Qt.AlignVCenter

        if decorationRect:
            x = decorationRect.right() + 5
        elif checkRect:
            x = checkRect.right() + 5
        else:
            x = 5

        w = rect_w - x - 5
        h = rect_h

        displayRect = QtCore.QRect(x, 0, w, h)

        # create the background rect
        backgroundRect = QtCore.QRect(0, 0, opt.rect.width(),
                                      opt.rect.height())

        # draw the item
        self.drawBackground(painter, opt, backgroundRect, bg)

        painter.setBrush(QtCore.Qt.NoBrush)
        painter.setPen(fg.color())

        self.drawCheck(painter, opt, checkRect, checkState)
        self.drawDecoration(painter, opt, decorationRect, pixmap)
        self.drawOverlay(painter, opt, overlayRect, overlay)
        self.drawDisplay(painter, opt, displayRect, text)
        self.drawGrid(painter, opt, backgroundRect, index)

        painter.restore()
예제 #17
0
    def __init__(self, parent):
        super(XLoggerWidget, self).__init__(parent)

        # set standard properties
        self.setReadOnly(True)
        self.setLineWrapMode(XLoggerWidget.NoWrap)

        # define custom properties
        self._clearOnClose = True
        self._handler = XLoggerWidgetHandler(self)
        self._currentMode = 'standard'
        self._blankCache = ''
        self._mutex = QtCore.QMutex()
        self._loggers = set()
        self._configurable = True
        self._destroyed = False

        # define the popup button for congfiguration
        self._configButton = XPopupButton(self)
        self._configButton.setIcon(
            QtGui.QIcon(resources.find('img/config.png')))
        self._configButton.setShadowed(True)

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

        bbox = popup.buttonBox()
        bbox.clear()
        bbox.addButton(QtGui.QDialogButtonBox.Ok)

        # set to a monospace font
        font = QtGui.QFont('Courier New')
        font.setPointSize(9)
        self.setFont(font)
        metrics = QtGui.QFontMetrics(font)
        self.setTabStopWidth(4 * metrics.width(' '))
        self.setAcceptRichText(False)

        # determine whether or not to use the light or dark configuration
        palette = self.palette()
        base = palette.color(palette.Base)
        avg = (base.red() + base.green() + base.blue()) / 3.0

        if avg < 160:
            colorSet = XLoggerColorSet.darkScheme()
        else:
            colorSet = XLoggerColorSet.lightScheme()

        self._colorSet = colorSet
        palette.setColor(palette.Text, colorSet.color('Standard'))
        palette.setColor(palette.Base, colorSet.color('Background'))
        self.setPalette(palette)

        # create the logger tree widget
        controls = XLoggerControls(self)
        self._configButton.setCentralWidget(controls)
        self._configButton.setDefaultAnchor(popup.Anchor.TopRight)

        # create connections
        self._handler.dispatch().messageLogged.connect(self.log)
        self.destroyed.connect(self.markDestroyed)
예제 #18
0
    def refresh(self):
        """
        Reloads the contents for this box based on the parameters.
        
        :return     <bool>
        """
        self.setDirty(False)
        self.blockSignals(True)
        self.setUpdatesEnabled(False)
        self.clear()

        locales = self._availableLocales
        if not locales:
            locales = self.allLocales()

        if not self.showLanguage():
            if self.isTranslated():
                sorter = lambda x: x.get_territory_name(base)
            else:
                sorter = lambda x: x.get_territory_name()
        else:
            if self.isTranslated():
                sorter = lambda x: x.get_language_name(base)
            else:
                sorter = lambda x: x.get_language_name()

        locales = sorted(locales, key=sorter)
        index = 0
        for i, locale in enumerate(locales):
            babel_locale = babel.Locale.parse(locale)
            code = '{0}_{1}'.format(babel_locale.language,
                                    babel_locale.territory)
            keys = {}
            if self.isTranslated():
                keys['lang'] = babel_locale.get_language_name(base)
                keys['territory'] = babel_locale.get_territory_name(base)
                keys['script'] = babel_locale.get_script_name(base)
            else:
                keys['lang'] = babel_locale.get_language_name()
                keys['territory'] = babel_locale.get_territory_name()
                keys['script'] = babel_locale.get_script_name()

            if self.showLanguage():
                opts = ''
                if self.showScriptName() and keys['script']:
                    opts += keys['script']
                if self.showTerritory() and keys['territory']:
                    if opts:
                        opts += ', '
                    opts += keys['territory']
                if opts:
                    opts = ' (' + opts + ')'

                label = keys['lang'] + opts

            elif self.showTerritory():
                label = keys['territory']
            else:
                label = code

            self.addItem(label)
            self.setItemData(i, wrapVariant(str(code)))

            name = babel_locale.territory.lower()
            ico = 'img/flags/{0}.png'.format(name)
            flag = QtGui.QIcon(resources.find(ico))
            if flag.isNull():
                ico = 'img/flags/_United Nations.png'
                flag = QtGui.QIcon(resources.find(ico))

            self.setItemIcon(i, flag)
            if code == self.baseLocale():
                index = i

        self.setCurrentIndex(index)
        self.setUpdatesEnabled(True)
        self.blockSignals(False)
예제 #19
0
 def _updateFrame(self):
     """
     Updates the frame for the given sender.
     """
     for col, mov in self._movies.items():
         self.setIcon(col, QtGui.QIcon(mov.currentPixmap()))