We will use a calculator widget that is already in linuxcnc (master)
I found this calculator widget on the net: http://sraji.wordpress.com/2009/09/08/calculator-using-python-and-glade/
I changed the keys a a bit for my use and switched to glade builder from libraryglade
here is the source code: upload:custom_calculator.zip
I apologize - this program uses leading tabs instead of spaces -that sucks but thats what the original program used.
If you run this with: python newcalculatorglade.py
It will display a calculator and pushing keys will change the display and pushing equals will do the math.
| This is the pre amble to set things up|
The first line lets you run this program from the gui by clicking on it
Importing sys and math allows system calls and math functions
importing pygtk actually seems not necessary - you could remove it.
importing gtk is necessary
If importing gtk fails an error message is printed and the program ends
| 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,