This commit is contained in:
Namhyeon Go 2020-10-28 17:18:17 +09:00
parent 8bba929f18
commit 7f3673608a
3 changed files with 132 additions and 19 deletions

View File

@ -2,11 +2,64 @@ var GTK = require("lib/gtk");
function main() {
GTK.init(function() {
var win = new GTK.Window();
var win, table, button, entry, text, radiogroup, radio1, radio2;
// create new window
win = new GTK.Window({
title: "Hello world",
width: 450,
height: 400
});
// create new table
table = new GTK.Table({
rows: 50,
columns: 50
});
win.setContainer(table);
// create new button
button = new GTK.Button({
text: "Exit"
});
button.addEventListener('click', function() {
GTK.exit();
});
table.attach(button, 41, 49, 45, 49);
// create new entry
entry = new GTK.Entry();
table.attach(entry, 1, 40, 45, 49);
// create new textbox
text = new GTK.TextBox();
table.attach(entry, 1, 49, 8, 44);
// create new radiogroup
radiogroup = new GTK.RadioGroup();
// create new radio (Radio 1)
radio1 = new GTK.RadioBox({
text: "Yes",
group: radiogroup
});
table.attach(radio1, 1, 10, 1, 4);
// create new radio (Radio 2)
radio2 = new GTK.RadioBox({
text: "No",
group: radiogroup
});
table.attach(radio2, 1, 10, 4, 7);
// showing window
win.show();
// focusing entry
entry.focus();
});
//GTK.wait(function() {});
GTK.wait();
}
exports.main = main;

View File

@ -4,18 +4,18 @@
var SHELL = require("lib/shell");
// set binPath
var binPath = "bin\\gtk-server.exe";
var binPath = "bin\\gtk-server";
// start GTKServer
var process = CreateObject("Wscript.Shell");
var GTKServer = process.Exec("bin\\gtk-server -stdin");
var GTKServer = SHELL.createProcess([binPath, "-stdin"]);
// Common (Widgets)
var GTKWidgets = {};
// Common (Element)
var GTKWidget = function() {
var GTKWidget = function(options) {
this.widgetType = "GTKWidget";
this.widgetID = "0";
this.dispatchEvent = function(event) {
event.target = this;
@ -37,7 +37,13 @@ var GTKWidget = function() {
this.setWidgetType = function(widgetType) {
this.widgetType = widgetType;
};
this.create = function() {
this.create = function(callback) {
if (typeof(options) === "object") {
for (var k in options) {
this[k] = options[k];
}
}
this.dispatchEvent(new GTKEvent("load"));
this.widgetID = GTKCreateWidget(this);
GTKWidgets[this.widgetID] = this;
@ -73,8 +79,6 @@ var GTKEventListener = function(widget) {
// GTKCreateWidget
var GTKCreateWidget = function(widget) {
var widgetID, commands = [];
console.info(widget.widgetType);
switch (widget.widgetType) {
case "Window":
@ -112,7 +116,7 @@ var GTKCreateWidget = function(widget) {
case "RadioBox":
commands.push([
"gtk_radio_button_new_with_label_from_widget",
widget.member,
"NULL",
"\"" + widget.text + "\""
]);
break;
@ -151,10 +155,10 @@ var GTKExecCommand = function(command) {
line = _command.join(' ');
console.info(line);
console.log(line);
GTKServer.StdIn.WriteLine(line);
return GTKServer.StdOut.ReadLine();
GTKServer.StdIn.WriteLine(line);
return GTKServer.StdOut.ReadLine();
};
// GTKInit
@ -184,6 +188,18 @@ var Window = function() {
this.widgetType = "Window";
this.type = 0;
this.title = "WelsonJS GTK GUI Application";
this.width = 450;
this.height = 400;
this.containerWidget = null;
this.setContainer = function(widget) {
this.containerWidget = widget;
return GTKExecCommand([
"gtk_container_add",
this.widgetID,
widget.widgetID
]);
};
this.show = function() {
return GTKExecCommand([
"gtk_widget_show_all",
@ -192,6 +208,19 @@ var Window = function() {
};
this.setWidgetType(this.widgetType);
this.create();
GTKExecCommand([
"gtk_window_set_title",
this.widgetID,
"\"" + this.title + "\""
]);
GTKExecCommand([
"gtk_widget_set_usize",
this.widgetID,
this.width,
this.height
]);
};
Window.prototype = new GTKWidget();
Window.prototype.constructor = Window;
@ -292,14 +321,45 @@ var RadioBox = function() {
this.widgetType = "RadioBox";
this.text = "New RadioBox";
this.member = "NULL";
this.group = {
widgetID: "NULL"
};
this.memberWidget = {
widgetID: "NULL"
};
this.setMemberWidget = function(widget) {
this.memberWidget = widget;
};
this.setWidgetType(this.widgetType);
if (this.group.widgetID != "NULL") {
this.group.add(this);
}
this.create();
};
RadioBox.prototype = new GTKWidget();
RadioBox.prototype.constructor = RadioBox;
// RadioGroup
var RadioGroup = function() {
GTKWidget.apply(this, arguments);
this.memberWidgets = [];
this.widgetType = "RadioGroup";
this.add = function(widget) {
if (memberWidgets.length > 0) {
widget.setMemberWidget(this.memberWidgets[0]);
}
this.memberWidgets.push(widget);
};
};
RadioBox.prototype = new GTKWidget();
RadioBox.prototype.constructor = RadioGroup;
// TextBox
var TextBox = function() {
GTKWidget.apply(this, arguments);
@ -331,8 +391,6 @@ TextBox.prototype.constructor = TextBox;
var GTKWait = function(callback) {
var even;
GTKInit();
while (true) {
even = GTKExecCommand([
"gtk_server_callback",
@ -357,10 +415,12 @@ exports.Table = Table;
exports.Button = Button;
exports.Entry = Entry;
exports.RadioBox = RadioBox;
exports.RadioGroup = RadioGroup;
exports.TextBox = TextBox;
exports.init = GTKInit;
exports.wait = GTKWait;
exports.exit = GTKExit;
exports.VERSIONINFO = "GTKServer Module (gtk.js) version 0.1";
exports.global = global;

View File

@ -62,7 +62,7 @@ exports.run = function(cmd, fork) {
WSH.Run(c, 0, !fork);
};
exports.createExecObject = function(cmd) {
exports.createProcess = function(cmd) {
var WSH = CreateObject("WScript.Shell");
return WSH.Exec(makeCommand(cmd));
};