⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtk-server_manual.html

📁 gtk_server的源代码
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">  <title>GTK-server Quickstart Manual</title>  <meta content="Peter van Eerten" name="author"></head><body><h1>The GTK-server Quickstart Manual.</h1><br><hr style="width: 100%; height: 2px;"><h2>1. The GTK-server binary.</h2>This binary tries to open the GTK library on your system. It will lookfor a GTK library mentioned in the 'gtk-server.cfg' file. For Windows theGTK DLL is provided in a separate installation package.<br><br>Both the Linux version and the Windows version of the GTK-server supportcommunication by a 2-waypipe, named pipe, TCP and UDP. In case of a 2-way pipe, the GTK-server must be started with the argument 'stdin'. In case of a named pipe, the GTK-servermust be started with the argument 'fifo', after which the name of the pipemust be mentioned. In Windows, the name of the named pipe can be omitted;the GTK-server will setup 2 independent pipes, with the predefined names "\\.\pipe\out" and "\\.\pipe\in". Finally, to enable TCP or UDP communication, the argument must be of the format '&lt;-tcp=ipaddress:port&gt;' or '&lt;-udp=ipaddress:port&gt;'.<br><br>Only the Linux version in TCP mode supports multiple connections to oneserver. To enable this feature, start the GTK-server with the argument'&lt;-tcp=ipaddress:port:max&gt;', where 'max' determines the maximum amountof clients which may connect. If the 'max' argument is omitted, onlyone program can connect. In case of Win32 however, the 'max' argumentcannot be used; here it is always necessary to start a separate serverfor each client program.<br><br>If the last argument is '-log=file.txt', the GTK-server will produce a logfilewith the title 'file.txt'. Any name can be used here, of course. This logfile willcontain the strings which were received by the GTK-server, and the responses of theGTK-server to those strings. This is how your script can be checked forGTK errors.<br><br><br><hr style="width: 100%; height: 2px;"><h2>2. The GTK-server configfile.</h2>In the config file you have to describe the GTK function you want toinvoke. Entry's starting with a '#' are skipped. You can use the '#' toput comments in your config file. Every GTK function has specificproperties. Let's take a look at an example:<br><br><small><b>FUNCTION_NAME = gtk_toggle_button_new_with_label, clicked,WIDGET, 1, STRING</b></small><br><br>In this line, the GTK function "gtk_toggle_button_new_with_label" isdescribed. (To find out what the properties are for GTK functions,consult the GTK documentation at <a href="http://www.gtk.org/">http://www.gtk.org</a>.)The next argument describes the type of callback for this widget. Acallback is a signal to which the GTK library has to listen. In thiscase, the toggle button by default will respond to a 'clicked' signal. This signaloccurs when you click with your mouse on this button. Remember, exceptfor the names of the GTK-functions and signals you have to use capitals here!<br><br>After the callback signal you have to enter which value is expectedback from the GTK function (the returnvalue). In the example above, awidget will be returned to the script. Other returnvalues are 'STRING','BOOL', 'LONG', 'FLOAT' and 'NONE'.<br><br>After that, you have to specify the amount of arguments needed for thisGTK function. In our example only one argument is expected. The type ofargument here is 'STRING'. Other argument types are 'LONG', 'WIDGET','FLOAT', 'DOUBLE', 'BASE64' and 'NULL'. So for each argument you have to declare the type -in the right order! In case of 3 arguments take care that the order youmention is the same as the real order for the GTK-function.<br><br><br><hr style="width: 100%; height: 2px;"><h2>3. Catching callback signals.</h2>To catch a callback signal from a widget, an internal GTK-serverfunction must be used. The name of the function is'gtk_server_callback'. This function takes only one argument, a '0', '1' or a '2'.Instead of the '1' also the word 'wait' can be used, and instead of '2' the word'update' can be used. The function checks if the userinterface has received acallback signal.<br><br>If the argument to 'gtk_server_callback' is '2' then the GTK-serverwill update all events waiting in the queue and check if there is a callback waiting.With this argument, 'gtk_server_callback' returns immediately. If there is no callback,a '0' is returned, else the widgetID is returned. If the argument is '1'the GTK-server will update all events in the queue and wait until an event hasoccured. Only then 'gtk_server_callback' returns, with the widgetID on which the signaltook place. Finally, if the argument is '0' the function will not update the userinterface,but it will only check on an event and return immediately. In this case, the client programhas to take care of updating the userinterface by itself - this is sometimes necessarywhen it needs to wait for other events (like network events) instead of GUI events.<br><br>So, if it must be checked in KSH whether or not a toggle button has emitted a'click' signal, this can be stated as:<br><br><small><b>print -p "gtk_server_callback wait"; read -p EVENT<br>if [ EVENT -eq BUTTON ]<br>then<br>&nbsp;&nbsp;&nbsp;&nbsp;print "Mouse button pressed!"<br>fi<br></b></small><br>In the above code, the call will return the widget ID in case an event hasoccured. Else it will wait. The result will be put into the variable "EVENT".This result can be compared with existing widget ID's to take appropriateaction.<br><br>Apart from the default callback signal in the 'gtk-server.cfg' file, it is alsopossible to connect a signal manually to a widget. For this the function 'gtk_server_connect'can be used. This function takes 3 arguments: the widget ID, the signal name anda string to identify the signal. For example:<br><br><small><b>print -p "gtk_server_connect BUTTON enter hello"; read -p RESULT<br>print -p "gtk_server_callback wait"; read -p EVENT<br>if [ EVENT -eq "hello" ]<br>then<br>&nbsp;&nbsp;&nbsp;&nbsp;print "Mouse entered button region!"<br>fi<br></b></small><br>Please keep in mind that the GTK-server always returns it's data as a string.In order to use the returned result as a number, some languages (like Scriptbasic)need a typecast.<br><br><br><hr style="width: 100%; height: 2px;"><h2>4. Using Glade XML files.</h2>If you have designed a user interface with Glade, the GTK-server can read the resultingXML file and realize the interface. First point to the location of the XML file:<br><br><small><b>print -p "glade_xml_new mygui.glade $NULL $NULL"; read -p XML<br></b></small><br>Then query Glade for the widgetID which can be used in the mainloop. The names of all widgetsare mentioned in the Glade XML file:<br><br><small><b>print -p "glade_xml_get_widget $XML nameofwidget"; read -p WIDGET<br></b></small><br>From here you can setup your program in a regular way, using the widgetID to connect signals andcatch them in your mainloop.<br><br><hr style="width: 100%; height: 2px;"><br>(c) December 2003 - December 2008, Peter van Eerten&nbsp; -&nbsp;http://www.gtk-server.org/<br><br><hr style="width: 100%; height: 2px;"><br></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -