[Tutor] Broblem with exiting a Tkinter app

2004-12-04 Thread Mark Kels
Hi all ,
I got 2 questions for you guys.

The fist question:
I wrote small Tkinter app while laerning about the Radiobutton widget,
and I added a "Quit" button, like this:
bb=Button(root, text="Quit", fg="BLUE", command=root.quit).pack()
When I pressed the button the app crashed and I got an error message (
program is not responding ) from windows.
I tried to add a frame to the program and then exit the frame, like this:
bb=Button(f, text="Quit", fg="BLUE", command=f.quit).pack()
But the result is the same...

Here is the full source code of the app:
from Tkinter import *
import sys
root=Tk()
f=Frame(root)
text=Label(root, text="how old are you?").pack()
v = IntVar(root)
Radiobutton(f, text="less than 13", variable=v, value=1).pack(side=LEFT)
Radiobutton(f, text="13-20", variable=v, value=2).pack(side=LEFT)
Radiobutton(f, text="20-40", variable=v, value=3).pack(side=LEFT)
Radiobutton(f, text="40+", variable=v, value=4).pack(side=LEFT)
bb=Button(f, text="Quit", fg="BLUE", command=f.quit).pack()
f.pack()
root.mainloop()

The second question:
I dont understand how to get the input fron the radio buttons...
It doesnt returns any value, so how can the app know what the user chose?

Thanks!!
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Broblem with exiting a Tkinter app

2004-12-04 Thread Mark Kels
On Sat, 04 Dec 2004 14:38:06 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Mark Kels wrote:
> 
> 
> > Hi all ,
> > I got 2 questions for you guys.
> >
> > The fist question:
> > I wrote small Tkinter app while laerning about the Radiobutton widget,
> > and I added a "Quit" button, like this:
> > bb=Button(root, text="Quit", fg="BLUE", command=root.quit).pack()
> > When I pressed the button the app crashed and I got an error message (
> > program is not responding ) from windows.
> > I tried to add a frame to the program and then exit the frame, like this:
> > bb=Button(f, text="Quit", fg="BLUE", command=f.quit).pack()
> > But the result is the same...
> >
> > Here is the full source code of the app:
> > from Tkinter import *
> > import sys
> > root=Tk()
> > f=Frame(root)
> > text=Label(root, text="how old are you?").pack()
> > v = IntVar(root)
> > Radiobutton(f, text="less than 13", variable=v, value=1).pack(side=LEFT)
> > Radiobutton(f, text="13-20", variable=v, value=2).pack(side=LEFT)
> > Radiobutton(f, text="20-40", variable=v, value=3).pack(side=LEFT)
> > Radiobutton(f, text="40+", variable=v, value=4).pack(side=LEFT)
> > bb=Button(f, text="Quit", fg="BLUE", command=f.quit).pack()
> > f.pack()
> > root.mainloop()
> 
> This program works fine for me on Win2K. How are you running the program?
> >
> > The second question:
> > I dont understand how to get the input fron the radio buttons...
> > It doesnt returns any value, so how can the app know what the user chose?
> 
> Read the value from the variable associated with the buttons - v. For example 
> if you define
> def quit():
>  print 'You chose button', v.get()
>  f.quit()
> 
> and change the command on bb to command=quit, the program will print the 
> selection value on exit.
> (You have to define quit before bb or you will get a NameError.)
> 
> Kent
> >
> > Thanks!!
> > ___
> > Tutor maillist  -  [EMAIL PROTECTED]
> > http://mail.python.org/mailman/listinfo/tutor
> >
> ___
> Tutor maillist  -  [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/tutor
> 

Thats weird...
Suddenly the program started to work fine :-) !

Thank you very much for your time.
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to get input from Tkinter app ?

2004-12-10 Thread Mark Kels
Hi all,

I got 2 questions:

