Axis 2 - touchscreen version of old friend
30 May 2022 00:33 #244166
by cakeslob
Replied by cakeslob on topic Axis 2 - touchscreen version of old friend
zack, I think you will find the usercommand file easier to use than you think. I would like some clarification from some of the pros, but I think the usercommand file is, when we use "root_window.tk.call" we are sending tcl language in the form of strings to the axis.tcl file. I did a quick conversion of your timer part using user command. I took your portion from the axis2.tcl, and turned it into a usercommand file. Here is the portion at the end of the file ive attatched
I dont understand it very well, but I took some of your code from axis2.tcl, and I think I turned it into strings, which get sent to axis.py (?) and then sent to axis.tcl
with that in mind, you can probably use your same code from the axis2.tcl in a usercommand file and send it this way, or you could do it in python
In the file ive attatched, just about everything is broken out so you can easily do your size and color configurations
linuxcnc.org/docs/devel/html/gui/axis.ht..._customization_hints
have a look at the user_live_update and the creating hal pins and you are half way there.
I dont know how you could do the gradient preview background, someone else might need to help you.
Personally for me, the time spent working in the usercommand file has payed dividends because I found it so fucking annoying having to patch axis every time I installed a new linuxcnc or did an update. The extra time/hassle for usercommand file was much worth the time saved doing not doing updates, with the added bonus of working with future and past versions of axis
W = root_window.tk.call
######### PACKING THE TIMER INTO INFO ########
W('canvas','.info.timer')
W('pack','.info.timer','-side','right')
W('label','.info.timer.counter',
'-text' ,'m:s',
'-relief','raised', \
'-pady','1',
'-width','12')
W('button','.info.timer.start',\
'-text',' Start', \
'-borderwidth', '1', \
'-width',' 4', \
'-pady',' 1 ',\
'-command',' ')
W('button','.info.timer.restart', \
'-text',' Reset',
'-borderwidth', '1', \
'-width',' 4', \
'-pady',' 1 ',\
'-command',' ')
W('button','.info.timer.stop',
'-text',' Stop',
'-borderwidth','1',
'-width','4',
'-pady','1')
W('pack','.info.timer.start','-side','left')
W('pack','.info.timer.stop','-side','left')
W('pack','.info.timer.restart','-side','left')
W('pack','.info.timer.counter','-side','right')
I dont understand it very well, but I took some of your code from axis2.tcl, and I think I turned it into strings, which get sent to axis.py (?) and then sent to axis.tcl
with that in mind, you can probably use your same code from the axis2.tcl in a usercommand file and send it this way, or you could do it in python
In the file ive attatched, just about everything is broken out so you can easily do your size and color configurations
linuxcnc.org/docs/devel/html/gui/axis.ht..._customization_hints
have a look at the user_live_update and the creating hal pins and you are half way there.
I dont know how you could do the gradient preview background, someone else might need to help you.
Personally for me, the time spent working in the usercommand file has payed dividends because I found it so fucking annoying having to patch axis every time I installed a new linuxcnc or did an update. The extra time/hassle for usercommand file was much worth the time saved doing not doing updates, with the added bonus of working with future and past versions of axis
The following user(s) said Thank You: tommylight, zack
Please Log in or Create an account to join the conversation.
31 May 2022 05:15 - 31 May 2022 05:16 #244263
by phillc54
Replied by phillc54 on topic Axis 2 - touchscreen version of old friend
For reading and writing preferences you could use similar to the following which creates a new instance of configparser to create a file in the config directory called <MACHINE_NAME>.prefs
Use a sane DEFAULT when reading then it will use that if there is no entry in the file.
Use a sane DEFAULT when reading then it will use that if there is no entry in the file.
Warning: Spoiler!
prefP = configparser.ConfigParser
class plasmacPreferences(prefP):
types = {bool: prefP.getboolean,
float: prefP.getfloat,
int: prefP.getint,
str: prefP.get,
repr: lambda self,section,option: eval(prefP.get(self,section,option)),
}
def __init__(self):
prefP.__init__(self, strict=False, interpolation=None)
self.fn = os.path.join(PATH, '{}.prefs'.format(vars.machine.get()))
self.read(self.fn)
def getPrefs(prefs, section, option, default=False, type=bool):
m = prefs.types.get(type)
if prefs.has_section(section.upper()):
if prefs.has_option(section, option):
return m(prefs, section.upper(), option)
else:
prefs.set(section.upper(), option, str(default))
prefs.write(open(prefs.fn, "w"))
return default
else:# print("no getPrefs section", section.upper())
prefs.add_section(section.upper())
prefs.set(section.upper(), option, str(default))
prefs.write(open(prefs.fn, "w"))
def putPrefs(prefs, section, option, value, type=bool):
if prefs.has_section(section.upper()):
prefs.set(section.upper(), option, str(type(value)))
prefs.write(open(prefs.fn, "w"))
else:
prefs.add_section(section.upper())
prefs.set(section.upper(), option, str(type(value)))
prefs.write(open(prefs.fn, "w"))
def removePrefsSect(prefs, section):
prefs.remove_section(section.upper())
prefs.write(open(prefs.fn, "w"))
PREFS = plasmacPreferences()
# write a setting to prefs SECTION, SETTING, VALUE, TYPE
putPrefs(PREFS, 'GUI', 'foreground color', fgColor, str)
# get a setting from prefs SECTION, SETTING, DEFAULT, TYPE
fgColor = getPrefs(PREFS, 'GUI', 'foreground color', '#FFEE00', str)
Last edit: 31 May 2022 05:16 by phillc54.
Please Log in or Create an account to join the conversation.
01 Jun 2022 03:19 #244341
by cakeslob
Replied by cakeslob on topic Axis 2 - touchscreen version of old friend
Not to derail zacks thread, but since it might be mutually beneficial for us both I will continue.Posting python without the indentations, cheeky lol, I found it a good exercise in understanding python. Thank you Phil, this is the first time Im using fancy python, but I think I got it
PATH = ""
prefP = configparser.ConfigParser
class plasmacPreferences(prefP):
types = {
bool: prefP.getboolean,
float: prefP.getfloat,
int: prefP.getint,
str: prefP.get,
repr: lambda self,section,option: eval(prefP.get(self,section,option)),
}
def __init__(self):
prefP.__init__(self, strict=False, interpolation=None)
self.fn = os.path.join(PATH, '{}.prefs'.format(vars.machine.get()))
self.read(self.fn)
def getPrefs(prefs, section, option, default=False, type=bool):
m = prefs.types.get(type)
if prefs.has_section(section.upper()):
if prefs.has_option(section, option):
return m(prefs, section.upper(), option)
else:
prefs.set(section.upper(), option, str(default))
prefs.write(open(prefs.fn, "w"))
return default
else:
print("no getPrefs section", section.upper())
prefs.add_section(section.upper())
prefs.set(section.upper(), option, str(default))
prefs.write(open(prefs.fn, "w"))
def putPrefs(prefs, section, option, value, type=bool):
if prefs.has_section(section.upper()):
prefs.set(section.upper(), option, str(type(value)))
prefs.write(open(prefs.fn, "w"))
else:
prefs.add_section(section.upper())
prefs.set(section.upper(), option, str(type(value)))
prefs.write(open(prefs.fn, "w"))
def removePrefsSect(prefs, section):
prefs.remove_section(section.upper())
prefs.write(open(prefs.fn, "w"))
PREFS = plasmacPreferences()
# write a setting to prefs SECTION, SETTING, VALUE, TYPE
PREFS.putPrefs('GUI', 'foreground color', 'red', str)
# get a setting from prefs SECTION, SETTING, DEFAULT, TYPE
fgColor = PREFS.getPrefs('GUI', 'foreground color', '#FFEE00', str)
[GUI]
foreground color = red
Please Log in or Create an account to join the conversation.
01 Jun 2022 05:18 #244345
by phillc54
Replied by phillc54 on topic Axis 2 - touchscreen version of old friend
Shoot, I didn't notice that. I am getting lazier and lazier...Posting python without the indentations, cheeky lol

Please Log in or Create an account to join the conversation.
01 Aug 2022 16:25 #248797
by zack
Replied by zack on topic Axis 2 - touchscreen version of old friend
this works for me now thanks for the heads up
Please Log in or Create an account to join the conversation.
Time to create page: 0.173 seconds