11#!/usr/bin/env python3
22# vim: sts=4 sw=4 et
3- # This is a component of EMC
4- # savestate.py copyright 2013 Andy Pugh
3+ # This is a component of LinuxCNC
4+ # Copyright 2013 Andy Pugh
55# based on code from
66# probe.py Copyright 2010 Michael Haberler
77#
4141debug = 0
4242notouch = 0
4343norun = 0
44+ svgfile = os .path .join (os .path .dirname (__file__ ), "LatheMacro.svg" )
4445
4546class HandlerClass :
4647 active = False
4748 tab_num = 0
4849
4950 def on_expose (self ,nb ,data = None ):
50- tab_num = nb .get_current_page ()
51- tab = nb .get_nth_page (tab_num )
52- alloc = tab .get_allocation ()
53- x , y , w , h = (alloc .x , alloc .y , alloc .width , alloc .height )
54- pixbuf = self .svg .get_pixbuf_sub (f'#layer{ tab_num } ' ).scale_simple (w - 10 , h - 10 , GdkPixbuf .InterpType .BILINEAR )
55- im = self .builder .get_object (f'Image{ tab_num } ' )
56- im .set_from_pixbuf (pixbuf )
57- for c in im .get_parent ().get_children ():
58- if c .get_has_tooltip ():
59- m = re .findall (r'<!--(\d+),(\d+)-->' , c .get_tooltip_markup ())
60- if len (m ) > 0 :
61- x1 = int (m [0 ][0 ]); y1 = int (m [0 ][1 ])
62- c .set_margin_left (max (0 , w * x1 / 1500 ))
63- c .set_margin_top (max (0 , h * y1 / 1000 ))
51+ if nb .has_focus ():
52+ tab_num = nb .get_current_page ()
53+ tab = nb .get_nth_page (tab_num )
54+ alloc = tab .get_allocation ()
55+ x , y , w , h = (alloc .x , alloc .y , alloc .width , alloc .height )
56+ pixbuf = self .svg .get_pixbuf_sub (f'#layer{ tab_num } ' ).scale_simple (w - 10 , h - 10 , GdkPixbuf .InterpType .BILINEAR )
57+ im = self .builder .get_object (f'Image{ tab_num } ' )
58+ im .set_from_pixbuf (pixbuf )
59+ for c in im .get_parent ().get_children ():
60+ if c .get_has_tooltip ():
61+ m = re .findall (r'<!--(\d+),(\d+)-->' , c .get_tooltip_markup ())
62+ if len (m ) > 0 :
63+ x1 = int (m [0 ][0 ]); y1 = int (m [0 ][1 ])
64+ c .set_margin_left (max (0 , w * x1 / 1500 ))
65+ c .set_margin_top (max (0 , h * y1 / 1000 ))
6466
6567
6668 # decide if our window is active to mask the cycle-start hardware button
@@ -112,17 +114,15 @@ def __init__(self, halcomp,builder,useropts):
112114
113115 # This connects the expose event to re-draw and scale the SVG frames
114116 t = self .builder .get_object ('tabs1' )
115- t .connect_after ("draw " , self .on_expose )
117+ t .connect_after ("state-flags-changed " , self .on_expose )
116118 t .connect ("destroy" , Gtk .main_quit )
117119 t .add_events (Gdk .EventMask .STRUCTURE_MASK )
118- self .svg = Rsvg .Handle ().new_from_file ('LatheMacro.svg' )
120+ self .svg = Rsvg .Handle ().new_from_file (svgfile )
119121 self .active = True
120122
121123 # handle Useropts
122124 if norun :
123- for c in range (0 ,6 ):
124- print (c )
125- print ( f'tab{ c } .action' )
125+ for c in range (0 ,7 ):
126126 self .builder .get_object (f'tab{ c } .action' ).set_visible (False )
127127
128128 def show_keyb (self , obj , data = None ):
@@ -148,7 +148,9 @@ def keyb_number_click(self, obj, data=None):
148148
149149 def keyb_pm_click (self , obj , data = None ):
150150 data = self .entry .get_text ()
151- if data [0 ] == '-' :
151+ if not data :
152+ data = "-"
153+ elif data [0 ] == '-' :
152154 data = data [1 :]
153155 else :
154156 data = '-' + data
@@ -214,4 +216,3 @@ def get_handlers(halcomp,builder,useropts):
214216 return [HandlerClass (halcomp ,builder ,useropts )]
215217
216218
217-
0 commit comments