From octave-graphics-request at bevo dot che dot wisc dot edu Mon May 22 10:38:35 2000 Subject: Re: some action From: Rafael Laboissiere To: octave-graphics at bevo dot che dot wisc dot edu Date: Mon, 22 May 2000 17:35:16 +0200 --W5WqUoFLvi1M7tJE Content-Type: text/plain; charset=us-ascii [ This is a belated reaction to jwe's msg "Some action" of March 12, 1999. ] After some weeks of struggle with the Octave internals, the GTK library and the Pthreads API, I finally succeeded to implement John's proposal of a year ago. (For those not following this mailing list since last year, and for those lazy to look at the archives, I am including below a copy of John's msg.) You will find attached to this msg a file octave-gui.tar.gz containing my very first attempt to implement a GUI in Octave using the GTK+ toolkit. It is very crude, it is not 100% robust, implements just a simple button object, will not serve you coffee. Nevertheless, it works and the code has lots of comments. This is meant to be just a starting point. 1) BUILDING You will need : Octave 2.1.30, GTK+ 1.2, and a implementation of the POSIX threads (PThreads). Pthreads are implemented in the GNU libc 2.1. My code works fine in a Debian GNU/Linux box. To build it, first change the value of the variabvle MKOCTFILE in Makefile to the path of mkoctfile-2.1.30 in your system. Then type make. I had to specify -I/usr/include/g++-3 to the mkoctfile command, I do not know why this is necessary. 1) USAGE Launch octave-2.1.30. You can create buttons with the command: but = gui_button ("Click me!", "cb") A button will be created in its own window with a label "Click me!". Clicking in the button will call the function "cb", defined as, e.g.: function cb disp ("Hello!"); fflush (stdout); endfunction The variable but is of type "gui_button", which is a derived type from struct. Indeed, it is printed as but = { label = Click me! callback = cb } The future goal is to manipulate the various button object properties (this is also jwe's proposal, see <14055 dot 32440 dot 318368 dot 431876 at tillamook-sharp dot bogus dot domain>), like: but.label = "quit"; but.callback = "exit"; redisplay (but) 3) IMPLEMENTATION DETAILS The tricky part of the code was the generation of a separate thread for the GTK main event loop. Actually, generating the thread is quite easy, but problems arose when GTK objects were created in the main thread (that running the Octave interpreter). It was necessary to create a dummy widget in the GTK thread and send a event to it through the USRSIG1 signal. It is sort of tricky, but it seems to work. Suggestions for improvement are welcome. 4) WHAT IS NEXT? Well, this test code can evolve towards a real implementation of a GUI for Octave. However, I am unable to undertake alone this task for two reasons: i) The Octave API for the GUI objects should be well defined. I think that JWE should give the word here. This API will eventually specify a particular object hierarchy, and how users will interact with the GUI objects. Also very important, the integration with a plotting library is necessary here. I am working towards integration of Gtk with PLplot (www.plplot.org, development just restarted recently). ii) The internals of my code are quite ugly. I am sure it can be written in a more elegant way. I am willing to work in a totally new design, if somebody comes out with a suitable one. We could also consider rewriting with one of the C++ bindings for GTK, but I am quite confortable doing it with the regular C API. As usual, comments are welcome. -- Rafael Laboissiere ----- Forwarded message from "John W. Eaton" ----- Date: Fri, 12 Mar 1999 03:05:43 -0600 Message-Id: <199903120905 dot DAA21998 at tillamook-sharp dot bogus dot domain> From: "John W. Eaton" To: octave-graphics at bevo dot che dot wisc dot edu Subject: some action X-Mailing-List: OK, here is an idea for some action. While we are deciding what heavy-duty toolkit(s) to use, I think it would be useful to come up with some simple proof-of-concept code based on a brain-dead simple toolkit. So, over the next few days, I'm going to try to work on integrating a few GUI objects into the 2.1.x sources. I'll be using libsx, which is a really simple toolkit based on the Athena widgets. I'm pretty sure there is no fancy web page for it. There is no team of developers. It's not pretty and it doesn't do everything under the sun, but it is small, easy to use, and stable. You can find it at ftp://ftp.x.org/contrib/libraries/libsx.tar.Z. Here's what I'm going to try to do: * Define a new octave_value data type for gui objects. * Define a few functions like gui_button, gui_draw_area, gui_scrollbar, etc. They will look something like this: DEFUN (gui_button, args, , "gui_button (label, callback)") { octave_value retval; if (args.length () == 2) { string label = args(0).string_value (); if (! error_state) { string callback = args(1).string_value (); if (! error_state) retval = octave_gui_button (label, octave_gui_button_callback, fcn_name); else error ("gui_button: expecting string as second arg"); } else error ("gui_button: expecting string as first arg"); } else print_usage ("gui_button"); return retval; } * The octave_gui_button_callback function will take the name of the Octave function to call. It will look something like this void octave_gui_button_callback (const string& fcn) { octave_value_list args; feval (fcn, args, 0); } * The constructor for the octave_gui_button object will take care of actually creating the button object using the appropriate toolkit code. For my purposes (trying out some ideas) libsx should be sufficient. Once this sample code is working well enough to put a few simple objects on the screen, I'll make it available with a new release of the development sources and people can take a look at it and see how their favorite toolkit will (or will not) fit in to the scheme. Then we can work out more of the details of how to define additional object types and start to integrate a real-world toolkit or two. Comments? jwe ----- End forwarded message ----- --W5WqUoFLvi1M7tJE Content-Type: application/octet-stream Content-Disposition: attachment; filename="octave-gui.tar.gz" Content-Transfer-Encoding: base64 H4sIAJ5RKTkAA+1a+3PaSBLeX62/opdLZcEBA37WmXOqiI0TLgRcNk4qtXelEtIAOguJk4RZ b873t9/XM6MHDye7V5vsXp26kiDm0d3T/fVjRAI7tu5FbbJw6999LWo0DhsnR0f43D84PDxR n/sH+Ezpu8ZJs7m/f9Q45udm86R59B0dfTWNcrSIYisk+i60xpbwnl7n2vNvoc63piDz/zvr ToxdT/zmMhrNRuP48PBJ/x8dNbX/D46OG5hvHhwcw/+N31yTLfR/7v93bwfnw8tur0NnVHes 2KorQ9QXUVgfuX59dgeIMCwM4/Xwba/76gYrn5WjqfA8msR3NTvwx+6EajXPHUUYmYbCcuhf 9DeDVmguQo9qgn549sw8+8vLVlSvhc6Db81cu15vzUPXj3+osIzLXvv1k0LssWdNUjEVwwBy zdEijgP/lLLnPds2dp6V09NVqBbkp3EmKLhDVOvKk7q+7S0cUZ+8eFE7gOREjYp65mNXVtmT YdiesPxTYyecUW1Mu5Ip/qVdOwhhrr2rN4P+x1OSy4zf29FPUC7+V473W8r4fPw3jw+aWf4/ bB5j/eFh47iI/29B9V3DOA/mD6E7mcZUPq/QPnxC19Ia1LNGgRtFrmA8D6duRJwJCJ9zK4wp GNNA4mfPMNQDT41DISgKxvHSCkWLHoIF2ZZPoXDcKA5dQAzLYrJ8px6ENAscd/yAAWPhOyKk eCooFuEsYu785XX/ll4LX4SWR1eLkefa1HNt4UeCLOjBI8gTDo0eeLlxydJvtHS6DMDVit3A b5FwMR/SvQgjfKf9KkF82YpZw5CCOa+qQK0Hw7PibOHK2bIjOOT6Ur9pMIfGU/DBoZYuEtZI 0CIS44VX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