1. How to get input from Tkinter widgets like Text, Entry,
Checkbutton, Scale etc (almost any widget that isn't a button) ?
for some reason its not explained clearly in any tutor I looked in... 

2. How to print text using python ( through the printer ) ?
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Tkinter questions

2004-12-17 Thread Mark Kels
Hi all ,
I got some Tkinter related questions for a project that I'm making:
1. How to add an image to a button ?
2. How can I print text using Tkinter (I want it to be cross platform,
so I cant use modules like win32print ) ?
3. How to I make the program to always open in a full window ?

Thanks allot.

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tkinter questions

2004-12-18 Thread Mark Kels
 > I find the easiest way is to create an PhotoImage object attach
> the graphic file(jpg,bmp,gif) to that and assign the PhotoImage
> object to the Button.image property. You can "animate" the image
> by simply reassigning the file to the underlying PhotoImage onject.
Thanks, but a practical explanation will be more helpful.

> You mean print as in to a printer?
> Personally I tend to generate an HTML file and use the
> native OS Tools to print that. You can get fancy and
> use the native OS priniting libraries but since its
> very OS specific I find HTML is easier! OUtside Tkinter
> you may well find the GUI libraries have done the cross
> platform stuff for you, but not in Tkinter.
Again, a practical explanation will be more helpful...

> Define a full window? You mean full screen?
> Thats usually better done as a parameter that the user can
> set unless there is a very good reason not to. (Personally
> I refuse to use any program that insists on opening full screen!)
Full window or full screen is when the window of the program is all
over the screen except the start bar (or whatever the blue line in the
bottom of a windows xp called).
And why you refuse to use any program that insists on opening full screen ?
If it does then there must be a good reason for that... 

> If OTOH you mean that you don't want the DOS box in the background
> thats easy, just rename the .py file to .pyw. But I suspect,
> since you talk about cross platform you mean full screen.
I did wanted a full screen, but this is very helpful too :) .

Thanks allot .

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tkinter questions

2004-12-20 Thread Mark Kels
On Mon, 20 Dec 2004 18:21:13 +1300, Liam Clarke <[EMAIL PROTECTED]> wrote:

> from Tkinter import *
> import Image, ImageTk
> root = Tk()
> img = Image.open('SonicCruiser.gif')
> phi = ImageTk.PhotoImage(img)
> button = Button(root, image=phi)
> button.pack()
> root.mainloop()

Thank you !!
But I don't have the Image module...
Is it a part of the PIL toolkit ?
If not, where can I get it ?

> 
> > Again, a practical explanation will be more helpful...
> 
> Cross platform easy printing? wxPython, which is totally different to Tkinter.
> 
> http://mail.python.org/pipermail/python-list/2004-January/205116.html
> 
> >Printing is not easy, it is a complicated matter.
> 
> >You can find 4 simplifications:
> 
> >1) wxPython has a print-framework, wxPython is cross platform (alas, I only
> used it in win32)
> 
> >2) print postscript. Ghostscript is available on "every" platform.
> (printing on PDAs and watches is  really different). Postscript is
> documented
> 
> >3) create PDF. PDF viewers & printers are available on "every" platform.
> PDF can be created by (free) ReportLab toolkit, and I'm sure there are more
> PDF-Classes
> 
> >4) create XHTML & a Print.CSS. HTML viewers are available on every
> Plattform, .CSS allows fairly good styling of printouts.
> 

Is it so hard if I only want to print plain text ?
Because I don't need anything special (only black text on white paper...).

> You mean like IE's really good reasons to insist on being my default
> browser for everything? You're putting a lot of faith in software
> developers.

Maybe I do... =)

> You do realise that -
> 
> no-one here is paid to answer queries?
> Alan Gauld is a very knowledgable person?
> Any knowledge is good knowledge?
> If at first you don't succeed, rephrase or Google?

Yes, I do.
Actually, I don't understand why you don't think its obvious to me (
must be because of my bad English =).

Thanks allot !

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Environment Variables On Windows

2004-12-26 Thread Mark Kels
Hello to all :-)

I'm writing a CGI script (one of my first ever CGI programs and I'm
using this tutor to learn CGI: http://www.oreilly.com/openbook/cgi/
This isn't a python tutor, but the introductions says that any
language will be good for this tutor.
Anyway, I got to the Using Environment Variables chapter that is in
this page: http://www.oreilly.com/openbook/cgi/ch02_02.html.
This is UNIX environment variables (as I understand), and I guess they
will not work on Windows...
So what are the Windows environment variables and how can I use them
with python (like any other variable or in a special way?) ?

Thanks!
   
-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Environment Variables On Windows

