summaryrefslogtreecommitdiff
path: root/doc/limbotk/tk.ms
blob: 4400afa36a43d83973acec5f0695b194e6e0d310 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
.nr dT 4
.nr P1 .2i
.de EX
.nr x \\$1v
\\!h0c n \\nx 0
..
.nr Pd \n(PD
.de FG		\" start figure caption: .FG filename.ps verticalsize
.KF
.BP \\$1 \\$2
.sp .5v
.EX \\$2v
.ps -1
.vs -1
..
.de fg		\" end figure caption (yes, it is clumsy)
.ps
.vs
.br
.KE
..
.de Tk		\" Tk option name and option
.CW \\$1
.I \\$2 \\$3
..
.de Tc		\" Tk command string
.IP "\\f(CW\\$1\\fP \\$2" \w'\f(CWburble\fP'u
.br
..
.de Kp		\" Keypress
.IP "\\f(CW\\$1\\fP" \w'\f(CWKeypress\fP'u
.br
..
.de d0		\" no gap between paragraphs
.nr PD 0
..
.de d1		\" restore gap
.nr PD \n(Pd
..
.ds Op "\fR[\fP\fIoptions ...\fP\fR]\fP
.TL
An Overview of Limbo/Tk
.AU
.I "Lucent Technologies Inc."
.br
Revised June 2000 by Vita Nuova
.SH
Overview
.LP
Limbo/Tk is a concise and powerful way to construct graphical user interfaces without directly using the Draw module primitives.
Standard interfaces can quickly be created from collections of menus, buttons, and other widgets that are part of Limbo/Tk's visual toolkit.
It is modelled on Ousterhout's Tk 4.0 [1,2], commonly deployed
with the scripting language Tcl as `Tcl/Tk'.
Although inspired by Tk 4.0, Inferno's Tk implementation is new, and unrelated to Ousterhout's.
It is intended to be used with the new programming language Limbo, not Tcl.
Limbo/Tk applications make
extensive use of Limbo's concurrent programming constructions and data structures,
and that is reflected in the interface.
Section 9 of Volume 1 of the
.I "Inferno Programmer's Manual"
provides a detailed reference for Limbo/Tk.
This paper provides an overview of its use in some simple staged examples, and
concludes with
a summary of the differences between the Limbo/Tk implementation and Tk 4.0.
In the rest of this paper, `Tk' refers to Limbo/Tk, and `Tk 4.0' refers to Ousterhout's
original implementation.
.NH 1
The Limbo/Tk environment
.LP
Limbo applications access Tk by means of a built-in module,
.CW "$Tk" .
The standard distribution also includes the window manager
.CW "wm"
and the Limbo module
.CW Wmlib .
Unlike
.CW Tk ,
.CW Wmlib
is not built-in but implemented in Limbo by
.CW /appl/lib/wmlib.b .
It simplifies and standardises the construction of windowed applications;
it also contains some graphical devices such as tabbed notebooks not provided
directly by Limbo/Tk.
The essentials of both
.CW Tk
and
.CW Wmlib
are discussed here.
.LP
Programmers usually need only three functions from the
.CW Tk
module:
.IP •
.CW toplevel
.br
Creates a graphical window \- a Tk `top level' widget \-
that can be used to build a Limbo/Tk application.
The function returns a reference to an adt
.CW "\%Tk->Toplevel"
adt that represents the window in subsequent Tk operations.
.IP •
.CW cmd
.br
Creates and arranges graphic objects within the toplevel window by processing Limbo/Tk command strings.
The interface to Tk is primarily the passing of strings between
the application and Tk
of the toolkit using
.CW cmd .
Each call to
.CW cmd
returns a string representing the result of the Tk command;
a string starting with
.CW ! ' `
diagnoses an error.
.IP •
.CW namechan
.br
Gives a name within Tk (in the scope of a given window) to a Limbo
.CW "chan of string"
that Tk commands can use to send data to a Limbo program.
.LP
Other functions in the module have more specialised uses that will not be discussed here.
For instance,
.CW "mouse"
and
.CW "keyboard"
are used by a window manager to send mouse and keyboard events
to the Tk implementation for distribution to applications.
.LP
Even
.CW toplevel
is not commonly used in the window manager environment:
a function
.CW Wmlib->titlebar
provides the usual interface to
.CW toplevel .
The low-level interface will be described first, for completeness,
then the normal case using
.CW titlebar .
.NH 1
Basic Limbo/Tk
.LP
This section shows a simple Tk application that uses only the fundamental Tk functions.
.NH 2
Preliminaries
.LP
The example assumes that the
.CW "Tk"
module is loaded as
.CW "tk" :
.P1
include "tk.m";
	tk:	Tk;
	...
init(ctxt: ref Draw->Context, nil: list of string)
{
	tk =  load Tk Tk->PATH;
	...
}
.P2
.NH 2
Creating a toplevel
.LP
The following fragment makes the Limbo identifier
.CW "top"
refer to a new
.CW "ref Tk->Toplevel"
for use in later Tk commands:
.P1
	top := tk->toplevel(ctxt.screen, "-x 150 -y 150");
.P2
The upper left corner of this window will be at point (150, 150), where (0,0) is the upper left corner of the screen;
.I x
coordinates increase from left to right, and
.I y
coordinates increase from top to bottom.
.LP
In general,
.CW "Tk->toplevel"
takes a screen argument and a string containing further options, and it returns a reference to a top-level Limbo/Tk widget on the given screen.
The options argument contains
.Tk -option value
pairs, such as
.CW "-relief raised" .
As well as the generic options,
.CW "toplevel"
accepts the options
.Tk -x int
and
.Tk -y int
to specify the upper left corner of the toplevel widget, where (0,0) is the top left corner of the screen,
and
.Tk -debug bool
to cause a trace of all Tk commands to be printed,
if the boolean value is true.
.NH 2
Creating a named channel to Tk
.LP
The following fragment creates a
.CW "chan of string"
called
.CW "c" ,
then associates the name
.CW "cmdchan"
within Tk with the Limbo channel
.CW "c" :
.P1
	c := chan of string;
	tk->namechan(top, c, "cmdchan");
.P2
The named channel
.CW "cmdchan"
can now be used in a special Tk
.CW send
command
to send strings to be processed by a Limbo program, typically notifying it of an event.
Note that the Limbo identifer name need not match the name given to Tk,
although it is invariably easier to follow the code if the two are the same.
.NH 2
Defining and positioning widgets
.LP
The following fragment uses
.CW "tk->cmd"
to define four widgets: two buttons, a label, and an entry widget. The widgets are positioned in their parent window (in this case the toplevel window
.CW "top" )
using the Tk command
.CW "pack" :
.P1
.ps -1
.vs -1
	\fI# define widgets\fP
	tk->cmd(top, "button .b1 -text Exit -command {send cmdchan exit}");
	tk->cmd(top, "button .b2 -text Send -command {send cmdchan send}");
	tk->cmd(top, "label .l -text {Name: }");
	tk->cmd(top, "entry .e");

	\fI# bind newline character in entry widget to command\fP
	tk->cmd(top, "bind .e <Key-\en> {send cmdchan send}");

	\fI# pack widgets\fP
	tk->cmd(top, "pack .b1 .b2 .l .e -side left; update");
.ps +1
.vs +1
.P2
This particular pack command packs the widgets named
.CW ".b1" ,
.CW ".b2" ,
.CW ".l" ,
and
.CW ".e"
into the
.CW "top"
window beginning at the left side. The
.CW "update"
command forces Tk to update the screen right away. The result is shown in Figure 1.
.FG "f1.ps" 0.21i
.ce
.I "Figure 1. Two buttons, a label and an entry widget."
.fg
.LP
Entering a newline (`return' or `enter' key)\-the character
.CW \en ' `
in Limbo\-
in the entry box results in the execution of the Tk command
.CW "{send cmdchan send}" ,
because of the binding set by
.CW "bind .e <Key-\en>"
previously executed by
.CW tk->cmd .
The
.CW "bind"
command is often used to bind specific widget events (including key presses, mouse button presses, and mouse motion) to Tk
.CW send
commands.
.NH 2
Processing widget events
.LP
This next fragment defines what will happen when a user selects either the
.CW "Exit"
or the
.CW "Send"
buttons. The
.CW "Exit"
behaviour is simple: the program ends. If a user touches
.CW Send ,
the program executes
.CW "tk->cmd"
to get whatever text is in the entry widget
.CW ".e"
then prints it to standard output.
.P1
	for(;;) {
		s := <- c;
		case s {
		"exit" =>
			return;

		"send" =>
			sys->print("name was: %s\en", tk->cmd(top, ".e get"));
		}
	}
.P2
.NH 1
Example - using Tk and Wmlib
.LP
This section uses both Tk and Wmlib to create a simple window manager application with a titlebar, including resize and exit buttons.
This is the usual way to create new windows.
.NH 1
Preamble
.LP
The example assumes that the
.CW "Tk"
module is loaded as before, as module variable
.CW "tk" ,
but furthermore that the
.CW "Wmlib"
module is also loaded, as
.CW "wmlib" :
.P1
include "tk.m";
	tk:	Tk;
include "wmlib.m";
	wmlib: Wmlib;
	...
	tk =  load Tk  Tk->PATH;
	wmlib = load Wmlib Wmlib->PATH;
	wmlib->init();
.P2
Note that
.CW wmlib->init
is called once to initialise the
.CW wmlib
module just loaded, before any other functions are called.
.LP
In window manager applications the
.CW Tk->toplevel
function is not normally used directly.
Instead, a window manager interface is used to create both
the top level widget and a channel to receive events from the window manager.
The
.CW titlebar
function has the signature:
.ps -1
.vs -1
.P1
	titlebar(scr: Draw->Screen, tkargs: string, title: string, buts: int):
		(ref Tk->Toplevel, chan of string);
.P2
.vs +1
.ps +1
The
.CW Screen
is the one on which the window is to be created, normally the
one passed in the
.CW Context
parameter to a program's
.CW init
function.
The
.I tkargs
parameter can control the position and appearance of the window,
but is best left nil (or the empty string) to use the window manager's
defaults (see
.I wmlib (2)
for details otherwise),
including automatic placement.
The
.I title
string gives the title that appears in the title bar.
Finally,
.I buts
is a bit set that selects the buttons to appear.
The value
.CW Wmlib->Appl
gives the usual resize and hide buttons;
the exit (delete) button always appears.
The following is used in the example:
.P1
	(top, titlechan) := wmlib->titlebar(ctxt.screen, nil,
					"Text Browser", Wmlib->Appl);
.P2
Note that
.CW titlebar
returns a tuple.
The first element is a reference to the Tk top level widget
for use in later Tk commands.
The second element of the tuple
is a Limbo channel of type
.CW "chan of string"
that passes window manager events to the application.
.LP
The channel
.CW "titlechan"
is used by
.CW "wmlib"
to send messages, but it is normally necessary
to create a channel to Tk to receive events from widgets the application creates:
.P1
	cmdchan := chan of string;
	tk->namechan(top, cmdchan, "cmdchan");
.P2
.NH 2
Defining and positioning widgets
.LP
The function
.CW "Wmlib->tkcmds"
takes two arguments, a
.CW "ref Tk->Toplevel"
that identifies a top level window,
and an
.CW "array of string" .
Each element of the array is a Tk command acceptable to
.CW "Tk->cmd" ;
.CW Wmlib->tkcmds
simply applies it
to each element of the array.
.LP
Most of the following fragment consists of Tk command strings that are members of the array of strings
.CW "tk_config" .
The comments describe the widgets being created. Not all widgets and menu items in this example are functional.
The last line executes the array of commands using
.CW "wmlib->tkcmds" :
.nr dP +1
.nr dV +1p
.P1
	tk_config := array[] of {

	\fI# define menubar frame, widget frame, text frame\fP
	"frame .mbar -relief groove -bd 2",
	"frame .w",
	"frame .text",

	\fI# define and pack menus\fP
	"menubutton .file -text File -menu .file.m",
	"menubutton .edit -text Edit -menu .edit.m",
	"menubutton .help -text Help -menu .help.m",

	"menu .file.m",
	".file.m add command -label Send -command {send cmdchan send}",
	".file.m add command -label Exit -command {send cmdchan exit}",
	"menu .edit.m",
	".edit.m add command -label Cut",

	"menu .help.m",
	".help.m add command -label Index -underline 0",

	"pack .file .edit -side left -in .mbar; update",
	"pack .help -side right -in .mbar",
.P3

	\fI# define and pack buttons and text entry box (for file name)\fP
	"button .b1 -text Send -command {send cmdchan send}",
	"button .b2 -text Open -command {send cmdchan open}",
	"label .l -text {Name: }",

	"entry .e",
	"bind .e <Key-\en> {send cmdchan open}",

	"pack .b1 .b2 .l .e -side left -in .w",
.P3

	\fI# define and pack text panel and its scrollbar\fP
	"text .t -yscrollcommand {.scroll set} -bg white",
	"scrollbar .scroll -command {.t yview}",
	"pack .scroll -side left -fill y -in .text",
	"pack .t -side right -in .text -expand 1 -fill both",

	\fI# pack frames\fP
	"pack .text -side bottom -fill both -expand 1",
	"pack .mbar .w -fill x; update",
	"pack propagate . 0",
	};

	\fI# run the Tk commands\fP
	wmlib->tkcmds(top, tk_config);
.P2
.nr dP -1
.nr dV -1p
The result of executing these Tk commands is shown in Figure 2.
.LP
The arrays defining Tk widgets are sometimes made global to a module
when they can sensibly be used by several functions.
It is also common to use small Limbo functions to replicate
similar widgets by building Tk commands from the value of parameters,
using Limbo string concatenation
or
.CW sys->sprint .
.FG "f2.ps" 2.16i
.ce
.I "Figure 2. A Wm application with a menu bar, a tool bar, and a text window."
.fg
.LP
.NH 2
Processing widget events
.LP
This fragment uses an
.CW "alt"
block to wait for strings to arrive from either
.CW "titlechan"
or
.CW "cmdchan" .
.LP
When a string is received on
.CW "titlechan" ,
the
.CW "case"
statement either handles it directly (as with
.CW exit )
or passes it to
.CW "wmlib->titlectl"
for normal handling by the window manager.
.LP
When a string is received on
.CW cmdchan ,
the program acts accordingly: it writes the text in the entry widget to standard output
.CW send ); (
calls
.CW "do_open"
to open the file name currently in the entry box
.CW open ); (
or returns from the processing loop
.CW exit ). (
.P1
	for(;;) {
		alt {
		s := <-titlechan =>	\fI# message from title bar buttons\fP
			case s {
			"exit" =>
				return;
			* =>
				wmlib->titlectl(top,s);
			}

		com := <-cmdchan =>	\fI# message from widgets created above\fP
			case com {
			"send" =>
				sys->print("name was: %s\en", tk->cmd(top, ".e get"));
			"open" =>
				do_open(top, tk->cmd(top, ".e get"));
			"exit" =>
				return;
			}
		}
	}
.P2
Although this example uses a Tk text entry widget,
.CW Wmlib
provides a function
.CW filename
that pops up a graphical device that allows a user to
select a file by typing a name, browsing the file system, or a mixture of both.
See
.I wmlib (2)
for details.
.NH 2
Putting text into the text widget
.LP
The
.CW "do_open"
function below uses
the buffered I/O module
.CW Bufio
to read lines from the file named in the entry widget and add them to the text currently in the text widget
.CW ".t" .
.P1
do_open(top: ref Tk->Toplevel, file: string)
{
	iofd := bufio->open(file, Bufio->OREAD);
	if(iofd == nil){
		wmlib->dialog(top, "error -fg red", "Open file",
			sys->sprint("%s: %r", file), 0, "Ok"::nil);
		return;
	}

	tk->cmd(top, ".t delete 1.0 end");
	tk->cmd(top, "cursor -bitmap cursor.wait");

	for(;;){
		line := iofd.gets('\en');
		if(line == nil)
			break;
		tk->cmd(top, ".t insert end '" + line);
	}
	tk->cmd(top, "cursor -default");
}
.P2
If the file cannot be opened,
.CW do_open
calls
.CW wmlib->dialog
to pop up a diagnostic message panel, rather than (say) printing a message to standard
error,
and returns.
If the file was opened,
.CW do_open
deletes the current
contents of the frame, and reads the
file into it, inserts one line at a time.
Tk allows the data inserted to contain embedded newlines, and
a more efficient implementation could read blocks
of data from the file and insert them, but some care is required.
A text file in Inferno contains Unicode characters in UTF-encoding, and the
bytes of a single character might be split across separate reads.
.CW Iobuf.gets
by contrast is guaranteed to reassemble complete Unicode characters from
the buffered input stream.
A program using
.CW Iobuf.read
(or
.CW Sys->read )
to fetch blocks of data would typically use
.CW Sys->utfbytes
to find maximal sequences of UTF-encoded characters
and insert large chunks of text at once.
See the function
.CW loadtfile
in
.CW /appl/wm/edit.b
for example.
.NH 1
Limbo/Tk command syntax
.LP
Once a toplevel widget has been built, an application calls
.CW "tk->cmd"
to issue commands to Tk and receive results.
This section describes in more detail the contents of the string argument
that conveys the commands.
.NH 2
Command strings
.LP
The command string may contain one or more commands, separated by semicolons. A semicolon is not a command separator when it is nested in braces
.CW "{}" ) (
or brackets
.CW "[]" ), (
or it is escaped by a backslash (\e).
.LP
Each command is divided into
.I "words" :
sequences of characters separated by one or more blanks or tabs,
subject to the following quoting rules:
.IP
.br
A word beginning with an opening brace
.CW { ) (
continues until the balancing closing brace
.CW } ) (
is reached.
The outer brace characters are stripped.
A backslash
.CW \e ) (
can be used to escape a brace, preventing special interpretation.
.IP
.br
A word beginning with an opening bracket
.CW [ ) (
continues until the balancing closing bracket
.CW ] ) (
is reached. The enclosed string is then evaluated as if it were a command string, and the resulting value is used as the contents of the word.
.IP
.br
At any point in the command string a single quote (\f5'\fP) causes the rest of the string to be treated as one word.
.LP
Single commands are executed in order until they are all done or an error is encountered. By convention, an error is signalled by a return value starting with an exclamation mark. The return value from
.CW "cmd"
is the return value of the first error-producing command or else the return value of the final single command.
.LP
To execute a single command, the first word is examined. It can be one of the following:
.IP \(bu
One of the following widget creating commands:
.RS
.TS
lf(CW) lf(CW) .
button	menu
canvas	menubutton
checkbutton	radiobutton
entry	scale
frame	scrollbar
label	text
listbox
.TE
The second word of each of these commands is the name of the widget to be created. The remaining words are option/value pairs.
.RE
.IP \(bu
A widget name (beginning with a dot
.CW . ') `
that corresponds to an existing widget. The second word gives the name of a particular widget subcommand and the remaining words are arguments for the subcommand.
.IP \(bu
A
.CW "pack" ,
.CW "bind" ,
.CW "focus" ,
.CW "grab" ,
.CW "put" ,
.CW "destroy" ,
.CW "image" ,
or
.CW "update"
command.
These commands manipulate existing widgets or control Tk.
Most are the same as documented for Tk 4.0.
The
.CW "bind"
command is significantly different, and the
.CW "image"
command is more limited.
.IP \(bu
The
.CW " send "
command,
which sends a string to a Limbo process.
The second word is the Tk name of a Limbo channel (previously registered with
.CW "namechan" ),
and the rest of the command is sent as a single string along the channel.
.IP \(bu
The
.CW "variable"
command.
Limbo/Tk generally does not provide the variables of Tcl/Tk; radio buttons are an exception. The
.CW "variable"
command takes the name of a variable defined in a radio button as the second word, and the value of the variable is the result of the command. Furthermore, there is one predefined variable whose value can be retrieved this way: the
.CW "lasterror"
variable is set every time a Tk command returns an error. The value is the offending command (possibly truncated) followed by the error return value. The
.CW "lasterror"
variable is cleared whenever it is retrieved using the variable command. This allows several
Tk commands to be executed without checking error returns each time. A call to the
.CW "variable"
command with
.CW "lasterror"
at strategic points can make sure that an unexpected error has not occurred.
.IP \(bu
The
.CW "cursor"
command. This command takes a number of option/value pairs to control the appearance and placement of the cursor. Available options are:
.Tk -x int
and
.Tk -y int ,
to change the cursor position to align its hotpoint at the given point (in screen coordinates);
.Tk -bitmap filename
or
.Tk -image imagename
to change the appearance of the cursor; and
.CW -default
to change back to the default appearance of the cursor.
.LP
Because the language accepted by the
.CW "cmd"
function has no user-defined functions, no control flow and very few variables, almost all applications need to have some of their logic in Limbo programs.
The modern concurrency constructions provided by Limbo \-
processes, channels, send/receive operators and
.CW alt \-
replace unstructured interrupts (`call backs'), often used by
other graphics systems, by structured control flow.
(The Inferno shell does provide support, however, for rapid prototyping using Tk
and a scripting language: see the manual pages for
.I sh-tk (1)
and
.I wish (1)
in Volume 1.)
.NH 2
Widget options
.LP
In Tk, all widget creation commands, and all
.CW "cget"
widget commands accept a common set of generic options in addition to widget-specific options.
Except as noted otherwise, the meanings are the same as they are in Tk 4.0. The allowable forms of things like
.I "color" ,
.I "dist" ,
and
.I "font"
are slightly different in Limbo/Tk.
See
.I types (9)
in Volume 1
for precise definitions.
The generic options are as follows:
.DS
.fi
.Tk -activebackground color
.br
.Tk -activeforeground color
.br
.Tk -actwidth dist
.br
.Tk -actheight dist
.DE
.QS
Note:
the
.CW -actwidth
and
.CW -actheight
variables are overridden by the
packer, but are useful as arguments to
.CW cget
to retrieve the actual
width and height (inside the border) of a widget after packing.
.QE
.DS
.fi
.Tk -background color
(or
.Tk -bg color )
.br
.Tk -borderwidth dist
(or
.Tk -bd dist )
.br
.Tk -font font
.br
.Tk -foreground color
(or
.Tk -fg color )
.br
.Tk -height dist
.br
.Tk -padx dist
.br
.Tk -pady dist
.br
.Tk -relief relief
.br
.Tk -state normal ,
.Tk -state active ,
or
.Tk -state disabled
.DE
.QS
Note:
.CW -state
is only relevant for some widgets (for example,
entry widgets).
.QE
.DS
.fi
.Tk -selectbackground color
.br
.Tk -selectborderwidth dist
.br
.Tk -selectcolor color
.DE
.QS
Note:
.CW -selectcolor
is the colour of the box in selection menu
items.
.QE
.DS
.fi
.Tk -selectforeground colour
.br
.Tk -width dist
.DE
In general, the manual page for each widget in section 9 of Volume 1 tells which of the
generic Tk options the widget accepts.
.LP
The
.I "dist"
parameters are lengths, expressed in the following form:
an optional minus sign, then one or more decimal digits (with possible embedded decimal point), then an optional units specifier.
The unit specifiers are the following:
.IP
.TS
lf(CW) lf(R)w(3i) .
c	centimetres
m	millimetres
i	inches
p	points
h	height of widget's font (*)
w	T{
width of `\f(CW0\fP' character in widget's font (*)
T}
.TE
.LP
The ones marked (*) are specific to Limbo/Tk.
.LP
Tcl/Tk 4.0 widgets do not uniformly take
.CW "-width"
and
.CW "-height"
options; instead, each widget may take either or both, and the interpretation
of a number lacking a unit specifier varies from widget to widget. For example, in Tk 4.0
.CW "-width 25"
means 25 characters to an entry widget, but 25 pixels to a canvas widget. In Limbo/Tk, all widgets may specify width and height, and bare numbers always mean screen pixels.
.LP
A
.I "colour"
parameter can be a colour name or an RGB value.
Only a few names are known:
.IP
.TS
lf(CW) lf(CW) lf(CW) lf(CW) lf(CW) .
aqua	fuchsia	maroon	purple	yellow
black	gray	navy	red
blue	green	olive	teal
darkblue	lime	orange	white
.TE
.LP
For RGB values, either
.CW "#" \fIrgb\fP
or
.CW "#" \fIrrggbb\fP
can be used, where
.I r ,
.I rr ,
etc.
are hexadecimal values for the corresponding colour components.
.LP
A
.I "font"
parameter gives the full path name of an Inferno font file; for example,
.CW "/fonts/pelm/unicode.9.font" .
.LP
A
.I bitmap
parameter is not used by any of the generic options, but is worth mentioning here.
Unlike Tk 4.0, a
.I bitmap
in Limbo/Tk is not restricted to a 1-bit deep bitmap to be coloured with foreground and background.
Instead, it can be a full-colour image (`pixmap' in X11 terminology),
which is displayed as is. If
.I "bitmap"
begins with a
.CW @ ', `
the remaining characters should be the path name of an Inferno image file. If
.I "bitmap"
begins with the character
.CW < ', `
the remaining characters must be a decimal integer giving a file descriptor number of an open file from which the bitmap can be loaded. Otherwise,
.I bitmap
should be the name of a bitmap file in the directory
.CW "/icons/tk" .
.NE 1i
.SH
Options not supported in Limbo/Tk
.LP
The following options provided by Tk 4.0 are not supported by any Limbo/Tk widget:
.P1
-cursor                  -insertofftime       -wraplength
-disabledforeground      -insertontime
-exportselection         -insertwidth
-geometry                -repeatdelay
-highlightbackground     -repeatinterval
-highlightcolor          -setgrid
-highlightthickness      -takefocus
-insertbackground        -textvariable
-insertborderwidth       -troughcolor
.P2
.NH 1
Limbo/Tk commands
.LP
This section lists all the commands documented in the Tk 4.0 man pages, giving the differences between the behaviour specified in those man pages and the behaviour implemented in Limbo/Tk.
Some common Tcl commands are listed as well.
Bear in mind that some Tk 4.0 options are unsupported, as noted above.
.Tc "bell" "[\f(CW-displayof \fP\fIwindow\fP]"
Not implemented.
.Tc "bind" "\fIwidget\fP <\fIevent-event-...-event\fP> \fIcommand\fP"
.d0
.Tc "bind" "\fIwidget\fP <\fIevent-event-...-event\fP> + \fIcommand\fP"
.d1
The bind command is perhaps the command that differs most from Tk 4.0.
In general, only a subset of its functionality is implemented. One difference is that
.I widget
must be the name of an existing widget.
The notion of a widget class is completely absent in Limbo/Tk.
Event sequence specifications are also more restricted. A sequence is either a single character (rune), meaning a
.CW "KeyPress"
of that character, or a sequence of
.I "events"
in angle brackets.
.I "Events"
are separated by blanks or minus signs.
See
.I bind (9)
for a complete discussion.
.Tc "bindtags" "\fIwindow\fP [\fItaglist\fP]"
Not implemented.
.Tc button "\fIpathname\fP \*(Op"
As in Tk 4.0 (but note difference in units for
.CW "-height"
and
.CW "-width" ).
.Tc canvas "\fIpathname\fP \*(Op"
The Postscript subcommand is not implemented.
.Tc checkbutton "\fIpathname\fP \*(Op"
Unimplemented options:
.CW "-indicatoron" ,
.CW "-offvalue" ,
.CW "-onvalue" ,
and
.CW "-selectimage" .
The
.CW flash
subcommand is not implemented.
.Tc clipboard \fIoperation\fP [\fIarg ...\fP]"
Not implemented.
.Tc "\fIpathname\fP configure [" "option ...\f5]\f1"
Configure options for widget
.I pathname .
Widget-specific; see the manual entry for the widget in
section 9 of Volume 1.
.Tc destroy "[\fIwindow ...\fP]"
As in Tk 4.0, but
note that
.CW "destroy ." ' `
is rarely needed because top level windows are automatically
destroyed by the Inferno garbage collector immediately when the last reference vanishes.
.Tc entry "\fIpathname\fP \*(Op"
The
.CW scan
subcommand is not implemented. Some key bindings are not implemented when there is currently no way to type those keys to Inferno (for example,
.CW "Home" ).
Note difference in units for
.CW "-height"
and
.CW "-width" .
.Tc "event" \fIoperation\fP [\fIarg ...\fP]"
Not implemented: normally replaced by Tk
.CW send
or Limbo channel send operation within the application.
.Tc focus \fIwindow\fP
The focus model in Inferno is different. Only one widget has the keyboard focus at a given time. Limbo/Tk does not maintain a private keyboard focus for each toplevel tree and automatically move the focus there whenever the tree is entered. (Canvas and text widgets, however, do maintain a private keyboard focus.)
The Limbo/Tk
.CW "focus"
command moves the keyboard focus to the given
.I window .
By default, the first press of the primary button in an
.CW "entry" ,
.CW "listbox"
or
.CW "text"
widget causes the focus to be moved to that widget. Just entering a menu widget gives it the focus.
The
.CW "-displayof" ,
.CW "-force"
and
.CW "-lastfor"
options are not implemented.
.Tc frame "\fIpathname\fP \*(Op"
Unimplemented options:
.CW "class" ,
.CW "colormap" ,
and
.CW "visual" .
.Tc grab "\fIwindow\fP"
.d0
.Tc grab "\fIoption\fP [\fIarg ...\fP]"
.d1
Limbo/Tk implements only global grabs, so the
.CW "-global"
option is not recognised. The
.CW "grab current"
command is not implemented. The
.CW "grab"
command is not recognised as a synonym for
.CW "grab set" .
.Tc "grid" "\fIoperation\fP [\fIarg ...\fP]"
Not implemented.
.Tc "image create bitmap" "[\fIname\fP] [\fIoptions\fP]"
.d0
.Tc image "\fIoption\fP [\fIarg arg ...\fP]"
.d1
Only bitmap image types are implemented, but, as documented under
.CW "bitmap" ,
Inferno `bitmaps' are not just 1-bit deep;
they encompass both bitmaps and `photo' (colour) images
as provided by Tk/4.0.
Limbo/Tk does not, however, recognise the wide variety of graphics formats that Tk 4.0 does.
Instead, only Inferno's own format is supported internally, and external programs
are provided to convert between that and other formats such as JPEG.
The file descriptor syntax for specifying bitmaps is useful when an external program writes the bitmap to a file descriptor.
If a maskfile is given, it may also have a depth greater than 1 bit; the meaning is that if a pixel of the mask is non-zero then the corresponding pixel of the image should be drawn.
(But see the handling of bitmaps used as stipples in
.I canvas (9).)
The
.CW -data
and
.CW -maskdata
options are not implemented.
.Tc label "\fIpathname\fP \*(Op"
Unimplemented options:
.CW "-justify"
and
.CW "-wraplength" .
Note difference in units for
.CW "-height"
and
.CW "-width" .
.Tc listbox "\fIpathname\fP \*(Op"
The
.CW "bbox"
and
.CW "scan"
subcommands are not implemented. Note difference in units for
.CW "-height"
and
.CW "-width" .
.Tc lower \fIwindow\fP
The
.CW "belowThis"
optional parameter is not recognised.
.Tc menu "\fIpathname\fP \*(Op"
Unimplemented options:
.CW "-postcommand" ,
.CW "-tearoff" ,
.CW "-tearoff"
command, and
.CW "-transient" .
In the
.CW add
subcommand, the
.CW "-accelerator" ,
.CW "-indicatoron" ,
and
.CW "-selectimage"
options are not implemented. In the
.CW "index"
subcommand, the
.CW "last"
and
.CW "pattern"
index forms are not implemented. The
.CW "configure"
and
.CW "entrycget"
subcommands are not implemented.
.Tc menubutton "\fIpathname\fP \*(Op"
Unimplemented options:
.CW "-indicatoron" ,
.CW "-justify" ,
and
.CW "-wraplength" .
.Tc "message" "\fIpathname\fP \*(Op"
Not implemented (subsumed by
.CW "label" ).
.Tc "option" "\fIoperation\fP [\fIarg ...\fP]"
Not implemented. There is no option database.
.Tc pack "\fIoption arg ...\fP"
.d0
.Tc pack "\fIslave\fP ...\*(Op"
.Tc "pack configure" "\fIslave\fP ... \*(Op"
.Tc "pack forget" "\fIslave\fP ..."
.Tc "pack propagate" "\fImaster\fP [0 | 1]"
.Tc "pack slaves" "\fImaster\fP"
.d1
The
.CW "info"
subcommand is not implemented.
.Tc place "\fIoperation\fP [\fIarg ...\fP]"
Not implemented.
.Tc radiobutton "\fIpathname\fP \*(Op"
Unimplemented options:
.CW "-indicatoron" ,
.CW "-justify" ,
.CW "-selectimage" ,
and
.CW -wraplength .
The
.CW "flash"
subcommand is not implemented.
.Tc raise \fIwindow\fP
The
.CW "aboveThis"
optional parameter is not recognised.
.Tc scale "\fIpathname\fP \*(Op"
Unimplemented options:
.CW "-digits "
and
.CW "-variable" .
.Tc scrollbar "\fIpathname\fP \*(Op"
The old syntax of
.CW "set"
and
.CW "get"
is not supported.
.Tc "selection"
Not implemented.
.Tc send "\fIchanname string\fP"
Rather than sending data to a different application, the
.CW "send"
command sends a given
.I string
down the Limbo channel associated with
.I channame ,
as set by
.CW namechan .
.Tc text "\fIpathname\fP \*(Op"
The
.CW "dump"
subcommand is not implemented. The
.CW "-regexp"
mode of the
.CW "search"
subcommand is not implemented.
.Tc tk "\fIoperation\fP [\fIarg ...\fP]"
Not implemented.
.Tc "tkerror"
Not implemented.
.Tc "tkwait" "\fIoperation name\fP"
Not implemented.
.Tc "toplevel" "\fIpathname\fP [\fIoption value\fP...]"
There is no
.CW "toplevel"
Tk command implemented by the
.CW "cmd"
function; instead, the Tk module entry point
.CW "toplevel"
is used to make toplevel widgets (windows)
as described above.
.Tc update
In Tcl/Tk,
.CW update
is a Tcl command that invokes the `event handler loop'.
In Limbo/Tk,
it flushes any pending updates to the screen.
The optional
.CW "idletasks"
argument is not recognised.
.Tc "winfo" "\fIoperation\fP [\fIarg ...\fP]"
Not implemented. Much of the information that
.CW "winfo"
would return can be got by applying
.CW "cget"
to each widget.
.Tc "wm" "\fIoperation window\fP [\fIarg ...\fP]"
Not implemented.
.NH 2
References
.IP 1.
John K Ousterhout,
.I "Tcl and the Tk Toolkit" ,
Addison-Wesley Publishing Company, Reading, Massachusetts, 1994.
.IP 2.
Paul Raines and Jeff Trantor,
.I "Tcl/Tk in a Nutshell" ,
O'Reilly, Sebastopol, California, 1999.
.IP 3.
B W Kernighan,
``Descent into Limbo'',
elsewhere in this volume.
.IP 4.
See
.I draw-intro (2),
.I tk (2)
and
.I wmlib (2)
in
.I "The Inferno Programmer's Manual",
Volume 1.