Create an Event Loop in the handler file???

More
7 years 9 months ago #123242 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?

Please Log in to join the conversation.

More
7 years 9 months ago #123243 by cmorley
in gladevcp typically a GObject timer is used
Code:
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 to join the conversation.

More
7 years 9 months ago #123244 by cmorley
drowidget.py is probably the simplest widget as an example.
/iib/python/gladevcp/drowidget.py

Chris M

Please Log in to join the conversation.

More
7 years 9 months ago #123363 by mmt
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)]

Please Log in to join the conversation.

More
7 years 9 months ago #123364 by cmorley
Code:
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 to join the conversation.

More
7 years 9 months ago #123366 by Grotius
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)]

Please Log in to join the conversation.

More
7 years 9 months ago #123368 by cmorley

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.

More
7 years 9 months ago #123371 by Grotius
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.

Please Log in to join the conversation.

More
7 years 9 months ago #123375 by cmorley
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

Please Log in to join the conversation.

More
7 years 9 months ago #123378 by mmt
I got it working from the example drowidget.py

Thank you gentleman

Please Log in to join the conversation.

Time to create page: 0.109 seconds
Powered by Kunena Forum