[Home]GladeVcpSetup

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

Showing revision 52
Difference (from revision 52 to revision 52) (minor diff, author diff)
(The revisions are identical or unavailable.)

This page is deprecated

please refer to updated documentation in http://www.linuxcnc.org/docs/2.5/html/gui/gladevcp.html

Setting up GladeVCP

GladeVCP is an EMC2 component which adds the ability to add a virtual control panel to EMC user interfaces like Axis or Touchy. It is similar to PyVCP; whereas PyVCP panels are created by editing an XML file manually, GladeVCP uses the glade WYSIWYG user interface editor. Therefore, it's faster and easier to create visually pleasing panels with GladeVCP?.

Status

Gladevcp is not in the 2.4 series and will be starting with 2.5. All main features have been merged into master as of Dec 20,2010 and this page reflects the current status in master. Recent fixes and enhancements are likely to show up in 'master' first.
For the examples below I assume master is installed as ~/emc2-dev/ .

Installation prerequisites

If you install from a package, all dependencies should be properly resolved automatically.

However, when installing from source, several packages need to be installed manually. The build would complete, but running gladevcp programs or editing glade files might fail otherwise. To pull in these packages, execute the following:

 $ apt-get install python-gnome2 python-glade2 python-numpy python-numpy python-imaging  python-xlib python-gtkglext1 python-configobj gtksourceview2 

Download, build and install emc2 master as per instructions at Installing EMC2 on Ubuntu 10.04 from source.
You have either to fetch current development version using git or install packages from [buildbot]

To create new UI components, you will need at least version 3.6.7 of glade (stock on Ubuntu 10.04):

 sudo apt-get install glade

To determine wether your gladevcp is up to date, run it as 'gladevcp -h'. if the usage message says it supports a '-H halfile' option, you're good to go.

On older systems, Gladevcp files that have been made with Glade 3.6.7 can be displayed on systems with older versions of Glade (eg Ubuntu 8.04)
But you can't edit and won't see the HAL objects using Glade.

If anyone wishes to donate more or needs help building new HAL widgets lets us know on the EMC Maillist.

Trying out an existing GladeVCP UI component

There's an example UI component in the source tree in emc2-dev/lib/python/gladevcp (currently not in the installed tree). To give it a try:
 $ cd emc2-dev/lib/python/gladevcp
 $ gladevcp  gladevcp-test.ui 
If you have no EMC user interface like Axis or Touchy running, you might have to start the realtime extension beforehand so gladevcp may create a hal component :
 $ sudo /etc/init.d/realtime restart
This might also be needed if your gladevcp application terminated abnormally and left an active HAL component 'lying around' in which case you'll get a 'HAL comonent already exists' error on the next run. This command should not be needed when running in simulator mode.

A new window with several leds and buttons should come up like so:

upload:gladevcp-test.png

Note also that a HAL component gladevcp-test with several pins has been created.

Creating your first GladeVCP UI component

Either modify an existing UI component, or start a new one with running glade. In the left tab, expand the 'HAL Python' components. Create a Window as top level window from the 'Toplevels' section (first icon), which by default will be named window1. Leave that name as is - gladevcp assumes the top level window has this name. Add a HAL_Box or a HAL_Table from 'HAL Python' to the frame, and pick and place some elements like LED, button etc in its box.

This will look like so:

upload:glade-myui.png

Select File->Save as, give it a name like 'myui.ui' and make sure it's saved as 'GtkBuilder' file (radio button left bottom corner in Save dialog). The convention for GtkBuilder file extension is '.ui'. You can now run it with:

 $ gladevcp myui.ui

Integrating the example UI into Axis

While you could run your UI as a separate top level window side-by-side with Axis, having it within the Axis frame as a tab side-by-side with the Preview and DRO tabs, or in the right side of the Axis window like PyVCP is more elegant. There are now both options how to place a gladevcp window in Axis, while formerly only embedding in a tab was possible.

Embedding in a tab next to Preview/DRO

Since gladevcp comes with a HAL component, the execution of HAL commands referring to these components must be done after that component is ready. There are two options to do this:

The recommended way of starting a gladevcp embedded tab is as follows: Edit your .ini file and add two variables to the DISPLAY section of ini file:

 EMBED_TAB_NAME = GladeVCP
 EMBED_TAB_COMMAND=halcmd loadusr -Wn gladevcp-test gladevcp -c gladevcp-test  -x {XID} gladevcp-test.glade