2004-12-26 Thread Mark Kels
> Morning Mark,
> 
> Happy New Year, Merry Christmas, and a jolly Winter Solstice Season!
> 
> Whenever you're talking about how to do something in Windows it REALLY
> helps when you include WHICH windows you're working with.
> 
> I believe the following will allow you to manipulate windows
> environmental variables.  If anyone sees I'm wrong I know they'll speak
> up.  The "set" command when run in a command window without parameters
> lists your current environmental variables.  You can also use it as:
> c:\> set hello=Hi there Mark
> which will set the variable "HELLO" to "Hi there Mark".
> c:\> echo %HELLO% or
> c:\> echo %hello%
> will now print "Hi there Mark" without the quotes.
> 
> Note that quoting, case sensitivity, and white spaces can all react
> differently under windows than they do in Python.
> 
> If you need to set an environmental variable to a value every time you
> start windows then you can either store the above set command (no spaces
> around that "=" remember) in the autoexec.bat file or on Windows 2000,
> XP and (I believe) NT you can right click on the desktop icon "My
> Computer" and select "Properties".  Now you're looking for the
> "Advanced" tab and the environmental variables button in Windows 2000.
> I THINK it's under the "System Performance" tab and advanced button in
> XP and you'll have to dig in NT.  I'm not sure you can do this here
> under the win 95/98/ME family.   Sorry, right now the only windows
> product I'm running at home is 2000.
> 
> You can also set Windows environmental variables from within your python
> script of course.
> 
> FYI being a coward myself before I go changing my setup I like to
> document things.  Say running "set > Environment-Before.txt" in a nice
> safe directory.  This will output your current setup so if things get
> weird you can at least bring things back to you starting point.
> 
> Have a good one,
> 
> John Purser
> 
Thanks allot !!
But I don't understand how to use the environment variables in the
script itself...
I tried to do this:

import os
import cgitb; cgitb.enable()
print "Content-type: text/html\n\n"
print "Hi there, ",os.system("echo %USERNAME%")

But I don't get anything in the browser (500 error - Internal Server
Error) and when I run the script in IDLE I get:

Hi there,  0

I guess its not the way to print them, but it's the only way I came up with.
And I got another question:
In my server program I have "User CGI Environment Variables" list that
should have pares of  Name:Value in it...
Whats that? (I guess its the same in all server programs).

Thanks!

BTW, I'm running Windows XP and Abyss Web Server on my PC.
-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Looking for a project participate in (a little OT)

2005-01-06 Thread Mark Kels
I'm learning python for a few months now, and I would like to get some
experience by participating in a good, open source, and small
python-CGI project.
I searched freshmeat.net but couldn't find anything interesting
(except __ but I think its dead...).
Anyone knows of a good small and open source python-CGI project that
needs people ?

Thanks.
And sorry if its to much OT.

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Problem with a variable in a CGI program

2005-01-07 Thread Mark Kels
HI all !
I started to read the following code (I will start working on it when
this problem is fixed) and it looks OK while I read it. But for some
reason it doesn't work...
Here is the code:

# MailList is copyright (c) 2000 of Programmed Integration
# You may use this code in any way you see fit, but please
# let use know where it is being used. If you make any changes to
# the source code, please send us a copy so we can incorporate
# the changes in future releases. If you have any other comments
# please feel free to contact us at [EMAIL PROTECTED]

# MailList version 1.0.0 22 August 2000

import sys
sys.path.append('/lib/python1.5')  # My ISP requires this to
correctly locate Python Modules

import cgi, re, string # Import all the required modules

try:
   useHead=open("head.txt", "r")   # Open the HTML header file
   useFoot=open("foot.txt", "r")   # Open the HTML footer file

   ContentLine="Content-type: text/html"   # Standard content type for
HTML files

   useform=cgi.FieldStorage()  # Assign all variables on
web form to UseForm variable
   email= useform["email"].value   # Assign from form to local
variables. Proposed email address
   email2= useform["email2"].value # ditto, verified email address
   password= useform["password"].value # ditto, proposed password
   password2= useform["password2"].value   # ditto, verified password
   action=useform["action"].value  # ditto, action, i.e
subscribe or unsubscribe

   try:   
  optout=useform["optout"].value   # ditto, optout clause, yes or no
   except: # I've enclosed this in a try/except
  optout='no'  # as if the checkbox is
unchecked, nothing
   # was returned.  This way
'no' is returned

   print ContentLine   # Print standard content line
   print   # Needs a blank line following
   print useHead.read()# Print HTML header
   if email!=email2:   # Checks to see if two
entered email addresses match
  print "Email addresses do not match" # If no match print error 
  sys.exit(0)  # Exit script with error 0
   elif password!=password2:   # Checks to see if two
entered passwords match
  print "Passwords do not match"   # If no match print error
  sys.exit(0)  # Exit script with error 0
   
   useMailList=open("maillist.txt", "r")   # Open mailling list
   memMailList=useMailList.readlines() # Assign mailing list to
internal list
   useMailList.close   # Close mailing list
   found=0 # Create found variable
   counter=0   # Create counter variable
   for UseLine in memMailList: # For loop until list end is reached
  if string.find(string.upper(UseLine), string.upper(email))!=-1:
