Re: [Tutor] moving from pack to grid in tkinter

2006-11-26 Thread John Fouhy
On 27/11/06, Tony Cappellini <[EMAIL PROTECTED]> wrote:
> I've got a main window which is 640 * 400.
>   self.root.geometry("600x400")
>
>  self.label.pack(side=BOTTOM, fill=X)
> This line would put the label at the bottom of the window, and extend to
> both left and right edges of the window.

So, something like a status bar?

Using pack() is really the easiest way to do this.  Here's what I'd do:

self.label = Label(root) # etc
self.label.pack(side=BOTTOM, fill=X)

self.interior = Frame(root)
self.interior.pack(SIDE=TOP, fill=BOTH, expand=True)

...and then create all your other widgets as children of self.interior.

> I want to change to grid geometry because I have several more widgets to put
> in the main window.
> self.label.grid(row=5, column=2, column=0)

Not sure why you have two column= options here.. One of them should be
columnspan, maybe?

> This put the label at row 5, in the center of the window, but the label
> didn't extend to the window edges.

Using grid geometry, widgets will take their natural size and sit in
the middle of the cell you place them in.  If you want to override
this, you need to specify which edge or edges you want the widget to
stick to.

In this case, you want the widget to stick to both the left and right
edges, so that it is stretched across the width of the screen.  You
can do this by saying:

self.label.grid(row=5, column=0, columnspan=2, sticky=E+W)

E+W means "east and west".

> self.label.grid(row=10, column=2, column=0)  didn't move the label any lower
> than row 5

If there is nothing in a row, the row will have a height of zero.  So
row 5 and row 10 are equivalent, if rows 6..9 are empty and there are
no other widgets in 5 or 10.

There's no way to say "put this in the last row", but you could put it
in row 999 or something.

> Although, the main window isn't calling grid explicitly either- that's a bit
> confusing, because I thought all widgets had to call grid or pack to be
> displayed...

The root window Tk(), and any windows you create using Toplevel(),
will display themselves.  Other widgets need to be put inside a frame
and pack()ed or grid()ded (or place()d).

HTH!

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with Tkinter, please

2006-11-26 Thread John Fouhy
On 27/11/06, Dick Moores <[EMAIL PROTECTED]> wrote:
> I have a question about the "EXIT" button's command,
> command=sys.exit. It fails to quit the program when I've entered too
> large an integer for factoring, or for prime testing, and I don't
> want to wait any more for the result. When I'm running the program
> from my Win XP console, I can quit with a simple Ctrl+C, but this
> won't be available to the friend I may send the executable to. Is it
> possible to build in a way to smoothly interrupt, say, a factoring
> process that's taking too long?

Well, as you may know, the "core" of Tkinter (or most GUIs, I think)
is the event loop.  The event loop basically does this:
 1. Look for events (mouse clicks, keypresses, etc.)
 2. Process events (update widgets, call callbacks)
 3. GOTO 1.

So, in this specific case, the event loop is doing this:

1. Look for events ==> user clicks on "factorise" button.
2. Process events ==> call "factorise" button callback.
3. Callback runs...
4. ...callback completes.
5. Look for events ==> user clicks on "exit" button.
6. Process events ==> call "exit" button callback.
7. Python exits.

So, you can see why clicking your exit button won't interrupt the
calculation in progress.  The only way you can do that is if you can
get the event loop to start looking for events again before the
callback finishes.  And that means THREADS.

HTH :-)

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] moving from pack to grid in tkinter

2006-11-26 Thread Tony Cappellini

I've got a main window which is 640 * 400.
 self.root.geometry("600x400")

self.label.pack(side=BOTTOM, fill=X)
This line would put the label at the bottom of the window, and extend to
both left and right edges of the window.

I want to change to grid geometry because I have several more widgets to put
in the main window.
self.label.grid(row=5, column=2, column=0)

This put the label at row 5, in the center of the window, but the label
didn't extend to the window edges.

After reading this http://effbot.org/tkinterbook/grid.htm

I tried playing around with other options, but can't get the label to move
any lower in the main window

self.label.grid(row=10, column=2, column=0)  didn't move the label any lower
than row 5

My main window isn't constructed using pack(), so I'm not mixing grid and
pack in this program.
Although, the main window isn't calling grid explicitly either- that's a bit
confusing, because I thought all widgets had to call grid or pack to be
displayed...

What args do I need to move the label to the bottom of the window, and
centered so it extends to both left and right edges?
I don't like to hard-code a row number, I'd rather make the label
dynamically be assigned to the bootm ros of the window, in case the window
grows or shrinks.


thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with Tkinter, please

2006-11-26 Thread Dick Moores
At 06:54 PM 11/26/2006, John Fouhy wrote:
>On 27/11/06, Dick Moores <[EMAIL PROTECTED]> wrote:
> > Well, I'm having a terrible time with grid(). I do have the 6 buttons
> > in the same row, but they're a real mess. Someone please run this and
> > tell me how to get them looking better.
>
>I'm not certain exactly what layout you want, but have a look at this
>to see if it looks any better:

A lot better! And now that I understand columnspan, I was able to 
move the buttons around and configure them a bit more. I'm quite 
satisfied now. For this program it seems I won't be needing to employ 
the nested frames suggested by Alan and Kent. But of course I'll try 
those anyway, just to learn about them.

I have a question about the "EXIT" button's command, 
command=sys.exit. It fails to quit the program when I've entered too 
large an integer for factoring, or for prime testing, and I don't 
want to wait any more for the result. When I'm running the program 
from my Win XP console, I can quit with a simple Ctrl+C, but this 
won't be available to the friend I may send the executable to. Is it 
possible to build in a way to smoothly interrupt, say, a factoring 
process that's taking too long?

Thanks very much, John.

Dick


