Jack Jansen | 0836542 | 1996-04-19 15:56:08 +0000 | [diff] [blame] | 1 | <HTML><HEAD><TITLE>Using WASTE</TITLE></HEAD> |
| 2 | <BODY> |
| 3 | <H1>Using WASTE</H1> |
| 4 | <HR> |
| 5 | |
| 6 | WASTE is an almost-compatible TextEdit replacement which overcomes |
| 7 | some 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 |
| 9 | and is therefore easier integrated in Python. <p> |
| 10 | |
| 11 | WASTE is written by Marco Piovanelli, <A HREF="mailto:piovanel@kagi.com"><piovanel@kagi.com></A>, |
| 12 | and copyrighted by him. You can always obtain the latest version (for use in C |
| 13 | or Pascal programs) and the documentation from |
| 14 | <A HREF="ftp://ftp.dsi.unimi.it/DSI/piovanel/WASTE"><ftp://ftp.dsi.unimi.it/DSI/piovanel/WASTE></A>. |
| 15 | |
| 16 | We 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>, |
| 19 | so you should have both sources handy. <p> |
| 20 | |
| 21 | Functionally, <code>wed.py</code> provides three new things: resizable windows, a horizontal |
| 22 | scroll bar and undo. <p> |
| 23 | |
| 24 | Let us look at the code, first at the application class <code>Wed</code>. The only real change is that |
| 25 | we now handle <code>undo</code>. Aside from enabling it in the creation routine and the addition of |
| 26 | a callback routine there is a bit of new code in <code>updatemenubar</code>: Waste not only handles |
| 27 | the 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 | |
| 30 | The <code>WasteWindow</code> has seen a bit more change. Initialization of the waste data structure is |
| 31 | a bit different, in that we can specify some options at creation time. Also, waste has no <code>SetText</code> |
| 32 | method but a <code>UseText</code> which expects a handle as parameter. We have to be <EM>very</EM> careful |
| 33 | that we keep this handle around, because Python will happily free the handle if we have no more references |
| 34 | to it (and I doubt that Waste would like this:-). A final difference in <code>open</code> |
| 35 | is that we use a large number for the destination rectangle width, because we will use a horizontal scroll |
| 36 | bar. <p> |
| 37 | |
| 38 | The <code>idle</code> method is a bit more involved, since we also call <code>WEAdjustCursor</code> to |
| 39 | provide 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 |
| 42 | updates the destination rectangle when the document changes. Also note that waste uses accessor functions |
| 43 | to 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). |
| 46 | It also handles horizontal scrolls (scrolling one-tenth and half a screenful with the buttons). This |
| 47 | function is also "multi-font-ready" in that scrolling one line will do the expected thing in case of multiple |
| 48 | fonts. We will implement a multi-font editor later. A minor annoyance of Waste is that is does not provide |
| 49 | a pinned scroll, so at the end of our callback routine we have to check that we have not scrolled past the |
| 50 | beginning 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). |
| 53 | Hence, 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 |
| 56 | Python, 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 |
| 58 | corresponding waste routines need a bit more information than their TextEdit counterparts. The Cut/copy/paste |
| 59 | code is simplified, because Waste uses the normal desktop scrap. <p> |
| 60 | |
| 61 | Implementing 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 |
| 63 | over what <code>ped</code> did: in ped it was possible that paste was enabled but that the data on the |
| 64 | scrap was incompatible with TextEdit. No more such problems here. <p> |
| 65 | |
Jack Jansen | 70e413d | 1996-10-23 15:40:48 +0000 | [diff] [blame] | 66 | That is all for now. There is an undocumented extended version of wed, <a href="waste/swed.py">swed.py</a>, |
| 67 | which supports multiple fonts, sizes and faces, and uses Waste's tab-calculation to do tab characters "right". |
| 68 | There is also an even more elaborate example, <a href="waste/htmled.py">htmled.py</a> which extends swed with |
| 69 | the ability to import html files, showing the use of color and how to use embedded object (rulers, in this case). |
| 70 | These two programs have not been documented yet, though, so you will have to look at them without guidance. <p> |
Jack Jansen | 0836542 | 1996-04-19 15:56:08 +0000 | [diff] [blame] | 71 | <hr> |
Jack Jansen | 70e413d | 1996-10-23 15:40:48 +0000 | [diff] [blame] | 72 | Back to the <A HREF="index.html">index</A> to pick another example. |