[Tutor] Get user input in wxpython

2005-08-06 Thread _ Dan _
Hi:
I'm new to python and wxpython, and I'm trying to make
a program to send mail. I'm using what follows:
class MyFrame1(wx.Frame):
def __init__(self, *args, **kwds):
...
self.message = wx.TextCtrl(self.panel_1, -1, "")
self.button_1 = wx.Button(self.panel_1, -1, "SEND
Mail")
...
# And then:
wx.EVT_BUTTON(self,self.button_1.GetId(),
self.Mail)

# The Mail method is:
def Mail(self,event):
   self.from = "[EMAIL PROTECTED]"
   self.host = "localhost"
   self.to = "[EMAIL PROTECTED]"

   self.body = self.message

   server = smtplib.SMTP(self.host)
   server.sendmail(self.from, [self.to],
self.body)
   server.quit()

But when pressing the Send Mail button I only get:
TypeError: len() of unsized object

Anybody knows what I'm doing wrong? Maybe I'm not
getting the user input, or just dont know how to use
that input in the Mail method...

Because if I use:
def Mail(self,event):
   self.from = "[EMAIL PROTECTED]"
   self.host = "localhost"
   self.to = "[EMAIL PROTECTED]"

   self.body = "any message" #as string everything
works fine.

   server = smtplib.SMTP(self.host)
   server.sendmail(self.from, [self.to], self.body)
   server.quit()

Thanks in advanced.
Daniel Queirolo.





__ 
Renovamos el Correo Yahoo! 
Nuevos servicios, más seguridad 
http://correo.yahoo.es
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Instances

2005-08-06 Thread Greg Kellogg
Lets say i do:

>>> i = f.get_movie('0092411')

No I know the i holds an instance:

>>> i


How can I find out the value of all the data this instance has?  I can
do a dir(i)

['_Movie__modFunct', '_Movie__movie_data', '_Movie__namesRefs',
'_Movie__titlesRefs', '__cmp__', '__contains__', '__deepcopy__',
'__delitem__', '__doc__', '__getitem__', '__init__', '__module__',
'__nonzero__', '__setitem__', '__str__', 'accessSystem',
'add_to_current_info', 'append_item', 'clear', 'copy', 'currentRole',
'current_info', 'default_info', 'get', 'get_current_info',
'get_namesRefs', 'get_titlesRefs', 'has_current_info', 'has_key',
'isSameTitle', 'items', 'keys', 'keys_alias', 'movieID', 'myID',
'myTitle', 'notes', 'reset', 'set_current_info', 'set_data',
'set_item', 'set_mod_funct', 'set_title', 'summary',
'update_namesRefs', 'update_titlesRefs', 'values']

I know there is more info in there than this, is there a way to see
everything that 'i" without hunting and pecking?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Functional question

2005-08-06 Thread Kent Johnson
Bernard Lebel wrote:
> Thanks Kent.
> 
> I had tried the very same thing, but with a list instead of a tuple,
> and got an got this:
> 
> 
dMap[ ['allo','bonjour'] ] = 'salut'
> 
> Traceback (most recent call last):
>   File "", line 1, in ?
> TypeError: list objects are unhashable
> 
> It never crossed my mind that a tuple would do it.

That is one of the key differences between a list and a tuple - a tuple can be 
used as a dictionary key. Dictionary keys must be hashable, which in practice 
means they must be immutable. A tuple whose members are also immutable works 
fine as a key.

Kent

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


Re: [Tutor] Get user input in wxpython

2005-08-06 Thread Kent Johnson
_ Dan _ wrote:
> Hi:
> I'm new to python and wxpython, and I'm trying to make
> a program to send mail. I'm using what follows:
> class MyFrame1(wx.Frame):
> def __init__(self, *args, **kwds):
> ...
> self.message = wx.TextCtrl(self.panel_1, -1, "")
> self.button_1 = wx.Button(self.panel_1, -1, "SEND
> Mail")
> ...
> # And then:
> wx.EVT_BUTTON(self,self.button_1.GetId(),
> self.Mail)
> 
> # The Mail method is:
> def Mail(self,event):
>self.from = "[EMAIL PROTECTED]"
>self.host = "localhost"
>self.to = "[EMAIL PROTECTED]"
> 
>self.body = self.message

This line is the problem as you might have guessed :-)
self.message is an instance of wx.TextCtrl, not a text string. Try
  self.body = self.message.GetValue()

Kent

PS There doesn't seem to be any need to make from, host, to and body be 
attributes of self; you could use plain local variables here.

> 
>server = smtplib.SMTP(self.host)
>server.sendmail(self.from, [self.to],
> self.body)
>server.quit()
> 
> But when pressing the Send Mail button I only get:
> TypeError: len() of unsized object
> 
> Anybody knows what I'm doing wrong? Maybe I'm not
> getting the user input, or just dont know how to use
> that input in the Mail method...
> 
> Because if I use:
> def Mail(self,event):
>self.from = "[EMAIL PROTECTED]"
>self.host = "localhost"
>self.to = "[EMAIL PROTECTED]"
> 
>self.body = "any message" #as string everything
> works fine.
> 
>server = smtplib.SMTP(self.host)
>server.sendmail(self.from, [self.to], self.body)
>server.quit()
> 
> Thanks in advanced.
> Daniel Queirolo.
> 
> 
> 
> 
>   
> __ 
> Renovamos el Correo Yahoo! 
> Nuevos servicios, más seguridad 
> http://correo.yahoo.es
> ___
> 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] Instances

