Debian Codegraph @

HOWTOs/Quad-GTK.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
5 <head>
6 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
7 <meta name="generator" content="AsciiDoc 10.1.2" />
8 <title>The GNU APL <strong>⎕GTK</strong> Cookbook</title>
9 <style type="text/css">
10 /* Shared CSS for AsciiDoc xhtml11 and html5 backends */
11
12 /* Default font. */
13 body {
14 font-family: Georgia,serif;
15 }
16
17 /* Title font. */
18 h1, h2, h3, h4, h5, h6,
19 div.title, caption.title,
20 thead, p.table.header,
21 #toctitle,
22 #author, #revnumber, #revdate, #revremark,
23 #footer {
24 font-family: Arial,Helvetica,sans-serif;
25 }
26
27 body {
28 margin: 1em 5% 1em 5%;
29 }
30
31 a {
32 color: blue;
33 text-decoration: underline;
34 }
35 a:visited {
36 color: fuchsia;
37 }
38
39 em {
40 font-style: italic;
41 color: navy;
42 }
43
44 strong {
45 font-weight: bold;
46 color: #083194;
47 }
48
49 h1, h2, h3, h4, h5, h6 {
50 color: #527bbd;
51 margin-top: 1.2em;
52 margin-bottom: 0.5em;
53 line-height: 1.3;
54 }
55
56 h1, h2, h3 {
57 border-bottom: 2px solid silver;
58 }
59 h2 {
60 padding-top: 0.5em;
61 }
62 h3 {
63 float: left;
64 }
65 h3 + * {
66 clear: left;
67 }
68 h5 {
69 font-size: 1.0em;
70 }
71
72 div.sectionbody {
73 margin-left: 0;
74 }
75
76 hr {
77 border: 1px solid silver;
78 }
79
80 p {
81 margin-top: 0.5em;
82 margin-bottom: 0.5em;
83 }
84
85 ul, ol, li > p {
86 margin-top: 0;
87 }
88 ul > li { color: #aaa; }
89 ul > li > * { color: black; }
90
91 .monospaced, code, pre {
92 font-family: "Courier New", Courier, monospace;
93 font-size: inherit;
94 color: navy;
95 padding: 0;
96 margin: 0;
97 }
98 pre {
99 white-space: pre-wrap;
100 }
101
102 #author {
103 color: #527bbd;
104 font-weight: bold;
105 font-size: 1.1em;
106 }
107 #email {
108 }
109 #revnumber, #revdate, #revremark {
110 }
111
112 #footer {
113 font-size: small;
114 border-top: 2px solid silver;
115 padding-top: 0.5em;
116 margin-top: 4.0em;
117 }
118 #footer-text {
119 float: left;
120 padding-bottom: 0.5em;
121 }
122 #footer-badges {
123 float: right;
124 padding-bottom: 0.5em;
125 }
126
127 #preamble {
128 margin-top: 1.5em;
129 margin-bottom: 1.5em;
130 }
131 div.imageblock, div.exampleblock, div.verseblock,
132 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
133 div.admonitionblock {
134 margin-top: 1.0em;
135 margin-bottom: 1.5em;
136 }
137 div.admonitionblock {
138 margin-top: 2.0em;
139 margin-bottom: 2.0em;
140 margin-right: 10%;
141 color: #606060;
142 }
143
144 div.content { /* Block element content. */
145 padding: 0;
146 }
147
148 /* Block element titles. */
149 div.title, caption.title {
150 color: #527bbd;
151 font-weight: bold;
152 text-align: left;
153 margin-top: 1.0em;
154 margin-bottom: 0.5em;
155 }
156 div.title + * {
157 margin-top: 0;
158 }
159
160 td div.title:first-child {
161 margin-top: 0.0em;
162 }
163 div.content div.title:first-child {
164 margin-top: 0.0em;
165 }
166 div.content + div.title {
167 margin-top: 0.0em;
168 }
169
170 div.sidebarblock > div.content {
171 background: #ffffee;
172 border: 1px solid #dddddd;
173 border-left: 4px solid #f0f0f0;
174 padding: 0.5em;
175 }
176
177 div.listingblock > div.content {
178 border: 1px solid #dddddd;
179 border-left: 5px solid #f0f0f0;
180 background: #f8f8f8;
181 padding: 0.5em;
182 }
183
184 div.quoteblock, div.verseblock {
185 padding-left: 1.0em;
186 margin-left: 1.0em;
187 margin-right: 10%;
188 border-left: 5px solid #f0f0f0;
189 color: #888;
190 }
191
192 div.quoteblock > div.attribution {
193 padding-top: 0.5em;
194 text-align: right;
195 }
196
197 div.verseblock > pre.content {
198 font-family: inherit;
199 font-size: inherit;
200 }
201 div.verseblock > div.attribution {
202 padding-top: 0.75em;
203 text-align: left;
204 }
205 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
206 div.verseblock + div.attribution {
207 text-align: left;
208 }
209
210 div.admonitionblock .icon {
211 vertical-align: top;
212 font-size: 1.1em;
213 font-weight: bold;
214 text-decoration: underline;
215 color: #527bbd;
216 padding-right: 0.5em;
217 }
218 div.admonitionblock td.content {
219 padding-left: 0.5em;
220 border-left: 3px solid #dddddd;
221 }
222
223 div.exampleblock > div.content {
224 border-left: 3px solid #dddddd;
225 padding-left: 0.5em;
226 }
227
228 div.imageblock div.content { padding-left: 0; }
229 span.image img { border-style: none; vertical-align: text-bottom; }
230 a.image:visited { color: white; }
231
232 dl {
233 margin-top: 0.8em;
234 margin-bottom: 0.8em;
235 }
236 dt {
237 margin-top: 0.5em;
238 margin-bottom: 0;
239 font-style: normal;
240 color: navy;
241 }
242 dd > *:first-child {
243 margin-top: 0.1em;
244 }
245
246 ul, ol {
247 list-style-position: outside;
248 }
249 ol.arabic {
250 list-style-type: decimal;
251 }
252 ol.loweralpha {
253 list-style-type: lower-alpha;
254 }
255 ol.upperalpha {
256 list-style-type: upper-alpha;
257 }
258 ol.lowerroman {
259 list-style-type: lower-roman;
260 }
261 ol.upperroman {
262 list-style-type: upper-roman;
263 }
264
265 div.compact ul, div.compact ol,
266 div.compact p, div.compact p,
267 div.compact div, div.compact div {
268 margin-top: 0.1em;
269 margin-bottom: 0.1em;
270 }
271
272 tfoot {
273 font-weight: bold;
274 }
275 td > div.verse {
276 white-space: pre;
277 }
278
279 div.hdlist {
280 margin-top: 0.8em;
281 margin-bottom: 0.8em;
282 }
283 div.hdlist tr {
284 padding-bottom: 15px;
285 }
286 dt.hdlist1.strong, td.hdlist1.strong {
287 font-weight: bold;
288 }
289 td.hdlist1 {
290 vertical-align: top;
291 font-style: normal;
292 padding-right: 0.8em;
293 color: navy;
294 }
295 td.hdlist2 {
296 vertical-align: top;
297 }
298 div.hdlist.compact tr {
299 margin: 0;
300 padding-bottom: 0;
301 }
302
303 .comment {
304 background: yellow;
305 }
306
307 .footnote, .footnoteref {
308 font-size: 0.8em;
309 }
310
311 span.footnote, span.footnoteref {
312 vertical-align: super;
313 }
314
315 #footnotes {
316 margin: 20px 0 20px 0;
317 padding: 7px 0 0 0;
318 }
319
320 #footnotes div.footnote {
321 margin: 0 0 5px 0;
322 }
323
324 #footnotes hr {
325 border: none;
326 border-top: 1px solid silver;
327 height: 1px;
328 text-align: left;
329 margin-left: 0;
330 width: 20%;
331 min-width: 100px;
332 }
333
334 div.colist td {
335 padding-right: 0.5em;
336 padding-bottom: 0.3em;
337 vertical-align: top;
338 }
339 div.colist td img {
340 margin-top: 0.3em;
341 }
342
343 @media print {
344 #footer-badges { display: none; }
345 }
346
347 #toc {
348 margin-bottom: 2.5em;
349 }
350
351 #toctitle {
352 color: #527bbd;
353 font-size: 1.1em;
354 font-weight: bold;
355 margin-top: 1.0em;
356 margin-bottom: 0.1em;
357 }
358
359 div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
360 margin-top: 0;
361 margin-bottom: 0;
362 }
363 div.toclevel2 {
364 margin-left: 2em;
365 font-size: 0.9em;
366 }
367 div.toclevel3 {
368 margin-left: 4em;
369 font-size: 0.9em;
370 }
371 div.toclevel4 {
372 margin-left: 6em;
373 font-size: 0.9em;
374 }
375
376 span.aqua { color: aqua; }
377 span.black { color: black; }
378 span.blue { color: blue; }
379 span.fuchsia { color: fuchsia; }
380 span.gray { color: gray; }
381 span.green { color: green; }
382 span.lime { color: lime; }
383 span.maroon { color: maroon; }
384 span.navy { color: navy; }
385 span.olive { color: olive; }
386 span.purple { color: purple; }
387 span.red { color: red; }
388 span.silver { color: silver; }
389 span.teal { color: teal; }
390 span.white { color: white; }
391 span.yellow { color: yellow; }
392
393 span.aqua-background { background: aqua; }
394 span.black-background { background: black; }
395 span.blue-background { background: blue; }
396 span.fuchsia-background { background: fuchsia; }
397 span.gray-background { background: gray; }
398 span.green-background { background: green; }
399 span.lime-background { background: lime; }
400 span.maroon-background { background: maroon; }
401 span.navy-background { background: navy; }
402 span.olive-background { background: olive; }
403 span.purple-background { background: purple; }
404 span.red-background { background: red; }
405 span.silver-background { background: silver; }
406 span.teal-background { background: teal; }
407 span.white-background { background: white; }
408 span.yellow-background { background: yellow; }
409
410 span.big { font-size: 2em; }
411 span.small { font-size: 0.6em; }
412
413 span.underline { text-decoration: underline; }
414 span.overline { text-decoration: overline; }
415 span.line-through { text-decoration: line-through; }
416
417 div.unbreakable { page-break-inside: avoid; }
418
419
420 /*
421 * xhtml11 specific
422 *
423 * */
424
425 div.tableblock {
426 margin-top: 1.0em;
427 margin-bottom: 1.5em;
428 }
429 div.tableblock > table {
430 border: 3px solid #527bbd;
431 }
432 thead, p.table.header {
433 font-weight: bold;
434 color: #527bbd;
435 }
436 p.table {
437 margin-top: 0;
438 }
439 /* Because the table frame attribute is overridden by CSS in most browsers. */
440 div.tableblock > table[frame="void"] {
441 border-style: none;
442 }
443 div.tableblock > table[frame="hsides"] {
444 border-left-style: none;
445 border-right-style: none;
446 }
447 div.tableblock > table[frame="vsides"] {
448 border-top-style: none;
449 border-bottom-style: none;
450 }
451
452
453 /*
454 * html5 specific
455 *
456 * */
457
458 table.tableblock {
459 margin-top: 1.0em;
460 margin-bottom: 1.5em;
461 }
462 thead, p.tableblock.header {
463 font-weight: bold;
464 color: #527bbd;
465 }
466 p.tableblock {
467 margin-top: 0;
468 }
469 table.tableblock {
470 border-width: 3px;
471 border-spacing: 0px;
472 border-style: solid;
473 border-color: #527bbd;
474 border-collapse: collapse;
475 }
476 th.tableblock, td.tableblock {
477 border-width: 1px;
478 padding: 4px;
479 border-style: solid;
480 border-color: #527bbd;
481 }
482
483 table.tableblock.frame-topbot {
484 border-left-style: hidden;
485 border-right-style: hidden;
486 }
487 table.tableblock.frame-sides {
488 border-top-style: hidden;
489 border-bottom-style: hidden;
490 }
491 table.tableblock.frame-none {
492 border-style: hidden;
493 }
494
495 th.tableblock.halign-left, td.tableblock.halign-left {
496 text-align: left;
497 }
498 th.tableblock.halign-center, td.tableblock.halign-center {
499 text-align: center;
500 }
501 th.tableblock.halign-right, td.tableblock.halign-right {
502 text-align: right;
503 }
504
505 th.tableblock.valign-top, td.tableblock.valign-top {
506 vertical-align: top;
507 }
508 th.tableblock.valign-middle, td.tableblock.valign-middle {
509 vertical-align: middle;
510 }
511 th.tableblock.valign-bottom, td.tableblock.valign-bottom {
512 vertical-align: bottom;
513 }
514
515
516 /*
517 * manpage specific
518 *
519 * */
520
521 body.manpage h1 {
522 padding-top: 0.5em;
523 padding-bottom: 0.5em;
524 border-top: 2px solid silver;
525 border-bottom: 2px solid silver;
526 }
527 body.manpage h2 {
528 border-style: none;
529 }
530 body.manpage div.sectionbody {
531 margin-left: 3em;
532 }
533
534 @media print {
535 body.manpage div#toc { display: none; }
536 }
537
538
539 </style>
540 <script type="text/javascript">
541 /*<![CDATA[*/
542 var asciidoc = { // Namespace.
543
544 /////////////////////////////////////////////////////////////////////
545 // Table Of Contents generator
546 /////////////////////////////////////////////////////////////////////
547
548 /* Author: Mihai Bazon, September 2002
549 * http://students.infoiasi.ro/~mishoo
550 *
551 * Table Of Content generator
552 * Version: 0.4
553 *
554 * Feel free to use this script under the terms of the GNU General Public
555 * License, as long as you do not remove or alter this notice.
556 */
557
558 /* modified by Troy D. Hanson, September 2006. License: GPL */
559 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
560
561 // toclevels = 1..4.
562 toc: function (toclevels) {
563
564 function getText(el) {
565 var text = "";
566 for (var i = el.firstChild; i != null; i = i.nextSibling) {
567 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
568 text += i.data;
569 else if (i.firstChild != null)
570 text += getText(i);
571 }
572 return text;
573 }
574
575 function TocEntry(el, text, toclevel) {
576 this.element = el;
577 this.text = text;
578 this.toclevel = toclevel;
579 }
580
581 function tocEntries(el, toclevels) {
582 var result = new Array;
583 var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');
584 // Function that scans the DOM tree for header elements (the DOM2
585 // nodeIterator API would be a better technique but not supported by all
586 // browsers).
587 var iterate = function (el) {
588 for (var i = el.firstChild; i != null; i = i.nextSibling) {
589 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
590 var mo = re.exec(i.tagName);
591 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
592 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
593 }
594 iterate(i);
595 }
596 }
597 }
598 iterate(el);
599 return result;
600 }
601
602 var toc = document.getElementById("toc");
603 if (!toc) {
604 return;
605 }
606
607 // Delete existing TOC entries in case we're reloading the TOC.
608 var tocEntriesToRemove = [];
609 var i;
610 for (i = 0; i < toc.childNodes.length; i++) {
611 var entry = toc.childNodes[i];
612 if (entry.nodeName.toLowerCase() == 'div'
613 && entry.getAttribute("class")
614 && entry.getAttribute("class").match(/^toclevel/))
615 tocEntriesToRemove.push(entry);
616 }
617 for (i = 0; i < tocEntriesToRemove.length; i++) {
618 toc.removeChild(tocEntriesToRemove[i]);
619 }
620
621 // Rebuild TOC entries.
622 var entries = tocEntries(document.getElementById("content"), toclevels);
623 for (var i = 0; i < entries.length; ++i) {
624 var entry = entries[i];
625 if (entry.element.id == "")
626 entry.element.id = "_toc_" + i;
627 var a = document.createElement("a");
628 a.href = "#" + entry.element.id;
629 a.appendChild(document.createTextNode(entry.text));
630 var div = document.createElement("div");
631 div.appendChild(a);
632 div.className = "toclevel" + entry.toclevel;
633 toc.appendChild(div);
634 }
635 if (entries.length == 0)
636 toc.parentNode.removeChild(toc);
637 },
638
639
640 /////////////////////////////////////////////////////////////////////
641 // Footnotes generator
642 /////////////////////////////////////////////////////////////////////
643
644 /* Based on footnote generation code from:
645 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
646 */
647
648 footnotes: function () {
649 // Delete existing footnote entries in case we're reloading the footnodes.
650 var i;
651 var noteholder = document.getElementById("footnotes");
652 if (!noteholder) {
653 return;
654 }
655 var entriesToRemove = [];
656 for (i = 0; i < noteholder.childNodes.length; i++) {
657 var entry = noteholder.childNodes[i];
658 if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")
659 entriesToRemove.push(entry);
660 }
661 for (i = 0; i < entriesToRemove.length; i++) {
662 noteholder.removeChild(entriesToRemove[i]);
663 }
664
665 // Rebuild footnote entries.
666 var cont = document.getElementById("content");
667 var spans = cont.getElementsByTagName("span");
668 var refs = {};
669 var n = 0;
670 for (i=0; i<spans.length; i++) {
671 if (spans[i].className == "footnote") {
672 n++;
673 var note = spans[i].getAttribute("data-note");
674 if (!note) {
675 // Use [\s\S] in place of . so multi-line matches work.
676 // Because JavaScript has no s (dotall) regex flag.
677 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
678 spans[i].innerHTML =
679 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
680 "' title='View footnote' class='footnote'>" + n + "</a>]";
681 spans[i].setAttribute("data-note", note);
682 }
683 noteholder.innerHTML +=
684 "<div class='footnote' id='_footnote_" + n + "'>" +
685 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
686 n + "</a>. " + note + "</div>";
687 var id =spans[i].getAttribute("id");
688 if (id != null) refs["#"+id] = n;
689 }
690 }
691 if (n == 0)
692 noteholder.parentNode.removeChild(noteholder);
693 else {
694 // Process footnoterefs.
695 for (i=0; i<spans.length; i++) {
696 if (spans[i].className == "footnoteref") {
697 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
698 href = href.match(/#.*/)[0]; // Because IE return full URL.
699 n = refs[href];
700 spans[i].innerHTML =
701 "[<a href='#_footnote_" + n +
702 "' title='View footnote' class='footnote'>" + n + "</a>]";
703 }
704 }
705 }
706 },
707
708 install: function(toclevels) {
709 var timerId;
710
711 function reinstall() {
712 asciidoc.footnotes();
713 if (toclevels) {
714 asciidoc.toc(toclevels);
715 }
716 }
717
718 function reinstallAndRemoveTimer() {
719 clearInterval(timerId);
720 reinstall();
721 }
722
723 timerId = setInterval(reinstall, 500);
724 if (document.addEventListener)
725 document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
726 else
727 window.onload = reinstallAndRemoveTimer;
728 }
729
730 }
731 asciidoc.install(4);
732 /*]]>*/
733 </script>
734 </head>
735 <body class="article">
736 <div id="header">
737 <h1>The GNU APL <strong>⎕GTK</strong> Cookbook</h1>
738 <div id="toc">
739 <div id="toctitle">Table of Contents</div>
740 </div>
741 </div>
742 <div id="content">
743 <div class="sect1">
744 <h2 id="_abstract">Abstract</h2>
745 <div class="sectionbody">
746 <div class="paragraph"><p>⎕GTK is a GNU APL system function that allows an APL program to create and
747 control a graphical user interface (GUI). The GUI is based on Gtk+ (Gimp
748 Toolkit) version 3+ (aka. GTK 3+). This document describes, by means of
749 simple examples, how <strong>⎕GTK</strong> based GUIs can be created and managed from GNU APL.</p></div>
750 </div>
751 </div>
752 <div class="sect1">
753 <h2 id="_philosophy">Philosophy</h2>
754 <div class="sectionbody">
755 <div class="paragraph"><p>A modern GUI such as Gtk provides a powerful API for controlling almost every
756 aspect of the GUI. A consequence of that power is an API that consists of
757 thousands of functions. The entire Gtk API is spread over 11 different
758 libraries:</p></div>
759 <div class="listingblock">
760 <div class="content">
761 <pre>
762
763 <code>$ pkg-config gtk+-3.0 --libs
764 -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0
765 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0</code>
766
767 </pre>
768 </div></div>
769 <div class="paragraph"><p>Each library contains tens, hundreds, or even thousands of symbols. Every
770 symbol represents either a function or a variable, and the vast majority of
771 symbols in the different libraries represent functions.</p></div>
772 <div class="tableblock">
773 <table rules="all"
774 width="60%"
775 frame="border"
776 cellspacing="0" cellpadding="4">
777 <caption class="title">Table 1. Gtk API Symbols</caption>
778 <col width="50%" />
779 <col width="50%" />
780 <thead>
781 <tr>
782 <th align="left" valign="top"> Gtk Library </th>
783 <th align="left" valign="top"> Number of Symbols</th>
784 </tr>
785 </thead>
786 <tfoot>
787 <tr>
788 <td align="left" valign="top"><p class="table">TOTAL</p></td>
789 <td align="left" valign="top"><p class="table">9950</p></td>
790 </tr>
791 </tfoot>
792 <tbody>
793 <tr>
794 <td align="left" valign="top"><p class="table">libgtk-3.so</p></td>
795 <td align="left" valign="top"><p class="table">4176</p></td>
796 </tr>
797 <tr>
798 <td align="left" valign="top"><p class="table">libgdk-3.so</p></td>
799 <td align="left" valign="top"><p class="table">632</p></td>
800 </tr>
801 <tr>
802 <td align="left" valign="top"><p class="table">libatk-1.0.so</p></td>
803 <td align="left" valign="top"><p class="table">265</p></td>
804 </tr>
805 <tr>
806 <td align="left" valign="top"><p class="table">libgio-2.0.so</p></td>
807 <td align="left" valign="top"><p class="table">1872</p></td>
808 </tr>
809 <tr>
810 <td align="left" valign="top"><p class="table">libpangocairo-1.0.so</p></td>
811 <td align="left" valign="top"><p class="table">33</p></td>
812 </tr>
813 <tr>
814 <td align="left" valign="top"><p class="table">libgdk_pixbuf-2.0.so</p></td>
815 <td align="left" valign="top"><p class="table">117</p></td>
816 </tr>
817 <tr>
818 <td align="left" valign="top"><p class="table">libcairo-gobject.so</p></td>
819 <td align="left" valign="top"><p class="table">33</p></td>
820 </tr>
821 <tr>
822 <td align="left" valign="top"><p class="table">libpango-1.0.so</p></td>
823 <td align="left" valign="top"><p class="table">405</p></td>
824 </tr>
825 <tr>
826 <td align="left" valign="top"><p class="table">libcairo.so</p></td>
827 <td align="left" valign="top"><p class="table">395</p></td>
828 </tr>
829 <tr>
830 <td align="left" valign="top"><p class="table">libgobject-2.0.so</p></td>
831 <td align="left" valign="top"><p class="table">427</p></td>
832 </tr>
833 <tr>
834 <td align="left" valign="top"><p class="table">libglib-2.0.so</p></td>
835 <td align="left" valign="top"><p class="table">1595</p></td>
836 </tr>
837 </tbody>
838 </table>
839 </div>
840 <div class="paragraph"><p>These numbers suggest that mapping every Gtk function to a corresponding APL
841 function would create an almost unusable API at the APL level. Even the
842 approach used for ⎕FIO or ⎕SQL - using function numbers as APL axis elements -
843 reaches its limits when used with almost 10000 functions.</p></div>
844 <div class="paragraph"><p>Now, the huge number of API functions in the different Gtk libraries contrasts
845 considerably with the moderate number of widgets (around 80) in a GUI and even
846 more with the number of actions (like clicking, marking text, typing text, etc.)
847 that a user can do with each of the widgets.</p></div>
848 <div class="paragraph"><p>If we look at the program <strong>glade</strong>, which is the default tool for constructing
849 Gtk based GUIs, then we see that there are 12 top-level widgets
850 (aka. "windows"), 20 containers (widgets containing other widgets), and 36
851 control widgets (most of them variants of the same base widget, like different
852 types of buttons).</p></div>
853 <div class="paragraph"><p>This discrepancy between the huge number of functions provided by Gtk and
854 rather small number of things that a user can do (like: click on a button,
855 select an item in a selection box, enter text in some text entry, etc.)
856 or perceive (color, font, etc.) suggests that there might be a clever way to
857 control a GUI without mapping each of the almost 10000 Gtk functions to a
858 corresponding APL function in a 1:1 fashion.</p></div>
859 <div class="paragraph"><p>⎕GTK uses a rigorous approach to reduce the number of functions:</p></div>
860 <div class="ulist"><ul>
861 <li>
862 <p>
863 Every GUI must be described by a suitable <strong>XML file</strong> or <strong>XML string</strong>.
864 </p>
865 <div class="ulist"><ul>
866 <li>
867 <p>
868 Suitable <strong>XML files</strong> can be created with the GUI construction tool <strong>glade</strong>
869 (which comes with GTK), while
870 </p>
871 </li>
872 <li>
873 <p>
874 suitable <strong>XML strings</strong> can be constructed programmatically in APL (see
875 workspace <strong>SQL_GUI</strong> which contains examples for <strong>⎕GTK</strong> and <strong>⎕SQL</strong>).
876
877 This requirement reduces the need for all functions that are concerned with
878 the instantiation of the GUI elements and their properties. It also speeds
879 up the design of the GUI itself.
880 </p>
881 </li>
882 </ul></div>
883 </li>
884 <li>
885 <p>
886 To the extent possible, visual widget aspects that are usually static (i.e.
887 that do not change over time) such as colors are required to be specified
888 with CSS (Cascading Style Sheets). This requirement eliminates the need
889 for the corresponding GTK functions that would otherwise control these
890 aspects, which further reduces the number of Gtk API functions needed.
891 It also speeds up the design of the GUI itself. The downside is a somewhat
892 static look-and-feel of the GUI, because, for example, colors cannot be
893 changed after the GUI was instantiated. However, the benefit of fancy
894 dynamic GUIs (if any) seems not to justify the complexity in the API
895 that would be needed to support them.
896 </p>
897 </li>
898 <li>
899 <p>
900 Implementation on demand. <strong>⎕GTK</strong> starts with a rather small (and therefore
901 incomplete) set of GTK widgets and events, but has a simple way to extend
902 that set. The mapping between <strong>⎕GTK</strong> on one side and libgtk functions and
903 events on the other side is defined in a single macro file <strong>Gtk/Gtk_map.def</strong>
904 that can be easily extended to accommodate new widgets and signals,
905 </p>
906 </li>
907 </ul></div>
908 </div>
909 </div>
910 <div class="sect1">
911 <h2 id="_architecture">Architecture</h2>
912 <div class="sectionbody">
913 <div class="paragraph"><p>The philosophy above has been implemented in the following architecture.</p></div>
914 <div class="olist arabic"><ol class="arabic">
915 <li>
916 <p>
917 The Gtk GUI itself has been implemented in a separate process running the
918 program <strong>Gtk_server</strong>. The Gtk_server is linked with the different Gtk
919 libraries, so that Gtk itself remains outside GNU APL.
920 </p>
921 </li>
922 <li>
923 <p>
924 The <strong>Gtk_server</strong> is started by <strong>⎕GTK</strong>, and after that <strong>⎕GTK</strong> communicates with
925 Gtk_server over a socket pair. The communication consists of a sequence of
926 TLV (Tag/Length/Value) buffers encoded with 33 ⎕CR and decoded with 34 ⎕CR
927 (aka. ¯33 ⎕CR) at the APL end. A user action (e.g. a button click) results
928 in an "event" (= a TLV buffer) received by APL while a "command" (sent from
929 APL to the Gtk_server results in some change in the GUI. However, many
930 details such as a button changing its form or its color when being pressed
931 are handled by the Gtk_server server process (one of the Gtk libraries) and
932 are not communicated to APL. The encoding and decoding of TLVs that are
933 exchanged between <strong>apl</strong> and <strong>Gtk_server</strong>) takes place inside <strong>⎕GTK</strong> so that
934 the APL programmer is not concerned with the details of this communication.
935 </p>
936 </li>
937 </ol></div>
938 <div class="listingblock">
939 <div class="content">
940 <pre>
941
942 <code> ╔════════════════════════════╗
943 ║ GUI-description.xml file ║
944 ║ ↓ GUI-stylesheet.css file ║
945 ║ ↓ ↓ ║
946 ║ ↓ ↓ ┌───────────────┐ ║
947 ║ ↓ ↓ │ GTK GUI │ ║
948 ╔════════════════╗ Commands ║ ↓ ↓ └─┬─────────┬┬──┘ ║
949 ║ GNU APL ┌──╨───┐ 33⎕CR → → → socket ║┌──────────┴─┐ ┌───┼┴────┐║
950 ║ application │ ⎕GTK ├───────────────────────-----────╫┤ Gtk_server │ ┌─┴───┴────┐│║
951 ║ program.apl └───╥──┘ 34⎕CR ← ← ← pair ║└────────────┘ │ GTK libs ├┘║
952 ╚═════════════════╝ Responses, Events ║ └──────────┘ ║
953 ╚════════════════════════════╝</code>
954
955 </pre>
956 </div></div>
957 <div class="olist arabic"><ol class="arabic" start="3">
958 <li>
959 <p>
960 One Gtk_server handles a single top-level window and its children (see also
961 <a href="#TAG_caveats">Caveats</a>.
962 </p>
963 </li>
964 <li>
965 <p>
966 For GUIs that consist of multiple top-level windows, one apl interpreter
967 process can start several Gtk_server processes.
968 </p>
969 </li>
970 </ol></div>
971 </div>
972 </div>
973 <div class="sect1">
974 <h2 id="_development_work_flow">Development Work-flow</h2>
975 <div class="sectionbody">
976 <div class="paragraph"><p>The architecture above leads to the following work-flow.</p></div>
977 <div class="olist arabic"><ol class="arabic">
978 <li>
979 <p>
980 The programmer specifies the GUI by means of the <strong>glade</strong> GUI design tool
981 that comes with Gtk. The result is an XML file that describes the GUI. The
982 XML file can be changed later on as needed, so that the programmer can
983 start with a subset of the GUI functionality and then extend that
984 functionality in an incremental fashion.
985 </p>
986 </li>
987 <li>
988 <p>
989 The programmer writes a CSS specification for the widgets in the GUI.
990 The CSS file specifies the styling (i.e. colors. sizes etc.) of the
991 widgets. In theory, this step is optional, but in practice it is inevitable
992 for a somewhat good-looking GUI.
993 </p>
994 </li>
995 <li>
996 <p>
997 The programmer writes a brief start-up routine for the GUI in which the
998 files created in steps 1. and 2. above are loaded into the GUI.
999 </p>
1000 </li>
1001 <li>
1002 <p>
1003 The programmer displays the GUI - either at the start of the APL
1004 application if the GUI shall be permanently visible or at some later time
1005 if the GUI is, for example, only popped up to request input from the user
1006 of the APL application. In the latter case the GUI is a single window
1007 (a "modal dialog") which is polled from APL until some final action of the
1008 user has occurred, while the former case the APL application has to poll
1009 the GUI for events at rather short intervals. To poll <strong>⎕GTK</strong> at regular
1010 intervals:
1011 </p>
1012 </li>
1013 </ol></div>
1014 <div class="listingblock">
1015 <div class="content">
1016 <pre>
1017
1018 <code> ╔══════════════════════╗
1019 ║ GUI Design (glade) ║ → my-application.ui
1020 ╚══════════╤═══════════╝
1021 │
1022 ╔══════════╧═══════════╗
1023 ║ Widget Details (CSS) ║ → my-application.css
1024 ╚══════════╤═══════════╝
1025 │
1026 ╔══════════╧═══════════╗
1027 ║ APL application ║ → my-application.apl
1028 ║ ──────────────────── ║
1029 ║ GUI start ║ → loads my-application.ui and my-application.css
1030 ║ ──────────────────── ║
1031 ║ GUI event loop ║ → polls and reacts to events (user actions)
1032 ╚══════════════════════╝</code>
1033
1034 </pre>
1035 </div></div>
1036 <div class="paragraph"><p>The example given below will be a modal dialog with the non-modal case left
1037 as an exercise for the reader.</p></div>
1038 </div>
1039 </div>
1040 <div class="sect1">
1041 <h2 id="_principles">Principles</h2>
1042 <div class="sectionbody">
1043 <div class="paragraph"><p>As may have become obvious by now, there isn&#8217;t much coding left to be done
1044 for the APL application. After APL has started the GUI, the process running
1045 GNU APL and the Gtk_server send "signals" to each other in an asynchronous
1046 fashion and according to the following rules:</p></div>
1047 <div class="ulist"><ul>
1048 <li>
1049 <p>
1050 Every APL application that has a GUI (and uses <strong>⎕GTK</strong>) starts its own
1051 Gtk_server(s). In a GUI with several top-level windows, each top-level
1052 window uses its own Gtk_server which is identified by an integer (handle) in
1053 APL. Multiple Gtk_servers are independent of each other, and the coordination
1054 of events between the windows must be performed in the APL application.
1055 </p>
1056 </li>
1057 <li>
1058 <p>
1059 GNU APL and Gtk_server then send signals (aka, TLV buffers) to each other. A
1060 signal is a sequence of bytes, starting with a 4-byte tag, followed by a
1061 4-byte data length, and concluded with 0 or more data bytes as indicated by
1062 the signal length.
1063 </p>
1064 </li>
1065 <li>
1066 <p>
1067 The encoding of the signals is the same in both directions, but we call
1068 signals from APL to Gtk_server <strong>commands</strong> and signals from Gtk_server to APL
1069 either <strong>responses</strong> (if they contain the result of a prior command), or else
1070 <strong>events</strong> (which are caused by a user&#8217;s activity such as clicking a button.
1071 </p>
1072 <div class="ulist"><ul>
1073 <li>
1074 <p>
1075 Commands are used to modify the GUI in some way, for example to enter an
1076 initial value into a text-entry widget.
1077 </p>
1078 </li>
1079 <li>
1080 <p>
1081 Events are sent by the Gtk_server upon final user actions such as pushing a
1082 button, or pressing ENTER after having modified the text in a text-entry
1083 widget.
1084 </p>
1085 </li>
1086 </ul></div>
1087 </li>
1088 <li>
1089 <p>
1090 Normally larger amounts of data are not sent in events, but in command
1091 responses. Assume, for example, a user has entered some (possibly larger)
1092 text into a (hypothetical) text-editor widget and leaves the text-editor.
1093 The text-editor would then only send an event to APL indicating that some
1094 new text is available. The new text itself, however, is not packed into that
1095 event but needs to be fetched from the text-editor widget in the Gtk_server
1096 by means of a corresponding retrieval command. The new text is then sent from
1097 the Gtk_server to APL in the response to the retrieval command. In other
1098 words, larger amounts of data are usually pulled by apl from a Gtk_server
1099 rather than pushed by the Gtk_server into APL. The reasons for this approach
1100 are:
1101 </p>
1102 <div class="ulist"><ul>
1103 <li>
1104 <p>
1105 the retrieval commands are usually needed anyway. It is often easier
1106 to specify the initial content of a widget in <strong>glade</strong> than to set it from
1107 the APL application and,
1108 </p>
1109 </li>
1110 <li>
1111 <p>
1112 the events become more uniform (not differing by different types of
1113 content). This, in turn, allows the same event to be used by different
1114 widgets that differ only by the type of data that they produce.
1115 </p>
1116 </li>
1117 </ul></div>
1118 </li>
1119 <li>
1120 <p>
1121 As a consequence, most events contain only the type of event and the widget
1122 that has sent the event.
1123 </p>
1124 </li>
1125 <li>
1126 <p>
1127 Every signal is a TLV buffer whose length is dictated by the length of the
1128 Value component. Such a TLV buffer is therefore already determined by an
1129 integer tag and the value bytes V; the length is then ⍴V. In APL it is
1130 therefore sufficient to specify only T and V as a vector TV←Tag,Value whose
1131 first element Tag = ↑TV identifies a particular command or event, and the
1132 rest 1↓TV is a (frequently empty) argument of that command or event. The
1133 GNU APL system functions 33 ⎕CR and 34 ⎕CR have been tailored to encode and
1134 decode tag/value vectors TV to/from respectively the TLV buffers exchanged
1135 between APL and Gtk_server.
1136 </p>
1137 </li>
1138 <li>
1139 <p>
1140 Sending of a TLV from APL to Gtk_server is done by encoding the TLV with 33
1141 ⎕FIO TLV, followed by a single write() (similar to ⎕FIO[42]) onto the
1142 connection (the "Handle") between APL and Gtk_server. Sending of only part
1143 of a TLV (for example, first the tag in one write() and then the length and
1144 the value in a second write()) is not allowed in either direction because
1145 that would hang the other side. That tags are divided into the following
1146 ranges:
1147 </p>
1148 <div class="ulist"><ul>
1149 <li>
1150 <p>
1151 1&#8230;999: commands that have no response
1152 </p>
1153 </li>
1154 <li>
1155 <p>
1156 1001&#8230;1999: commands that have a response (i.e. that expect a result)
1157 </p>
1158 </li>
1159 <li>
1160 <p>
1161 -1999&#8230;-1000 error indications for commands 1000&#8230;1999. If command
1162 1xxx fails in Gtk_server, then Gtk_server sends -1xxx to APL.
1163 </p>
1164 </li>
1165 <li>
1166 <p>
1167 2001-2999: responses (2xxx is the response for command 1xxx)
1168 </p>
1169 </li>
1170 <li>
1171 <p>
1172 3001-3999: event classes. They tell <strong>⎕GTK</strong> how to decode the data supplied
1173 with the tag and how to present that data (event name, widget, possibly
1174 X/Y coordinates of mouse events, etc.) to APL.
1175 </p>
1176 </li>
1177 </ul></div>
1178 </li>
1179 <li>
1180 <p>
1181 Receiving from Gtk_server is done with a single read() call (like ⎕FIO[43])
1182 from the handle followed by decoding the received bytes with 34 ⎕CR.
1183 </p>
1184 </li>
1185 </ul></div>
1186 <div class="admonitionblock">
1187 <table><tr>
1188 <td class="icon">
1189 <img src="/usr/share/asciidoc/icons/note.png" alt="Note" />
1190 </td>
1191 <td class="content">the details of TLV encoding and tag ranges are only mentioned for
1192 completeness and are not needed by the APL programmer.</td>
1193 </tr></table>
1194 </div>
1195 </div>
1196 </div>
1197 <div class="sect1">
1198 <h2 id="_detailed_example">Detailed Example</h2>
1199 <div class="sectionbody">
1200 <div class="paragraph"><p>In the following, the implementation of a simple GUI will be described
1201 step-by-step. The GUI will consist of a window that contains two labels (=
1202 fixed texts), two text entry boxes, and a button that the user can push to end
1203 the text entry.</p></div>
1204 <div class="sect2">
1205 <h3 id="_step_1_defining_the_gui_with_glade">Step 1: Defining the GUI with Glade</h3>
1206 <div class="paragraph"><p>Start <strong>glade</strong> without a filename:</p></div>
1207 <div class="listingblock">
1208 <div class="content">
1209 <pre>
1210
1211 <code>$ glade</code>
1212
1213 </pre>
1214 </div></div>
1215 <div class="paragraph"><p>A window with four larger areas pops up:</p></div>
1216 <div class="imageblock">
1217 <div class="content">
1218 <img src="glade-0.png" alt="glade-0.png" />
1219 </div>
1220 </div>
1221 <div class="paragraph"><p>The four areas are:</p></div>
1222 <div class="olist arabic"><ol class="arabic">
1223 <li>
1224 <p>
1225 A <strong>widget selection area</strong> on the left,
1226 </p>
1227 </li>
1228 <li>
1229 <p>
1230 A <strong>GUI visualization</strong> in the middle (empty)
1231 </p>
1232 </li>
1233 <li>
1234 <p>
1235 A <strong>GUI structure</strong> on the (top-) right (empty), and
1236 </p>
1237 </li>
1238 <li>
1239 <p>
1240 A <strong>widget property area</strong> on the (bottom-) right (empty).
1241 </p>
1242 </li>
1243 </ol></div>
1244 <div class="admonitionblock">
1245 <table><tr>
1246 <td class="icon">
1247 <img src="./images/icons/note.png" alt="Note" />
1248 </td>
1249 <td class="content">recent <strong>glade</strong> versions look slightly different, for example the widget
1250 selection area has been replaced by drop-down menus. However, the description
1251 given here should suffice to briefly explain <strong>glade</strong>. For <strong>glade alternatives</strong>,
1252 see also <a href="#TAG_programmatically">Chapter 8 Specifying GUIs Programmatically</a>
1253 below.</td>
1254 </tr></table>
1255 </div>
1256 <div class="paragraph"><p>The <strong>widget selection area</strong> is further divided into several widget groups named</p></div>
1257 <div class="ulist"><ul>
1258 <li>
1259 <p>
1260 Actions,
1261 </p>
1262 </li>
1263 <li>
1264 <p>
1265 Toplevels,
1266 </p>
1267 </li>
1268 <li>
1269 <p>
1270 Containers,
1271 </p>
1272 </li>
1273 <li>
1274 <p>
1275 Control and Display, and
1276 </p>
1277 </li>
1278 <li>
1279 <p>
1280 GTK+ Unix Print Toplevels
1281 </p>
1282 </li>
1283 </ul></div>
1284 <div class="admonitionblock">
1285 <table><tr>
1286 <td class="icon">
1287 <img src="/usr/share/asciidoc/icons/tip.png" alt="Tip" />
1288 </td>
1289 <td class="content">If you move the mouse pointer over one of the widgets, then the widget
1290 is highlighted and a tool-tip showing the type of the widget pops up.</td>
1291 </tr></table>
1292 </div>
1293 </div>
1294 <div class="sect2">
1295 <h3 id="_step_1a_add_top_level_window">Step 1a: Add top-level Window</h3>
1296 <div class="paragraph"><p>Drag the first widget of type <strong>Window</strong> from the Toplevels group and drop
1297 it into the <strong>GUI visualization area</strong>. That is, move the mouse pointer
1298 over the widget, push and hold down the left mouse button, move the mouse
1299 pointer to the <strong>GUI visualization area</strong> in the middle, and release the
1300 mouse button.</p></div>
1301 <div class="paragraph"><p>You will now see a new rectangular area in the <strong>GUI visualization area</strong>,
1302 a widget item named <strong>window1</strong> in the <strong>GUI structure</strong>, and
1303 the properties of the new widget below.</p></div>
1304 <div class="paragraph"><p>Your GUI now consists of one widget. You see the grid as child <strong>grid1</strong> of
1305 <strong>window1</strong> in the <strong>GUI structure</strong>.</p></div>
1306 </div>
1307 <div class="sect2">
1308 <h3 id="_step_1b_add_a_positioning_grid">Step 1b: Add a positioning Grid</h3>
1309 <div class="paragraph"><p>Next, drag the widget of type <strong>Grid</strong> onto the <strong>window1</strong> in the
1310 middle and enter 6 rows / 10 columns in the dialog that pops up.</p></div>
1311 <div class="paragraph"><p>This grid is a helper-widget for controlling the placement of other widgets
1312 inside <strong>window1</strong>.</p></div>
1313 </div>
1314 <div class="sect2">
1315 <h3 id="_step_1c_add_labels_and_text_entry_widgets_to_the_positioning_grid">Step 1c: Add labels and text entry widgets to the positioning Grid</h3>
1316 <div class="paragraph"><p>Next, drag the widget of type <strong>Label</strong> from the "Control and Display" group
1317 onto row 2, column 2 of the grid and another one of type <strong>Label</strong> onto row 3,
1318 column 2 of the grid. Similarly, drag 2 widgets of type "Text Entry" to
1319 rows 2 and 3, column 4,</p></div>
1320 <div class="paragraph"><p>Unfortunately this makes the grid uneven because the newly placed widgets are
1321 larger than the fields in the grid. You can fix that by:</p></div>
1322 <div class="ulist"><ul>
1323 <li>
1324 <p>
1325 selecting each widget in the <strong>GUI structure</strong>,
1326 </p>
1327 </li>
1328 <li>
1329 <p>
1330 selecting the <strong>Packing</strong> tab in the properties area, and
1331 </p>
1332 </li>
1333 <li>
1334 <p>
1335 setting the <strong>Width</strong> property from its default 1 to, say, 6.
1336 </p>
1337 </li>
1338 </ul></div>
1339 <div class="paragraph"><p>That tells <strong>glade</strong> to use 6 grid cells instead of 1, so that the grid looks
1340 almost normal again.</p></div>
1341 <div class="paragraph"><p>At this point you can change the property <strong>label</strong> under the <strong>General tab</strong> to
1342 that text that the label should have. We choose <strong>Employee</strong> for <strong>label2</strong> and
1343 <strong>Position</strong> for label2.</p></div>
1344 </div>
1345 <div class="sect2">
1346 <h3 id="_step_1d_add_an_ok_button_and_save_the_gui">Step 1d: Add an OK button and save the GUI</h3>
1347 <div class="paragraph"><p>Finally, drag the widget of type <strong>Button</strong> from the <strong>Control and Display</strong> group
1348 to row 5, column 5, then set its <strong>width</strong> to <strong>2</strong>, and its <strong>label</strong> to <strong>OK</strong>
1349 (you need to scroll down in the General tab to see that property).</p></div>
1350 <div class="paragraph"><p>Then <strong>SAVE THE GUI !!!</strong> in <strong>glade</strong>'s menu-bar under <strong>File → Save As</strong> and give
1351 it the filename <strong>my-application.ui</strong>.</p></div>
1352 <div class="paragraph"><p>In <strong>glade</strong>, the GUI should now look like this:</p></div>
1353 <div class="imageblock">
1354 <div class="content">
1355 <img src="glade-1.png" alt="glade-1.png" />
1356 </div>
1357 </div>
1358 <div class="paragraph"><p>At this point you can exit <strong>glade</strong>. <strong>glade</strong> has produced the file
1359 <strong>my-application.ui</strong>, which is an XML file describing the GUI, Its content is
1360 this:</p></div>
1361 <div class="listingblock">
1362 <div class="content">
1363 <pre>
1364
1365 <code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
1366 &lt;!-- Generated with glade 3.16.1 --&gt;
1367 &lt;interface&gt;
1368 &lt;requires lib="gtk+" version="3.10"/&gt;
1369 &lt;object class="GtkWindow" id="window1"&gt;
1370 &lt;property name="can_focus"&gt;False&lt;/property&gt;
1371 &lt;child&gt;
1372 &lt;object class="GtkGrid" id="grid1"&gt;
1373 &lt;property name="visible"&gt;True&lt;/property&gt;
1374 &lt;property name="can_focus"&gt;False&lt;/property&gt;
1375 &lt;child&gt;
1376 &lt;object class="GtkLabel" id="label1"&gt;
1377 &lt;property name="visible"&gt;True&lt;/property&gt;
1378 &lt;property name="can_focus"&gt;False&lt;/property&gt;
1379 &lt;property name="label" translatable="yes"&gt;Employee&lt;/property&gt;
1380 &lt;/object&gt;
1381 &lt;packing&gt;
1382 &lt;property name="left_attach"&gt;1&lt;/property&gt;
1383 &lt;property name="top_attach"&gt;1&lt;/property&gt;
1384 &lt;property name="width"&gt;1&lt;/property&gt;
1385 &lt;property name="height"&gt;1&lt;/property&gt;
1386 &lt;/packing&gt;
1387 &lt;/child&gt;
1388 &lt;child&gt;
1389 &lt;object class="GtkLabel" id="label2"&gt;
1390 &lt;property name="name"&gt;label2&lt;/property&gt;
1391 &lt;property name="visible"&gt;True&lt;/property&gt;
1392 &lt;property name="can_focus"&gt;False&lt;/property&gt;
1393 &lt;property name="label" translatable="yes"&gt;Position&lt;/property&gt;
1394 &lt;/object&gt;
1395 &lt;packing&gt;
1396 &lt;property name="left_attach"&gt;1&lt;/property&gt;
1397 &lt;property name="top_attach"&gt;2&lt;/property&gt;
1398 &lt;property name="width"&gt;1&lt;/property&gt;
1399 &lt;property name="height"&gt;1&lt;/property&gt;
1400 &lt;/packing&gt;
1401 &lt;/child&gt;
1402 &lt;child&gt;
1403 &lt;object class="GtkEntry" id="entry1"&gt;
1404 &lt;property name="visible"&gt;True&lt;/property&gt;
1405 &lt;property name="can_focus"&gt;True&lt;/property&gt;
1406 &lt;/object&gt;
1407 &lt;packing&gt;
1408 &lt;property name="left_attach"&gt;3&lt;/property&gt;
1409 &lt;property name="top_attach"&gt;1&lt;/property&gt;
1410 &lt;property name="width"&gt;6&lt;/property&gt;
1411 &lt;property name="height"&gt;1&lt;/property&gt;
1412 &lt;/packing&gt;
1413 &lt;/child&gt;
1414 &lt;child&gt;
1415 &lt;object class="GtkEntry" id="entry2"&gt;
1416 &lt;property name="visible"&gt;True&lt;/property&gt;
1417 &lt;property name="can_focus"&gt;True&lt;/property&gt;
1418 &lt;/object&gt;
1419 &lt;packing&gt;
1420 &lt;property name="left_attach"&gt;3&lt;/property&gt;
1421 &lt;property name="top_attach"&gt;2&lt;/property&gt;
1422 &lt;property name="width"&gt;6&lt;/property&gt;
1423 &lt;property name="height"&gt;1&lt;/property&gt;
1424 &lt;/packing&gt;
1425 &lt;/child&gt;
1426 &lt;child&gt;
1427 &lt;object class="GtkButton" id="button1"&gt;
1428 &lt;property name="label" translatable="yes"&gt;OK&lt;/property&gt;
1429 &lt;property name="name"&gt;OK-button&lt;/property&gt;
1430 &lt;property name="visible"&gt;True&lt;/property&gt;
1431 &lt;property name="can_focus"&gt;True&lt;/property&gt;
1432 &lt;property name="receives_default"&gt;True&lt;/property&gt;
1433 &lt;signal name="clicked" handler="clicked" swapped="no"/&gt;
1434 &lt;/object&gt;
1435 &lt;packing&gt;
1436 &lt;property name="left_attach"&gt;4&lt;/property&gt;
1437 &lt;property name="top_attach"&gt;4&lt;/property&gt;
1438 &lt;property name="width"&gt;2&lt;/property&gt;
1439 &lt;property name="height"&gt;1&lt;/property&gt;
1440 &lt;/packing&gt;
1441 &lt;/child&gt;
1442 &lt;child&gt;
1443 &lt;placeholder/&gt;
1444 &lt;/child&gt;
1445 &lt;child&gt;
1446 &lt;placeholder/&gt;
1447 &lt;/child&gt;
1448 &lt;child&gt;
1449 &lt;placeholder/&gt;
1450 &lt;/child&gt;
1451 &lt;child&gt;
1452 &lt;placeholder/&gt;
1453 &lt;/child&gt;
1454 &lt;child&gt;
1455 &lt;placeholder/&gt;
1456 &lt;/child&gt;
1457 &lt;child&gt;
1458 &lt;placeholder/&gt;
1459 &lt;/child&gt;
1460 &lt;child&gt;
1461 &lt;placeholder/&gt;
1462 &lt;/child&gt;
1463 &lt;child&gt;
1464 &lt;placeholder/&gt;
1465 &lt;/child&gt;
1466 &lt;child&gt;
1467 &lt;placeholder/&gt;
1468 &lt;/child&gt;
1469 &lt;child&gt;
1470 &lt;placeholder/&gt;
1471 &lt;/child&gt;
1472 &lt;child&gt;
1473 &lt;placeholder/&gt;
1474 &lt;/child&gt;
1475 &lt;child&gt;
1476 &lt;placeholder/&gt;
1477 &lt;/child&gt;
1478 &lt;child&gt;
1479 &lt;placeholder/&gt;
1480 &lt;/child&gt;
1481 &lt;child&gt;
1482 &lt;placeholder/&gt;
1483 &lt;/child&gt;
1484 &lt;child&gt;
1485 &lt;placeholder/&gt;
1486 &lt;/child&gt;
1487 &lt;child&gt;
1488 &lt;placeholder/&gt;
1489 &lt;/child&gt;
1490 &lt;child&gt;
1491 &lt;placeholder/&gt;
1492 &lt;/child&gt;
1493 &lt;child&gt;
1494 &lt;placeholder/&gt;
1495 &lt;/child&gt;
1496 &lt;child&gt;
1497 &lt;placeholder/&gt;
1498 &lt;/child&gt;
1499 &lt;child&gt;
1500 &lt;placeholder/&gt;
1501 &lt;/child&gt;
1502 &lt;child&gt;
1503 &lt;placeholder/&gt;
1504 &lt;/child&gt;
1505 &lt;child&gt;
1506 &lt;placeholder/&gt;
1507 &lt;/child&gt;
1508 &lt;child&gt;
1509 &lt;placeholder/&gt;
1510 &lt;/child&gt;
1511 &lt;child&gt;
1512 &lt;placeholder/&gt;
1513 &lt;/child&gt;
1514 &lt;child&gt;
1515 &lt;placeholder/&gt;
1516 &lt;/child&gt;
1517 &lt;child&gt;
1518 &lt;placeholder/&gt;
1519 &lt;/child&gt;
1520 &lt;child&gt;
1521 &lt;placeholder/&gt;
1522 &lt;/child&gt;
1523 &lt;child&gt;
1524 &lt;placeholder/&gt;
1525 &lt;/child&gt;
1526 &lt;child&gt;
1527 &lt;placeholder/&gt;
1528 &lt;/child&gt;
1529 &lt;/object&gt;
1530 &lt;/child&gt;
1531 &lt;/object&gt;
1532 &lt;/interface&gt;</code>
1533
1534 </pre>
1535 </div></div>
1536 </div>
1537 <div class="sect2">
1538 <h3 id="_step_2_starting_the_gui_from_apl">Step 2: Starting the GUI from APL</h3>
1539 <div class="paragraph"><p>The GUI is not yet finished, but we can already look at it from APL. In the
1540 following we assume that:</p></div>
1541 <div class="ulist"><ul>
1542 <li>
1543 <p>
1544 The GUI file is /home/eedjsa/projects/juergen/apl-1.7/HOWTOs/my-application.ui
1545 </p>
1546 </li>
1547 </ul></div>
1548 <div class="paragraph"><p>You need to adjust these paths on your machine. Then start
1549 GNU APL and enter the following:</p></div>
1550 <div class="listingblock">
1551 <div class="content">
1552 <pre>
1553
1554 <code> GUI_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/my-application.ui'
1555 Handle ← *⎕GTK* GUI_path ⍝ fork Gtk_server and connect to it</code>
1556
1557 </pre>
1558 </div></div>
1559 <div class="paragraph"><p>We see a new window at the top-left corner of the screen (that position can be
1560 changed by window properties in <strong>glade</strong> later on):</p></div>
1561 <div class="imageblock">
1562 <div class="content">
1563 <img src="glade-2.png" alt="glade-2.png" />
1564 </div>
1565 </div>
1566 <div class="paragraph"><p>You can then stop the GUI with <strong>)CLEAR</strong> before leaving APL with <strong>)OFF</strong>:</p></div>
1567 <div class="listingblock">
1568 <div class="content">
1569 <pre>
1570
1571 <code> )CLEAR
1572 )OFF</code>
1573
1574 </pre>
1575 </div></div>
1576 </div>
1577 <div class="sect2">
1578 <h3 id="_step_3_styling_the_gui_with_css">Step 3: Styling the GUI with CSS</h3>
1579 <div class="paragraph"><p>There exist numerous functions for controlling how widgets look (colors, fonts,
1580 sizes, etc). However, constructing a GUI using these functions is a tedious
1581 and error-prone task.</p></div>
1582 <div class="paragraph"><p>For that reason, <strong>⎕GTK</strong> does not provide access to all these functions. Instead,
1583 one can specify these properties by means of a standard CSS (cascading style
1584 sheet) file as the (optional) left argument of dyadic <strong>⎕GTK</strong>:</p></div>
1585 <div class="listingblock">
1586 <div class="content">
1587 <pre>
1588
1589 <code> GUI_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/my-application.ui'
1590 CSS_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/my-application.css'
1591 Handle ← CSS_path *⎕GTK* GUI_path ⍝ fork Gtk_server and connect to it</code>
1592
1593 </pre>
1594 </div></div>
1595 <div class="paragraph"><p>Consider the following CSS example, (file <strong>my-application.css</strong>):</p></div>
1596 <div class="listingblock">
1597 <div class="content">
1598 <pre>
1599
1600 <code>/* general button */
1601 .BUTTON { color: #F00; background: #FFF; }
1602
1603 /* the OK button */
1604 #OK-button { color: #F00; background: #4F4; }</code>
1605
1606 </pre>
1607 </div></div>
1608 <div class="paragraph"><p>It specifies that buttons should, in general, have a white background and a
1609 red foreground (= text color), but that the button with the name <strong>"OK-button"</strong>
1610 in the XML file <strong>my-application.ui</strong> shall have a green background instead.
1611 It is important to note that the relevant name in CSS (here: <strong>#OK-button</strong>)
1612 is <strong>not</strong> the ID: in the <strong>General</strong> tab in <strong>glade</strong>, but the property
1613 <strong>Widget Name:</strong> in the <strong>Common</strong> tab in <strong>glade</strong>.</p></div>
1614 <div class="paragraph"><p>The "general button" has no effect in our simple example because our GUI
1615 has only one button and the stronger <strong>#OK-button</strong> clause wins over the more
1616 general (and thus weaker) <strong>.BUTTON</strong> clause. It is useful, though, for
1617 debug purposes: a white button would indicate a button that has not been
1618 matched by a more specific selector (e.g. by the widget name).</p></div>
1619 <div class="paragraph"><p>With the <strong>my-application.css</strong> example file above we now get this:</p></div>
1620 <div class="imageblock">
1621 <div class="content">
1622 <img src="glade-3.png" alt="glade-3.png" />
1623 </div>
1624 </div>
1625 </div>
1626 <div class="sect2">
1627 <h3 id="_step_4_managing_windows">Step 4: Managing windows</h3>
1628 <div class="paragraph"><p><strong>Monadic ⎕GTK</strong> with integer argument <strong>0</strong> returns a (possibly empty) integer
1629 vector containing all window handles that are currently open.</p></div>
1630 <div class="paragraph"><p><strong>Dyadic ⎕GTK</strong> with integer right argument <strong>0</strong> and integer left argument <strong>Ah</strong>
1631 closes the window whose handle is <strong>Ah</strong>.</p></div>
1632 <div class="admonitionblock">
1633 <table><tr>
1634 <td class="icon">
1635 <img src="/usr/share/asciidoc/icons/note.png" alt="Note" />
1636 </td>
1637 <td class="content">there is a summary of all <strong>⎕GTK</strong> syntax variants (a <strong>⎕GTK</strong> cheat sheet)
1638 in the <a href="#TAG_appendix">Appendix</a> of this document.</td>
1639 </tr></table>
1640 </div>
1641 <div class="listingblock">
1642 <div class="content">
1643 <pre>
1644
1645 <code> )CLEAR
1646 *⎕GTK* 0 ⍝ get window handles (empty)
1647
1648 GUI_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/my-application.ui'
1649 CSS_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/my-application.css'
1650 Handle ← CSS_path *⎕GTK* GUI_path ⍝ fork Gtk_server and connect to it
1651
1652 *⎕GTK* 0 ⍝ get window handles (now there is one window)
1653 6
1654
1655 6 *⎕GTK* 0 ⍝ close window handle 6
1656 0</code>
1657
1658 </pre>
1659 </div></div>
1660 <div class="paragraph"><p>The handle above (6) can, in theory, also be used with ⎕FIO functions like
1661 fread() if you know what you are doing. This practice is, however, dangerous
1662 because it might create inconsistencies between <strong>⎕GTK</strong> and ⎕FIO. For example,
1663 closing a <strong>⎕GTK</strong> handle with ⎕FIO is technically possible, but usually bad
1664 idea.</p></div>
1665 <div class="paragraph"><p>Please note that a window can normally be closed from two ends: from APL with
1666 <strong>Ah *⎕GTK</strong> 0* and from the GUI via <strong>Close</strong> in the top-left window menu.
1667 The latter may, however, close the window but leave the Gtk_server process
1668 that was running the window alive. You should therefore aim at always
1669 closing windows from APL, possibly by connecting window close signals to APL.</p></div>
1670 </div>
1671 <div class="sect2">
1672 <h3 id="_step_5_managing_widgets">Step 5: Managing widgets</h3>
1673 <div class="paragraph"><p>A window is a (top-level) widget that usually contains other widgets. When you
1674 place a new widget in <strong>glade</strong>, then <strong>glade</strong> assigns a unique ID to the widget
1675 and makes sure that the id remains unique.</p></div>
1676 <div class="admonitionblock">
1677 <table><tr>
1678 <td class="icon">
1679 <img src="/usr/share/asciidoc/icons/caution.png" alt="Caution" />
1680 </td>
1681 <td class="content"><strong>⎕GTK</strong> requires that you do not change the ID assigned by <strong>glade</strong> (even
1682 though <strong>glade</strong> allows you to do that). The ID assigned by <strong>glade</strong> is found as
1683 property <strong>ID:</strong> under the <strong>General</strong> tab and shall not be confused with the
1684 <strong>widget name:</strong> under the <strong>Common</strong> tab. The <strong>ID:</strong> property is used in the
1685 direction APL → Gtk_server to address widgets, while the <strong>widget name:</strong>
1686 property is used in the reverse direction APL ← Gtk_server to identify the
1687 widget that has sent a signal.</td>
1688 </tr></table>
1689 </div>
1690 <div class="paragraph"><p>The ID consists of a class name followed by an instance number, for example
1691 "window1", <strong>⎕GTK</strong> uses the class name in the ID to construct the function name
1692 in GTK that shall be called.</p></div>
1693 <div class="paragraph"><p>⎕GTK has different function signatures, which follow a simple rule:</p></div>
1694 <div class="ulist"><ul>
1695 <li>
1696 <p>
1697 functions that address a GUI (opened with some .ui file) have no axis
1698 argument,
1699 </p>
1700 </li>
1701 <li>
1702 <p>
1703 functions that address widgets inside a GUI have an axis argument such that
1704 </p>
1705 </li>
1706 <li>
1707 <p>
1708 the axis argument is: <strong>H_ID ← H, ID</strong> where H is the GUI handle and ID is
1709 the ID discussed above.
1710 </p>
1711 </li>
1712 </ul></div>
1713 <div class="paragraph"><p>All properties are strings, even though the content of some widgets can
1714 only be numbers. Currently only a small subset of the many existing GTK
1715 functions are implemented in <strong>⎕GTK</strong> and Gtk_server. However, the mapping from
1716 <strong>⎕GTK</strong> functions to functions in libGtk can be easily extended by:</p></div>
1717 <div class="ulist"><ul>
1718 <li>
1719 <p>
1720 adding new mappings to src/Gtk/Gtk_map.def
1721 </p>
1722 </li>
1723 <li>
1724 <p>
1725 recompiling and re-installing GNU APL
1726 </p>
1727 </li>
1728 </ul></div>
1729 <div class="paragraph"><p>The second step also updates the <strong>⎕GTK</strong> Cheat Sheet in the Appendix below.
1730 We extend our example to set the initial value of the employee to "John Doe",</p></div>
1731 <div class="listingblock">
1732 <div class="content">
1733 <pre>
1734
1735 <code> )CLEAR
1736 GUI_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/my-application.ui'
1737 CSS_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/my-application.css'
1738 Handle ← CSS_path *⎕GTK* GUI_path ⍝ fork Gtk_server and connect to it
1739
1740 H_ID ← Handle, "entry1" ⍝ the Employee: entry
1741 "John Doe" ⎕GTK[H_ID] "set_text" ⍝ set the entry to "John Doe"
1742
1743 6 *⎕GTK* 0 ⍝ close window handle 6
1744 0</code>
1745
1746 </pre>
1747 </div></div>
1748 <div class="paragraph"><p>The GUI now looks like this:</p></div>
1749 <div class="imageblock">
1750 <div class="content">
1751 <img src="glade-4.png" alt="glade-4.png" />
1752 </div>
1753 </div>
1754 <div class="paragraph"><p>Finally, we can read data back from widgets. The following example is rather
1755 crude (just good enough to demonstrate the access to a widget&#8217;s content), but
1756 we will see a smarter way in the next chapter (Managing Events). For the moment
1757 we simply give the user 20 seconds time to enter data in the "Position:" entry
1758 and read the entry data after that time has elapsed (regardless of whether the
1759 user has entered any data or not).</p></div>
1760 <div class="listingblock">
1761 <div class="content">
1762 <pre>
1763
1764 <code> )CLEAR
1765 GUI_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/my-application.ui'
1766 CSS_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/my-application.css'
1767 Handle ← CSS_path *⎕GTK* GUI_path ⍝ fork Gtk_server and connect to it
1768
1769 H_ID ← Handle, "entry1" ⍝ the Employee: entry
1770 "John Doe" ⎕GTK[H_ID] "set_text" ⍝ set the entry to "John Doe"
1771
1772 "Please enter the Position: within 20 seconds..."
1773 ⊣⎕DL 20 ⍝ wait 20 seconds
1774 "End of input interval"
1775
1776 H_ID ← Handle, "entry2" ⍝ H_ID is the Position: entry
1777 ⎕GTK[H_ID] "get_text" ⍝ get the content of entry2
1778
1779 6 *⎕GTK* 0 ⍝ close window handle 6
1780 0</code>
1781
1782 </pre>
1783 </div></div>
1784 <div class="paragraph"><p>Let <strong>B<sub>int</sub></strong> be:</p></div>
1785 <div class="ulist"><ul>
1786 <li>
1787 <p>
1788 the (positive) function number B if B is a positive integer scalar, or
1789 </p>
1790 </li>
1791 <li>
1792 <p>
1793 the function number corresponding to B if B is a function name like
1794 "set_text" above.
1795 </p>
1796 </li>
1797 </ul></div>
1798 <div class="paragraph"><p>Then result of <strong>⎕GTK[H_ID] B</strong> is:</p></div>
1799 <div class="ulist"><ul>
1800 <li>
1801 <p>
1802 <strong>B<sub>int</sub></strong> if the corresponding Gtk function was successful but returns no data
1803 (which is typical for all set_XXX() functions like set_text() above), or
1804 </p>
1805 </li>
1806 <li>
1807 <p>
1808 <strong>-B<sub>int</sub></strong> if the corresponding Gtk function has failed, or
1809 </p>
1810 </li>
1811 <li>
1812 <p>
1813 a vector <strong>B<sub>int</sub>, DATA</strong> if the corresponding Gtk function was successful and
1814 has returned the result <strong>DATA</strong> (which is typical for all <strong>get_XXX()</strong>
1815 functions such as <strong>get_text()</strong> above).
1816 </p>
1817 </li>
1818 </ul></div>
1819 <div class="paragraph"><p>Therefore, even though some Gtk functions (i.e. those having a C/C++ result
1820 type of <strong>void</strong>) do not return values, <strong>⎕GTK</strong> always returns a value.</p></div>
1821 </div>
1822 </div>
1823 </div>
1824 <div class="sect1">
1825 <h2 id="_step_6_managing_events">Step 6: Managing Events</h2>
1826 <div class="sectionbody">
1827 <div class="paragraph"><p>In the example developed so far the transfer of data to and from widgets was
1828 initiated from APL. Of course, giving a user 20 seconds time to enter some
1829 data is a ridiculous approach for a serious application program. What is
1830 needed instead is a way for the GUI to indicate that something of interest has
1831 happened, such as the user pressing the OK button after she has finished her
1832 input. Another option would have been to indicate the end of input by hitting
1833 the return key.</p></div>
1834 <div class="paragraph"><p>If an application program having a GUI is written in C/C++, then events such
1835 as pressing a button or a key on the keyboard are usually forwarded to the
1836 application by means of callback functions. Whenever the events used by the
1837 application change - typically accompanied by a change of the GUI - then the
1838 application needs to be recompiled so that the callbacks are properly updated.</p></div>
1839 <div class="paragraph"><p>Since APL normally has no such thing as a callback function, and since we do
1840 not want to recompile Gtk_server for every APL application, the following
1841 approach is used:</p></div>
1842 <div class="ulist"><ul>
1843 <li>
1844 <p>
1845 Gtk_server currently provides a rather small set of callback functions:
1846 </p>
1847 <div class="ulist"><ul>
1848 <li>
1849 <p>
1850 draw
1851 </p>
1852 </li>
1853 <li>
1854 <p>
1855 destroy
1856 </p>
1857 </li>
1858 <li>
1859 <p>
1860 row_selected
1861 </p>
1862 </li>
1863 <li>
1864 <p>
1865 clicked
1866 </p>
1867 </li>
1868 <li>
1869 <p>
1870 changed
1871 </p>
1872 </li>
1873 <li>
1874 <p>
1875 check_resize
1876 </p>
1877 </li>
1878 <li>
1879 <p>
1880 activate
1881 </p>
1882 </li>
1883 <li>
1884 <p>
1885 backspace
1886 </p>
1887 </li>
1888 <li>
1889 <p>
1890 cut_clipboard
1891 </p>
1892 </li>
1893 <li>
1894 <p>
1895 copy_clipboard
1896 </p>
1897 </li>
1898 <li>
1899 <p>
1900 paste_clipboard
1901 </p>
1902 </li>
1903 <li>
1904 <p>
1905 toggle_overwrite
1906 </p>
1907 </li>
1908 <li>
1909 <p>
1910 activate_cursor_row
1911 </p>
1912 </li>
1913 <li>
1914 <p>
1915 toggle_cursor_row
1916 </p>
1917 </li>
1918 <li>
1919 <p>
1920 selected_rows_changed
1921 </p>
1922 </li>
1923 <li>
1924 <p>
1925 select_all
1926 </p>
1927 </li>
1928 <li>
1929 <p>
1930 unselect_all
1931 </p>
1932 </li>
1933 <li>
1934 <p>
1935 toggled
1936 </p>
1937 </li>
1938 <li>
1939 <p>
1940 show
1941 </p>
1942 </li>
1943 <li>
1944 <p>
1945 hide
1946 </p>
1947 </li>
1948 <li>
1949 <p>
1950 map
1951 </p>
1952 </li>
1953 <li>
1954 <p>
1955 unmap
1956 </p>
1957 </li>
1958 <li>
1959 <p>
1960 realize
1961 </p>
1962 </li>
1963 <li>
1964 <p>
1965 unrealize
1966 </p>
1967 </li>
1968 <li>
1969 <p>
1970 composited_changed
1971 </p>
1972 </li>
1973 <li>
1974 <p>
1975 style_updated
1976 </p>
1977 </li>
1978 <li>
1979 <p>
1980 keys_changed
1981 </p>
1982 </li>
1983 </ul></div>
1984 </li>
1985 <li>
1986 <p>
1987 in the <strong>glade</strong> GUI design, the "real" events (called "signals" in the Gtk
1988 documentation) are connected to the above callback functions. An event
1989 emitted by a widget then causes the connected callback function to be
1990 called.
1991 </p>
1992 </li>
1993 <li>
1994 <p>
1995 every callback inserts a single event into an event queue inside <strong>⎕GTK</strong>.
1996 </p>
1997 </li>
1998 <li>
1999 <p>
2000 <strong>⎕GTK</strong> is then used to poll events out of the event queue. The event queue in
2001 <strong>⎕GTK</strong> decouples the creation of an event from the handling of the event.
2002 </p>
2003 </li>
2004 </ul></div>
2005 <div class="paragraph"><p>Note: The Gtk widget class can currently emit around 70 different signals,
2006 while Gtk_server currently provides only a rather small set of callback
2007 functions. This set is supposed to grow over time as the need for new callbacks
2008 arises. However, the plan is <strong>not</strong> to end up with 70 callbacks in Gtk_server.</p></div>
2009 <div class="paragraph"><p>Technically speaking a set of callbacks is sufficient for sending and
2010 identifying every signal in APL if:</p></div>
2011 <div class="ulist"><ul>
2012 <li>
2013 <p>
2014 for every signal with arguments a1, a2, &#8230; aN of type t1, t2, &#8230; tN in Gtk
2015 there is at least one matching callback in Gtk_server to which the signal
2016 can be connected, and
2017 </p>
2018 </li>
2019 <li>
2020 <p>
2021 for every widget that can emit N different signals with the same argument
2022 types (i.e. t1, t2, &#8230; tN) there are N different callbacks to which these
2023 signals can be connected.
2024 </p>
2025 </li>
2026 </ul></div>
2027 <div class="paragraph"><p>In short this means that every signal can be connected to a callback and all
2028 signals emitted by a widget can be connected to different callbacks. If a set
2029 of callbacks satisfy the above then they:</p></div>
2030 <div class="ulist"><ul>
2031 <li>
2032 <p>
2033 make Gtk_server more compact, and
2034 </p>
2035 </li>
2036 <li>
2037 <p>
2038 reduce the size of the APL function(s) decoding the events, but
2039 </p>
2040 </li>
2041 <li>
2042 <p>
2043 possibly decrease the readability of the event decoder because a signal
2044 name may not reflect its true meaning.
2045 </p>
2046 </li>
2047 </ul></div>
2048 <div class="sect2">
2049 <h3 id="_6a_the_life_cycle_of_an_event">6a. The life-cycle of an Event</h3>
2050 <div class="paragraph"><p>It might be useful to briefly describe the entire life-cycle of an event.
2051 Details (like how to do things) will follow after that. We use the example
2052 discussed so far.</p></div>
2053 <div class="paragraph"><p>The entire life-cycle of an event is this:</p></div>
2054 <div class="olist arabic"><ol class="arabic">
2055 <li>
2056 <p>
2057 <strong>Prerequisite:</strong> In <strong>glade</strong>, the signal named <strong>clicked</strong> of the OK button was
2058 connected to the callback function <strong>clicked</strong> in Gtk_server
2059 </p>
2060 </li>
2061 <li>
2062 <p>
2063 The user clicks the green OK button
2064 </p>
2065 </li>
2066 <li>
2067 <p>
2068 Gtk calls the function <strong>clicked()</strong> in the Gtk_server.
2069 </p>
2070 </li>
2071 <li>
2072 <p>
2073 function <strong>clicked()</strong> in the Gtk_server <strong>send()s</strong> the event to APL over the
2074 connection between APL and Gtk_server.
2075 </p>
2076 </li>
2077 <li>
2078 <p>
2079 APL <strong>read()s</strong> the event from the connection between APL and
2080 Gtk_server. and stores it into its event queue.
2081 </p>
2082 </li>
2083 <li>
2084 <p>
2085 the APL application polls the event out of the queue. At this point
2086 the event has become an APL data structure in the APL workspace. The
2087 life-time of the event ends here, but the (application-specific) processing
2088 of the APL data usually continues a little further. In our example, the OK
2089 button was meant to let the user tell when her input was finished, so the
2090 next actions would be to read the contents of the <strong>entry1</strong> and <strong>entry2</strong>
2091 widgets as already described above.
2092 </p>
2093 </li>
2094 </ol></div>
2095 <div class="paragraph"><p>Now to the details &#8230;</p></div>
2096 <div class="sect3">
2097 <h4 id="_6b_connecting_signals_to_gtk_server_callback_functions">6b. Connecting Signals to Gtk_server Callback Functions</h4>
2098 <div class="paragraph"><p>Every signal of a widget that shall be sent to APL needs to be connected in
2099 <strong>glade</strong>:</p></div>
2100 <div class="ulist"><ul>
2101 <li>
2102 <p>
2103 start <strong>glade</strong> with our example GUI file:
2104 </p>
2105 </li>
2106 </ul></div>
2107 <div class="listingblock">
2108 <div class="content">
2109 <pre>
2110
2111 <code>$ glade my-application.ui</code>
2112
2113 </pre>
2114 </div></div>
2115 <div class="ulist"><ul>
2116 <li>
2117 <p>
2118 select the <strong>button1</strong> widget by clicking onto the OK button in the
2119 <strong>GUI visualization area</strong>. The single widget <strong>window1</strong> in the widget
2120 structure area (top-right of the <strong>glade</strong> window) will open and show its
2121 children. One of the children - <strong>button1</strong> is now shown as being selected.
2122 </p>
2123 </li>
2124 <li>
2125 <p>
2126 select the "Signals" tab in the widget property area (bottom-right of the
2127 <strong>glade</strong> window)
2128 </p>
2129 </li>
2130 <li>
2131 <p>
2132 select the row with signal "clicked", which highlights the row in blue
2133 </p>
2134 </li>
2135 <li>
2136 <p>
2137 click on the selected row below the column "Handler", which opens a small
2138 text entry field.
2139 </p>
2140 </li>
2141 <li>
2142 <p>
2143 in the text entry field, enter "clicked", which is the name of the handler
2144 function in Gtk_server that shall be called when widget <strong>button1</strong> was clicked.
2145 [If you need to pass another object to the callback, then enter "clicked_1"
2146 instead of "clicked" and select the object in the dialog that pops up if
2147 you click on "User Data:" in the blue row, Don&#8217;t do that in this example.]
2148 </p>
2149 </li>
2150 <li>
2151 <p>
2152 Finally, save the GUI in <strong>glade</strong>'s menu-bar under <strong>File → Save</strong>.
2153 </p>
2154 </li>
2155 </ul></div>
2156 <div class="paragraph"><p>For those interested in the details, <strong>glade</strong> has added one line to our file
2157 <strong>my-application.ui</strong>:</p></div>
2158 <div class="listingblock">
2159 <div class="content">
2160 <pre>
2161
2162 <code> &lt;signal name="clicked" handler="clicked" swapped="no"/&gt;</code>
2163
2164 </pre>
2165 </div></div>
2166 <div class="paragraph"><p>At this point the <strong>Prerequisite</strong> for sending the clicked signal from
2167 <strong>button1</strong> to APL is met, and steps 2-5 in the life-cycle of an event
2168 happen automatically at the proper point in time, What remains is step 6.</p></div>
2169 </div>
2170 </div>
2171 <div class="sect2">
2172 <h3 id="_6c_polling_the_event_loop_in_apl">6c. Polling the Event Loop in APL</h3>
2173 <div class="paragraph"><p>The event loop can be polled from APL in two fashions: <strong>blocking</strong> or
2174 <strong>non-blocking</strong>. <strong>Blocking</strong> means that the APL functions that do the poll
2175 returns an event to APL immediately if the event has occurred already (e.g.
2176 the user has clicked <strong>button1</strong> <em>before</em> the event queue was polled), and
2177 otherwise waits until that event has occurred. <strong>Non-blocking</strong> means that the
2178 APL functions that do the poll <em>always</em> return immediately, but return a
2179 special event with number 0 to indicate that the event queue was empty at the
2180 time when the poll function was called.</p></div>
2181 <div class="paragraph"><p>Non-blocking calls are inevitably performed in some kind of loop at APL level
2182 and therefore are more complicated. Blocking calls are simpler to program but
2183 stop the APL application until the next event (which may or not be the event
2184 that the application is waiting for) has occurred.</p></div>
2185 <div class="paragraph"><p>Another aspect is the scope of a poll. The APL application can either poll for
2186 an event from a single GUI, or for an event in any of the GUIs that were
2187 started from the interpreter instance.</p></div>
2188 <div class="paragraph"><p>The invocation for a blocking poll is <strong>Z←⎕GTK 1</strong>; The invocation for a
2189 non-blocking poll is <strong>Z←⎕GTK 2</strong>.</p></div>
2190 <div class="paragraph"><p>The return value <strong>Z</strong> of a non-blocking poll is the integer scalar 0 if the
2191 event queue is empty. In all other cases Z is either a 3-element APL vector
2192 <strong>Gi,Ws,Es</strong> or a 4-element APL vector <strong>Gi,Ws,Es,Us</strong> if an event with
2193 <strong>User Data:</strong> Us is received, where:</p></div>
2194 <div class="ulist"><ul>
2195 <li>
2196 <p>
2197 <strong>G</strong> is an integer scalar for the handle of the GUI window in which the event
2198 was created,
2199 </p>
2200 </li>
2201 <li>
2202 <p>
2203 <strong>Ws</strong> is the name of the widget that has created the event (<strong>button1</strong> in our
2204 example),
2205 </p>
2206 </li>
2207 <li>
2208 <p>
2209 <strong>Es</strong> is the name of the signal in <strong>glade</strong> (<strong>clicked</strong> in our example), and
2210 </p>
2211 </li>
2212 <li>
2213 <p>
2214 <strong>Us</strong> (if present) is the name of an object specified as <strong>User Data:</strong> in
2215 <strong>glade</strong>.
2216 </p>
2217 </li>
2218 </ul></div>
2219 </div>
2220 <div class="sect2">
2221 <h3 id="_6d_waiting_for_a_click_event_from_the_ok_button">6d. Waiting for a Click Event from the OK Button</h3>
2222 <div class="paragraph"><p>We are now ready to replace the awkward 20 seconds interval in our example by a
2223 more appropriate one: we give the user as much time as she needs to fill out
2224 the Employee: and Position: fields until she pushes the OK-button to indicate
2225 that the entry of data is complete.</p></div>
2226 <div class="paragraph"><p>Since our GUI only has one relevant event (clicking the OK button; the editing
2227 of the Employee: and Position: fields is managed internally by Gtk), we keep
2228 things simple and use a blocking poll of the <strong>⎕GTK</strong> event queue.
2229 The connection from the OK-button to the GTK callback clicked() was already
2230 done in Step 6b. above (and we assume that the updated my-application.ui is
2231 used). All that is needed then is to replace:</p></div>
2232 <div class="listingblock">
2233 <div class="content">
2234 <pre>
2235
2236 <code> "Please enter the Position: within 20 seconds..."
2237 ⊣⎕DL 20 ⍝ wait 20 seconds
2238 "End of input interval</code>
2239
2240 </pre>
2241 </div></div>
2242 <div class="paragraph"><p>by:</p></div>
2243 <div class="listingblock">
2244 <div class="content">
2245 <pre>
2246
2247 <code> ⊣⎕GTK 1 ⍝ wait for click on the OK button</code>
2248
2249 </pre>
2250 </div></div>
2251 <div class="paragraph"><p>The example therefore becomes:</p></div>
2252 <div class="listingblock">
2253 <div class="content">
2254 <pre>
2255
2256 <code> )CLEAR
2257 GUI_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/my-application.ui'
2258 CSS_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/my-application.css'
2259 Handle ← CSS_path *⎕GTK* GUI_path ⍝ fork Gtk_server and connect to it
2260
2261 H_ID ← Handle, "entry1" ⍝ the Employee: entry
2262 "John Doe" ⎕GTK[H_ID] "set_text" ⍝ set the entry to "John Doe"
2263
2264 *⎕GTK* 1 ⍝ wait for click on the OK button
2265
2266 ⍝ [ at this point the user enters "Engineer" into entry2 and then pushes the OK button ]
2267
2268 H_ID ← Handle, "entry2" ⍝ H_ID is the Position: entry
2269 ⎕GTK[H_ID] "get_text" ⍝ get the content of entry2
2270
2271 Handle *⎕GTK* 0 ⍝ close window handle 6
2272 0</code>
2273
2274 </pre>
2275 </div></div>
2276 </div>
2277 <div class="sect2">
2278 <h3 id="_6e_wrap_up">6e. Wrap-up</h3>
2279 <div class="paragraph"><p>The last thing to do is to put our example code into a defined function. We
2280 remove the H_ID variable (which was only used to make Step 5 above explicit),
2281 and we hide useless return values from <strong>⎕GTK 1</strong> and <strong>⎕GTK[] "get_text"</strong> with ⊣:</p></div>
2282 <div class="listingblock">
2283 <div class="content">
2284 <pre>
2285
2286 <code>∇Z←get_NAME_and_POSITION;GUI_path;CSS_path;Handle
2287 GUI_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/my-application.ui'
2288 CSS_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/my-application.css'
2289 Handle ← CSS_path *⎕GTK* GUI_path ⍝ fork Gtk_server and connect to it
2290 ⊣⎕GTK 1 ⍝ wait for click on the OK button
2291 Z ← ⊂1↓⎕GTK[Handle, "entry1"] "get_text" ⍝ get the content of entry1
2292 Z ← Z,⊂1↓⎕GTK[Handle, "entry2"] "get_text" ⍝ get the content of entry2
2293 ⊣Handle *⎕GTK* 0 ⍝ close the GUI handle
2294 ∇</code>
2295
2296 </pre>
2297 </div></div>
2298 </div>
2299 </div>
2300 </div>
2301 <div class="sect1">
2302 <h2 id="_step_7_optional_custom_drawings">Step 7 (optional): Custom Drawings</h2>
2303 <div class="sectionbody">
2304 <div class="paragraph"><p>Gtk provides the widget type GtkDrawingArea that can be used to create, for
2305 example, a canvas onto which one can draw lines, circles, texts, and so on.
2306 To simplify the drawing onto a canvas from APL, <strong>⎕GTK</strong> provides special
2307 functions for this purpose. The simple example described in the following
2308 explains the steps needed to draw a red circle onto a white background.</p></div>
2309 <div class="sect2">
2310 <h3 id="_7a_the_gui">7a. The GUI</h3>
2311 <div class="paragraph"><p>In <strong>glade</strong>, design a GUI with a top-level widget of type <strong>Window</strong> that has one
2312 child of type <strong>DrawingArea</strong>. That child is the canvas on which the circle will
2313 be drawn. In the <strong>Common</strong> tab of the canvas, set the property <strong>Width request</strong>
2314 to 400 and <strong>Height request</strong> to 300, and store the GUI as file <strong>circle.ui</strong>.
2315 That defines the size of the canvas, In the <strong>Signals</strong> tab, set the handler for
2316 signal <strong>draw</strong> to <strong>do_draw</strong>. The resulting XML file <strong>circle.ui</strong> is then:</p></div>
2317 <div class="listingblock">
2318 <div class="content">
2319 <pre>
2320
2321 <code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
2322 &lt;!-- Generated with glade 3.16.1 --&gt;
2323 &lt;interface&gt;
2324 &lt;requires lib="gtk+" version="3.10"/&gt;
2325 &lt;object class="GtkWindow" id="window1"&gt;
2326 &lt;property name="can_focus"&gt;False&lt;/property&gt;
2327 &lt;child&gt;
2328 &lt;object class="GtkDrawingArea" id="drawingarea1"&gt;
2329 &lt;property name="width_request"&gt;400&lt;/property&gt;
2330 &lt;property name="height_request"&gt;300&lt;/property&gt;
2331 &lt;property name="visible"&gt;True&lt;/property&gt;
2332 &lt;property name="can_focus"&gt;False&lt;/property&gt;
2333 &lt;signal name="draw" handler="do_draw" swapped="no"/&gt;
2334 &lt;/object&gt;
2335 &lt;/child&gt;
2336 &lt;/object&gt;
2337 &lt;/interface&gt;</code>
2338
2339 </pre>
2340 </div></div>
2341 </div>
2342 <div class="sect2">
2343 <h3 id="_7b_apl_start_up_code">7b. APL Start-up Code</h3>
2344 <div class="paragraph"><p>The start-up code for the GUI is similar to the previous example, except that
2345 no CSS file is used:</p></div>
2346 <div class="listingblock">
2347 <div class="content">
2348 <pre>
2349
2350 <code> )CLEAR
2351 GUI_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/circle.ui'
2352 Handle ← *⎕GTK* GUI_path ⍝ fork Gtk_server and connect to it</code>
2353
2354 </pre>
2355 </div></div>
2356 <div class="paragraph"><p>That code alone creates an empty canvas. That empty canvas can then be filled
2357 by means of drawing commands as described below.</p></div>
2358 </div>
2359 <div class="sect2">
2360 <h3 id="_7c_apl_drawing_code">7c. APL Drawing Code</h3>
2361 <div class="paragraph"><p>A single drawing command is a string starting with a keyword followed by
2362 parameters.
2363 An entire drawing is a nested vector of drawing commands. Our simple example
2364 uses four drawing commands: two for filling the canvas background and two for
2365 drawing the red circle. A real-world example would, of course, consist of
2366 many more drawing commands. GNU APL provides two convenient methods for
2367 creating vectors of strings: ⎕INP for strings entered in immediate
2368 execution mode (and therefore also for apl scripts) and multi-line strings
2369 inside defined functions.</p></div>
2370 <div class="paragraph"><p>Our example in immediate execution mode or in an APL scripts could use a
2371 variable, say <strong>DrawCmd</strong>, that is constructed with ⎕INP:</p></div>
2372 <div class="listingblock">
2373 <div class="content">
2374 <pre>
2375
2376 <code> DrawCmd ← ⎕INP '▄'
2377 background 255 255 255 ⍝ white background
2378 fill -color 255 0 0 ⍝ red ellipse at 200:150 with radii 100 and 75
2379 ellipse (200 150) (100 75)
2380 ▄</code>
2381
2382 </pre>
2383 </div></div>
2384 <div class="paragraph"><p>An alternative to a variable is a niladic defined function using multi-line
2385 strings:</p></div>
2386 <div class="listingblock">
2387 <div class="content">
2388 <pre>
2389
2390 <code>∇Z←DrawCmd
2391 Z←1↓"
2392 background 255 255 255 ⍝ white background
2393 fill -color 255 0 0 ⍝ red ellipse at 200:150 with radii 100 and 75
2394 ellipse (200 150) (100 75)"
2395 ∇</code>
2396
2397 </pre>
2398 </div></div>
2399 <div class="paragraph"><p>In both cases <strong>DrawCmd</strong> is a 4-element vector of strings. Once the
2400 <strong>DrawCmd</strong> strings are constructed they are sent to the drawing area widget:</p></div>
2401 <div class="listingblock">
2402 <div class="content">
2403 <pre>
2404
2405 <code> H_ID ← Handle, "drawingarea1"
2406 DrawCmd ⎕GTK[H_ID] "draw_commands"</code>
2407
2408 </pre>
2409 </div></div>
2410 </div>
2411 <div class="sect2">
2412 <h3 id="_7d_wrap_up">7d. Wrap-up</h3>
2413 <div class="paragraph"><p>Putting the pieces above together we get:</p></div>
2414 <div class="listingblock">
2415 <div class="content">
2416 <pre>
2417
2418 <code> )CLEAR
2419 GUI_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/circle.ui'
2420 Handle ← *⎕GTK* GUI_path ⍝ fork Gtk_server and connect to it
2421
2422 DrawCmd ← ⎕INP '▄'
2423 background 255 255 255 ⍝ white background
2424 fill-color 255 0 0 ⍝ red ellipse at 200:150 with radii 100 and 75
2425 ellipse (200 150) (100 75)
2426 ▄
2427
2428 H_ID ← Handle, "drawingarea1"
2429 DrawCmd ⎕GTK[H_ID] "draw_commands"</code>
2430
2431 </pre>
2432 </div></div>
2433 <div class="paragraph"><p>The GUI created by the APL code above then looks like this:</p></div>
2434 <div class="imageblock">
2435 <div class="content">
2436 <img src="glade-5.png" alt="glade-5.png" />
2437 </div>
2438 </div>
2439 <div class="paragraph"><p>A slightly more advanced example that uses the same XML file <strong>circle.ui</strong> but
2440 different drawing commands to show additional features (lines, text, objects
2441 with and without borders is:</p></div>
2442 <div class="listingblock">
2443 <div class="content">
2444 <pre>
2445
2446 <code> )CLEAR
2447 GUI_path ← '/home/eedjsa/projects/juergen/apl-1.7/HOWTOs/circle.ui'
2448 Handle ← *⎕GTK* GUI_path ⍝ fork Gtk_server and connect to it
2449
2450 DrawCmd ← ⎕INP '▄'
2451 background 208 208 255 ⍝ blueish background
2452 line-color 0 0 0 255 ⍝ black opaque pen → areas have a border
2453 line-width 200%
2454 text (40 20) shapes with line-width = 200%
2455 line (0 140) (400 140)
2456 fill-color 0 160 0 ⍝ green rectangle...
2457 rectangle (20 60) (80 100)
2458 fill-color 255 255 0 ⍝ yellow circle...
2459 circle (130 80) 30
2460 fill-color 255 0 0 ⍝ red ellipse...
2461 ellipse (250 80) (50 30)
2462 fill-color 128 128 255 ⍝ blue triangle...
2463 polygon (320 60) (380 60) (350 100)
2464 line-color 0 0 0 0 ⍝ transparent pen → areas have no border
2465 font-family monospace
2466 text (40 170) shapes without a border
2467 fill-color 0 160 0 ⍝ green rectangle...
2468 rectangle (20 210) (60 250)
2469 fill-color 255 255 0 ⍝ yellow circle...
2470 circle (130 230) 30
2471 fill-color 255 0 0 ⍝ red ellipse...
2472 ellipse (250 230) (50 30)
2473 fill-color 128 128 255 ⍝ blue triangle...
2474 polygon (320 210) (380 210) (350 250)·
2475 ▄
2476
2477 H_ID ← Handle, "drawingarea1"
2478 DrawCmd ⎕GTK[H_ID] "draw_commands"</code>
2479
2480 </pre>
2481 </div></div>
2482 <div class="paragraph"><p>It produces the following GUI:</p></div>
2483 <div class="imageblock">
2484 <div class="content">
2485 <img src="glade-6.png" alt="glade-6.png" />
2486 </div>
2487 </div>
2488 </div>
2489 <div class="sect2">
2490 <h3 id="_7e_notes">7e. Notes</h3>
2491 <div class="paragraph"><p>The following notes may be helpful when creating custom drawings.</p></div>
2492 <div class="ulist"><ul>
2493 <li>
2494 <p>
2495 The <a href="#TAG_appendix">Appendix</a> contains a <a href="#Tag_table4">table</a> that lists
2496 the syntax of all drawing commands that are currently understood by <strong>⎕GTK</strong>.
2497 </p>
2498 </li>
2499 <li>
2500 <p>
2501 Every call of <strong>DrawCommands ⎕GTK[] "draw_commands"</strong> overrides the previous
2502 one. If a drawing cannot be created in one go (like above) then you need to
2503 collect pieces into a single <strong>DrawCommands</strong> variable <strong>before</strong> calling <strong>⎕GTK</strong>
2504 (once). The need to construct a drawing in pieces typically occurs when the
2505 drawing commands are being computed (e.g. when writing a data plotting
2506 application).
2507 </p>
2508 </li>
2509 <li>
2510 <p>
2511 Opaque colors are specified as a 3-element vector containing the red, green,
2512 and blue component of each color. Each color component is an integer value
2513 between 0 and 255 (inclusive), The background is always opaque.
2514 </p>
2515 </li>
2516 <li>
2517 <p>
2518 Transparent colors are specified as a 4-element vector containing the red,
2519 green, and blue component of each color (o-255), and an opacity value
2520 between 0 (fully transparent) and 100 (fully opaque).
2521 </p>
2522 </li>
2523 <li>
2524 <p>
2525 Most graphical objects are controlled by two colors:
2526 </p>
2527 <div class="ulist"><ul>
2528 <li>
2529 <p>
2530 A line color (called the <strong>pen</strong> color in other places), and
2531 </p>
2532 </li>
2533 <li>
2534 <p>
2535 A fill color (called "brush* color elsewhere).
2536 </p>
2537 </li>
2538 <li>
2539 <p>
2540 The opaqueness of the line and fill colors can be used to control how a
2541 2-dimensional object is painted:
2542 </p>
2543 <div class="ulist"><ul>
2544 <li>
2545 <p>
2546 Fill color opacity = 0: (only) the border (in line color), or
2547 </p>
2548 </li>
2549 <li>
2550 <p>
2551 Line color opacity = 0: (only) the area inside the border (in fill color),
2552 or else
2553 </p>
2554 </li>
2555 <li>
2556 <p>
2557 a combination of the above according to the two opacity values
2558 </p>
2559 </li>
2560 </ul></div>
2561 </li>
2562 <li>
2563 <p>
2564 A pen width of 0 has the same effect as a pen color opacity of 0, although
2565 for different reasons.
2566 </p>
2567 </li>
2568 </ul></div>
2569 </li>
2570 <li>
2571 <p>
2572 Lines are 1-dimensional and therefore have no fill color. They are painted
2573 with the line color.
2574 </p>
2575 </li>
2576 <li>
2577 <p>
2578 To simplify the drawing of objects, colors are not assigned to
2579 individual objects, but are sent once using one of the following commands:
2580 </p>
2581 <div class="ulist"><ul>
2582 <li>
2583 <p>
2584 <strong>background R G B</strong>
2585 </p>
2586 </li>
2587 <li>
2588 <p>
2589 <strong>fill-color R G B [A]</strong>
2590 </p>
2591 </li>
2592 <li>
2593 <p>
2594 <strong>fill color R G B [A]</strong>
2595 </p>
2596 </li>
2597 <li>
2598 <p>
2599 the optional parameter A controls the opacity
2600 </p>
2601 </li>
2602 </ul></div>
2603 </li>
2604 <li>
2605 <p>
2606 these color commands are then applied to subsequent drawing commands,
2607 </p>
2608 </li>
2609 <li>
2610 <p>
2611 Valid font names are system-specific, but at least the generic names used in
2612 CSS2 (i.e. <strong>serif</strong>, <strong>sans-serif</strong>, <strong>cursive</strong>, <strong>fantasy</strong>, <strong>monospace</strong> are
2613 supposed to work,
2614 </p>
2615 </li>
2616 </ul></div>
2617 </div>
2618 </div>
2619 </div>
2620 <div class="sect1">
2621 <h2 id="TAG_programmatically">8 Specifying GUIs Programmatically</h2>
2622 <div class="sectionbody">
2623 <div class="paragraph"><p>A GUI builder like <strong>glade</strong> can give you a quick head start if you are
2624 not yet familiar with the development of GUIs with GTK. However, it also
2625 has some limitations and disadvantages, for example:</p></div>
2626 <div class="ulist"><ul>
2627 <li>
2628 <p>
2629 not all GTK widgets or objects have an XML representation (this is actually
2630 a limitation of GTK class GtkBuilder which reads the .ui files produced by
2631 glade).
2632 </p>
2633 </li>
2634 <li>
2635 <p>
2636 workspaces that depend on additional files (XML or CSS) are more difficult
2637 to distribute than self-contained (i.e. single-file) workspaces
2638 </p>
2639 </li>
2640 <li>
2641 <p>
2642 regular structures like horizontally or vertically aligned sets of widgets
2643 are cumbersome to create or maintain.
2644 </p>
2645 </li>
2646 </ul></div>
2647 <div class="paragraph"><p>For this reason the filename (APL string) arguments <strong>A</strong> and <strong>B</strong> of dyadic
2648 <strong>A *⎕GTK</strong> B* and monadic <strong>⎕GTK B</strong> can also be the contents of the files instead
2649 of the file names. Most <strong>.ui</strong> files (as produced by glade) and in particular
2650 the .css (if any) files are reasonably small. It makes therefore a lot of
2651 sense, to construct the contents (i.e. strings) of these files directly in
2652 APL rather than loading them from external files produced elsewhere. GNU APL
2653 is shipped with an example workspace <strong>workspaces/SQL_GUI.apl</strong> that could serve
2654 as a starting point for your own, self-contained GUI. This workspace is
2655 reasonably well documented, but some related concepts may be helpful to note
2656 before looking into the APL code of that workspace.</p></div>
2657 <div class="sect2">
2658 <h3 id="_8_1_what_glade_actually_does">8.1 What glade actually does</h3>
2659 <div class="paragraph"><p>In short, glade produces an XML string that is understood by <strong>⎕GTK</strong>. It
2660 normally stores it in some file, say <strong>my-gui.xml</strong>, that can later be
2661 loaded with <strong>⎕GTK "my-gui.xml"</strong> or with <strong>CSS *⎕GTK</strong> "my-gui.xml"* where
2662 CSS is a string produced elsewhere (and not of concern here).</p></div>
2663 <div class="paragraph"><p>Lets start with:</p></div>
2664 <div class="olist arabic"><ol class="arabic">
2665 <li>
2666 <p>
2667 start <strong>glade</strong>,
2668 </p>
2669 </li>
2670 <li>
2671 <p>
2672 → Create a new project,
2673 </p>
2674 </li>
2675 <li>
2676 <p>
2677 → add a new <strong>Toplevel</strong> widget of type <strong>GtkWindow</strong>, and
2678 </p>
2679 </li>
2680 <li>
2681 <p>
2682 → select the new window and set the (topmost) property <strong>ID</strong>
2683 in tab <strong>Genera</strong> to <strong>window1</strong>
2684 </p>
2685 </li>
2686 <li>
2687 <p>
2688 → <strong>Save as</strong> the project as <strong>my-gui</strong>.
2689 </p>
2690 </li>
2691 </ol></div>
2692 <div class="paragraph"><p>This produces a file named <strong>my-gui.glade</strong> in the current directory.
2693 Opening this file with a text editor shows its content:</p></div>
2694 <div class="listingblock">
2695 <div class="content">
2696 <pre>
2697
2698 <code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
2699 &lt;!-- Generated with glade 3.22.1 --&gt;
2700 &lt;interface&gt;
2701 &lt;requires lib="gtk+" version="3.20"/&gt;
2702 &lt;object class="GtkWindow" id="window1"&gt;
2703 &lt;property name="can_focus"&gt;False&lt;/property&gt;
2704 &lt;child&gt;
2705 &lt;placeholder/&gt;
2706 &lt;/child&gt;
2707 &lt;child&gt;
2708 &lt;placeholder/&gt;
2709 &lt;/child&gt;
2710 &lt;/object&gt;
2711 &lt;/interface&gt;</code>
2712
2713 </pre>
2714 </div></div>
2715 <div class="paragraph"><p>Comparing step 4. above with line 5 of <strong>my-gui.glade</strong>, i.e.</p></div>
2716 <div class="listingblock">
2717 <div class="content">
2718 <pre>
2719
2720 <code> &lt;object class="GtkWindow" id="window1"&gt;</code>
2721
2722 </pre>
2723 </div></div>
2724 <div class="paragraph"><p>exposes the primary functionality of <strong>glade</strong>: producing XML templates and
2725 filling in fields in those templates according to choices made by the user (the
2726 window ID <strong>window1</strong> in this simple example). The two <strong>&lt;child&gt;</strong> tags with content
2727 <strong>&lt;placeholder/&gt;</strong> are used by <strong>glade</strong> to simplify a later replacement with
2728 other widgets and have no effect.</p></div>
2729 <div class="paragraph"><p>File <strong>my-gui.glade</strong> is already a fully functional GUI (albeit empty and thus
2730 boring) that can be used in APL via <strong>⎕GTK</strong>:</p></div>
2731 <div class="listingblock">
2732 <div class="content">
2733 <pre>
2734
2735 <code> *⎕GTK* "my-gui.glade"
2736 6</code>
2737
2738 </pre>
2739 </div></div>
2740 <div class="paragraph"><p>This returns GTK handle 6 and opens the following GUI:</p></div>
2741 <div class="imageblock">
2742 <div class="content">
2743 <img src="glade-7.png" alt="glade-7.png" />
2744 </div>
2745 </div>
2746 <div class="paragraph"><p>Now, lets test the claim above: <em>the filename (APL string) arguments <strong>A</strong>
2747 and <strong>B</strong> of dyadic <strong>A *⎕GTK</strong> B* and monadic <strong>⎕GTK B</strong> can also be the contents
2748 of the files instead of the file names</em>:</p></div>
2749 <div class="listingblock">
2750 <div class="content">
2751 <pre>
2752
2753 <code> )CLEAR
2754 CLEAR WS
2755
2756 XML←"""
2757 &lt;?xml version="1.0" encoding="UTF-8"?&gt;
2758 &lt;!-- Generated with glade 3.22.1 --&gt;
2759 &lt;interface&gt;
2760 &lt;requires lib="gtk+" version="3.20"/&gt;
2761 &lt;object class="GtkWindow" id="window1"&gt;
2762 &lt;property name="can_focus"&gt;False&lt;/property&gt;
2763 &lt;child&gt;
2764 &lt;placeholder/&gt;
2765 &lt;/child&gt;
2766 &lt;child&gt;
2767 &lt;placeholder/&gt;
2768 &lt;/child&gt;
2769 &lt;/object&gt;
2770 &lt;/interface&gt;
2771 """
2772
2773 ⍴XML ⍝ number of nested APL strings between """ ... """
2774 14
2775
2776 *⎕GTK* 36 ⎕CR XML
2777 6</code>
2778
2779 </pre>
2780 </div></div>
2781 <div class="paragraph"><p>Voila, the same window as above pops up:</p></div>
2782 <div class="imageblock">
2783 <div class="content">
2784 <img src="glade-7.png" alt="glade-7.png" />
2785 </div>
2786 </div>
2787 <div class="paragraph"><p>To see why, we note the following:</p></div>
2788 <div class="ulist"><ul>
2789 <li>
2790 <p>
2791 The text lines between the first and the second """ above constitutes a
2792 multi-line string (a non-standard GNU APL feature, see <strong>info apl</strong> for details).
2793 </p>
2794 </li>
2795 <li>
2796 <p>
2797 Every line becomes a nested (string) component of the multi-line string. The
2798 multi-line string is then assigned to variable <strong>XML</strong>. Therefore <strong>⍴XML</strong>
2799 is 14 for the 14 lines of text between """ and """.
2800 </p>
2801 </li>
2802 <li>
2803 <p>
2804 <strong>⎕GTK B</strong> expects B to be a simple APL vector (aka. APL string) where
2805 multiple lines are separated by newline characters and not a vector of
2806 nested APL strings. <strong>36 ⎕CR XML</strong> does the required conversion from
2807 nested APL strings to a simple APL string with <strong>\n</strong> aka. <strong>ASCII FL</strong> as
2808 line separator.
2809 </p>
2810 </li>
2811 <li>
2812 <p>
2813 the XML standard treats newlines and blanks alike, therefore the string
2814 lines could have been separated by blanks (or tabs etc.) as well. However,
2815 no corrsponding ⎕CR conversion exists, so <strong>36 ⎕CR</strong> was used and long XML
2816 strings using \n are easier to read than those using blanks or TABs.
2817 </p>
2818 </li>
2819 </ul></div>
2820 <div class="paragraph"><p>All properties of the new windows, like its size, caption, etc. are set to
2821 their defaults. We will explain, by means of examples, how to change that in
2822 the following description.</p></div>
2823 </div>
2824 <div class="sect2">
2825 <h3 id="_8_2_some_gtk_and_glade_details">8.2 Some GTK (and glade) details</h3>
2826 <div class="paragraph"><p>As already mentioned, <strong>glade</strong> produces an XML file that describes the desired
2827 GUI on the one hand, and GTK, more precisely a GTK object (of type
2828 <strong>GtkBuilder</strong>) on the other. The GtkBuilder provides functions that read the
2829 XML file or string and creates (instantiates) the widget objects needed to
2830 do so. This works by means of a naming convention between the XML text file
2831 (produced by glade or, as here, by APL) and the C source files (actually C
2832 header files) that come with the GTK libraries. The GTK header files are
2833 usually installed in either <strong>/usr/include/gtk-3.0/gtk/</strong> or else in
2834 <strong>/usr/local/include/gtk-3.0/gtk/</strong>.</p></div>
2835 <div class="paragraph"><p>You can use <strong>⎕GTK</strong> without any C/C++ knowledge, but looking at some of the
2836 header files (i.e. files with extension <strong>.h</strong>) may help in understanding the
2837 naming conventions between XML and GTK. Understanding (and following) this
2838 naming convention is essential for producing a proper XML description for
2839 a GUI.</p></div>
2840 <div class="paragraph"><p>In variable XML above, we have already seen the first (and so far only)
2841 GTK widget, i.e. <strong>window</strong>:</p></div>
2842 <div class="listingblock">
2843 <div class="content">
2844 <pre>
2845
2846 <code> &lt;object class="GtkWindow" id="window1"&gt;
2847 ...
2848 &lt;/object&gt;</code>
2849
2850 </pre>
2851 </div></div>
2852 <div class="paragraph"><p>To fully understand the naming conventions we use two more widgets with
2853 compound names: <strong>gtktextview</strong> and <strong>gtktreeviewcolumn</strong>. We call the
2854 names <strong>window</strong>, <strong>gtktextview</strong>, and <strong>gtktreeviewcolumn</strong> the *core name*s
2855 of the widgets. Every relevant naming convention (XML uses only some of
2856 them but we will explain them all) start with the core name of a widget
2857 and produces similar looking names as described in the following sections.</p></div>
2858 <div class="sect3">
2859 <h4 id="_core_name">Core Name</h4>
2860 <div class="paragraph"><p>A core name is a sequence of lowercase (!) ASCII characters a..z.</p></div>
2861 <div class="paragraph"><p>Neither digits 0..9, nor underscore (_), nor minus (-) or other non-alphabetic
2862 characters are part of a core name. These characters are instead used to derive
2863 other name variants from a core name.</p></div>
2864 <div class="paragraph"><p>As already mentioned, the examples discussed here use the core names <strong>window</strong>,
2865 <strong>gtktextview</strong>, and <strong>gtktreeviewcolumn</strong>. The other core names then follow suit.
2866 ..</p></div>
2867 </div>
2868 <div class="sect3">
2869 <h4 id="_header_file_name">Header File Name</h4>
2870 <div class="paragraph"><p>The name of the header file for <strong>corename</strong> is <strong>gtkcorename.h</strong>. Therefore, the
2871 header files in our example are: <strong>gtkwindow.h</strong>, <strong>gtktextview.h</strong>, and
2872 <strong>gtktreeviewcolumn.h</strong></p></div>
2873 <div class="paragraph"><p>Depending on the platform, all these header files are most likely located in
2874 directory <strong>/usr/include/gtk-3.0/gtk/</strong> or .<strong>/usr/local/include/gtk-3.0/gtk/</strong>,
2875 or sometimes below /opt.</p></div>
2876 <div class="paragraph"><p>The user is normally not concerned with these header files. They are sometimes
2877 helpful to disambiguate core names. For example, to decide (below) if
2878 <strong>treeviewcolumn</strong> should mean 3 words <strong>tree-view-column</strong> or 2 words
2879 <strong>treeview-column</strong>.</p></div>
2880 </div>
2881 <div class="sect3">
2882 <h4 id="_object_class">Object Class</h4>
2883 <div class="paragraph"><p>Every widget is an instance of an associated class which is declared in the
2884 corresponding header file. The class for <strong>corename</strong> is either <strong>GtkCoreName</strong> or
2885 GtkCorename*. In our example the class names are <strong>GtkWidget</strong>, <strong>GtkTextView</strong>,
2886 and <strong>GtkTreeViewColumn</strong>.</p></div>
2887 <div class="paragraph"><p>Confusingly, many widget not only declare the class name as described, but
2888 in addition another class with suffix <strong>Class</strong>. For instance both
2889 <strong>GtkTreeViewColumn</strong> and <strong>GtkTreeViewColumnClass</strong> in <strong>gtktreeviewcolumn.h</strong>.</p></div>
2890 <div class="paragraph"><p>The name variant with the <strong>Class</strong> suffix is not used by <strong>⎕GTK</strong>.</p></div>
2891 <div class="paragraph"><p>As of this writing it is not entirely clear if the XML attribute
2892 <strong>class="GtkWindow"</strong> above refers to a GTK object class or to a CSS style class
2893 (since both exist). For the moment we assume a GTK object class; GtkServer
2894 does not use it, but the <strong>GtkBuilder</strong> may in some way.</p></div>
2895 </div>
2896 <div class="sect3">
2897 <h4 id="_object_id">Object ID</h4>
2898 <div class="paragraph"><p>The &lt;object &#8230;&gt; tag in XML may or may not contain the optional XML
2899 attribute <strong>id=</strong> (see above). In many cases the ID is not needed and should
2900 then not be mentioned in the XML. The relevant exceptions (in which cases
2901 the ID is mandatory) are:</p></div>
2902 <div class="ulist"><ul>
2903 <li>
2904 <p>
2905 top-level windows. <strong>⎕GTK</strong> uses the ID of the top-level window to find the
2906 GTK object with that ID.
2907 </p>
2908 </li>
2909 <li>
2910 <p>
2911 widgets for which APL calls widget functions (i.e. <strong>Z←⎕GTK[H_ID]
2912 "function-name"</strong> or <strong>Z←A ⎕GTK[H_ID] "function-name"</strong>.
2913 </p>
2914 </li>
2915 </ul></div>
2916 <div class="paragraph"><p>The object ID of a widget consists of an <strong>ID-prefix</strong> and an <strong>ID-suffix</strong>
2917 according to these rules:</p></div>
2918 <div class="ulist"><ul>
2919 <li>
2920 <p>
2921 The <strong>ID-prefix</strong> is the leading lowercase ASCII characters a..z of some name,
2922 </p>
2923 </li>
2924 <li>
2925 <p>
2926 The <strong>ID-suffix</strong> is the trailing characters of that name, i.e. the suffix
2927 does NOT start with a lowercase ASCII character a..z.
2928 </p>
2929 </li>
2930 <li>
2931 <p>
2932 The <strong>ID-prefix</strong> should be the same as the function name prefix explained below.
2933 </p>
2934 </li>
2935 </ul></div>
2936 <div class="paragraph"><p>The purpose of the <strong>ID-suffix</strong> is to distinguish different instances of the
2937 same widget, e.g multiple buttons in the same window.</p></div>
2938 <div class="paragraph"><p>In older glade versions, the <strong>ID-suffixes</strong> were automatically set to 0, 1, 2,
2939 &#8230; for multiple instances of the same widget class (but could be changed by
2940 the user). In newer glade versions the ID is left empty by default. For that
2941 reason we had to do Step 4:</p></div>
2942 <div class="listingblock">
2943 <div class="content">
2944 <pre>
2945
2946 <code>→ select the new window and set the (topmost) property ID in tab Genera to window1</code>
2947
2948 </pre>
2949 </div></div>
2950 <div class="paragraph"><p>above.</p></div>
2951 </div>
2952 <div class="sect3">
2953 <h4 id="_widget_function_prefix">Widget Function Prefix</h4>
2954 <div class="paragraph"><p>Every widget has a number of associated functions. The same function name
2955 may be used for different widget classes. For example. many widgets have a
2956 <strong>get_value()</strong> function.</p></div>
2957 <div class="paragraph"><p>In C++ interfaces to GTK a widget like <strong>window</strong> is declared in header file
2958 <strong>window.h</strong>, declare a <strong>namespace Gtk</strong>, a C++ class <strong>Window</strong> inside namespace
2959 <strong>Gtk</strong>, and member functions fun1, fun2, &#8230; of that class.</p></div>
2960 <div class="paragraph"><p>⎕GTK uses the C interface instead and the C++ luxury of namespaces and classes
2961 become function name prefixes. This makes</p></div>
2962 <div class="listingblock">
2963 <div class="content">
2964 <pre>
2965
2966 <code> Gtk::Window::fun1(args...) in C++, and
2967 gtk_window_fun1(gtk_window *, args...) in C</code>
2968
2969 </pre>
2970 </div></div>
2971 <div class="paragraph"><p>essentially the same. Coming back to our example, the widget name prefixes are
2972 <strong>gtk_window_</strong>, <strong>gtk_text_view_</strong>, and <strong>gtk_tree_view_column</strong>.</p></div>
2973 </div>
2974 </div>
2975 <div class="sect2">
2976 <h3 id="_8_3_how_a_gtk_h_id_b_works">8.3 How (A) ⎕GTK[H_ID] B works</h3>
2977 <div class="paragraph"><p>Let:</p></div>
2978 <div class="listingblock">
2979 <div class="content">
2980 <pre>
2981
2982 <code>H←⎕GTK 36 ⎕CR XML ⍝ i.e. 6 as above
2983 H_ID← H, "window1" ⍝ handle and widget ID
2984 "MY-TITLE" ⎕GTK[H_ID] "set_title" ⍝</code>
2985
2986 </pre>
2987 </div></div>
2988 <div class="paragraph"><p>Then the <strong>⎕GTK</strong> calls above hopefully do this:</p></div>
2989 <div class="olist arabic"><ol class="arabic">
2990 <li>
2991 <p>
2992 The first <strong>⎕GTK</strong> call opens a new GUI window according to XML
2993 </p>
2994 </li>
2995 <li>
2996 <p>
2997 The second <strong>⎕GTK</strong> call splits <strong>H_ID</strong> into the numeric handle <strong>H</strong> (a
2998 connection to a separate process that handles the events of the window)
2999 and a string <strong>ID</strong> which is the Object ID of a widget in that window.
3000 </p>
3001 </li>
3002 <li>
3003 <p>
3004 The widget class (= the ID prefix <strong>window</strong> of the ID <strong>window1</strong> and the
3005 right <strong>⎕GTK</strong> argument (= <strong>set_title</strong>) are combined into the window function
3006 name <strong>gtk_window_set_title</strong>. This function (in the GTK library) is called
3007 and its result is returned.
3008 </p>
3009 </li>
3010 <li>
3011 <p>
3012 In step 3. the function arguments and the function result (if any) are
3013 trans-coded between APL values and C values. For this reason, only widget
3014 functions whose arguments and/or results are integer (including enums) or
3015 strings can be supported by <strong>⎕GTK</strong>. This is fortunately the case for the
3016 majority of widget functions.
3017 </p>
3018 </li>
3019 </ol></div>
3020 <div class="paragraph"><p>Adding the second <strong>⎕GTK</strong> call to our code gives:</p></div>
3021 <div class="listingblock">
3022 <div class="content">
3023 <pre>
3024
3025 <code> )CLEAR
3026 CLEAR WS
3027
3028 XML←"""
3029 &lt;?xml version="1.0" encoding="UTF-8"?&gt;
3030 &lt;!-- Generated with glade 3.22.1 --&gt;
3031 &lt;interface&gt;
3032 &lt;requires lib="gtk+" version="3.20"/&gt;
3033 &lt;object class="GtkWindow" id="window1"&gt;
3034 &lt;property name="can_focus"&gt;False&lt;/property&gt;
3035 &lt;child&gt;
3036 &lt;placeholder/&gt;
3037 &lt;/child&gt;
3038 &lt;child&gt;
3039 &lt;placeholder/&gt;
3040 &lt;/child&gt;
3041 &lt;/object&gt;
3042 &lt;/interface&gt;
3043 """
3044
3045 H←⎕GTK 36 ⎕CR XML ⍝ display GUI defined by XML
3046 H_ID← H, "window1" ⍝ handle and widget ID (in XML)
3047 "MY-TITLE" ⎕GTK[H_ID] "set_title" ⍝ calls gtk_window_set_title()</code>
3048
3049 </pre>
3050 </div></div>
3051 <div class="paragraph"><p>and, when executed, this GUI:</p></div>
3052 <div class="imageblock">
3053 <div class="content">
3054 <img src="glade-8.png" alt="glade-8.png" />
3055 </div>
3056 </div>
3057 <div class="paragraph"><p>A little quirk in this example (which is beyond the control of <strong>⎕GTK</strong> or
3058 Gtk_server) is that the new window title <strong>MY-TITLE</strong> does not show immediately
3059 but only after the window obtains the focus again. This is most likely platform
3060 dependent.</p></div>
3061 <div class="paragraph"><p>At this point, two issues related to widget functions may be worthwhile
3062 to mention:</p></div>
3063 <div class="olist arabic"><ol class="arabic">
3064 <li>
3065 <p>
3066 In most cases the widget function is a function of the widget itself.
3067 Sometimes, however, the desired function is not a function of the widget
3068 itself (such functions have the widget as their first argument in C), but
3069 a function of some ancestor class of the widget. The GTK documentation
3070 for a widget usually lists the ancestor(s) of the widget under the topic
3071 <strong>Hierarchy</strong> and/or <strong>Ancestors</strong>. Note that the parent/child relation in
3072 XML refers to (visual) containment (<em>buttons A and B are contained (placed
3073 inside) window W</em>) while the ancestor relation refers to class containment
3074 (<em>GtkButton A can also call the functions of its ancestor classes, in
3075 particular of its ancestor GtkWidget</em>).+
3076 <br />
3077 For example. we use widgets of class <strong>GtkButton</strong> for buttons, If we were
3078 interested in the state (pushed or not pushed) of some button, then we
3079 would maybe like to call the widget function that tells us, which is
3080 function <strong>get_state_flags</strong>. Unfortunately <strong>get_state_flags</strong> is not a
3081 widget function of class <strong>GtkButton</strong>, but a widget function of its
3082 ancestor class <strong>GtkWidget</strong><br />
3083 <br />
3084 If we would try to call monadic <strong>⎕GTK[H_ID]'get_state_flags'</strong> with the
3085 <strong>H_ID</strong> for some button, then this would ask the Gtk_server to call the
3086 C function <strong>gtk_button_get_state_flags()</strong>, which is wrong because no such
3087 function exists. Instead we should have asked the Gtk_server to call the
3088 C function <strong>gtk_widget_get_state_flags()</strong>.<br />
3089 <br />
3090 Such cases are resolved by prefixing the function name with the name of the
3091 ancestor class that actually defines the function, separated by ::.
3092 In this example, the proper APL code would have been
3093 <strong>⎕GTK[H_ID]'GtkWidget::get_state_flags'</strong>.<br />
3094 </p>
3095 </li>
3096 </ol></div>
3097 <div class="paragraph"><p>Most widget functions of interest are used to construct the GUI and return
3098 no value. Some, like <strong>GtkWidget::get_state_flags</strong>, do return a value. In
3099 that case the result Z is a (possibly mixed) vector. The first vector component
3100 <strong>↑Z</strong> is the function number (APL integer) of the function that has returned
3101 the result. The rest <strong>1↓Z</strong> is the result itself (an APL integer, APL Float,
3102 or a (not enclosed) string.</p></div>
3103 </div>
3104 <div class="sect2">
3105 <h3 id="_8_4_adding_window_properties">8.4 Adding Window Properties</h3>
3106 <div class="paragraph"><p>The XML for a widget in a GUI defines how the widget looks initially.
3107 In our previous example above:</p></div>
3108 <div class="ulist"><ul>
3109 <li>
3110 <p>
3111 the top-level <strong>window</strong> was created with its default title <strong>Gtk)server</strong>,
3112 </p>
3113 </li>
3114 <li>
3115 <p>
3116 the default title was then changed to <strong>MY-TITLE</strong> by calling widget function
3117 <strong>set_title</strong>.
3118 </p>
3119 </li>
3120 </ul></div>
3121 <div class="paragraph"><p>A better approach, which works for most but maybe not all properties is
3122 to specify them in XML <strong>before</strong> the widget is created and not by calling
3123 a corresponding widget function <strong>after</strong> the widget was created. This
3124 is achieved by XML tag &lt;property&gt;. In the case of the window title the
3125 property is called <strong>title</strong> (another GTK naming convention):</p></div>
3126 <div class="listingblock">
3127 <div class="content">
3128 <pre>
3129
3130 <code> &lt;property name="title"&gt;MY-TITLE&lt;/property&gt;</code>
3131
3132 </pre>
3133 </div></div>
3134 <div class="paragraph"><p>Our complete code is now (observe how MY-TITLE has moved from APL to XML:</p></div>
3135 <div class="listingblock">
3136 <div class="content">
3137 <pre>
3138
3139 <code> )CLEAR
3140 CLEAR WS
3141
3142 XML←"""
3143 &lt;?xml version="1.0" encoding="UTF-8"?&gt;
3144 &lt;!-- Generated with glade 3.22.1 --&gt;
3145 &lt;interface&gt;
3146 &lt;requires lib="gtk+" version="3.20"/&gt;
3147 &lt;object class="GtkWindow" id="window1"&gt;
3148 &lt;property name="title"&gt;MY-TITLE&lt;/property&gt;
3149 &lt;property name="can_focus"&gt;False&lt;/property&gt;
3150 &lt;child&gt;
3151 &lt;placeholder/&gt;
3152 &lt;/child&gt;
3153 &lt;child&gt;
3154 &lt;placeholder/&gt;
3155 &lt;/child&gt;
3156 &lt;/object&gt;
3157 &lt;/interface&gt;
3158 """
3159
3160 H←⎕GTK 36 ⎕CR XML ⍝ display GUI defined by XML</code>
3161
3162 </pre>
3163 </div></div>
3164 <div class="paragraph"><p>The GUI looks as before but the focus quirk has disappeared since
3165 the proper <strong>MY-TITLE</strong> was set <strong>before</strong> the <strong>window</strong> was created. Properties
3166 are somewhat widget-specific, but most widgets have at least the XML &lt;property&gt;
3167 tags with XML attributes <strong>name="width_request"</strong>, <strong>name="height_request</strong>",
3168 or <strong>name="visible"</strong>. The value of each property is the entire text between the
3169 XML start tag &lt;property&gt; and the corresponding XML end tag &lt;/property&gt;.</p></div>
3170 <div class="admonitionblock">
3171 <table><tr>
3172 <td class="icon">
3173 <img src="./images/icons/warning.png" alt="Warning" />
3174 </td>
3175 <td class="content">blanks in a property value are preserved and may cause problems
3176 for certain data types like numbers or the Boolean <strong>True</strong> and <strong>False</strong>.</td>
3177 </tr></table>
3178 </div>
3179 <div class="paragraph"><p>Gtk widgets have a fairly large number of properties that allow for a very
3180 fine-tuned control of how the widget will behave. However, most properties
3181 have suitable default values so that in most cases only a few of them need
3182 to be specified in XML.</p></div>
3183 </div>
3184 <div class="sect2">
3185 <h3 id="_8_5_adding_child_widgets">8.5 Adding Child Widgets</h3>
3186 <div class="paragraph"><p>An obvious problem with our current <strong>window</strong> is that it can not be closed.
3187 We can fix that by adding an OK button to it. The button itself is defined
3188 by the following XML snipplet:</p></div>
3189 <div class="listingblock">
3190 <div class="content">
3191 <pre>
3192
3193 <code> &lt;child&gt;
3194 &lt;object class="GtkButton"&gt;
3195 &lt;property name="label"&gt;OK&lt;/property&gt;
3196 &lt;property name="visible"&gt;True&lt;/property&gt;
3197 &lt;property name="width_request"&gt;80&lt;/property&gt;
3198 &lt;property name="height_request"&gt;30&lt;/property&gt;
3199 &lt;/object&gt;
3200 &lt;/child&gt;</code>
3201
3202 </pre>
3203 </div></div>
3204 <div class="paragraph"><p>The entire code is now:</p></div>
3205 <div class="listingblock">
3206 <div class="content">
3207 <pre>
3208
3209 <code> )CLEAR
3210 CLEAR WS
3211
3212 XML←"""
3213 &lt;?xml version="1.0" encoding="UTF-8"?&gt;
3214 &lt;!-- Generated with glade 3.22.1 --&gt;
3215 &lt;interface&gt;
3216 &lt;requires lib="gtk+" version="3.20"/&gt;
3217 &lt;object class="GtkWindow" id="window1"&gt;
3218 &lt;property name="title"&gt;MY-TITLE&lt;/property&gt;
3219 &lt;property name="can_focus"&gt;False&lt;/property&gt;
3220 &lt;property name="width_request"&gt;400&lt;/property&gt;
3221 &lt;property name="height_request"&gt;200&lt;/property&gt;
3222 &lt;child&gt;
3223 &lt;object class="GtkButton"&gt;
3224 &lt;property name="label"&gt;OK&lt;/property&gt;
3225 &lt;property name="visible"&gt;True&lt;/property&gt;
3226 &lt;property name="width_request"&gt;80&lt;/property&gt;
3227 &lt;property name="height_request"&gt;30&lt;/property&gt;
3228 &lt;property name="halign"&gt;start&lt;/property&gt;
3229 &lt;property name="valign"&gt;start&lt;/property&gt;
3230 &lt;/object&gt;
3231 &lt;/child&gt;
3232 &lt;/object&gt;
3233 &lt;/interface&gt;
3234 """
3235
3236 H←⎕GTK 36 ⎕CR XML ⍝ display GUI defined by XML</code>
3237
3238 </pre>
3239 </div></div>
3240 <div class="paragraph"><p>and produces:</p></div>
3241 <div class="imageblock">
3242 <div class="content">
3243 <img src="glade-9.png" alt="glade-9.png" />
3244 </div>
3245 </div>
3246 <div class="paragraph"><p>To explain the the above:</p></div>
3247 <div class="ulist"><ul>
3248 <li>
3249 <p>
3250 the properties <strong>width_request</strong> and <strong>height_request</strong> specify the desired
3251 sizes of the parent widget <strong>window1</strong> and its (so far) anonymous child
3252 of type <strong>GtkButton</strong>.
3253 </p>
3254 </li>
3255 <li>
3256 <p>
3257 the properties <strong>halign</strong> and <strong>valign</strong> of the button with value <strong>start</strong> tell
3258 the parent widget that the button shall be placed at the start (= horizontal
3259 left and vertical top resp.) of the parent. Without them the button
3260 would have grabbed the entire available space of the parent, making the
3261 button almost as big as the parent.
3262 </p>
3263 </li>
3264 </ul></div>
3265 </div>
3266 <div class="sect2">
3267 <h3 id="_8_6_placing_child_widgets">8.6 Placing Child Widgets</h3>
3268 <div class="paragraph"><p>Of course the position of the button at the top left corner of the window is
3269 still somewhat unusual. We would assume that either the GtkWindow or the
3270 GtkButton class have a property or a widget function that could place the
3271 button at a different offset, say <strong>x</strong> pixels Right and <strong>y</strong> pixels down from
3272 the top-left corner. Unfortunately no such property or function exists and
3273 an attempt to specify one yields an error, e.g.:</p></div>
3274 <div class="listingblock">
3275 <div class="content">
3276 <pre>
3277
3278 <code>(Gtk_server:17553): Gtk-WARNING **: 17:17:39.760: GtkWindow does not have a child property called y</code>
3279
3280 </pre>
3281 </div></div>
3282 <div class="paragraph"><p>GTK handles the placement of child widgets of a parent widget by means of
3283 an intermediate widget that provides the missing properties. There exist
3284 several suitable intermediate widgets (<strong>GtkFixed</strong>, <strong>GtkBox</strong>, <strong>GtkGrid</strong>,
3285 <strong>GtkLayout</strong>, &#8230;) with different capabilities as to how the children
3286 should be placed into their common parent. We use the simplest of them:
3287 <strong>GtkFixed</strong>.</p></div>
3288 <div class="paragraph"><p>Our current XML has a two-level widget structure like:</p></div>
3289 <div class="listingblock">
3290 <div class="content">
3291 <pre>
3292
3293 <code>GtkWindow ⊃ GtkButton</code>
3294
3295 </pre>
3296 </div></div>
3297 <div class="paragraph"><p>where A ⊃ B should mean that B is a child of A. We replace that by
3298 a three-level widget structure like this:</p></div>
3299 <div class="listingblock">
3300 <div class="content">
3301 <pre>
3302
3303 <code>GtkWindow ⊃ GtkFixed ⊃ GtkButton
3304 │
3305 └──────────── &lt;packing&gt;
3306 &lt;property name="x"&gt;pos_x&lt;/property&gt;
3307 &lt;property name="y"&gt;pos_x&lt;/property&gt;
3308 &lt;/packing&gt;</code>
3309
3310 </pre>
3311 </div></div>
3312 <div class="paragraph"><p>The widget placement belongs to class <strong>GtkFixed</strong>, and happens in a separate
3313 XML Tag named <strong>&lt;packing&gt;</strong>, which has properties named <strong>x</strong> and <strong>y</strong>. That
3314 is, the positions are specified <em>next to</em> the child rather than <em>inside</em>
3315 the child (or <em>inside the parent</em> for that matter).</p></div>
3316 <div class="paragraph"><p>Our APL code becomes:</p></div>
3317 <div class="listingblock">
3318 <div class="content">
3319 <pre>
3320
3321 <code> )CLEAR
3322 CLEAR WS
3323
3324 XML←"""
3325 &lt;?xml version="1.0" encoding="UTF-8"?&gt;
3326 &lt;!-- Generated with glade 3.22.1 --&gt;
3327 &lt;interface&gt;
3328 &lt;requires lib="gtk+" version="3.20"/&gt;
3329 &lt;object class="GtkWindow" id="window1"&gt;
3330 &lt;property name="title"&gt;MY-TITLE&lt;/property&gt;
3331 &lt;property name="can_focus"&gt;False&lt;/property&gt;
3332 &lt;property name="width_request"&gt;400&lt;/property&gt;
3333 &lt;property name="height_request"&gt;200&lt;/property&gt;
3334 &lt;child&gt;
3335 &lt;object class="GtkFixed"&gt;
3336 &lt;property name="visible"&gt;True&lt;/property&gt;
3337 &lt;child&gt;
3338 &lt;object class="GtkButton"&gt;
3339 &lt;property name="label"&gt;OK&lt;/property&gt;
3340 &lt;property name="visible"&gt;True&lt;/property&gt;
3341 &lt;property name="width_request"&gt;80&lt;/property&gt;
3342 &lt;property name="height_request"&gt;30&lt;/property&gt;
3343 &lt;property name="halign"&gt;start&lt;/property&gt;
3344 &lt;property name="valign"&gt;start&lt;/property&gt;
3345 &lt;/object&gt;
3346 &lt;packing&gt;
3347 &lt;property name="x"&gt;160&lt;/property&gt;
3348 &lt;property name="y"&gt;150&lt;/property&gt;
3349 &lt;/packing&gt;
3350
3351 &lt;/child&gt;
3352 &lt;/object&gt;
3353 &lt;/child&gt;
3354 &lt;/object&gt;
3355 &lt;/interface&gt;
3356 """
3357
3358 H←⎕GTK 36 ⎕CR XML ⍝ display GUI defined by XML</code>
3359
3360 </pre>
3361 </div></div>
3362 <div class="paragraph"><p>And the GUI:</p></div>
3363 <div class="imageblock">
3364 <div class="content">
3365 <img src="glade-10.png" alt="glade-10.png" />
3366 </div>
3367 </div>
3368 </div>
3369 <div class="sect2">
3370 <h3 id="_8_7_adding_style">8.7 Adding Style</h3>
3371 <div class="paragraph"><p>In the early days of HTML, a green button would have looked something
3372 like this:</p></div>
3373 <div class="listingblock">
3374 <div class="content">
3375 <pre>
3376
3377 <code>&lt;BUTTON name="Bn-OK" bgcolor="green"&gt;"OK"&lt;/BUTTON&gt;</code>
3378
3379 </pre>
3380 </div></div>
3381 <div class="paragraph"><p>These days that button would maybe look more like:</p></div>
3382 <div class="listingblock">
3383 <div class="content">
3384 <pre>
3385
3386 <code>&lt;BUTTON name="Bn-OK"&gt;"OK"&lt;/BUTTON&gt;</code>
3387
3388 </pre>
3389 </div></div>
3390 <div class="paragraph"><p>and some CSS file or style somewhere else would e.g. say:</p></div>
3391 <div class="listingblock">
3392 <div class="content">
3393 <pre>
3394
3395 <code>#OK-button { background-color: green }</code>
3396
3397 </pre>
3398 </div></div>
3399 <div class="paragraph"><p>Nowadays the size of style files has grown to such an extent that it is no
3400 longer possible to specify the style of a button or other HTML widget inline
3401 as attributes of the widget.</p></div>
3402 <div class="paragraph"><p>This division into form on the one hand and style on the other was
3403 therefore necessary and fruitful, even though it is not entirely clear
3404 if the enormous growth of style information has pushed CSS or if CSS
3405 has pushed the growth of style information. Anyway, GTK has adopted
3406 CSS as well, although with some subtle differences:</p></div>
3407 <div class="ulist"><ul>
3408 <li>
3409 <p>
3410 In HTML/CSS size related and position properties (like height and width)
3411 could be defined in HTML as well as in CSS. In GTK these properties can
3412 only be defined in XML but not in CSS.
3413 </p>
3414 </li>
3415 <li>
3416 <p>
3417 In HTML/CSS style related and position properties (like colors)
3418 could be defined in HTML as well as in CSS. In GTK these properties can
3419 only be defined in CSS but not in XML.
3420 </p>
3421 </li>
3422 </ul></div>
3423 <div class="paragraph"><p>The use of CSS with <strong>⎕GTK</strong> requires 3 things:</p></div>
3424 <div class="olist arabic"><ol class="arabic">
3425 <li>
3426 <p>
3427 a suitable APL string CSS (either a filename or file content as for XML),
3428 </p>
3429 </li>
3430 <li>
3431 <p>
3432 dyadic <strong>H←CSS *⎕GTK</strong> XML* instead of monadic <strong>H←⎕GTK XML</strong>, and
3433 </p>
3434 </li>
3435 <li>
3436 <p>
3437 possibly a relation between the widgets defined in XML and the styles
3438 defined in CSS.
3439 </p>
3440 </li>
3441 </ol></div>
3442 <div class="paragraph"><p>The CSS is a sequence of statements with the following simple syntax:</p></div>
3443 <div class="listingblock">
3444 <div class="content">
3445 <pre>
3446
3447 <code>Selector(s) { style attributes... }</code>
3448
3449 </pre>
3450 </div></div>
3451 <div class="paragraph"><p>The style attributes define how a widget looks (color, borders, etc.),
3452 while the selectors define which widgets should have the style attributes.
3453 The selectors as well as the style attributes can be used in multiple CSS
3454 statements. The key to success with CSS is to keep matters simple, and
3455 therefore it is better to have fewer selectors and style attributes
3456 than more by splitting bigger statements into a sequence of smaller ones.
3457 More details can be found here:</p></div>
3458 <div class="paragraph"><p><a href="https://docs.gtk.org/gtk3/css-overview.html">https://docs.gtk.org/gtk3/css-overview.html</a></p></div>
3459 <div class="paragraph"><p>Lets start simple (with variable XML as above):</p></div>
3460 <div class="listingblock">
3461 <div class="content">
3462 <pre>
3463
3464 <code> CSS ← """
3465 window { background: #FF0; }
3466
3467 /* all widgets of (style-) class button */
3468 button { color: white; background-color: blue }
3469 """
3470
3471 (36 ⎕CR CSS) *⎕GTK* (36 ⎕CR XML)</code>
3472
3473 </pre>
3474 </div></div>
3475 <div class="paragraph"><p>Not too surprisingly this shows:</p></div>
3476 <div class="imageblock">
3477 <div class="content">
3478 <img src="glade-11.png" alt="glade-11.png" />
3479 </div>
3480 </div>
3481 <div class="paragraph"><p>The selectors <strong>window</strong> and <strong>button</strong> in the CSS above are (style-) class
3482 selectors, which means that all widgets of the respective class will have
3483 the style (i.e. colors) above. For the top-level window that is normally
3484 not a problem because there is only one. For buttons it is more likely
3485 that there is more than one (e.g. a CANCEL button in a different color).</p></div>
3486 <div class="paragraph"><p>In order to have different colors for different buttons, we need a way
3487 to distinguish them. The simplest way to distinguish widgets is to give
3488 them names (in XML). Naming a widget uses the property called "name" in
3489 XML, the value of that property (e.g. <strong>Bn-OK</strong> below) must then be prefixed
3490 with <strong>#</strong> in CSS to refer to the widget with that name:</p></div>
3491 <div class="listingblock">
3492 <div class="content">
3493 <pre>
3494
3495 <code>In XML:
3496 &lt;object class="GtkButton"&gt;
3497 &lt;property name="label"&gt;OK&lt;/property&gt;
3498 &lt;property name="name"&gt;Bn-OK&lt;/property&gt;
3499 ... ──┬──
3500 &lt;/object&gt; │
3501 │
3502 In CSS: │
3503 ┌────────────────────────────────┘
3504 │
3505 ──┴──
3506 #Bn-OK { color: #000; background-color: #3E3; } /* button */
3507 #Bn-OK label { color: #000; background-color: #3E3; } /* button label */</code>
3508
3509 </pre>
3510 </div></div>
3511 <div class="paragraph"><p>You may wonder why there are CSS lines for the green OK button but only one
3512 for the blue class button. The reason is a little quirk in GTK (which will
3513 probably disappear at some point in time. A <strong>button</strong> is a widget that has an
3514 internal sub-widget of type <strong>label</strong> which holds the button text. As it
3515 happens, using a widget class as CSS selector selects the widgets of that
3516 class <strong>including their sub-widgets</strong> while a widget name as CSS selector
3517 selects the widget(s) with that name <strong>excluding their sub-widgets</strong>.</p></div>
3518 <div class="paragraph"><p>The entire application is now:</p></div>
3519 <div class="listingblock">
3520 <div class="content">
3521 <pre>
3522
3523 <code> )CLEAR
3524 CLEAR WS
3525
3526 XML←"""
3527 &lt;?xml version="1.0" encoding="UTF-8"?&gt;
3528 &lt;!-- Generated with glade 3.22.1 --&gt;
3529 &lt;interface&gt;
3530 &lt;requires lib="gtk+" version="3.20"/&gt;
3531 &lt;object class="GtkWindow" id="window1"&gt;
3532 &lt;property name="title"&gt;MY-TITLE&lt;/property&gt;
3533 &lt;property name="can_focus"&gt;False&lt;/property&gt;
3534 &lt;property name="width_request"&gt;400&lt;/property&gt;
3535 &lt;property name="height_request"&gt;200&lt;/property&gt;
3536 &lt;child&gt;
3537 &lt;object class="GtkFixed"&gt;
3538 &lt;property name="visible"&gt;True&lt;/property&gt;
3539 &lt;child&gt;
3540 &lt;object class="GtkButton"&gt;
3541 &lt;property name="name"&gt;Bn-OK&lt;/property&gt;
3542 &lt;property name="label"&gt;OK&lt;/property&gt;
3543 &lt;property name="visible"&gt;True&lt;/property&gt;
3544 &lt;property name="width_request"&gt;80&lt;/property&gt;
3545 &lt;property name="height_request"&gt;30&lt;/property&gt;
3546 &lt;property name="halign"&gt;start&lt;/property&gt;
3547 &lt;property name="valign"&gt;start&lt;/property&gt;
3548 &lt;/object&gt;
3549 &lt;packing&gt;
3550 &lt;property name="x"&gt;160&lt;/property&gt;
3551 &lt;property name="y"&gt;150&lt;/property&gt;
3552 &lt;/packing&gt;
3553 &lt;/child&gt;
3554 &lt;/object&gt;
3555 &lt;/child&gt;
3556 &lt;/object&gt;
3557 &lt;/interface&gt;
3558 """
3559
3560 CSS ← """
3561 window { background: #FFF; }
3562
3563 /* all buttons of class button */
3564 button { color: white; background-color: blue }
3565 button:hover { font-weight: bold; }
3566
3567 #Bn-OK { color: #000; background-color: #3E3; } /* button */
3568 #Bn-OK label { color: #000; background-color: #3E3; } /* button label */
3569 """
3570
3571 *⎕GTK* 3 ◊ ⊣ (36 ⎕CR CSS) *⎕GTK* (36 ⎕CR XML) ◊ ⊣ ⎕DL 2.0</code>
3572
3573 </pre>
3574 </div></div>
3575 <div class="paragraph"><p>It produces:</p></div>
3576 <div class="imageblock">
3577 <div class="content">
3578 <img src="glade-12.png" alt="glade-12.png" />
3579 </div>
3580 </div>
3581 </div>
3582 <div class="sect2">
3583 <h3 id="_8_8_handling_events">8.8 Handling Events</h3>
3584 <div class="paragraph"><p>A button defined so far is alive in the sense that it changes its font weight
3585 when the mouse is moved over it (by virtue of the CSS <strong>button:hover</strong> style),
3586 but has no connection to APL yet. Let&#8217;s say we want to close the window when
3587 the OK button is being pushed. There are then a number of possibilities how
3588 that can be achieved, each with its own characteristics in terms of
3589 functionality and simplicity.</p></div>
3590 <div class="paragraph"><p>More complicated situations typically require looping in APL and are then not
3591 directly usable in immediate execution mode (and consequently not in scripts).</p></div>
3592 <div class="sect3">
3593 <h4 id="_direct_polling_of_widgets_from_apl">Direct Polling of Widgets from APL</h4>
3594 <div class="paragraph"><p>Widgets like buttons or checkboxes have widget functions that can be used to
3595 determine (in an APL loop) when their state changes and to return only when
3596 a particular widget state was reached (by an action of the user):</p></div>
3597 <div class="listingblock">
3598 <div class="content">
3599 <pre>
3600
3601 <code>∇WAIT_FOR_BUTTON_DOWN H_ID;FLAGS
3602 ⍝
3603 ⍝ /usr/include/gtk-3.0/gtk/gtkenums.h : odd state flags ←→ button down
3604 ⍝
3605 LOOP: FLAGS←⎕GTK[H_ID]'GtkWidget::get_state_flags'
3606 → (2∣¯1↑FLAGS)⍴0 ⍝ return when button "pushed"
3607 ⎕DL 0.1 ◊ → LOOP ⍝ and wait if not
3608 ∇</code>
3609
3610 </pre>
3611 </div></div>
3612 <div class="paragraph"><p>Of course, more than one widget (Cancel button, Help button, &#8230;) can
3613 be polled inside such a loop.</p></div>
3614 </div>
3615 <div class="sect3">
3616 <h4 id="_waiting_for_any_event">Waiting for any Event</h4>
3617 <div class="paragraph"><p>In simple cases, for example a GUI with only one (OK-) button, one can simply
3618 wait for the next <strong>⎕GTK</strong> event. Since only one kind of event can occur, checking
3619 the parameters of that event is mere overhead. Also, the APL code is trivial
3620 (assuming we want to close window when the button is pushed):</p></div>
3621 <div class="listingblock">
3622 <div class="content">
3623 <pre>
3624
3625 <code> ⊣ *⎕GTK* 1 ⍝ blocking wait for the next GTK event; discard the result
3626 H *⎕GTK* 0 ⍝ close the window with handle H</code>
3627
3628 </pre>
3629 </div></div>
3630 <div class="paragraph"><p>and it may, since no APL loop is required, even be use in immediate execution
3631 mode or in APL scripts.</p></div>
3632 <div class="paragraph"><p>Sometimes you want to do something else while waiting for a user action, for
3633 example updating a progress bar. In that case you could use <strong>⎕GTK 2</strong> (the
3634 non-blocking companion of <strong>⎕GTK 1</strong>) in the loop.</p></div>
3635 <div class="paragraph"><p>By default, GTK widgets send events (signals) to each other to achieve
3636 visual effects, but these events are not forwarded to APL.</p></div>
3637 <div class="admonitionblock">
3638 <table><tr>
3639 <td class="icon">
3640 <img src="./images/icons/note.png" alt="Note" />
3641 </td>
3642 <td class="content">As an important consequence, <strong>⎕GTK 1</strong> blocks forever by default.</td>
3643 </tr></table>
3644 </div>
3645 <div class="paragraph"><p>To change that, the XML for every widget that shall forward events such as
3646 user clicks on buttons to APL need to specify which events shall be forwarded.
3647 For example:</p></div>
3648 <div class="listingblock">
3649 <div class="content">
3650 <pre>
3651
3652 <code> &lt;object class="GtkButton"&gt;
3653 &lt;property name="label"&gt;OK&lt;/property&gt;
3654 &lt;property name="name"&gt;Bn-OK&lt;/property&gt;
3655 ...
3656 &lt;signal name="clicked" handler="clicked"/&gt;
3657 &lt;/object&gt;</code>
3658
3659 </pre>
3660 </div></div>
3661 <div class="ulist"><ul>
3662 <li>
3663 <p>
3664 The <strong>signal=</strong> value shall be a valid signal for the widget class (select
3665 some widget in <strong>glade</strong> and see <strong>glade</strong> tab named <strong>Signals</strong> to see the list
3666 of signals that the widget or its ancestors can send).
3667 </p>
3668 </li>
3669 <li>
3670 <p>
3671 The <strong>handler=</strong> value is an existing signal handler in the Gtk_server:
3672 </p>
3673 <div class="ulist"><ul>
3674 <li>
3675 <p>
3676 draw
3677 </p>
3678 </li>
3679 <li>
3680 <p>
3681 destroy
3682 </p>
3683 </li>
3684 <li>
3685 <p>
3686 row_selected
3687 </p>
3688 </li>
3689 <li>
3690 <p>
3691 clicked
3692 </p>
3693 </li>
3694 <li>
3695 <p>
3696 changed
3697 </p>
3698 </li>
3699 <li>
3700 <p>
3701 check_resize
3702 </p>
3703 </li>
3704 <li>
3705 <p>
3706 activate
3707 </p>
3708 </li>
3709 <li>
3710 <p>
3711 backspace
3712 </p>
3713 </li>
3714 <li>
3715 <p>
3716 cut_clipboard
3717 </p>
3718 </li>
3719 <li>
3720 <p>
3721 copy_clipboard
3722 </p>
3723 </li>
3724 <li>
3725 <p>
3726 paste_clipboard
3727 </p>
3728 </li>
3729 <li>
3730 <p>
3731 toggle_overwrite
3732 </p>
3733 </li>
3734 <li>
3735 <p>
3736 activate_cursor_row
3737 </p>
3738 </li>
3739 <li>
3740 <p>
3741 toggle_cursor_row
3742 </p>
3743 </li>
3744 <li>
3745 <p>
3746 selected_rows_changed
3747 </p>
3748 </li>
3749 <li>
3750 <p>
3751 select_all
3752 </p>
3753 </li>
3754 <li>
3755 <p>
3756 unselect_all
3757 </p>
3758 </li>
3759 <li>
3760 <p>
3761 toggled
3762 </p>
3763 </li>
3764 <li>
3765 <p>
3766 show
3767 </p>
3768 </li>
3769 <li>
3770 <p>
3771 hide
3772 </p>
3773 </li>
3774 <li>
3775 <p>
3776 map
3777 </p>
3778 </li>
3779 <li>
3780 <p>
3781 unmap
3782 </p>
3783 </li>
3784 <li>
3785 <p>
3786 realize
3787 </p>
3788 </li>
3789 <li>
3790 <p>
3791 unrealize
3792 </p>
3793 </li>
3794 <li>
3795 <p>
3796 composited_changed
3797 </p>
3798 </li>
3799 <li>
3800 <p>
3801 style_updated
3802 </p>
3803 </li>
3804 <li>
3805 <p>
3806 keys_changed
3807 </p>
3808 </li>
3809 </ul></div>
3810 </li>
3811 </ul></div>
3812 <div class="paragraph"><p>See <a href="#Tag_table3">Table 3 in the Appendix</a> for a list of handlers.</p></div>
3813 <div class="admonitionblock">
3814 <table><tr>
3815 <td class="icon">
3816 <img src="./images/icons/note.png" alt="Note" />
3817 </td>
3818 <td class="content">The author, at least, frequently forgets the &lt;signal &#8230; /&gt; entry in the
3819 XML of the object that sends the event and then wonders what is wrong.</td>
3820 </tr></table>
3821 </div>
3822 <div class="paragraph"><p>Even though this method is somewhat crude, it has the advantage that
3823 no loop (which repeats if the wrong signal was received) is required
3824 and can therefore also be used in immediate execution mode without a
3825 defined function that contains the loop.</p></div>
3826 </div>
3827 <div class="sect3">
3828 <h4 id="_waiting_for_specific_event">Waiting for specific Event</h4>
3829 <div class="paragraph"><p>In more complicated cases, it might be needed to decode which widget has sent
3830 which event:</p></div>
3831 <div class="listingblock">
3832 <div class="content">
3833 <pre>
3834
3835 <code>LOOP: Event←⎕GTK 1 ⍝ blocking wait for next event, then decode it
3836 (H W E) ← 3↑Event ⍝ common event header
3837 → (W ≢ "Bn-OK")/LOOP ⍝ not from Bn-OK
3838 → (E ≢ "clicked")/LOOP ⍝ not button click
3839 H *⎕GTK* 0 ⍝ OK button clicked: close the window</code>
3840
3841 </pre>
3842 </div></div>
3843 <div class="paragraph"><p>The same &lt;signal&gt; line as in the example before is required. The parameters
3844 of an event are defined by the handler, but all start with the 3 described
3845 in the following example (button click).</p></div>
3846 <div class="paragraph"><p>The event received from a button click is a 3-item vector like this:</p></div>
3847 <div class="listingblock">
3848 <div class="content">
3849 <pre>
3850
3851 <code>┌→──────────────────┐
3852 │7 ┌→────┐ ┌→──────┐│
3853 │ │Bn-OK│ │clicked││
3854 │ └─────┘ └───────┘│
3855 └ϵ──────────────────┘</code>
3856
3857 </pre>
3858 </div></div>
3859 <div class="paragraph"><p>The 3 components are:</p></div>
3860 <div class="ulist"><ul>
3861 <li>
3862 <p>
3863 The handle for the Gtk window (small integer)
3864 </p>
3865 </li>
3866 <li>
3867 <p>
3868 the name (APL string) of the widget sending the event, and
3869 </p>
3870 </li>
3871 <li>
3872 <p>
3873 the name (APL string) of the event.
3874 </p>
3875 </li>
3876 </ul></div>
3877 </div>
3878 </div>
3879 <div class="sect2">
3880 <h3 id="_8_9_summary">8.9 Summary</h3>
3881 <div class="paragraph"><p>The sections above have hopefully touched upon all topics that may occur when
3882 designing GUIs with <strong>⎕GTK</strong>. By combining these simple steps it should be
3883 straightforward to construct more advanced GUIs. Before starting from scratch,
3884 though, it may be worthwhile to have a look at the workspace
3885 <strong>workspaces/SQL_GUI.apl</strong> which is shipped with GNU APL. This workspace
3886 contains several examples of using <strong>⎕GTK</strong> (and also ⎕SQL) that could be
3887 copied into your own application.</p></div>
3888 </div>
3889 </div>
3890 </div>
3891 <div class="sect1">
3892 <h2 id="TAG_appendix">A. Appendix</h2>
3893 <div class="sectionbody">
3894 <div class="sect2">
3895 <h3 id="_a_1_the_strong_gtk_strong_cheat_sheet">A.1 The <strong>⎕GTK</strong> Cheat Sheet</h3>
3896 <div class="paragraph"><p>In the Table 2 below, it is assumed that:</p></div>
3897 <div class="listingblock">
3898 <div class="content">
3899 <pre>
3900
3901 <code> ⍝ H is a window handle (from some H ← Zh←⎕GTK "filename.ui")
3902 ⍝ ID is a string containing the id= property of some widget in filename.ui
3903 ⍝ H_ID ← H, ID ⍝ e.g. 6,"entry1". H_ID uniquely identifies a widget</code>
3904
3905 </pre>
3906 </div></div>
3907 <div class="tableblock" id="Tag_table2">
3908 <table rules="all"
3909 width="100%"
3910 frame="border"
3911 cellspacing="0" cellpadding="4">
3912 <caption class="title">Table 2. ⎕GTK Syntax Variants (Signatures)</caption>
3913 <col width="33%" />
3914 <col width="7%" />
3915 <col width="59%" />
3916 <thead>
3917 <tr>
3918 <th align="left" valign="top"> Syntax</th>
3919 <th align="center" valign="top"> Fun<br />
3920 (Bi)</th>
3921 <th align="left" valign="top"> Result/Action</th>
3922 </tr>
3923 </thead>
3924 <tbody>
3925 <tr>
3926 <td align="left" valign="top"><p class="table">Zh←⎕GTK "file.ui"</p></td>
3927 <td align="center" valign="top"><p class="table">-</p></td>
3928 <td align="left" valign="top"><p class="table">Zh is a handle for a new window according to <strong>glade</strong> file file.ui (no CSS)</p></td>
3929 </tr>
3930 <tr>
3931 <td align="left" valign="top"><p class="table">Zh← "file.css" <strong>⎕GTK</strong> "file.ui"</p></td>
3932 <td align="center" valign="top"><p class="table">-</p></td>
3933 <td align="left" valign="top"><p class="table">Zh is a handle for a new window according to CSS file <strong>file.css</strong> and
3934 <strong>glade</strong> XML file <strong>file.ui</strong></p></td>
3935 </tr>
3936 <tr>
3937 <td align="left" valign="top"><p class="table">Zi← <strong>⎕GTK</strong> 0</p></td>
3938 <td align="center" valign="top"><p class="table">-</p></td>
3939 <td align="left" valign="top"><p class="table">Zi is an integer vector containing all open window handles</p></td>
3940 </tr>
3941 <tr>
3942 <td align="left" valign="top"><p class="table">Zi← Ah <strong>⎕GTK</strong> 0</p></td>
3943 <td align="center" valign="top"><p class="table">0</p></td>
3944 <td align="left" valign="top"><p class="table">close window handle Ah, return 0 on success, or errno otherwise</p></td>
3945 </tr>
3946 <tr>
3947 <td align="left" valign="top"><p class="table">Zi← <strong>⎕GTK</strong> 1</p></td>
3948 <td align="center" valign="top"><p class="table">1</p></td>
3949 <td align="left" valign="top"><p class="table">blocking poll for the next event</p></td>
3950 </tr>
3951 <tr>
3952 <td align="left" valign="top"><p class="table">Zi← <strong>⎕GTK</strong> 2</p></td>
3953 <td align="center" valign="top"><p class="table">2</p></td>
3954 <td align="left" valign="top"><p class="table">non-blocking poll for the next event (Zi≡0 means: no event)</p></td>
3955 </tr>
3956 <tr>
3957 <td align="left" valign="top"><p class="table">Zi←Ah <strong>⎕GTK</strong> 3</p></td>
3958 <td align="center" valign="top"><p class="table">3</p></td>
3959 <td align="left" valign="top"><p class="table">increment the (debug-) verbosity of Gtk_server (subject to be changed)</p></td>
3960 </tr>
3961 <tr>
3962 <td align="left" valign="top"><p class="table">Zi←Ah <strong>⎕GTK</strong> 4</p></td>
3963 <td align="center" valign="top"><p class="table">4</p></td>
3964 <td align="left" valign="top"><p class="table">decrement the (debug-) verbosity of Gtk_server (subject to be changed)</p></td>
3965 </tr>
3966 <tr>
3967 <td align="left" valign="top"><p class="table">Text ⎕GTK[H_ID] "entry"</p></td>
3968 <td align="center" valign="top"><p class="table">NOTE</p></td>
3969 <td align="left" valign="top"><p class="table">set the text in e.g. a text entry</p></td>
3970 </tr>
3971 <tr>
3972 <td align="left" valign="top"><p class="table">Text ← ⎕GTK[H_ID] "entry"</p></td>
3973 <td align="center" valign="top"><p class="table">NOTE</p></td>
3974 <td align="left" valign="top"><p class="table">return the text in e.g. a text entry</p></td>
3975 </tr>
3976 <tr>
3977 <td align="left" valign="top"><p class="table">Text ⎕GTK[H_ID] "label"</p></td>
3978 <td align="center" valign="top"><p class="table">NOTE</p></td>
3979 <td align="left" valign="top"><p class="table">set the text of e.g. a label</p></td>
3980 </tr>
3981 <tr>
3982 <td align="left" valign="top"><p class="table">Fraction ⎕GTK[H_ID] "progress_bar"</p></td>
3983 <td align="center" valign="top"><p class="table">NOTE</p></td>
3984 <td align="left" valign="top"><p class="table">set the progress shown by a progress bar</p></td>
3985 </tr>
3986 <tr>
3987 <td align="left" valign="top"><p class="table">Fraction ← ⎕GTK[H_ID] "progress_bar"</p></td>
3988 <td align="center" valign="top"><p class="table">NOTE</p></td>
3989 <td align="left" valign="top"><p class="table">return the progress shown by a progress bar</p></td>
3990 </tr>
3991 <tr>
3992 <td align="left" valign="top"><p class="table">Level ⎕GTK[H_ID] "level_bar"</p></td>
3993 <td align="center" valign="top"><p class="table">NOTE</p></td>
3994 <td align="left" valign="top"><p class="table">set the level shown by a level bar</p></td>
3995 </tr>
3996 <tr>
3997 <td align="left" valign="top"><p class="table">Level ← ⎕GTK[H_ID] "level_bar"</p></td>
3998 <td align="center" valign="top"><p class="table">NOTE</p></td>
3999 <td align="left" valign="top"><p class="table">return the level shown by level bar</p></td>
4000 </tr>
4001 <tr>
4002 <td align="left" valign="top"><p class="table">Selected ⎕GTK[H_ID] "combo_box"</p></td>
4003 <td align="center" valign="top"><p class="table">NOTE</p></td>
4004 <td align="left" valign="top"><p class="table">set the selected item of a combo box (-1 for none)</p></td>
4005 </tr>
4006 <tr>
4007 <td align="left" valign="top"><p class="table">Selected ← ⎕GTK[H_ID] "combo_box"</p></td>
4008 <td align="center" valign="top"><p class="table">NOTE</p></td>
4009 <td align="left" valign="top"><p class="table">return the selected item of a combo box (-1 = none)</p></td>
4010 </tr>
4011 <tr>
4012 <td align="left" valign="top"><p class="table">DrawCmd ⎕GTK[H_ID] "drawingarea"</p></td>
4013 <td align="center" valign="top"><p class="table">NOTE</p></td>
4014 <td align="left" valign="top"><p class="table">set the commands needed to draw a drawing area</p></td>
4015 </tr>
4016 <tr>
4017 <td align="left" valign="top"><p class="table">SX_SY ⎕GTK[H_ID] "drawingarea"</p></td>
4018 <td align="center" valign="top"><p class="table">NOTE</p></td>
4019 <td align="left" valign="top"><p class="table">set the area size to SX_SY &gt;&gt; 16 : SX_SY &amp; 0xFFFF</p></td>
4020 </tr>
4021 <tr>
4022 <td align="left" valign="top"><p class="table">Origin ⎕GTK[H_ID] "drawingarea"</p></td>
4023 <td align="center" valign="top"><p class="table">NOTE</p></td>
4024 <td align="left" valign="top"><p class="table">set the Y-origin to the top (1) or the bottom (0)</p></td>
4025 </tr>
4026 <tr>
4027 <td align="left" valign="top"><p class="table">Selected ← ⎕GTK[H_ID] "combo_box_text"</p></td>
4028 <td align="center" valign="top"><p class="table">NOTE</p></td>
4029 <td align="left" valign="top"><p class="table">return the selected text in a combo box text</p></td>
4030 </tr>
4031 <tr>
4032 <td align="left" valign="top"><p class="table">Selected ← ⎕GTK[H_ID] "spin_button"</p></td>
4033 <td align="center" valign="top"><p class="table">NOTE</p></td>
4034 <td align="left" valign="top"><p class="table">return the current value</p></td>
4035 </tr>
4036 <tr>
4037 <td align="left" valign="top"><p class="table">Selected ← ⎕GTK[H_ID] "spin_button"</p></td>
4038 <td align="center" valign="top"><p class="table">NOTE</p></td>
4039 <td align="left" valign="top"><p class="table">return the current value</p></td>
4040 </tr>
4041 <tr>
4042 <td align="left" valign="top"><p class="table">Text ⎕GTK[H_ID] "text_view"</p></td>
4043 <td align="center" valign="top"><p class="table">NOTE</p></td>
4044 <td align="left" valign="top"><p class="table">add a row to a text view</p></td>
4045 </tr>
4046 </tbody>
4047 </table>
4048 </div>
4049 <div class="admonitionblock">
4050 <table><tr>
4051 <td class="icon">
4052 <img src="./images/icons/warning.png" alt="Warning" />
4053 </td>
4054 <td class="content">In Table 2 above, <strong>⎕GTK</strong> functions with axis argument, are <strong>widget
4055 functions</strong>. The axis argument <strong>H_ID</strong> combines the numeric handle <strong>H</strong> (returned
4056 from some <strong>H←⎕GTK filename.ui</strong> with a widget id <strong>ID</strong> specified in that
4057 <strong>filename.ui</strong> as to uniquely identify a widget on the screen (either a top-level
4058 window or a widget inside some other widget). The functions without axis
4059 arguments are <strong>generic</strong> and control <strong>⎕GTK</strong> itself rather than a widget
4060 displayed by <strong>⎕GTK</strong>. The mandatory right argument B of almost all <strong>⎕GTK</strong> calls
4061 is either a function number (APL integer scalar) or a function name (APL
4062 string). The function numbers of generic functions are assigned by GNU APL
4063 and will be maintained in a backward-compatible fashion. In contrast, the
4064 numbers for widget functions, are automatically generated from the source
4065 files of the GTK libraries and are highly volatile. These numbers differ
4066 on different platforms, between different GTK library versions, and even
4067 between different SVN versions of GNU APL. For this reason (and for the sake
4068 of portability of GNU APL workspaces, you should <strong>never use numbers for widget
4069 functions</strong> even though they are somewhat easier to enter. BTW: the Gtk_server
4070 can be started from the command line like: <strong>Gtk_server --numbers</strong> and then
4071 displays the mapping between widget function numbers and function names (of
4072 that Gtk_server).</td>
4073 </tr></table>
4074 </div>
4075 <div class="paragraph"><p>The functions <strong>⎕GTK 1</strong> and <strong>⎕GTK 2</strong> return an event vector according to
4076 Table 3 below. The elements of this event vector have the following meaning:</p></div>
4077 <div class="ulist"><ul>
4078 <li>
4079 <p>
4080 <strong>Hi</strong> (APL integer): the handle (= Gtk_server instance) on which the event was
4081 received. The handle was returned by some <strong>⎕GTK "file.ui"</strong> or
4082 <strong>CSS *⎕GTK</strong> "file.ui").
4083 </p>
4084 </li>
4085 <li>
4086 <p>
4087 <strong>Ns</strong> (nested APL string): the <strong>Widget Name</strong> (if provided: in glade tab
4088 <strong>Common</strong> or by object property <strong>name</strong> in XML). <strong>""</strong> if not provided.
4089 </p>
4090 </li>
4091 <li>
4092 <p>
4093 <strong>Es</strong> (APL string): The event (callback name), for example: <strong>"clicked"</strong> when
4094 a button was pushed.
4095 </p>
4096 </li>
4097 <li>
4098 <p>
4099 <strong>Is</strong> (APL string): The ID of the widget that has sent the event (if
4100 provided: in glade tab <strong>General</strong> or XML attribute <strong>"id="</strong> in the start tag
4101 &lt;object &#8230;&gt; of the widget). <strong>""</strong> if not provided.
4102 </p>
4103 </li>
4104 <li>
4105 <p>
4106 <strong>Cs</strong> (string): The <strong>Gtk class</strong> of the widget that has sent the event, for
4107 example: <strong>"GtkButton"</strong>.
4108 </p>
4109 </li>
4110 <li>
4111 <p>
4112 <strong>Xi</strong> (APL integer): Mouse position X (pixels) of a mouse click
4113 </p>
4114 </li>
4115 <li>
4116 <p>
4117 <strong>Yi</strong> (APL integer): Mouse position Y (pixels) of a mouse click
4118 </p>
4119 </li>
4120 <li>
4121 <p>
4122 <strong>Bi</strong> (APL integer): Mouse button (1, 2, or 3) of a mouse click
4123 </p>
4124 </li>
4125 <li>
4126 <p>
4127 <strong>Li</strong> (APL integer): Text row number of a mouse click (GtkTextView)
4128 </p>
4129 </li>
4130 </ul></div>
4131 <div class="tableblock" id="Tag_table3">
4132 <table rules="all"
4133 width="100%"
4134 frame="border"
4135 cellspacing="0" cellpadding="4">
4136 <caption class="title">Table 3. ⎕GTK Events</caption>
4137 <col width="17%" />
4138 <col width="29%" />
4139 <col width="52%" />
4140 <thead>
4141 <tr>
4142 <th align="left" valign="top"> Callback (in <strong>glade</strong> or <strong>XML</strong>)</th>
4143 <th align="left" valign="top"> Items of <strong>Z←⎕GTK 1</strong></th>
4144 <th align="left" valign="top"> APL Example of a <strong>⎕GTK 1</strong> Result</th>
4145 </tr>
4146 </thead>
4147 <tbody>
4148 <tr>
4149 <td align="left" valign="top"><p class="table"><code><strong>draw</strong></code></p></td>
4150 <td align="left" valign="top"><p class="table">(Hi Ns Es Is Cs)←Event</p></td>
4151 <td align="left" valign="top"><p class="table"><code>6</code> <code>'Canvas'</code> <code>'draw'</code> <code>'drawingarea1'</code> <code>'GtkDrawingArea'</code></p></td>
4152 </tr>
4153 <tr>
4154 <td align="left" valign="top"><p class="table"><code><strong>destroy</strong></code></p></td>
4155 <td align="left" valign="top"><p class="table">(Hi Ns Es Is Cs)←Event</p></td>
4156 <td align="left" valign="top"><p class="table"><code>6</code> <code>'Main-Window'</code> <code>'destroy'</code> <code>'window1'</code> <code>'GtkWindow'</code></p></td>
4157 </tr>
4158 <tr>
4159 <td align="left" valign="top"><p class="table"><code><strong>row_selected</strong></code></p></td>
4160 <td align="left" valign="top"><p class="table">(Hi Ns Es Xi Yi Bi Li)←Event</p></td>
4161 <td align="left" valign="top"><p class="table"><code>6</code> <code>'text_view-Mouse'</code> <code>'row_selected'</code> <code> </code> <code> </code></p></td>
4162 </tr>
4163 <tr>
4164 <td align="left" valign="top"><p class="table"><code><strong>clicked</strong></code></p></td>
4165 <td align="left" valign="top"><p class="table">(Hi Ns Es Is Cs)←Event</p></td>
4166 <td align="left" valign="top"><p class="table"><code>6</code> <code>'OK-button'</code> <code>'clicked'</code> <code>'button1'</code> <code>'GtkButton'</code></p></td>
4167 </tr>
4168 <tr>
4169 <td align="left" valign="top"><p class="table"><code><strong>changed</strong></code></p></td>
4170 <td align="left" valign="top"><p class="table">(Hi Ns Es Is Cs)←Event</p></td>
4171 <td align="left" valign="top"><p class="table"><code>6</code> <code>'Select-box'</code> <code>'changed'</code> <code>'combobox1'</code> <code>'GtkComboBox'</code></p></td>
4172 </tr>
4173 <tr>
4174 <td align="left" valign="top"><p class="table"><code><strong>activate</strong></code></p></td>
4175 <td align="left" valign="top"><p class="table">(Hi Ns Es Is Cs)←Event</p></td>
4176 <td align="left" valign="top"><p class="table"><code>6</code> <code>'Text-entry'</code> <code>'activate'</code> <code>'entry1'</code> <code>'GtkEntry'</code></p></td>
4177 </tr>
4178 </tbody>
4179 </table>
4180 </div>
4181 <div class="tableblock" id="Tag_table4">
4182 <table rules="all"
4183 width="100%"
4184 frame="border"
4185 cellspacing="0" cellpadding="4">
4186 <caption class="title">Table 4. ⎕GTK Drawing Commands</caption>
4187 <col width="28%" />
4188 <col width="71%" />
4189 <thead>
4190 <tr>
4191 <th align="left" valign="top"> Command </th>
4192 <th align="left" valign="top"> Effect</th>
4193 </tr>
4194 </thead>
4195 <tbody>
4196 <tr>
4197 <td align="left" valign="top"><p class="table"><code><strong>background R G B</strong></code></p></td>
4198 <td align="left" valign="top"><p class="table">Set the background color of the drawing area widget. This command shall be
4199 the first command given.</p></td>
4200 </tr>
4201 <tr>
4202 <td align="left" valign="top"><p class="table"><code><strong>line-width W</strong></code></p></td>
4203 <td align="left" valign="top"><p class="table">set the line width that is used to draw lines and borders. W=100 (%)
4204 gives the default line width in Gtk.</p></td>
4205 </tr>
4206 <tr>
4207 <td align="left" valign="top"><p class="table"><code><strong>line-color R G B</strong></code></p></td>
4208 <td align="left" valign="top"><p class="table">same as <strong>line-color R G B 100</strong> (fully opaque color).</p></td>
4209 </tr>
4210 <tr>
4211 <td align="left" valign="top"><p class="table"><code><strong>line-color R G B A</strong></code></p></td>
4212 <td align="left" valign="top"><p class="table">set the line color to the color with red, green, and blue components of R,
4213 G, and B resp, and opacity A (%).</p></td>
4214 </tr>
4215 <tr>
4216 <td align="left" valign="top"><p class="table"><code><strong>fill-color R G B</strong></code></p></td>
4217 <td align="left" valign="top"><p class="table">same as <strong>fill-color R G B 100</strong> (fully opaque color).</p></td>
4218 </tr>
4219 <tr>
4220 <td align="left" valign="top"><p class="table"><code><strong>fill-color R G B A</strong></code></p></td>
4221 <td align="left" valign="top"><p class="table">set the fill color to the color with red, green, and blue components of R,
4222 G, and B resp. and opacity A (%).</p></td>
4223 </tr>
4224 <tr>
4225 <td align="left" valign="top"><p class="table"><code><strong>font-size S</strong></code></p></td>
4226 <td align="left" valign="top"><p class="table">set the font size used in subsequent <strong>text</strong> commands. S=100 (%) is the
4227 default font size of Gtk.</p></td>
4228 </tr>
4229 <tr>
4230 <td align="left" valign="top"><p class="table"><code><strong>font-family F</strong></code></p></td>
4231 <td align="left" valign="top"><p class="table">set the font family (<strong>serif</strong>, <strong>sans-serif</strong>, <strong>cursive</strong>, <strong>fantasy</strong>,
4232 <strong>monospace</strong>) used in subsequent <strong>text</strong>
4233 commands.</p></td>
4234 </tr>
4235 <tr>
4236 <td align="left" valign="top"><p class="table"><code><strong>font-slant S</strong></code></p></td>
4237 <td align="left" valign="top"><p class="table">set the font slant used in subsequent <strong>text</strong> commands. S is <strong>NORMAL</strong>,
4238 <strong>ITALIC</strong>, or <strong>OBLIQUE</strong>.</p></td>
4239 </tr>
4240 <tr>
4241 <td align="left" valign="top"><p class="table"><code><strong>font-weight W</strong></code></p></td>
4242 <td align="left" valign="top"><p class="table">set the font weight used in subsequent <strong>text</strong> commands. W is either <strong>NORMAL</strong>
4243 or <strong>BOLD</strong></p></td>
4244 </tr>
4245 <tr>
4246 <td align="left" valign="top"><p class="table"><code><strong>line (X0 Y0) (X1 Y1)</strong></code></p></td>
4247 <td align="left" valign="top"><p class="table">draw a line from point (X0 Y0) to point (X1 Y1).</p></td>
4248 </tr>
4249 <tr>
4250 <td align="left" valign="top"><p class="table"><code><strong>rectangle (X0 Y0) (X1 Y1)</strong></code></p></td>
4251 <td align="left" valign="top"><p class="table">draw a rectangle with corners (X0 Y0) and (X1 Y1).</p></td>
4252 </tr>
4253 <tr>
4254 <td align="left" valign="top"><p class="table"><code><strong>circle (X Y) R</strong></code></p></td>
4255 <td align="left" valign="top"><p class="table">draw a circle with center (X Y) and radius R.</p></td>
4256 </tr>
4257 <tr>
4258 <td align="left" valign="top"><p class="table"><code><strong>ellipse (X Y) (RX RY)</strong></code></p></td>
4259 <td align="left" valign="top"><p class="table">draw an ellipse with center (X Y) and radii RX and RY.</p></td>
4260 </tr>
4261 <tr>
4262 <td align="left" valign="top"><p class="table"><code><strong>polygon (X0 Y0) (X1 Y1) (X2 Y2) &#8230;</strong></code></p></td>
4263 <td align="left" valign="top"><p class="table">draw a polygon with points (X0 Y0), (X1 Y1), (X2 Y2) &#8230;</p></td>
4264 </tr>
4265 <tr>
4266 <td align="left" valign="top"><p class="table"><code><strong>text (X Y) T</strong></code></p></td>
4267 <td align="left" valign="top"><p class="table">draw the text <strong>T</strong> at position (X Y).</p></td>
4268 </tr>
4269 </tbody>
4270 </table>
4271 </div>
4272 </div>
4273 <div class="sect2">
4274 <h3 id="TAG_caveats">Caveats</h3>
4275 <div class="paragraph"><p>With <strong>glade</strong> it is possible to design a single GUI that contains multiple
4276 top-level windows or no top-level window. However, <strong>⎕GTK</strong> currently supports
4277 only GUIs with one top-level widget of type "Window (the first widget in the
4278 top-level group in glade).</p></div>
4279 </div>
4280 <div class="sect2">
4281 <h3 id="_references">References</h3>
4282 <div class="paragraph"><p>See also:</p></div>
4283 <div class="paragraph"><p><a href="https://developer.gnome.org/gtk3/stable/">https://developer.gnome.org/gtk3/stable/</a></p></div>
4284 </div>
4285 </div>
4286 </div>
4287 </div>
4288 <div id="footnotes"><hr /></div>
4289 <div id="footer">
4290 <div id="footer-text">
4291 Last updated
4292 2024-03-14 14:48:59 CET
4293 </div>
4294 </div>
4295 </body>
4296 </html>