示例#1
0
 def saveSettings(self, settings):
     """
     Saves the logging settings for this widget to the inputed settings.
     
     :param      <QtCore.QSettings>
     """
     lvls = []
     for logger, level in self.loggerLevels().items():
         lvls.append('{0}:{1}'.format(logger, level))
     
     settings.setValue('filter', wrapVariant(self.uiFilterTXT.text()))
     settings.setValue('levels', wrapVariant(','.join(map(str, self.activeLevels()))))
     settings.setValue('loggerLevels', wrapVariant(','.join(lvls)))
     
     self.uiRecordTREE.saveSettings(settings)
示例#2
0
 def __init__(self, loggerWidget):
     super(XLoggerControls, self).__init__(loggerWidget)
     
     # load the user interface
     projexui.loadUi(__file__, self)
     
     self._url = 'https://docs.python.org/2/library/logging.html#logrecord-attributes'
     self._loggerWidget = loggerWidget
     self.uiLoggerTREE.setLoggerWidget(loggerWidget)
     self.uiFormatTXT.setText(loggerWidget.formatText())
     
     # load the levels
     if 'designer' not in sys.executable:
         tree = self.uiLevelTREE
         from projexui.widgets.xloggerwidget import XLoggerWidget
         items = sorted(XLoggerWidget.LoggingMap.items())
         for i, (level, data) in enumerate(items):
             item = XTreeWidgetItem(tree, [projex.text.pretty(data[0])])
             item.setFixedHeight(22)
             item.setData(0, QtCore.Qt.UserRole, wrapVariant(level))
             item.setCheckState(0, QtCore.Qt.Unchecked)
     
     # create connections
     self.uiFormatTXT.textChanged.connect(loggerWidget.setFormatText)
     self.uiLevelTREE.itemChanged.connect(self.updateLevels)
     self.uiHelpBTN.clicked.connect(self.showHelp)
示例#3
0
    def saveSettings(self, settings):
        """
        Saves the logging settings for this widget to the inputed settings.
        
        :param      <QtCore.QSettings>
        """
        lvls = []
        for logger, level in self.loggerLevels().items():
            lvls.append('{0}:{1}'.format(logger, level))

        settings.setValue('filter', wrapVariant(self.uiFilterTXT.text()))
        settings.setValue('levels',
                          wrapVariant(','.join(map(str, self.activeLevels()))))
        settings.setValue('loggerLevels', wrapVariant(','.join(lvls)))

        self.uiRecordTREE.saveSettings(settings)
示例#4
0
 def setSortData( self, column, data ):
     """
     Sets the sorting information for the inputed column to the given data.
     
     :param      column | <int>
                 data   | <variant>
     """
     self.setData(column, self.SortRole, wrapVariant(data))
示例#5
0
 def setModelData(self, editor, model, index):
     """
     Updates the item with the new data value.
     
     :param      editor  | <QtGui.QWidget>
                 model   | <QtGui.QModel>
                 index   | <QtGui.QModelIndex>
     """
     value = editor.currentText()
     model.setData(index, wrapVariant(value))
示例#6
0
 def setModelData(self, editor, model, index):
     """
     Updates the item with the new data value.
     
     :param      editor  | <QtGui.QWidget>
                 model   | <QtGui.QModel>
                 index   | <QtGui.QModelIndex>
     """
     value = editor.currentText()
     model.setData(index, wrapVariant(value))
示例#7
0
    def saveSettings(self, settings):
        """
        Records the current structure of the view widget to the inputed \
        settings instance.
        
        :param      settings | <QSettings>
        """
        # record the profile
        profile = self.saveProfile()
        key = self.objectName()

        settings.setValue('%s/profile' % key, wrapVariant(profile.toString()))

        # record the view type settings
        for viewType in self.viewTypes():
            viewType.saveGlobalSettings(settings)
