[Tutor] (no subject)

D-Man dsh8290@rit.edu
Sun, 21 Jan 2001 22:13:03 -0500

On Sat, Jan 20, 2001 at 05:56:09PM -0800, Matthias Hager wrote:
| I know you guys are about to rip your hair out over me, I'm annoying I know! But I have some questions here on how to do some special stuff in Python. (And is it possible to use a GUI with Perl?)

Yes, but you'll have to find the bindings yourself.  (I'm sure there
are bindings for Tk, Gtk+, Qt, maybe more)  I think there are GUI
bindings for every language in use.

| 1. How do I access the clipboard, so I can make cut and paste options?

MS Windows?  X?  I don't know for either, but if you are using Windows
try the win32all module maintained by Mark Hammond.

| 2. What all does ScrollingText support? I've found background, fg, font. What else is there? How can I change the size of the text, and how can I add the ability to have the user change the text color and everything? How can I change how it rounds off its text on the right? It justs takes whatever you type to the next line, cutting words in two.

What gui toolkit?  Tkinter?  It depends on the gui a, you should check
the docs.  I like GTK myself, never used Tk.

| How can I change the blinking | thing's color? And finally, how can I make it say stuff according to what they type? Like in idle, if you start typing askopenfilename() It will tell you what to type in? How do I do that?

I expect that the text widget would have a Changed event (or something
similar).  You would need to register a listener for the event, then
do what you want with the data.  For example, have a string object
somewhere.  When you get the changed event it should give you the
charecter entered (or deleted, and tell you which).  If it is a space,
clear your string object, else append the character to it.  If the
string matches somehting you want (ie askopenfilename) do what you
want to have happen.

| 3. What are, and how do I use classes? A program I saw, uses them, but what are they?

Classes are very cool.  Read the tutorial, but I don't remember how
much they teach about classses in general or how much they assume you
already know.  Classes are a way of describing an object.  An object
is a collection of data and a set of functions that operate on the
data.  Ideally you don't know what an object's implementation is, just
the interface (functions is has).  You would use the functins to get
the work done, but don't have to deal with the data itself.

I don't have time to give a tutorial right now, but read the chapter
from the tutorial (Ch. 9 I think) and then come back with more
questions :-).  I'll be happy to answer them when I have a few

| 4. How do I open another window, that has more stuff in it, like buttons and stuff?

First read the stuff on classes.  Every gui I've ever used (ok, just
GTK and Swing, but I know Qt follows this as well) uses an object
model.  Once you understand classes and objects it will make more
sense what you need to do.  In GTK, 

import Gtk

window = Gtk.Window()
window.add( Gtk.Label( "Label Text" ) )

(basically, it's been a while so I might (propably) have the details

| 5. How can I change what it says when they hover over an icon to my program?

These are usually called "tooltips".  It depends on your gui toolkit,
but there should be some way to create a tooltip object and add it to
the button object.  The button then handles the displaying of it.
(Objects rock!)

| 6. How do I check if they have made any changes to a file, and do something according to whether they have or not?

I imagine that you have a Text Entry widget of some sort.  The widget
is upposed to represent the contents of a text file.  You also have
the name of the file.  One solution, as wheelege hinted at, is to open
the file, read it, and compare the text to the text in the widget.
While functional, this would be slow and use a lot of memory (for
large files).  A better approach would be to have a flag (say
'is_modified').  Set this to false (0) at the beginning of the program
and each time a save is successful.  When you get the "Changed" event
from the widget set the flag to true (1).  This will be much more
efficeint (and easier!) than checking the file on disk every time.

| Again, I'm sorry to bother you all.
| But thanks, A LOT.

No problem.  This is the /Tutor/ list.  It's meant for all these
questions.  :-)

| Matthias


(PS.  Sorry for the many spelling mistakes and typos.  I am using a
slow dial-up connection and have very bad response.  It makes it
harder to fix the typos.)