Ejemplo n.º 1
0
 def __init__(self, title=None, comment=None, icon=""):
     # self.widget = custom_widgets.SettingsWidget()
     self.dialog = widgets.BaseDialog()
     self.dialog.set_modality("application")
     self.dialog.setMinimumWidth(400)
     self.dialog.title = title
     self.dialog.set_icon(icon)
     self.dialog.set_layout("grid")
     self.dialog.box.set_spacing(20)
     self.dialog.box.set_margin(20)
     for i, (k, item) in enumerate(self._items.items()):
         self.dialog.box[i, item.label_col] = widgets.Label(item.label)
         self.dialog.box[i, item.label_col + 1:item.label_col +
                         3] = item.widget
         item.widget.id = k
         item.widget.value_changed.connect(self.on_update)
         for active in item.active_on:
             item.widget.setEnabled(self._items[active].widget.get_value())
             self._items[active].widget.value_changed.connect(
                 item.widget.setEnabled)
         for active in item.not_active_on:
             item.widget.setDisabled(self._items[active].widget.get_value())
             self._items[active].widget.value_changed.connect(
                 item.widget.setDisabled)
     if comment:
         label = widgets.Label(comment)
         label.setWordWrap(True)
         self.dialog.box[i + 1, 0:3] = label
     button_box = widgets.DialogButtonBox()
     self.ok_btn = button_box.add_default_button(
         "ok", callback=self.dialog.accept)
     button_box.add_default_button("cancel", callback=self.dialog.reject)
     self.dialog.box.append(button_box)
     self.on_update()
Ejemplo n.º 2
0
def test_dialogbuttonbox():
    box = widgets.DialogButtonBox()
    box.set_horizontal()
    box.set_vertical()
    btn = box.add_default_button("apply")
    assert len(box) == 1
    assert btn == box["apply"]
    for item in box:
        pass
Ejemplo n.º 3
0
def test_dialogbuttonbox():
    box = widgets.DialogButtonBox()
    box.set_horizontal()
    box.set_vertical()
    btn = box.add_default_button("apply")
    with pytest.raises(ValueError):
        btn = box.add_default_button("test")
    box.set_orientation("horizontal")
    with pytest.raises(ValueError):
        box.set_orientation("test")
    assert box.get_orientation() == "horizontal"
    box.add_button("test", callback=print)
    assert len(box) == 2
    assert btn == box["apply"]
    assert "apply" in box
    for item in box:
        pass
    btn = box.add_default_buttons(["ok"])
Ejemplo n.º 4
0
    def create_dialog(self):
        dialog = widgets.Dialog()
        dialog.set_modality("application")
        dialog.setMinimumWidth(400)
        dialog.set_title(self.dialog_title)
        dialog.set_icon(self.dialog_icon)
        dialog.set_layout("grid")
        dialog.box.set_spacing(10)
        dialog.box.set_margin(20)

        button_box = widgets.DialogButtonBox()
        ok_btn = button_box.add_default_button("ok", callback=dialog.accept)
        button_box.add_default_button("cancel", callback=dialog.reject)
        widget_dict = {k: v.create_widget() for k, v in self._items.items()}
        widget_dict = {k: v for k, v in widget_dict.items() if v is not None}

        def on_update():
            is_valid = all(i.is_valid() if hasattr(i, "is_valid") else True
                           for i in widget_dict.values())
            ok_btn.setEnabled(is_valid)

        for i, (k, item) in enumerate(self._items.items()):
            if k not in widget_dict:
                continue
            dialog.box[i, item.label_col] = widgets.Label(item.label)
            dialog.box[i,
                       item.label_col + 1:item.label_col + 3] = widget_dict[k]
            widget = widget_dict[k]
            widget.set_id(k)
            widget.value_changed.connect(on_update)
            for active in item.enabled_on:
                widget.setEnabled(widget_dict[active].get_value())
                widget_dict[active].value_changed.connect(widget.setEnabled)
            for active in item.disabled_on:
                widget.setDisabled(widget_dict[active].get_value())
                widget_dict[active].value_changed.connect(widget.setDisabled)
        if self.dialog_comment:
            label = widgets.Label(self.dialog_comment)
            label.setWordWrap(True)
            dialog.box[len(self._items) + 1, 0:3] = label
        dialog.box.append(button_box)
        on_update()
        return dialog
Ejemplo n.º 5
0
def test_dialogbuttonbox():
    box = widgets.DialogButtonBox()
    box.show()
    box.close()
Ejemplo n.º 6
0
 def add_buttonbox(self):
     button_box = widgets.DialogButtonBox()
     button_box.add_buttons(["cancel", "ok"])
     button_box.accepted.connect(self.accepted)
     button_box.rejected.connect(self.reject)
     self.layout.addWidget(button_box)