>I think you were a bit confused about the role of columnspan.  If you
>say .grid(row=R, column=C, columnspan=2) then the widget you are
>gridding will occupy (row R, column C) _and_ (row R, column C+1) (ie:
>it spans two columns).
>
>from Tkinter import *
>
>root = Tk()
>root.option_add('*font', ('verdana', 11))
>root.title("Fun with integers")
>fram = Frame(root).grid()
>
>Label(fram, text="Enter a positive integer, n",
>  fg="#99").grid(row=0,column=1,sticky=W)
>
>entry = Entry(fram, fg="red", bg="#DCDCDC", width = 30)
>entry.focus_set()
>entry.grid(row=1,column=1, padx=5, pady=5,sticky=E+W)
>
>
>b1=Button(fram, text="Compute n!", bg="black", fg="white", width = 19)
>b1.grid(row=2,column=0,sticky=W)
>
>b2=Button(fram, text="Partially spell n", fg="black", bg="white",
>  width = 19)
>b2.grid(row=2,column=1,sticky=W)
>
>b3=Button(fram, text="Compute factors of n", bg="#D3D3D3",
>  fg="yellow", width = 19)
>b3.grid(row=2,column=2,sticky=W)
>
>b4=Button(fram, text="Find primes in [n, n+99]", bg="yellow",
>fg="red", width = 19)
>b4.grid(row=2,column=3,sticky=W)
>
>long_text = "See the largest number that can be spelled"
>b5=Button(fram, text=long_text, fg="green", bg="#BF6AF5", width = 19)
>b5.grid(row=3,column=0,columnspan=3,sticky=E+W)
>
>b6=Button(fram, text="EXIT", fg="white", bg="red", width = 
>19,command=sys.exit)
>b6.grid(row=3,column=3,sticky=W)
>
>#text = ScrolledText(fram, bg = "cyan", fg = "#33", height=18)
>text = Text(fram)
>text.insert(END, "n-factorial or n-cubed will appear here.\n\n")
>text.insert(END, 'And again, with commas inserted.\n\n')
>text.insert(END, "And yet again, in scientific notation.")
>text.grid(row=4,column=0,columnspan=4,sticky=N+S+E+W)
>
>mainloop()
>___
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] to learn

2006-11-26 Thread John Fouhy
On 27/11/06, ED PENNELL <[EMAIL PROTECTED]> wrote:
> my name is ED PENNELL,   i am using MAC TIGER want
> to learn python and use it on emacs,i down loaded 2.5
> python,i will start with IDLE, DO I NEED PORTS FOR  MY
> MAC and need tutor with MAC.a very fresh starter.
>  THANKS ED

Hi Ed,

If you download python from here: http://www.python.org/download/ you
get a build with some mac-specific features.  You must use this build
if you want to use wxWidgets (which is a framework you can use to make
graphical user interfaces).

You can use macports to install python as well, but it will lack the
mac-specific features.  macports will make installing some modules
easy, though.

For what it's worth, I am using python on a mac and I am not using the
macports version.

Hope this helps.

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with Tkinter, please

2006-11-26 Thread Dick Moores
At 03:09 PM 11/26/2006, Alan Gauld wrote:

>"Dick Moores" <[EMAIL PROTECTED]> wrote
>
> > Some time has passed and I've made some progress. My question now is
> > about the placement of buttons.
>...
> > one, but I can't get the layout I want, which is the Label on top of
> > the Entry, then a row of the first 3 buttons (which respectively
> > trigger 3 different computations on the integer the user enters).
> > Then below that, the Exit button, with the Text widget at the
> > bottom.
>
>Sounds like 4 frames to me:
>1 Frame for the outer 'skin', packed with fill for both X and Y.
>
>1 frame for the label/entry combo, using pack to position the widgets
>inside the frame, then pack the frame inside the outer frame
>
>1 frame for the row of buttons and I'd use grid to position the
>buttons insdide the frame and then pack the frame into the
>outer frame (I tend to use grid where I'm positioning things
>horizontally and pack when i'm doing it vertiacally. So I
>divide my GUI into horizontal layers and then use grid
>inside teach layer for horizontally laid out widgets)
>
>1 frame for the bottom exit button and pack it into the
>outer.
>
> > How to do this? Is it impossible with the pack() method?
>
>Horizontal layouts are possible using pack, take a look at
>the GUI topic and the GUI section of the Case Study topic
>in my tutor for examples of using pure pack. But IMHO grid
>is easier for horizontal sets.
>
>Mixing layout styles in a GUI is fine provided you keep each
>layout in a frame to itself.

Thanks very much, Alan and Kent. For some reason I didn't see your 
replies before posting my wail of frustration with grid(). Please ignore it.

I had tried using extra frames, but hadn't thought to use frames 
inside of frames. And then a grid inside of one of the inner frames. 
I'll give that a try right now. And check out the Case Study.

Dick



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with Tkinter, please

2006-11-26 Thread John Fouhy
On 27/11/06, Dick Moores <[EMAIL PROTECTED]> wrote:
> Well, I'm having a terrible time with grid(). I do have the 6 buttons
> in the same row, but they're a real mess. Someone please run this and
> tell me how to get them looking better.

I'm not certain exactly what layout you want, but have a look at this
to see if it looks any better:

I think you were a bit confused about the role of columnspan.  If you
say .grid(row=R, column=C, columnspan=2) then the widget you are
gridding will occupy (row R, column C) _and_ (row R, column C+1) (ie:
it spans two columns).

from Tkinter import *

root = Tk()
root.option_add('*font', ('verdana', 11))
root.title("Fun with integers")
fram = Frame(root).grid()

Label(fram, text="Enter a positive integer, n",
 fg="#99").grid(row=0,column=1,sticky=W)

entry = Entry(fram, fg="red", bg="#DCDCDC", width = 30)
entry.focus_set()
entry.grid(row=1,column=1, padx=5, pady=5,sticky=E+W)


b1=Button(fram, text="Compute n!", bg="black", fg="white", width = 19)
b1.grid(row=2,column=0,sticky=W)

b2=Button(fram, text="Partially spell n", fg="black", bg="white",
 width = 19)
b2.grid(row=2,column=1,sticky=W)

b3=Button(fram, text="Compute factors of n", bg="#D3D3D3",
 fg="yellow", width = 19)
b3.grid(row=2,column=2,sticky=W)

b4=Button(fram, text="Find primes in [n, n+99]", bg="yellow",
fg="red", width = 19)
b4.grid(row=2,column=3,sticky=W)

long_text = "See the largest number that can be spelled"
b5=Button(fram, text=long_text, fg="green", bg="#BF6AF5", width = 19)
b5.grid(row=3,column=0,columnspan=3,sticky=E+W)

b6=Button(fram, text="EXIT", fg="white", bg="red", width = 19,command=sys.exit)
b6.grid(row=3,column=3,sticky=W)

#text = ScrolledText(fram, bg = "cyan", fg = "#33", height=18)
text = Text(fram)
text.insert(END, "n-factorial or n-cubed will appear here.\n\n")
text.insert(END, 'And again, with commas inserted.\n\n')
text.insert(END, "And yet again, in scientific notation.")
text.grid(row=4,column=0,columnspan=4,sticky=N+S+E+W)

mainloop()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python exceptions

2006-11-26 Thread John Fouhy
On 27/11/06, johnf <[EMAIL PROTECTED]> wrote:
> So there are outside exception handlers?  OK.  thanks for the answer.  For now
> that all I needed to understand.

I'm not sure that "outside" is quite the right word ..

