Glade Custom Widgets

From LSDevLinux
Revision as of 23:03, 23 November 2010 by Spammer (talk | contribs)

Jump to: navigation, search

Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly

<p>Glade and GTK# are a powerful combination. One that we are using for our Mono re-implementation of WorldPad. It's quite possible to build a very functional application using just the standard widgets provided by GTK, but sometimes specific functionality is needed which is not found in the regular set of widgets.</p> <p>In this instance, a "custom widget" can be inserted into a Glade interface. This is easy to do, but filling in the custom widget with something useful is a bit more tricky.</p> <p>How do we implement the custom widget?</p> <p>In our case, we needed a custom colour picking widget. (Note that GTK does have a colour selection button, but we wanted something simpler, to more closely follow WorldPad). All that is needed is to stick a custom widget from the "GTK+ Additional" set into your window or dialog. You can then set a few generic string and integer properties that can be used when the widget is instantiated.</p> <p>If you have custom controls in your glade file, an <code>XMLCustomWidgetHandler</code> should be registered and will be called when you run load the Glade file. This function accepts a few parameters, most usefully the name of the widget and the properties that you may have defined in Glade.</p> <p>To register the handler, create a method (we called ours <code>on_custom_widget_found()</code>*) and set the static property <code>Glade.XML.CustomWidgetHandler</code> to a new <code>XMLCustomWidgetHandler</code> constructed with the above method as a parameter</p> <p>In our program, we simply took the name of the widget and used it to decide which widget to create and set up**. The widget is then returned by the function, et voila! Any widget you can construct using GTK# can appear in your Glade application.</p> <p>*<code>Gtk.Widget on_custom_widget_found(XML xml, string func_name, string name, string string1, string string2, int int1, int int2)</code></p> <p>**Each widget was constructed, had an event attached, and was displayed using <code>Show()</code>.</p>