Label
- BigJohnT
-
Topic Author
- Offline
- Administrator
-
- Posts: 7000
- Thank you received: 1175
Thanks for the help on this. I got it working once I noticed the added include for GTK

I added an off color of F5F5F5 and it is close to the normal background, is there a way to just not have the color set when off?
John
Please Log in or Create an account to join the conversation.
- BigJohnT
-
Topic Author
- Offline
- Administrator
-
- Posts: 7000
- Thank you received: 1175
Please Log in or Create an account to join the conversation.
- BigJohnT
-
Topic Author
- Offline
- Administrator
-
- Posts: 7000
- Thank you received: 1175
Please Log in or Create an account to join the conversation.
- BigJohnT
-
Topic Author
- Offline
- Administrator
-
- Posts: 7000
- Thank you received: 1175
Please Log in or Create an account to join the conversation.
- mhaberler
- Offline
- Moderator
-
- Posts: 195
- Thank you received: 11
git.mah.priv.at/gitweb/emc2-dev.git/shor...s/heads/custom-label
-m
Please Log in or Create an account to join the conversation.
- Rick G
-
- Offline
- Junior Member
-
- Posts: 26
- Thank you received: 155
Rick G
Please Log in or Create an account to join the conversation.
- BigJohnT
-
Topic Author
- Offline
- Administrator
-
- Posts: 7000
- Thank you received: 1175
I'm trying to add a second value dependent label and can't quite figure out what needs to be added. Starting with the simple example I've got this far... but I have a few questions.
#!/usr/bin/env python
import hal
import hal_glib
#
class HandlerClass:
def _on_value_change(self,hal_pin,data=None):
#print "_on_value_change() - HAL pin value: %s" % (hal_pin.get())
value = hal_pin.get()
if value < 0:
self.label.set_label("REVERSE")
elif value > 0:
self.label.set_label("FORWARD")
else:
self.label.set_label("OFF")
def _on_status_change(self,hal_pin,data=None):
#print "_on_value_change() - HAL pin value: %s" % (hal_pin.get())
value = hal_pin.get()
if value < 0:
self.label.set_label("Drive OK")
elif value > 0:
self.label.set_label("Drive Broken")
else:
self.label.set_label("Drive Unknown")
def __init__(self, halcomp,builder,useropts):
self.halcomp = halcomp
self.builder = builder
# hal pins with change callback, unrelated to any HAL widget.
# When the pin's value changes the callback is executed.
self.inpin = hal_glib.GPin(halcomp.newpin('input-pin', hal.HAL_FLOAT, hal.HAL_IN))
self.inpin.connect('value-changed', self._on_value_change)
self.label = self.builder.get_object('label1')
# second pin
self.inpin = hal_glib.GPin(halcomp.newpin('status-pin', hal.HAL_FLOAT, hal.HAL_IN))
self.inpin.connect('value-changed', self._on_staus_change)
self.label = self.builder.get_object('label2')
# Does the line above need a unique name?
def get_handlers(halcomp,builder,useropts):
return [HandlerClass(halcomp,builder,useropts)]
Please Log in or Create an account to join the conversation.
- mhaberler
- Offline
- Moderator
-
- Posts: 195
- Thank you received: 11
...
def __init__(self, halcomp,builder,useropts):
# this makes self.label to refer to the 'label1' object
self.label = self.builder.get_object('label1')
....
# the line below overwrites the above reference, so both
# _on_status_change and _on_value_change will
# change the label of the 'label2' object:
self.label = self.builder.get_object('label2')
'label1' and 'label2' are the names given to the labels in glade
whereas self.label is a Python reference to an object (which is returned by builder.get_object(<name>)
just name the references identical like the string names - less confusing, like so:
self.label1 = self.builder.get_object('label1')
self.label2 = self.builder.get_object('label2')
you need to fix the references in the _on_... handlers, too
-m
Please Log in or Create an account to join the conversation.
- BigJohnT
-
Topic Author
- Offline
- Administrator
-
- Posts: 7000
- Thank you received: 1175
However for some reason the background color changes for the drive status label and I can't spot my error...
#!/usr/bin/env python
import gtk
import hal
import hal_glib
#
class HandlerClass:
def _on_value_change(self,hal_pin,data=None):
#print "_on_value_change() - HAL pin value: %s" % (hal_pin.get())
value = hal_pin.get()
if value < 0:
self.label.set_label("REV")
self.eventbox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("red"))
elif value > 0:
self.label.set_label("FWD")
self.eventbox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("green"))
else:
self.label.set_label("OFF")
self.eventbox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#F5F5F5"))
def _on_status1_change(self,hal_pin,data=None):
value = hal_pin.get()
print "_on_status1_change() - HAL pin value: %s" % (hal_pin.get())
if value == 0:
self.label2.set_label("Drive Status = No Faults")
elif value == 1:
self.label2.set_label("Drive Status = Over Current")
elif value == 2:
self.label2.set_label("Drive Status = Over Voltage")
elif value == 3:
<snip>
else:
self.label2.set_label("Drive Status = Unknown")
def __init__(self, halcomp,builder,useropts):
self.halcomp = halcomp
self.builder = builder
# hal pins with change callback, unrelated to any HAL widget.
# When the pin's value changes the callback is executed.
self.inpin = hal_glib.GPin(halcomp.newpin('input-pin', hal.HAL_FLOAT, hal.HAL_IN))
self.inpin.connect('value-changed', self._on_value_change)
self.label = self.builder.get_object('spindle-direction')
self.eventbox = self.builder.get_object('eventbox1')
self.button = self.builder.get_object('hal_button1')
self.button.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("yellow"))
self.button.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse("red"))
self.button.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse("blue"))
# define gs2 status 1
self.inpin = hal_glib.GPin(halcomp.newpin('gs2-status1', hal.HAL_S32, hal.HAL_IN))
self.inpin.connect('value-changed', self._on_status1_change)
self.label2 = self.builder.get_object('gs2-status1')
self.eventbox = self.builder.get_object('eventbox2')
def get_handlers(halcomp,builder,useropts):
return [HandlerClass(halcomp,builder,useropts)]
Thanks
John
Please Log in or Create an account to join the conversation.
- mhaberler
- Offline
- Moderator
-
- Posts: 195
- Thank you received: 11
Ok, the label text changes as expected now as the drive status value changes YIPPIE!
However for some reason the background color changes for the drive status label and I can't spot my error...
Thanks
John
I think it could have to do with this:
developer.gnome.org/gtk-faq/stable/x810.html
mail.gnome.org/archives/gtk-app-devel-li...anuary/msg00432.html
unit of coloring is an X window object and labels dont have their own for performance reasons methinks
Try putting the label inside a Event box which has an X window, and color this enclosing event box
can you post both glade and python files so I can try?
-Michael
Please Log in or Create an account to join the conversation.