2323from qtvcp .widgets .entry_widget import TouchInterface
2424from qtvcp .core import Status , Action , Info
2525from qtvcp import logger
26+ from qtvcp .widgets .touchEntry import TouchDoubleSpinBox ,TouchSpinBox
2627
2728# Instantiate the libraries with global reference
2829# INFO holds INI file details
3637
3738# Set the log level for this module
3839if not INFO .LINUXCNC_IS_RUNNING :
39- LOG .setLevel (logger .ERROR ) # One of DEBUG, INFO, WARNING, ERROR, CRITICAL
40+ LOG .setLevel (logger .DEBUG ) # One of DEBUG, INFO, WARNING, ERROR, CRITICAL
4041
4142try :
4243 from PyQt5 import QtSvg
@@ -158,13 +159,14 @@ def __init__(self, parent=None):
158159 vbox .addLayout (hbox )
159160 # add all that stuff above to me
160161 self .setLayout (vbox )
161- # add everything else
162- self .buildStack ()
163162
164163 def sizeHint (self ):
165164 return QtCore .QSize (200 , 200 )
166165
167166 def _hal_init (self ):
167+ # add The macros to the stacked wodget
168+ self .buildStack (INFO .SUB_PATH_LIST )
169+
168170 self .runButton .setEnabled (False )
169171 STATUS .connect ('state-off' , lambda w : self .runButton .setEnabled (False ))
170172 STATUS .connect ('state-estop' , lambda w : self .runButton .setEnabled (False ))
@@ -183,9 +185,13 @@ def _hal_init(self):
183185 # then build a menu page
184186 # then build the stack
185187 # anything goes wrong display an error page
186- def buildStack (self ):
188+ def buildStack (self , pathlist ):
189+ def checkIfFloat (val ):
190+ return all ([ [any ([i .isnumeric (), i in ['.' ,'e' ]]) for i in val ], len (val .split ('.' )) == 2 ] )
191+
187192 macroFlag = False
188- for path in INFO .SUB_PATH_LIST :
193+ for path in pathlist :
194+ print (path )
189195 if 'macro' in path :
190196 path = os .path .expanduser (path )
191197 tabName = self ._findMacros (path )
@@ -224,7 +230,7 @@ def buildStack(self):
224230
225231 # layout holds label and entry for one line
226232 hbox2 = QtWidgets .QHBoxLayout ()
227- # make a label
233+ # make a label
228234 l = QtWidgets .QLabel (name [0 ])
229235
230236 # make appropriate entries:
@@ -235,13 +241,26 @@ def buildStack(self):
235241 self ['%s%d' % (tName , n )].setChecked (True )
236242 # line edits that will pop an entry dialog:
237243 else :
238- self ['%s%d' % (tName , n )] = QtWidgets .QLineEdit ()
244+ print (name [1 ], checkIfFloat (name [1 ]))
245+ if checkIfFloat (name [1 ]):
246+ #self['%s%d' % (tName, n)] = QtWidgets.QLineEdit()
247+ #self['%s%d' % (tName, n)].setText(name[1])
248+ self ['%s%d' % (tName , n )] = TouchDoubleSpinBox ()
249+ self ['%s%d' % (tName , n )].callDialog = self .getNumbers
250+ self ['%s%d' % (tName , n )].setValue (float (name [1 ]))
251+ else :
252+ self ['%s%d' % (tName , n )] = TouchSpinBox ()
253+ self ['%s%d' % (tName , n )].callDialog = self .getNumbers
254+ self ['%s%d' % (tName , n )].setValue (int (name [1 ]))
255+ self ['%s%d' % (tName , n )]._label = name [0 ]
256+ self ['%s%d' % (tName , n )]._tabName = tName
257+ self .set_style (self ['%s%d' % (tName , n )])
239258 self ['%s%d' % (tName , n )].keyboard_type = 'numeric'
240- self [ '%s%d' % ( tName , n )]. setText ( name [ 1 ])
259+
241260 hbox2 .addWidget (l )
242261 hbox2 .addWidget (self ['%s%d' % (tName , n )])
243262
244- # add label/entry layout to vertical layout fr this tab
263+ # add label/entry layout to vertical layout fr this tab
245264 vbox .addLayout (hbox2 )
246265
247266 #add the SVG/image pic layer
@@ -279,7 +298,7 @@ def buildStack(self):
279298 # show a message
280299 if macroFlag == False :
281300 self ._buildErrorTab ()
282-
301+ print ( self . stack . count ())
283302 # Menu page has icon buttons to select the macro
284303 # it finds the icon info from the macro file
285304 # using the magic comments parsed before this
@@ -342,7 +361,7 @@ def _buildErrorTab(self):
342361 # self['macroname'] = [ [DEFAULT DATA],[SVG FILE,LAYER,ICON LAYER],{OPTION DICT NAME:OPTION DICT DATA,}]
343362 # returns a list on the macro names that it finds valid
344363
345- def _findMacros (self ,path ):
364+ def _findMacros (self , path ):
346365 tName = []
347366 macros = []
348367 defaults = []
@@ -362,7 +381,7 @@ def _findMacros(self,path):
362381 # check if they have the magic comments
363382 if 'MACROCOMMAND' in first_line and \
364383 'MACRODEFAULT' in second_line and \
365- ('MACROSVG' in third_line or
384+ ('MACROSVG' in third_line or
366385 'MACROIMAGE' in third_line ):
367386 name = os .path .splitext (f )[0 ]
368387 # yes, now keep everything after '='
@@ -532,7 +551,7 @@ def saveReturn(self, path):
532551 line = '%s,%s, %s\n ' % ( widgetname , str (data ), i [0 ])
533552 QtCore .QTextStream (file ) << line
534553 else :
535- QtWidgets . QMessageBox .information (self , "Unable to open file" ,
554+ QMessageBox .information (self , "Unable to open file" ,
536555 file .errorString ())
537556
538557 # we do this instead of directly so the dialog version's title changes
@@ -541,10 +560,10 @@ def setTitle(self, string):
541560 self .setWindowTitle (string )
542561
543562 # get numeric data
544- def getNumbers (self ,widget ,ktype ):
563+ def getNumbers (self ,widget ,ktype = None ):
545564 mess = {'NAME' :self ._request_name ,'ID' :'%s__macro' ,
546565 'PRELOAD' :float (widget .text ()),
547- 'TITLE' :'Macro Entry Calculator' ,'WIDGET' :widget }
566+ 'TITLE' :'{} Macro Entry For {}' . format ( widget . _tabName , widget . _label ) ,'WIDGET' :widget }
548567 STATUS .emit ('dialog-request' , mess )
549568
550569 # request the system to pop a load path picker dialog
@@ -585,7 +604,53 @@ def returnFromDialog(self, w, message):
585604 widget = message .get ('WIDGET' )
586605 if code and widget is not None :
587606 if num is not None :
588- widget .setText (str (num ))
607+ widget .setValue (num )
608+
609+ def set_style (self , widget ):
610+ widget .setStyleSheet (
611+ """
612+ QDoubleSpinBox,
613+ QSpinBox {
614+ padding-right: 15px; /* make room for the arrows */
615+ border-image: url(:/images/frame.png) 4;
616+ border-width: 3;
617+ padding-left: 5px;
618+ padding-right: 5px;
619+ padding-top: 0px;
620+ padding-bottom: 0px;
621+ font-size:20px;
622+ border: 1px solid black;
623+ min-width: 100px;
624+ max-height: 30;
625+ }
626+
627+ QDoubleSpinBox::up-button,
628+ QSpinBox::up-button {
629+ subcontrol-origin: border;
630+ subcontrol-origin: padding;
631+ subcontrol-position: right; width: 30px; height: 28px;
632+ image: url(:/widget/images/arrow_up1.png);
633+ border: 1px solid black;
634+ }
635+ QDoubleSpinBox::up-button:pressed,
636+ QSpinBox::up-button:pressed {
637+ image: url(:/widget/images/arrow_up2.png);
638+ }
639+
640+ QDoubleSpinBox::down-button,
641+ QSpinBox::down-button {
642+ subcontrol-origin: border;
643+ subcontrol-origin: padding;
644+ subcontrol-position: left; width: 30px; height: 28px;
645+ image: url(:/widget/images/arrow_down1.png);
646+ border: 1px solid black;
647+ }
648+ QDoubleSpinBox::down-button:pressed,
649+ QSpinBox::down-button:pressed {
650+ image: url(:/widget/images/arrow_down2.png) 1;
651+ }
652+
653+ """ )
589654
590655 # usual boiler code
591656 # (used so we can use code such as self[SomeDataName]
@@ -600,6 +665,7 @@ def __setitem__(self, item, value):
600665 app = QtWidgets .QApplication (sys .argv )
601666 #sw = QtSvg.QSvgWidget('LatheMacro.svg')
602667 sw = MacroTab ()
668+ sw .buildStack (['~/linuxcnc/nc_files/examples/macros/lathe' ])
603669 sw .setGeometry (50 , 50 , 759 , 668 )
604670 sw .show ()
605671 sys .exit (app .exec_ ())
0 commit comments