[15285] | 1 | README for guile-gtk preliminary version 0.17 |
---|
| 2 | ********************************************* |
---|
| 3 | |
---|
| 4 | This is some glue code to make Gtk accessible from Guile so it provides |
---|
| 5 | a convenient interface for Scheme programmers to develop visual |
---|
| 6 | applications. It can optionally integrate with GNOME via the Gnome-guile |
---|
| 7 | module. |
---|
| 8 | |
---|
| 9 | Guile-gtk was started by Marius Vollmer <mvo@zagadka.ping.de> and is |
---|
| 10 | currently mantained by Ariel Rios<jarios@usa.net> and other intrepid Guile |
---|
| 11 | hackers around the world. |
---|
| 12 | |
---|
| 13 | Guile-gtk is free software licensed under the GPL. |
---|
| 14 | |
---|
| 15 | New versions of this package will be available from |
---|
| 16 | |
---|
| 17 | http://www.ping.de/sites/zagadka/guile-gtk/ |
---|
| 18 | or in one of the mirrors: |
---|
| 19 | http://erin.netpedia.net/guile-gtk/ (USA) |
---|
| 20 | http://erin.linuxbox.com/guile-gtk/ (USA) |
---|
| 21 | http://linux.cem.itesm.mx/~jarios/guile-gtk/ (MEXICO) |
---|
| 22 | |
---|
| 23 | You can also get at the most recent development sources thru the Gnome |
---|
| 24 | CVS repository. Guile-gtk is contained in the gnome-guile module. |
---|
| 25 | See www.gnome.org for details. |
---|
| 26 | |
---|
| 27 | Guile-gtk was made with the idea of making it as generic as possible. |
---|
| 28 | As a result, it should be easy to extend it to new widgets and other Gtk |
---|
| 29 | extensions. |
---|
| 30 | |
---|
| 31 | It might even be possible to use some of this code for wrapping |
---|
| 32 | completely different C libraries, but that was not the goal. |
---|
| 33 | |
---|
| 34 | To somewhat unify the different high-level language bindings (such as |
---|
| 35 | the ones for Perl, Python, Objective C, maybe Java, etc.) Marius |
---|
| 36 | Vollmer tried to collect the salient bits of the Gtk API into a formal |
---|
| 37 | description. |
---|
| 38 | |
---|
| 39 | You should be able to generate large parts of the language specific |
---|
| 40 | glue code from it. Unfortunately, this formal description hasn't |
---|
| 41 | stabilized yet and we are currently more interested in completeness than |
---|
| 42 | in generality. |
---|
| 43 | |
---|
| 44 | Table of Contents |
---|
| 45 | |
---|
| 46 | - Acknowledgements |
---|
| 47 | - Bugs |
---|
| 48 | - Mailing List |
---|
| 49 | - Gtk versions |
---|
| 50 | - Related stuff |
---|
| 51 | - Package contents |
---|
| 52 | - Installing |
---|
| 53 | - Testing |
---|
| 54 | - Dynamic Linking |
---|
| 55 | - Wrapping Your Own Widgets |
---|
| 56 | - Composite Types and `call-by-reference' |
---|
| 57 | - Documentation |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | Acknowledgements |
---|
| 61 | ---------------- |
---|
| 62 | |
---|
| 63 | Many people have contributed to guile-gtk by now. Many thanks to all |
---|
| 64 | of them! Please refer to the ChangeLog for details. |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | Bugs |
---|
| 68 | ---- |
---|
| 69 | |
---|
| 70 | The main aim still is robustness, with an eye towards completeness. It |
---|
| 71 | should not be possible to crash your program from Scheme. Guile-gtk |
---|
| 72 | has to cope with anything. So if you find that your program crashes |
---|
| 73 | and you think it is due to a bug in your Scheme code, you have |
---|
| 74 | actually found a bug in guile-gtk or Gtk. |
---|
| 75 | |
---|
| 76 | Please report these bugs to the current maintainer,Ariel Rios, |
---|
| 77 | <jarios@usa.net> or to the mailing list <guile-gtk@sourceware.cygnus.com> |
---|
| 78 | |
---|
| 79 | Mailing List |
---|
| 80 | ------------ |
---|
| 81 | To subscribe to the list send mail to: |
---|
| 82 | <guile-gtk-subscribe@sourceware.cygnus.com> |
---|
| 83 | |
---|
| 84 | To post messages please write to: |
---|
| 85 | <guile-gtk@sourceware.cygnus.com> |
---|
| 86 | |
---|
| 87 | Gtk Versions |
---|
| 88 | ------------ |
---|
| 89 | |
---|
| 90 | [ Whoa, can anyone put this into more simple words? Seems like I can't |
---|
| 91 | see the forest for all the trees. ] |
---|
| 92 | |
---|
| 93 | There are two lines of Gtk versions in active development, modeled |
---|
| 94 | after the Linux kernel scheme, I think. One is the stable branch that |
---|
| 95 | will maintain binary compatability, and the other is the development |
---|
| 96 | branch, where new features are tried out. The stable branch has |
---|
| 97 | version numbers like 1.2.x; the development branch is labeled 1.3.x |
---|
| 98 | and the absolutely latest version is made available thru CVS. |
---|
| 99 | |
---|
| 100 | Guile-gtk can be built for both gtk-1.2 and gtk-1.3. It is possible |
---|
| 101 | to have these two versions of guile-gtk installed and in use |
---|
| 102 | simultanously, but the sources can only be configured for one of them |
---|
| 103 | at any one time. That is, when you want to switch between Gtk |
---|
| 104 | versions, be sure to make distclean and re-configure. |
---|
| 105 | |
---|
| 106 | The version number of gtk that guile-gtk has been built for will be |
---|
| 107 | reflected in the names of the installed programs and libraries. When |
---|
| 108 | you are building for gtk-1.2, for example, you will get guile-gtk-1.2 |
---|
| 109 | and libguilegtk-1.2. |
---|
| 110 | |
---|
| 111 | Likewise, the guile modules include the version of gtk in their |
---|
| 112 | prefix. The modules for gtk-1.2 are named `(gtk-1.2 <suffix>)', for |
---|
| 113 | example. When you want to use a specific version of gtk, you thus |
---|
| 114 | just have to use the right module names. You can't mix gtk-1.2 and |
---|
| 115 | gtk-1.3 modules and you will receive an error when you try to do so. |
---|
| 116 | |
---|
| 117 | This package will also install generic aliases for both the modules |
---|
| 118 | and the guile-gtk programs that refer to the gtk version that has been |
---|
| 119 | used while building it. In addition to "guile-gtk-1.2" or |
---|
| 120 | "guile-gtk-1.3" there will also be a symlink from plain "guile-gtk" to |
---|
| 121 | one of them. There will also be modules called `(gtk <suffix>)' that |
---|
| 122 | will dispatch to the `appropriate' version of gtk. What is |
---|
| 123 | `appropriate' is determined in two steps: when one of the specific |
---|
| 124 | modules has already been activated, the generic modules will just |
---|
| 125 | refer to them. When no specific gtk module has been used before, they |
---|
| 126 | will refer to the version of gtk that has been used for building the |
---|
| 127 | package. |
---|
| 128 | |
---|
| 129 | Both guile-gtk-1.2 and guile-gtk-1.3 will activate their specific |
---|
| 130 | versions of the gtk modules at startup. Thus, the generic modules |
---|
| 131 | `(gtk <suffix>)' always refer to gtk version used by the guile-gtk |
---|
| 132 | executable used to run them. |
---|
| 133 | |
---|
| 134 | Guile-gtk should always target the latest released versions of Gtk in |
---|
| 135 | both lines of development. There is no reason to use anything else |
---|
| 136 | than the latest `bug-fixing' gtk-1.2, and everybody who is using the |
---|
| 137 | unstable gtk-1.3 series can be expected to be up-to-date, right? |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | Related Stuff |
---|
| 141 | ------------- |
---|
| 142 | |
---|
| 143 | Jeff Dike is writing a layer of macros/functions on top of guile-gtk |
---|
| 144 | that makes it simpler and fairly uniform to create widgets within |
---|
| 145 | Guile. It is available here |
---|
| 146 | |
---|
| 147 | http://www.mv.com/ipusers/karaya/simple-gtk/simple-gtk.scm |
---|
| 148 | |
---|
| 149 | David Lutterkort is writing a tool that makes it easy to give command |
---|
| 150 | line programs with too many options a nice GUI. Available here |
---|
| 151 | |
---|
| 152 | http://www.cs.purdue.edu/homes/lutterdc/software/wickel.html |
---|
| 153 | |
---|
| 154 | There is also a list of applications developed using guile-gtk in: |
---|
| 155 | http://erin.netpedia.net/guile-gtk/apps.html |
---|
| 156 | |
---|
| 157 | Package Contents |
---|
| 158 | ---------------- |
---|
| 159 | |
---|
| 160 | guile-gtk.c |
---|
| 161 | guile-gtk.h Support for converting between Scheme types and Gtk types |
---|
| 162 | and the basic machine for making it all happen. |
---|
| 163 | |
---|
| 164 | gtk-support.c Some handwritten glue code. |
---|
| 165 | guile-compat.c Code to adapt to different versions of Guile. |
---|
| 166 | gtk-compat.c Code to adapt to different versions of Gtk. |
---|
| 167 | |
---|
| 168 | gdk-1.2.defs The formal description of the Gdk API for gtk-1.2. |
---|
| 169 | gtk-1.2.defs The formal description of the Gtk API for gtk-1.2. |
---|
| 170 | |
---|
| 171 | gdk-1.3.defs The formal description of the Gdk API for gtk-1.3. |
---|
| 172 | gtk-1.3.defs The formal description of the Gtk API for gtk-1.3. |
---|
| 173 | |
---|
| 174 | build-guile-gtk A Scheme program to generate much of the glue code. |
---|
| 175 | |
---|
| 176 | gtk/gtk.scm The Scheme part of the (gtk gtk) module. |
---|
| 177 | gtk/gdk.scm The Scheme part of the (gtk gdk) module. |
---|
| 178 | gtk/dynlink.scm Alternative dlopening that works better than the |
---|
| 179 | one in Guile. |
---|
| 180 | gtk/event-repl.scm |
---|
| 181 | Support for event driven read-eval-print loops. |
---|
| 182 | gtk-1.2/ Scheme modules for Gtk-1.2 |
---|
| 183 | gtk-1.3/ Scheme modules for Gtk-1.3 |
---|
| 184 | |
---|
| 185 | examples/ Some example programs. |
---|
| 186 | |
---|
| 187 | The rest is the usual configuration and building cruft. |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | Installing |
---|
| 191 | ---------- |
---|
| 192 | |
---|
| 193 | See INSTALL for generic installation instructions. |
---|
| 194 | |
---|
| 195 | This package will build a new program, "guile-gtk" that is a regular |
---|
| 196 | Guile interpreter with the Gtk support already linked in. It accepts |
---|
| 197 | the usual "guile" command line options and in addition to that, it |
---|
| 198 | also understands the Gtk options. |
---|
| 199 | |
---|
| 200 | On a few systems, this package is also able to arrange things so that |
---|
| 201 | you can just use the (gtk gtk) module from a vanilla "guile". In |
---|
| 202 | fact, "guile-gtk" is only a kludge until dynamic linking works well |
---|
| 203 | enough. |
---|
| 204 | |
---|
| 205 | The package will also install "build-guile-gtk", a program for |
---|
| 206 | generating glue code for arbitrary *.defs files. It can also produce |
---|
| 207 | new executables that are variants of guile-gtk, with a different set |
---|
| 208 | of glue code pre-linked. |
---|
| 209 | |
---|
| 210 | NOTE: This package installs its Scheme code in a location determined |
---|
| 211 | by the prefix given to the configure script. It does not pay |
---|
| 212 | attention to where your Guile is installed. When Guile and this |
---|
| 213 | package are installed under the same prefix, everything is fine. When |
---|
| 214 | you use a different prefix for this package, you need to make sure |
---|
| 215 | that Guile knows about this location. For example, when you install |
---|
| 216 | this package under /usr/local/stuff/guile-gtk, you may want to add |
---|
| 217 | GUILE_LOAD_PATH=/usr/local/stuff/guile-gtk/share/guile to your |
---|
| 218 | environment. Or you might want to make some symlinks. This package |
---|
| 219 | does not try to be clever about these issues, as there are too many |
---|
| 220 | variations and potential solutions. |
---|
| 221 | |
---|
| 222 | Testing |
---|
| 223 | ------- |
---|
| 224 | |
---|
| 225 | % cd examples/ |
---|
| 226 | % ../guile-gtk -s test-gtk.scm |
---|
| 227 | |
---|
| 228 | should pop up a familiar pile of buttons. Not every test has been |
---|
| 229 | implemented, tho. All unexpected behaviour is probably a bug and I |
---|
| 230 | would be glad if you would tell me about it. |
---|
| 231 | |
---|
| 232 | |
---|
| 233 | Dynamic Linking |
---|
| 234 | --------------- |
---|
| 235 | |
---|
| 236 | Guile-gtk uses its own approach to dynamic linking of compiled code |
---|
| 237 | modules. The experimental mechanism provided by Guile itself proved |
---|
| 238 | to be troublesome in the real world. |
---|
| 239 | |
---|
| 240 | As long as you build your shared libraries with libtool, and you have |
---|
| 241 | the dlopen function, everything should just work. At least in theory. |
---|
| 242 | Please refer to gtk/dynlink.scm for the implementation and gtk/gdk.scm |
---|
| 243 | for a simple application. |
---|
| 244 | |
---|
| 245 | The code in gtk/dynlink.scm parses the *.la files installed by libtool |
---|
| 246 | and uses the information contained therein to resolve inter-library |
---|
| 247 | dependencies on its own. When a library is requested that has no |
---|
| 248 | associated *.la file, it simply calls dlopen with a ".so" suffix. |
---|
| 249 | When this ".so" library can't be opened it is simply ignored (with a |
---|
| 250 | warning). |
---|
| 251 | |
---|
| 252 | So the rule is: you must make sure that you have correct inter-library |
---|
| 253 | dependencies. Either use libtool, which will put these dependencies |
---|
| 254 | into its *.la files where we can find them; or build your shared |
---|
| 255 | libraries `by hand', so that dlopen can resolve the dependencies. In |
---|
| 256 | either case, do not include static libraries in the inter-library |
---|
| 257 | dependencies. |
---|
| 258 | |
---|
| 259 | As an exception, you do not need to include the Guile libraries |
---|
| 260 | (-lguile, -lqthreads, etc) in your dependencies, because they are |
---|
| 261 | always there. You *do* need -lguilegtk and the Gtk libraries, tho. |
---|
| 262 | |
---|
| 263 | We need to use the RTLD_GLOBAL flag to make all this happen, but |
---|
| 264 | unfortunately, Guile calls dlopen without this flag. This is why we |
---|
| 265 | have a very simple libguiledlopenhelper. |
---|
| 266 | |
---|
| 267 | The code in gtk/dynlink.scm tries to emulate the way the linker |
---|
| 268 | searches for libraries: First, each directory in LD_LIBRARY_PATH is |
---|
| 269 | tried, then "/usr/local/lib", "/usr/lib", "/lib", in that order. |
---|
| 270 | |
---|
| 271 | I expect things to change for the better in the future, of course, but |
---|
| 272 | shared libraries and dlopening are a very effective time-sink, it |
---|
| 273 | seems. |
---|
| 274 | |
---|
| 275 | UPDATE: when configure detects a recent version of libtool that looks |
---|
| 276 | like it can handle inter-library dependencies on its own, |
---|
| 277 | gtk/dynlink.scm just opens the library and does not try to be clever |
---|
| 278 | about *.la files. Libtool 1.2e works for me in this way. |
---|
| 279 | |
---|
| 280 | |
---|
| 281 | Wrapping Your Own Widgets |
---|
| 282 | ------------------------- |
---|
| 283 | |
---|
| 284 | There is a complete autoconfed/automade example for this. |
---|
| 285 | |
---|
| 286 | After installing the guile-gtk package, change to the examples/ |
---|
| 287 | directory: |
---|
| 288 | |
---|
| 289 | % cd examples |
---|
| 290 | % ./configure |
---|
| 291 | % make |
---|
| 292 | |
---|
| 293 | Again: you need to have guile-gtk installed for this to work! |
---|
| 294 | |
---|
| 295 | Now you should have a new executable `guile-foo' that has glue code |
---|
| 296 | for the function `foo-new' in the `(gtk foo)' module. You can test it |
---|
| 297 | thus: |
---|
| 298 | |
---|
| 299 | % ./guile-foo -s test-foo.scm |
---|
| 300 | |
---|
| 301 | Here is the general procedure: |
---|
| 302 | |
---|
| 303 | When you have some Gtk widgets that are not described in gtk.defs or |
---|
| 304 | gdk.defs, you can use build-guile-gtk to automatically generate glue |
---|
| 305 | code for them. Here is how to wrap the hypothetical GtkFoo widget and |
---|
| 306 | its related function gtk-foo-new. They are assumed to live in gtkfoo.h |
---|
| 307 | and libfoo. |
---|
| 308 | |
---|
| 309 | - Write the foo.defs file |
---|
| 310 | |
---|
| 311 | ;; We use the types defined in gtk-1.2.defs |
---|
| 312 | |
---|
| 313 | (import "gtk-1.2.defs") |
---|
| 314 | |
---|
| 315 | (define-object GtkFoo (GtkWidget)) |
---|
| 316 | |
---|
| 317 | (define-func gtk_foo_new |
---|
| 318 | GtkFoo |
---|
| 319 | ()) |
---|
| 320 | |
---|
| 321 | (options |
---|
| 322 | ;; Includes needed to compile code that uses GtkFoo. |
---|
| 323 | (includes "#include <gtkfoo.h>") |
---|
| 324 | ;; The name of the generated initialization function. |
---|
| 325 | (init-func "foo_init_glue") |
---|
| 326 | ;; Libraries needed to link. libguilefoo will contain |
---|
| 327 | ;; the glue code and libfoo contains the widget itself. |
---|
| 328 | (libs "-lguilefoo -lfoo")) |
---|
| 329 | |
---|
| 330 | - Write the foo.scm file |
---|
| 331 | |
---|
| 332 | (define-module (gtk foo) |
---|
| 333 | :use-module (gtk dynlink)) |
---|
| 334 | |
---|
| 335 | ;; Call the init function, either using a pre-linked -lguilefoo or |
---|
| 336 | ;; dynamically linking it. |
---|
| 337 | (merge-compiled-code "foo_init_glue" "libguilefoo") |
---|
| 338 | |
---|
| 339 | - Generate the glue code |
---|
| 340 | |
---|
| 341 | % build-guile-gtk glue foo.defs >foo-glue.c |
---|
| 342 | |
---|
| 343 | - Compile the glue code into a shared library, using libtool |
---|
| 344 | |
---|
| 345 | [This will be simplified and then explained. Right now, keep in |
---|
| 346 | mind to use gtk-config and build-guile to get all necessary flags and |
---|
| 347 | libraries.] |
---|
| 348 | |
---|
| 349 | % libtool --mode=link ... -o libguilefoo.la ... |
---|
| 350 | |
---|
| 351 | - Install the shared library, again using libtool. |
---|
| 352 | |
---|
| 353 | % libtool --mode=install cp libguilefoo.la <exec_prefix>/lib/ |
---|
| 354 | |
---|
| 355 | - Install the foo.scm file |
---|
| 356 | |
---|
| 357 | % cp foo.scm <prefix>/share/guile/gtk/foo.scm |
---|
| 358 | |
---|
| 359 | - Install the *.defs files for other people to use. |
---|
| 360 | |
---|
| 361 | % cp foo.defs foo.defs.guile <prefix>/share/guile-gtk/ |
---|
| 362 | |
---|
| 363 | Now you should be able to just (use-modules (gtk foo)). When dynamic |
---|
| 364 | linking does not work for you, you might want to try |
---|
| 365 | |
---|
| 366 | % build-guile-gtk link foo.defs -o guile-foo |
---|
| 367 | |
---|
| 368 | This will link a new executable named guile-foo that will have the |
---|
| 369 | libguilefoo library pre-linked into it so that you do not need |
---|
| 370 | dynamic-link. This will work with any number of *.defs files. |
---|
| 371 | |
---|
| 372 | |
---|
| 373 | Composite Types and `call-by-reference' |
---|
| 374 | --------------------------------------- |
---|
| 375 | |
---|
| 376 | Guile-gtk has (still experimental) support for composite types like |
---|
| 377 | lists and vectors. On the Gtk+ side, the types GSList (singly linked |
---|
| 378 | list), GList (doubly linked list), and counted and fixed length |
---|
| 379 | vectors are supported. On the Scheme side, you can use Scheme lists |
---|
| 380 | and Scheme vectors. You can mix these types freely. That is you can |
---|
| 381 | use a list on the Scheme side to represent a vector on the Gtk+ side, |
---|
| 382 | and vice versa. |
---|
| 383 | |
---|
| 384 | Composite types have modes associated with them. They can be `in', |
---|
| 385 | `out', or `inout'. When a composite type is marked with a `in' mode, |
---|
| 386 | the Gtk+ side is not allowed to make changes to the contents of the |
---|
| 387 | composite. When it is `out', it must initialize the contents before |
---|
| 388 | it returns and is not allowed to read it prior to initialization. |
---|
| 389 | Consequently, mode `inout' indicates that the Gtk+ side may both read |
---|
| 390 | and write the composite freely, and that the contents has been |
---|
| 391 | initialized by the caller. On the Scheme side, mode `out' turns off |
---|
| 392 | type checking for the contents of composites and the initial values of |
---|
| 393 | the composite passed to Gtk+ will be undefined. |
---|
| 394 | |
---|
| 395 | The default mode is `in'. |
---|
| 396 | |
---|
| 397 | The available variations are: |
---|
| 398 | |
---|
| 399 | [ *.defs file syntax ] [ C side function arguments ] |
---|
| 400 | [ Comment ] |
---|
| 401 | |
---|
| 402 | (slist <type> [<mode>]) GSList *lst |
---|
| 403 | For singly linked lists. Scheme owns the memory of the list nodes. |
---|
| 404 | |
---|
| 405 | (list <type> [<mode>]) GList *lst |
---|
| 406 | For doubly linked lists. Scheme owns the memory of the list nodes. |
---|
| 407 | |
---|
| 408 | (cvec <type> [<mode>]) int len, <type>* vec |
---|
| 409 | For counted vectors. The length of the Scheme composite is passed |
---|
| 410 | to the Gtk+ function. Scheme owns the memory of the vector. |
---|
| 411 | |
---|
| 412 | (cvecr <type> [<mode>]) <type>* vec, int len |
---|
| 413 | For counted vectors, reverse order of arguments. Scheme owns the |
---|
| 414 | memory of the vector. |
---|
| 415 | |
---|
| 416 | (fvec <type> <len> [<mode>]) <type>* vec |
---|
| 417 | For fixed length vectors. The Scheme composite must be of length <len>. |
---|
| 418 | Scheme owns the memory of the vector. |
---|
| 419 | |
---|
| 420 | (ret <type>) <type>* vec |
---|
| 421 | Abbreviation for (fvec <type> 1 out) |
---|
| 422 | |
---|
| 423 | These composite types are also intended to be used for |
---|
| 424 | call-by-reference arguments. Neither Scheme nor C really has these |
---|
| 425 | call-by-reference arguments, so guile-gtk wont either. In C, you |
---|
| 426 | would pass a pointer to the desired object; in Scheme you use a |
---|
| 427 | one-element list or a vector of length one. For guile-gtk, these |
---|
| 428 | types are modelled with a `fvec' composite type of length one and mode |
---|
| 429 | out, or equivalently but shorter with the `ret' type. |
---|
| 430 | |
---|
| 431 | For example, when you have a Gtk+ function with a prototype like |
---|
| 432 | |
---|
| 433 | void gtk_foo (char **strptr); |
---|
| 434 | |
---|
| 435 | that deposits some string in *STRPTR (whose memory should be taken |
---|
| 436 | over by the caller), you can wrap it like this: |
---|
| 437 | |
---|
| 438 | (define-func gtk_foo |
---|
| 439 | none |
---|
| 440 | ((ret string) strptr)) |
---|
| 441 | |
---|
| 442 | Usage is a little cumbersome from Scheme. This code snippet |
---|
| 443 | |
---|
| 444 | (let ((strptr (list #f))) |
---|
| 445 | (gtk-foo strptr) |
---|
| 446 | (car strptr)) |
---|
| 447 | |
---|
| 448 | would yield the returned string. |
---|
| 449 | |
---|
| 450 | |
---|
| 451 | Documentation |
---|
| 452 | ------------- |
---|
| 453 | |
---|
| 454 | Nothing available yet, but the Scheme interface to Gtk is very similar |
---|
| 455 | to the C one. Almost all functions take the same arguments as their C |
---|
| 456 | counterparts. Exceptions are: |
---|
| 457 | |
---|
| 458 | - To access the Gtk functions, you need to use the `(gtk gtk)' |
---|
| 459 | module. You can do this with |
---|
| 460 | |
---|
| 461 | (use-modules (gtk gtk)) |
---|
| 462 | |
---|
| 463 | or |
---|
| 464 | |
---|
| 465 | (define-module (your module) |
---|
| 466 | :use-modules (gtk gtk)) |
---|
| 467 | |
---|
| 468 | Likewise, you need to use the `(gtk gdk)' module if you want to use |
---|
| 469 | functions from Gdk. |
---|
| 470 | |
---|
| 471 | - Booleans are expressed with Scheme's real boolean values #f and #t. |
---|
| 472 | |
---|
| 473 | - Enumerations are expressed with symbols. For example |
---|
| 474 | GTK_WINDOW_TOPLEVEL is written as 'toplevel. The symbols should be |
---|
| 475 | easy to guess from their C counterparts, but they are not completely |
---|
| 476 | systematic. See gtk.defs for the definite details. |
---|
| 477 | |
---|
| 478 | - Flags (or bitmasks) are expressed as lists of symbols. For example |
---|
| 479 | GTK_EXPAND|GTK_FILL is '(expand fill). |
---|
| 480 | |
---|
| 481 | - Callbacks don't take a client-data argument, so you don't have to |
---|
| 482 | specify one to gtk_signal_connect, or gtk_timeout_add, etc. |
---|
| 483 | |
---|
| 484 | - Signal handlers don't get the Object as their first argument. In my |
---|
| 485 | view, this would be more often annoying than helpful. |
---|
| 486 | |
---|
| 487 | - NULL pointers are expressed as #f. |
---|
| 488 | |
---|
| 489 | - Some parameters are optional and get a default value when left |
---|
| 490 | unspecified. |
---|
| 491 | |
---|
| 492 | - Each type that is derived from GtkObject has an associated predicate |
---|
| 493 | function to test whether a Scheme value is of that type. The |
---|
| 494 | predicate for GtkObject is called `gtk-object?', the one for |
---|
| 495 | GtkRadioButton `gtk-radio-button?', etc. |
---|
| 496 | |
---|
| 497 | - gtk-radio-button-new and gtk-radio-button-new-with-label don't take |
---|
| 498 | a list as their group argument but a GtkWidget whose group is used |
---|
| 499 | instead. |
---|
| 500 | |
---|
| 501 | - Likewise for gtk-radio-menu-item. |
---|
| 502 | |
---|
| 503 | - Colors and fonts can be specified with strings, like "red" or |
---|
| 504 | "fixed". If you want to convert from these strings to the real |
---|
| 505 | values (for efficiency reasons, say) you can use the functions |
---|
| 506 | `gdk-color-intern' and `gdk-font-intern'. |
---|
| 507 | |
---|
| 508 | - It might be that your code is loaded into an application that |
---|
| 509 | already has an event loop running (or will run one after |
---|
| 510 | initialization is complete). You should then restrain from calling |
---|
| 511 | `gtk-main' yourself (except maybe for modal dialog boxes) and you |
---|
| 512 | should not terminate the program. |
---|
| 513 | |
---|
| 514 | You can use the function `gtk-standalone?' to find out whether your |
---|
| 515 | code is `standalone', i.e. whether you should call `gtk-main' |
---|
| 516 | yourself. |
---|
| 517 | |
---|
| 518 | For convenience you can also use |
---|
| 519 | |
---|
| 520 | gtk-standalone-main TOPLEVEL |
---|
| 521 | |
---|
| 522 | This will arrange things so that the program is terminated with |
---|
| 523 | `gtk-exit' when the TOPLEVEL widget is destroyed and will call |
---|
| 524 | `gtk-main'. All these things will only happen when |
---|
| 525 | `gtk-standalone?' returns true. |
---|
| 526 | |
---|
| 527 | |
---|
| 528 | And all the things I forgot about. Be sure to read the NEWS file as |
---|
| 529 | it is currently the only place that documents most details. |
---|
| 530 | "examples/calc.scm" is quite heavily commented, but does not explain |
---|
| 531 | Gtk programming. It is more an example about extensibility. |
---|
| 532 | |
---|
| 533 | Have fun! |
---|
| 534 | |
---|
| 535 | Marius Vollmer |
---|
| 536 | Ariel Rios |
---|