If you write Tkinter code, you will (at some point) call mainloop().

mainloop(), in turn, will call your functions, as the user does stuff.

If your code raises an exception, mainloop() will "handle" that
exception, in that it will print some stuff out, and then go back to
looking for events.  But it's still part of your program (as opposed
to, say, part of the interpreter), it's just not code that you've
written yourself.

Different GUIs might do things differently..

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with Tkinter, please

2006-11-26 Thread Dick Moores
At 08:59 AM 11/26/2006, Michael Lange wrote:
>On Sat, 25 Nov 2006 17:23:39 -0800
>Dick Moores <[EMAIL PROTECTED]> wrote:
>
> > I've done a lot of fiddling around with setting "side=left", and
> > trying to put all the buttons inside a second Frame inside the first
> > one, but I can't get the layout I want, which is the Label on top of
> > the Entry, then a row of the first 3 buttons (which respectively
> > trigger 3 different computations on the integer the user enters).
> > Then below that, the Exit button, with the Text widget at the bottom.
> > How to do this? Is it impossible with the pack() method?
> >
>
>It is certainly not impossible, as long as you do not mind creating
>a bunch of extra Frames, however to me this really sound like a
>job for grid() .
>You could simply use grid(row=  , column=0, columnspan=2)
>for the widgets that should use the whole window's width and grid
>the 3 buttons into columns 0, 1 and 2 .

Well, I'm having a terrible time with grid(). I do have the 6 buttons 
in the same row, but they're a real mess. Someone please run this and 
tell me how to get them looking better.

When I use pack(), the buttons are nicely centered, but lined up 
vertically, one above the other. Maybe I can live with that. But I'd 
still like to learn how to use grid() well.

Dick


from Tkinter import *

root = Tk()
root.option_add('*font', ('verdana', 11))
root.title("Fun with integers")
fram = Frame(root).grid()

Label(fram, text="Enter a positive integer, n", 
fg="#99").grid(row=0,column=3)

entry = Entry(fram, fg="red", bg="#DCDCDC", width = 30)
entry.focus_set()
entry.grid(row=2,column=3, padx=5, pady=5)


b1=Button(fram, text="Compute n!", bg="black", fg="white", width = 
19,command=compute_fact)
b1.grid(row=4,column=0,columnspan=2,sticky=W)

b2=Button(fram, text="Partially spell n", fg="black", bg="white", 
width = 19,command=integer_spell)
b2.grid(row=4,column=1,columnspan=2,sticky=W)

b3=Button(fram, text="Compute factors of n", bg="#D3D3D3", 
fg="yellow", width = 19,command=compute_factors)
b3.grid(row=4,column=2,columnspan=2,sticky=W)

b4=Button(fram, text="Find primes in [n, n+99]", bg="yellow", 
fg="red", width = 19,command=primes_in_interval)
b4.grid(row=4,column=3,columnspan=2,sticky=W)

long_text = "See the largest number that can be spelled"
b5=Button(fram, text=long_text, fg="green", bg="#BF6AF5", width = 
19,command=largest_number)
b5.grid(row=4,column=4,columnspan=2,sticky=W)

b6=Button(fram, text="EXIT", fg="white", bg="red", width = 19,command=sys.exit)
b6.grid(row=4,column=5,columnspan=2,sticky=W)

text = ScrolledText(fram, bg = "cyan", fg = "#33", height=18)
#text = Text(fram)
text.insert(END, "n-factorial or n-cubed will appear here.\n\n")
text.insert(END, 'And again, with commas inserted.\n\n')
text.insert(END, "And yet again, in scientific notation.")
text.grid(row=5,columnspan=7,sticky=S)

mainloop()
==


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python exceptions

2006-11-26 Thread johnf
On Sunday 26 November 2006 16:17, John Fouhy wrote:
> On 27/11/06, johnf <[EMAIL PROTECTED]> wrote:
> > I can but it's not the issue - I think?  I want to know how it works -
> > exceptions not handled by python that is.  Are there exception handled
> > outside of python when using modules such as wxPython and pyQT?  Or are
> > some exceptions not handled when running from the command line.
>
> If your GUI callbacks raise exceptions, the program may still function
> correctly.
>
> eg, basic Tkinter example (my Tkinter is a little rusty, so forgive
> errors):
>
> #
> e = Entry(parent)
> e.pack()
>
> def clear():
> e.delete(0, END)
> raise ValueError
>
> b = Button(parent, label='Clear', command=clear)
> b.pack()
> #
>
> The button will (I think) work correctly, and the program won't crash.
>  But you should see the exception printed to the command line (if you
> run this program from a shell).  I don't know for sure, but I imagine
> the Tkinter mainloop() does something like:
>
> try:
> callback()
> except:
> # print trace to stderr
>
> This is the only possibility I can think of at the moment.  But there
> could be other things going on, which is why we'd like to see an
> example.
So there are outside exception handlers?  OK.  thanks for the answer.  For now 
that all I needed to understand.  
-- 
John Fabiani
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] to learn

2006-11-26 Thread Luke Paireepinart
ED PENNELL wrote:
> my name is ED PENNELL,   i am using MAC TIGER want
> to learn python and use it on emacs,i down loaded 2.5
> python,i will start with IDLE, DO I NEED PORTS FOR  MY
> MAC
You had me up till here and then you lost me.
What do you mean, ports?
network ports?  software ports (as in Linux -> OSx)
or what?
>  and need tutor with MAC.
We don't offer private tutors here.
If you have questions about Python or you run into problems you can't solve,
we help you with them.
Did you mean you need a tutorial?
If so, you can use any Python tutorial.  There's no need for you to look 
for a MAC specific one because Python is largely the same on any OS you 
use it on.
> a very fresh starter. 
>  THANKS ED
>
>   
Glad to hear from ya, ed!
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] adjust key bindings

2006-11-26 Thread Luke Paireepinart
John CORRY wrote:
> Hi All,
>
> I have been trying to bind the "z" key to the "Down" key using Python
> 2.4, Glade 2 and Pygtk.  I have posted this problem on the Pygtk list
> but have had no response.  I was hoping somebody on the tutor list could
> help.  I think that I am close.  I can capture the "z" key press and
> assign a "Down" key press but I can't get the "Down" key press to
> register on the Treeview in the GUI.
>
> Any thoughts greatly appreciated.
>
> Thanks,
>
> John.
I highly doubt that what you want to do when someone hits a 'z' is to 
generate a 'down' keypress.
What if the user assigned the down key to z?
then you'd have a
z -> down -> z -> down ->  infinite loop.
What I expect you want is that each key, z and down, perform the same 
action.
In other words, they both call the same function.
So basically what you'd want is something like this (non-pyGTK specific 
code)

