Create an Event Loop in the handler file???
- mmt
- Offline
- Premium Member
Less
More
- Posts: 124
- Thank you received: 2
31 Dec 2018 21:15 #123242
by mmt
Create an Event Loop in the handler file??? was created by mmt
Basically I want to click a button that enters text in a label and have it loop to continuously update the text.
I have successfully done it with Glade but it does not work with GladeVCP.
Does anyone know of, or have an example?
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 or Create an account to join the conversation.
- cmorley
- Away
- Moderator
Less
More
- Posts: 7761
- Thank you received: 2046
31 Dec 2018 21:35 #123243
by cmorley
Replied by cmorley on topic Create an Event Loop in the handler file???
in gladevcp typically a GObject timer is used
In master i hope to add code soon to connect a 'periodic_update' message from GSTAT, which would be more efficient.
Chris M
import gobject
##### initialization code #####
# check linuxcnc status every half second
gobject.timeout_add(500, self.periodic_check)
def periodic_check(self):
#do something and return true to continue next event
return True
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 or Create an account to join the conversation.
- cmorley
- Away
- Moderator
Less
More
- Posts: 7761
- Thank you received: 2046
31 Dec 2018 21:38 #123244
by cmorley
Replied by cmorley on topic Create an Event Loop in the handler file???
drowidget.py is probably the simplest widget as an example.
/iib/python/gladevcp/drowidget.py
Chris M
/iib/python/gladevcp/drowidget.py
Chris M
Please Log in or Create an account to join the conversation.
- mmt
- Offline
- Premium Member
Less
More
- Posts: 124
- Thank you received: 2
02 Jan 2019 22:07 #123363
by mmt
Replied by mmt on topic Create an Event Loop in the handler file???
Thank you so much for your help, however I am not very good with python.
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)]
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 or Create an account to join the conversation.
- cmorley
- Away
- Moderator
Less
More
- Posts: 7761
- Thank you received: 2046
02 Jan 2019 22:13 #123364
by cmorley
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
Replied by cmorley on topic Create an Event Loop in the handler file???
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
gobject.timeout_add(10, self.open_loop)
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 get_handlers(halcomp,builder,useropts):
return [HandlerClass(halcomp,builder,useropts)]
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 or Create an account to join the conversation.
- Grotius
- Offline
- Platinum Member
Less
More
- Posts: 2232
- Thank you received: 1947
02 Jan 2019 22:19 - 02 Jan 2019 22:29 #123366
by Grotius
Replied by Grotius on topic Create an Event Loop in the handler file???
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)]
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)]
Last edit: 02 Jan 2019 22:29 by Grotius.
Please Log in or Create an account to join the conversation.
- cmorley
- Away
- Moderator
Less
More
- Posts: 7761
- Thank you received: 2046
02 Jan 2019 22:39 #123368
by cmorley
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
Replied by cmorley on topic Create an Event Loop in the handler file???
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 or Create an account to join the conversation.
- Grotius
- Offline
- Platinum Member
Less
More
- Posts: 2232
- Thank you received: 1947
02 Jan 2019 22:53 - 02 Jan 2019 22:57 #123371
by Grotius
Replied by Grotius on topic Create an Event Loop in the handler file???
Chris,
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.
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.
Last edit: 02 Jan 2019 22:57 by Grotius.
Please Log in or Create an account to join the conversation.
- cmorley
- Away
- Moderator
Less
More
- Posts: 7761
- Thank you received: 2046
02 Jan 2019 23:35 #123375
by cmorley
Replied by cmorley on topic Create an Event Loop in the handler file???
Grotius:
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
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 or Create an account to join the conversation.
- mmt
- Offline
- Premium Member
Less
More
- Posts: 124
- Thank you received: 2
03 Jan 2019 00:18 #123378
by mmt
Replied by mmt on topic Create an Event Loop in the handler file???
I got it working from the example drowidget.py
Thank you gentleman
Thank you gentleman
Please Log in or Create an account to join the conversation.
Moderators: HansU
Time to create page: 0.080 seconds