From 3b540c1189b777b6c9f124c40e6e47dffa13d533 Mon Sep 17 00:00:00 2001 From: bartool Date: Sun, 28 Dec 2025 18:54:46 +0100 Subject: [PATCH] dodalem sidebar z przyciskami czesc relative jeszcze nie dziala --- .../template_sidebar/template_sidebar.py | 133 ++++++- .../template_sidebar/template_sidebar.ui | 329 ++++++++++++++++++ 2 files changed, 461 insertions(+), 1 deletion(-) diff --git a/configs/probe_basic/user_tabs/template_sidebar/template_sidebar.py b/configs/probe_basic/user_tabs/template_sidebar/template_sidebar.py index 1bcd807..7e45d19 100644 --- a/configs/probe_basic/user_tabs/template_sidebar/template_sidebar.py +++ b/configs/probe_basic/user_tabs/template_sidebar/template_sidebar.py @@ -3,10 +3,12 @@ import linuxcnc from qtpy import uic from qtpy.QtCore import Qt -from qtpy.QtWidgets import QWidget +from qtpy.QtWidgets import QWidget, QPushButton +from qtpyvcp.actions import machine, machine_actions from qtpyvcp.plugins import getPlugin from qtpyvcp.utilities import logger +from widgets.conversational.float_line_edit import FloatLineEdit LOG = logger.getLogger(__name__) @@ -14,6 +16,7 @@ STATUS = getPlugin('status') TOOL_TABLE = getPlugin('tooltable') INI_FILE = linuxcnc.ini(os.getenv('INI_FILE_NAME')) +CMD = linuxcnc.command() class UserTab(QWidget): @@ -21,3 +24,131 @@ class UserTab(QWidget): super(UserTab, self).__init__(parent) ui_file = os.path.splitext(os.path.basename(__file__))[0] + ".ui" uic.loadUi(os.path.join(os.path.dirname(__file__), ui_file), self) + + STATUS.on.notify(self._update_controls) + STATUS.all_axes_homed.notify(self._update_controls) + + STATUS.g5x_index.notify(self.update_wcs_label) + self.update_wcs_label() + + # self.btn_wcs_x.clicked.connect(lambda: self.move_wcs(x=self.fle_wcs_x.value())) + # self.btn_wcs_y.clicked.connect(lambda: self.move_wcs(y=self.fle_wcs_y.value())) + # self.fle_wcs_x.editingFinished.connect(self._format_x) + + self.edits: list[FloatLineEdit] = self.findChildren(FloatLineEdit) + + for fle in self.edits: + fle.setEnabled(False) + fle.editingFinished.connect(self.format_float) + + self.buttons: list[QPushButton] = self.findChildren(QPushButton) + + for btn in self.buttons: + btn.setEnabled(False) + btn.clicked.connect(self.move_axis) + + def format_float(self): + if not isinstance(self.sender(), FloatLineEdit): + return + + w: FloatLineEdit = self.sender() + if w is None: + LOG.debug(f"fn _format_float, sender None") + return + LOG.debug(f"fn: _format_float, sender name: {w.objectName()}") + + value = w.value() + fmt = w.format_string + val_fmt = fmt.format(value) + w.setText(val_fmt) + + + + def update_wcs_label(self): + idx = STATUS.g5x_index + self.statuslabel_wcs.setText(f"WCS {idx}") + # 'G54' if ch[0] == 1 else 'G55' if ch[0] == 2 else 'G56' if ch[0] == 3 else 'none' + + def move_x(self): + machine_actions.jog.axis(axis='x', direction=1, distance=0.5) + LOG.debug(f"fn: move_x. fle_wcs_x:{self.fle_wcs_x.value()}") + + + def move_axis(self): + if not isinstance(self.sender(), QPushButton): + return + + sender: QPushButton = self.sender() + btn_name = sender.objectName() + LOG.debug(f"fn: move_axis. sender:{btn_name}") + + if "abs" in btn_name: + dest_x = self.fle_abs_x.value() + dest_y = self.fle_abs_y.value() + dest_z = self.fle_abs_z.value() + if "_x" in btn_name: + self.move_wcs(x=dest_x, abs=True) + return + if "_y" in btn_name: + self.move_wcs(y=dest_y, abs=True) + return + if "_z" in btn_name: + self.move_wcs(z=dest_z, abs=True) + return + self.move_wcs(dest_x, dest_y, dest_z, abs=True) + LOG.debug(f"fn: move_wcs[ABS] x:{dest_x}, y:{dest_y}, z:{dest_z}") + + if "wcs" in btn_name: + dest_x = self.fle_wcs_x.value() + dest_y = self.fle_wcs_y.value() + dest_z = self.fle_wcs_z.value() + if "_x" in btn_name: + self.move_wcs(x=dest_x) + return + if "_y" in btn_name: + self.move_wcs(y=dest_y) + return + if "_z" in btn_name: + self.move_wcs(z=dest_z) + return + + self.move_wcs(dest_x, dest_y, dest_z) + LOG.debug(f"fn: move_wcs[WCS] x:{dest_x}, y:{dest_y}, z:{dest_z}") + + + + def move_wcs(self, x=None, y=None, z=None, abs=False): + + if abs: + mdi_cmd = "G53 G0" + else: + mdi_cmd = "G0" + + if x is not None: + mdi_cmd += f" X{x}" + if y is not None: + mdi_cmd += f" Y{y}" + if z is not None: + mdi_cmd += f" Z{z}" + + LOG.debug(f"fn: move_wcs. MDI:{mdi_cmd}") + machine_actions.issue_mdi(mdi_cmd) + + def _machine_ready(self) -> bool: + LOG.debug(f"fn: machine_ready, on:{STATUS.on()}") + LOG.debug(f"fn: machine_ready, all_axes_homed:{STATUS.all_axes_homed()}") + return ( + STATUS.on() + and STATUS.all_axes_homed() + ) + + def _update_controls(self, *args): + ready = self._machine_ready() + LOG.debug(f"Machine ready: {ready}") + + for btn in self.buttons: + btn.setEnabled(ready) + + for fle in self.edits: + fle.setEnabled(ready) + diff --git a/configs/probe_basic/user_tabs/template_sidebar/template_sidebar.ui b/configs/probe_basic/user_tabs/template_sidebar/template_sidebar.ui index 6b28ca9..81415cc 100644 --- a/configs/probe_basic/user_tabs/template_sidebar/template_sidebar.ui +++ b/configs/probe_basic/user_tabs/template_sidebar/template_sidebar.ui @@ -22,7 +22,336 @@ true + + + + + + + QLabel{ + color: rgb(238, 238, 236); + font: 16pt "Bebas Kai"; +} + + + ABSOLUTE + + + + + + + + + 1.1234 + + + Qt::AlignCenter + + + 0 + + + [{"name": "postion_x", "property": "Text", "expression": "ch[0]", "channels": [{"url": "position:abs?string&axis=x", "trigger": true}]}] + + + + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + GO X + + + true + + + + + + + + + + + 0.0000 + + + Qt::AlignCenter + + + [{"name": "position_y", "property": "Text", "expression": "ch[0]", "channels": [{"url": "position:abs?string&axis=y", "trigger": true}]}] + + + + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + GO Y + + + true + + + + + + + + + + + 0.0000 + + + Qt::AlignCenter + + + [{"name": "position_z", "property": "Text", "expression": "ch[0]", "channels": [{"url": "position:abs?string&axis=z", "trigger": true}]}] + + + + + + + + 0 + 0 + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + GO Z + + + true + + + + + + + + + GO XYZ + + + true + + + + + + + + + + + QLabel{ + color: rgb(238, 238, 236); + font: 16pt "Bebas Kai"; +} + + + [] + + + + + + + + + 0.0000 + + + Qt::AlignCenter + + + 0 + + + [{"name": "postion_x", "property": "Text", "expression": "ch[0]", "channels": [{"url": "position:Relative?string&axis=x", "trigger": true}]}] + + + + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + GO X + + + + + + + + + + + 0.0000 + + + Qt::AlignCenter + + + [{"name": "position_y", "property": "Text", "expression": "ch[0]", "channels": [{"url": "position:Relative?string&axis=y", "trigger": true}]}] + + + + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + GO Y + + + + + + + + + + + 0.0000 + + + Qt::AlignCenter + + + [{"name": "position_z", "property": "Text", "expression": "ch[0]", "channels": [{"url": "position:Relative?string&axis=z", "trigger": true}]}] + + + + + + + + 0 + 0 + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + GO Z + + + + + + + + + GO XYZ + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + StatusLabel + QLabel +
qtpyvcp.widgets.display_widgets.status_label
+
+ + VCPLineEdit + QLineEdit +
qtpyvcp.widgets.input_widgets.line_edit
+
+ + FloatLineEdit + VCPLineEdit +
widgets.conversational.float_line_edit
+
+