- Posts: 102
- Thank you received: 0
Create an Event Loop in the handler file???
I have successfully done it with Glade but it does not work with GladeVCP.
Does anyone know of, or have an example?
Please Log in to join the conversation.
In master i hope to add code soon to connect a 'periodic_update' message from GSTAT, which would be more efficient.
Chris M
Please Log in to join the conversation.
/iib/python/gladevcp/drowidget.py
Chris M
Please Log in to join the conversation.
Also I could not find the example file you posted.
Here is my code, what am I doing wrong?
import hal
import glib
import time
import urllib
import time
import gobject
class HandlerClass:
def __init__(self, halcomp,builder,useropts):
self.halcomp = halcomp
self.builder = builder
def open_loop(self):
current_in_str = str("OLC")
self.currentin = self.builder.get_object("currentin")
self.currentin.set_text(current_in_str)
current_gain_str = str("---")
self.currentgain = self.builder.get_object("currentgain")
self.currentgain.set_text(current_gain_str)
current_out_get = ("http://192.168.1.5:9080/HOSTLINK/RVIA")
current_out_open = urllib.urlopen(current_out_get)
current_out_read = current_out_open.read()
current_out_hex = current_out_read[-5:-1]
current_out_int = int(current_out_hex, 16)
current_out_str = str(current_out_int)
self.currentout = self.builder.get_object("currentout")
self.currentout.set_text(current_out_str)
return True
def on_open_loop_clicked(self, button):
gobject.timeout_add(10, self.open_loop)
def get_handlers(halcomp,builder,useropts):
return [HandlerClass(halcomp,builder,useropts)]
Please Log in to join the conversation.
Something like this would be more like it. ( not tested and of course the indets are wrong.
here is a reference to drowidget:
github.com/LinuxCNC/linuxcnc/blob/2.7/li...ladevcp/drowidget.py
hope that helps
Chris M
Please Log in to join the conversation.
import hal
import glib
import time
import urllib
import time
import gobject
class HandlerClass:
def __init__(self, halcomp,builder,useropts):
self.halcomp = halcomp
self.builder = builder
def open_loop(self):
current_in_str = str("OLC")
self.currentin = self.builder.get_object("currentin")
self.currentin.set_text(current_in_str)
current_gain_str = str("---")
self.currentgain = self.builder.get_object("currentgain")
self.currentgain.set_text(current_gain_str)
current_out_get = ("http://192.168.1.5:9080/HOSTLINK/RVIA")
current_out_open = urllib.urlopen(current_out_get)
current_out_read = current_out_open.read()
current_out_hex = current_out_read[-5:-1]
current_out_int = int(current_out_hex, 16)
current_out_str = str(current_out_int)
self.currentout = self.builder.get_object("currentout")
self.currentout.set_text(current_out_str)
return True
#at init section :
gobject.timeout_add(10, self.open_loop)
#at program section :
def periodic(self):
self.s.poll()
print " yo men, this text is printed overy 100 times a second "
return True
#button click example :
def on_open_loop_clicked(self, button):
print " i am happy now, this brings me luck "
#self.widgets. your label here .set_text("this is the power of linux :" + current_gain_str)
#or
#self. your label here .set_text("this is also the power of linux :" + current_gain_str)
#button pressed example :
#def on_open_loop_pressed(self, button):
# print " i am happy now, this brings me luck "
#button released example :
#def on_open_loop_released(self, button):
# print " a have released the button "
def get_handlers(halcomp,builder,useropts):
return [HandlerClass(halcomp,builder,useropts)]
Please Log in to join the conversation.
Grotius wrote: Try this :
import hal
import glib
import time
import urllib
import time
import gobject
class HandlerClass:
def __init__(self, halcomp,builder,useropts):
self.halcomp = halcomp
self.builder = builder
def open_loop(self):
current_in_str = str("OLC")
self.currentin = self.builder.get_object("currentin")
self.currentin.set_text(current_in_str)
current_gain_str = str("---")
self.currentgain = self.builder.get_object("currentgain")
self.currentgain.set_text(current_gain_str)
current_out_get = ("http://192.168.1.5:9080/HOSTLINK/RVIA")
current_out_open = urllib.urlopen(current_out_get)
current_out_read = current_out_open.read()
current_out_hex = current_out_read[-5:-1]
current_out_int = int(current_out_hex, 16)
current_out_str = str(current_out_int)
self.currentout = self.builder.get_object("currentout")
self.currentout.set_text(current_out_str)
return True
#at init section :
gobject.timeout_add(10, self.open_loop)
#at program section :
def periodic(self):
self.s.poll()
print " yo men, this text is printed overy 100 times a second "
return True
#button click example :
def on_open_loop_clicked(self, button):
print " i am happy now, this brings me luck "
#self.widgets. your label here .set_text("this is the power of linux :" + current_gain_str)
#or
#self. your label here .set_text("this is also the power of linux :" + current_gain_str)
#button pressed example :
#def on_open_loop_pressed(self, button):
# print " i am happy now, this brings me luck "
#button released example :
#def on_open_loop_released(self, button):
# print " a have released the button "
def get_handlers(halcomp,builder,useropts):
return [HandlerClass(halcomp,builder,useropts)]
This maybe an example of a Gscreen or a modified Gmoccapy handler file.
i say this as that would be the only way the function 'periodic' would be called.
I can't see how this could work with gladevcp without more code.
I think it would need more comments to help understand what your changes do.
I also assumed (maybe wrong) that MMT is using 2.7 ?
Chris M
Please Log in to join the conversation.
I assumed that his code was tested for running. Did not look if it would be functional stand alone...
So i changed the periodic section to a more working environment, so he could display a label text.
For him there is a minimal basic working config posted on the forum, where he could start with.
The minimal linuxcnc custom gui config file to test with :
forum.linuxcnc.org/media/kunena/attachme...ationtemplate.tar.gz
He can change names. It's a very short python code i did have a look now. A very compact code to test with.
Please Log in to join the conversation.
I think we are talking two different things.
As I understand it MMT is looking for a GladeVCP addon panel example.
You seem to be showing a costum screen example.
Chris M
Please Log in to join the conversation.