# Checks to see if email is in mailing list
 found=1   # If yes, found = true (1)
 UseSplit=re.split(',',UseLine)# Create list of found line
and delimit with a comma
 break # Exit for loop
  counter=counter+1# If not found incrememnt
count and repeat
   if not found:   # If email address not
found in mailing list
  if action=="unsubscribe":# And if action is unsubscribe
 print "Email address "+email+" does not exist on our
database" # Print error message
  else:# Otherwise
 lineuse=email+","+password+','+optout+"\n" # Form valid
mailing list entry
 memMailList.append(lineuse)   # Add to internal list
 print "Subscription for "+email+" successful"
#Print success to HTML
 print "Many thanks for subscribing.  Please be sure to make a note"
 print "of the email address you subscribed with.  You will only"
 print "be able to unsubscribe if you use that email address."
   else:   # Otherwise if email
address not found in mailing list
  if action=="unsubscribe":# And if actions is unsubscribe
 if password==UseSplit[1]: # If password is valid
memMailList[counter]=''# Empty internal mailing list entry
print "Unsubscription for "+email+" successful" #
Print unsubscribe success to HTML
 else: # Otherwise if password not valid
print "Unsubscription for "+email+" unsuccessful. 
Password is invalid" # Print unsubscribe unsuccessful to HTML
print "Remember that passwords are case sensitive.  i.e.
password is not the same as PassWord"
  else:# Otherwise if subscribe
 print "Subscription for "+email+" al

Re: [Tutor] Problem with a variable in a CGI program

2005-01-07 Thread Mark Kels
On Fri, 7 Jan 2005 11:16:29 -0800 (PST), Danny Yoo
<[EMAIL PROTECTED]> wrote:
> 
> 
> On Fri, 7 Jan 2005, Mark Kels wrote:
> 
> > I started to read the following code (I will start working on it when
> > this problem is fixed) and it looks OK while I read it. But for some
> > reason it doesn't work...
> 
> Hi Mark,
> 
> Ok, let's take a look at the error message:
> 
> 
> > Traceback (most recent call last):
> >   File "C:\maillist.py", line 80, in ?
> > useMailList.writelines(memMailList) # Copy internal mailing list to 
> > file
> >
> > NameError: name 'memMailList' is not defined
> 
> Ok, good, so we know what we should look for: we should see where
> 'memMailList' is defined, and see if there's any way that the program flow
> can route around the definition.
> 
> Ok, I see it, embedded within the context of a try/except block.
> 
> ##
> try:
> 
> ## some code before definition of memMailList...
> 
> memMailList=useMailList.readlines()
> 
> ## some more code cut...
> 
> finally:
>useMailList=open("maillist.txt", "w")
>useMailList.writelines(memMailList)
>useMailList.close
>print useFoot.read()
>useHead.close;
>useFoot.close;
> ##
> 
> There's one possibility that strikes me: it's very possible that in the
> code before the definition of memMailList might raise an exception, or
> exit out prematurely due to a sys.exit().  If that happens, then Python
> will finish things up by jumping into the 'finally' block.  And if that
> happens, then we haven't reached memMailList's definition, and the
> NameError is inevitable.
> 
> Here's a simplified example of what might be happening:
> 
> ###
> >>> try:
> ... a = 42
> ... 5 / 0
> ... b = 17
> ... finally:
> ... print "a is", a
> ... print "b is", b
> ...
> a is 42
> b is
> Traceback (most recent call last):
>   File "", line 7, in ?
> NameError: name 'b' is not defined
> ###
> 
> A direct way to debug this is to drop the 'finally' block altogether.  If
> we do so, like this:
> 
> ##
> ## some code before definition of memMailList...
> 
> memMailList=useMailList.readlines()
> 
> ## some more code cut...
> 
> useMailList=open("maillist.txt", "w")
> useMailList.writelines(memMailList)
> useMailList.close
> print useFoot.read()
> useHead.close;
> useFoot.close;
> ##
> 
> then the real cause of the problem should pop up quickly.
> 
> A few more comments:
> 
> 1.  The calls to close() need parentheses.  Unlike some other programming
> languages, function calls fire off only with parens.  Instead of:
> 
> useFoot.close
> 
> you probably want:
> 
> useFoot.close()
> 
> 2.  I also see that the code is hardcoded to use Python 1.5.  Is there any
> way you can use a more modern version of Python?  The reason I ask is that
> recent versions of Python have really good modules for debugging CGI
> programs, including the excellent 'cgitb' module:
> 
> http://www.python.org/doc/current/lib/module-cgitb.html
> 
> Writing CGI programs without 'cgitb' is almost criminal.  *grin*  If you
> can, use it.
> 
> 3.  The program is long.  Can you break it down into some functions?  The
> program looks like one big monolith, and I'm actually quite terrified of
> it.  *grin*
> 
> Small functions are much easier to debug, and more approachable for
> maintainers of the code.  This is a style critique, but it does matter
> because although computers don't care what code looks like, human
> programmers do.
> 
> 4.  Related to Comment Three is: there are way too many comments on the
> side margin.  Comments like:
> 
> ###
> if email != email2:  # Checks to see if two entered
>  # email addresses match
> print "Email addresses do not match" # If no match print error
> sys.exit(0)  # Exit script with error 0
> elif password != password2:  # Checks to see if two
>  # entered passwords match
> print "Passwords do not match"   # If no match print error
> sys.exit(0)  # Exit script with error 0
> ###
> 
> are redundant, since they basically parrot what the code is doing.
> 
> Concise comments that explain the reason why the code is doing what it's
> doing can be more 

