Ejemplo n.º 1
0
    def set_state(self, state, next_states):
        self.model = QuickComboModel(None)

        all_states = [state]

        if next_states:
            # Convert from tuple to array
            all_states += [s for s in next_states]

        self.model.buildModelFromArray([c.description for c in all_states],
                                       all_states)  # user strings, references
        self.widget.setModel(self.model)
Ejemplo n.º 2
0
    def __init__(self,
                 field_name,
                 user_name,
                 nullable=False,
                 widget=None,
                 parent=None):
        if widget is None:
            widget = QComboBox(parent)

        StandardEditInstrumentation.__init__(self, field_name, user_name,
                                             nullable, widget)
        QObject.__init__(self)

        self.model = QuickComboModel(None)
Ejemplo n.º 3
0
    def __init__(self, parent):
        super(PresenceDialog, self).__init__(parent)

        self.model = QuickComboModel(None)

        self.tar_type_edit = TaskActionReportTypeComboBox("action_type",
                                                          _("Action"),
                                                          nullable=False)
        self.tar_type_edit.set_model(
            [TaskActionReportType.day_in, TaskActionReportType.day_out])
        self.start_time_edit = TimeStampEdit("start_time",
                                             _("Start time"),
                                             nullable=False)
        self.form_fields = [self.tar_type_edit, self.start_time_edit]

        form_layout = QFormLayout()
        form_layout.addRow(_("Action"), self.tar_type_edit.widget)
        form_layout.addRow(_("Start time"), self.start_time_edit.widget)

        self.buttons = QDialogButtonBox()
        self.buttons.addButton(QDialogButtonBox.Ok)
        self.buttons.addButton(QDialogButtonBox.Cancel)
        self.buttons.accepted.connect(self.save_and_accept)
        self.buttons.rejected.connect(self.cancel)

        top_layout = QVBoxLayout()
        top_layout.addLayout(form_layout)
        top_layout.addWidget(self.buttons)

        self.setLayout(top_layout)
Ejemplo n.º 4
0
    def set_model(self, original_state):

        # This first state is the current one so that it
        # is properly displayed

        states = []
        states.append(original_state)
        for s in business_computations_service.order_possible_next_states(
                original_state):
            if s != original_state:
                states.append(s)

        self.model = QuickComboModel(None)
        self.model.buildModelFromArray([c.description for c in states],
                                       states)  # user strings, references
        self.widget.setModel(self.model)
Ejemplo n.º 5
0
class Blew(QWidget):
    def __init__(self):
        super(Blew, self).__init__()
        self.setWindowModality(Qt.NonModal)
        self.setWindowFlags(
            Qt.FramelessWindowHint)  # Qt.Tool | Qt.FramelessWindowHint

        l = QHBoxLayout()
        self.items_view = QTableView()

        # Make the dropdown nice
        l.setContentsMargins(0, 0, 0, 0)
        self.items_view.horizontalHeader().setStretchLastSection(True)
        self.items_view.horizontalHeader().hide()
        self.items_view.verticalHeader().hide()
        self.items_view.setShowGrid(False)
        self.setMinimumSize(300, 100)

        self.model = QuickComboModel(self)
        self.items_view.setModel(self.model)
        l.addWidget(self.items_view)
        self.setLayout(l)

    def get_current_completion(self):
        """ Get the currently selected completion """
        return self.items_view.currentIndex().data()

    @Slot(list)
    def set_possible_completions(self, completions):
        if completions:
            self.model.buildModelFromArray(completions)
            # self.show()
        else:
            self.model.clear()
            self.hide()

    completion_discarded = Signal()

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            event.ignore()
            self.hide()
            self.completion_discarded.emit()

        return super(Blew, self).keyPressEvent(event)
Ejemplo n.º 6
0
    def __init__(self):
        super(Blew, self).__init__()
        self.setWindowModality(Qt.NonModal)
        self.setWindowFlags(
            Qt.FramelessWindowHint)  # Qt.Tool | Qt.FramelessWindowHint

        l = QHBoxLayout()
        self.items_view = QTableView()

        # Make the dropdown nice
        l.setContentsMargins(0, 0, 0, 0)
        self.items_view.horizontalHeader().setStretchLastSection(True)
        self.items_view.horizontalHeader().hide()
        self.items_view.verticalHeader().hide()
        self.items_view.setShowGrid(False)
        self.setMinimumSize(300, 100)

        self.model = QuickComboModel(self)
        self.items_view.setModel(self.model)
        l.addWidget(self.items_view)
        self.setLayout(l)
