mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-06 15:04:58 +00:00
fix
This commit is contained in:
parent
8bba929f18
commit
7f3673608a
59
gtktest.js
59
gtktest.js
|
@ -2,11 +2,64 @@ var GTK = require("lib/gtk");
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
GTK.init(function() {
|
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();
|
win.show();
|
||||||
|
|
||||||
|
// focusing entry
|
||||||
|
entry.focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
//GTK.wait(function() {});
|
GTK.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.main = main;
|
exports.main = main;
|
||||||
|
|
90
lib/gtk.js
90
lib/gtk.js
|
@ -4,18 +4,18 @@
|
||||||
var SHELL = require("lib/shell");
|
var SHELL = require("lib/shell");
|
||||||
|
|
||||||
// set binPath
|
// set binPath
|
||||||
var binPath = "bin\\gtk-server.exe";
|
var binPath = "bin\\gtk-server";
|
||||||
|
|
||||||
// start GTKServer
|
// start GTKServer
|
||||||
var process = CreateObject("Wscript.Shell");
|
var GTKServer = SHELL.createProcess([binPath, "-stdin"]);
|
||||||
var GTKServer = process.Exec("bin\\gtk-server -stdin");
|
|
||||||
|
|
||||||
// Common (Widgets)
|
// Common (Widgets)
|
||||||
var GTKWidgets = {};
|
var GTKWidgets = {};
|
||||||
|
|
||||||
// Common (Element)
|
// Common (Element)
|
||||||
var GTKWidget = function() {
|
var GTKWidget = function(options) {
|
||||||
this.widgetType = "GTKWidget";
|
this.widgetType = "GTKWidget";
|
||||||
|
this.widgetID = "0";
|
||||||
|
|
||||||
this.dispatchEvent = function(event) {
|
this.dispatchEvent = function(event) {
|
||||||
event.target = this;
|
event.target = this;
|
||||||
|
@ -37,7 +37,13 @@ var GTKWidget = function() {
|
||||||
this.setWidgetType = function(widgetType) {
|
this.setWidgetType = function(widgetType) {
|
||||||
this.widgetType = 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.dispatchEvent(new GTKEvent("load"));
|
||||||
this.widgetID = GTKCreateWidget(this);
|
this.widgetID = GTKCreateWidget(this);
|
||||||
GTKWidgets[this.widgetID] = this;
|
GTKWidgets[this.widgetID] = this;
|
||||||
|
@ -73,8 +79,6 @@ var GTKEventListener = function(widget) {
|
||||||
// GTKCreateWidget
|
// 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":
|
||||||
|
@ -112,7 +116,7 @@ var GTKCreateWidget = function(widget) {
|
||||||
case "RadioBox":
|
case "RadioBox":
|
||||||
commands.push([
|
commands.push([
|
||||||
"gtk_radio_button_new_with_label_from_widget",
|
"gtk_radio_button_new_with_label_from_widget",
|
||||||
widget.member,
|
"NULL",
|
||||||
"\"" + widget.text + "\""
|
"\"" + widget.text + "\""
|
||||||
]);
|
]);
|
||||||
break;
|
break;
|
||||||
|
@ -151,10 +155,10 @@ var GTKExecCommand = function(command) {
|
||||||
|
|
||||||
line = _command.join(' ');
|
line = _command.join(' ');
|
||||||
|
|
||||||
console.info(line);
|
console.log(line);
|
||||||
|
|
||||||
GTKServer.StdIn.WriteLine(line);
|
GTKServer.StdIn.WriteLine(line);
|
||||||
return GTKServer.StdOut.ReadLine();
|
return GTKServer.StdOut.ReadLine();
|
||||||
};
|
};
|
||||||
|
|
||||||
// GTKInit
|
// GTKInit
|
||||||
|
@ -184,6 +188,18 @@ var Window = function() {
|
||||||
this.widgetType = "Window";
|
this.widgetType = "Window";
|
||||||
this.type = 0;
|
this.type = 0;
|
||||||
this.title = "WelsonJS GTK GUI Application";
|
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() {
|
this.show = function() {
|
||||||
return GTKExecCommand([
|
return GTKExecCommand([
|
||||||
"gtk_widget_show_all",
|
"gtk_widget_show_all",
|
||||||
|
@ -192,6 +208,19 @@ var Window = function() {
|
||||||
};
|
};
|
||||||
this.setWidgetType(this.widgetType);
|
this.setWidgetType(this.widgetType);
|
||||||
this.create();
|
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 = new GTKWidget();
|
||||||
Window.prototype.constructor = Window;
|
Window.prototype.constructor = Window;
|
||||||
|
@ -292,14 +321,45 @@ var RadioBox = function() {
|
||||||
|
|
||||||
this.widgetType = "RadioBox";
|
this.widgetType = "RadioBox";
|
||||||
this.text = "New 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);
|
this.setWidgetType(this.widgetType);
|
||||||
|
|
||||||
|
if (this.group.widgetID != "NULL") {
|
||||||
|
this.group.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
this.create();
|
this.create();
|
||||||
};
|
};
|
||||||
RadioBox.prototype = new GTKWidget();
|
RadioBox.prototype = new GTKWidget();
|
||||||
RadioBox.prototype.constructor = RadioBox;
|
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
|
// TextBox
|
||||||
var TextBox = function() {
|
var TextBox = function() {
|
||||||
GTKWidget.apply(this, arguments);
|
GTKWidget.apply(this, arguments);
|
||||||
|
@ -331,8 +391,6 @@ TextBox.prototype.constructor = TextBox;
|
||||||
var GTKWait = function(callback) {
|
var GTKWait = function(callback) {
|
||||||
var even;
|
var even;
|
||||||
|
|
||||||
GTKInit();
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
even = GTKExecCommand([
|
even = GTKExecCommand([
|
||||||
"gtk_server_callback",
|
"gtk_server_callback",
|
||||||
|
@ -357,10 +415,12 @@ exports.Table = Table;
|
||||||
exports.Button = Button;
|
exports.Button = Button;
|
||||||
exports.Entry = Entry;
|
exports.Entry = Entry;
|
||||||
exports.RadioBox = RadioBox;
|
exports.RadioBox = RadioBox;
|
||||||
|
exports.RadioGroup = RadioGroup;
|
||||||
exports.TextBox = TextBox;
|
exports.TextBox = TextBox;
|
||||||
|
|
||||||
exports.init = GTKInit;
|
exports.init = GTKInit;
|
||||||
exports.wait = GTKWait;
|
exports.wait = GTKWait;
|
||||||
|
exports.exit = GTKExit;
|
||||||
|
|
||||||
exports.VERSIONINFO = "GTKServer Module (gtk.js) version 0.1";
|
exports.VERSIONINFO = "GTKServer Module (gtk.js) version 0.1";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
|
|
|
@ -62,7 +62,7 @@ exports.run = function(cmd, fork) {
|
||||||
WSH.Run(c, 0, !fork);
|
WSH.Run(c, 0, !fork);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.createExecObject = function(cmd) {
|
exports.createProcess = function(cmd) {
|
||||||
var WSH = CreateObject("WScript.Shell");
|
var WSH = CreateObject("WScript.Shell");
|
||||||
return WSH.Exec(makeCommand(cmd));
|
return WSH.Exec(makeCommand(cmd));
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user