[Vala] widget bindings take 2



My widget bindings project is to have a declaration for each widget as part of a vala class, so that the author doesn't have to write this.xml.get_widget("dialer-entry"); all over the place, but definitions for each widget are generated and linked automatically;
e.g.

myform.widgets.inputbox

implemented in C as something like:
_GladeMyformPrivate->widgets->inputbox

I've written some xslt which generates a C (.h) file from a .glade file with all the right definitions.

The demo.glade.h file can be build with the attached gen-glade-widget-bindings.xslt, like this:

xsltproc --nodtdattr --path /usr/share/xml/libglade gen-glade-widget-bindings.xslt src/demo.glade > src/demo.glade.h

The difficulty is importing the defined widgets union declaration into the vala file, I need it to be a private member. I also need to be able to get at the embedded xml from vala in order to pass to the Glade.XML

I think I need advice; I'm nearly there but I think I'm also at a dead end.

Possibly there are some [CCode] options to use but I don't think they are enough.

I think that if the union members will be available from vala, that I have to define a vala struct or class, but the union members are meant to be private to an existing vala class in another file, and there's no #include for vala that I know of.

Maybe the generated vala should be an ancestor class to the authored code, but vala doesn't support protected properties, only public or private (protected methods exist) so I'm a bit lost, maybe vala isn't neatly capable of this after without IDE integrated to edit the code on-the-fly.

Sam

Attachment: gen-glade-widget-bindings.xslt
Description: application/xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Sat Jun 21 14:10:38 2008 -->
<glade-interface>
  <widget class="GtkWindow" id="window1">
    <child>
      <widget class="GtkVBox" id="vbox1">
        <property name="visible">True</property>
        <child>
          <widget class="GtkImage" id="image1">
            <property name="visible">True</property>
            <property name="stock">gtk-missing-image</property>
          </widget>
        </child>
        <child>
          <widget class="GtkButton" id="button1">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <property name="label" translatable="yes">gtk-ok</property>
            <property name="use_stock">True</property>
            <property name="response_id">0</property>
          </widget>
          <packing>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <widget class="GtkStatusbar" id="statusbar1">
            <property name="visible">True</property>
            <property name="spacing">2</property>
          </widget>
          <packing>
            <property name="expand">False</property>
            <property name="position">2</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>
/* Auto generated by gen-glade-widget-bindings.xslt */

#define window1_WIDGET_COUNT 5

union widgets {
  GtkWidget by_number[window1_WIDGET_COUNT];
  struct {
    GtkWindow window1; /* GtkWindow window1 */
    GtkVBox vbox1; /* GtkVBox vbox1 */
    GtkImage image1; /* GtkImage image1 */
    GtkButton button1; /* GtkButton button1 */
    GtkStatusbar statusbar1; /* GtkStatusbar statusbar1 */

  } by_name;
};/* widget name list for runtime binding */


struct { 
  int index;
  char* name;
  char* class;
} widget_info[]= {
  {0, "GtkWindow", "window1"},
  {1, "GtkVBox", "vbox1"},
  {2, "GtkImage", "image1"},
  {3, "GtkButton", "button1"},
  {4, "GtkStatusbar", "statusbar1"},
  {0,NULL,NULL}
};
static inline int GET_WIGET_ID_BY_NAME(char* name) {
  int c=0;
  while (widget_info[c].name) {
    if (strcmp(name,widget_info[c].name)==0) return widget_info[c].index;
    c++;
  }
  return -1;
}

static inline int GET_WIGET_ID_BY_NAME_CLASS(char* name, char* class) {
  int c=0;
  while (widget_info[c].name) {
    if (strcmp(name,widget_info[c].name)==0 &&
        strcmp(class,widget_info[c].class)==0) return widget_info[c].index;
    c++;
  }
  return -1;
}

char* glade_xml="<!-- Generated with glade3 3.4.5 on Sat Jun 21 14:10:38 2008 --><glade-interface>\n"
"  <widget class=\"GtkWindow\" id=\"window1\">\n"
"    <child>\n"
"      <widget class=\"GtkVBox\" id=\"vbox1\">\n"
"        <property name=\"visible\">True</property>\n"
"        <child>\n"
"          <widget class=\"GtkImage\" id=\"image1\">\n"
"            <property name=\"visible\">True</property>\n"
"            <property name=\"stock\">gtk-missing-image</property>\n"
"          </widget>\n"
"        </child>\n"
"        <child>\n"
"          <widget class=\"GtkButton\" id=\"button1\">\n"
"            <property name=\"visible\">True</property>\n"
"            <property name=\"can_focus\">True</property>\n"
"            <property name=\"receives_default\">True</property>\n"
"            <property name=\"label\" translatable=\"yes\">gtk-ok</property>\n"
"            <property name=\"use_stock\">True</property>\n"
"            <property name=\"response_id\">0</property>\n"
"          </widget>\n"
"          <packing>\n"
"            <property name=\"position\">1</property>\n"
"          </packing>\n"
"        </child>\n"
"        <child>\n"
"          <widget class=\"GtkStatusbar\" id=\"statusbar1\">\n"
"            <property name=\"visible\">True</property>\n"
"            <property name=\"spacing\">2</property>\n"
"          </widget>\n"
"          <packing>\n"
"            <property name=\"expand\">False</property>\n"
"            <property name=\"position\">2</property>\n"
"          </packing>\n"
"        </child>\n"
"      </widget>\n"
"    </child>\n"
"  </widget>\n"
"</glade-interface>";


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]