blob: 856d79204f05f9ca4a3671b91766d7b1b3c1a7d8 [file] [log] [blame]
Jack Jansen08365421996-04-19 15:56:08 +00001<HTML><HEAD><TITLE>Using WASTE</TITLE></HEAD>
2<BODY>
3<H1>Using WASTE</H1>
4<HR>
5
6WASTE is an almost-compatible TextEdit replacement which overcomes
7some of the limitations of it (like the 32K limit) and provides some extensions
8(drag and drop, images, undo support). Moreover, it has a much cleaner interface
9and is therefore easier integrated in Python. <p>
10
11WASTE is written by Marco Piovanelli, <A HREF="mailto:piovanel@kagi.com">&lt;piovanel@kagi.com&gt;</A>,
12and copyrighted by him. You can always obtain the latest version (for use in C
13or Pascal programs) and the documentation from
14<A HREF="ftp://ftp.dsi.unimi.it/DSI/piovanel/WASTE">&lt;ftp://ftp.dsi.unimi.it/DSI/piovanel/WASTE&gt;</A>.
15
16We explain the useage of waste here by showing how to modify the TextEdit based
17<A HREF="textedit/ped.py">ped.py</A> of the
18<A HREF="textedit.html">previous example</A> into the waste-based <A HREF="waste/wed.py">wed.py</A>,
19so you should have both sources handy. <p>
20
21Functionally, <code>wed.py</code> provides three new things: resizable windows, a horizontal
22scroll bar and undo. <p>
23
24Let us look at the code, first at the application class <code>Wed</code>. The only real change is that
25we now handle <code>undo</code>. Aside from enabling it in the creation routine and the addition of
26a callback routine there is a bit of new code in <code>updatemenubar</code>: Waste not only handles
27the full details of implementing undo, it will also tell us what the next undo operation will undo
28(or redo). We use this to our advantage by changing the undo menu label to tell the user. <p>
29
30The <code>WasteWindow</code> has seen a bit more change. Initialization of the waste data structure is
31a bit different, in that we can specify some options at creation time. Also, waste has no <code>SetText</code>
32method but a <code>UseText</code> which expects a handle as parameter. We have to be <EM>very</EM> careful
33that we keep this handle around, because Python will happily free the handle if we have no more references
34to it (and I doubt that Waste would like this:-). A final difference in <code>open</code>
35is that we use a large number for the destination rectangle width, because we will use a horizontal scroll
36bar. <p>
37
38The <code>idle</code> method is a bit more involved, since we also call <code>WEAdjustCursor</code> to
39provide the correct cursor based on mouse-position. Users like this. <p>
40
41<code>Getscrollbarvalues</code> is simpler than its' TextEdit counterpart because Waste correctly
42updates the destination rectangle when the document changes. Also note that waste uses accessor functions
43to get at internal values, as opposed to direct struct access for TextEdit. <p>
44
45<code>Scrollbar_callback</code> on the other hand is more elaborate (but also provides more functionality).
46It also handles horizontal scrolls (scrolling one-tenth and half a screenful with the buttons). This
47function is also "multi-font-ready" in that scrolling one line will do the expected thing in case of multiple
48fonts. We will implement a multi-font editor later. A minor annoyance of Waste is that is does not provide
49a pinned scroll, so at the end of our callback routine we have to check that we have not scrolled past the
50beginning or end of the document, and adjust when needed. <p>
51
52<code>do_update</code> is also changed, because Waste is completely region-based (as opposed to rect-based).
53Hence, we erase regions here and we can also return immedeately if there is nothing to update. <p>
54
55<code>Do_postresize</code> is new: because Waste uses accessor functions we can now modify the viewRect from
56Python, which is impossible in the Python TextEdit interface, and hence we can implement resize. The
57<code>do_key</code> and <code>do_contentclick</code> methods have also seen minor changes, because the
58corresponding waste routines need a bit more information than their TextEdit counterparts. The Cut/copy/paste
59code is simplified, because Waste uses the normal desktop scrap. <p>
60
61Implementing undo is a wonder of simplicity: Waste handles all the details for us. Also, the new
62<code>can_paste</code> method (which controls greying out of the paste menu entry) is an improvement
63over what <code>ped</code> did: in ped it was possible that paste was enabled but that the data on the
64scrap was incompatible with TextEdit. No more such problems here. <p>
65
66<hr>
67That is all for now. At some point in the future I will extend this editor to incorporate multiple fonts and
68pointsizes, pictures and possibly drag-and-drop editing but I will first have to write the code for it.
69For now you will have to go back to the <A HREF="index.html">index</A> to pick another example.