GladeVCP - getting started with buttons
- tnl.lambert
- Offline
- Junior Member
Less
More
- Posts: 37
- Thank you received: 1
10 Dec 2014 01:10 #53850
by tnl.lambert
GladeVCP - getting started with buttons was created by tnl.lambert
So - very new to GladeVCP, but I'm trying to get a panel together that will do a few things:
- interact with the user via buttons and toggles
- generate a text file to log error messages
- send and receive signals over rs232
- generate G-code that will be run by AXIS
Unpacking this a bit:
I need to develop a panel that will communicate over rs232 to another machine during the operation of a g-code file. I need to log any errors that I get in the g-code, linuxcnc, or from the other machine. I assume that python callbacks will suffice to perform these tasks. That said: I'm stuck at a relatively early part of the setup.
I have modified my INI file to read like this:
My handlers.py file looks like this:
And my test1.ui file looks like this:
I assume that there are some basic things I'm missing.
- interact with the user via buttons and toggles
- generate a text file to log error messages
- send and receive signals over rs232
- generate G-code that will be run by AXIS
Unpacking this a bit:
I need to develop a panel that will communicate over rs232 to another machine during the operation of a g-code file. I need to log any errors that I get in the g-code, linuxcnc, or from the other machine. I assume that python callbacks will suffice to perform these tasks. That said: I'm stuck at a relatively early part of the setup.
I have modified my INI file to read like this:
GLADEVCP = -u /home/stan/Documents/pythontests/handlers.py /home/stan/Documents/gladetests/test1.ui (apparently calling the .ui file earlier in the line than the .py file generated an error)
My handlers.py file looks like this:
#!/usr/bin/env python
import hal
import gtk
import glib
#import serial
class HandlerClass:
def __init__(self):
filename = "/home/stan/Documents/gladetests/test1.ui"
builder = gtk.Builder()
builder.add_from_file(filename)
builder.connect_signals(self)
nhits = 0
def on_hal_button1_press(self,hal_button1,hal_label1,data=None):
global nhits
nhits += 1
hal_label1.set_label("hits: %d" % nhits)
print "on_led_pin_changed() - HAL pin value: %d",hal_led1.hal_pin1.get()
def get_handlers(halcomp,builder,useropts):
for cmd in useropts:
exec cmd in globals()
return [HandlerClass(halcomp,builder,useropts)]
And my test1.ui file looks like this:
<?xml version="1.0"?>
<interface>
<!-- interface-requires gladevcp 0.0 -->
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="window1">
<child>
<object class="HAL_Table" id="hal_table1">
<property name="visible">True</property>
<property name="n_rows">3</property>
<property name="n_columns">3</property>
<child>
<object class="HAL_LED" id="hal_led1">
<property name="visible">True</property>
<property name="led_blink_rate">500</property>
<signal name="hal_pin_changed" handler="on_hal_led1_hal_pin_changed"/>
</object>
</child>
<child>
<object class="HAL_LED" id="hal_led2">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<object class="HAL_LED" id="hal_led3">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
</packing>
</child>
<child>
<object class="HAL_Button" id="hal_button1">
<property name="label" translatable="yes">X Button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="pressed" handler="on_hal_button1_pressed"/>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="HAL_Button" id="hal_button2">
<property name="label" translatable="yes">Y Button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="HAL_Button" id="hal_button3">
<property name="label" translatable="yes">Z Button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="HAL_Label" id="hal_label1">
<property name="visible">True</property>
<property name="label" translatable="yes">label</property>
<signal name="hal_pin_changed" handler="on_hal_label1_hal_pin_changed"/>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<object class="HAL_Label" id="hal_label2">
<property name="visible">True</property>
<property name="label" translatable="yes">label</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<object class="HAL_Label" id="hal_label3">
<property name="visible">True</property>
<property name="label" translatable="yes">label</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkAction" id="action1"/>
</interface>
I assume that there are some basic things I'm missing.
Please Log in or Create an account to join the conversation.
10 Dec 2014 19:23 #53866
by andypugh
What isn't happening that you expected to happen?
Replied by andypugh on topic GladeVCP - getting started with buttons
That said: I'm stuck at a relatively early part of the setup.
What isn't happening that you expected to happen?
Please Log in or Create an account to join the conversation.
10 Dec 2014 19:26 #53867
by andypugh
hal_button1_press / hal_button1_pressed looks like one likely source of trouble.
Replied by andypugh on topic GladeVCP - getting started with buttons
def on_hal_button1_press(self,hal_button1,hal_label1,data=None): global nhits<object class="HAL_Button" id="hal_button1"> ... <signal name="pressed" handler="on_hal_button1_pressed"/>
I assume that there are some basic things I'm missing.
hal_button1_press / hal_button1_pressed looks like one likely source of trouble.
Please Log in or Create an account to join the conversation.
- tnl.lambert
- Offline
- Junior Member
Less
More
- Posts: 37
- Thank you received: 1
12 Dec 2014 04:43 #53936
by tnl.lambert
Replied by tnl.lambert on topic GladeVCP - getting started with buttons
Good catch on the handler name, but it apparently wasn't the source of the problem. Running my system from the terminal gives:
I think that there might be an issue with how I've set up the whole thing. What libraries do I need to import? Or is there a problem with how I've defined my handlers?
(gladevcp:1876): libglade-WARNING **: did not finish in PARSER_FINISH state
**** GLADE VCP INFO: Not a libglade project, trying to load as a GTK builder project
gladevcp: trouble looking for handlers in 'handlers': __init__() takes exactly 1 argument (4 given)
Traceback (most recent call last):
File "/usr/bin/gladevcp", line 122, in load_handlers
objlist = h(halcomp,builder,useropts)
File "/home/stan/Documents/pythontests/handlers.py", line 58, in get_handlers
return [HandlerClass(halcomp,builder,useropts)]
TypeError: __init__() takes exactly 1 argument (4 given)
/usr/bin/gladevcp:211: RuntimeWarning: missing handler 'on_hal_label1_hal_pin_changed'
builder.connect_signals(handlers)
/usr/bin/gladevcp:211: RuntimeWarning: missing handler 'on_hal_button1_pressed'
builder.connect_signals(handlers)
/usr/bin/gladevcp:211: RuntimeWarning: missing handler 'on_hal_led1_hal_pin_changed'
builder.connect_signals(handlers)
Xlib.protocol.request.QueryExtension
Xlib.protocol.request.QueryExtension
I think that there might be an issue with how I've set up the whole thing. What libraries do I need to import? Or is there a problem with how I've defined my handlers?
Please Log in or Create an account to join the conversation.
12 Dec 2014 05:00 #53937
by andypugh
So, your __init__(self) is only expecting one argument, but something is giving it 4.
If you look at the examples, they use :
def __init__(self, halcomp,builder,useropts):
(ie, variables to accept 4 arguments)
Replied by andypugh on topic GladeVCP - getting started with buttons
gladevcp: trouble looking for handlers in 'handlers': __init__() takes exactly 1 argument (4 given)
So, your __init__(self) is only expecting one argument, but something is giving it 4.
If you look at the examples, they use :
def __init__(self, halcomp,builder,useropts):
(ie, variables to accept 4 arguments)
Please Log in or Create an account to join the conversation.
- tnl.lambert
- Offline
- Junior Member
Less
More
- Posts: 37
- Thank you received: 1
12 Dec 2014 06:05 #53940
by tnl.lambert
Replied by tnl.lambert on topic GladeVCP - getting started with buttons
Okay, I've gotten rid of that problem, but I still don't really have a handle on the reasoning. I understand that mismatched calls will result in errors, but I don't know what I'm passing in, or why. I also have no idea what the realm of possibilities are for gladeVCP. Is there a good manual for it? I've read the stuff I've found, but none of it has covered actions that affect other gladeVCP objects, or actions that are persistent. Can I run g-code from python through gladeVCP for instance?
Please Log in or Create an account to join the conversation.
12 Dec 2014 07:36 #53944
by andypugh
__init__() is called by the setup code that does the GladeVCP magic in LinuxCNC. You just have to know what parameters it takes, and the page you have probably seen shows that:
www.linuxcnc.org/docs/html/gui/gladevcp....GladeVCP_Programming
The LinuxCNC-specific widgets are described on that page too. For the other controls (non-HAL buttons etc) you need to look at the GTK docs to see what is passed in to your event handler.
developer.gnome.org/pygtk/stable/
www.linuxcnc.org/docs/html/common/python-interface.html
Replied by andypugh on topic GladeVCP - getting started with buttons
I understand that mismatched calls will result in errors, but I don't know what I'm passing in, or why.
__init__() is called by the setup code that does the GladeVCP magic in LinuxCNC. You just have to know what parameters it takes, and the page you have probably seen shows that:
www.linuxcnc.org/docs/html/gui/gladevcp....GladeVCP_Programming
The LinuxCNC-specific widgets are described on that page too. For the other controls (non-HAL buttons etc) you need to look at the GTK docs to see what is passed in to your event handler.
developer.gnome.org/pygtk/stable/
Yes, the easiest way is the MDI command of the LinuxCNC Python interface:Can I run g-code from python through gladeVCP for instance?
www.linuxcnc.org/docs/html/common/python-interface.html
The following user(s) said Thank You: tnl.lambert
Please Log in or Create an account to join the conversation.
Moderators: HansU
Time to create page: 0.437 seconds