Beispiel #1
0
    def __init__(self, parent=None):
        super(XTimeEdit, self).__init__(parent)

        # define custom properties
        self._editable = False
        self._showSeconds = False
        self._showMinutes = True
        self._showHours = True
        self._militaryTime = False

        # define the ui
        self._hourCombo = QtGui.QComboBox(self)
        self._hourSeparator = QtGui.QLabel(':', self)
        self._minuteCombo = QtGui.QComboBox(self)
        self._minuteSeparator = QtGui.QLabel(':', self)
        self._secondCombo = QtGui.QComboBox(self)
        self._timeOfDayCombo = QtGui.QComboBox(self)

        self._secondCombo.hide()
        self._minuteSeparator.hide()

        # define default UI settings
        self._hourCombo.addItems(['{0}'.format(i + 1) for i in xrange(12)])
        self._minuteCombo.addItems(
            ['{0:02d}'.format(i) for i in xrange(0, 60, 5)])
        self._secondCombo.addItems(
            ['{0:02d}'.format(i) for i in xrange(0, 60, 5)])
        self._timeOfDayCombo.addItems(['am', 'pm'])

        # setup combo properties
        for combo in (self._hourCombo, self._minuteCombo, self._secondCombo,
                      self._timeOfDayCombo):
            combo.setInsertPolicy(combo.NoInsert)
            combo.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                QtGui.QSizePolicy.Expanding)

        # layout the widgets
        h_layout = QtGui.QHBoxLayout()
        h_layout.setContentsMargins(0, 0, 0, 0)
        h_layout.setSpacing(0)
        h_layout.addWidget(self._hourCombo)
        h_layout.addWidget(self._hourSeparator)
        h_layout.addWidget(self._minuteCombo)
        h_layout.addWidget(self._minuteSeparator)
        h_layout.addWidget(self._secondCombo)
        h_layout.addWidget(self._timeOfDayCombo)

        self.setLayout(h_layout)

        # assign the default time
        self.setTime(QtCore.QDateTime.currentDateTime().time())
    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