image indicator with glade

More
22 Aug 2014 15:29 #50176 by Lavalu
Hi,

i have installed LinuxCNC on several smal and large machines the last few years and i am a realy big fan of your stuff.
yesterday i found the great tool glade to create panel instead of using pyvcp. i am familar with pyvcp, hal, and c to customize linuxcnc but now there is one question for building nice looking panels with glade:
in pyvcp i often use the "u32 image" widget to print out states of big cnc maschines to the user.

is there a way to show different images in a glade panel by changing a hal pin ?

thanks for aswering

Lavalu (www.lavalu.de)

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

More
22 Aug 2014 20:38 #50184 by ArcEye
Replied by ArcEye on topic image indicator with glade
Hi

I would check out JTs tutorial on gladevcp
gnipsel.com/linuxcnc/gladevcp

I don't use glade, but there will be, whether it is hiding one image and making another visible, or just writing a different image to the same widget

regards

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

More
23 Aug 2014 10:48 - 23 Aug 2014 11:17 #50200 by cmorley
Replied by cmorley on topic image indicator with glade
Gladevcp does not have that type of widget built in.
You could use the handler_file technique to do the same thing, it if you know python.

It would be a good widget to add as standard.

Chris M
Last edit: 23 Aug 2014 11:17 by cmorley.

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

More
24 Aug 2014 01:48 #50211 by Lavalu
Replied by Lavalu on topic image indicator with glade
thanks for your reply, will try both on monday. I learn python3 at the moment. i builded a very smal tool with it but never use the handler_file technique.

Lavalu

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

More
25 Aug 2014 11:08 - 25 Aug 2014 11:09 #50253 by cmorley
Replied by cmorley on topic image indicator with glade
Here is a basic example.
load it with loadusr gladevcp -u handler_file.py gladefile.glade

assuming the path/name to the handler_file and glade file is right.
also assuming the glade file has an image with the name 'hal_image1' in it.
of course loading your own images is possible search pygtk examples.
www.pygtk.org/pygtk2reference/class-gtkimage.html

Chris M
import hal_glib
import hal
import gtk # for image references

# boiler code to register our handler
def get_handlers(halcomp,builder,useropts):
    return [HandlerClass(halcomp,builder,useropts)]

class HandlerClass:
    def __init__(self, halcomp,builder,useropts):
        example_trigger = hal_glib.GPin(halcomp.newpin('hal_image1', hal.HAL_BIT, hal.HAL_IN))
        example_trigger.connect('value-changed', self._on_example_trigger_change)
        self.hal_image1 = builder.get_object('hal_image1') # the glade file's image must be the same as this.

    def _on_example_trigger_change(self,pin,userdata=None):
        print "pin value changed to:%d" % (pin.get())
        if pin.get():
            self.hal_image1.set_from_stock(gtk.STOCK_APPLY,gtk.ICON_SIZE_LARGE_TOOLBAR)
        else:
            self.hal_image1.set_from_stock(gtk.STOCK_CANCEL,gtk.ICON_SIZE_LARGE_TOOLBAR)
Last edit: 25 Aug 2014 11:09 by cmorley.

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

More
28 Aug 2014 17:26 - 28 Aug 2014 17:28 #50386 by Lavalu
Replied by Lavalu on topic image indicator with glade
with the post above and the apps in the LinuxCNC 2.6 configuration tree i was able to do a pyvcp image_u32 replacement for gladevcp.

here is the result code of a short example how to:
'''
This file demonstrate how to change a gladevcp picture with a created
hal pin.
notes:
- the handler is linked to "image1" of gladevcp
- to set a filename of a picture the image1 must have the filename opion activated
- the files error_0.png, error_0.png, error_0.png must exist
'''

#---import the needed librarys---
import hal
import glib
import hal_glib
import time
from inspect import stack


#---create a variable with filenames that can be loaded index---
error_files  = ( "./Gui/error_0.png", 
                 "./Gui/error_1.png",
                 "./Gui/error_2.png")
          

#---python code that is not associated with gladevcp ui's---
class OtherClass:

    #---???---	
    def invisible(selfself):
        pass


class HandlerClass:

    #---button press event---
    def on_button_press(self,widget,data=None):
        '''only if button is used'''

    #---hal pin "message" change event---
    def _on_message_change(self,hal_pin,data=None):

        #---set the filename from gladevcp image1 with the value on "message" pin--- 
        self.builder.get_object('image1').set_from_file( error_files[ self.halcomp['message'] ] )


    #---startup procedure---
    def __init__(self, halcomp,builder,useropts):

        #---init halcomp/ builder---        
	self.halcomp = halcomp
        self.builder = builder

        #---create a new halpin to choose an image---
        self.example_trigger = hal_glib.GPin(halcomp.newpin('message',  hal.HAL_U32, hal.HAL_IN))
	
        #---assign the message pin to the _on_message_change event---
        self.example_trigger.connect('value-changed', self._on_message_change)

#---???---
other = OtherClass() 

#---connect this handler to gladevcp instances---
def get_handlers(halcomp,builder,useropts):
    return [HandlerClass(halcomp,builder,useropts)]

To see a "live" example i made a tiny LinuxCNC config with the new gmoccapy screen, see attached file. Copy the file to your config folder and start it with LinuxCNC.

File Attachment:

File Name: PicHandlerEx.zip
File Size:24 KB



Thanks Guys
You Rock The World
Attachments:
Last edit: 28 Aug 2014 17:28 by Lavalu.

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

More
28 Aug 2014 21:39 #50406 by newbynobi
Looks good,
and the best is you are using gmoccapy ;-)

we should integrate a custom widget in gladevcp.
Unfortunately I am still out of time.

Norbert

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

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