From octave-graphics-request at bevo dot che dot wisc dot edu Mon Jun 24 18:14:40 2002 Subject: GTK and Octave From: Ben Sapp To: octave-graphics at bevo dot che dot wisc dot edu Date: Mon, 24 Jun 2002 17:12:32 -0600 Hello, I have written a class and some DLD functions to accompany the class that allow a person to bring up most GTK widgets from within Octave. I also have a callback implementation working. The real motivation for this email is to hopefully rekindle interest in providing a GUI API for Octave. Based on the work already done it would not be difficult to allow access to all of gtk from within octave. A large portion is already available through the widget_set routine and DLD functions could be used to provide access to any thing that cannot be manipulated that way. However, the general concensus has been that it would be better to provide a consistent API that many widget sets could be plugged into. I agree with the concensus. I am encouraged with how little software was needed to provide access to a large portion of GTK. I have looked at QT and believe that a similar thing could be accomplished with QT with about the same amount of software. I have not familiarized myself with other toolkits but if they are written in an object oriented fashion the same should be possible. So here are a my thoughts on how to implement the API. 1. We should provide a semi-consistent API at the C++ class level. We should NOT try to provide the full API of the whatever widget library we are implementing. Rather just a limited subset of things we actually need to know about, like callbacks. What do you think of this abstract class as a start of the C++ API? What else should be added or changed? class octave_base_widget : public octave_base_value { public: // Connect callback command to a signal virtual void signal_connect(std::string signal, std::string command) = 0; // initialize the widgets true -> success, false -> failure virtual static bool initialize_widgets(void) = 0; octave_base_widget(std::string widget_name): octave_base_value() {} }; 2. Most of the work should be done in a widget specific set of DLD functions or scripts.(gtk_button for gtk, qt_button for qt, wx_button for wxWindows, ...) For each widget set implemented there would be a widget_value member function that returned a pointer to the actual widget. Then, different DLD functions would be implemented for each widget set. These functions would then use the normal methods provided by the widget set to perform whatever function was requested. 3. The only part of the API that should be identical for the all widget sets should be at the octave script level. We should implement a set of scripts like gui_button which determines at run time which toolkit's are available and returns a widget from the chosen widget set. The implementation outlined is fairly simple to implement. Most of the work is not complicated but is time consuming. You can build the package if you have gtk+-2.0 or greater installed as well as GNU Octave development version. Find it at http://bsoctave.sourceforge.net/octave-widget.tar.gz . The commands: ./configure make should build all the .oct files. You must first run widget_start from the Octave command line to use any of the functions. Be sure to run widget_stop before performing a clear otherwise octave will crash. There are two .m files that illustrate how to use it.(hello_world and widget_hbox) Unlike GTK, it is limited to one callback per signal. Callbacks can be any octave command. They do not have to be functions. -- Ben Sapp Los Alamos National Laboratory email: Phone: (505)667-3277 Fax: (505)665-7920 URL: http://www.neutrino.lanl.gov/ --