| <HTML><HEAD><TITLE>Using WASTE</TITLE></HEAD> |
| <BODY> |
| <H1>Using WASTE</H1> |
| <HR> |
| |
| WASTE is an almost-compatible TextEdit replacement which overcomes |
| some of the limitations of it (like the 32K limit) and provides some extensions |
| (drag and drop, images, undo support). Moreover, it has a much cleaner interface |
| and is therefore easier integrated in Python. <p> |
| |
| WASTE is written by Marco Piovanelli, <A HREF="mailto:piovanel@kagi.com"><piovanel@kagi.com></A>, |
| and copyrighted by him. You can always obtain the latest version (for use in C |
| or Pascal programs) and the documentation from |
| <A HREF="http://www.boingo.com/waste/"><http://www.boingo.com/waste/></A>. |
| |
| We explain the useage of waste here by showing how to modify the TextEdit based |
| <A HREF="textedit/ped.py">ped.py</A> of the |
| <A HREF="textedit.html">previous example</A> into the waste-based <A HREF="waste/wed.py">wed.py</A>, |
| so you should have both sources handy. <p> |
| |
| Functionally, <code>wed.py</code> provides three new things: resizable windows, a horizontal |
| scroll bar and undo. <p> |
| |
| Let us look at the code, first at the application class <code>Wed</code>. The only real change is that |
| we now handle <code>undo</code>. Aside from enabling it in the creation routine and the addition of |
| a callback routine there is a bit of new code in <code>updatemenubar</code>: Waste not only handles |
| the full details of implementing undo, it will also tell us what the next undo operation will undo |
| (or redo). We use this to our advantage by changing the undo menu label to tell the user. <p> |
| |
| The <code>WasteWindow</code> has seen a bit more change. Initialization of the waste data structure is |
| a bit different, in that we can specify some options at creation time. Also, waste has no <code>SetText</code> |
| method but a <code>UseText</code> which expects a handle as parameter. We have to be <EM>very</EM> careful |
| that we keep this handle around, because Python will happily free the handle if we have no more references |
| to it (and I doubt that Waste would like this:-). A final difference in <code>open</code> |
| is that we use a large number for the destination rectangle width, because we will use a horizontal scroll |
| bar. <p> |
| |
| The <code>idle</code> method is a bit more involved, since we also call <code>WEAdjustCursor</code> to |
| provide the correct cursor based on mouse-position. Users like this. <p> |
| |
| <code>Getscrollbarvalues</code> is simpler than its' TextEdit counterpart because Waste correctly |
| updates the destination rectangle when the document changes. Also note that waste uses accessor functions |
| to get at internal values, as opposed to direct struct access for TextEdit. <p> |
| |
| <code>Scrollbar_callback</code> on the other hand is more elaborate (but also provides more functionality). |
| It also handles horizontal scrolls (scrolling one-tenth and half a screenful with the buttons). This |
| function is also "multi-font-ready" in that scrolling one line will do the expected thing in case of multiple |
| fonts. We will implement a multi-font editor later. A minor annoyance of Waste is that is does not provide |
| a pinned scroll, so at the end of our callback routine we have to check that we have not scrolled past the |
| beginning or end of the document, and adjust when needed. <p> |
| |
| <code>do_update</code> is also changed, because Waste is completely region-based (as opposed to rect-based). |
| Hence, we erase regions here and we can also return immedeately if there is nothing to update. <p> |
| |
| <code>Do_postresize</code> is new: because Waste uses accessor functions we can now modify the viewRect from |
| Python, which is impossible in the Python TextEdit interface, and hence we can implement resize. The |
| <code>do_key</code> and <code>do_contentclick</code> methods have also seen minor changes, because the |
| corresponding waste routines need a bit more information than their TextEdit counterparts. The Cut/copy/paste |
| code is simplified, because Waste uses the normal desktop scrap. <p> |
| |
| Implementing undo is a wonder of simplicity: Waste handles all the details for us. Also, the new |
| <code>can_paste</code> method (which controls greying out of the paste menu entry) is an improvement |
| over what <code>ped</code> did: in ped it was possible that paste was enabled but that the data on the |
| scrap was incompatible with TextEdit. No more such problems here. <p> |
| |
| That is all for now. There is an undocumented extended version of wed, <a href="waste/swed.py">swed.py</a>, |
| which supports multiple fonts, sizes and faces, and uses Waste's tab-calculation to do tab characters "right". |
| There is also an even more elaborate example, <a href="waste/htmled.py">htmled.py</a> which extends swed with |
| the ability to import html files, showing the use of color and how to use embedded object (rulers, in this case). |
| These two programs have not been documented yet, though, so you will have to look at them without guidance. <p> |
| <hr> |
| Back to the <A HREF="index.html">index</A> to pick another example. |