2222import os
2323from shutil import copy as COPY
2424
25+ # move qtplasmac options from ini file to prefs file pre V1.227.219 2022/07/14)
26+ def move_options_to_prefs_file (inifile , prefs ):
27+ text = prefs .getpref ('shutdown_msg_detail' , '' , str , 'SHUTDOWN_OPTIONS' )
28+ prefs .putpref ('Exit warning text' , text , str , 'GUI_OPTIONS' )
29+ prefs .remove_section ('SHUTDOWN_OPTIONS' )
30+ prefs .write (open (prefs .fn , "w" ))
31+ data = inifile .find ('QTPLASMAC' , 'MODE' ) or None
32+ if data :
33+ prefs .putpref ('Mode' , data , int , 'GUI_OPTIONS' )
34+ data = inifile .find ('QTPLASMAC' , 'ESTOP_TYPE' ) or None
35+ if data :
36+ prefs .putpref ('Estop type' , data , int , 'GUI_OPTIONS' )
37+ data = inifile .find ('QTPLASMAC' , 'DRO_POSITION' ) or None
38+ if data :
39+ prefs .putpref ('DRO position' , data , str , 'GUI_OPTIONS' )
40+ data = inifile .find ('QTPLASMAC' , 'FLASH_ERROR' ) or None
41+ if data :
42+ prefs .putpref ('Flash error' , data , bool , 'GUI_OPTIONS' )
43+ data = inifile .find ('QTPLASMAC' , 'HIDE_RUN' ) or None
44+ if data :
45+ prefs .putpref ('Hide run' , data , bool , 'GUI_OPTIONS' )
46+ data = inifile .find ('QTPLASMAC' , 'HIDE_PAUSE' ) or None
47+ if data :
48+ prefs .putpref ('Hide pause' , data , bool , 'GUI_OPTIONS' )
49+ data = inifile .find ('QTPLASMAC' , 'HIDE_ABORT' ) or None
50+ if data :
51+ prefs .putpref ('Hide abort' , data , bool , 'GUI_OPTIONS' )
52+ data = inifile .find ('QTPLASMAC' , 'CUSTOM_STYLE' ) or None
53+ if data :
54+ prefs .putpref ('Custom style' , data , str , 'GUI_OPTIONS' )
55+ data = inifile .find ('QTPLASMAC' , 'AUTOREPEAT_ALL' ) or None
56+ if data :
57+ prefs .putpref ('Autorepeat all' , data , bool , 'GUI_OPTIONS' )
58+ data = inifile .find ('QTPLASMAC' , 'LASER_TOUCHOFF' ) or None
59+ if data :
60+ x , y , d = get_offsets (data )
61+ prefs .putpref ('X axis' , x , float , 'LASER_OFFSET' )
62+ prefs .putpref ('Y axis' , y , float , 'LASER_OFFSET' )
63+ data = inifile .find ('QTPLASMAC' , 'CAMERA_TOUCHOFF' ) or None
64+ if data :
65+ x , y , d = get_offsets (data )
66+ prefs .putpref ('X axis' , x , float , 'CAMERA_OFFSET' )
67+ prefs .putpref ('Y axis' , y , float , 'CAMERA_OFFSET' )
68+ data = inifile .find ('QTPLASMAC' , 'OFFSET_PROBING' ) or None
69+ if data :
70+ x , y , d = get_offsets (data )
71+ prefs .putpref ('X axis' , x , float , 'OFFSET_PROBING' )
72+ prefs .putpref ('Y axis' , y , float , 'OFFSET_PROBING' )
73+ prefs .putpref ('Delay' , d , float , 'OFFSET_PROBING' )
74+ data = inifile .find ('QTPLASMAC' , 'PM_PORT' ) or None
75+ if data :
76+ prefs .putpref ('Port' , data , str , 'GUI_OPTIONS' )
77+ for bNum in range (1 ,21 ):
78+ bName = inifile .find ('QTPLASMAC' , 'BUTTON_{}_NAME' .format (bNum )) or None
79+ bCode = inifile .find ('QTPLASMAC' , 'BUTTON_{}_CODE' .format (bNum )) or None
80+ if bName and bCode :
81+ prefs .putpref ('{} Name' .format (bNum ), bName , str , 'BUTTONS' )
82+ prefs .putpref ('{} Code' .format (bNum ), bCode , str , 'BUTTONS' )
83+
84+ def move_options_to_prefs_file_iniwrite (inifile ):
85+ tmpFile = '{}~' .format (inifile )
86+ COPY (inifile , tmpFile )
87+ with open (tmpFile , 'r' ) as inFile :
88+ with open (inifile , 'w' ) as outFile :
89+ remove = False
90+ for line in inFile :
91+ if not line :
92+ break
93+ elif line .startswith ('[QTPLASMAC]' ):
94+ remove = True
95+ continue
96+ elif remove :
97+ if line .startswith ('[' ):
98+ remove = False
99+ else :
100+ continue
101+ outFile .write (line )
102+ if os .path .isfile (tmpFile ):
103+ os .remove (tmpFile )
104+ update_notify ('V1.227.219' )
105+
25106# remove the qtplasmac link from the config directory (pre V1.225.208 2022/06/29)
26- def remove_qtplasmac_link (inifile ):
107+ def remove_qtplasmac_link_iniwrite (inifile ):
27108 tmpFile = '{}~' .format (inifile )
28109 COPY (inifile , tmpFile )
29110 with open (tmpFile , 'r' ) as inFile :
@@ -43,7 +124,7 @@ def remove_qtplasmac_link(inifile):
43124 update_notify ('V1.225.208' )
44125
45126# change startup parameters from a subroutine (pre V1.224.207 2022/06/22)
46- def rs274ngc_startup_code (inifile ): #, unitsCode ):
127+ def rs274ngc_startup_code_iniwrite (inifile ):
47128 tmpFile = '{}~' .format (inifile )
48129 COPY (inifile , tmpFile )
49130 with open (tmpFile , 'r' ) as inFile :
@@ -122,7 +203,41 @@ def split_prefs_file(old, new, prefs):
122203 update_notify ('V1.222.170' )
123204
124205# use qtplasmac_comp.hal for component connections (pre V1.221.154 2022/01/18)
125- def add_component_hal_file (path , inifile , halfiles ):
206+ def add_component_hal_file (path , halfiles ):
207+ pinsToCheck = ['PLASMAC COMPONENT INPUTS' ,'plasmac.arc-ok-in' ,'plasmac.axis-x-position' ,
208+ 'plasmac.axis-y-position' ,'plasmac.breakaway' ,'plasmac.current-velocity' ,
209+ 'plasmac.cutting-start' ,'plasmac.cutting-stop' ,'plasmac.feed-override' ,
210+ 'plasmac.feed-reduction' ,'plasmac.float-switch' ,'plasmac.feed-upm' ,
211+ 'plasmac.ignore-arc-ok-0' ,'plasmac.machine-is-on' ,'plasmac.motion-type' ,
212+ 'plasmac.offsets-active' ,'plasmac.ohmic-probe' ,'plasmac.program-is-idle' ,
213+ 'plasmac.program-is-paused' ,'plasmac.program-is-running' ,'plasmac.scribe-start' ,
214+ 'plasmac.spotting-start' ,'plasmac.thc-disable' ,'plasmac.torch-off' ,
215+ 'plasmac.units-per-mm' ,'plasmac.x-offset-current' ,'plasmac.y-offset-current' ,
216+ 'plasmac.z-offset-current' ,
217+ 'PLASMAC COMPONENT OUTPUTS' ,'plasmac.adaptive-feed' ,'plasmac.feed-hold' ,
218+ 'plasmac.offset-scale' ,'plasmac.program-pause' ,'plasmac.program-resume' ,
219+ 'plasmac.program-run' ,'plasmac.program-stop' ,'plasmac.torch-on' ,
220+ 'plasmac.x-offset-counts' ,'plasmac.y-offset-counts' ,'plasmac.xy-offset-enable' ,
221+ 'plasmac.z-offset-counts' ,'plasmac.z-offset-enable' ,'plasmac.requested-velocity' ]
222+ for f in halfiles :
223+ f = os .path .expanduser (f )
224+ if not 'custom' in f :
225+ halfile = os .path .join (path , f )
226+ with open (halfile , 'r' ) as inFile :
227+ if 'plasmac.cutting-start' in inFile .read ():
228+ inFile .seek (0 )
229+ tmpFile = '{}~' .format (halfile )
230+ COPY (halfile , tmpFile )
231+ with open (tmpFile , 'r' ) as inFile :
232+ with open (f , 'w' ) as outFile :
233+ for line in inFile :
234+ if any (pin in line for pin in pinsToCheck ):
235+ continue
236+ outFile .write (line )
237+ if os .path .isfile (tmpFile ):
238+ os .remove (tmpFile )
239+
240+ def add_component_hal_file_iniwrite (inifile ):
126241 written = False
127242 tmpFile = '{}~' .format (inifile )
128243 COPY (inifile , tmpFile )
@@ -163,44 +278,25 @@ def add_component_hal_file(path, inifile, halfiles):
163278 outFile .write (line )
164279 if os .path .isfile (tmpFile ):
165280 os .remove (tmpFile )
166- #'plasmac.axis-z-position',
167- pinsToCheck = ['PLASMAC COMPONENT INPUTS' ,'plasmac.arc-ok-in' ,'plasmac.axis-x-position' ,
168- 'plasmac.axis-y-position' ,'plasmac.breakaway' ,'plasmac.current-velocity' ,
169- 'plasmac.cutting-start' ,'plasmac.cutting-stop' ,'plasmac.feed-override' ,
170- 'plasmac.feed-reduction' ,'plasmac.float-switch' ,'plasmac.feed-upm' ,
171- 'plasmac.ignore-arc-ok-0' ,'plasmac.machine-is-on' ,'plasmac.motion-type' ,
172- 'plasmac.offsets-active' ,'plasmac.ohmic-probe' ,'plasmac.program-is-idle' ,
173- 'plasmac.program-is-paused' ,'plasmac.program-is-running' ,'plasmac.scribe-start' ,
174- 'plasmac.spotting-start' ,'plasmac.thc-disable' ,'plasmac.torch-off' ,
175- 'plasmac.units-per-mm' ,'plasmac.x-offset-current' ,'plasmac.y-offset-current' ,
176- 'plasmac.z-offset-current' ,
177- 'PLASMAC COMPONENT OUTPUTS' ,'plasmac.adaptive-feed' ,'plasmac.feed-hold' ,
178- 'plasmac.offset-scale' ,'plasmac.program-pause' ,'plasmac.program-resume' ,
179- 'plasmac.program-run' ,'plasmac.program-stop' ,'plasmac.torch-on' ,
180- 'plasmac.x-offset-counts' ,'plasmac.y-offset-counts' ,'plasmac.xy-offset-enable' ,
181- 'plasmac.z-offset-counts' ,'plasmac.z-offset-enable' ,'plasmac.requested-velocity' ]
182- for f in halfiles :
183- f = os .path .expanduser (f )
184- if not 'custom' in f :
185- halfile = os .path .join (path , f )
186- with open (halfile , 'r' ) as inFile :
187- if 'plasmac.cutting-start' in inFile .read ():
188- inFile .seek (0 )
189- tmpFile = '{}~' .format (halfile )
190- COPY (halfile , tmpFile )
191- with open (tmpFile , 'r' ) as inFile :
192- with open (f , 'w' ) as outFile :
193- for line in inFile :
194- if any (pin in line for pin in pinsToCheck ):
195- continue
196- outFile .write (line )
197- if os .path .isfile (tmpFile ):
198- os .remove (tmpFile )
199281 update_notify ('V1.221.154' )
200282
283+ # common functions
284+
285+ def get_offsets (data ):
286+ x = y = d = 0
287+ parms = data .lower ().split ()
288+ for parm in parms :
289+ if parm .startswith ('x' ):
290+ x = float (parm .replace ('x' , '' ))
291+ elif parm .startswith ('y' ):
292+ y = float (parm .replace ('y' , '' ))
293+ else :
294+ d = float (parm )
295+ return x , y , d
296+
201297def update_notify (version , restart = False ):
202- print ('-------------------------------' )
298+ print ('\n -------------------------------' )
203299 print ('QtPlasmac updated to' , version )
204300 if restart :
205301 print ('\n **** A restart is required ****\n ' )
206- print ('-------------------------------' )
302+ print ('-------------------------------\n ' )
0 commit comments