Label

More
09 Jan 2012 23:31 #16488 by BigJohnT
Replied by BigJohnT on topic Re:Label
Michael,

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.

More
09 Jan 2012 23:49 - 09 Jan 2012 23:54 #16491 by BigJohnT
Replied by BigJohnT on topic Re:Label
Forward

Attachments:
Last edit: 09 Jan 2012 23:54 by BigJohnT.

Please Log in or Create an account to join the conversation.

More
09 Jan 2012 23:50 - 09 Jan 2012 23:54 #16492 by BigJohnT
Replied by BigJohnT on topic Re:Label
Reverse

Attachments:
Last edit: 09 Jan 2012 23:54 by BigJohnT.

Please Log in or Create an account to join the conversation.

More
09 Jan 2012 23:53 - 09 Jan 2012 23:55 #16494 by BigJohnT
Replied by BigJohnT on topic Re:Label
Off

Attachments:
Last edit: 09 Jan 2012 23:55 by BigJohnT.

Please Log in or Create an account to join the conversation.

More
10 Jan 2012 07:02 #16509 by mhaberler
Replied by mhaberler on topic Re:Label
I updated the custom-label branch to retrieve the default background color, and set that if the pin value is zero.

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.

More
10 Jan 2012 09:30 #16512 by Rick G
Replied by Rick G on topic Re:Label
Pretty neat

Rick G

Please Log in or Create an account to join the conversation.

More
29 Jan 2012 15:11 - 29 Jan 2012 15:12 #17261 by BigJohnT
Replied by BigJohnT on topic Re:Label
Michael,

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)]
Last edit: 29 Jan 2012 15:12 by BigJohnT.

Please Log in or Create an account to join the conversation.

More
29 Jan 2012 15:25 #17262 by mhaberler
Replied by mhaberler on topic Re:Label
ok, what happens is:
...
    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.

More
01 Feb 2012 15:04 #17317 by BigJohnT
Replied by BigJohnT on topic Re:Label
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...
#!/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.

More
01 Feb 2012 15:20 #17318 by mhaberler
Replied by mhaberler on topic Re:Label
BigJohnT wrote:

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.

Moderators: mhaberlerHansU
Time to create page: 0.088 seconds
Powered by Kunena Forum