webglade

JavaScript library to dynamically create XUL GUI from Glade XML files
git clone https://logand.com/git/webglade.git/
Log | Files | Refs | README | LICENSE

commit 99b9998407f7a96ae10048d7dfde9c54bac674ee
parent df1a349e0a4b04865f682c4cb11494b811e72c45
Author: Eric Schug <schugschug@gmail.com>
Date:   Sat, 18 Sep 2010 02:02:34 +0200

Added limited stock image support
Added GtkCheckMenuItem, GtkImageMenuItem, GtkExpander*, GtkViewport*, GtkMenuToolButton*
Added basic support for GtkBuilder format

Diffstat:
Mwebglade.js | 186+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 186 insertions(+), 0 deletions(-)

diff --git a/webglade.js b/webglade.js @@ -238,6 +238,28 @@ var WBUILD = { }; var WPACK = { }; + +// ECS add GTK stock_id support +var stock_id = { }; +stock_names = new Array("open","close","about","undo","redo","cut","copy","paste","save") + +for (x in stock_names) { + var id =stock_names[x]; + stock_id['gtk-'+id]={label : 'Open'}; +} + +function stock_id_get_label(id) { + //label = stock_id[id]["label"]; + label = id[4].toUpperCase()+id.substring(5).replace('-',' '); + return label; +}; + +function stock_id_get_icon(id) { + //label = stock_id[id]["icon"]; + label = 'gtk_stock/' + id + '.png'; + return label; +}; + function wclass(widget) { if (widget.class == 'Custom') { return getProperty(widget, 'creation_function'); @@ -246,6 +268,8 @@ function wclass(widget) { }; }; + +// ECS adding support for GtkBuilder (incomplete) function parseGlade(glade) { var widgets = { }; { @@ -301,6 +325,9 @@ function parseGlade(glade) { case 'widget': current = recWidget(parent, child); break; + case 'object': // GTKBuilder same as widget + current = recWidget(parent, child); + break; case 'packing': recPacking(parent, child, current); }; }; @@ -341,9 +368,15 @@ function parseGlade(glade) { case 'glade-interface': rec(parent, node.childNodes); break; + case 'interface': // GTKBuilder same as widget + rec(parent, node.childNodes); + break; case 'widget': recWidget(parent, node); break; + case 'object': // GTKBuilder same as widget + recWidget(parent, node); + break; case 'child': recChild(parent, node); break; @@ -500,6 +533,10 @@ function (pw, self) { readonly : 'False' == editable ? true : undefined }, { change : changed }); }; +WPACK['GtkEntryCompletion'] = +function (pw, w, self) { + return WPACK['GtkEntry'](pw, w, self); +}; WBUILD['GtkTextView'] = function (pw, self) { @@ -540,6 +577,54 @@ function (pw, self) { wbuild(w, body); }; +// ECS added based on GtkFrame needs work +WBUILD['GtkExpander'] = +function (pw, self) { + var w = wmake(pw, 'xul:groupbox', { id : self.id }); + var w2 = wmake(w, 'xul:caption'); + var label = [ ]; + var body = [ ]; + { + var tmpArr17 = self.children; + if (tmpArr17) { + for (var tmpI18 = 0; tmpI18 < tmpArr17.length; tmpI18 = tmpI18 + 1) { + var child = tmpArr17[tmpI18]; + if ('label_item' == getPacking(child, 'type')) { + push(child, label); + } else { + push(child, body); + }; + }; + }; + }; + wbuild(w2, label); + wbuild(w, body); +}; + +// ECS added based on GTKFrame +WBUILD['GtkViewport'] = +function (pw, self) { + var w = wmake(pw, 'xul:groupbox', { id : self.id }); + var w2 = wmake(w, 'xul:caption'); + var label = [ ]; + var body = [ ]; + { + var tmpArr17 = self.children; + if (tmpArr17) { + for (var tmpI18 = 0; tmpI18 < tmpArr17.length; tmpI18 = tmpI18 + 1) { + var child = tmpArr17[tmpI18]; + if ('label_item' == getPacking(child, 'type')) { + push(child, label); + } else { + push(child, body); + }; + }; + }; + }; + wbuild(w2, label); + wbuild(w, body); +}; + WBUILD['GtkAlignment'] = function (pw, self) { wbuild(pw, self.children); @@ -589,6 +674,14 @@ function (pw, self) { return w; }; +// ECS added +WBUILD['GtkMenuToolButton'] = +function (pw, self) { + var w = wmake(pw, 'xul:menupopup', { id : self.id }); + wbuild(w, self.children); + return w; +}; + WBUILD['GtkSeparatorMenuItem'] = function (pw, self) { return wmake(pw, 'xul:menuseparator', { id : self.id }); @@ -633,6 +726,82 @@ function (pw, self) { }; }; +// ECS added +WBUILD['GtkImageMenuItem'] = +function (pw, self) { + var label = getProperty(self, 'label'); + // ECS support gtk stock items + var use_stock = getProperty(self, 'use_stock'); + var activate = getSignal(self, 'activate'); + var icon = getProperty(self, 'icon'); + var showLabel = true; + var showImage = true; + if(use_stock) { + icon = stock_id_get_icon(label); + label = stock_id_get_label(label); + } + if ('GtkMenuBar' == wclass(self.parent) || 0 < self.children.length) { + var w = + wmake + (pw, 'xul:menu', + { id : self.id, + label : removeAccessKey(label), + accesskey : findAccessKey(label) }, + { command : activate }); + if (0 < self.children.length) { + wbuild(w, self.children); + } else { + wmake(w, 'xul:menupopup'); + }; + return w; + } else { + return wmake + (pw, 'xul:menuitem', + { id : self.id, + class : stock_id, + label : removeAccessKey(label), + image : showImage ? imageUrl(icon) : undefined, + accesskey : findAccessKey(label) }, + { command : activate }); + }; +}; + +// ECS added +WBUILD['GtkCheckMenuItem'] = +function (pw, self) { + var label = getProperty(self, 'label'); + // ECS support gtk stock items + var use_stock = getProperty(self, 'use_stock'); + var activate = getSignal(self, 'activate'); + if(use_stock) { + label = stock_id_get_label(label); + } + if ('GtkMenuBar' == wclass(self.parent) || 0 < self.children.length) { + var w = + wmake + (pw, 'xul:menu', + { id : self.id, + label : removeAccessKey(label), + accesskey : findAccessKey(label) }, + { command : activate }); + if (0 < self.children.length) { + wbuild(w, self.children); + } else { + wmake(w, 'xul:menupopup'); + }; + return w; + } else { + return wmake + (pw, 'xul:menuitem', + { id : self.id, + class : stock_id, + type : "checkbox", + label : removeAccessKey(label), + accesskey : findAccessKey(label) }, + { command : activate }); + }; +}; + WBUILD['GtkHBox'] = function (pw, self) { var w = @@ -851,12 +1020,19 @@ function (pw, self) { var label = getProperty(self, 'label'); var icon = getProperty(self, 'icon'); var tooltip = getProperty(self, 'tooltip'); + // ECS added stock_id support using css classes + var stock_id = getProperty(self, 'stock_id'); var clicked = getSignal(self, 'clicked'); var showLabel = true; var showImage = true; + if(stock_id) { + label = stock_id_get_label(stock_id); + icon = stock_id_get_icon(stock_id); + } return wmake (pw, 'xul:toolbarbutton', { id : self.id, + class : stock_id, label : showLabel ? label : undefined, image : showImage ? imageUrl(icon) : undefined, tooltiptext : tooltip }, @@ -986,6 +1162,16 @@ function (pw, self) { return wmake(pw, 'xul:tree', { id : self.id }); }; +// ECS added +WBUILD['GtkCalender'] = +function (pw, self) { + return wmake + (pw, 'xul:datepicker', + { id : self.id, + }); +}; + + WBUILD['xul:iframe'] = function (pw, self) { var string1 = getProperty(self, 'string1');