mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-03-11 16:35:13 +00:00
fix
This commit is contained in:
parent
507eecf119
commit
8560f2eb45
12
gtktest.js
Normal file
12
gtktest.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
var GTK = require("lib/gtk");
|
||||
|
||||
function main() {
|
||||
GTK.init(function() {
|
||||
var win = new GTK.Window();
|
||||
win.show();
|
||||
});
|
||||
|
||||
//GTK.wait(function() {});
|
||||
}
|
||||
|
||||
exports.main = main;
|
71
lib/gtk.js
71
lib/gtk.js
|
@ -7,7 +7,8 @@ var SHELL = require("lib/shell");
|
|||
var binPath = "bin\\gtk-server.exe";
|
||||
|
||||
// start GTKServer
|
||||
var GTKServer = SHELL.createExecObject([binPath, "-stdin"]);
|
||||
var process = CreateObject("Wscript.Shell");
|
||||
var GTKServer = process.Exec("bin\\gtk-server -stdin");
|
||||
|
||||
// Common (Widgets)
|
||||
var GTKWidgets = {};
|
||||
|
@ -15,8 +16,7 @@ var GTKWidgets = {};
|
|||
// Common (Element)
|
||||
var GTKWidget = function() {
|
||||
this.widgetType = "GTKWidget";
|
||||
this.widgetID = GTKCreateWidget(this);
|
||||
|
||||
|
||||
this.dispatchEvent = function(event) {
|
||||
event.target = this;
|
||||
if(event.eventName in this) {
|
||||
|
@ -29,25 +29,28 @@ var GTKWidget = function() {
|
|||
} else {
|
||||
throw new TypeError("EventListener must be a function");
|
||||
}
|
||||
};.
|
||||
};
|
||||
this.eventListener = function() {
|
||||
this.dispatchEvent(new GTKEvent("wait"));
|
||||
return GTKEventListener(this);
|
||||
};
|
||||
|
||||
GTKWidgets[this.widgetID] = this;
|
||||
|
||||
this.setWidgetType = function(widgetType) {
|
||||
this.widgetType = widgetType;
|
||||
};
|
||||
|
||||
this.dispatchEvent(new GTKEvent("load"));
|
||||
this.widgetID = GTKCreateWidget(this);
|
||||
GTKWidgets[this.widgetID] = this;
|
||||
};
|
||||
|
||||
// Common (definedEvents)
|
||||
var definedEvents = {
|
||||
"Window" [],
|
||||
"Window": [],
|
||||
"Table": [],
|
||||
"Button": ["click"],
|
||||
"Entry": ["keyup"]
|
||||
"Entry": ["keyup"],
|
||||
"RadioBox": ["click"],
|
||||
"TextBox" []
|
||||
"TextBox": []
|
||||
};
|
||||
|
||||
// Common (Event)
|
||||
|
@ -66,9 +69,11 @@ var GTKEventListener = function(widget) {
|
|||
}
|
||||
};
|
||||
|
||||
// GTKCreateElement
|
||||
// GTKCreateWidget
|
||||
var GTKCreateWidget = function(widget) {
|
||||
var widgetID, commands = [];
|
||||
|
||||
console.info(widget.widgetType);
|
||||
|
||||
switch (widget.widgetType) {
|
||||
case "Window":
|
||||
|
@ -144,18 +149,24 @@ var GTKExecCommand = function(command) {
|
|||
}
|
||||
|
||||
line = _command.join(' ');
|
||||
|
||||
console.info(line);
|
||||
|
||||
GTKServer.StdIn.WriteLine(line);
|
||||
return GTKServer.StdOut.ReadLine();
|
||||
};
|
||||
|
||||
// GTKInit
|
||||
var GTKInit = function() {
|
||||
return GTKExecCommand([
|
||||
var GTKInit = function(callback) {
|
||||
GTKExecCommand([
|
||||
"gtk_init",
|
||||
"NULL"
|
||||
"NULL",
|
||||
"NULL"
|
||||
]);
|
||||
|
||||
if (typeof(callback) == "function") {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
// GTKExit
|
||||
|
@ -169,16 +180,16 @@ var GTKExit = function() {
|
|||
var Window = function() {
|
||||
GTKWidget.apply(this, arguments);
|
||||
|
||||
this.elementType = "Window";
|
||||
this.widgetType = "Window";
|
||||
this.type = 0;
|
||||
this.title = "WelsonJS GTK GUI Application";
|
||||
|
||||
this.show() = function() {
|
||||
this.show = function() {
|
||||
return GTKExecCommand([
|
||||
"gtk_widget_show_all",
|
||||
this.widgetID
|
||||
]);
|
||||
};
|
||||
this.setWidgetType(this.widgetType);
|
||||
};
|
||||
Window.prototype = new GTKWidget();
|
||||
Window.prototype.constructor = Window;
|
||||
|
@ -187,7 +198,7 @@ Window.prototype.constructor = Window;
|
|||
var Table = function() {
|
||||
GTKWidget.apply(this, arguments);
|
||||
|
||||
this.elementType = "Table";
|
||||
this.widgetType = "Table";
|
||||
this.rows = 1;
|
||||
this.columns = 1;
|
||||
this.homogeneous = true;
|
||||
|
@ -206,6 +217,8 @@ var Table = function() {
|
|||
bottom
|
||||
]);
|
||||
};
|
||||
|
||||
this.setWidgetType(this.widgetType);
|
||||
};
|
||||
Table.prototype = new GTKWidget();
|
||||
Table.prototype.constructor = Table;
|
||||
|
@ -214,8 +227,10 @@ Table.prototype.constructor = Table;
|
|||
var Button = function() {
|
||||
GTKWidget.apply(this, arguments);
|
||||
|
||||
this.elementType = "Button";
|
||||
this.widgetType = "Button";
|
||||
this.text = "New Button";
|
||||
|
||||
this.setWidgetType(this.widgetType);
|
||||
};
|
||||
Button.prototype = new GTKWidget();
|
||||
Button.prototype.constructor = Button;
|
||||
|
@ -224,7 +239,7 @@ Button.prototype.constructor = Button;
|
|||
var Entry = function() {
|
||||
GTKWidget.apply(this, arguments);
|
||||
|
||||
this.elementType = "Entry";
|
||||
this.widgetType = "Entry";
|
||||
this.text = "New Label";
|
||||
|
||||
this.focus = function() {
|
||||
|
@ -261,6 +276,7 @@ var Entry = function() {
|
|||
};
|
||||
|
||||
this.setText(this.text);
|
||||
this.setWidgetType(this.widgetType);
|
||||
};
|
||||
Entry.prototype = new GTKWidget();
|
||||
Entry.prototype.constructor = Entry;
|
||||
|
@ -269,9 +285,11 @@ Entry.prototype.constructor = Entry;
|
|||
var RadioBox = function() {
|
||||
GTKWidget.apply(this, arguments);
|
||||
|
||||
this.elementType = "RadioBox";
|
||||
this.widgetType = "RadioBox";
|
||||
this.text = "New RadioBox";
|
||||
this.member = "NULL";
|
||||
|
||||
this.setWidgetType(this.widgetType);
|
||||
};
|
||||
RadioBox.prototype = new GTKWidget();
|
||||
RadioBox.prototype.constructor = RadioBox;
|
||||
|
@ -280,7 +298,7 @@ RadioBox.prototype.constructor = RadioBox;
|
|||
var TextBox = function() {
|
||||
GTKWidget.apply(this, arguments);
|
||||
|
||||
this.elementType = "TextBox";
|
||||
this.widgetType = "TextBox";
|
||||
this.text = "New TextBox";
|
||||
|
||||
this.setText = function(text) {
|
||||
|
@ -291,12 +309,13 @@ var TextBox = function() {
|
|||
"NULL",
|
||||
"NULL",
|
||||
"NULL",
|
||||
"\"" + this.text + "\""
|
||||
"\"" + this.text + "\"",
|
||||
"-1"
|
||||
]);
|
||||
};
|
||||
|
||||
this.setText(this.text);
|
||||
this.setWidgetType(this.widgetType);
|
||||
};
|
||||
TextBox.prototype = new GTKWidget();
|
||||
TextBox.prototype.constructor = TextBox;
|
||||
|
@ -325,10 +344,16 @@ var GTKWait = function(callback) {
|
|||
GTKExit();
|
||||
};
|
||||
|
||||
exports.Widget = GTKWidget;
|
||||
exports.Window = Window;
|
||||
exports.Table = Table;
|
||||
exports.Button = Button;
|
||||
exports.Entry = Entry;
|
||||
exports.RadioBox = RadioBox;
|
||||
exports.TextBox = TextBox;
|
||||
exports.init = GTKInit;
|
||||
exports.wait = GTKWait;
|
||||
|
||||
exports.VERSIONINFO = "GTKServer Module (gtk.js) version 0.1";
|
||||
exports.global = global;
|
||||
exports.require = require;
|
||||
|
|
Loading…
Reference in New Issue
Block a user