def aFunc():
print "Hello, World!"

bindKey = {'down':aFunc}

keypress = raw_input("What keypress do you want to perform?")

bindKey[keypress]()#this will call the 'aFunc' function if they type 
'down', otherwise, it'll probably crash.

bindKey['z'] = aFunc

bindKey['z']()# now performs the same function as
bindkey['down']()#this does.

If you really do want to generate 'down' keypresses when someone hits 
'z', please explain why, and I will try to the best of my abilities to 
help you in that regard!
Good Luck!
-Luke
>
>   

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] to learn

2006-11-26 Thread ED PENNELL
my name is ED PENNELL,   i am using MAC TIGER want
to learn python and use it on emacs,i down loaded 2.5
python,i will start with IDLE, DO I NEED PORTS FOR  MY
MAC and need tutor with MAC.a very fresh starter. 
 THANKS ED


 

Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python exceptions

2006-11-26 Thread John Fouhy
On 27/11/06, johnf <[EMAIL PROTECTED]> wrote:
> I can but it's not the issue - I think?  I want to know how it works -
> exceptions not handled by python that is.  Are there exception handled
> outside of python when using modules such as wxPython and pyQT?  Or are some
> exceptions not handled when running from the command line.

If your GUI callbacks raise exceptions, the program may still function
correctly.

eg, basic Tkinter example (my Tkinter is a little rusty, so forgive errors):

#
e = Entry(parent)
e.pack()

def clear():
e.delete(0, END)
raise ValueError

b = Button(parent, label='Clear', command=clear)
b.pack()
#

The button will (I think) work correctly, and the program won't crash.
 But you should see the exception printed to the command line (if you
run this program from a shell).  I don't know for sure, but I imagine
the Tkinter mainloop() does something like:

try:
callback()
except:
# print trace to stderr

This is the only possibility I can think of at the moment.  But there
could be other things going on, which is why we'd like to see an
example.

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python exceptions

2006-11-26 Thread johnf
On Sunday 26 November 2006 15:43, Alan Gauld wrote:
> "johnf" <[EMAIL PROTECTED]> wrote
>
> > My debugger comes up with lots of exceptions (builtin with my IDE
> > wing) when I
> > run code I have obtained from others.  This is not a formating
> > error - but
> > real unhandled exceptions.  But the when the program/programs is/are
> > run from
> > the command line they work as expected.
>
> Can you show us a short example?
> Show the code and the errors from Wing
>
> Alan G.
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

I can but it's not the issue - I think?  I want to know how it works - 
exceptions not handled by python that is.  Are there exception handled 
outside of python when using modules such as wxPython and pyQT?  Or are some 
exceptions not handled when running from the command line.

i.e.: python SomeApp.  Has exceptions but because it's running from the 
command line exceptions are passed???  Or something else is happening?



-- 
John Fabiani
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie string & File I/O questions......

2006-11-26 Thread Alan Gauld

"Moedeloos Overste" <[EMAIL PROTECTED]> wrote

> This is what I've been able to come up with so far:
>

> vDraws = input("How many times do you want to draw the lottery? :>")

input is considered a damngerous function because a
user could input malicious python code. Its better to use
raw_input and convert to an integer or float etc.

> while vDraws > 0:
>List_LotNumbers = random.sample(range(0,46), 6) #random numbers 
> from
> range into list
>output_string = str(List_LotNumbers) #converting list to string 
> to store

You probably want to use the join string method here rather
than str(). str just produces a string representation of your list,
which includes the []. Join will produce a string from the members
of a list

Try

>>> help(''.join)

> vView = raw_input("Do want to see the results? y/n :>")
>
> if vView == "y" or vView == "Y":

You might prefer to use 'in' here:

if vView[0] in 'yY'

will work for y, Y, yes, Yes (and yesterday too in case
thats a problem!)

> My question is: how do I write the output of each lottery drawing on 
> a
> separate line

Previous poster answered that

> second question: how do i print the lottery drawings to the screen 
> without
> the brackets[]

Use join instead of str

> third:can somebody point me in the right direction as to how do I 
> make the
> program read from the file and count how many times a number has 
> been drawn.

Try using a dictionary with each number drawn as a key and
the corresponding value being the count.

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python exceptions

2006-11-26 Thread Alan Gauld

"johnf" <[EMAIL PROTECTED]> wrote

> My debugger comes up with lots of exceptions (builtin with my IDE 
> wing) when I
> run code I have obtained from others.  This is not a formating 
> error - but
> real unhandled exceptions.  But the when the program/programs is/are 
> run from
> the command line they work as expected.

Can you show us a short example?
Show the code and the errors from Wing

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] my program problem!

2006-11-26 Thread Alan Gauld

"Alan Gilfoy" <[EMAIL PROTECTED]> wrote
> So sleep(10) would simply be a shorter snippet of code for that 
> purpose?

sleep just gices a long pause before quitting, usually enough
to read the output.

> The \n thing might be handy if I was short on space, but I don't 
> mind
> separate 'print' lines, I find that my code seems easier to read 
> that
> way. (at least to me)

Consider triple quoted strings too. String formatting works with these 
too:

print """
This is a long text message,
It includes new lines.
It also shows the result of some interpolated values here:

The sum of %d and % d is %d
""" % (4,5,4+5)


I find that more readable than lots of \ns or lots of print
statements.

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] program spontaneously closes...

2006-11-26 Thread Alan Gauld

"Luke Paireepinart" <[EMAIL PROTECTED]> wrote

> And what's all of this 'command-line' business?  Your python script 
> is
> the same when run by double-clicking as it is when run from idle:

I'll have to disdagree with you here Luke.

IDLE changes script behaviour in quite a number of subtle
ways that can lead to strange anomolies. Exceptions which
cause programs to crash and burn are caught in IDLE.
In particular this causes things like CTRL-C and CTRL-Z to
behave differently. Also notoriously, Tkinter code will behave
in rather unpredictable ways.

The difference is small but big enough that it can confuse
beginners. I always recommend that if folks are encountering
strange behaviour in IDLE that they try running from a DOS
prompt to see what happens.

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] program spontaneously closes...

2006-11-26 Thread Alan Gauld

"Alan Gilfoy" <[EMAIL PROTECTED]> wrote

> The command line program seems to work through my program OK, but 
> the
> command line program shuts down immediately after the program has 
> run

Yes this is normal behaviour.
There are several ways around it, one of which is the
raw_input trick you have used.

Another is to change the Python startup behaviour to include
the /i parameter to python which causes the interpreter not
to exit - handy for debugging faulty scripts.

