- Posts: 4739
- Thank you received: 2
image indicator with glade
- Todd Zuercher
- Offline
- Platinum Member
-
Less
More
2 years 5 months ago #299554
by Todd Zuercher
Replied by Todd Zuercher on topic image indicator with glade
Why does it always seem that you can't make any progress figuring something out, until you go and post a question about it. Then soon after you finally figure it out?
I think I finally have it working! I know there are still problems with my vcp and it's handler file but at least the image changing is working now.
Here is what the handler file looks like.
(Now to work on all of the other error messages and warnings that pop up in the terminal, but this is a good start for me.)
I think I finally have it working! I know there are still problems with my vcp and it's handler file but at least the image changing is working now.
Here is what the handler file looks like.
Code:
import hal
import glib
import hal_glib
import time
import gtk # for image references
from inspect import stack
#---create a variable with filenames that can be loaded index---
vfd_img_files = ( "./images/0-fault-lockout.gif",
"./images/1-fault.gif",
"./images/2-start-pending.gif",
"./images/3-stop.gif",
"./images/4-dc-brake.gif",
"./images/5-run-at-0hz.gif",
"./images/6-run.gif",
"./images/7-accel.gif",
"./images/8-decel.gif",
"./images/9-current-limit.gif",
"./images/10-decel-override.gif",
"./images/11-lower-transistors-switchin-on.gif")
# 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):
self.builder = builder
self.halcomp = halcomp
self.jog_increment = self.builder.get_object('jog_increment')
self.g54inch = self.builder.get_object('g54inch_jog')
self.g54tenths = self.builder.get_object('g54tenth_jog')
self.g54hundredths = self.builder.get_object('g54hundedth_jog')
self.g54thousandths = self.builder.get_object('g54thousandth_jog')
self.zw_label = self.builder.get_object('zw_label')
self.example_trigger = hal_glib.GPin(halcomp.newpin('label-trigger', hal.HAL_BIT, hal.HAL_IN))
self.example_trigger.connect('value-changed', self.on_label_trigger_value_changed)
self.vac_on = self.builder.get_object('vac_on')
self.vac_off = self.builder.get_object('vac_off')
self.on_vacuum_state = hal_glib.GPin(halcomp.newpin('on-vacuum-state', hal.HAL_BIT, hal.HAL_IN))
self.off_vacuum_state = hal_glib.GPin(halcomp.newpin('off-vacuum-state', hal.HAL_BIT, hal.HAL_IN))
self.on_vacuum_state.connect('value-changed', self.on_vacuum_state_value_changed)
self.off_vacuum_state.connect('value-changed', self.off_vacuum_state_value_changed)
#Create hal pins for VFD status images
vfd_msg1 = hal_glib.GPin(halcomp.newpin('msg-vfd1', hal.HAL_U32, hal.HAL_IN))
vfd_msg1.connect('value-changed', self._on_vfd_msg1_change)
vfd_msg2 = hal_glib.GPin(halcomp.newpin('msg-vfd2', hal.HAL_U32, hal.HAL_IN))
vfd_msg2.connect('value-changed', self._on_vfd_msg2_change)
vfd_msg3 = hal_glib.GPin(halcomp.newpin('msg-vfd3', hal.HAL_U32, hal.HAL_IN))
vfd_msg3.connect('value-changed', self._on_vfd_msg3_change)
vfd_msg4 = hal_glib.GPin(halcomp.newpin('msg-vfd4', hal.HAL_U32, hal.HAL_IN))
vfd_msg4.connect('value-changed', self._on_vfd_msg4_change)
vfd_msg5 = hal_glib.GPin(halcomp.newpin('msg-vfd5', hal.HAL_U32, hal.HAL_IN))
vfd_msg5.connect('value-changed', self._on_vfd_msg5_change)
vfd_msg6 = hal_glib.GPin(halcomp.newpin('msg-vfd6', hal.HAL_U32, hal.HAL_IN))
vfd_msg6.connect('value-changed', self._on_vfd_msg6_change)
vfd_msg7 = hal_glib.GPin(halcomp.newpin('msg-vfd7', hal.HAL_U32, hal.HAL_IN))
vfd_msg7.connect('value-changed', self._on_vfd_msg7_change)
vfd_msg8 = hal_glib.GPin(halcomp.newpin('msg-vfd8', hal.HAL_U32, hal.HAL_IN))
vfd_msg8.connect('value-changed', self._on_vfd_msg8_change)
#Use the hal pin value to choose the image displayed
def _on_vfd_msg1_change(self,hal_pin,data=None):
self.builder.get_object('img-vfd1').set_from_file( vfd_img_files[ self.halcomp['msg-vfd1'] ] )
def _on_vfd_msg2_change(self,hal_pin,data=None):
self.builder.get_object('img-vfd2').set_from_file( vfd_img_files[ self.halcomp['msg-vfd2'] ] )
def _on_vfd_msg3_change(self,hal_pin,data=None):
self.builder.get_object('img-vfd3').set_from_file( vfd_img_files[ self.halcomp['msg-vfd3'] ] )
def _on_vfd_msg4_change(self,hal_pin,data=None):
self.builder.get_object('img-vfd4').set_from_file( vfd_img_files[ self.halcomp['msg-vfd4'] ] )
def _on_vfd_msg5_change(self,hal_pin,data=None):
self.builder.get_object('img-vfd5').set_from_file( vfd_img_files[ self.halcomp['msg-vfd5'] ] )
def _on_vfd_msg6_change(self,hal_pin,data=None):
self.builder.get_object('img-vfd6').set_from_file( vfd_img_files[ self.halcomp['msg-vfd6'] ] )
def _on_vfd_msg7_change(self,hal_pin,data=None):
self.builder.get_object('img-vfd7').set_from_file( vfd_img_files[ self.halcomp['msg-vfd7'] ] )
def _on_vfd_msg8_change(self,hal_pin,data=None):
self.builder.get_object('img-vfd8').set_from_file( vfd_img_files[ self.halcomp['msg-vfd8'] ] )
def on_label_trigger_value_changed(self, pin):
state = pin.get()
if state:
self.zw_label.set_attributes(self.attr_true)
self.zw_label.set_text('ZZ')
else:
self.zw_label.set_attributes(self.attr_false)
self.zw_label.set_text('ZW')
def activ_inc(self, widget):
if widget.get_active():
if widget == self.g54inch: self.jog_increment.set_text('1.000')
elif widget == self.g54tenths: self.jog_increment.set_text('0.100')
elif widget == self.g54hundredths: self.jog_increment.set_text('0.010')
elif widget == self.g54thousandths: self.jog_increment.set_text('0.001')
def on_vacuum_state_value_changed(self, pin):
state = pin.get()
if state:
self.vac_on.set_active(True)
def off_vacuum_state_value_changed(self, pin):
state = pin.get()
if state:
self.vac_off.set_active(True)
# This is boiler code, required for gladevcp
def get_handlers(halcomp,builder,useropts):
return [HandlerClass(halcomp,builder,useropts)]
(Now to work on all of the other error messages and warnings that pop up in the terminal, but this is a good start for me.)
Please Log in to join the conversation.
Time to create page: 0.046 seconds