Note the 'halcmd loadusr' way of starting the tab command - this assures that POSTGUI_HALFILE will only be run after the HAL component (in this case gladevcp-test) is ready. In rare cases you might run a a command here which uses a tab but does not have an associated HAL component. Such a command can be started without 'halcmd loadusr', and this signifies to Axis it doesnt have to wait for a HAL component since there is none.

Try it out by running Axis - there should be a new tab called 'GladeVCP' near the DRO tab. Select that tab, you should see the example panel nicely fit within Axis like so:

upload:axis-gladevcp.png

(Note that my setup still runs a PyVCP panel on the right which is a bit of an overkill but I havent migrated yet).

Embedding in a separate frame like PyVCP

You can achieve this by simply specifying the following in the DISPLAY section:

GLADEVCP=myapp.ui

An application started through the GLADEVCP option is slighty different from an EMBED_TAB_COMMAND:

This means you can add arbitrary gladevcp options here, as long as they dont collide with the above command line, so it could also read:

GLADEVCP= -d -u myhandlerfile.py myapp.ui

Integrating into Touchy

Touchy also understands EMBED_TAB_NAME/EMBED_TAB_COMMAND variables from INI file so instructions for it are equal to Axis. Touchy currently does not have an equivalent to GLADEVCP in Axis.

upload:touchy-gladevcp-small.png

Axis: linking HAL pins in the example UI

To be useful, the pins in your UI need to be linked to the rest of your setup. Usually this is done by running one or several HAL files through the HALFILE and POSTGUI_HALFILE statements in the HAL section of your .ini file.

Provided you start you EMBED_TAB_COMMAND as outlined above, or use the GLADEVCP option, you can execute all HAL commands in POSTGUI_HALFILE.

For the above EMBED_TAB_NAME and GLADEVCP examples, add the HAL statements from lib/python/gladevcp/gladevcp-test.hal to your POSTGUI_HALFILE. Note that in the GLADEVCP case, the component will be forced to the name 'gladevcp' so you will have to rename the component part in ths HAL file from gladevcp-test to gladevcp .

Adding custom user callbacks in Python

This is just a very minimal example to convey the idea - for a detailed description on how to program a gladevcp application, see GladeVCPprogramming and HalWidgets .

gladevcp cannot only manipulate or display HAL pins, you can also write regular event handlers in Python. This could be used, among others, to execute MDI commands. Here's how you do it:

Write a Python module like so and save as e.g. handlers.py:

 nhits = 0

 def on_button_press(gtkobj,data=None):
    global nhits
    nhits += 1
    gtkobj.set_label("hits: %d" % nhits)

In glade, define a button or HAL button, select the 'Signals' tab, and in the GtkButton properties select the 'pressed' line. Enter 'on_button_press' there, and save the glade file.

Then add the option '-u handlers.py' to the gladevcp command line. If your event handlers are spread over several files, just add multiple '-u <pyfilename>' options.

Now, pressing the button should change its label since it's set in the callback function.

What the -u flag does is: all Python functions in this file are collected and setup as potential callback handlers for your Gtk widgets - they can be referenced from glade 'Signals' tabs. The callback handlers are called with the particular object instance as parameter, like the GtkButton instance above, so you can apply any GtkButton method from there.

Or do some more useful stuff, like calling an MDI command!.

Gladevcp commandline options

See also 'man gladevcp' . This is the usage message when you run 'gladevcp -h':

 Usage: gladevcp [options] myfile.ui

 Options:
  -h, --help   show this help message and exit
  -c NAME      Set component name to NAME. Default is basename of UI file
  -d           Enable debug output
  -g GEOMETRY  Set geometry WIDTHxHEIGHT?+XOFFSET+YOFFSET. Values are in pixel
               units, XOFFSET/YOFFSET is referenced from top left of screen
               use -g WIDTHxHEIGHT? for just setting size or -g
               +XOFFSET+YOFFSET for just position
  -H FILE      execute hal statements from FILE with halcmd after the
               component is set up and ready
  -m MAXIMUM   Force panel window to maximize
  -t THEME     Set gtk theme. Default is system theme
  -x XID       Reparent gladevcp into an existing window XID instead of
               creating a new top level window
  -u FILE      Use FILEs as additional user defined modules with handlers
  -U USEROPT   pass USEROPTs to Python modules

Troubleshooting

Status

This page is current per December 2010. Authors Michael Haberler and Pavel Shramov .


LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions | View current revision
Edited July 18, 2011 3:05 am by MichaelHaberler (diff)
Search:
Published under a Creative Commons License