These options are discussed near the end of the Style topic in
my tutor

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please suggest a python book

2006-11-26 Thread Alan Gauld

"Narasimha" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi! Friends,
>
> I am new to python. I have a vacation of 15 days. Please suggest me 
> a python
> book (or a website).
>
> I already know C language. I have heard much about Python.


If you know C then the best place to start is the official tutorial
on the Python web site (or in the documentation download).

You can then proceed either to one of the Special Interest areas
or Topic Guides or for more general info DiveIntoPython as already
suggested.

Personally I'd suggest that you'll learn more by doing the
official tutor(2 days max!) and then just writing some code...


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with Tkinter, please

2006-11-26 Thread Alan Gauld

"Dick Moores" <[EMAIL PROTECTED]> wrote

> Some time has passed and I've made some progress. My question now is
> about the placement of buttons.
...
> one, but I can't get the layout I want, which is the Label on top of
> the Entry, then a row of the first 3 buttons (which respectively
> trigger 3 different computations on the integer the user enters).
> Then below that, the Exit button, with the Text widget at the 
> bottom.

Sounds like 4 frames to me:
1 Frame for the outer 'skin', packed with fill for both X and Y.

1 frame for the label/entry combo, using pack to position the widgets
inside the frame, then pack the frame inside the outer frame

1 frame for the row of buttons and I'd use grid to position the
buttons insdide the frame and then pack the frame into the
outer frame (I tend to use grid where I'm positioning things
horizontally and pack when i'm doing it vertiacally. So I
divide my GUI into horizontal layers and then use grid
inside teach layer for horizontally laid out widgets)

1 frame for the bottom exit button and pack it into the
outer.

> How to do this? Is it impossible with the pack() method?

Horizontal layouts are possible using pack, take a look at
the GUI topic and the GUI section of the Case Study topic
in my tutor for examples of using pure pack. But IMHO grid
is easier for horizontal sets.

Mixing layout styles in a GUI is fine provided you keep each
layout in a frame to itself.

HTH

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with Tkinter, please

2006-11-26 Thread Kent Johnson
Dick Moores wrote:
> At 08:59 AM 11/26/2006, Michael Lange wrote:
>> On Sat, 25 Nov 2006 17:23:39 -0800
>> Dick Moores <[EMAIL PROTECTED]> wrote:
>>
>>> I've done a lot of fiddling around with setting "side=left", and
>>> trying to put all the buttons inside a second Frame inside the first
>>> one, but I can't get the layout I want, which is the Label on top of
>>> the Entry, then a row of the first 3 buttons (which respectively
>>> trigger 3 different computations on the integer the user enters).
>>> Then below that, the Exit button, with the Text widget at the bottom.
>>> How to do this? Is it impossible with the pack() method?
>>>
>> It is certainly not impossible, as long as you do not mind creating
>> a bunch of extra Frames, however to me this really sound like a
>> job for grid() .
>> You could simply use grid(row=  , column=0, columnspan=2)
>> for the widgets that should use the whole window's width and grid
>> the 3 buttons into columns 0, 1 and 2 .
> 
> Thanks. I'll give grid() a try.

It's pretty common to use nested Frames (or the equivalent in other GUI 
toolkits) to get the layout you want. If you can't do what you need with 
a single grid layout don't be shy about nesting layouts.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie string & File I/O questions.....

2006-11-26 Thread Asrarahmed Kadri

You can use, '\n' with each value, that u are writing to the file.

eg.   outstring = outstring + '\n'

\n  stands for new line character.

I couldnt get the second question.

Regarding the third question, you can do this:

done = 0
fd = open(filename,'r')
while not done:
   line = fd.readline()
   if line == '':
   done = 1
   else:
  for i in line:
 dict[i] = int(dict[i]) + 1# dict is a dictionary containing
numbers as the keys and initial value 0 for each key


HTH,

Regards,
Asrarahmed Kadri

On 11/26/06, Moedeloos Overste <[EMAIL PROTECTED]> wrote:


Hi everybody,

I am new to python and trying to write a lottery program for a
schoolproject.

The program is supposed to draw the lottery any entered(user input) number
of times, then store the drawing results in a file. After drawings the
user
should see (if he wants to) how many times each of the possible numbers
was
picked by the computer and which were the six most succesful numbers.
These
data must be calculated from the data stored in the file!

This is what I've been able to come up with so far:

# Lottery chances.
# Programs ask how many times you want to have the lottery drawn by the
# computer. Then stores these draws and then shows the 6 numbers most
drawn
# by the computer.

# Importing for making the program nicer later on...
import os, sys
import time
import random


vDraws = input("How many times do you want to draw the lottery? :>")

# Draw lottery numbers & writing them to file

while vDraws > 0:
   List_LotNumbers = random.sample(range(0,46), 6) #random numbers from
range into list
   output_string = str(List_LotNumbers) #converting list to string to
store
it.
   fout = open("draw__output.dat", "a")
   fout.write(output_string)   #writing string to file
   fout.close()
   vDraws = vDraws - 1


# Printing all numbers drawn

vView = raw_input("Do want to see the results? y/n :>")

if vView == "y" or vView == "Y":
   fout = open("draw__output.dat", "r")
   Print_list = fout.readline()
   print Print_list

#end of program so far

My question is: how do I write the output of each lottery drawing on a
separate line

second question: how do i print the lottery drawings to the screen without
the brackets[]

third:can somebody point me in the right direction as to how do I make the
program read from the file and count how many times a number has been
drawn.

Any help or pointers would greatly be appreciated.

thanks,

Robert (forgive me my english, I am Dutch)

_
Windows Live Mail: Kies je eigen kleur, indeling en contacten!
http://imagine-windowslive.com/mail/launch/default.aspx?Locale=nl-nl

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor





--
To HIM you shall return.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Newbie string & File I/O questions......

2006-11-26 Thread Moedeloos Overste
Hi everybody,

I am new to python and trying to write a lottery program for a 
schoolproject.

The program is supposed to draw the lottery any entered(user input) number 
of times, then store the drawing results in a file. After drawings the user 
should see (if he wants to) how many times each of the possible numbers was 
picked by the computer and which were the six most succesful numbers. These 
data must be calculated from the data stored in the file!

This is what I've been able to come up with so far:

# Lottery chances.
# Programs ask how many times you want to have the lottery drawn by the
# computer. Then stores these draws and then shows the 6 numbers most drawn
# by the computer.

# Importing for making the program nicer later on...
import os, sys
import time
import random


vDraws = input("How many times do you want to draw the lottery? :>")

# Draw lottery numbers & writing them to file

