def restoreDataSet( settings, key, dataSet ): """ Restores the dataset settings to the inputed data set for the given key. :param settings | <QSettings> key | <str> dataSet | <projex.dataset.DataSet> """ for datakey in dataSet.keys(): vtype = unwrapVariant(settings.value('%s/%s/type' % (key, datakey))) value = unwrapVariant(settings.value('%s/%s/value' % (key, datakey))) if ( vtype is None ): continue vtype = nativestring(vtype) if ( vtype in _dataValueTypes ): datavalue = _dataValueTypes[vtype][1](value) else: logger.warning('Could not restore %s' % vtype) continue if ( type(datavalue).__name__ == 'QString' ): datavalue = unicode(datavalue) dataSet.setValue(datakey, datavalue)
def setCurrentPanel(self, panel): super(XViewTabMenu, self).setCurrentPanel(panel) # update the current tab based on what view type it is viewType = '' grp = -1 if panel is not None and panel.currentView(): viewType = panel.currentView().viewName() grp = panel.currentView().viewingGroup() self._panelGroup.blockSignals(True) for act in self._panelGroup.actions(): act.setChecked(viewType == act.text()) self._panelGroup.blockSignals(False) self._groupingGroup.blockSignals(True) for act in self._groupingGroup.actions(): act.setChecked(grp == unwrapVariant(act.data())) self._groupingGroup.blockSignals(False) self._pluginMenu.setCurrentPanel(panel) self._groupingMenu.setEnabled(grp != -1) if panel: self._hideAction.setChecked(panel.hideTabsWhenLocked()) self._hideAction.setEnabled(True) else: self._hideAction.setEnabled(False)
def restoreSettings( self, settings ): """ Restores the current structure of the view widget from the inputed \ settings instance. :param settings | <QSettings> """ key = self.objectName() value = qt.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
def recordAt(self, index): """ Returns the record at the inputed index. :return <orb.Table> || None """ return unwrapVariant(self.itemData(index, Qt.UserRole))
def updateLogger( self ): """ Updates which logger is being used by the system. """ curr_text = str(self.uiLoggerDDL.currentText()) if ( curr_text == ROOT_LOGGER_TEXT ): logger = logging.root elif ( not curr_text.startswith('---') ): logger = logging.getLogger(curr_text) else: logger = None self.uiConsoleEDIT.setLogger(logger) if ( not logger ): return level = logger.getEffectiveLevel() self.uiLevelDDL.blockSignals(True) for i in range(self.uiLevelDDL.count()): if ( unwrapVariant(self.uiLevelDDL.itemData(i)) == level ): self.uiLevelDDL.setCurrentIndex(i) break self.uiLevelDDL.blockSignals(False)
def apply( self ): """ Applies the scheme to the current application. """ font = self.value('font') try: font.setPointSize(self.value('fontSize')) # errors in linux for some reason except TypeError: pass palette = self.value('colorSet').palette() if ( unwrapVariant(QApplication.instance().property('useScheme')) ): QApplication.instance().setFont(font) QApplication.instance().setPalette(palette) # hack to support MDI Areas for widget in QApplication.topLevelWidgets(): for area in widget.findChildren(QMdiArea): area.setPalette(palette) else: logger.debug('The application doesnt have the useScheme property.')
def setCurrentPanel( self, panel ): self._currentPanel = panel # update the current tab based on what view type it is viewType = '' grp = -1 if ( panel is not None and panel.currentView() ): viewType = panel.currentView().viewName() grp = panel.currentView().viewingGroup() self._panelGroup.blockSignals(True) for act in self._panelGroup.actions(): act.setChecked(viewType == act.text()) self._panelGroup.blockSignals(False) self._groupingGroup.blockSignals(True) for act in self._groupingGroup.actions(): act.setChecked(grp == qt.unwrapVariant(act.data())) self._groupingGroup.blockSignals(False) if ( self._groupingMenu ): self._groupingMenu.setEnabled(grp != -1) if ( self._interfaceMenu ): self._interfaceMenu.setCurrentPanel(panel)
def addItems(self, menus, processed=None): """ Adds items to the completion tree from the menu. :param menus | [<QMenu>, ..] procesed | [<QAction>, ..] || None """ if processed is None: processed = [] for menu in menus: for action in menu.actions(): # since we can have 1 action in more than 1 submenu, we # will want to make sure we're only adding a unique one # so we don't have duplicates text = nativestring(action.text()) if text in processed or action.isSeparator(): continue processed.append(text) if text and unwrapVariant(action.data()) != 'menu': item = XTreeWidgetItem(self._completer, [text]) item.setFixedHeight(20) item.setIcon(0, action.icon()) item.setToolTip(0, action.toolTip()) item.setData(0, Qt.UserRole, wrapVariant(action))
def restoreSettings(self, settings): hist = [] settings.beginGroup('console') for key in sorted(settings.childKeys()): hist.append(unwrapVariant(settings.value(key))) settings.endGroup() self._history = hist
def emitFileTriggered( self, action ): """ Emits that the filename has been triggered for the inputed action. :param action | <QAction> """ if not self.signalsBlocked(): filename = nativestring(unwrapVariant(action.data())) self.fileTriggered.emit(filename)
def triggerItem(self, item): """ Triggers the item by calling its action's toggled state to display or hide the dock panel. :param item | <QtGui.QTreeWidgetItem> """ if not item: return # emit the trigger action self._triggerText = item.text(0) self._completer.hide() self._completer.setCurrentItem(None) self.parent().hide() # trigger the action unwrapVariant(item.data(0, Qt.UserRole)).trigger()
def restoreSettings(self, settings): """ Restores the files for this menu from the settings. :param settings | <QSettings> """ value = unwrapVariant(settings.value('recent_files')) if value: self.setFilenames(value.split(os.path.pathsep))
def registerToDataTypes( cls ): """ Registers this class as a valid datatype for saving and loading via the datatype system. """ from projexui.xdatatype import registerDataType registerDataType(cls.__name__, lambda pyvalue: pyvalue.toString(), lambda qvariant: cls.fromString(unwrapVariant(qvariant)))
def assignGroup(self, action): """ Assigns the group for the given action to the current view. :param action | <QAction> """ grp = unwrapVariant(action.data()) view = self._currentPanel.currentView() view.setViewingGroup(grp)
def dataCollector( tree, items ): data = QMimeData() actions = [] for item in items: actions.append(str(qt.unwrapVariant(item.data(0, Qt.UserRole)))) actionstr = ','.join(actions) data.setData('application/x-actions', QByteArray(actionstr)) return data
def value(self, key, default=None): """ Returns the value for the given key for this settings instance. :return <variant> """ if self._customFormat: return self._customFormat.value(key, default) else: return unwrapVariant(super(XSettings, self).value(key))
def adjustLevel( self ): """ Matches the current level to the level from the editor. """ level = self.uiLevelDDL.itemData(self.uiLevelDDL.currentIndex()) level = unwrapVariant(level) logger = self.uiConsoleEDIT.logger() logger.setLevel(level) self.adjustLoggerIcons()
def restoreSettings(self, settings, merge=False, loadProfile=True): """ Restores this profile from settings. :param settings | <QSettings> """ value = unwrapVariant(settings.value('profile_toolbar')) if not value: return self.loadString(value, merge, loadProfile=loadProfile)
def loadValues(self, values): """ Loads the values from the inputed dictionary to the widget. :param values | <dict> """ table = self.tableType() if table: schema = table.schema() else: schema = None process = [] for widget in self.findChildren(QWidget): prop = widget.property('columnName') if not prop: continue order = widget.property('columnOrder') if order: order = unwrapVariant(order) else: order = 10000000 process.append((order, widget, prop)) process.sort() for order, widget, prop in process: columnName = nativestring(unwrapVariant(prop, '')) if not columnName: continue if isinstance(widget, XEnumBox) and schema: column = schema.column(columnName) if column.enum() is not None: widget.setEnum(column.enum()) if columnName in values: projexui.setWidgetValue(widget, values.get(columnName))
def emitCurrentRecordChanged(self): """ Emits the current record changed signal for this combobox, provided \ the signals aren't blocked. """ record = unwrapVariant(self.itemData(self.currentIndex(), Qt.UserRole)) if not Table.recordcheck(record): record = None self._currentRecord = record if not self.signalsBlocked(): self._changedRecord = record self.currentRecordChanged.emit(record)
def toggleDataset(self, state, dataset=None): """ Toggles the dataset based on the given action or dataset. :param state | <bool> dataset | <XChartDataset> """ if dataset is None and self.sender(): dataset = unwrapVariant(self.sender().data()) dataset.setVisible(state) self._dataChanged = True self.recalculate()
def restoreSettings(self, settings): """ Restores settings from the application. :param settings | <QSettings> """ settings.beginGroup(self.objectName()) curr_prof = None curr_name = qt.unwrapVariant(settings.value('current')) profiles = [] for prof_name in settings.childGroups(): settings.beginGroup(prof_name) prof_str = qt.unwrapVariant(settings.value('profile')) profile = XViewProfile.fromString(prof_str) profile.setName(prof_name) if (prof_name == curr_name): curr_prof = profile profiles.append(profile) settings.endGroup() self.blockSignals(True) self._profileCombo.blockSignals(True) self.setProfiles(profiles) if (curr_prof): self.setCurrentProfile(curr_prof) self._profileCombo.blockSignals(False) self.blockSignals(False) settings.endGroup()
def restoreSettings(self, settings): """ Restores settings from the application. :param settings | <QSettings> """ settings.beginGroup(self.objectName()) curr_prof = None curr_name = unwrapVariant(settings.value('current')) profiles = [] for prof_name in settings.childGroups(): settings.beginGroup(prof_name) prof_str = unwrapVariant(settings.value('profile')) profile = XViewProfile.fromString(prof_str) profile.setName(prof_name) if prof_name == curr_name: curr_prof = profile profiles.append(profile) settings.endGroup() self.blockSignals(True) self._profileCombo.blockSignals(True) self.setProfiles(profiles) if curr_prof: self.setCurrentProfile(curr_prof) self._profileCombo.blockSignals(False) self.blockSignals(False) settings.endGroup()
def setCurrentRecord(self, record, autoAdd=False): """ Sets the index for this combobox to the inputed record instance. :param record <orb.Table> :return <bool> success """ if record is not None and not Table.recordcheck(record): return False # don't reassign the current record # clear the record if record is None: self._currentRecord = None blocked = self.signalsBlocked() self.blockSignals(True) self.setCurrentIndex(-1) self.blockSignals(blocked) if not blocked: self.currentRecordChanged.emit(None) return True elif record == self.currentRecord(): return False self._currentRecord = record found = False blocked = self.signalsBlocked() self.blockSignals(True) for i in range(self.count()): stored = unwrapVariant(self.itemData(i, Qt.UserRole)) if stored == record: self.setCurrentIndex(i) found = True break if not found and autoAdd: self.addRecord(record) self.setCurrentIndex(self.count() - 1) self.blockSignals(blocked) if not blocked: self.currentRecordChanged.emit(record) return False
def pathFromIndex(self, index): """ Returns the joined path from the given model index. This will join together the full path with periods. :param index | <QModelIndex> :return <str> """ out = [] while index and index.isValid(): out.append(str(unwrapVariant(index.data()))) index = self._model.parent(index) return self.joiner().join(reversed(out))
def pathFromIndex(self, index): """ Returns the joined path from the given model index. This will join together the full path with periods. :param index | <QModelIndex> :return <str> """ out = [] while index and index.isValid(): out.append(nativestring(unwrapVariant(index.data()))) index = self._model.parent(index) return self.joiner().join(reversed(out))
def updateCurrentValue(self, value): """ Implementation of QAbstractAnimation's abstract method, called when the value is changed internally and is supposed to update the python object's value. :param value | <QVariant> || <variant> """ try: method = getattr(self._targetObject, self._setter) except AttributeError: return try: method(unwrapVariant(value)) except: return
def updateItemData(self, item, index): """ Updates the item information from the tree. :param item | <XGanttWidgetItem> index | <int> """ value = qt.unwrapVariant(item.data(index, Qt.EditRole)) if type(value) == QDateTime: value = value.date() item.setData(index, Qt.EditRole, qt.wrapVariant(value)) if type(value) == QDate: value = value.toPython() columnName = self.treeWidget().columnOf(index) item.setProperty(columnName, value) item.sync()
def saveXml( self, xparent, item ): """ Saves the information from the tree item to xml. :param xparent | <xml.etree.ElementTree.Element> item | <QTreeWidgetItem> """ key = str(qt.unwrapVariant(item.data(0, Qt.UserRole))) if ( key == 'separator' ): ElementTree.SubElement(xparent, 'separator') elif ( key == 'menu' ): elem = ElementTree.SubElement(xparent, 'menu') elem.set('title', str(item.text(0))) for c in range(item.childCount()): self.saveXml(elem, item.child(c)) else: elem = ElementTree.SubElement(xparent, 'action') elem.set('name', key)
def saveXml(self, xparent, item): """ Saves the information from the tree item to xml. :param xparent | <xml.etree.ElementTree.Element> item | <QTreeWidgetItem> """ key = nativestring(unwrapVariant(item.data(0, Qt.UserRole))) if (key == 'separator'): ElementTree.SubElement(xparent, 'separator') elif (key == 'menu'): elem = ElementTree.SubElement(xparent, 'menu') elem.set('title', nativestring(item.text(0))) for c in range(item.childCount()): self.saveXml(elem, item.child(c)) else: elem = ElementTree.SubElement(xparent, 'action') elem.set('name', key)
def propertyWidgetMap(self): """ Returns the mapping for this page between its widgets and its scaffold property. :return {<projex.scaffold.Property>: <QtGui.QWidget>, ..} """ out = {} scaffold = self.scaffold() # initialize the scaffold properties for widget in self.findChildren(QtGui.QWidget): propname = unwrapVariant(widget.property('propertyName')) if not propname: continue prop = scaffold.property(propname) if not prop: continue out[prop] = widget return out
def refreshUi( self ): """ Load the plugin information to the interface. """ dataSet = self.dataSet() if not dataSet: return False # lookup widgets based on the data set information for widget in self.findChildren(QWidget): prop = unwrapVariant(widget.property('dataName')) if prop is None: continue # update the data for the widget prop_name = str(prop) if prop_name in dataSet: value = dataSet.value(prop_name) projexui.setWidgetValue(widget, value) return True
def refreshUi( self ): """ Load the plugin information to the interface. """ dataSet = self.dataSet() if not dataSet: return False # lookup widgets based on the data set information for widget in self.findChildren(QWidget): prop = unwrapVariant(widget.property('dataName')) if prop is None: continue # update the data for the widget prop_name = nativestring(prop) if prop_name in dataSet: value = dataSet.value(prop_name) projexui.setWidgetValue(widget, value) return True
def exportTreeItem(self, sheet, cols, item): """ Exports the inputed item to the given Excel worksheet for the given visible columns. :param sheet | <xlwt.WorkSheet> cols | [<int>, ..] item | <QTreeWidgetItem> """ # export item information for c, col in enumerate(cols): data = unwrapVariant(item.data(Qt.EditRole, col)) if data: sheet.write(self._currrow, c, nativestring(data)) else: sheet.write(self._currrow, c, nativestring(item.text(col))) self._currrow += 1 # export children as rows for c in range(item.childCount()): self.exportTreeItem(sheet, cols, item.child(c))
def updateItemData(self, item, index): """ Updates the item information from the tree. :param item | <XGanttWidgetItem> index | <int> """ from projexui.widgets.xganttwidget.xganttwidgetitem import XGanttWidgetItem if not isinstance(item, XGanttWidgetItem): return value = unwrapVariant(item.data(index, Qt.EditRole)) if type(value) == QDateTime: value = value.date() item.setData(index, Qt.EditRole, wrapVariant(value)) if type(value) == QDate: value = value.toPython() columnName = self.treeWidget().columnOf(index) item.setProperty(columnName, value) item.sync()
def save( self ): """ Saves the ui information to the data for this widget's data set. :return <bool> saved """ dataSet = self.dataSet() if ( not dataSet ): return True # lookup widgets based on the data set information for widget in self.findChildren(QWidget): prop = unwrapVariant(widget.property('dataName')) if prop is None: continue # update the data for the dataset value, success = projexui.widgetValue(widget) if not success: continue dataSet.setValue(prop, value) return self.plugin().save()
def saveValues(self): """ Generates a dictionary of values from the widgets in this editor that will be used to save the values on its record. :return {<str> columnName: <variant> value, ..} """ output = {} for widget in self.findChildren(QWidget): prop = widget.property('columnName') if not prop: continue columnName = str(unwrapVariant(prop, '')) if (not columnName): continue value, success = projexui.widgetValue(widget) if (not success): continue # convert from values to standard python values if (isinstance(value, QDateTime)): value = value.toPyDateTime() elif (isinstance(value, QDate)): value = value.toPyDate() elif (isinstance(value, QTime)): value = value.toPyTime() elif (type(value).__name__ == 'QString'): value = str(value) output[columnName] = value return output
def decodeFont(qvariant): font = QtGui.QFont() font.fromString(qt.unwrapVariant(qvariant)) return font
if (datatype in _dataValueTypes): datavalue = _dataValueTypes[datatype][0](value) else: datavalue = value settings.setValue('%s/%s/type' % (key, datakey), qt.wrapVariant(datatype)) settings.setValue('%s/%s/value' % (key, datakey), qt.wrapVariant(datavalue)) #------------------------------------------------------------------------------- # register getter/setter value types registerDataType('bool', lambda pyvalue: int(pyvalue), lambda qvariant: qt.unwrapVariant(qvariant, False)) registerDataType('int', lambda pyvalue: int(pyvalue), lambda qvariant: qt.unwrapVariant(qvariant, 0)) registerDataType('float', lambda pyvalue: float(pyvalue), lambda qvariant: qt.unwrapVariant(qvariant, 0.0)) registerDataType('str', lambda pyvalue: str(pyvalue), lambda qvariant: str(qt.unwrapVariant(qvariant, ''))) registerDataType('unicode', lambda pyvalue: unicode(pyvalue), lambda qvariant: unicode(qt.unwrapVariant(qvariant, ''))) def decodeFont(qvariant):
if (datatype in _dataValueTypes): datavalue = _dataValueTypes[datatype][0](value) else: datavalue = value settings.setValue('%s/%s/type' % (key, datakey), wrapVariant(datatype)) settings.setValue('%s/%s/value' % (key, datakey), wrapVariant(datavalue)) #------------------------------------------------------------------------------- # register getter/setter value types registerDataType('bool', lambda pyvalue: int(pyvalue), lambda qvariant: unwrapVariant(qvariant, False)) registerDataType('int', lambda pyvalue: int(pyvalue), lambda qvariant: unwrapVariant(qvariant, 0)) registerDataType('float', lambda pyvalue: float(pyvalue), lambda qvariant: unwrapVariant(qvariant, 0.0)) registerDataType('str', lambda pyvalue: nativestring(pyvalue), lambda qvariant: nativestring(unwrapVariant(qvariant, ''))) registerDataType('unicode', lambda pyvalue: unicode(pyvalue), lambda qvariant: unicode(unwrapVariant(qvariant, ''))) def decodeFont(qvariant):
def setEditorData(self, editor, index): i = editor.findText(unwrapVariant(index.data())) editor.setCurrentIndex(i) editor.lineEdit().selectAll()