Skip to content

Commit

Permalink
Merge pull request #2798 from phillc54/phillc54/pncconf
Browse files Browse the repository at this point in the history
pncconf: use CSS for coloring stepscale and encoderscale widgets
  • Loading branch information
andypugh authored Dec 26, 2023
2 parents a94f732 + 769d1d7 commit 8bcef84
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/emc/usr_intf/pncconf/a_motor.glade
Original file line number Diff line number Diff line change
Expand Up @@ -2148,6 +2148,7 @@
</child>
<child>
<object class="GtkSpinButton" id="aencoderscale">
<property name="name">aencoderscale</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
Expand Down Expand Up @@ -2176,6 +2177,7 @@
</child>
<child>
<object class="GtkSpinButton" id="astepscale">
<property name="name">astepscale</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
Expand Down
4 changes: 0 additions & 4 deletions src/emc/usr_intf/pncconf/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,6 @@ def initialize(self):
self.a.fill_pintype_model()

self.intro_prepare()
# get the original background color, must realize the widget first to get the true color.
# we use this later to high light missing axis info
self.w.xencoderscale.realize()
self.a.origbg = self.w.xencoderscale.get_style_context().get_property("background-color", Gtk.StateFlags.NORMAL)
# TODO TODO cannot set size correctly, try in pncconf.py L289
# self.w.window1.set_geometry_hints(min_width=750)
self.w.button_save.set_visible(False)
Expand Down
21 changes: 17 additions & 4 deletions src/emc/usr_intf/pncconf/pncconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ def __init__(self, dbgstate=0):
self.widgets.createshortcut.set_active(short)
self.widgets.advancedconfig.set_active(show_pages)

# setup stylesheet for widget coloring
# we use this later to highlight missing axis and encoder info
self.css_provider = Gtk.CssProvider()
context = Gtk.StyleContext()
screen = Gdk.Screen.get_default()
context.add_provider_for_screen(screen, self.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

tempfile = os.path.join(self._p.DISTDIR, "configurable_options/ladder/TEMP.clp")
if os.path.exists(tempfile):
os.remove(tempfile)
Expand Down Expand Up @@ -4899,16 +4906,22 @@ def motor_encoder_sanity_check(self,widgets,axis):
if self.findsignal(axis+"-encoder-a"): encoder = True
if self.findsignal(axis+"-resolver"): resolver = True
if self.findsignal(axis+"-pot-outpot"): pot = True
css = ""
if encoder or resolver:
if self.widgets[axis+"encoderscale"].get_value() < 1:
self.widgets[axis+"encoderscale"].override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA.from_color(Gdk.color_parse('red')))
css += f'#{axis}encoderscale'
dbg('encoder resolver scale bad %f'%self.widgets[axis+"encoderscale"].get_value())
bad = True
if stepdrive:
if self.widgets[axis+"stepscale"].get_value() < 1:
self.widgets[axis+"stepscale"].override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA.from_color(Gdk.color_parse('red')))
if css:
css += ", "
css += f'#{axis}stepscale'
dbg('step scale bad')
bad = True
if css:
css += '{background-color: red}'
self.css_provider.load_from_data(css.encode())
if not (encoder or resolver) and not stepdrive and not axis == "s":
dbg('encoder %s resolver %s stepper %s axis %s'%(encoder,resolver,stepdrive,axis))
bad = True
Expand All @@ -4925,8 +4938,8 @@ def motor_encoder_sanity_check(self,widgets,axis):
self.widgets[axis + "axistest"].set_sensitive(0)
else:
dbg('motor %s_encoder sanity check - good'%axis)
self.widgets[axis+"encoderscale"].override_background_color(Gtk.StateFlags.NORMAL, self.origbg)
self.widgets[axis+"stepscale"].override_background_color(Gtk.StateFlags.NORMAL, self.origbg)
css = f'#{axis}stepscale, #{axis}encoderscale {{background-color: @theme_bg_color;}}'
self.css_provider.load_from_data(css.encode())
self.p.set_buttons_sensitive(1,1)
self.widgets[axis + "axistune"].set_sensitive(1)
self.widgets[axis + "axistest"].set_sensitive(1)
Expand Down
2 changes: 2 additions & 0 deletions src/emc/usr_intf/pncconf/x_motor.glade
Original file line number Diff line number Diff line change
Expand Up @@ -2248,6 +2248,7 @@
</child>
<child>
<object class="GtkSpinButton" id="xencoderscale">
<property name="name">xencoderscale</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
Expand Down Expand Up @@ -2278,6 +2279,7 @@
</child>
<child>
<object class="GtkSpinButton" id="xstepscale">
<property name="name">xstepscale</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
Expand Down
2 changes: 2 additions & 0 deletions src/emc/usr_intf/pncconf/y_motor.glade
Original file line number Diff line number Diff line change
Expand Up @@ -2242,6 +2242,7 @@
</child>
<child>
<object class="GtkSpinButton" id="yencoderscale">
<property name="name">yencoderscale</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
Expand Down Expand Up @@ -2272,6 +2273,7 @@
</child>
<child>
<object class="GtkSpinButton" id="ystepscale">
<property name="name">ystepscale</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
Expand Down
2 changes: 2 additions & 0 deletions src/emc/usr_intf/pncconf/z_motor.glade
Original file line number Diff line number Diff line change
Expand Up @@ -2242,6 +2242,7 @@
</child>
<child>
<object class="GtkSpinButton" id="zencoderscale">
<property name="name">zencoderscale</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
Expand Down Expand Up @@ -2272,6 +2273,7 @@
</child>
<child>
<object class="GtkSpinButton" id="zstepscale">
<property name="name">zstepscale</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
Expand Down

0 comments on commit 8bcef84

Please sign in to comment.