Ejemplo n.º 7
0
class ConstrainedMachineEdit(QObject, StandardEditInstrumentation):
    def __init__(self,
                 field_name,
                 user_name,
                 nullable=False,
                 widget=None,
                 parent=None):
        if widget is None:
            widget = QComboBox(parent)

        StandardEditInstrumentation.__init__(self, field_name, user_name,
                                             nullable, widget)
        QObject.__init__(self)

        self.model = QuickComboModel(None)

    def set_model(self, machines):
        refs = [None] + machines
        label = [None] + [m.fullname for m in machines]
        self.model.buildModelFromArray(label, refs)  # user strings, references
        self.widget.setModel(self.model)

    @property
    def value(self):
        # Somehow, using itemData transforms some KeyedTupel reference into
        # simple list... FIXME !

        row = self.widget.currentIndex()  # an int
        r = self.model.references[row]

        mainlog.debug("ConstrainedMachineEdit.value:{}".format(type(r)))
        return r

    def check(self):
        return True

    def set_value(self, value):
        super(ConstrainedMachineEdit, self).set_value(value)
Ejemplo n.º 8
0
class TaskActionReportTypeComboBox(StandardEditInstrumentation):
    def __init__(self, field_name, user_name, nullable=False, widget=None):
        if widget is None:
            widget = QComboBox()
        super(TaskActionReportTypeComboBox,
              self).__init__(field_name, user_name, nullable, widget)

    def set_model(self, tars):
        self.model = QuickComboModel(None)
        self.model.buildModelFromArray([c.description for c in tars],
                                       tars)  # user strings, references
        self.widget.setModel(self.model)

    @property
    def value(self):
        return self.widget.itemData(self.widget.currentIndex())

    def check(self):
        return True

    def get_current_type(self):
        # FIXME Obsolete, use value() instead
        return self.itemData(self.currentIndex())
Ejemplo n.º 9
0
class OrderStateEdit(QObject, StandardEditInstrumentation
                     ):  # StandardEditInstrumentation

    signal_state_changed = Signal()

    def __init__(self,
                 field_name,
                 user_name,
                 nullable=False,
                 widget=None,
                 parent=None):
        if widget is None:
            widget = QComboBox(parent)

        widget.activated.connect(self.state_changed_slot)
        self.last_index = 0

        StandardEditInstrumentation.__init__(self, field_name, user_name,
                                             nullable, widget)
        QObject.__init__(self)

    @Slot(int)
    def state_changed_slot(self, ndx):
        mainlog.debug("State changed {} - {}".format(
            ndx, self.widget.currentIndex()))
        if self.last_index != self.widget.currentIndex():
            self.last_index = self.widget.currentIndex()
            self.signal_state_changed.emit()

    def set_model(self, original_state):

        # This first state is the current one so that it
        # is properly displayed

        states = []
        states.append(original_state)
        for s in business_computations_service.order_possible_next_states(
                original_state):
            if s != original_state:
                states.append(s)

        self.model = QuickComboModel(None)
        self.model.buildModelFromArray([c.description for c in states],
                                       states)  # user strings, references
        self.widget.setModel(self.model)

    @property
    def value(self):
        return self.widget.itemData(self.widget.currentIndex())

    def set_state(self, state, next_states):
        self.model = QuickComboModel(None)

        all_states = [state]

        if next_states:
            # Convert from tuple to array
            all_states += [s for s in next_states]

        self.model.buildModelFromArray([c.description for c in all_states],
                                       all_states)  # user strings, references
        self.widget.setModel(self.model)

    def set_value(self, value):
        """ Sets the combo to the given state. The other possibilities
        in the combo are the states reachable from the given one.
        """

        super(OrderStateEdit, self).set_value(value)
        self.set_model(value)
        self.widget.setCurrentIndex(0)
        self.last_index = 0

    def check(self):
        return True

    def get_current_type(self):
        # FIXME Obsolete, use value() instead
        return self.itemData(self.currentIndex())
Ejemplo n.º 10
0
 def set_model(self, tars):
     self.model = QuickComboModel(None)
     self.model.buildModelFromArray([c.description for c in tars],
                                    tars)  # user strings, references
     self.widget.setModel(self.model)