summaryrefslogtreecommitdiffstats
path: root/Doc/lib/libstdwin.tex
blob: e009e3f0e064015a863cd4dc4e3ecd6a16079698 (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
\chapter{Standard Windowing Interface}

The modules in this chapter are available only on those systems where
the STDWIN library is available.  STDWIN runs on \UNIX{} under X11 and
on the Macintosh.  See CWI report CS-R8817.

\strong{Warning:} Using STDWIN is not recommended for new
applications.  It has never been ported to Microsoft Windows or
Windows NT, and for X11 or the Macintosh it lacks important
functionality --- in particular, it has no tools for the construction
of dialogs.  For most platforms, alternative, native solutions exist
(though none are currently documented in this manual): Tkinter for
\UNIX{} under X11, native Xt with Motif or Athena widgets for \UNIX{}
under X11, Win32 for Windows and Windows NT, and a collection of
native toolkit interfaces for the Macintosh.

\section{Built-in Module \sectcode{stdwin}}
\bimodindex{stdwin}

This module defines several new object types and functions that
provide access to the functionality of STDWIN.

On Unix running X11, it can only be used if the \code{DISPLAY}
environment variable is set or an explicit \samp{-display
\var{displayname}} argument is passed to the Python interpreter.

Functions have names that usually resemble their C STDWIN counterparts
with the initial `w' dropped.
Points are represented by pairs of integers; rectangles
by pairs of points.
For a complete description of STDWIN please refer to the documentation
of STDWIN for C programmers (aforementioned CWI report).

\subsection{Functions Defined in Module \sectcode{stdwin}}
\nodename{STDWIN Functions}

The following functions are defined in the \code{stdwin} module:

\renewcommand{\indexsubitem}{(in module stdwin)}
\begin{funcdesc}{open}{title}
Open a new window whose initial title is given by the string argument.
Return a window object; window object methods are described below.%
\footnote{The Python version of STDWIN does not support draw procedures; all
	drawing requests are reported as draw events.}
\end{funcdesc}

\begin{funcdesc}{getevent}{}
Wait for and return the next event.
An event is returned as a triple: the first element is the event
type, a small integer; the second element is the window object to which
the event applies, or
\code{None}
if it applies to no window in particular;
the third element is type-dependent.
Names for event types and command codes are defined in the standard
module
\code{stdwinevent}.
\end{funcdesc}

\begin{funcdesc}{pollevent}{}
Return the next event, if one is immediately available.
If no event is available, return \code{()}.
\end{funcdesc}

\begin{funcdesc}{getactive}{}
Return the window that is currently active, or \code{None} if no
window is currently active.  (This can be emulated by monitoring
WE_ACTIVATE and WE_DEACTIVATE events.)
\end{funcdesc}

\begin{funcdesc}{listfontnames}{pattern}
Return the list of font names in the system that match the pattern (a
string).  The pattern should normally be \code{'*'}; returns all
available fonts.  If the underlying window system is X11, other
patterns follow the standard X11 font selection syntax (as used e.g.
in resource definitions), i.e. the wildcard character \code{'*'}
matches any sequence of characters (including none) and \code{'?'}
matches any single character.
On the Macintosh this function currently returns an empty list.
\end{funcdesc}

\begin{funcdesc}{setdefscrollbars}{hflag\, vflag}
Set the flags controlling whether subsequently opened windows will
have horizontal and/or vertical scroll bars.
\end{funcdesc}

\begin{funcdesc}{setdefwinpos}{h\, v}
Set the default window position for windows opened subsequently.
\end{funcdesc}

\begin{funcdesc}{setdefwinsize}{width\, height}
Set the default window size for windows opened subsequently.
\end{funcdesc}

\begin{funcdesc}{getdefscrollbars}{}
Return the flags controlling whether subsequently opened windows will
have horizontal and/or vertical scroll bars.
\end{funcdesc}

\begin{funcdesc}{getdefwinpos}{}
Return the default window position for windows opened subsequently.
\end{funcdesc}

\begin{funcdesc}{getdefwinsize}{}
Return the default window size for windows opened subsequently.
\end{funcdesc}

\begin{funcdesc}{getscrsize}{}
Return the screen size in pixels.
\end{funcdesc}

\begin{funcdesc}{getscrmm}{}
Return the screen size in millimeters.
\end{funcdesc}

\begin{funcdesc}{fetchcolor}{colorname}
Return the pixel value corresponding to the given color name.
Return the default foreground color for unknown color names.
Hint: the following code tests whether you are on a machine that
supports more than two colors:
\bcode\begin{verbatim}
if stdwin.fetchcolor('black') <> \
          stdwin.fetchcolor('red') <> \
          stdwin.fetchcolor('white'):
    print 'color machine'
else:
    print 'monochrome machine'
\end{verbatim}\ecode
\end{funcdesc}

\begin{funcdesc}{setfgcolor}{pixel}
Set the default foreground color.
This will become the default foreground color of windows opened
subsequently, including dialogs.
\end{funcdesc}

\begin{funcdesc}{setbgcolor}{pixel}
Set the default background color.
This will become the default background color of windows opened
subsequently, including dialogs.
\end{funcdesc}

\begin{funcdesc}{getfgcolor}{}
Return the pixel value of the current default foreground color.
\end{funcdesc}

\begin{funcdesc}{getbgcolor}{}
Return the pixel value of the current default background color.
\end{funcdesc}

\begin{funcdesc}{setfont}{fontname}
Set the current default font.
This will become the default font for windows opened subsequently,
and is also used by the text measuring functions \code{textwidth},
\code{textbreak}, \code{lineheight} and \code{baseline} below.
This accepts two more optional parameters, size and style:
Size is the font size (in `points').
Style is a single character specifying the style, as follows:
\code{'b'} = bold,
\code{'i'} = italic,
\code{'o'} = bold + italic,
\code{'u'} = underline;
default style is roman.
Size and style are ignored under X11 but used on the Macintosh.
(Sorry for all this complexity --- a more uniform interface is being designed.)
\end{funcdesc}

\begin{funcdesc}{menucreate}{title}
Create a menu object referring to a global menu (a menu that appears in
all windows).
Methods of menu objects are described below.
Note: normally, menus are created locally; see the window method
\code{menucreate} below.
\strong{Warning:} the menu only appears in a window as long as the object
returned by this call exists.
\end{funcdesc}

\begin{funcdesc}{newbitmap}{width\, height}
Create a new bitmap object of the given dimensions.
Methods of bitmap objects are described below.
Not available on the Macintosh.
\end{funcdesc}

\begin{funcdesc}{fleep}{}
Cause a beep or bell (or perhaps a `visual bell' or flash, hence the
name).
\end{funcdesc}

\begin{funcdesc}{message}{string}
Display a dialog box containing the string.
The user must click OK before the function returns.
\end{funcdesc}

\begin{funcdesc}{askync}{prompt\, default}
Display a dialog that prompts the user to answer a question with yes or
no.
Return 0 for no, 1 for yes.
If the user hits the Return key, the default (which must be 0 or 1) is
returned.
If the user cancels the dialog, the
\code{KeyboardInterrupt}
exception is raised.
\end{funcdesc}

\begin{funcdesc}{askstr}{prompt\, default}
Display a dialog that prompts the user for a string.
If the user hits the Return key, the default string is returned.
If the user cancels the dialog, the
\code{KeyboardInterrupt}
exception is raised.
\end{funcdesc}

\begin{funcdesc}{askfile}{prompt\, default\, new}
Ask the user to specify a filename.
If
\var{new}
is zero it must be an existing file; otherwise, it must be a new file.
If the user cancels the dialog, the
\code{KeyboardInterrupt}
exception is raised.
\end{funcdesc}

\begin{funcdesc}{setcutbuffer}{i\, string}
Store the string in the system's cut buffer number
\var{i},
where it can be found (for pasting) by other applications.
On X11, there are 8 cut buffers (numbered 0..7).
Cut buffer number 0 is the `clipboard' on the Macintosh.
\end{funcdesc}

\begin{funcdesc}{getcutbuffer}{i}
Return the contents of the system's cut buffer number
\var{i}.
\end{funcdesc}

\begin{funcdesc}{rotatecutbuffers}{n}
On X11, rotate the 8 cut buffers by
\var{n}.
Ignored on the Macintosh.
\end{funcdesc}

\begin{funcdesc}{getselection}{i}
Return X11 selection number
\var{i.}
Selections are not cut buffers.
Selection numbers are defined in module
\code{stdwinevents}.
Selection \code{WS_PRIMARY} is the
\dfn{primary}
selection (used by
xterm,
for instance);
selection \code{WS_SECONDARY} is the
\dfn{secondary}
selection; selection \code{WS_CLIPBOARD} is the
\dfn{clipboard}
selection (used by
xclipboard).
On the Macintosh, this always returns an empty string.
\end{funcdesc}

\begin{funcdesc}{resetselection}{i}
Reset selection number
\var{i},
if this process owns it.
(See window method
\code{setselection()}).
\end{funcdesc}

\begin{funcdesc}{baseline}{}
Return the baseline of the current font (defined by STDWIN as the
vertical distance between the baseline and the top of the
characters).
\end{funcdesc}

\begin{funcdesc}{lineheight}{}
Return the total line height of the current font.
\end{funcdesc}

\begin{funcdesc}{textbreak}{str\, width}
Return the number of characters of the string that fit into a space of
\var{width}
bits wide when drawn in the curent font.
\end{funcdesc}

\begin{funcdesc}{textwidth}{str}
Return the width in bits of the string when drawn in the current font.
\end{funcdesc}

\begin{funcdesc}{connectionnumber}{}
\funcline{fileno}{}
(X11 under \UNIX{} only) Return the ``connection number'' used by the
underlying X11 implementation.  (This is normally the file number of
the socket.)  Both functions return the same value;
\code{connectionnumber()} is named after the corresponding function in
X11 and STDWIN, while \code{fileno()} makes it possible to use the
\code{stdwin} module as a ``file'' object parameter to
\code{select.select()}.  Note that if \code{select()} implies that
input is possible on \code{stdwin}, this does not guarantee that an
event is ready --- it may be some internal communication going on
between the X server and the client library.  Thus, you should call
\code{stdwin.pollevent()} until it returns \code{None} to check for
events if you don't want your program to block.  Because of internal
buffering in X11, it is also possible that \code{stdwin.pollevent()}
returns an event while \code{select()} does not find \code{stdwin} to
be ready, so you should read any pending events with
\code{stdwin.pollevent()} until it returns \code{None} before entering
a blocking \code{select()} call.
\ttindex{select}
\end{funcdesc}

\subsection{Window Objects}

Window objects are created by \code{stdwin.open()}.  They are closed
by their \code{close()} method or when they are garbage-collected.
Window objects have the following methods:

\renewcommand{\indexsubitem}{(window method)}

\begin{funcdesc}{begindrawing}{}
Return a drawing object, whose methods (described below) allow drawing
in the window.
\end{funcdesc}

\begin{funcdesc}{change}{rect}
Invalidate the given rectangle; this may cause a draw event.
\end{funcdesc}

\begin{funcdesc}{gettitle}{}
Returns the window's title string.
\end{funcdesc}

\begin{funcdesc}{getdocsize}{}
\begin{sloppypar}
Return a pair of integers giving the size of the document as set by
\code{setdocsize()}.
\end{sloppypar}
\end{funcdesc}

\begin{funcdesc}{getorigin}{}
Return a pair of integers giving the origin of the window with respect
to the document.
\end{funcdesc}

\begin{funcdesc}{gettitle}{}
Return the window's title string.
\end{funcdesc}

\begin{funcdesc}{getwinsize}{}
Return a pair of integers giving the size of the window.
\end{funcdesc}

\begin{funcdesc}{getwinpos}{}
Return a pair of integers giving the position of the window's upper
left corner (relative to the upper left corner of the screen).
\end{funcdesc}

\begin{funcdesc}{menucreate}{title}
Create a menu object referring to a local menu (a menu that appears
only in this window).
Methods of menu objects are described below.
{\bf Warning:} the menu only appears as long as the object
returned by this call exists.
\end{funcdesc}

\begin{funcdesc}{scroll}{rect\, point}
Scroll the given rectangle by the vector given by the point.
\end{funcdesc}

\begin{funcdesc}{setdocsize}{point}
Set the size of the drawing document.
\end{funcdesc}

\begin{funcdesc}{setorigin}{point}
Move the origin of the window (its upper left corner)
to the given point in the document.
\end{funcdesc}

\begin{funcdesc}{setselection}{i\, str}
Attempt to set X11 selection number
\var{i}
to the string
\var{str}.
(See stdwin method
\code{getselection()}
for the meaning of
\var{i}.)
Return true if it succeeds.
If  succeeds, the window ``owns'' the selection until
(a) another application takes ownership of the selection; or
(b) the window is deleted; or
(c) the application clears ownership by calling
\code{stdwin.resetselection(\var{i})}.
When another application takes ownership of the selection, a
\code{WE_LOST_SEL}
event is received for no particular window and with the selection number
as detail.
Ignored on the Macintosh.
\end{funcdesc}

\begin{funcdesc}{settimer}{dsecs}
Schedule a timer event for the window in
\code{\var{dsecs}/10}
seconds.
\end{funcdesc}

\begin{funcdesc}{settitle}{title}
Set the window's title string.
\end{funcdesc}

\begin{funcdesc}{setwincursor}{name}
\begin{sloppypar}
Set the window cursor to a cursor of the given name.
It raises the
\code{RuntimeError}
exception if no cursor of the given name exists.
Suitable names include
\code{'ibeam'},
\code{'arrow'},
\code{'cross'},
\code{'watch'}
and
\code{'plus'}.
On X11, there are many more (see
\file{<X11/cursorfont.h>}).
\end{sloppypar}
\end{funcdesc}

\begin{funcdesc}{setwinpos}{h\, v}
Set the the position of the window's upper left corner (relative to
the upper left corner of the screen).
\end{funcdesc}

\begin{funcdesc}{setwinsize}{width\, height}
Set the window's size.
\end{funcdesc}

\begin{funcdesc}{show}{rect}
Try to ensure that the given rectangle of the document is visible in
the window.
\end{funcdesc}

\begin{funcdesc}{textcreate}{rect}
Create a text-edit object in the document at the given rectangle.
Methods of text-edit objects are described below.
\end{funcdesc}

\begin{funcdesc}{setactive}{}
Attempt to make this window the active window.  If successful, this
will generate a WE_ACTIVATE event (and a WE_DEACTIVATE event in case
another window in this application became inactive).
\end{funcdesc}

\begin{funcdesc}{close}{}
Discard the window object.  It should not be used again.
\end{funcdesc}

\subsection{Drawing Objects}

Drawing objects are created exclusively by the window method
\code{begindrawing()}.
Only one drawing object can exist at any given time; the drawing object
must be deleted to finish drawing.
No drawing object may exist when
\code{stdwin.getevent()}
is called.
Drawing objects have the following methods:

\renewcommand{\indexsubitem}{(drawing method)}

\begin{funcdesc}{box}{rect}
Draw a box just inside a rectangle.
\end{funcdesc}

\begin{funcdesc}{circle}{center\, radius}
Draw a circle with given center point and radius.
\end{funcdesc}

\begin{funcdesc}{elarc}{center\, \(rh\, rv\)\, \(a1\, a2\)}
Draw an elliptical arc with given center point.
\code{(\var{rh}, \var{rv})}
gives the half sizes of the horizontal and vertical radii.
\code{(\var{a1}, \var{a2})}
gives the angles (in degrees) of the begin and end points.
0 degrees is at 3 o'clock, 90 degrees is at 12 o'clock.
\end{funcdesc}

\begin{funcdesc}{erase}{rect}
Erase a rectangle.
\end{funcdesc}

\begin{funcdesc}{fillcircle}{center\, radius}
Draw a filled circle with given center point and radius.
\end{funcdesc}

\begin{funcdesc}{fillelarc}{center\, \(rh\, rv\)\, \(a1\, a2\)}
Draw a filled elliptical arc; arguments as for \code{elarc}.
\end{funcdesc}

\begin{funcdesc}{fillpoly}{points}
Draw a filled polygon given by a list (or tuple) of points.
\end{funcdesc}

\begin{funcdesc}{invert}{rect}
Invert a rectangle.
\end{funcdesc}

\begin{funcdesc}{line}{p1\, p2}
Draw a line from point
\var{p1}
to
\var{p2}.
\end{funcdesc}

\begin{funcdesc}{paint}{rect}
Fill a rectangle.
\end{funcdesc}

\begin{funcdesc}{poly}{points}
Draw the lines connecting the given list (or tuple) of points.
\end{funcdesc}

\begin{funcdesc}{shade}{rect\, percent}
Fill a rectangle with a shading pattern that is about
\var{percent}
percent filled.
\end{funcdesc}

\begin{funcdesc}{text}{p\, str}
Draw a string starting at point p (the point specifies the
top left coordinate of the string).
\end{funcdesc}

\begin{funcdesc}{xorcircle}{center\, radius}
\funcline{xorelarc}{center\, \(rh\, rv\)\, \(a1\, a2\)}
\funcline{xorline}{p1\, p2}
\funcline{xorpoly}{points}
Draw a circle, an elliptical arc, a line or a polygon, respectively,
in XOR mode.
\end{funcdesc}

\begin{funcdesc}{setfgcolor}{}
\funcline{setbgcolor}{}
\funcline{getfgcolor}{}
\funcline{getbgcolor}{}
These functions are similar to the corresponding functions described
above for the
\code{stdwin}
module, but affect or return the colors currently used for drawing
instead of the global default colors.
When a drawing object is created, its colors are set to the window's
default colors, which are in turn initialized from the global default
colors when the window is created.
\end{funcdesc}

\begin{funcdesc}{setfont}{}
\funcline{baseline}{}
\funcline{lineheight}{}
\funcline{textbreak}{}
\funcline{textwidth}{}
These functions are similar to the corresponding functions described
above for the
\code{stdwin}
module, but affect or use the current drawing font instead of
the global default font.
When a drawing object is created, its font is set to the window's
default font, which is in turn initialized from the global default
font when the window is created.
\end{funcdesc}

\begin{funcdesc}{bitmap}{point\, bitmap\, mask}
Draw the \var{bitmap} with its top left corner at \var{point}.
If the optional \var{mask} argument is present, it should be either
the same object as \var{bitmap}, to draw only those bits that are set
in the bitmap, in the foreground color, or \code{None}, to draw all
bits (ones are drawn in the foreground color, zeros in the background
color).
Not available on the Macintosh.
\end{funcdesc}

\begin{funcdesc}{cliprect}{rect}
Set the ``clipping region'' to a rectangle.
The clipping region limits the effect of all drawing operations, until
it is changed again or until the drawing object is closed.  When a
drawing object is created the clipping region is set to the entire
window.  When an object to be drawn falls partly outside the clipping
region, the set of pixels drawn is the intersection of the clipping
region and the set of pixels that would be drawn by the same operation
in the absence of a clipping region.
\end{funcdesc}

\begin{funcdesc}{noclip}{}
Reset the clipping region to the entire window.
\end{funcdesc}

\begin{funcdesc}{close}{}
\funcline{enddrawing}{}
Discard the drawing object.  It should not be used again.
\end{funcdesc}

\subsection{Menu Objects}

A menu object represents a menu.
The menu is destroyed when the menu object is deleted.
The following methods are defined:

\renewcommand{\indexsubitem}{(menu method)}

\begin{funcdesc}{additem}{text\, shortcut}
Add a menu item with given text.
The shortcut must be a string of length 1, or omitted (to specify no
shortcut).
\end{funcdesc}

\begin{funcdesc}{setitem}{i\, text}
Set the text of item number
\var{i}.
\end{funcdesc}

\begin{funcdesc}{enable}{i\, flag}
Enable or disables item
\var{i}.
\end{funcdesc}

\begin{funcdesc}{check}{i\, flag}
Set or clear the
\dfn{check mark}
for item
\var{i}.
\end{funcdesc}

\begin{funcdesc}{close}{}
Discard the menu object.  It should not be used again.
\end{funcdesc}

\subsection{Bitmap Objects}

A bitmap represents a rectangular array of bits.
The top left bit has coordinate (0, 0).
A bitmap can be drawn with the \code{bitmap} method of a drawing object.
Bitmaps are currently not available on the Macintosh.

The following methods are defined:

\renewcommand{\indexsubitem}{(bitmap method)}

\begin{funcdesc}{getsize}{}
Return a tuple representing the width and height of the bitmap.
(This returns the values that have been passed to the \code{newbitmap}
function.)
\end{funcdesc}

\begin{funcdesc}{setbit}{point\, bit}
Set the value of the bit indicated by \var{point} to \var{bit}.
\end{funcdesc}

\begin{funcdesc}{getbit}{point}
Return the value of the bit indicated by \var{point}.
\end{funcdesc}

\begin{funcdesc}{close}{}
Discard the bitmap object.  It should not be used again.
\end{funcdesc}

\subsection{Text-edit Objects}

A text-edit object represents a text-edit block.
For semantics, see the STDWIN documentation for C programmers.
The following methods exist:

\renewcommand{\indexsubitem}{(text-edit method)}

\begin{funcdesc}{arrow}{code}
Pass an arrow event to the text-edit block.
The
\var{code}
must be one of
\code{WC_LEFT},
\code{WC_RIGHT},
\code{WC_UP}
or
\code{WC_DOWN}
(see module
\code{stdwinevents}).
\end{funcdesc}

\begin{funcdesc}{draw}{rect}
Pass a draw event to the text-edit block.
The rectangle specifies the redraw area.
\end{funcdesc}

\begin{funcdesc}{event}{type\, window\, detail}
Pass an event gotten from
\code{stdwin.getevent()}
to the text-edit block.
Return true if the event was handled.
\end{funcdesc}

\begin{funcdesc}{getfocus}{}
Return 2 integers representing the start and end positions of the
focus, usable as slice indices on the string returned by
\code{gettext()}.
\end{funcdesc}

\begin{funcdesc}{getfocustext}{}
Return the text in the focus.
\end{funcdesc}

\begin{funcdesc}{getrect}{}
Return a rectangle giving the actual position of the text-edit block.
(The bottom coordinate may differ from the initial position because
the block automatically shrinks or grows to fit.)
\end{funcdesc}

\begin{funcdesc}{gettext}{}
Return the entire text buffer.
\end{funcdesc}

\begin{funcdesc}{move}{rect}
Specify a new position for the text-edit block in the document.
\end{funcdesc}

\begin{funcdesc}{replace}{str}
Replace the text in the focus by the given string.
The new focus is an insert point at the end of the string.
\end{funcdesc}

\begin{funcdesc}{setfocus}{i\, j}
Specify the new focus.
Out-of-bounds values are silently clipped.
\end{funcdesc}

\begin{funcdesc}{settext}{str}
Replace the entire text buffer by the given string and set the focus
to \code{(0, 0)}.
\end{funcdesc}

\begin{funcdesc}{setview}{rect}
Set the view rectangle to \var{rect}.  If \var{rect} is \code{None},
viewing mode is reset.  In viewing mode, all output from the text-edit
object is clipped to the viewing rectangle.  This may be useful to
implement your own scrolling text subwindow.
\end{funcdesc}

\begin{funcdesc}{close}{}
Discard the text-edit object.  It should not be used again.
\end{funcdesc}

\subsection{Example}
\nodename{STDWIN Example}

Here is a minimal example of using STDWIN in Python.
It creates a window and draws the string ``Hello world'' in the top
left corner of the window.
The window will be correctly redrawn when covered and re-exposed.
The program quits when the close icon or menu item is requested.

\bcode\begin{verbatim}
import stdwin
from stdwinevents import *

def main():
    mywin = stdwin.open('Hello')
    #
    while 1:
        (type, win, detail) = stdwin.getevent()
        if type == WE_DRAW:
            draw = win.begindrawing()
            draw.text((0, 0), 'Hello, world')
            del draw
        elif type == WE_CLOSE:
            break

main()
\end{verbatim}\ecode

\section{Standard Module \sectcode{stdwinevents}}
\stmodindex{stdwinevents}

This module defines constants used by STDWIN for event types
(\code{WE_ACTIVATE} etc.), command codes (\code{WC_LEFT} etc.)
and selection types (\code{WS_PRIMARY} etc.).
Read the file for details.
Suggested usage is

\bcode\begin{verbatim}
>>> from stdwinevents import *
>>> 
\end{verbatim}\ecode

\section{Standard Module \sectcode{rect}}
\stmodindex{rect}

This module contains useful operations on rectangles.
A rectangle is defined as in module
\code{stdwin}:
a pair of points, where a point is a pair of integers.
For example, the rectangle

\bcode\begin{verbatim}
(10, 20), (90, 80)
\end{verbatim}\ecode

is a rectangle whose left, top, right and bottom edges are 10, 20, 90
and 80, respectively.
Note that the positive vertical axis points down (as in
\code{stdwin}).

The module defines the following objects:

\renewcommand{\indexsubitem}{(in module rect)}
\begin{excdesc}{error}
The exception raised by functions in this module when they detect an
error.
The exception argument is a string describing the problem in more
detail.
\end{excdesc}

\begin{datadesc}{empty}
The rectangle returned when some operations return an empty result.
This makes it possible to quickly check whether a result is empty:

\bcode\begin{verbatim}
>>> import rect
>>> r1 = (10, 20), (90, 80)
>>> r2 = (0, 0), (10, 20)
>>> r3 = rect.intersect([r1, r2])
>>> if r3 is rect.empty: print 'Empty intersection'
Empty intersection
>>> 
\end{verbatim}\ecode
\end{datadesc}

\begin{funcdesc}{is_empty}{r}
Returns true if the given rectangle is empty.
A rectangle
\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})}
is empty if
\iftexi
\code{\var{left} >= \var{right}} or \code{\var{top} => \var{bottom}}.
\else
$\var{left} \geq \var{right}$ or $\var{top} \geq \var{bottom}$.
%%JHXXX{\em left~$\geq$~right} or {\em top~$\leq$~bottom}.
\fi
\end{funcdesc}

