The list of currently supported languages is impressive,How does it work? The GTK-server is a standalone binary, which is able to communicate by a 2-way pipe, a named pipe or by a TCP/UDP port. The script invokes this binary, sets up a pipe or a TCP/UDP connection and prints the GTK call in plain text to the pipe or socket. The GTK-server then sends information back which can be used in the program or script.
Next to this binary there is also a configuration file, in which the user of the GTK-server has to describe the API call he wants to invoke. In the configfile every API call must be defined; the type of callback signal must be set, the return value, the number of arguments and the type of these arguments. If you are not familiar with the GTK API, you can download a default configfile from this place.
Currently the following languages have been tested successfully with the GTK-server:
This seems simple enough to work with. A simple rewrite of:
http://www.gtk-server.org/demo-stdin.py.txt
I've shown below:
import Axon
from Kamaelia.File.UnixProcess import UnixProcess
from Kamaelia.Chassis.Graphline import Graphline
class GTKServerClient(Axon.ThreadedComponent.threadedcomponent):
def gtk(self, value, outbox="outbox", inbox="inbox"):
self.send(value, outbox)
while not self.dataReady("inbox"):
self.pause(0.1)
result = self.recv(inbox)
return result
def main(self):
self.gtk("gtk_init NULL NULL")
win = self.gtk("gtk_window_new 0")
self.gtk("gtk_window_set_title " + win + " \"Python Demo
program with STDIN\"")
self.gtk("gtk_widget_set_usize " + win + " 450 400")
table = self.gtk("gtk_table_new 50 50 1")
self.gtk("gtk_container_add " + win + " " + table)
button = self.gtk("gtk_button_new_with_label Exit")
self.gtk("gtk_table_attach_defaults " + table + " " + button +
" 41 49 45 49")
entry = self.gtk("gtk_entry_new")
self.gtk("gtk_table_attach_defaults " + table + " " + entry +
" 1 40 45 49")
text = self.gtk("gtk_text_new NULL NULL")
self.gtk("gtk_table_attach_defaults " + table + " " + text + "
1 49 8 44")
radio1 = self.gtk
("gtk_radio_button_new_with_label_from_widget NULL Yes")
self.gtk ("gtk_table_attach_defaults " + table + " " + radio1
+ " 1 10 1 4")
radio2 = self.gtk
("gtk_radio_button_new_with_label_from_widget " + radio1 + " No")
self.gtk ("gtk_table_attach_defaults " + table + " " + radio2
+ " 1 10 4 7")
self.gtk ("gtk_widget_show_all " + win)
self.gtk ("gtk_widget_grab_focus " + entry)
# Initialize
event = 0
# Mainloop
while event != button and event != win:
event = self.gtk ("gtk_server_callback WAIT")
if event == entry:
tmp = self.gtk ("gtk_entry_get_text " + entry)
self.gtk ("gtk_text_insert " + text + " NULL
NULL NULL " + tmp + " -1")
self.gtk ("gtk_entry_set_text " + entry + " \" \"")
# Exit GTK-server
self.gtk ("gtk_exit 0")
Graphline (
GTKLIB = UnixProcess('gtk-server stdin'),
APP = GTKServerClient(),
linkages = {
("GTKLIB", "outbox") : ("APP" , "inbox"),
("APP", "outbox") : ("GTKLIB" , "inbox"),
}
).run()
The list of languages would be quite impressive BTW, it appears to be
just a programme that is controlled either via a simple shell like interface
over stdin, tcp or UDP. (Don't get me wrong, it's a nice little app!)
However it's worth mentioning that you could also do this:
Pipeline (
ConsoleReader(">>> "),
UnixProcess('gtk-server stdin'),
ConsoleEchoer(),
).run()
And run that & interact with it manually as follows:
~> ./kamaelia-gtk-server.py
>>> gtk_init NULL NULL
>>> ok
gtk_window_new 0
>>> 134870432
gtk_window_set_title 134870432 "Python Demo program with STDIN"
>>> ok
gtk_widget_set_usize 134870432 450 400
>>> ok
gtk_table_new 50 50 1
>>> 134886848
gtk_container_add 134870432 134886848
>>> ok
gtk_button_new_with_label Exit
>>> 135283888
gtk_table_attach_defaults 134886848 135283888 41 49 45 49
>>> ok
gtk_entry_new
>>> 135283304
gtk_table_attach_defaults 134886848 135283304 1 40 45 49
>>> ok
gtk_text_new NULL NULL
>>> 135331488
gtk_table_attach_defaults 134886848 135331488 1 49 8 44
>>> ok
gtk_radio_button_new_with_label_from_widget NULL Yes
>>> 135373704
gtk_table_attach_defaults 134886848 135373704 1 10 1 4
>>> ok
gtk_radio_button_new_with_label_from_widget 135373704 No
>>> 135326168
gtk_table_attach_defaults 134886848 135326168 1 10 4 7
>>> ok
gtk_widget_show_all 134870432
>>> ok
gtk_widget_grab_focus 135283304
>>> ok
gtk_server_callback WAIT
>>>
(at this point in time the window appears BTW, showing this has worked)
I doubt much of the code would change dramatically for the TCP based
code, nor the UDP.
Michael.
On 1/6/07, M. David Peterson <xmlh...@gmail.com> wrote:
> via Peter Fisk (thanks, Peter!),
>
> demoscript on this site).Seems to me that this could be a nice marriage
Pipeline (
ConsoleReader(">>> "),
UnixProcess('gtk-server stdin'),
ConsoleEchoer(),
).run()