while vDraws > 0:
List_LotNumbers = random.sample(range(0,46), 6) #random numbers from 
range into list
output_string = str(List_LotNumbers) #converting list to string to store 
it.
fout = open("draw__output.dat", "a")
fout.write(output_string)   #writing string to file
fout.close()
vDraws = vDraws - 1


# Printing all numbers drawn

vView = raw_input("Do want to see the results? y/n :>")

if vView == "y" or vView == "Y":
fout = open("draw__output.dat", "r")
Print_list = fout.readline()
print Print_list

#end of program so far

My question is: how do I write the output of each lottery drawing on a 
separate line

second question: how do i print the lottery drawings to the screen without 
the brackets[]

third:can somebody point me in the right direction as to how do I make the 
program read from the file and count how many times a number has been drawn.

Any help or pointers would greatly be appreciated.

thanks,

Robert (forgive me my english, I am Dutch)

_
Windows Live Mail: Kies je eigen kleur, indeling en contacten! 
http://imagine-windowslive.com/mail/launch/default.aspx?Locale=nl-nl

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] shebang question

2006-11-26 Thread Michael P. Reilly

Very true about Python being installed in different places.  In fact, for
system compatibility reasons, it is sometime required that two or three very
different releases of Python need to exist on the same system.  If more than
one happen to be in your path, then the use of "env python" becomes a
craps-shoot.  Env is not to be used in shebang unless you specifically using
it for the purpose it was designed for, and then make sure it is used
properly - "#!/usr/bin/env python" is not proper use.

FYI, most all good UNIX products for the last number of decades ship scripts
with fully qualified pathnames in the shebang lines.  As part of the
installation, if required, the line will be rewriten to the proper value.

 -Arcege

On 11/26/06, زياد بن عبدالعزيز الباتلي <[EMAIL PROTECTED]> wrote:


"john maclean" <[EMAIL PROTECTED]> On Sun, 26 Nov 2006 01:34:28 +
wrote:
> From what I can tell/remember, the first works in the *nix environment
> if python is in your $PATH, ...
Actually, no.  The first will try to feed the script to the executable
"/usr/bin/python".  If that doesn't exist (or is not executable) it'll
fail.

> ...the latter will find python "somehere" on your system by looking at
> wher the executables should be.
True, assuming there's "/usr/bin/env" on your system (and is executable)
and that "python" is found in your "$PATH" (and is executable).


The problem is that Python is not installed in the same place on all
OSes!  Some will install it under "/usr/local", others under "/opt".

The idea of "/usr/bin/env" is that it's always installed there (or it
should be!).  So, you don't need to figure out where is python (or perl,
ruby, make, sed, awk, or any other executable that "feeds" on
scripts/text files) installed as long as it's in your "$PATH".

(Of course, "env" have other uses.  As long as I can tell, this is not
the intended use of "env".  See "info env" for more information, or
if you don't have "info" see the manual.)

Ziyad.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor





--
There's so many different worlds,
So many different suns.
And we have just one world,
But we live in different ones.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are the issues in running Python script on another machine (developed on Windows but will be using on Linux)

2006-11-26 Thread Andreas Kostyrka
* Asrarahmed Kadri <[EMAIL PROTECTED]> [061126 16:15]:
> Hi folks,
> 
> I have a couple of programs that I want to test on a different machine..
> 
> I have developed these on Win-XP platform, but I want to test them on my
> college's machine, which is running Linux.
> 
> Are there any issues involved or i just need to take my files on a USB
> memory stick, and copy paste and that is it..?

Well, you can try that. Details certainly depend upon if your scripts
depend upon third party extensions, and if these are available on Linux.

Andreas
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with Tkinter, please

2006-11-26 Thread Dick Moores
At 08:59 AM 11/26/2006, Michael Lange wrote:
>On Sat, 25 Nov 2006 17:23:39 -0800
>Dick Moores <[EMAIL PROTECTED]> wrote:
>
> > I've done a lot of fiddling around with setting "side=left", and
> > trying to put all the buttons inside a second Frame inside the first
> > one, but I can't get the layout I want, which is the Label on top of
> > the Entry, then a row of the first 3 buttons (which respectively
> > trigger 3 different computations on the integer the user enters).
> > Then below that, the Exit button, with the Text widget at the bottom.
> > How to do this? Is it impossible with the pack() method?
> >
>
>It is certainly not impossible, as long as you do not mind creating
>a bunch of extra Frames, however to me this really sound like a
>job for grid() .
>You could simply use grid(row=  , column=0, columnspan=2)
>for the widgets that should use the whole window's width and grid
>the 3 buttons into columns 0, 1 and 2 .

Thanks. I'll give grid() a try.

Dick



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python exceptions

2006-11-26 Thread johnf
My debugger comes up with lots of exceptions (builtin with my IDE wing) when I 
run code I have obtained from others.  This is not a formating error - but 
real unhandled exceptions.  But the when the program/programs is/are run from 
the command line they work as expected.  

So does this mean that the code has some sort of exception handler not part of 
the python code?  Or could mean that Python ignores certain exceptions.  BTW 
this comes mostly from GUI programs.
-- 
John Fabiani
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with Tkinter, please

2006-11-26 Thread Michael Lange
On Sat, 25 Nov 2006 17:23:39 -0800
Dick Moores <[EMAIL PROTECTED]> wrote:

> I've done a lot of fiddling around with setting "side=left", and 
> trying to put all the buttons inside a second Frame inside the first 
> one, but I can't get the layout I want, which is the Label on top of 
> the Entry, then a row of the first 3 buttons (which respectively 
> trigger 3 different computations on the integer the user enters). 
> Then below that, the Exit button, with the Text widget at the bottom. 
> How to do this? Is it impossible with the pack() method?
> 

It is certainly not impossible, as long as you do not mind creating
a bunch of extra Frames, however to me this really sound like a
job for grid() .
You could simply use grid(row=  , column=0, columnspan=2)
for the widgets that should use the whole window's width and grid
the 3 buttons into columns 0, 1 and 2 .

Michael

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] What are the issues in running Python script on another machine (developed on Windows but will be using on Linux)

2006-11-26 Thread Asrarahmed Kadri

Hi folks,

I have a couple of programs that I want to test on a different machine..

I have developed these on Win-XP platform, but I want to test them on my
college's machine, which is running Linux.

Are there any issues involved or i just need to take my files on a USB
memory stick, and copy paste and that is it..?

thanks for the help.

Regards,
Asrarahmed

--
To HIM you shall return.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] my program problem!

2006-11-26 Thread Alan Gilfoy
Hey! Glad to hear that using raw_input() at the end is the actual  
solution, not just a jury-rigged workaround. :)
So sleep(10) would simply be a shorter snippet of code for that purpose?

