コード例 #1
0
ファイル: _controller_base.py プロジェクト: mrdunk/CNCtastic
    def gui_layout_components(self) -> Dict[str, List[sg.Element]]:
        """ Return a dict of GUI widgets to be included in controller related pages. """
        button_col = sg.LOOK_AND_FEEL_TABLE[sg.theme()]["BUTTON"]
        disabled_button_col = ("grey", button_col[1])

        components = {}
        components["view_label"] = [
            sg.Text("Title:", size=(12, 1)),
            sg.Text(self.label, key=self.key_gen("label"), size=(20, 1)),
        ]
        components["edit_label"] = [
            sg.Text("Title:", size=(12, 1)),
            sg.InputText(self.label,
                         key=self.key_gen("label_edit"),
                         size=(20, 1)),
        ]
        components["view_buttons"] = [
            sg.Button("Connect",
                      key=self.key_gen("connect"),
                      size=(10, 1),
                      pad=(2, 2)),
            sg.Button('Disconnect',
                      key=self.key_gen("disconnect"),
                      size=(10, 1),
                      pad=(2, 2)),
        ]
        components["edit_buttons"] = [
            sg.Button("Save",
                      key=self.key_gen("save_edit"),
                      size=(10, 1),
                      pad=(2, 2),
                      disabled=True,
                      button_color=disabled_button_col),
            sg.Button("Cancel",
                      key=self.key_gen("cancel_edit"),
                      size=(10, 1),
                      pad=(2, 2),
                      disabled=True,
                      button_color=disabled_button_col),
            sg.Button("Delete", size=(10, 1), pad=(2, 2)),
        ]
        components["view_connection"] = [
            sg.Text("Connection state (desired/actual):", size=(24, 1)),
            sg.Text(key=self.key_gen("desired_connection_status"),
                    size=(15, 1),
                    pad=(0, 0)),
            sg.Text(key=self.key_gen("connection_status"),
                    size=(15, 1),
                    pad=(0, 0),
                    justification="left"),
        ]

        self.__edit_buttons = components["edit_buttons"]

        self.event_subscriptions[self.key_gen("label_edit")] = (
            "_modify_controller", None)
        self.event_subscriptions[self.key_gen("cancel_edit")] = (
            "_undo_modify_controller", None)
        return components
コード例 #2
0
ファイル: terminal.py プロジェクト: mrdunk/CNCtastic
    def gui_layout(self) -> List[List[sg.Element]]:
        """ Layout information for the PySimpleGUI interface. """
        log_size = (60, 10)
        self.widget_log = sg.Multiline(
            key=self.key_gen("log"),
            size=log_size,
            disabled=True,
            autoscroll=True,
            metadata={
                "skip_update": True,
                "size": log_size
            },
        )

        self.widget_newline = sg.Input(
            size=(60, 1),
            key=self.key_gen("gcode_newline"),
            metadata={"skip_update": True},
            focus=True,
        )

        layout = [
            [sg.Text("Title:", size=(20, 1))],
            [self.widget_log],
            [self.widget_newline],
            [
                sg.Button(
                    "Submit",
                    visible=False,
                    key=self.key_gen("gcode_submit"),
                    bind_return_key=True,
                )
            ],
        ]
        return layout
コード例 #3
0
    def gui_layout_components(self) -> Dict[str, List[sg.Element]]:
        """ GUI layout common to all derived classes. """
        components = super().gui_layout_components()

        self.device_picker = sg.Combo(
            values=["to_populate"],
            size=(25, 1),
            key=self.key_gen("device_picker"),
            default_value=self.serial_port,
            enable_events=True,
        )
        device_scan = sg.Button(
            "Scan",
            size=(5, 1),
            key=self.key_gen("device_scan"),
            tooltip="Scan for serial ports.",
        )

        self.search_device()

        components["view_serial_port"] = [
            sg.Text("Serial port:", size=(12, 1)),
            sg.Text(self.serial_port, key=self.key_gen("serial_port"))
        ]
        components["edit_serial_port"] = [
            sg.Text("Serial port:", size=(12, 1)), self.device_picker,
            device_scan
        ]

        return components
コード例 #4
0
    def gui_layout(self) -> List[List[List[sg.Element]]]:
        """ Return the GUI page with sections for all controllers. """
        chooser_elements = []
        view_elements = []
        self.controller_widgets = {}
        self.controller_buttons = {}

        # TODO: Make the enabled value persistent.
        if not self.enabled:
            self.enabled = list(self.controllers.keys())[0]

        for label, controller in self.controllers.items():
            choose = self._button(label)
            chooser_elements.append([choose])

            view = self._view_widget(label, controller)
            view_elements.append(view)

        button = self._button("##new_controller")
        chooser_elements.append([button])
        widget = self._new_widget()
        view_elements.append(widget)

        chooser = sg.Column(chooser_elements,
                            pad=(0, 0),
                            background_color="grey")

        output = [
            [chooser] + view_elements,
            [sg.Button("Restart", size=(8, 2), key="gui:restart")],
        ]
        return output
コード例 #5
0
    def _button(self, label: str) -> sg.Button:
        """ Return a button widget for selecting which controller is selected. """
        key = "%s:active_buttonpress" % label
        self.event_subscriptions[key] = ("_on_button_press", label)

        if label == self.enabled:
            color = ("white", "red")
        else:
            color = ("white", "green")

        button = sg.Button(label,
                           key=key,
                           size=(15, 1),
                           pad=(0, 0),
                           button_color=color)
        self.controller_buttons[key] = button

        return button
コード例 #6
0
    def _new_widget(self) -> sg.Frame:
        """ Return a widget for selecting what type of new controller is wanted. """
        visible = bool(self.enabled == "##new_controller")

        layout = []
        for label in self.controller_classes:
            key = self.key_gen("new_controller__%s" % label)
            self.event_subscriptions[key] = ("_new_controller", label)
            button = sg.Button(
                label,
                key=key,
            )
            layout.append([button])

        widget = sg.Frame(
            "New controller",
            layout,
            visible=visible,
        )
        key = self.key_gen("view_##new_controller")
        self.controller_widgets[key] = widget
        return widget
コード例 #7
0
ファイル: jog.py プロジェクト: mrdunk/CNCtastic
 def but(label: str, key: str) -> sg.Button:
     """ Square button. """
     return sg.Button(label,
                      key=self.key_gen(key),
                      size=(int(but_w), int(but_h)))