2005-08-06 Thread Kent Johnson
Greg Kellogg wrote:
> Lets say i do:
> 
> 
i = f.get_movie('0092411')
> 
> 
> No I know the i holds an instance:
> 
> 
i
> 
> 
> 
> How can I find out the value of all the data this instance has?  I can
> do a dir(i)
... 
> I know there is more info in there than this, is there a way to see
> everything that 'i" without hunting and pecking?

You appear to be using imdbpy. The file docs/README.package gives some tips on 
how to use Movie objects. A Movie behaves like a dictionary; the data is stored 
as key/value pairs. To see all the data in a movie you could use
for key in movie.keys():
  print key, '=', movie[key]

(Normally I would use 
  for key, value in movie.items():
but there is a bug in movie.items() and this doesn't work.

Also Movie has a summary() method that returns a string describing the movie, 
so you could use
print movie.summary()

Here is an example based on info from README.packages:

 >>> from imdb import IMDb
 >>> i = IMDb()
 >>> movie_list = i.search_movie('beautiful girls')
 >>> first_match = movie_list[0]
 >>> print first_match.summary()
Movie
=
Title: Beautiful Girls (1996)

 >>> i.update(first_match)
 >>> print first_match.summary()
Movie
=
Title: Beautiful Girls (1996)
Genres: Drama, Comedy, Romance.
Director: Ted Demme.
Writer: Scott Rosenberg.
Cast: Matt Dillon (Tommy 'Birdman' Rowland), Noah Emmerich (Michael 'Mo' 
Morris), Annabeth Gish (Tracy Stover), Lauren Holly (Darian Smalls), Timothy
Hutton (Willie Conway).
Runtime: 112.
Country: USA.
Language: English.
Rating: 7.2
Votes: 7754
Plot: Beautiful Girls is about a group of small-town friends joining up for 
their first high school reunion. They find themselves evaluating their liv
es and their relationships. It's about growing up and facing reality.
 >>> i.update(first_match, 'all')
 >>> print first_match.summary()
 >>> for key, value in first_match.items():
 ...   print key, '=', value
 ...
Traceback (most recent call last):
  File "", line 1, in ?
  File "imdb\Movie.py", line 226, in items
return [(k, self.__movie_data[k]) for k in self.keys()]
KeyError: 'canonical title'
 >>> for k in first_match.keys():
 ...   print k, '=', first_match[k]
 ...
rating = 7.2
composer = [, , , , , ]
producer = [, , , , , , ]
film length (metres) = ['3145 m']
locations = ['Hopkins, Minnesota, USA (Reunion Location)']
runtimes = ['112']
... LOTS more info about the movie!

Kent

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


Re: [Tutor] Get user input in wxpython

2005-08-06 Thread danf_1979
Just if someone is trying something similar... I did it! Thanks Ismael for your 
info!
...
self.label_1 = wx.StaticText(self.panel_1, -1, "TO:")
self.label_2 = wx.StaticText(self.panel_1, -1, "FROM:")
self.label_3 = wx.StaticText(self.panel_1, -1, "SUBJECT")
self.label_4 = wx.StaticText(self.panel_1, -1, "MESSAGE:")
self.text_ctrl_hacia = wx.TextCtrl(self.panel_1, -1, "")
self.text_ctrl_tumail = wx.TextCtrl(self.panel_1, -1, "")
self.text_ctrl_asunto = wx.TextCtrl(self.panel_1, -1, "")
self.text_ctrl_mensaje = wx.TextCtrl(self.panel_1, -1, "", 
style=wx.TE_MULTILINE)
self.button_sendmail = wx.Button(self.panel_1, -1, "SEND MAIL")
...
wx.EVT_BUTTON(self,self.button_sendmail.GetId(), self.Mail)
...
def Mail(self,event):
print self.text_ctrl_hacia.GetValue()
self.hacia = self.text_ctrl_hacia.GetValue()
self.desde = self.text_ctrl_tumail.GetValue()
self.asunto = self.text_ctrl_asunto.GetValue()
self.mensaje = self.text_ctrl_mensaje.GetValue()
self.body = string.join(("From: %s" % self.desde,"To: %s" % 
self.hacia,"Subject: %s" % self.asunto,"",self.mensaje), "\r\n")
self.host = "localhost"
server = smtplib.SMTP(self.host)
server.sendmail(self.desde, [self.hacia], self.body)
server.quit()  

So I'm sending this mail from my program :)

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


[Tutor] Lots of variables

2005-08-06 Thread Øyvind
Hello.

I am trying to write a gui that has a lot of checkboxes. It is over 200
different ones. I use a for statement to generate:

ver = 200
for i in ['Car','House','Boat','Plane']:
self.fra26_che01p = Checkbutton (self.fra26)
self.fra26_che01p.place(in_=self.fra26,x=5,y=ver)
self.fra26_che01p.configure(text=i)
self.getattr(self,i)1 = IntVar()
self.fra26_che01p.configure(variable=getattr(self,i))
self.fra26_che01v = Checkbutton (self.fra26)
self.fra26_che01v.place(in_=self.fra26,x=70,y=ver)
#self.fra26_che01v.configure(text="1p")
self.getattr(self,i)2 = IntVar()
self.fra26_che01v.configure(variable=getattr(self,i))
ver = ver + 17

The variable does not work for obvious reasons. I need to change variable
for each new creation. If I had made the variables manually, I would have
written (variable=self.car1)/(variable=self.car2) and so forth. Is there
some way I can make lots of variables without declaring them up front?

Thanks in advance

-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


Re: [Tutor] Lots of variables

2005-08-06 Thread Kent Johnson
Øyvind wrote:
> Hello.
> 
> I am trying to write a gui that has a lot of checkboxes. It is over 200
> different ones. I use a for statement to generate:
> 
> ver = 200
> for i in ['Car','House','Boat','Plane']:
> self.fra26_che01p = Checkbutton (self.fra26)
> self.fra26_che01p.place(in_=self.fra26,x=5,y=ver)
> self.fra26_che01p.configure(text=i)
> self.getattr(self,i)1 = IntVar()
> self.fra26_che01p.configure(variable=getattr(self,i))
> self.fra26_che01v = Checkbutton (self.fra26)
> self.fra26_che01v.place(in_=self.fra26,x=70,y=ver)
> #self.fra26_che01v.configure(text="1p")
> self.getattr(self,i)2 = IntVar()
> self.fra26_che01v.configure(variable=getattr(self,i))
> ver = ver + 17
> 
> The variable does not work for obvious reasons. I need to change variable
> for each new creation. If I had made the variables manually, I would have
> written (variable=self.car1)/(variable=self.car2) and so forth. Is there
> some way I can make lots of variables without declaring them up front?

The usual way to do this is to keep a dictionary mapping the 'variable' names 
to the values, or maybe just a list of the values. Since you access the 
checkbuttons through IntVars you may not need to keep a reference to the button 
itself. So maybe something like this:

self.vars = {}
ver = 200
for i in ['Car','House','Boat','Plane']:
check1 = Checkbutton (self.fra26)
check1.place(in_=self.fra26,x=5,y=ver)
check1.configure(text=i)
var1 = self.vars[i+'1'] = IntVar()
check1 .configure(variable=var1)
check2 = Checkbutton (self.fra26)
check2.place(in_=self.fra26,x=70,y=ver)
var2 = self.vars[i+'2'] = IntVar()
check2.configure(variable=var2)
ver = ver + 17

Now self.vars will have entries for 'Car1', 'Car2', etc. whose values will be 
the corresponding IntVars.

Kent

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


Re: [Tutor] IP Address from Python module?

2005-08-06 Thread Joseph Quigley
Thanks.. I hoped python had something like that!!!

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