The \n thing might be handy if I was short on space, but I don't mind  
separate 'print' lines, I find that my code seems easier to read that  
way. (at least to me)
I understand that having highly readable code is a ratehr desirable  
quality...:)
-- 
"Blind faith in bad leadership is not patriotism."

"One of the most horrible features of war is that all the war-propaganda, all
the screaming and lies and hatred, comes invariably from people who are not
fighting."-George Orwell, _Homage to Catalonia_





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] shebang question

2006-11-26 Thread shawn bright

well thanks for all the info, gents,  i appreciate it a lot !
sk

On 11/26/06, زياد بن عبدالعزيز الباتلي <[EMAIL PROTECTED]> wrote:


"john maclean" <[EMAIL PROTECTED]> On Sun, 26 Nov 2006 01:34:28 +
wrote:
> From what I can tell/remember, the first works in the *nix environment
> if python is in your $PATH, ...
Actually, no.  The first will try to feed the script to the executable
"/usr/bin/python".  If that doesn't exist (or is not executable) it'll
fail.

> ...the latter will find python "somehere" on your system by looking at
> wher the executables should be.
True, assuming there's "/usr/bin/env" on your system (and is executable)
and that "python" is found in your "$PATH" (and is executable).


The problem is that Python is not installed in the same place on all
OSes!  Some will install it under "/usr/local", others under "/opt".

The idea of "/usr/bin/env" is that it's always installed there (or it
should be!).  So, you don't need to figure out where is python (or perl,
ruby, make, sed, awk, or any other executable that "feeds" on
scripts/text files) installed as long as it's in your "$PATH".

(Of course, "env" have other uses.  As long as I can tell, this is not
the intended use of "env".  See "info env" for more information, or
if you don't have "info" see the manual.)

Ziyad.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please suggest a python book

2006-11-26 Thread Dick Moores
At 06:34 AM 11/25/2006, Eike Welk wrote:
>If you are a natural scientist or an engineer you should look at:
>
>Hans P. Langtangen
>Python Scripting for Computational Science
>
>It's an introduction to Python and to topical libs, for people who
>want to do numerical computations.

Thanks for this!

BTW Amazon lets us look inside: 

Dick Moores


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] adjust key bindings

2006-11-26 Thread John CORRY
Hi All,

I have been trying to bind the "z" key to the "Down" key using Python
2.4, Glade 2 and Pygtk.  I have posted this problem on the Pygtk list
but have had no response.  I was hoping somebody on the tutor list could
help.  I think that I am close.  I can capture the "z" key press and
assign a "Down" key press but I can't get the "Down" key press to
register on the Treeview in the GUI.

Any thoughts greatly appreciated.

Thanks,

John.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of John CORRY
Sent: 25 November 2006 17:23
To: 'Fabian Braennstroem'; pygtk@daa.com.au
Subject: RE: [pygtk] Re: adjust key bindings

Fabian,

I have had a go at binding the "z" key to the down cursor key.  I can
block the Z key press and assign the "down" cursor key press and print
out the "down" key press but I can't redirect the signal back to the
widget.  I have enclosed the code below, maybe someone else on the list
can finish off the code.

The code below assumes that you have a window in Glade with one treeview
widget.  Both widgets have the "key_press_event" assigned in glade.

import shutil
import pygtk
import findgtk
import gtk
import gtk.glade

import gobject
import os
import sys

class Shopcard:

def __init__(self):
self.wTree = gtk.glade.XML ("project12.glade", "window1")
dic={"on_window1_delete_event" : self.quit100, }
self.wTree.signal_autoconnect (dic)
tree1 = self.wTree.get_widget("treeview1")
windy = self.wTree.get_widget("window1")
tree1.connect("key_press_event",self.callback3000,tree1,windy)
model = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
self.hostmodel = model
host_inter=self.insert_row(model,None,"test",'Test')
host_inter=self.insert_row(model,None,"test1",'Test')
host_inter=self.insert_row(model,None,"test2",'Test')
host_inter=self.insert_row(model,None,"test3",'Test')
host_inter=self.insert_row(model,None,"test4",'Test')
tree1.set_model(model)
renderer=gtk.CellRendererText()
column=gtk.TreeViewColumn("Col1",renderer,text=0)
column.set_resizable(True)
tree1.append_column(column)
renderer=gtk.CellRendererText()
column=gtk.TreeViewColumn("Col2",renderer,text=1)
column.set_resizable(True)
tree1.append_column(column)

def insert_row(self,model,parent,firstcolumn,secondcolumn,
thirdcolumn=None):
myiter=model.insert_after(parent,None)
model.set_value(myiter,0,firstcolumn)
model.set_value(myiter,1,secondcolumn)
if thirdcolumn !=None:
model.set_value(myiter,2,thirdcolumn)
return myiter


def callback3000(self,widget,event,tree1,windy):
import re

"""prevents the possibility of inputting wrong chars"""
## fixme: missing comma, and cut&paste
key = gtk.gdk.keyval_name (event.keyval)

 
ONLYDIGITS="([0-9.,z]|BackSpace|Left|Right|F1|period|Tab|Up|Down)"
if not re.match (ONLYDIGITS, key):
print "True"
return True

else:
if key == "z":
tree1.emit_stop_by_name("key_press_event") # This blocks
the signal from the key press
event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
event.keyval = 65364 # This is the code for the down key


event.state = gtk.gdk.CONTROL_MASK
event.time = 0 # assign current time
print gtk.gdk.keyval_name(event.keyval)
tree1.emit('key_press_event', event)
tree1.connect("key_press_event",self.callback3001)

else:
print event.keyval
print "else"
return False
def callback3001(self,widget,event):
import re

"""prevents the possibility of inputting wrong chars"""
## fixme: missing comma, and cut&paste
key = gtk.gdk.keyval_name (event.keyval)
print key
print "made it"
 
ONLYDIGITS="([0-9.,z]|BackSpace|Left|Right|F1|period|Tab|Up|Down)"
if not re.match (ONLYDIGITS, key):
print "True2"
return True
def quit(self,obj):
gtk.main_quit()
sys.exit(1)
def quit100(self,obj,wind):
gtk.main_quit()
sys.exit(1)  

if __name__ == '__main__':
Shopcard()
try:
gtk.threads_init()
except:
print "No threading was enabled when you compiled pyGTK!"
import sys
sys.exit(1)
gtk.threads_enter()
gtk.main()
gtk.threads_leave()

The code outputs the following:

When you hit the down cursor it prints:
65364
else

and when you hit the "z" key it prints:
Down
65364
else

Regards,

