def setCollapsed(self, state):
        if self._collapsed == state:
            return

        self._collapsed = state

        # update the sizing constraints
        palette = self.palette()
        if state:
            height = 24
        else:
            height = self.expandedHeight()

        if self.isVisible() and self.parent() and self.isAnimated():
            # show the uncollapsed items collapsing
            if not state:
                # update the visible children based on the state
                for widget in self.children():
                    prop = unwrapVariant(widget.property('showCollapsed'))
                    if prop is not None:
                        widget.setVisible(bool(prop) == state)

            self._startHeight = self.height()
            self._targetHeight = height
            self._targetPercent = 0.0
            self.startTimer(10)
        else:
            # update the visible children based on the state
            for widget in self.children():
                prop = unwrapVariant(widget.property('showCollapsed'))
                if prop is not None:
                    widget.setVisible(bool(prop) == state)

            self.setFixedHeight(height)
 def setCollapsed(self, state):
     if self._collapsed == state:
         return
     
     self._collapsed = state
     
     # update the sizing constraints
     palette = self.palette()
     if state:
         height = 24
     else:
         height = self.expandedHeight()
     
     if self.isVisible() and self.parent() and self.isAnimated():
         # show the uncollapsed items collapsing
         if not state:
             # update the visible children based on the state
             for widget in self.children():
                 prop = unwrapVariant(widget.property('showCollapsed'))
                 if prop is not None:
                     widget.setVisible(bool(prop) == state)
         
         self._startHeight = self.height()
         self._targetHeight = height
         self._targetPercent = 0.0
         self.startTimer(10)
     else:
         # update the visible children based on the state
         for widget in self.children():
             prop = unwrapVariant(widget.property('showCollapsed'))
             if prop is not None:
                 widget.setVisible(bool(prop) == state)
         
         self.setFixedHeight(height)
예제 #3
0
 def __lt__(self, other):
     # make sure we're comparing apples to apples
     if not isinstance(other, QtGui.QTreeWidgetItem):
         return 0
         
     tree = self.treeWidget()
     if not tree:
         return 0
     
     col = tree.sortColumn()
     
     # compare sorting data
     mdata = unwrapVariant(self.data(col, self.SortRole))
     odata = unwrapVariant(other.data(col, self.SortRole))
     
     # compare editing data
     if mdata is None or odata is None:
         mdata = unwrapVariant(self.data(col, QtCore.Qt.EditRole))
         odata = unwrapVariant(other.data(col, QtCore.Qt.EditRole))
     
     if type(mdata) == type(odata) and not type(mdata) in (str, unicode):
         return mdata < odata
     
     # compare display data by natural sorting mechanisms on a string
     mdata = nativestring(self.text(col))
     odata = nativestring(other.text(col))
     
     return projex.sorting.natural(mdata, odata) == -1
예제 #4
0
 def sortData( self, column ):
     """
     Returns the data to be used when sorting.  If no sort data has been
     explicitly defined, then the value in the EditRole for this item's
     column will be used.
     
     :param      column | <int>
     
     :return     <variant>
     """
     value = unwrapVariant(self.data(column, self.SortRole))
     if value is None:
         return None
     return unwrapVariant(self.data(column, QtCore.Qt.EditRole))
예제 #5
0
 def restoreSettings(self, settings):
     """
     Restores the current structure of the view widget from the inputed \
     settings instance.
     
     :param      settings | <QSettings>
     """
     key     = self.objectName()
     value   = unwrapVariant(settings.value('%s/profile' % key))
     
     if not value:
         self.reset(force = True)
         return False
         
     profile = value
     
     # restore the view type settings
     for viewType in self.viewTypes():
         viewType.restoreGlobalSettings(settings)
     
     # restore the profile
     self.restoreProfile(XViewProfile.fromString(profile))
     
     if not self.views():
         self.reset(force = True)
     
     return True
예제 #6
0
    def restoreSettings(self, settings):
        """
        Restores the current structure of the view widget from the inputed \
        settings instance.
        
        :param      settings | <QSettings>
        """
        key = self.objectName()
        value = unwrapVariant(settings.value('%s/profile' % key))

        if not value:
            self.reset(force=True)
            return False

        profile = value

        # restore the view type settings
        for viewType in self.viewTypes():
            viewType.restoreGlobalSettings(settings)

        # restore the profile
        self.restoreProfile(XViewProfile.fromString(profile))

        if not self.views():
            self.reset(force=True)

        return True
예제 #7
0
 def setEditorData(self, editor, index):
     """
     Updates the editor with the model data.
     
     :param      editor | <QtGui.QWidget>
                 index  | <QtGui.QModelIndex>
     """
     data = unwrapVariant(index.data())
     editor.setCurrentIndex(editor.findText(data))
예제 #8
0
 def setEditorData(self, editor, index):
     """
     Updates the editor with the model data.
     
     :param      editor | <QtGui.QWidget>
                 index  | <QtGui.QModelIndex>
     """
     data = unwrapVariant(index.data())
     editor.setCurrentIndex(editor.findText(data))
예제 #9
0
 def updateLevels(self):
     levels = []
     tree = self.uiLevelTREE
     tree.blockSignals(True)
     for item in tree.checkedItems():
         level = unwrapVariant(item.data(0, QtCore.Qt.UserRole))
         if level is not None:
             levels.append(level)
     tree.blockSignals(False)
     self._loggerWidget.setActiveLevels(levels)
예제 #10
0
    def restoreSettings(self, settings):
        """
        Restores the settings for this logger from the inputed settings.
        
        :param      <QtCore.QSettings>
        """
        val = unwrapVariant(settings.value('format'))
        if val:
            self.setFormatText(val)

        levels = unwrapVariant(settings.value('levels'))
        if levels:
            self.setActiveLevels(map(int, levels.split(',')))

        logger_levels = unwrapVariant(settings.value('loggerLevels'))
        if logger_levels:
            for key in logger_levels.split(','):
                logger, lvl = key.split(':')
                lvl = int(lvl)
                self.setLoggerLevel(logger, lvl)
예제 #11
0
 def restoreSettings(self, settings):
     """
     Restores the settings for this logger from the inputed settings.
     
     :param      <QtCore.QSettings>
     """
     val = unwrapVariant(settings.value('format'))
     if val:
         self.setFormatText(val)
     
     levels = unwrapVariant(settings.value('levels'))
     if levels:
         self.setActiveLevels(map(int, levels.split(',')))
     
     logger_levels = unwrapVariant(settings.value('loggerLevels'))
     if logger_levels:
         for key in logger_levels.split(','):
             logger, lvl = key.split(':')
             lvl = int(lvl)
             self.setLoggerLevel(logger, lvl)
예제 #12
0
 def restoreSettings(self, settings):
     """
     Restores the settings for this logger from the inputed settings.
     
     :param      <QtCore.QSettings>
     """
     levels = unwrapVariant(settings.value('levels'))
     if levels:
         self.setActiveLevels(map(int, levels.split(',')))
     
     logger_levels = unwrapVariant(settings.value('loggerLevels'))
     if logger_levels:
         for key in logger_levels.split(','):
             logger, lvl = key.split(':')
             lvl = int(lvl)
             self.setLoggerLevel(logger, lvl)
     
     filt = unwrapVariant(settings.value('filter'))
     if filt:
         self.uiFilterTXT.setText(filt)
     self.uiRecordTREE.restoreSettings(settings)
예제 #13
0
    def restoreSettings(self, settings):
        """
        Restores the settings for this logger from the inputed settings.
        
        :param      <QtCore.QSettings>
        """
        levels = unwrapVariant(settings.value('levels'))
        if levels:
            self.setActiveLevels(map(int, levels.split(',')))

        logger_levels = unwrapVariant(settings.value('loggerLevels'))
        if logger_levels:
            for key in logger_levels.split(','):
                logger, lvl = key.split(':')
                lvl = int(lvl)
                self.setLoggerLevel(logger, lvl)

        filt = unwrapVariant(settings.value('filter'))
        if filt:
            self.uiFilterTXT.setText(filt)
        self.uiRecordTREE.restoreSettings(settings)
예제 #14
0
 def showEvent(self, event):
     super(XLogRecordControls, self).showEvent(event)
     
     # update the active levels
     lvls = self._loggerWidget.activeLevels()
     tree = self.uiLevelTREE
     tree.blockSignals(True)
     for item in tree.topLevelItems():
         if unwrapVariant(item.data(0, QtCore.Qt.UserRole)) in lvls:
             item.setCheckState(0, QtCore.Qt.Checked)
         else:
             item.setCheckState(0, QtCore.Qt.Unchecked)
     tree.blockSignals(False)
 def timerEvent(self, event):
     self._targetPercent += 0.05
     if self._targetPercent >= 1:
         self.killTimer(event.timerId())
         self.setFixedHeight(self._targetHeight)
         
         # always show the logger widget
         if self.isCollapsed():
             # update the visible children based on the state
             for widget in self.children():
                 prop = unwrapVariant(widget.property('showCollapsed'))
                 if prop is not None:
                     widget.setVisible(bool(prop) == self.isCollapsed())
         
     else:
         delta = (self._startHeight - self._targetHeight) * self._targetPercent
         self.setFixedHeight(self._startHeight - delta)
    def timerEvent(self, event):
        self._targetPercent += 0.05
        if self._targetPercent >= 1:
            self.killTimer(event.timerId())
            self.setFixedHeight(self._targetHeight)

            # always show the logger widget
            if self.isCollapsed():
                # update the visible children based on the state
                for widget in self.children():
                    prop = unwrapVariant(widget.property('showCollapsed'))
                    if prop is not None:
                        widget.setVisible(bool(prop) == self.isCollapsed())

        else:
            delta = (self._startHeight -
                     self._targetHeight) * self._targetPercent
            self.setFixedHeight(self._startHeight - delta)
예제 #17
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()
예제 #18
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()