1616
1717import sys , os
1818import math
19- import linuxcnc
2019import re
2120import inspect
2221
@@ -73,6 +72,8 @@ class HAL_DRO(Gtk.Label):
7372 GObject .ParamFlags .READWRITE ),
7473 'homed_color' : (Gdk .RGBA .__gtype__ , 'Homed Color' , 'The color of the DRO text when homed' ,
7574 GObject .ParamFlags .READWRITE ),
75+ 'background_color' : (Gdk .RGBA .__gtype__ , 'Background Color' , 'The color of the DRO background' ,
76+ GObject .ParamFlags .READWRITE ),
7677 }
7778 __gproperties = __gproperties__
7879
@@ -82,6 +83,7 @@ def __init__(self, *a, **kw):
8283 font-family: sans;
8384 font-size: 26px;
8485 font-weight: bold;
86+ background: black;
8587 }}
8688.dro_unhomed {{color: red}}
8789.dro_homed {{color: green}}
@@ -91,18 +93,6 @@ def __init__(self, *a, **kw):
9193 self .display_units_mm = 0
9294 self .machine_units_mm = 0
9395 self .unit_convert = [1 ]* 9
94-
95- self .css_text = """
96- .background {background-color: #000000;}
97- .labelcolor {color: #FF0000;}
98- """
99-
100- self .css = Gtk .CssProvider ()
101- self .css .load_from_data (bytes (self .css_text , 'utf-8' ))
102- self .get_style_context ().add_provider (self .css ,Gtk .STYLE_PROVIDER_PRIORITY_APPLICATION )
103- self .get_style_context ().add_class ('background' )
104- self .get_style_context ().add_class ('labelcolor' )
105-
10696 try :
10797 self .inifile = linuxcnc .ini (INIPATH )
10898 # check the INI file if UNITS are set to mm"
@@ -127,6 +117,7 @@ def __init__(self, *a, **kw):
127117 self .get_style_context ().add_class ('dro_unhomed' )
128118 self .unhomed_color = self .str_to_rgba ('red' )
129119 self .homed_color = self .str_to_rgba ('green' )
120+ self .background_color = self .str_to_rgba ('black' )
130121 if self .linuxcnc :
131122 GStat ().connect ('homed' , self ._homed )
132123 GStat ().connect ('unhomed' , self ._homed )
@@ -184,6 +175,13 @@ def do_set_property(self, property, value):
184175 else :
185176 LOG .warning (f"Invalid homed_color '{ value } ', " \
186177 "it should be a Gdk.RGBA color" )
178+ elif name == "background_color" :
179+ if not value : value = self .background_color
180+ if isinstance (value , gi .overrides .Gdk .RGBA ):
181+ self .set_style ("background" , self .rgba_to_hex (value ))
182+ else :
183+ LOG .warning (f"Invalid background_color '{ value } ', " \
184+ "it should be a Gdk.RGBA color" )
187185 if name in list (self .__gproperties .keys ()):
188186 setattr (self , name , value )
189187 self .queue_draw ()
@@ -200,6 +198,9 @@ def set_style(self, property, value):
200198 elif property == "weight" :
201199 old = '-wei.*'
202200 new = f"-weight: { value } ;"
201+ elif property == "background" :
202+ old = 'background.*'
203+ new = f"background: { value } ;"
203204 elif property == "unhomed" :
204205 old = '.dro_u.*'
205206 new = f".dro_unhomed {{color: { value } }}"
@@ -326,33 +327,6 @@ def set_to_diameter(self):
326327 def set_to_radius (self ):
327328 self .diameter = False
328329
329- def set_style (self , property , Data ):
330- # self.css_text = """
331- # .background {background-color: black;}
332- # .labelcolor {color: red;}
333- # """
334-
335- if property == "background" :
336- self .get_style_context ().remove_class ('background' )
337- replacement_string = ".background {background-color: " + Data + ";}"
338- self .css_text = re .sub (r'[.][b][a][c][k][g][r][o][u][n][d].*' , replacement_string , self .css_text , re .IGNORECASE )
339-
340- elif property == "labelcolor" :
341- self .get_style_context ().remove_class ('labelcolor' )
342- replacement_string = ".labelcolor {color: " + Data + ";}"
343- self .css_text = re .sub (r'[.][l][a][b][e][l][c][o][l][o][r].*' , replacement_string , self .css_text , re .IGNORECASE )
344-
345- else :
346- print ("Got unknown property in <<set_style>>" )
347- return
348-
349- self .css .load_from_data (bytes (self .css_text , 'utf-8' ))
350-
351- self .get_style_context ().add_class ('background' )
352- self .get_style_context ().add_class ('labelcolor' )
353-
354- self .queue_draw ()
355-
356330# for testing without glade editor:
357331def main ():
358332 window = Gtk .Dialog ("My dialog" ,
0 commit comments