John.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Fabian Braennstroem
Sent: 18 November 20

Re: [Tutor] Auto-hyperlinking ignoring html tags

2006-11-26 Thread Kent Johnson
anil maran wrote:
> Hey
> 
> I m trying to auto-hyperlink urls,
> i found libcia.web.Regextransform.py
> but the problem is it applies auto hyperlink on html tags
> for eg < img src = " http://www.google.com/a.gif " >
> 
> becomes
> *gta* img src=" < a href= "http://www.google.com/a.gif " *lt
> 
> is there any way to auto-hyperlink on text, ignoring whatever is in html 
> tags ie within < >

I'm not sure I understand what you want. I think you have some HTML and 
you want to find URLs that are in the text of the HTML and convert them 
to hyperlinks.

To do this you have to parse the HTML, for example using Beautiful Soup.
http://www.crummy.com/software/BeautifulSoup/

Then you can walk through the parsed tags and modify the text of the 
tags to include the hyperlinks.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please suggest a python book

2006-11-26 Thread Eike Welk
If you are a natural scientist or an engineer you should look at:

Hans P. Langtangen
Python Scripting for Computational Science

It's an introduction to Python and to topical libs, for people who 
want to do numerical computations.

Eike

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] shebang question

2006-11-26 Thread زياد بن عبدالعزيز الباتلي
"john maclean" <[EMAIL PROTECTED]> On Sun, 26 Nov 2006 01:34:28 +
wrote:
> From what I can tell/remember, the first works in the *nix environment
> if python is in your $PATH, ...
Actually, no.  The first will try to feed the script to the executable
"/usr/bin/python".  If that doesn't exist (or is not executable) it'll
fail.

> ...the latter will find python "somehere" on your system by looking at
> wher the executables should be.
True, assuming there's "/usr/bin/env" on your system (and is executable)
and that "python" is found in your "$PATH" (and is executable).


The problem is that Python is not installed in the same place on all
OSes!  Some will install it under "/usr/local", others under "/opt".

The idea of "/usr/bin/env" is that it's always installed there (or it
should be!).  So, you don't need to figure out where is python (or perl,
ruby, make, sed, awk, or any other executable that "feeds" on
scripts/text files) installed as long as it's in your "$PATH".

(Of course, "env" have other uses.  As long as I can tell, this is not
the intended use of "env".  See "info env" for more information, or
if you don't have "info" see the manual.)

Ziyad.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] program spontaneously closes...

2006-11-26 Thread Luke Paireepinart
Bob has answered your original question, but I'd like to make some 
observations.
Alan Gilfoy wrote:
> Hello All.
> I've been concocting some simple programs based on an online tutorial,  
> and I, of course, save a program as a .py file.
>
> When running my program via IDLE, once I've cleaned out the bugs, it  
> works as I expect it to.
>   
Perhaps the way you expect it to work is not the way it should work :)
> But I noticed something else:
>
> Clicking directly on the file's icon has the program open in the  
> Windows command line program as a .exe file.
>   
I'm not really sure why you say 'as a .exe file.'  Nowhere along the 
line is your python script compiled into an exe file.
Yes, Python itself is an executable, but your script is not, unless you 
explicitly make it one.
> The command line program seems to work through my program OK, but the  
> command line program shuts down immediately after the program has run  
> through, as opposed to staying open in order to display the result. [I  
> noticed that if the command line program is not waiting for a resposne  
> to a prompt, it stays open.]
>   
I think you mean 'if the command line program IS waiting for a response 
to a prompt, it stays open.'
And what's all of this 'command-line' business?  Your python script is 
the same when run by double-clicking as it is when run from idle:
it's interpreted by Python.  IDLE happens to have a wrapper for the 
interpreter that captures all the output, so that it can display the 
tracebacks in nice pretty red colors,
and things like that.  But it is still the same as when you run it by 
double-clicking the script.
> Relevant code block:
>
> #rectangle stuff
> length = int(raw_input("Please enter the length of your rectangle, as  
> a whole number : ")) #lets user input a number
> width = int(raw_input("Please enter the width of your rectangle, as a  
> whole number : ")) #lets user input a number
> area = length * width
> print " "
> print " "
> print " "
>   
If you're trying to make blank lines, you don't need to print a blank space.
This could just as well be
print ""
or even
print
but a better way, in my opinion, to do this is to add newlines!

eg.
print "\n"*3
or
print "\n\n\n"

> print "the length is"
> print length
> print " "
> print "the width is"
> print width
> print " "
> print "So the area is"
> print area
> print " "
>   
and all of this could be shortened to:
print "The length is " + length + ",\nand the width is" + width + 
".\nThe Area, therefore, is " + area + ".\n"
or even
print "Length: %s, Width: %s, Area: %s." % (length, width, area)
But of course you don't have to listen to my suggestions,
particularly if their functionality doesn't make sense.
No reason to copy-pasta.
It's more important that you know what the crap is going on with your 
code :)


On a final note, consider if the Python interpreter didn't automatically 
exit whenever it was done executing code:
So we've been doing console IO for a few days, and we're moving on to a 
GUI app.  So we make an app that
edits MP3 version 1 tags, say.  Now, whenever someone messes with the 
tag and exits our program, there's this crazy dos box that just sits 
there saying
'press any key to exit!' or something, and otherwise it's completely blank.
Is that what you want to happen?
Just remember that Python is used for many things besides console IO, 
and it makes everything much simpler if Python just requires you to put 
a sleep(10)
at the end of your program, or a raw_input, if you want to view the results.

Eventually you'll get into scripts that have a menu, that's displayed in 
a loop, and then you'll have a 'quit' option to exit out of the loop.
Otherwise, the loop just runs through again and you can look back at 
your previous data if you want.
SO in this case you could see the previously calculated rectangle values 
while it's asking you for the new data.

HTH,
-_-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about HORIZONTAL BAR CHART.....

2006-11-26 Thread Luke Paireepinart
Asrarahmed Kadri wrote:
> As far as I understand, I need to design an algorithm which computes 
> the padding between each bar (space between each bar) and the length 
> of each bar ( remember that this is a HORIZONTAL BAR CHART).
I think what you want to design is an algorithm that computes the HEIGHT 
of each bar (as it's a HORIZONTAL bar chart)
because the vertical padding, (The space between each bar) is a fixed 
number, like 20 pixels.  At least that's what i would do.
This height is dependent upon the number of data sets you have.

For the width of the bars (remember this is a horizontal bar chart, so 
the heights of the bars will all be the same, but the widths will be 
different)
you will want to set it up so that the largest data value is set to the 
widest bar, and the rest are percentages of this width.
I hope that helps.
-Luke

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor