Skip to content

Commit

Permalink
gladevcp/drowidget: Fix missing property 'background_color'
Browse files Browse the repository at this point in the history
  • Loading branch information
hansu committed Jan 5, 2025
1 parent 27dca77 commit bbbf40b
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions lib/python/gladevcp/drowidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,22 @@ class HAL_DRO(Gtk.Label):
GObject.ParamFlags.READWRITE),
'homed_color' : (Gdk.RGBA.__gtype__, 'Homed Color', 'The color of the DRO text when homed',
GObject.ParamFlags.READWRITE),
'background_color' : (Gdk.RGBA.__gtype__, 'Background Color', 'The color of the DRO background',
GObject.ParamFlags.READWRITE),
}
__gproperties = __gproperties__

def __init__(self, *a, **kw):
self.css = Gtk.CssProvider()
self.css_text = f"""label {{
font-family: sans;
font-size: 26px;
font-weight: bold;
}}
.dro_unhomed {{color: red}}
.dro_homed {{color: green}}
"""
font-family: sans;
font-size: 26px;
font-weight: bold;
background: black;
}}
.dro_unhomed {{color: red}}
.dro_homed {{color: green}}
"""
Gtk.Label.__init__(self, *a, **kw)
self.status = linuxcnc.stat()
self.display_units_mm = 0
Expand Down Expand Up @@ -114,6 +117,7 @@ def __init__(self, *a, **kw):
self.get_style_context().add_class('dro_unhomed')
self.unhomed_color = self.str_to_rgba('red')
self.homed_color = self.str_to_rgba('green')
self.background_color = self.str_to_rgba('black')
if self.linuxcnc:
GStat().connect('homed', self._homed )
GStat().connect('unhomed', self._homed )
Expand Down Expand Up @@ -171,6 +175,13 @@ def do_set_property(self, property, value):
else:
LOG.warning(f"Invalid homed_color '{value}', " \
"it should be a Gdk.RGBA color")
elif name == "background_color":
if not value: value = self.background_color
if isinstance(value, gi.overrides.Gdk.RGBA):
self.set_style("background", self.rgba_to_hex(value))
else:
LOG.warning(f"Invalid background_color '{value}', " \
"it should be a Gdk.RGBA color")
if name in list(self.__gproperties.keys()):
setattr(self, name, value)
self.queue_draw()
Expand All @@ -193,6 +204,9 @@ def set_style(self, property, value):
elif property == "homed":
old = '.dro_h.*'
new = f".dro_homed {{color: {value}}}"
elif property == "background":
old = 'background.*'
new = f"background: {value};"
else:
LOG.warning(f"'{property}' is an unknown property")
return
Expand Down

0 comments on commit bbbf40b

Please sign in to comment.