Hi, I am just starting to learn how to use the glade-sharp, but I have been playing for some time with python-gtk and I am missing some of the functionality from there. More specifically, I try to add some custom widgets from glade. In python, it is enough to create a method with the same name as that specified in glade to create the widget. The python binding, when autoconnecting all the stuff, also dispatches the calls to the correct methods for creating the custom controls, if the correct method is detected.
For example, let's say I add a customTree in glade, to be built by the
createCustomTree method. When the python autoconnects, it searches for a
method named createCustomTree and calls it to produce the customTree widget.
>From what I have seen, with glade-sharp the only solution is to use
SetCustomHandler. However, this method needs some boilerplate that
should go in the binding, in my opinion. For example, now I do this in
my custom handler:
//////////////////////////////////////////////////
public Widget createCustomTree(string name,
string s1, string s2, int i1, int i2)
{
Button btn = new Button(name);
btn.Show();
return btn;
}
public Widget custom(XML xml, string func_name,
string name, string s1, string s2,
int i1, int i2)
{
Widget w;
switch(func_name)
{
case "createCustomTree":
w = createCustomTree(name, s1, s2, i1, i2);
break;
default:
// this should throw an exception
w = new Button("Custom");
break;
}
w.Show();
return w;
}
//////////////////////////////////////////////////
The problem is this handler has hardcoded the methods used to create the
custom widgets. It would be great if the binding would provide a default
that checks the func_name and, using introspection, dispatches to the
correct method. Also, if the widget is also specified with:
[Widget] CustomTree customTree;
the custom should also store the reference of the custom widget in that
variable.
Is this already done and I simply missed it? Can it be done in the binding?
Also, how do I get the properties specified in the glade for the custom
widget (like it's minimum width)?
I have added a simple cs and glade file that illustrates the above state
of affairs...
TIA,
--
Ionutz Borcoman
http://borco.net/
http://developer.berlios.de/users/borco/
using System;
using Gtk;
using Glade;
namespace DeweyCatalog
{
class GuiApp
{
static void Main()
{
new GuiApp();
}
GuiApp()
{
Application.Init();
Glade.XML.SetCustomHandler(new Glade.XMLCustomWidgetHandler(custom));
Glade.XML gxml = new Glade.XML("DeweyGui.glade", "MainWindow", null);
gxml.Autoconnect(this);
Application.Run();
}
void OnMainWindowDeleteEvent(object o, DeleteEventArgs args)
{
Application.Quit();
args.RetVal = true;
}
public Widget createCustomTree(string name, string s1, string s2, int i1, int i2)
{
Console.WriteLine("name: {0}, s1: {1}, s2: {2}, i1: {3}, i2: {4}", name, s1, s2, i1, i2);
Button btn = new Button(name);
btn.Show();
return btn;
}
public Widget custom(XML xml, string func_name, string name, string s1, string s2, int i1, int i2)
{
Widget w;
switch(func_name)
{
case "createCustomTree":
w = createCustomTree(name, s1, s2, i1, i2);
break;
default:
w = new Button("Custom");
break;
}
w.Show();
return w;
}
}
}
DeweyGui.glade
Description: application/glade
_______________________________________________ Gtk-sharp-list maillist - [email protected] http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