[Tutor] Python with MySQL ?

2005-01-11 Thread Mark Kels
Hi all.
How can I send SQL querys to a MySQL database with a python-CGI program ?

Thanks.
-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python and IRC

2005-01-19 Thread Mark Kels
Hi all,

I want to make an IRC bot with python...
The problem is that I cant find any good information about this topic
(not even documentation for the irclib module).
Does anyone here have some experience with python programming for IRC
(clients, bots, etc) and can give me some simple source code or a good
tutorial (name of book will be fine too) ?

Thanks.
-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Tkinter questions

2005-02-01 Thread Mark Kels
Hello,
I got some Tkinter questions that I need the answer for to complete a
little project of mine:
1. How can I make the program to open in a X*Y sized window ?
2. How can I open another window from the first one (without closing it) ?
3. How can I add a file browser for my app (like the one you get when
you press "Save as..." in windows apps) ?
4. How do I configure the font size on the Text widget (its realy
huge, and I would like to change it to somthing like 12).
5. [OT] Do you know any web-sites that I can store my project at (like
sourceforge and others) ?

This is all for now :)
Thanks in advence .

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] A problem with a Tkinter program (using the text widget)

2005-02-05 Thread Mark Kels
Hi all.
Whats wrong here ?? :
from Tkinter import *
def p_text():
print text.get()
root=Tk()
text=Text(root).pack()
button=Button(root,text="Click here!!",command=p_text).pack()
root.mainloop()

I get an error that says that nontype object has no attribute 'get'...
whats wrong ??

Thanks.


-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] The Tkinter Text widget and .get()

2005-02-06 Thread Mark Kels
Hi all.

As I understand, .get() has to get an index argument to get the text
from the Text index...
The problem is that I dont realy understand what is this index thing
and what index do I need to give to the function so I'll get all the
text in the widget.
Any ideas ??

Thanks ! 
-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Downloading from http

2005-02-12 Thread Mark Kels
Hi list.

How can I download a file from an HTTP server ?
I checked the documentation but couldn't find what I need.

Thanks!
-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Downloading from http

2005-02-12 Thread Mark Kels
On Sat, 12 Feb 2005 09:25:10 -0500, Jacob S. <[EMAIL PROTECTED]> wrote:
> urllib or urllib2 or maybe httplib maybe?
> 
> urlopen( url[, data])
> 
>   Open the URL url, which can be either a string or a Request object.
>   data should be a string, which specifies additional data to send to the
> server. In HTTP requests, which are the only ones that support data, it
> should be a buffer in the format of application/x-www-form-urlencoded, for
> example one returned from urllib.urlencode().
> 
>   This function returns a file-like object with two additional methods:
> 
> a.. geturl() -- return the URL of the resource retrieved
> b.. info() -- return the meta-information of the page, as a
> dictionary-like object
>   Raises URLError on errors.
> 
>   Note that None may be returned if no handler handles the request (though
> the default installed global OpenerDirector uses UnknownHandler to ensure
> this never happens).
> 
> This is taken from the docs on urllib2. I think that's what you want, right?
> The tutorial or whatever, called "Dive into python", goes into accessing web
> pages a little more in depth than the docs do, I think.  You can google for
> it, I believe.
> 
> HTH,
> Jacob
> 
I'm sorry, but I didn't understood a thing (maybe its because of my
bad english, and mybe its because I'm just dumb :). Anyway, can you
give me a code example or a link to a tutorial that talks about this ?

Thanks alot.

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cross platform gui

2005-02-13 Thread Mark Kels
On Sun, 13 Feb 2005 08:03:45 -0800, Lobster <[EMAIL PROTECTED]> wrote:

> 
> Hi all,
> 
> i'm interested in building a gui for some code we have. I'm after
> pointers on gui programming, and a recommendation on a cross platform
> gui library, wxpython? pythoncard, qt? What do people use. Ideally i'd
> like something that can work on windows, osx and linux. Its a science
> program so the look is a of lesser importance  :)
> 
> cheers
> Kim

