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.

More
22 Apr 2024 20:38 #298863 by Todd Zuercher
I tried to open the above example and it doesn't seem to work with the current version of Linuxcnc. What all would need to be changed in order for it to work again?

Or would there be a better way to achieve the equivalent of a PyVCP U32 Image in Glade now? I need to have a series of indicators that show 1 of 11 different states, depending on the value of a hal pin.

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

More
22 Apr 2024 21:34 #298871 by HansU
Replied by HansU on topic image indicator with glade
This GladeVCP is basically compatible with the current LinuxCNC version. Only in the python file there is a mix of tabs and spaces for indentation which make this fail with Python3.
Fixing this make the VCP work. I attached the fixed version.
 
 
Attachments:
The following user(s) said Thank You: Todd Zuercher

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

More
02 May 2024 12:46 #299547 by Todd Zuercher
I'm really struggling with the python side of this. So far everything I've tried fails and I haven't been able to usefully decipher the output at the command line to understand where I'm going wrong.  I'd like to have all of the image files stored in a sub directory in the machine config directory and I need to use the same list of possible images for multiple displays in the VCP. Here is the beginning of what I'd like the gladevcp to look like.
 
The 8 orange "Fault Locout" images, are the ones that I need to change depending on the state of each VFDs status.
The list of all of the image names is 0-fault-lockout.gif, 1-fault.gif, 2-start-pending.gif, 3-stop.gif, 4-dc-brake.gif, 5-run-at-0hz.gif, 6-run.gif, 7-accel.gif, 8-decel.gif, 9-current-limit.gif, 10-decel-override.gif, and 11-lower-transistors-switchin-on.gif
Attachments:

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

Moderators: HansU
Time to create page: 0.133 seconds
Powered by Kunena Forum