示例#8
0
 def saveSettings(self, settings):
     """
     Records the current structure of the view widget to the inputed \
     settings instance.
     
     :param      settings | <QSettings>
     """
     # record the profile
     profile = self.saveProfile()
     key     = self.objectName()
     
     settings.setValue('%s/profile' % key, wrapVariant(profile.toString()))
     
     # record the view type settings
     for viewType in self.viewTypes():
         viewType.saveGlobalSettings(settings)
示例#9
0
    def saveXml(self, xml):
        """
        Saves the logging settings for this widget to XML format.
        
        :param      xml | <xml.etree.ElementTree.Element>
        """
        lvls = []
        for logger, level in self.loggerLevels().items():
            lvls.append('{0}:{1}'.format(logger, level))

        xlevels = ElementTree.SubElement(xml, 'levels')
        xlevels.text = ','.join(map(str, self.activeLevels()))

        xloggerlevels = ElementTree.SubElement(xml, 'logger_levels')
        xloggerlevels.text = ','.join(lvls)

        xml.set('filter', wrapVariant(self.uiFilterTXT.text()))

        xtree = ElementTree.SubElement(xml, 'tree')
        self.uiRecordTREE.saveXml(xtree)
示例#10
0
 def saveXml(self, xml):
     """
     Saves the logging settings for this widget to XML format.
     
     :param      xml | <xml.etree.ElementTree.Element>
     """
     lvls = []
     for logger, level in self.loggerLevels().items():
         lvls.append('{0}:{1}'.format(logger, level))
     
     xlevels = ElementTree.SubElement(xml, 'levels')
     xlevels.text = ','.join(map(str, self.activeLevels()))
     
     xloggerlevels = ElementTree.SubElement(xml, 'logger_levels')
     xloggerlevels.text = ','.join(lvls)
     
     xml.set('filter', wrapVariant(self.uiFilterTXT.text()))
     
     xtree = ElementTree.SubElement(xml, 'tree')
     self.uiRecordTREE.saveXml(xtree)
示例#11
0
 def __init__(self, loggerWidget):
     super(XLogRecordControls, self).__init__(loggerWidget)
     
     # load the user interface
     projexui.loadUi(__file__, self)
     
     self._loggerWidget = loggerWidget
     self.uiLoggerTREE.setLoggerWidget(loggerWidget)
     
     # load the levels
     if 'designer' not in sys.executable:
         tree = self.uiLevelTREE
         from projexui.widgets.xloggerwidget import XLoggerWidget
         items = sorted(XLoggerWidget.LoggingMap.items())
         for i, (level, data) in enumerate(items):
             item = XTreeWidgetItem(tree, [projex.text.pretty(data[0])])
             item.setFixedHeight(22)
             item.setData(0, QtCore.Qt.UserRole, wrapVariant(level))
             item.setCheckState(0, QtCore.Qt.Unchecked)
     
     # create connections
     self.uiLevelTREE.itemChanged.connect(self.updateLevels)
示例#12
0
 def createEditor(self, parent, option, index):
     """
     Creates a new editor for the given index parented to the inputed widget.
     
     :param      parent | <QtGui.QWidget>
                 option | <QtGui.QStyleOption>
                 index  | <QtGui.QModelIndex>
     
     :return     <QWidget> || None
     """
     if index.column() != 1:
         return None
     
     editor = QtGui.QComboBox(parent)
     
     # load the levels
     items = sorted(XLoggerWidget.LoggingMap.items())
     for i, (level, data) in enumerate(items):
         editor.addItem(projex.text.pretty(data[0]))
         editor.setItemData(i, wrapVariant(level))
     
     return editor
示例#13
0
    def createEditor(self, parent, option, index):
        """
        Creates a new editor for the given index parented to the inputed widget.
        
        :param      parent | <QtGui.QWidget>
                    option | <QtGui.QStyleOption>
                    index  | <QtGui.QModelIndex>
        
        :return     <QWidget> || None
        """
        if index.column() != 1:
            return None

        editor = QtGui.QComboBox(parent)

        # load the levels
        items = sorted(XLoggerWidget.LoggingMap.items())
        for i, (level, data) in enumerate(items):
            editor.addItem(projex.text.pretty(data[0]))
            editor.setItemData(i, wrapVariant(level))

        return editor
示例#14
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)
示例#15
0
    def __init__(self, parent, record):
        super(XLogRecordItem, self).__init__(parent)

        # set default properties
        self.setFixedHeight(22)

        created = datetime.datetime.fromtimestamp(record.created)

        self.setData(0, QtCore.Qt.DisplayRole, wrapVariant(record.levelname))
        self.setData(1, QtCore.Qt.DisplayRole, wrapVariant(record.levelno))
        self.setData(2, QtCore.Qt.DisplayRole, wrapVariant(record.name))
        self.setData(3, QtCore.Qt.DisplayRole, wrapVariant(str(created)))
        self.setData(4, QtCore.Qt.DisplayRole, wrapVariant(record.message))
        self.setData(
            5, QtCore.Qt.DisplayRole,
            wrapVariant('% 10.4f' % (record.relativeCreated / 1000.0)))
        self.setData(6, QtCore.Qt.DisplayRole, wrapVariant(record.filename))
        self.setData(7, QtCore.Qt.DisplayRole, wrapVariant(record.module))
        self.setData(8, QtCore.Qt.DisplayRole, wrapVariant(record.funcName))
        self.setData(9, QtCore.Qt.DisplayRole, wrapVariant(record.lineno))
        self.setData(10, QtCore.Qt.DisplayRole, wrapVariant(record.pathname))
        self.setData(11, QtCore.Qt.DisplayRole, wrapVariant(record.process))
        self.setData(12, QtCore.Qt.DisplayRole,
                     wrapVariant(record.processName))
        self.setData(13, QtCore.Qt.DisplayRole, wrapVariant(record.thread))
        self.setData(14, QtCore.Qt.DisplayRole, wrapVariant(record.threadName))

        clr = XLogRecordItem.Colors.get(record.levelno)
        if clr:
            for i in range(self.columnCount()):
                self.setForeground(i, QtGui.QColor(clr))

        # create custom properties
        self._record = record
示例#16
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)
示例#17
0
 def __init__(self, parent, record):
     super(XLogRecordItem, self).__init__(parent)
     
     # set default properties
     self.setFixedHeight(22)
     
     created = datetime.datetime.fromtimestamp(record.created)
     
     self.setData( 0, QtCore.Qt.DisplayRole, wrapVariant(record.levelname))
     self.setData( 1, QtCore.Qt.DisplayRole, wrapVariant(record.levelno))
     self.setData( 2, QtCore.Qt.DisplayRole, wrapVariant(record.name))
     self.setData( 3, QtCore.Qt.DisplayRole, wrapVariant(str(created)))
     self.setData( 4, QtCore.Qt.DisplayRole, wrapVariant(record.message))
     self.setData( 5, QtCore.Qt.DisplayRole, wrapVariant('% 10.4f' % (record.relativeCreated / 1000.0)))
     self.setData( 6, QtCore.Qt.DisplayRole, wrapVariant(record.filename))
     self.setData( 7, QtCore.Qt.DisplayRole, wrapVariant(record.module))
     self.setData( 8, QtCore.Qt.DisplayRole, wrapVariant(record.funcName))
     self.setData( 9, QtCore.Qt.DisplayRole, wrapVariant(record.lineno))
     self.setData(10, QtCore.Qt.DisplayRole, wrapVariant(record.pathname))
     self.setData(11, QtCore.Qt.DisplayRole, wrapVariant(record.process))
     self.setData(12, QtCore.Qt.DisplayRole, wrapVariant(record.processName))
     self.setData(13, QtCore.Qt.DisplayRole, wrapVariant(record.thread))
     self.setData(14, QtCore.Qt.DisplayRole, wrapVariant(record.threadName))
     
     clr = XLogRecordItem.Colors.get(record.levelno)
     if clr:
         for i in range(self.columnCount()):
             self.setForeground(i, QtGui.QColor(clr))
     
     # create custom properties
     self._record = record