I think Tkinter will be the best for your needs...
Its totally cross platform (I believe it works anywhere python does)
and its the python default GUI toolkit (no additional modules needed).
Its downside is that it don't got any fancy widgets, but you don't
need them for a science program anyway.

Good luck !!


-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help with error handling in a while loop

2005-02-18 Thread Mark Kels
Hi all.
I'm trying to build a simple port scanner (just to learn sockets).
here is the code (doesn't work) :
import socket
sk=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host=raw_input("Enter name of host to scan: ")
start_port=input("Enter the start port: ")
end_port=input("Enter the end port: ")
while start_porthttp://mail.python.org/mailman/listinfo/tutor


[Tutor] help with .get in Tkinter

2005-02-20 Thread Mark Kels
Hi all.
First, here is the code I have a problem with (I got same problem in
my project) :
from Tkinter import *
def go():
e.get()
print e

main=Tk()
e=Entry(main)
e.pack()
b=Button(main,text='OK',command=go()).pack()
main.mainloop()

For some reason the function is called before I click the button, and
I get .10037088 before I have done a thing.
How do I do it right ???
-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help debuging a small program

2005-02-21 Thread Mark Kels
Hi list !
Here is a small port scanner I made to practice sockets and GUI
programming ( WARNING: the program crash when scan button is clicked):

#--Imports--
from Tkinter import * 
import socket
#--The result GUI window function-
def result():
global result_t #I made result_t global so I will be able to
insert data into it from the scan function
r_root=Toplevel(root)
result_t=Text(r_root)
result_t.pack()

#--Command Functions--
# + ---Function to get the info from the gui and start the scan---
def get_info():
result()
host=host_e.get()
start_port=int(start_port_e.get())
end_port=int(end_port_e.get())
scan(host,start_port,end_port)

# + ---The Scan---
def scan(host,start_port,end_port):
sk=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while start_port<=end_port:
try:
sk.connect((host,start_port))
except:
result_t.insert(END,"Port",start_port,"is CLOSED on",host,"\n")
else:
result_t.insert(END,"Port",start_port,"is OPENED on",host,"\n")
start_port=start_port+1

#--The main GUI window--
root=Tk()
Label(root,text="Host: ").grid(row=1,column=1)
host_e=Entry(root)
host_e.grid(row=1,column=2)
Label(root,text="Start port: ").grid(row=2,column=1)
start_port_e=Entry(root)
start_port_e.grid(row=2,column=2)
Label(root,text="End port: ").grid(row=3,column=1)
end_port_e=Entry(root)
end_port_e.grid(row=3,column=2)
Button(root,text="Scan",command=get_info).grid(row=5,column=1)

root.mainloop()

Why does the program crash (without any errors :-/ ) when I click the
Scan button ??

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help debuging a small program

2005-02-22 Thread Mark Kels
On Mon, 21 Feb 2005 13:21:35 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote:
> How far does it get? How do you know?
> 
> I would put some debug print statements in. Also you should call sk.close() 
> in the else clause of
> scan(). Finally, I don't think you will see any output in the result window 
> until get_info()
> returns; you have to give some time to mainloop() for it to be able to 
> trigger the updates.
I don't understand how to prevent the program from crashing right now...
I'll deal with other bugs when I'll finish this one :)
So, why does the program crashes and how can I prevent it ??

Thanks !!

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] 3 questions for my port scanner project

2005-02-26 Thread Mark Kels
Hi list.