\begin{funcdesc}{intersect}{list}
Returns the intersection of all rectangles in the list argument.
It may also be called with a tuple argument.
Raises
\code{rect.error}
if the list is empty.
Returns
\code{rect.empty}
if the intersection of the rectangles is empty.
\end{funcdesc}

\begin{funcdesc}{union}{list}
Returns the smallest rectangle that contains all non-empty rectangles in
the list argument.
It may also be called with a tuple argument or with two or more
rectangles as arguments.
Returns
\code{rect.empty}
if the list is empty or all its rectangles are empty.
\end{funcdesc}

\begin{funcdesc}{pointinrect}{point\, rect}
Returns true if the point is inside the rectangle.
By definition, a point
\code{(\var{h}, \var{v})}
is inside a rectangle
\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})} if
\iftexi
\code{\var{left} <= \var{h} < \var{right}} and
\code{\var{top} <= \var{v} < \var{bottom}}.
\else
$\var{left} \leq \var{h} < \var{right}$ and
$\var{top} \leq \var{v} < \var{bottom}$.
\fi
\end{funcdesc}

\begin{funcdesc}{inset}{rect\, \(dh\, dv\)}
Returns a rectangle that lies inside the
\code{rect}
argument by
\var{dh}
pixels horizontally
and
\var{dv}
pixels
vertically.
If
\var{dh}
or
\var{dv}
is negative, the result lies outside
\var{rect}.
\end{funcdesc}

\begin{funcdesc}{rect2geom}{rect}
Converts a rectangle to geometry representation:
\code{(\var{left}, \var{top}), (\var{width}, \var{height})}.
\end{funcdesc}

\begin{funcdesc}{geom2rect}{geom}
Converts a rectangle given in geometry representation back to the
standard rectangle representation
\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})}.
\end{funcdesc}