'''
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)]