Here are the questions (-:
1. How do I make a progress bar in Tkinter ?
2. I got a while loop which does the port scan itself. How can I end
it while its working ?
3. For some reason the scan is too slow (2-3 seconds for a port). Is
there a way to make it faster (other port scanner work allot faster...
) ?

Thanks in advance !! 

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 3 questions for my port scanner project

2005-02-27 Thread Mark Kels
On Sun, 27 Feb 2005 03:24:07 -0800 (PST), Shitiz Bansal
<[EMAIL PROTECTED]> wrote:
> 
> The ports which do not respond are the ones which take
> most of the time.You can use the timer object to fix
> the time for each port.For eg. if a port does not
> respond within .1 sec it can reasonably be expected to
> be closed.The exact implementation will depend upon
> your code.You can also use threads to ping more than
> one port simultaneously.
> 
Thank you very much for yuor help !!
Now I only need to figure out how to make a progress bar and my
trubles are over :)

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 3 questions for my port scanner project

2005-02-27 Thread Mark Kels
On Sun, 27 Feb 2005 16:00:12 -, Alan Gauld <[EMAIL PROTECTED]> wrote:
> One option:
> Use a set up gif images and update the image periodically
> OR
> Use a canvas and redraw a rectangle slightly larger every
> time through the scanning loop.

Thats think this is the easy part...
The hard part is to make the bar move "with" the program (so every
port it finishes the bar will slightly move, which depends on the
total number of ports to scan...).

 
> The best way is to have the loop running in a seperate thread
> to the GUI and checking a flag on each iteration. Then you can
> have a stop button on the GUI that sets the flag.
> Its generally a bad idea in a GUI to have long running processes
> within an event handler, better to put them in a separate thread.
> Unfortunately this is a lesson that Microsoft's programmers don't
> appear to have learned yet!

I knew I will have to learn threads some day...
Are they hard ?
Can you give me some good and simple tutorials ? (I found some, but
they look scary)


> Alan G.



-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to use threads ?

2005-03-01 Thread Mark Kels
Can anyone give me a very simple example on thread programming ?
I looked at some tutorials but they don't really make sense...


Thanks in advance
-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to use threads ?

