def createEditor(self, parent, option, index): combo = QComboBox(parent) keys = Q.Op.keys() keys = map(lambda x: projex.text.joinWords(x, ' ').lower(), keys) combo.addItems(sorted(keys)) combo.setEditable(True) combo.setInsertPolicy(QComboBox.NoInsert) return combo
def createEditor( self, parent, option, index ): combo = QComboBox(parent) keys = Q.Op.keys() keys = map(lambda x: projex.text.joinWords(x, ' ').lower(), keys) combo.addItems(sorted(keys)) combo.setEditable(True) combo.setInsertPolicy(QComboBox.NoInsert) return combo
def createEditor( self, parent, option, index ): schema = self.parent().schema() if ( not schema ): return None colNames = map(lambda x: x.displayName(), schema.columns()) combo = QComboBox(parent) combo.setEditable(True) combo.setInsertPolicy(QComboBox.NoInsert) combo.addItems(colNames) return combo
def createEditor(self, parent, option, index): schema = self.parent().schema() if (not schema): return None colNames = map(lambda x: x.displayName(), schema.columns()) combo = QComboBox(parent) combo.setEditable(True) combo.setInsertPolicy(QComboBox.NoInsert) combo.addItems(colNames) return combo
def createEditor( self, parent, option, index ): tree = self.parent() querywidget = tree.parent() item = tree.itemFromIndex(index) if ( isinstance(item, XQueryItem) and not item.childCount() ): ttype = querywidget.tableType() options = querywidget.factory().columnOptions(ttype) elif ( isinstance(item, XJoinItem) ): options = ['and', 'or'] combo = QComboBox(parent) combo.setEditable(True) combo.setInsertPolicy(QComboBox.NoInsert) combo.addItems(sorted(options)) return combo
def createEditor(self, parent, option, index): tree = self.parent() querywidget = tree.parent() item = tree.itemFromIndex(index) if (isinstance(item, XQueryItem) and not item.childCount()): ttype = querywidget.tableType() options = querywidget.factory().columnOptions(ttype) elif (isinstance(item, XJoinItem)): options = ['and', 'or'] combo = QComboBox(parent) combo.setEditable(True) combo.setInsertPolicy(QComboBox.NoInsert) combo.addItems(sorted(options)) return combo
def createEditor(self, parent, option, index): combo = QComboBox(parent) item = self.parent().itemFromIndex(index) columnType = item.columnType() operators = Q.ColumnOps.get(columnType, Q.ColumnOps[None]) # create the keys based on the column type keys = [] for operator in operators: op_name = Q.Op[operator] keys.append(projex.text.joinWords(op_name, ' ').lower()) combo.addItems(sorted(keys)) combo.setEditable(True) combo.setInsertPolicy(QComboBox.NoInsert) return combo
def createEditor( self, parent, option, index ): combo = QComboBox(parent) item = self.parent().itemFromIndex(index) columnType = item.columnType() operators = Q.ColumnOps.get(columnType, Q.ColumnOps[None]) # create the keys based on the column type keys = [] for operator in operators: op_name = Q.Op[operator] keys.append(projex.text.joinWords(op_name, ' ').lower()) combo.addItems(sorted(keys)) combo.setEditable(True) combo.setInsertPolicy(QComboBox.NoInsert) return combo
class XTimeDeltaEdit(QFrame): def __init__(self, parent=None): super(XTimeDeltaEdit, self).__init__(parent) # define custom properties self.setStyleSheet(COMBO_STYLE) self._numberSpinner = QSpinBox(self) self._numberSpinner.setRange(0, 100000) self._numberSpinner.setFrame(False) self._numberSpinner.setButtonSymbols(QSpinBox.NoButtons) self._numberSpinner.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._unitCombo = QComboBox(self) self._unitCombo.setEditable(True) self._unitCombo.setInsertPolicy(QComboBox.NoInsert) self._unitCombo.setFrame(False) self._unitCombo.addItems(['year(s)', 'month(s)', 'week(s)', 'day(s)', 'hour(s)', 'minute(s)', 'second(s)']) self._unitCombo.setCurrentIndex(3) self._unitCombo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._directionCombo = QComboBox(self) self._directionCombo.addItems(['ago', 'from now']) self._directionCombo.setEditable(True) self._directionCombo.setInsertPolicy(QComboBox.NoInsert) self._directionCombo.setFrame(False) self._directionCombo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) # setup ui self.setFrameShape(QFrame.StyledPanel) self.setFrameShadow(QFrame.Sunken) self.setBackgroundRole(QPalette.Base) self.setAutoFillBackground(True) layout = QHBoxLayout() layout.setContentsMargins(2, 2, 2, 2) layout.setSpacing(0) layout.addWidget(self._numberSpinner) layout.addWidget(self._unitCombo) layout.addWidget(self._directionCombo) self.setLayout(layout) def delta(self): """ Returns a delta based on this widget's information. :return <datetime.timedelta> """ number = self._numberSpinner.value() unit = self._unitCombo.currentText() direction = self._directionCombo.currentText() # use past tense if direction == 'ago': number = -number if unit == 'year(s)': return datetime.timedelta(number * 365) elif unit == 'month(s)': return datetime.timedelta(number * 30) elif unit == 'week(s)': return datetime.timedelta(number * 7) elif unit == 'day(s)': return datetime.timedelta(number) elif unit == 'hour(s)': return datetime.timedelta(0, number * 3600) elif unit == 'minute(s)': return datetime.timedelta(0, number * 60) else: return datetime.timedelta(0, number) def setDelta(self, delta): """ Sets the time delta for this widget to the inputed delta. :param delta | <datetime.timedelta> """ days = int(delta.days) secs = int(delta.total_seconds()) direction = 'from now' if secs < 0: direction = 'ago' if days and days % 365 == 0: number = days / 365 unit = 'year(s)' elif days and days % 30 == 0: number = days / 30 unit = 'month(s)' elif days and days % 7 == 0: number = days / 7 unit = 'week(s)' elif days: number = days unit = 'day(s)' elif secs % 3600 == 0: number = secs / 3600 unit = 'hour(s)' elif secs % 60 == 0: number = secs / 60 unit = 'minute(s)' else: number = secs unit = 'second(s)' self._numberSpinner.setValue(abs(int(number))) self._unitCombo.setCurrentIndex(self._unitCombo.findText(unit)) index = self._directionCombo.findText(direction) self._directionCombo.setCurrentIndex(index)