This commit is contained in:
Namhyeon Go 2020-10-27 14:44:09 +09:00
parent 507eecf119
commit 8560f2eb45
2 changed files with 60 additions and 23 deletions

12
gtktest.js Normal file
View 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;

View File

@ -7,7 +7,8 @@ var SHELL = require("lib/shell");
var binPath = "bin\\gtk-server.exe"; var binPath = "bin\\gtk-server.exe";
// start GTKServer // start GTKServer
var GTKServer = SHELL.createExecObject([binPath, "-stdin"]); var process = CreateObject("Wscript.Shell");
var GTKServer = process.Exec("bin\\gtk-server -stdin");
// Common (Widgets) // Common (Widgets)
var GTKWidgets = {}; var GTKWidgets = {};
@ -15,7 +16,6 @@ var GTKWidgets = {};
// Common (Element) // Common (Element)
var GTKWidget = function() { var GTKWidget = function() {
this.widgetType = "GTKWidget"; this.widgetType = "GTKWidget";
this.widgetID = GTKCreateWidget(this);
this.dispatchEvent = function(event) { this.dispatchEvent = function(event) {
event.target = this; event.target = this;
@ -29,25 +29,28 @@ var GTKWidget = function() {
} else { } else {
throw new TypeError("EventListener must be a function"); throw new TypeError("EventListener must be a function");
} }
};. };
this.eventListener = function() { this.eventListener = function() {
this.dispatchEvent(new GTKEvent("wait")); this.dispatchEvent(new GTKEvent("wait"));
return GTKEventListener(this); return GTKEventListener(this);
}; };
this.setWidgetType = function(widgetType) {
GTKWidgets[this.widgetID] = this; this.widgetType = widgetType;
};
this.dispatchEvent(new GTKEvent("load")); this.dispatchEvent(new GTKEvent("load"));
this.widgetID = GTKCreateWidget(this);
GTKWidgets[this.widgetID] = this;
}; };
// Common (definedEvents) // Common (definedEvents)
var definedEvents = { var definedEvents = {
"Window" [], "Window": [],
"Table": [], "Table": [],
"Button": ["click"], "Button": ["click"],
"Entry": ["keyup"] "Entry": ["keyup"],
"RadioBox": ["click"], "RadioBox": ["click"],
"TextBox" [] "TextBox": []
}; };
// Common (Event) // Common (Event)
@ -66,10 +69,12 @@ var GTKEventListener = function(widget) {
} }
}; };
// GTKCreateElement // GTKCreateWidget
var GTKCreateWidget = function(widget) { var GTKCreateWidget = function(widget) {
var widgetID, commands = []; var widgetID, commands = [];
console.info(widget.widgetType);
switch (widget.widgetType) { switch (widget.widgetType) {
case "Window": case "Window":
commands.push([ commands.push([
@ -145,17 +150,23 @@ var GTKExecCommand = function(command) {
line = _command.join(' '); line = _command.join(' ');
console.info(line);
GTKServer.StdIn.WriteLine(line); GTKServer.StdIn.WriteLine(line);
return GTKServer.StdOut.ReadLine(); return GTKServer.StdOut.ReadLine();
}; };
// GTKInit // GTKInit
var GTKInit = function() { var GTKInit = function(callback) {
return GTKExecCommand([ GTKExecCommand([
"gtk_init", "gtk_init",
"NULL" "NULL",
"NULL" "NULL"
]); ]);
if (typeof(callback) == "function") {
callback();
}
}; };
// GTKExit // GTKExit
@ -169,16 +180,16 @@ var GTKExit = function() {
var Window = function() { var Window = function() {
GTKWidget.apply(this, arguments); GTKWidget.apply(this, arguments);
this.elementType = "Window"; this.widgetType = "Window";
this.type = 0; this.type = 0;
this.title = "WelsonJS GTK GUI Application"; this.title = "WelsonJS GTK GUI Application";
this.show = function() {
this.show() = function() {
return GTKExecCommand([ return GTKExecCommand([
"gtk_widget_show_all", "gtk_widget_show_all",
this.widgetID this.widgetID
]); ]);
}; };
this.setWidgetType(this.widgetType);
}; };
Window.prototype = new GTKWidget(); Window.prototype = new GTKWidget();
Window.prototype.constructor = Window; Window.prototype.constructor = Window;
@ -187,7 +198,7 @@ Window.prototype.constructor = Window;
var Table = function() { var Table = function() {
GTKWidget.apply(this, arguments); GTKWidget.apply(this, arguments);
this.elementType = "Table"; this.widgetType = "Table";
this.rows = 1; this.rows = 1;
this.columns = 1; this.columns = 1;
this.homogeneous = true; this.homogeneous = true;
@ -206,6 +217,8 @@ var Table = function() {
bottom bottom
]); ]);
}; };
this.setWidgetType(this.widgetType);
}; };
Table.prototype = new GTKWidget(); Table.prototype = new GTKWidget();
Table.prototype.constructor = Table; Table.prototype.constructor = Table;
@ -214,8 +227,10 @@ Table.prototype.constructor = Table;
var Button = function() { var Button = function() {
GTKWidget.apply(this, arguments); GTKWidget.apply(this, arguments);
this.elementType = "Button"; this.widgetType = "Button";
this.text = "New Button"; this.text = "New Button";
this.setWidgetType(this.widgetType);
}; };
Button.prototype = new GTKWidget(); Button.prototype = new GTKWidget();
Button.prototype.constructor = Button; Button.prototype.constructor = Button;
@ -224,7 +239,7 @@ Button.prototype.constructor = Button;
var Entry = function() { var Entry = function() {
GTKWidget.apply(this, arguments); GTKWidget.apply(this, arguments);
this.elementType = "Entry"; this.widgetType = "Entry";
this.text = "New Label"; this.text = "New Label";
this.focus = function() { this.focus = function() {
@ -261,6 +276,7 @@ var Entry = function() {
}; };
this.setText(this.text); this.setText(this.text);
this.setWidgetType(this.widgetType);
}; };
Entry.prototype = new GTKWidget(); Entry.prototype = new GTKWidget();
Entry.prototype.constructor = Entry; Entry.prototype.constructor = Entry;
@ -269,9 +285,11 @@ Entry.prototype.constructor = Entry;
var RadioBox = function() { var RadioBox = function() {
GTKWidget.apply(this, arguments); GTKWidget.apply(this, arguments);
this.elementType = "RadioBox"; this.widgetType = "RadioBox";
this.text = "New RadioBox"; this.text = "New RadioBox";
this.member = "NULL"; this.member = "NULL";
this.setWidgetType(this.widgetType);
}; };
RadioBox.prototype = new GTKWidget(); RadioBox.prototype = new GTKWidget();
RadioBox.prototype.constructor = RadioBox; RadioBox.prototype.constructor = RadioBox;
@ -280,7 +298,7 @@ RadioBox.prototype.constructor = RadioBox;
var TextBox = function() { var TextBox = function() {
GTKWidget.apply(this, arguments); GTKWidget.apply(this, arguments);
this.elementType = "TextBox"; this.widgetType = "TextBox";
this.text = "New TextBox"; this.text = "New TextBox";
this.setText = function(text) { this.setText = function(text) {
@ -291,12 +309,13 @@ var TextBox = function() {
"NULL", "NULL",
"NULL", "NULL",
"NULL", "NULL",
"\"" + this.text + "\"" "\"" + this.text + "\"",
"-1" "-1"
]); ]);
}; };
this.setText(this.text); this.setText(this.text);
this.setWidgetType(this.widgetType);
}; };
TextBox.prototype = new GTKWidget(); TextBox.prototype = new GTKWidget();
TextBox.prototype.constructor = TextBox; TextBox.prototype.constructor = TextBox;
@ -325,10 +344,16 @@ var GTKWait = function(callback) {
GTKExit(); GTKExit();
}; };
exports.Widget = GTKWidget;
exports.Window = Window; exports.Window = Window;
exports.Table = Table; exports.Table = Table;
exports.Button = Button; exports.Button = Button;
exports.Entry = Entry; exports.Entry = Entry;
exports.RadioBox = RadioBox; exports.RadioBox = RadioBox;
exports.TextBox = TextBox; exports.TextBox = TextBox;
exports.init = GTKInit;
exports.wait = GTKWait; exports.wait = GTKWait;
exports.VERSIONINFO = "GTKServer Module (gtk.js) version 0.1";
exports.global = global;
exports.require = require;