2005-03-02 Thread Mark Kels
On Tue, 1 Mar 2005 12:25:37 -0800 (PST), Shitiz Bansal
<[EMAIL PROTECTED]> wrote:
> 
> Here is a simple program
> 
> class abc(threading.Thread):
> def __init__(self):
> threading.Thread.__init__(self)
> self.x=1 etc. etc.
> self.cont_flag=1
> def run(self):
> while self.cont_flag:
>print self.x
>(you can set the self.cont_falg to zero
> whenever you wish to end the loop(and
> hence
> the thread., either
> here, or even from outside the thread.
> of course, it isnt necessary that your
> thread is a loop, it can be a finite
> function.)
> 
Thanks alot !!
I think I got it ths time.
The only problem is that when I try to do it my thread doesnt closes.
When does a thread closes ?

Thanks again. 

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to use threads ?

2005-03-03 Thread Mark Kels
On Wed, 2 Mar 2005 14:48:11 -0800 (PST), Shitiz Bansal
<[EMAIL PROTECTED]> wrote:
> The thread finishes when:
> 1.The run method finishes.
> 2.In case of the loop- you may -
> 
> >>> import threading
> >>> class abc(threading.Thread):
> def __init__(self):
> threading.Thread.__init__(self)
> self.cont_flag=1
> def run(self):
> while self.cont_flag:
> pass
> 
> >>> abcd=abc()
> >>> abcd
> 
> >>> abcd.start()
> >>> abcd
> 
> >>> abcd.cont_flag=0
> >>> abcd
> 

But for some reason it keeps working after its job is done in my app...
Here is the class:
(the app itself got some Entrys to get the input and a Button to start
the go() and stop() functions)

class scan(threading.Thread):
def _init_(self):
threading.thread._init_(self)
def scanner(self):
self.open_counter=0
self.flag='scan'
try:
host=host_e.get()
start_port=int(start_port_e.get())
end_port=int(end_port_e.get())
except ValueError:
tkMessageBox.showerror("Bad input","You must enter a vaild
host IP and port numbers.")
pass
else:
start.config(text="Stop",command=stop)
root.update()
result.insert(END,"Scanning "+str(host)+"...\n\n")
root.update()
while start_port<=end_port and self.flag=='scan':
self.sk=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sk.settimeout(0.01)
try:
  self.sk.connect((host,start_port))
except:
pass
else:
result.insert(END,str(start_port)+"\n")
root.update()
self.open_counter=self.open_counter+1
self.sk.close()
start_port=start_port+1
if self.flag=='scan':
result.insert(END,"\nDone !!\nFound
"+str(self.open_counter)+" opened ports")
root.update()
start.config(text="Scan",command=go)
root.update()
elif self.flag=='stop':
result.insert(END,"\n Scan stopped.")
start.config(text="Scan",command=go)
root.update()
app=scan()

Here is the go() function, which starts the thread:
def go():
app.start()
app.scanner()

And here is the stop() function that should end the thread and the
scan (and for some reason it ends only the scan loop):
def stop():
app.flag='stop'

You got any Idea whats wrong here ??

Thanks allot.
-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to use threads ?

2005-03-03 Thread Mark Kels
On Thu, 3 Mar 2005 14:31:55 +, Gwyn Evans <[EMAIL PROTECTED]> wrote:
> Hi,
>   The one thing that stands out is that when you subclass Thread as
> you do, you need to override the 'run' method, which will get called
> as a result of you calling 'start()'.
>   You're calling start(), but you've not got a run method, so the new
> thread doesn't call your code.  Instead you've got your own call to
> 'scanner()', that is running under the main thread.
> 
>   Rename 'scanner()' to 'run()', remove the call to 'scanner()' and
> see how that looks.

It looks the same, but with 1 line less...
The thread is still working after the loop is done, so after I stop
the scan I cant start another one.


-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to use threads ?

2005-03-03 Thread Mark Kels
On Thu, 3 Mar 2005 16:36:05 +, Gwyn Evans <[EMAIL PROTECTED]> wrote:
>   How are you trying to start another scan?  You'd have to create a
> new instance, you can't just call app.start() again.

Thanks allot !!
This is exactly what I was doing wrong.
Now it works :)

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Whats so good about OOP ?

2005-03-12 Thread Mark Kels
Hi list !
I want to know whats so great in OOP...
I have learned some of it, but I don't understand why everybody like
it so much...
Can anyone give me an example for a task that could be done only with
OOP or will be much simpler to do with it ?

Thanks in advance.

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Unreadable code explanation

2005-03-17 Thread Mark Kels
Hi list. 
I have downloaded some code from useless python that was writen buy a
guy named Sammy Mannaert. The code should show that python can be
unreadable, and it really is...
Can anyone explain to me how does this thing works ??
Here is the code (it prints "python readable ?"):
f=lambda x="8<:477\02092020162\020\037",y="01001000110100101":reduce(lambda
x,y:x+y,map(lambda y,x:chr(ord(y)*2+x),x,map(int,y)));print f();
(it all should be in one line)

Hope you can help :)
Thanks in advance.
-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python and ICQ??

2005-04-28 Thread Mark Kels
Hi list !
Does anyone here knows of a way to connect to ICQ with Python?

Thanks in advance.
-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python and ICQ??

2005-04-29 Thread Mark Kels
On 4/29/05, tanja pislar <[EMAIL PROTECTED]> wrote:
> try pyICQ-t, (it's an ICQ transport for jabber implemented in python)
> http://pyicq-t.blathersource.org/
> 
> regards,
> tanja

Thanks, but its to complicated for my needs. What I need is a simple
module that will allow me to connect to ICQ and send some messages to
users.

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Program to lock folders under win32

2005-05-26 Thread Mark Kels
Hi list.

I want to make a program to lock folders (so the user can only access
them if he knows the password) under win32, the only problem is that I
have no idea how to start or what to do. Do you guys have any ideas of
how to do it?

Thanks!


-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Virtual keyboard

2005-07-14 Thread Mark Kels
Hi list.
I want to make a virtual keyboard with Tkinter.
 Can I have some pointers on how to do it?
 Will it be hard (it doesn't look so hard...)? 

Thanks.
-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Virtual keyboard

2005-07-14 Thread Mark Kels
On 7/14/05, luke <[EMAIL PROTECTED]> wrote:

> I don't think it will be hard, but it depends what you want to pass
> keypresses to.
> If you want your virtual keyboard to type in any program you will have to
> deal with
> focus issues and it seems to me that would be hard, if possible.
> but if you just want it to type into its own (tkinter) text box, you're
> right, that shouldn't be too hard.

I do want it to type in any entry (websites, notepad and other
programs), and thats what makes it harder. I dont think that shouldnt
be too hard as well, but I have no idea how to do it.

Anyway, thanks for the quick replay.

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Virtual keyboard

2005-07-14 Thread Mark Kels
On 7/14/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> You would need some way of getting a handle for the widget you want to type
> into.. I don't know how to do this (or even if you can), but I wonder if you
> might have more luck if you used PythonWin and the Microsoft factory classes 
> to
> build your GUI?

That looks too hard...
If there isnt an easyer solution I'll just find another project to work on :-)

Thanks anyway,

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor