import os import linuxcnc from qtpy import uic from qtpy.QtCore import Qt from qtpy.QtWidgets import QWidget, QLabel, QPushButton from qtpyvcp.plugins import getPlugin from qtpyvcp.widgets.button_widgets.led_button import LEDButton from qtpyvcp.widgets.input_widgets.jog_increment import JogIncrementWidget from qtpyvcp.utilities import logger from qtpyvcp.utilities.settings import getSetting, setSetting LOG = logger.getLogger(__name__) STATUS = getPlugin('status') TOOL_TABLE = getPlugin('tooltable') INI_FILE = linuxcnc.ini(os.getenv('INI_FILE_NAME')) from qtpyvcp.utilities.info import Info INFO = Info() class UserTab(QWidget): def __init__(self, parent=None): 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) # Clear any widgets added in the UI file while self.verticalLayout.count(): child = self.verticalLayout.takeAt(0) if child.widget(): child.widget().deleteLater() # Get all available jog increments and create a label for each increments = INFO.getIncrements() for increment in increments: label = QLabel(f"Increment: {increment}") self.verticalLayout.addWidget(label) # Add the two buttons left_button = QPushButton("Lewo") right_button = QPushButton("Prawo") self.verticalLayout.addWidget(left_button) self.verticalLayout.addWidget(right_button) # Connect button signals to their respective slots left_button.clicked.connect(self.left_btn_clicked) right_button.clicked.connect(self.right_btn_clicked) # Add a spacer to push all widgets to the top self.verticalLayout.addStretch(1) LOG.info("Initialized bartek") self.find_jog_buttons(parent) def left_btn_clicked(self): LOG.info("Lewo button clicked") setSetting('machine.jog.increment', '10mm') def right_btn_clicked(self): LOG.info("Prawo button clicked", ) setSetting('machine.jog.increment', '1mm') def find_jog_buttons(self, parent): if parent is None: LOG.warning("Parent widget is None") return jog = parent.findChild(JogIncrementWidget) if jog is None: LOG.warning("JogIncrement widget not found in parent") return self.jog_buttons = jog.findChildren(LEDButton) if not self.jog_buttons: LOG.warning("No LEDButton widgets found in JogIncrement") return LOG.info(f"Found {len(self.jog_buttons)} jog buttons")