[Home]History of GladeVCP Custom Widgets

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

Revision 45 . . (edit) October 16, 2012 8:04 pm by Cmorley
Revision 44 . . (edit) July 2, 2012 12:29 pm by Cmorley
Revision 43 . . (edit) July 2, 2012 11:23 am by Cmorley
Revision 42 . . (edit) July 2, 2012 11:22 am by Cmorley
Revision 41 . . (edit) July 2, 2012 11:21 am by Cmorley
Revision 40 . . (edit) July 2, 2012 11:20 am by Cmorley
Revision 39 . . (edit) July 2, 2012 11:16 am by Cmorley
Revision 38 . . (edit) June 29, 2012 11:01 pm by Cmorley
Revision 37 . . (edit) June 28, 2012 11:28 pm by Cmorley
Revision 36 . . (edit) June 28, 2012 10:24 pm by Cmorley
Revision 35 . . (edit) June 28, 2012 10:24 pm by Cmorley
Revision 34 . . (edit) June 27, 2012 11:48 pm by Cmorley
Revision 33 . . (edit) June 27, 2012 11:46 pm by Cmorley
Revision 32 . . (edit) June 27, 2012 11:43 pm by Cmorley
Revision 31 . . (edit) June 27, 2012 11:39 pm by Cmorley
Revision 30 . . (edit) June 27, 2012 11:38 pm by Cmorley
Revision 29 . . (edit) June 27, 2012 11:32 pm by Cmorley
Revision 28 . . (edit) June 27, 2012 11:19 pm by Cmorley
Revision 27 . . (edit) June 27, 2012 11:14 pm by Cmorley
Revision 26 . . (edit) June 27, 2012 11:13 pm by Cmorley
Revision 25 . . (edit) June 27, 2012 10:48 pm by Cmorley
Revision 24 . . (edit) June 26, 2012 10:28 pm by Cmorley
Revision 23 . . (edit) June 26, 2012 10:16 pm by Cmorley
Revision 22 . . (edit) June 25, 2012 9:08 pm by Cmorley
Revision 21 . . (edit) June 25, 2012 8:59 pm by Cmorley
Revision 20 . . (edit) June 25, 2012 8:58 pm by Cmorley
Revision 19 . . (edit) June 25, 2012 8:51 pm by Cmorley
Revision 18 . . (edit) June 25, 2012 8:48 pm by Cmorley
Revision 17 . . June 25, 2012 8:45 pm by Cmorley [beginnings of a GTK custom widget tutorial]
Revision 16 . . (edit) June 25, 2012 8:42 pm by Cmorley
Revision 15 . . (edit) June 25, 2012 8:33 pm by Cmorley
Revision 14 . . (edit) June 25, 2012 8:24 pm by Cmorley
Revision 13 . . (edit) June 25, 2012 8:22 pm by Cmorley
Revision 12 . . (edit) June 25, 2012 8:08 pm by Cmorley
Revision 11 . . (edit) June 25, 2012 8:07 pm by Cmorley
Revision 10 . . (edit) June 25, 2012 7:13 pm by Cmorley
Revision 9 . . (edit) June 25, 2012 2:19 pm by Cmorley
Revision 8 . . (edit) June 25, 2012 2:19 pm by Cmorley
Revision 7 . . (edit) June 25, 2012 2:19 pm by Cmorley
Revision 6 . . (edit) June 25, 2012 2:08 pm by Cmorley
Revision 5 . . (edit) June 25, 2012 1:15 pm by Cmorley
Revision 4 . . (edit) June 25, 2012 1:15 pm by Cmorley
Revision 3 . . (edit) June 25, 2012 1:12 pm by Cmorley
Revision 2 . . (edit) June 25, 2012 1:05 pm by Cmorley
Revision 1 . . (edit) June 25, 2012 1:03 pm by Cmorley
  

Difference (from prior major revision) (minor diff)

Changed: 2c2
Note i am not a programmer by trade, more of a hacker, so what I so you works, but there may be better ways.

Note i am not a programmer by trade, more of a hacker, so what I show you works, but there may be better ways.


Changed: 27c27,28
|| Here we initialize the class
The class name is the generic name for our widget - Calculator
the eval_string is a variable used through out the program
gladefile is the path/name of the GLADE file we have produced for this widget. In this case it assumes that the glade file is in the path that the program was launched from which is probably not a good assumption.GtkBuilder? is the method that builds our widget from the glade file. Then we write a dictionary of the signals and corresponding function calls. The signals were picked in the GLADE editor. Using a dictionary is one way of connecting signals- another common one seen is letting GLADe autoconnect them. If that is done the function calls names are the same as the signalname,
|| upload:calculator_code2.png ||
|| Here we initialize the class
The class name is the generic name for our widget - Calculator
the eval_string is a variable used through out the program
gladefile is the path/name of the GLADE file we have produced for this widget. In this case it assumes that the glade file is in the path that the program was launched from which is probably not a good assumption.Gtk.builder is the method that builds our widget from the glade file. Then we write a dictionary of the signals and corresponding function calls. The signals were picked in the GLADE editor. Using a dictionary is one way of connecting signals- another common one seen is letting GLADE autoconnect them. If that is done the function calls names are the same as the signalnames,
Then we connect the signals. At the end we tell builder to find the window_calculator object in the GLADE file and show it || upload:calculator_code2.png ||
||We skipped a few lines here.
here is the code that the signals from the calculator buttons call
.At the bottom is the funny if __name__ = __main__ command. This lets the program know if it is launched stand alone to run the commands under it. other wise it will just call the initialization code. The cal = Calculator() is the instantiation command, it creates an object of class Calculator, then the next command calls gtk.main() so it listens for signals from the buttons
|| upload:calculator_code3.png ||

Added: 29a31
upload:calculator_widget.zip


Added: 32a35,51
In this version of the widget we added functions to change the display font, to get the current value, to set the display value and to get that preset-value later and set the display as editable or not.

The GLADE editor uses Gobject to interact with the widget while displaying it, so we must add that to our program if we want to be able to interact with the widget live.

1.1. looking at the new code



||We import pango so we can do font changes.The arrow points to code that finds the path to where the program actually is rather then where it was called from. This is used later to load the glade file, which is assumed in the same folder as this program. We also import Gobject needed for GLADE interaction.

Note that our calculator class is now subclassed from VBox. Meaning it is based on (and acts like) GTK's VBox widget. The first purple box shows the Gobject code for some attributes that we would like to be able to change in the glade editor

The second shows some new variables - note font and is_editable are the same as the Gobject attributes names -|| upload:widget_code1.png ||
||This arrow points to where we re-parent out widget to our Vbox
The rest of the code is the functions to get and set the attributes
|| upload:widget_code2.png ||
||These are the functions that Gobject calls when attributes changes
Note that when when are attributes are set we call the appropriate function to actually do the work.

In the main function (used for testing) note that you can set the attributes directly by calling their function directly.|| upload:widget_code3.png ||

1.2. How to add widget to GLADE editor




There are two files that we must edit (talking about RIP compiled version)

HAL_python.xml and halpythonplugin.py

1.2.1. hal_pythonplugin



upload:hal_pythonplugin_01.png

1.2.2. HAL_python.xml



upload:xml_03.png
upload:xml_01.png


|| Here we add some commands so that the number-of-items question is not asked and some other option are not shown
These come up because thw widget is based on the VBox widget. || upload:xml_02.png ||

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
Search:
Published under a Creative Commons License