- User Interfaces
- QtPyVCP
- Read and write qtpyvcp widgets form GCode or access numbered parameters from py
Read and write qtpyvcp widgets form GCode or access numbered parameters from py
- anfänger
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 626
- Thank you received: 253
14 Sep 2024 13:05 - 15 Sep 2024 07:51 #310143
by anfänger
Read and write qtpyvcp widgets form GCode or access numbered parameters from py was created by anfänger
Is there a way that I can read and write the content go widgets from Code?
I have machine Parameters which I want to show and edit. They should be set by a m code that runs on startup and restores the values from machine parameters.
It should update the parameters when edited, so I used the Action spin box, but I have no clue how to write it from gcode.
also updating gives me some trouble
the action name is:
machine.issue_mdi: M200 P#<cposem35> Q4
with cposem35 the name of the widget. and I get following error
I have machine Parameters which I want to show and edit. They should be set by a m code that runs on startup and restores the values from machine parameters.
It should update the parameters when edited, so I used the Action spin box, but I have no clue how to write it from gcode.
also updating gives me some trouble
the action name is:
machine.issue_mdi: M200 P#<cposem35> Q4
with cposem35 the name of the widget. and I get following error
Traceback (most recent call last):File "/usr/lib/python3/dist-packages/qtpyvcp/actions/machine_actions.py", line 207, in issue_mdifor cmd in command.strip().split(';'):^^^^^^^^^^^^^AttributeError: 'int' object has no attribute 'strip'
Or would it male more sense to use he settings widget and not store it in the parameters. they actually don't need to be written anytime else except on startup.
I guess I am thinking too complicated.
thanks
Patrick
Last edit: 15 Sep 2024 07:51 by anfänger.
Please Log in or Create an account to join the conversation.
- anfänger
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 626
- Thank you received: 253
15 Sep 2024 07:54 - 15 Sep 2024 09:30 #310181
by anfänger
Replied by anfänger on topic Read and write qtpyvcp widgets form GCode or access numbered parameters from py
There is still python (even though I am no friends of I simply prefer brackets). Setting the widgets should work here, for not being able to access the parameters I think setting them in the ini might be neater.
I glued together a script
but I get an error:
I glued together a script
#python script to write values from the ini to the userinterface
import configparser
import sys
from probe_basic.probe_basic import ProbeBasic
# fucntion to read ini file
def read_ini_values(file_path, section):
config = configparser.ConfigParser()
config.read(file_path)
if section not in config:
print(f"Section {section} not found in the ini file.")
return {}
return config[section]
# Function, to assingn values from INI-File to the widgets
def assign_values_to_widgets(self, ini_values):
for key, value in ini_values.items():
widget = ui.findChild(QtWidgets.QWidget, key)
if widget:
# check for Widget-Type and assign corresponding values
if isinstance(widget, QtWidgets.QLineEdit):
widget.setText(value)
elif isinstance(widget, QtWidgets.QSpinBox):
widget.setValue(int(value))
elif isinstance(widget, QtWidgets.QCheckBox):
widget.setChecked(value.lower() == 'true')
elif isinstance(widget, QtWidgets.QLabel):
widget.setText(value)
# main function
def main():
# read ini file
ini_file = 'probe_basic.ini'
section = 'QTPYVCP_Values'
ini_values = read_ini_values(ini_file, section)
if not ini_values:
print("No values found or section missing.")
return
class CustomProbeBasic(ProbeBasic):
"""Main window class for the ProbeBasic VCP."""
def __init__(self, *args, **kwargs):
super(CustomProbeBasic, ui).__init__(*args, **kwargs)
# assign INI values to the Widgets
assign_values_to_widgets(ui, ini_values)
sys.exit(app.exec_())
if __name__ == "__main__":
main()
but I get an error:
[qtpyvcp.plugins][ERROR] Failed to find plugin with ID 'status' (__init__.py:99)
Or is there another way to keep values in widgets in qtpyvcp persistent?
Last edit: 15 Sep 2024 09:30 by anfänger.
Please Log in or Create an account to join the conversation.
- Lcvette
- Offline
- Moderator
Less
More
- Posts: 1178
- Thank you received: 618
16 Sep 2024 18:55 #310280
by Lcvette
Replied by Lcvette on topic Read and write qtpyvcp widgets form GCode or access numbered parameters from py
if you are on the latest version you can have a look at how the probing parameters are stored, its kind of ugly and cumbersome but currently is the only way we could figure to do it from within the ui. we are essentially sending the widget entry parameters to a subroutine (which is a built in feature and simple by using the widget container name: #<widget_name> = #1 as shown there for example. however this does not work for M6 Remap calls for some reason, so we have had to add an extra step which is to send the widget parameters to a subroutine where we can then write them to the var file. its cumbersome and not pretty but it does work relaiably. the parameters are stored int he ui and are loaded from the settings file based on the yaml file definitions.
it works fine but in the future we would like to find a more elegant solution. remap kind of plays by its own rules which has been found to be difficult to work around.
hope this helps!
Chris
it works fine but in the future we would like to find a more elegant solution. remap kind of plays by its own rules which has been found to be difficult to work around.
hope this helps!
Chris
The following user(s) said Thank You: anfänger
Please Log in or Create an account to join the conversation.
- JT
- Online
- Administrator
Less
More
- Posts: 823
- Thank you received: 444
17 Sep 2024 11:32 #310303
by JT
Replied by JT on topic Read and write qtpyvcp widgets form GCode or access numbered parameters from py
Chris,
I just added the ability to create a spin box and it's a HAL float pin. The preset is loaded into the HAL pin at startup. Then in your G code you and read the HAL values with #<_hal[name.of.pin]>
Hit me up on the IRC if you want more info on this.
JT
I just added the ability to create a spin box and it's a HAL float pin. The preset is loaded into the HAL pin at startup. Then in your G code you and read the HAL values with #<_hal[name.of.pin]>
Hit me up on the IRC if you want more info on this.
JT
The following user(s) said Thank You: anfänger
Please Log in or Create an account to join the conversation.
- Lcvette
- Offline
- Moderator
Less
More
- Posts: 1178
- Thank you received: 618
19 Sep 2024 12:46 #310450
by Lcvette
Replied by Lcvette on topic Read and write qtpyvcp widgets form GCode or access numbered parameters from py
awesome! i will, thanks JT!!
Please Log in or Create an account to join the conversation.
- anfänger
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 626
- Thank you received: 253
23 Sep 2024 07:17 #310628
by anfänger
Replied by anfänger on topic Read and write qtpyvcp widgets form GCode or access numbered parameters from py
Thanks all for your help.
In the end I used the HAL to solve the problem.
In the end I used the HAL to solve the problem.
Please Log in or Create an account to join the conversation.
Moderators: KCJ, Lcvette
- User Interfaces
- QtPyVCP
- Read and write qtpyvcp widgets form GCode or access numbered parameters from py
Time to create page: 0.065 seconds