named pipe input

2005-09-01 Thread max(01)*
hi there.

i have some problems understanding following behaviour.

consider this:

...
$ cat file_input_3.pl
#!/usr/bin/perl

open MIAPIPE, una_pipe;

while ($riga = MIAPIPE)
   {
 print STDOUT ($riga);
   }

$ cat file_input_3.py
#!/usr/bin/python

import sys

MIAPIPE = open(una_pipe, r)

for riga in MIAPIPE:
   print riga,
...

where una_pipe is a named pipe (created with mkfifo).

when i run this on console #1:

...
$ ./file_input_3.pl
...

and this un console #2:

...
$ cat  una_pipe
aaa
bbb
ccc
...

then each line typed in console #2 appears on console #1 as soon as the 
line is terminated (hit return).

BUT if i try to do the same with the python code, something different 
happens: i have to type ALL the lines on console #2 and complete the cat 
command (ctrl-d) before seeing the lines echoed on console #1.

i tried the -u flag but doesnt seem to work.

any help?

bye
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: named pipe input

2005-09-01 Thread max(01)*
Eric Nieuwland wrote:
 max(01)* wrote:
 
 $ cat file_input_3.py
 #!/usr/bin/python

 import sys

 MIAPIPE = open(una_pipe, r)

 for riga in MIAPIPE:
print riga,
 ...
 [...]
 BUT if i try to do the same with the python code, something different
 happens: i have to type ALL the lines on console #2 and complete the cat
 command (ctrl-d) before seeing the lines echoed on console #1.
 
 
 You could try:
 
 for riga in MIAPIPE:
 print riga # NO COMMA!
 sys.stdout.flush()
 

doesn't work! :-(
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pipes like perl

2005-08-25 Thread max(01)*
many thanks to all the fellows who cared to answer!

bye

max
-- 
http://mail.python.org/mailman/listinfo/python-list


pipes like perl

2005-08-23 Thread max(01)*
hi.

in perl i can do this:

...
if (open (MYPIPE, *some_system_command* |))
   {
 ...
 *do_something*
 ...
 while ($answer = MYPIPE)
   {
 print $answer;
   }
 ...
 *do_something_more*
 ...
   }
else
   {
 ...
 *do_something_else*
 ...
   }
...

but i do not know how to do it in python, because if *command*: gives 
syntax error.

moreover, if i use

...
import os
...
try:
   MYPIPE = os.popen(*some_system_command*, r)
   ...
   *do_something*
   ...
   for answer in MYPIPE:
 print answer,
   MYPIPE.close()
   ...
   *do_something_more*
   ...
except:
   ...
   *do_something_else*
   ...
...

it doesn't work, since *do_something* and *do_something_more* are 
always executed (it seems like

MYPIPE = os.popen(*some_system_command*, r)

does not raise any exception even if *some_system_command* does not 
exist/work...

any help?

thanks a lot

max
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pipes like perl

2005-08-23 Thread max(01)*
bruno modulix wrote:
 max(01)* wrote:
 
hi.
 
 
 (snip)
 
 
it doesn't work, since *do_something* and *do_something_more* are
always executed (it seems like

MYPIPE = os.popen(*some_system_command*, r)

does not raise any exception even if *some_system_command* does not
exist/work...

any help?
 
 
 http://www.python.org/doc/2.4.1/lib/os-newstreams.html#os-newstreams
 
 The exit status of the command (encoded in the format specified for
 wait()) is available as the return value of the close() method of the
 file object, except that when the exit status is zero (termination
 without errors), None is returned.
 

but i need to check the success/failure of the external command *before* 
closing the file!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pipes like perl

2005-08-23 Thread max(01)*
infidel wrote:
 Here's one technique I use to run an external command in a particular
 module:
 
 stdin, stdout, stderr = os.popen3(cmd)
 stdin.close()
 results = stdout.readlines()
 stdout.close()
 errors = stderr.readlines()
 stderr.close()
 if errors:
 raise Exception(''.join(errors))
 
 Maybe this will get you going in a better direction?
 

yeah thanks!

i translated as:


import os

CMD_STDIN, CMD_STDOUT, CMD_STDERR = \
   os.popen3(*some_system_command*, r)
if not CMD_STDERR.readlines():
   ...
   *do_something*
   ...
   for answer in CMD_STDOUT:
 print answer,
   ...
   *do_something_more*
   ...
else:
   ...
   *do_something_else*
   ...
CMD_STDIN.close()
CMD_STDOUT.close()
CMD_STDERR.close()


bye

max

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pipes like perl

2005-08-23 Thread max(01)*
max(01)* wrote:
 infidel wrote:
 
 Here's one technique I use to run an external command in a particular
 module:

 stdin, stdout, stderr = os.popen3(cmd)
 stdin.close()
 results = stdout.readlines()
 stdout.close()
 errors = stderr.readlines()
 stderr.close()
 if errors:
 raise Exception(''.join(errors))

 Maybe this will get you going in a better direction?

 
 yeah thanks!
 
 i translated as:
 
 .
 import os
 .
 CMD_STDIN, CMD_STDOUT, CMD_STDERR = \
   os.popen3(*some_system_command*, r)
 if not CMD_STDERR.readlines():
   ...
   *do_something*
   ...
   for answer in CMD_STDOUT:
 print answer,
   ...
   *do_something_more*
   ...
 else:
   ...
   *do_something_else*
   ...
 CMD_STDIN.close()
 CMD_STDOUT.close()
 CMD_STDERR.close()
 .

but... i see it doesn't work for some commands, like man python (it 
gets stuck on the if line)...

how come?

-- 
http://mail.python.org/mailman/listinfo/python-list


regular expressions use

2005-08-22 Thread max(01)*
hi everyone.

i would like to do some uri-decoding, which means to translate patterns 
like %2b/dhg-%3b %7E into +/dhg-; ~: in practice, if a sequence like 
%2b is found, it should be translated into one character whose hex 
ascii code is 2b.

i did this:

...
import re
import sys

modello = re.compile(%([0-9a-f][0-9a-f]), re.IGNORECASE)

def funzione(corrispondenza):
   return chr(eval('0x' + corrispondenza.group(1)))

for riga in sys.stdin:
   riga = modello.sub(funzione, riga)
   sys.stdout.write(riga)
...

please comment it. can it be made easily or more compactly? i am a 
python regexp novice.

bye

max

ps: i was trying to pythonate this kind of perl code:

$riga =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/chr(hex($1))/ge;
-- 
http://mail.python.org/mailman/listinfo/python-list


stdin - stdout

2005-08-19 Thread max(01)*
hi.

i was wondering, what's the simplest way to echo the standard input to 
the standard output, with no modification.

i came up with:

...
while True:
   try:
 raw_input()
   except EOFError:
 break
...

but i guess there must be a simpler way.

using bash i simply do 'cat', *sigh*!

bye

max

ps: in perl you ca do this:

...
while ($line = STDIN)
   {
 print STDOUT ($line);
   }
...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and glut

2005-05-07 Thread max(01)*
Lonnie Princehouse wrote:

 DRI not working could also be a permissions issue; check to see if it
 works as root.

that's it! :-)

now, how can i make it work as joe user?

bye

max
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and glut

2005-05-07 Thread max(01)*
Lonnie Princehouse wrote:
 Welcome to the exciting world of trying to make graphics work on Linux
 =)
 
 DRI is direct rendering.
[...]
 DRI not working could also be a permissions issue; check to see if it
 works as root.

that's it! :-)

now, how can i make it work as joe user?

bye

max

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and glut

2005-05-05 Thread max(01)*
Mike Meyer wrote:
 max(01)* [EMAIL PROTECTED] writes:
 
 
$ python GLE.py
freeglut (GLE.py): OpenGL GLX extension not supported by display ':0.0'

what's up? what's missing?
 
 
 The GLX extension to your X server.
 
 
i use a standard debian installation.
 
 
 I don't know which X debian uses, and it may have changed over time,

mine uses XFree86, Version 4.3.0.1 (from the man page)

 so you'll want to specify the name of the distribution.

woody.

thanks

max
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and glut

2005-05-05 Thread max(01)*
Lonnie Princehouse wrote:
 See if you can run `glxgears`, and read the output of `glxinfo`.

$ glxgears
Xlib:  extension GLX missing on display :0.0.
Error: couldn't get an RGB, Double-buffered visual
$ glxinfo
name of display: :0.0
Xlib:  extension GLX missing on display :0.0.
Xlib:  extension GLX missing on display :0.0.
Xlib:  extension GLX missing on display :0.0.
Error: couldn't find RGB GLX visual

visual  x  bf lv rg d st colorbuffer ax dp st accumbuffer  ms  cav
  id dep cl sp sz l  ci b ro  r  g  b  a bf th cl  r  g  b  a ns b eat
--
Xlib:  extension GLX missing on display :0.0.
Xlib:  extension GLX missing on display :0.0.
0x21 16 tc  1  0  0 c  .  .  0  0  0  0  0  0  0  0  0  0  0  0 0 None



now what?

bye

max
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and glut

2005-05-05 Thread max(01)*
Lonnie Princehouse wrote:
 See if you can run `glxgears`, and read the output of `glxinfo`.   If
 neither of those work, you will probably have better luck on a debian
 or XFree86/xorg forum than on c.l.py
 

your hints were helpful anyway. thanks!

ok, i uncommented the line:

Load   glx

in my /etc/X11/XF86Config file.

now glxgears seems to work...

except for the following message:

Xlib:  extension XFree86-DRI missing on display :0.0.

can you give some more help? (sorry again for being offtopic)

max
-- 
http://mail.python.org/mailman/listinfo/python-list


python and glut

2005-05-04 Thread max(01)*
hi there.

i installed python2.3-opengl, then i tried one of those demos:



#!/usr/bin/python2.3

# This is statement is required by the build system to query build info
if __name__ == '__build__':
 raise Exception

import sys
from OpenGL.GL import *
from OpenGL.GLE import *
from OpenGL.GLUT import *


class GLE_demo:

 def __init__(self):
 # initial mouse position
 self.lastx = 121
 self.lasty = 121

 # set the display mode and create the window
 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
 glutCreateWindow(GLE demo)

 # setup the callbacks
 glutDisplayFunc(self.on_display)
 glutMotionFunc(self.on_motion)
 glutReshapeFunc(self.on_reshape)

 #
 glClearDepth(1.0)
 glEnable(GL_DEPTH_TEST)
 glClearColor(0.0, 0.0, 0.0, 0.0)
 glShadeModel(GL_SMOOTH)

 glMatrixMode(GL_MODELVIEW)
 # initialize lighting */
 glLightfv(GL_LIGHT0, GL_POSITION,  (40.0, 40, 100.0, 0.0))
 glLightfv(GL_LIGHT0, GL_DIFFUSE, (0.99, 0.99, 0.99, 1.0))
 glEnable(GL_LIGHT0)
 glLightfv(GL_LIGHT1, GL_POSITION, (-40.0, 40, 100.0, 0.0))
 glLightfv(GL_LIGHT1, GL_DIFFUSE, (0.99, 0.99, 0.99, 1.0))
 glEnable(GL_LIGHT1)
 glEnable(GL_LIGHTING)
 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE)
 glEnable(GL_COLOR_MATERIAL)


 def on_motion(self, x, y):
 # store the mouse coordinate
 self.lastx = x
 self.lasty = y
 # redisplay
 glutPostRedisplay()


 def on_reshape(self, width, height):
 # setup the viewport
 glViewport(0, 0, width, height)
 # setup the projection matrix
 glMatrixMode(GL_PROJECTION)
 glLoadIdentity()
 # calculate left/right and top/bottom clipping planes 
based the
smallest square viewport
 a = 9.0/min(width, height)
 clipping_planes = (a*width, a*height)
 # setup the projection
 glFrustum(-clipping_planes[0], clipping_planes[0], 
-clipping_pla
nes[1], clipping_planes[1], 50.0, 150.0)


 def on_display(self):
 # clear the buffer
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

 # Set up the model view matrix
 glMatrixMode(GL_MODELVIEW)
 glLoadIdentity()
 glTranslatef(0.0, 0.0, -80.0)
 glRotatef(self.lastx, 0.0, 1.0, 0.0)
 glRotatef(self.lasty, 1.0, 0.0, 0.0)

 # a nice pale lime green
 glColor3f(0.6, 0.8, 0.3)

 # set the join styles for GLE
 gleSetJoinStyle(TUBE_NORM_EDGE | TUBE_JN_ANGLE | 
TUBE_JN_CAP)
 gleHelicoid(1.0, 6.0, 2.0, -3.0, 4.0, None, None, 0.0, 
1080.0)

 # swap the buffer
 glutSwapBuffers()



if __name__ == '__main__':
 # initialize GLUT
 glutInit(sys.argv)
 # create the demo window
 GLE_demo()
 # enter the event loop
 glutMainLoop ()



(sorry for some line breaks, some day i'll repair my newsreader)

but when i try to run it:

$ python GLE.py
freeglut (GLE.py): OpenGL GLX extension not supported by display ':0.0'

what's up? what's missing?

i use a standard debian installation.

thanks for your attention

bye

max
-- 
http://mail.python.org/mailman/listinfo/python-list


domain specific UI languages

2005-04-13 Thread max(01)*
hi.
in a previous thread, mr lundh talks about the possibility to create 
domain specific UI languages using tkinter.

can he (or anyone else who pleases) explain what they are? give some 
examples (simple is better)?

bye
macs
--
http://mail.python.org/mailman/listinfo/python-list


Re: very simple tkinter demo program

2005-04-10 Thread max(01)*
Samantha wrote:
I can not get it to run.
S
sorry about that. baybe it is a conflict between tabstop width in my 
editor and in my newsreader.

i substituted tabs with spaces and i hope now you can run it.
bye
macs
cuthere
from Tkinter import *
class MiaApp:
  def __init__(self, genitore):
self.MioGenitore = genitore
fonte = (Helvetica, 12)
self.campi = [Cognome, Nome , Data di nascita]
quadro_grande = Frame(genitore)
quadro_grande.pack(expand = YES, fill = BOTH)
quadro_menu = Frame(quadro_grande)
quadro_menu.configure(
  bd = 1,
  relief = RAISED
  )
quadro_menu.pack(side = TOP, fill = X)
pm_file = Menubutton(quadro_menu)
pm_file.configure(text = File)
pm_file.pack(side = LEFT)
m_file = Menu(pm_file)
pm_file.configure(menu = m_file)
m_file.configure(tearoff = NO)
m_file.add_command(
  label = Scrivi,
  command = self.premuto_scrivi
  )
m_file.add_command(
  label = Leggi,
  command = self.premuto_leggi
  )
m_file.add_separator()
m_file.add_command(
  label = Chiudi,
  command = genitore.destroy
  )
pm_mod = Menubutton(quadro_menu)
pm_mod.configure(text = Modifica)
pm_mod.pack(side = LEFT)
pm_aiuto = Menubutton(quadro_menu)
pm_aiuto.configure(text = ?)
pm_aiuto.pack(side = RIGHT)
msg = Label(quadro_grande)
msg.configure(
  font = fonte,
  relief = RIDGE,
  wraplength = 10c,
  justify = LEFT,
  text = uQuesto \u00E8 un programma in Python \
che trae ispirazione da un analogo lavoro del collega \
G. Renda. Il programma originale era scritto \
in linguaggio Java, e sfruttava le librerie JFC \
(\u00ABJava Foundation Class\u00BB, dette anche \
\u00ABSwing\u00BB); questo invece usa le librerie Tk, \
mediante il modulo Tkinter.
  )
msg.pack(
  side = TOP,
  padx = 2m,
  pady = 2m
  )
quadro_pulsanti = Frame(quadro_grande)
quadro_pulsanti.pack(
  side = BOTTOM,
  fill = X,
  padx = 2m,
  pady = 2m
  )
scrivi = Button(quadro_pulsanti)
scrivi.configure(
  text = Scrivi,
  command = self.premuto_scrivi
  )
scrivi.pack(side = LEFT, expand = YES)
leggi = Button(quadro_pulsanti)
leggi.configure(text = Leggi, command = self.premuto_leggi)
leggi.pack(side = LEFT, expand = YES)
chiudi = Button(quadro_pulsanti)
chiudi.configure(text = Chiudi, command = genitore.destroy)
chiudi.pack(side = LEFT, expand = YES)
  def premuto_scrivi(self):
InserimentoRecord()
  def premuto_leggi(self):
ConsultazioneRecord()
class InserimentoRecord(Toplevel):
  def __init__(self):
Toplevel.__init__(self)
self.titolo = Inserimento
self.wm_title(self.titolo)
quadro_grande = Frame(self)
quadro_grande.pack(expand = YES, fill = BOTH)
self.quadro_pulsanti = Frame(quadro_grande)
self.quadro_pulsanti.pack(
  side = BOTTOM,
  fill = X,
  padx = 2m,
  pady = 2m
  )
quadri_ing = []
self.n = len(miaApp.campi)
self.var = []
eti = []
larg_eti = max(map(len, miaApp.campi))
ing = []
for i in range(self.n):
  quadri_ing.append(None)
  self.var.append(None)
  ing.append(None)
  eti.append(None)
  quadri_ing[i] = Frame(quadro_grande)
  quadri_ing[i].pack(side = TOP, expand = YES, fill = BOTH)
  self.var[i] = StringVar()
  eti[i] = Label(quadri_ing[i])
  eti[i].configure(
text = miaApp.campi[i] + : ,
width = larg_eti,
anchor = E
)
  eti[i].pack(side = LEFT, pady = 5, padx = 10, fill = X)
  ing[i] = Entry(quadri_ing[i], textvariable = self.var[i])
  ing[i].pack(side = LEFT, pady = 5, padx = 10, fill = X)
self.salva = Button(self.quadro_pulsanti)
self.salva.configure(
  text = Salva,
  command = self.premuto_salva
  )
self.salva.pack(side = LEFT, expand = YES)
self.annulla = Button(self.quadro_pulsanti)
self.annulla.configure(
  text = Annulla,
  command = self.premuto_annulla
  )
self.annulla.pack(side = LEFT, expand = YES)
  def premuto_salva(self):
import tkFileDialog
import pickle
dati = []
for i in range(self.n):
  dati.append(None)
  dati[i] = self.var[i].get()
nomefile = tkFileDialog.asksaveasfilename(
  defaultextension = .ana,
  filetypes = [
(Record anagrafici, *.ana),
(Tutti i file, *)
]
  )
if nomefile:
  f = open(nomefile, w)
  pickle.dump(dati, f)
  f.close()
self.destroy()
  def premuto_annulla(self):
self.destroy()
class ConsultazioneRecord(Toplevel):
  def __init__(self):
import tkFileDialog
nomefile = tkFileDialog.askopenfilename(
  defaultextension = .ana,
  filetypes = [
(Record anagrafici, *.ana),
(Tutti i file, *)
]
  )
if nomefile:
  try:  ### Il metodo 'pickle.load' potrebbe generare una
### eccezione se 

visibility between modules

2005-04-09 Thread max(01)*
hi.
if i have a single program file, different class instances can share 
information in (at least) two fashions:

1. using instance variables:
class AClass:
  def __init__(self):
self.att_1 = 42
self.att_2 = Hello!
class AnotherClass:
  def __init__(self):
self.att_1 = anInstanceOfAClass.att_1
anInstanceOfAClass = AClass()
anInstanceOfAnotherClass = AnotherClass()
print anInstanceOfAnotherClass.att_1  ### This should print out 42
2. using globals:
class AClass:
  def __init__(self):
self.att_1 = 42
self.att_2 = Hello!
class AnotherClass:
  pass
aGlobalString = No way.
anInstanceOfAClass = AClass()
anInstanceOfAClass.att2 = aGlobalString
anInstanceOfAnotherClass = AnotherClass()
anInstanceOfAnotherClass.att_1 = aGlobalString
print anInstanceOfAClass.att2  ### This should output No way.
print anInstanceOfAnotherClass.att_1  ### And this too

i admit i prefer the fisrt way to do it. i have tried to make it work 
even if the main program and each class definition reside in different 
files, but i could not make it work:

[EMAIL PROTECTED]:/tmp$ cat AClass.py
class AClass:
  def __init__(self):
self.att_1 = 42
self.att_2 = Hello!
[EMAIL PROTECTED]:/tmp$ cat AnotherClass.py
class AnotherClass:
  def __init__(self):
self.att_1 = anInstanceOfAClass.att_1
[EMAIL PROTECTED]:/tmp$ cat Main.py
from AClass import *
from AnotherClass import *
anInstanceOfAClass = AClass()
anInstanceOfAnotherClass = AnotherClass()
print anInstanceOfAnotherClass.att_1  ### This should print out 42
[EMAIL PROTECTED]:/tmp$ python Main.py
Traceback (most recent call last):
  File Main.py, line 4, in ?
anInstanceOfAnotherClass = AnotherClass()
  File /tmp/AnotherClass.py, line 3, in __init__
self.att_1 = anInstanceOfAClass.att_1
NameError: global name 'anInstanceOfAClass' is not defined
[EMAIL PROTECTED]:/tmp$

any suggestion?
bye max
--
http://mail.python.org/mailman/listinfo/python-list


serialize a tkinter thing

2005-04-09 Thread max(01)*
hi.
i tried to serialize a list of StringVar's, but i got a pickle error.
this got me to thinking that tkinter objects are not picklable (in general).
would somebody confirm and/or give examples?
thanks
macs
--
http://mail.python.org/mailman/listinfo/python-list


very simple tkinter demo program

2005-04-09 Thread max(01)*
hello.
i wrote a very simple tkinter demo program that uses menus, buttons, 
labels, entries, frames and secondary toplevels.

it is a python version of a java program made by a colleague.
the user can create (Scrivi) a record with his second name, first name 
and date of birth, save (Salva) the record to a file or read in 
(Leggi) a previously created file. Annulla is to cancel. Chiudi is 
to close.

i also used try-except for checking for invalid files.
only one menu is real (File), the others are for future use.
i'd like to hear your suggestions and comments for improving it.
i recently learned tkiner from stephen ferg's website and reading the 
tk8.4 widget demo programs.

one thing i still cannot do is to make the primary window and the 
secondary aware of each other (so avoid that a second instance of a 
secondary window can be generated if an instance still exists, for example).

so, here it is folks:
---cut here---
from Tkinter import *
class MiaApp:
  def __init__(self, genitore):
self.MioGenitore = genitore
fonte = (Helvetica, 12)
self.campi = [Cognome, Nome , Data di nascita]
quadro_grande = Frame(genitore)
quadro_grande.pack(expand = YES, fill = BOTH)
quadro_menu = Frame(quadro_grande)
quadro_menu.configure(
  bd = 1,
  relief = RAISED
  )
quadro_menu.pack(side = TOP, fill = X)
pm_file = Menubutton(quadro_menu)
pm_file.configure(text = File)
pm_file.pack(side = LEFT)
m_file = Menu(pm_file)
pm_file.configure(menu = m_file)
m_file.configure(tearoff = NO)
m_file.add_command(
  label = Scrivi,
  command = self.premuto_scrivi
  )
m_file.add_command(
  label = Leggi,
  command = self.premuto_leggi
  )
m_file.add_separator()
m_file.add_command(
  label = Chiudi,
  command = genitore.destroy
  )
pm_mod = Menubutton(quadro_menu)
pm_mod.configure(text = Modifica)
pm_mod.pack(side = LEFT)
pm_aiuto = Menubutton(quadro_menu)
pm_aiuto.configure(text = ?)
pm_aiuto.pack(side = RIGHT)
msg = Label(quadro_grande)
msg.configure(
  font = fonte,
  relief = RIDGE,
  wraplength = 10c,
  justify = LEFT,
  text = uQuesto \u00E8 un programma in Python \
che trae ispirazione da un analogo lavoro del collega \
G. Renda. Il programma originale era scritto \
in linguaggio Java, e sfruttava le librerie JFC \
(\u00ABJava Foundation Class\u00BB, dette anche \
\u00ABSwing\u00BB); questo invece usa le librerie Tk, \
mediante il modulo Tkinter.
  )
msg.pack(
  side = TOP,
  padx = 2m,
  pady = 2m
  )
quadro_pulsanti = Frame(quadro_grande)
quadro_pulsanti.pack(
  side = BOTTOM,
  fill = X,
  padx = 2m,
  pady = 2m
  )
scrivi = Button(quadro_pulsanti)
scrivi.configure(
  text = Scrivi,
  command = self.premuto_scrivi
  )
scrivi.pack(side = LEFT, expand = YES)
leggi = Button(quadro_pulsanti)
leggi.configure(text = Leggi, command = self.premuto_leggi)
leggi.pack(side = LEFT, expand = YES)
chiudi = Button(quadro_pulsanti)
chiudi.configure(text = Chiudi, command = genitore.destroy)
chiudi.pack(side = LEFT, expand = YES)
  def premuto_scrivi(self):
InserimentoRecord()
  def premuto_leggi(self):
ConsultazioneRecord()
class InserimentoRecord(Toplevel):
  def __init__(self):
Toplevel.__init__(self)
self.titolo = Inserimento
self.wm_title(self.titolo)
quadro_grande = Frame(self)
quadro_grande.pack(expand = YES, fill = BOTH)
self.quadro_pulsanti = Frame(quadro_grande)
self.quadro_pulsanti.pack(
  side = BOTTOM,
  fill = X,
  padx = 2m,
  pady = 2m
  )
quadri_ing = []
self.n = len(miaApp.campi)
self.var = []
eti = []
larg_eti = max(map(len, miaApp.campi))
ing = []
for i in range(self.n):
  quadri_ing.append(None)
  self.var.append(None)
  ing.append(None)
  eti.append(None)
  quadri_ing[i] = Frame(quadro_grande)
  quadri_ing[i].pack(side = TOP, expand = YES, fill = BOTH)
  self.var[i] = StringVar()
  eti[i] = Label(quadri_ing[i])
  eti[i].configure(
text = miaApp.campi[i] + : ,
width = larg_eti,
anchor = E
)
  eti[i].pack(side = LEFT, pady = 5, padx = 10, fill = X)
  ing[i] = Entry(quadri_ing[i], textvariable = self.var[i])
  ing[i].pack(side = LEFT, pady = 5, padx = 10, fill = X)
self.salva = Button(self.quadro_pulsanti)
self.salva.configure(
  text = Salva,
  command = self.premuto_salva
  )
self.salva.pack(side = LEFT, expand = YES)
self.annulla = Button(self.quadro_pulsanti)
self.annulla.configure(
  text = Annulla,
  command = self.premuto_annulla
  )
self.annulla.pack(side = LEFT, expand = YES)
  def premuto_salva(self):
import tkFileDialog
import pickle
dati = []
for i in range(self.n):
  dati.append(None)
  dati[i] = self.var[i].get()
 

Re: redundant importr

2005-04-05 Thread max(01)*
Peter Hansen wrote:
max(01)* wrote:
Peter Hansen wrote:
No it doesn't.  I thought I was clear, but I can reword
it for you: the files are compiled *in-memory* and the
results are never written to disk.
  *if* they are compiled, where are they put, if the
corresponding *.py files are on a non-writeable directory?

They are not put anywhere.  

ok, maybe it is an implementation-dependent issue after all.

Not really.
consider this:
[snip]
-rw-r--r--1 max2 max2  307 2005-04-02 17:45 imported.pyc
see?

Yes, but you don't, yet. :-)
Obviously the .pyc file is being written, so my comments
above, out of context, is wrong.
oops!
Now please go put them back in context.  You asked what
would happen if the directory was not writable.  That's
the context in which to interpret my claims that the
bytecode (the *result* of the compilation) is not
written to disk.
I'll try one last time, before giving up in abject
failure and letting someone else take a stab at this:
the compilation will occur every time if a .pyc file
does not exist.  The interpreter will attempt to write
the results of the compilation process to disk in a
..pyc file to cache it for the next time, to avoid
having to recompile.  *If* this is not possible, then
no caching takes place, no .pyc file is written, and
the next time you run the code, the compilation step
will occur all over again (note: with the results being
held in memory only while the program runs, then
discarded).
Please tell me it's clear now. :-)
it's not clear. it's crystalline. :-)
thanks for your patience and help.
best regards
macs
--
http://mail.python.org/mailman/listinfo/python-list


Re: instance name

2005-04-05 Thread max(01)*
many many thanks to each and everyone who bothered to answer my op.
best regards
macs
--
http://mail.python.org/mailman/listinfo/python-list


Re: redundant imports

2005-04-05 Thread max(01)*
Mike Meyer wrote:
max(01)* [EMAIL PROTECTED] writes:

Peter Hansen wrote:
max(01)* wrote:

hi everybody.
suppose that code-1.py imports code-2.py and code-3.py (because it
uses names from both), and that code-2.py imports code-3.py.
if python were c, code-1.c should only *include* code-2.c, because
the latter in turns includes code-3.c.
inclusion of modules in c is a purely preprocessing textual matter
(compilation is deferred to after the fact), i guess, so that such
things are possible. import of modules in python is a different
beast, so the redundancy is (i think) necessary.
any comment/suggestion/idea?
You're mixed up about this whole idea.
that's why i am asking for advice here.
my concern was motivated by a (clumsy) attempt to understand the
difference of mechanism between the approach to modular programming in
a more traditional language (c) and python.

[Names changed to be valid python module names.]
I feel I ought to point out that you don't really *have* to import the
code_3.py in code_1.py. You can get to things code_3.py in code_1.py
as code_2.code_3.thing.
oh. it never occured to me. interesting i must say...
The semantic behavior of include in C is the same as from module
import * in python. Both cases add all the names in the included
namespace directly to the including namespace. This usage is
depreciated in Python, because it leads to problems figuring out where
a specific variable came from. 
so 'import module' is to be preferred, right?
In C, it creates a problem called name
space pollution. This is the case when a file1.c gets all the symbols
for some_header.h, even though it doesn't include/need those symbols,
because some header file1.c included needed a symbol from
some_header.h. This is especially galling if the pollution collides
with some_header2.h that file1.c actually needs.
 mike
thanks a lot, mike!
--
http://mail.python.org/mailman/listinfo/python-list


Re: redundant importr

2005-04-02 Thread max(01)*
Peter Hansen wrote:
max(01)* wrote:
Peter Hansen wrote:
Not required except for performance reasons.  If the .pyc
files don't exist, the .py files are recompiled and the
resulting bytecode is simply held in memory and not cached
and the next startup will recompile all over again.

but the other files *are* compiled, right? 

Yes, definitely.  I did say that.
so the initial question remains unanswered: 

No it doesn't.  I thought I was clear, but I can reword
it for you: the files are compiled *in-memory* and the
results are never written to disk.
  *if* they are compiled, where are they put, if the
corresponding *.py files are on a non-writeable directory?

They are not put anywhere.  Compilation is a process
by which the source is converted to executable bytecodes.
This says nothing about where either the source or the
compiled result resides.  The actual compilation works
on a long series of bytes in memory, and the result is
just another long series of bytes.  Nothing requires that
either of these things are even stored in a file.
ok, maybe it is an implementation-dependent issue after all.
i am working on a debian woody platform with the standard python2.3 package.
consider this:
[EMAIL PROTECTED]:~/tmp/import-enigma$ ll
total 8
-rw-r--r--1 max2 max2   36 2005-04-02 17:44 imported.py
-rw-r--r--1 max2 max2   33 2005-04-02 17:44 importer.py
[EMAIL PROTECTED]:~/tmp/import-enigma$ cat importer.py
import imported
imported.fun_1()
[EMAIL PROTECTED]:~/tmp/import-enigma$ cat imported.py
def fun_1():
  print I am fun_1()
[EMAIL PROTECTED]:~/tmp/import-enigma$ python importer.py
I am fun_1()
[EMAIL PROTECTED]:~/tmp/import-enigma$ ll
total 12
-rw-r--r--1 max2 max2   36 2005-04-02 17:44 imported.py
-rw-r--r--1 max2 max2  307 2005-04-02 17:45 imported.pyc
-rw-r--r--1 max2 max2   33 2005-04-02 17:44 importer.py
[EMAIL PROTECTED]:~/tmp/import-enigma$
see?
bye
macs
--
http://mail.python.org/mailman/listinfo/python-list


instance name

2005-04-02 Thread max(01)*
hi.
is there a way to define a class method which prints the instance name?
e.g.:
 class class_1:
...   def myName(self):
... what should i do here
...
 instance_1 = class_1()
 instance_1.myName()
'instance_1'

bye
macs
--
http://mail.python.org/mailman/listinfo/python-list


Re: instance name

2005-04-02 Thread max(01)*
Andrew Koenig wrote:
max(01)* [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]


is there a way to define a class method which prints the instance name?

The term the instance name is misleading, because it assumes, without 
saying so explicitly, that every instance has a unique name.

In fact, there is no reason that an instance needs to have a name at all, or 
that it should have only one.

You gave this example:
instance_1 = class_1()
instance_1.myName()
but what if I did this instead?
class_1().myName()
Or this?
instance_1 = class_1()
instance_2 = instance_1
instance_2.myName()

excellent points.
i'll get back with proper questions afterwards.
thanks
macs
--
http://mail.python.org/mailman/listinfo/python-list


Re: instance name

2005-04-02 Thread max(01)*
Irmen de Jong wrote:
max(01)* wrote:
hi.
is there a way to define a class method which prints the instance name?
e.g.:

class class_1:
...   def myName(self):
... what should i do here
...
instance_1 = class_1()
instance_1.myName()
'instance_1'
bye
macs

What should the following do, you think?

a=class_1()
b=a
b is a
True
b.myName()
print what
There is no such thing as the instance name.
(a and b both point to the same instance, in my example)
Also: why do you want this? It smells like you're
actually looking for the use of a dict to do your job.
right. it seems i need to dive deeper in the language spirit.
thanks a lot
bye
macs
--
http://mail.python.org/mailman/listinfo/python-list


Re: redundant imports

2005-04-01 Thread max(01)*
Peter Hansen wrote:
max(01)* wrote:
this leads me to another question. since *.pyc files are automatically 
created the first time an import statement in executed on a given 
module, i guess that if i ship a program with modules for use in a 
directory where the user has no write privileges then i must ship the 
*.pyc files along too. right?

Not required except for performance reasons.  If the .pyc
files don't exist, the .py files are recompiled and the
resulting bytecode is simply held in memory and not cached
and the next startup will recompile all over again.
Note also that the main file (the one invoke from the
command line) is never cached in a .pyc...
but the other files *are* compiled, right? so the initial question 
remains unanswered: *if* they are compiled, where are they put, if the 
corresponding *.py files are on a non-writeable directory?
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter destroy()

2005-04-01 Thread max(01)*
also the app seems to have too many variables and widgets defined as
self objects.  That isn't necessary unless they will be used outside
the method they were created in (which labels and buttons usually
aren't), so all you are doing is using up more memory than necessary.
you are right, and at the end of this post you will find a new version 
of my code which heeds to your suggestion.

but i think there are exceptions.
consider for example building a BitmapImage for successive use in a 
widget, such as:

self.immagine_1a = PhotoImage()
self.immagine_1a.configure(
  file = terra.gif
  )
self.e1 = Label(self.quadro_grande)
self.e1.configure(
  image = self.immagine_1a,
  bd = 1,
  relief = SUNKEN
  )
if we follow your advice we should do:
immagine_1a = PhotoImage()

instead, but it doesn't work. why?
And just a matter
of personal taste, but splitting up widget configuration over many
lines for me impedes readiblity and makes the code look like java or
c++ : surely not what we want?
i thought about it. i prefer not to have lines longer than the usual 80 
char display, since (in my opinion) this produces an even more 
unreadable code layout. but we are starting a holy war i think...

Also your three state
variables could be members of a list, so you don't have to have
separate constructors for each of them.
it's true. but the drawback is that you have to keep an explicit 
mappping between names and variables; and what's worst is that this 
mapping must be known by the function that displays the second windows, 
and this is against data hiding.

if you are so kind as to peek at the attached code, you'll see that i 
also have restructured that part as one class. i'd like to hear your 
opinion about that. (now the code for the second window in completely 
reusable, i guess)

Anyway here's a version of your app that makes use of a 'for' statement
to draw the labels and checkbuttons, so it's only half as long as your
original app.  It also does the right thing - the key pont you were
missing was to use a 'textvariable' argument in defining your label
widgets in the 2nd window.
... and to use eval()

massimo = len(max(self.testo)) + 2
better:   massimo = max(map(len, self.testo)) + 2

anyway, here it is. bye!

from Tkinter import *
class MiaApp:
  def __init__(self, genitore):
fonte = (Helvetica, 12)
quadro_grande = Frame(genitore)
quadro_grande.pack(expand = YES, fill = BOTH)
msg = Label(quadro_grande)
msg.configure(
  font = fonte,
  wraplength = 10c,
  justify = LEFT,
  text = uSono qui sotto presentati tre pulsanti a spunta. \
Premendo un pulsante, se ne varia lo stato di selezione e si \
imposta una variabile a un valore che indica lo stato del \
pulsante stesso. Premendo il pulsante \u00ABMostra \
Variabili\u00BB si possono vedere i valori correnti delle \
variabili.
  )
msg.pack(side = TOP)
pulsanti = Frame(quadro_grande)
pulsanti.pack(side = BOTTOM, fill = X, padx = 2m)
pulsanti_spunta = Frame(quadro_grande)
pulsanti_spunta.pack(side = TOP, fill = X, padx = 2m)
chiudi = Button(pulsanti)
chiudi.configure(text = Chiudi, command = genitore.destroy)
chiudi.pack(side = LEFT, expand = YES)
self.var = Button(pulsanti)
self.var.configure(
  text = Mostra Variabili,
  command = self.pulsanteMostraVariabiliPremuto,
  default = NORMAL
  )
self.var.pack(side = LEFT, expand = YES)
self.tergicristalli = IntVar()
ps1 = Checkbutton(pulsanti_spunta)
ps1.configure(
  text = Tergicristalli a posto,
  variable = self.tergicristalli,
  relief = FLAT
  )
ps1.pack(side = TOP, pady = 2, anchor = W)
self.freni = IntVar()
ps2 = Checkbutton(pulsanti_spunta)
ps2.configure(
  text = Freni a posto,
  variable = self.freni,
  relief = FLAT
  )
ps2.pack(side = TOP, pady = 2, anchor = W)
self.autista = IntVar()
ps3 = Checkbutton(pulsanti_spunta)
ps3.configure(
  text = Autista sobrio,
  variable = self.autista,
  relief = FLAT
  )
ps3.pack(side = TOP, pady = 2, anchor = W)
  def pulsanteMostraVariabiliPremuto(self):
if self.var.cget(state) == ACTIVE:
  self.var.configure(state = DISABLED)
  mv = MostraVariabili(
self,
tergicristalli,
freni,
autista
)
class MostraVariabili(Toplevel):
  def __init__(self, chiamante, *variabili):
Toplevel.__init__(self)
self.mioChiamante = chiamante
fonteVar = (Helvetica, 14)
self.wm_title(Valori delle variabili)
quadro_grande = Frame(self)
quadro_grande.pack(expand = YES, fill = BOTH)
titolo = Label(quadro_grande)
titolo.configure(
  text = Valori delle variabili:,
  width = 20,
  font = fonteVar
  )
titolo.pack(side = TOP, fill = X)
lung = max(map(len, variabili))
dq = {}
dn = {}
dv = {}
for i in variabili:
  dq[i] = 

Re: tkinter destroy()

2005-03-31 Thread max(01)*
[EMAIL PROTECTED] wrote:
Your app seems to give the right state values only if you select 'Freni
a posto'.   But I see you recognize that with your 'FIXME' note.
also the app seems to have too many variables and widgets defined as
self objects.  That isn't necessary unless they will be used outside
the method they were created in (which labels and buttons usually
aren't), so all you are doing is using up more memory than necessary.
very good advice. i'll try to follow it (i am a newbie, you see...)
Reading the code with Italian names adds a little difficulty in
understanding your code (non parlo italiano ma si parlo espagnol),
i am trying to write an introductory article for an italian audience, 
you see... next time i'll try to translate the names (i was a bit in a 
hurry, sorry ;-)

but
I'm left feeling that your app is more complicated than it needs to be
- unless I'm missing something.  What you are doing is just showing how
you can capture the state of the checkbuttons for use elsewhere, right?
And also, that the state in the 2nd window should be live, so that it
updates with the change in value in the 1st window? 
precisely.
 And just a matter
of personal taste, but splitting up widget configuration over many
lines for me impedes readiblity and makes the code look like java or
c++ : surely not what we want?
right... :-)
I also think you could get away with no frames in your initial window,
at least if you use grid() instead of pack().  
as a matter of personal taste i prefer pack(), unless special reasons 
for doing differently. i like better to give general structure 
(hyerarchically) to the gui than hardcoding the appearance.

Also your three state
variables could be members of a list, so you don't have to have
separate constructors for each of them.
ok...
Anyway here's a version of your app that makes use of a 'for' statement
to draw the labels and checkbuttons, so it's only half as long as your
original app.  It also does the right thing - the key pont you were
missing was to use a 'textvariable' argument in defining your label
widgets in the 2nd window.
cheers
Stewart in Calgary
i am going to study it thoroughly. thanks a lot.
bye
macs
--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with tkinter

2005-03-30 Thread max(01)*
Pierre Quentel wrote:
Instead of indexing self.lab by strings, you can index them by the 
attributes themselves : self.lab[self.i], and change line 23 into

 for var in (self.s, self,i)
For your example, I wouldn't have used the text option in the 
definition of the labels, then textvariable in the callback method 
(procedi) ; I would have used only text and no IntVar or StringVar, 
just an integer and a string :

class MiaApp:
def __init__(self, genitore):
   self.mioGenitore = genitore
   self.i = 42
   self.s = Baobab
   self.lab = {}
   self.lab[self.i] = Label(self.mioGenitore)
   self.lab[self.i].configure(width = 30, relief = RIDGE,
 text = [vuota])
   self.lab[self.i].pack()
   self.lab[self.s] = Label(self.mioGenitore)
   self.lab[self.s].configure(width = 30, relief = RIDGE,
 text = [vuota])
   self.lab[self.s].pack()
   self.but = Button(self.mioGenitore)
   self.but.configure(text = Vai!, command = self.procedi)
   self.but.pack()
def procedi(self):
   for var in (self.i, self.s):
 self.lab[var].configure(text = var)
Regards,
Pierre
hi pierre.
i don't think this would not have worked as expected (by me). in my 
intentions, the text of the label must be slaved to a variable, so that 
it would change dynamically during the mainloop execution if another 
part of the code had chenged the content of the variable.

maybe here is a more convincing example (the previous one was contrived 
too hastily i guess):

  1 from Tkinter import *
  2
  3 class MiaApp:
  4 def __init__(self, genitore):
  5self.mioGenitore = genitore
  6self.var = {0: 42, 1: Baobab}
  7self.lab = {}
  8self.lab[0] = Label(self.mioGenitore)
  9self.lab[0].configure(width = 30, relief = RIDGE,
 10  text = [vuota])
 11self.lab[0].pack()
 12self.lab[1] = Label(self.mioGenitore)
 13self.lab[1].configure(width = 30, relief = RIDGE,
 14  text = [vuota])
 15self.lab[1].pack()
 16self.but = Button(self.mioGenitore)
 17self.but.configure(text = Vai!, command = self.procedi)
 18self.but.pack()
 19self.but2 = Button(self.mioGenitore)
 20self.but2.configure(text = Torna!, command = 
self.procedi2)
 21self.but2.pack()
 22 def procedi(self):
 23for var in self.lab.keys():
 24  self.lab[var].configure(text = self.var[var])
 25 def procedi2(self):
 26self.var[0] = 24
 27self.var[1] = Cactus
 28
 29 radice = Tk()
 30 miaApp = MiaApp(radice)
 31 radice.mainloop()

in this example, when user presses Torna!, the labels are not updated 
as i expect; they only will be when user presses Vai! again (not what 
i want).

thanks again
macs
--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with tkinter

2005-03-30 Thread max(01)*
Eric Brunel wrote:
On Tue, 29 Mar 2005 22:32:59 +0200, Pierre Quentel 
[EMAIL PROTECTED] wrote:
[...]
mr brunel,
i thank you for prompt reply. i will take my time to read it carefully.
meanwhile, i inform you and the ng that someone else gave me a quick and 
dirty answer to my problem, namely subststuting line #24 like this:

 24   self.lab[var].configure(textvariable = eval(var))
which seems to work as desired.
thanks again
bye
macs
--
http://mail.python.org/mailman/listinfo/python-list


redundant imports

2005-03-30 Thread max(01)*
hi everybody.
suppose that code-1.py imports code-2.py and code-3.py (because it uses 
names from both), and that code-2.py imports code-3.py.

if python were c, code-1.c should only *include* code-2.c, because the 
latter in turns includes code-3.c.

inclusion of modules in c is a purely preprocessing textual matter 
(compilation is deferred to after the fact), i guess, so that such 
things are possible. import of modules in python is a different beast, 
so the redundancy is (i think) necessary.

any comment/suggestion/idea?
bye
macs
--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with tkinter

2005-03-30 Thread max(01)*
Eric Brunel wrote:
On Tue, 29 Mar 2005 22:32:59 +0200, Pierre Quentel 
[EMAIL PROTECTED] wrote:

Instead of indexing self.lab by strings, you can index them by the
attributes themselves : self.lab[self.i], and change line 23 into
  for var in (self.s, self,i)

I really think this is asking for trouble: I suppose that the i and s 
attributes are meant to change at some point in the future, and you're 
mapping their *values* to the corresponding labels. So if the value 
changes, you won't be able to get the label again.

For your example, I wouldn't have used the text option in the
definition of the labels, then textvariable in the callback method
(procedi) ; I would have used only text and no IntVar or StringVar,
just an integer and a string :

I would have done exactly the contrary, as it is far more easier to use. 
Using the textvariable option in Label's does not require you to 
remember the labels, but only the variables used to hold their contents. 
I'd also use two mappings: the first mapping a name to a Tkinter 
variable for the label variables, and the second for the values to give 
to these variables later.

Here is my version of the class code:
class MiaApp:
 def __init__(self, genitore):
self.mioGenitore = genitore
## Mapping for variables
self.variables = {
  i : StringVar(),
  s : StringVar()
}
## Mapping for future variable values
self.values = {
  i : 42,
  s : Baobab
}
## Now, create the labels
for var in self.variables.values():
  ## Default text
  var.set([vuota])
  ## Create label
  lb = Label(self.mioGenitore, width=30, relief=RIDGE, 
textvariable=var)
  lb.pack()
## The button is no more remembered in an attribute, as it does 
not seem to be needed
but = Button(self.mioGenitore, text = Vai!, command = 
self.procedi)
but.pack()

 def procedi(self):
   ## Just change the variable values
   for varName in self.variables.keys():
 self.variables[varName].set(self.values[varName])
your technique is most interirting and clean, i must say.
nevertheless, i cannot find a natural way to modularize it, in such a 
way that the machinery of the method might be isolated from the code 
that uses it.

consider for example the following two programs:

$ cat Miodialogo.py
from Tkinter import *
class MioDialogo(Toplevel):
  def __init__(self, genitore, chiamante):
Toplevel.__init__(self, genitore)
self.wm_title(Valori delle variabili)
self.mioGenitore = genitore
self.mioChiamante = chiamante
self.fonteVar = (Helvetica, 14)
self.quadro_grande = Frame(self)
self.quadro_grande.pack(expand = YES, fill = BOTH)
self.titolo = Label(self.quadro_grande)
self.titolo.configure(
  text = Valori delle variabili:,
  width = 20,
  font = self.fonteVar
  )
self.titolo.pack(side = TOP, fill = X)
  def mostraVariabili(self, *argomenti):
lung = 1
for i in argomenti:
  if len(i)  lung:
lung = len(i)
self.dq = {}
self.dn = {}
self.dv = {}
for i in argomenti:
  self.dq[i] = Frame(self.quadro_grande)
  self.dq[i].pack(
side = TOP,
anchor = W,
fill = X
)
  self.dn[i] = Label(self.dq[i])
  self.dn[i].configure(
text = i + : ,
width = lung + 2,
anchor = W
)
  self.dn[i].pack(
side = LEFT
)
  self.dv[i] = Label(self.dq[i])
  self.dv[i].configure(
textvariable = eval(self.mioChiamante. + i),
anchor = W
)
  self.dv[i].pack(
side = LEFT,
expand = YES,
fill = X
)
self.vaBene = Button(self.quadro_grande)
self.vaBene.configure(
  text = Va Bene,
  command = self.pulsanteVaBenePremuto,
  default = ACTIVE
  )
self.vaBene.bind(
  Return,
  self.pulsanteVaBenePremuto_a
  )
self.vaBene.focus_force()
self.vaBene.pack(
  side = BOTTOM,
  pady = 2
  )
  def pulsanteVaBenePremuto(self):
self.destroy()
self.mioChiamante.var.configure(state = NORMAL)
  def pulsanteVaBenePremuto_a(self, evento):
self.pulsanteVaBenePremuto()
$ cat spunta-4.py
from Tkinter import *
from Miodialogo import *
class MiaApp:
  def __init__(self, genitore):
self.mioGenitore = genitore
self.fonte = (Helvetica, 12)
self.quadro_grande = Frame(genitore)
self.quadro_grande.pack(expand = YES, fill = BOTH)
self.msg = Label(self.quadro_grande)
self.msg.configure(
  font = self.fonte,
  wraplength = 10c,
  justify = LEFT,
  text = uSono qui sotto presentati tre pulsanti a spunta. \
Premendo un pulsante, se ne varia lo stato di selezione e si \
imposta una variabile a un valore che indica lo stato del \
pulsante stesso. Premendo il pulsante \u00ABMostra \
Variabili\u00BB si possono vedere i valori correnti delle \

passing keyword args as a parameter

2005-03-29 Thread max(01)*
hi there!
this post is somewhat a generalization of one previous question.
i was wondering if it is possible to pass an argument list as a
parameter to a function. example:
def fun_con_pc(pc1 = Ciao!, pc2 = 42):
  print pc1
  print pc2
fun_con_pc()
fun_con_pc(pc1 = Addio...)
fun_con_pc(pc2 = 666, pc1 = Addio...)
arg = 'pc2 = 666, pc1 = Addio...'
fun_con_pc(arg)

if i execute, i get:
Ciao!
42
Addio...
42
Addio...
666
pc2 = 666, pc1 = Addio...
42
**but** i want to get:
Ciao!
42
Addio...
42
Addio...
666
Addio...
666

see what i mean?
bye
macs
--
http://mail.python.org/mailman/listinfo/python-list


tkinter destroy()

2005-03-29 Thread max(01)*
hi people.
when i create a widget, such as a toplevel window, and then i destroy 
it, how can i test that it has been destroyed? the problem is that even 
after it has been destroyed, the instance still exists and has a tkinter 
name, so testing for None is not feasible:

 import Tkinter
 fin = None
 fin1 = Tkinter.Toplevel()
 fin1.destroy()
 print fin1
.1075951116
any help?
bye
macs
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter destroy()

2005-03-29 Thread max(01)*
Eric Brunel wrote:
On Tue, 29 Mar 2005 10:37:10 GMT, max(01)* [EMAIL PROTECTED] wrote:
hi people.
when i create a widget, such as a toplevel window, and then i destroy
it, how can i test that it has been destroyed? the problem is that even
after it has been destroyed, the instance still exists and has a tkinter
name, so testing for None is not feasible:
  import Tkinter
  fin = None
  fin1 = Tkinter.Toplevel()
  fin1.destroy()
  print fin1
.1075951116

The winfo_exists method is what you want:
print fin1.winfo_exists()
0
However, I'm curious about *why* you want to do that: since *you* made 
the call to destroy, what would you want to do anything with a widget 
you've already destroyed?
my main window has a button that opens another toplevel window. this 
button is bound to a method that creates the window and does some other 
processing *only if* the windows does not exist yet (otherwise, the user 
could click more on the button and multiple copies of the window would 
pop up, which is not what i want... in fact what i do is to assign None 
to a variable called self.dialogo in my main application code, then i do 
self.dialogo = Toplevel() inside the method...)

in this precise moment, though, it comes to my mind that i could achieve 
the purpose simply activating/deactivating the button according to a flag...

anyway, i attach the code, so you can see better what i mean...
anyone who has to say anything about is welcome of course...
it is a tentative adapration of a program found in the tcl/tk package demo
---cut here---
from Tkinter import *
class MiaApp:
  def __init__(self, genitore):
self.mioGenitore = genitore
self.fonte = (Helvetica, 12)
self.fonteVar = (Helvetica, 14)
self.quadro_grande = Frame(genitore)
self.quadro_grande.pack(expand = YES, fill = BOTH)
self.msg = Label(self.quadro_grande)
self.msg.configure(
  font = self.fonte,
  wraplength = 10c,
  justify = LEFT,
  text = uSono qui sotto presentati tre pulsanti a spunta. \
Premendo un pulsante, se ne varia lo stato di selezione e si \
imposta una variabile a un valore che indica lo stato del \
pulsante stesso. Premendo il pulsante \u00ABMostra \
Variabili\u00BB si possono vedere i valori correnti delle \
variabili.
  )
self.msg.pack(side = TOP)
self.pulsanti = Frame(self.quadro_grande)
self.pulsanti.pack(side = BOTTOM, fill = X, padx = 2m)
self.pulsanti_spunta = Frame(self.quadro_grande)
self.pulsanti_spunta.pack(side = TOP, fill = X, padx = 2m)
self.annulla = Button(self.pulsanti)
self.annulla.configure(
  text = Annulla,
  command = self.mioGenitore.destroy
  )
self.annulla.pack(side = LEFT, expand = YES)
self.var = Button(self.pulsanti)
self.var.configure(
  text = Mostra Variabili,
  command = self.pulsanteMostraVariabiliPremuto
  )
self.var.pack(side = LEFT, expand = YES)
self.tergicristalli = IntVar()
self.b1 = Checkbutton(self.pulsanti_spunta)
self.b1.configure(
  text = Tergicristalli a posto,
  variable = self.tergicristalli,
  relief = FLAT
  )
self.b1.pack(
  side = TOP,
  pady = 2,
  anchor = W
  )
self.freni = IntVar()
self.b2 = Checkbutton(self.pulsanti_spunta)
self.b2.configure(
  text = Freni a posto,
  variable = self.freni,
  relief = FLAT
  )
self.b2.pack(
  side = TOP,
  pady = 2,
  anchor = W
  )
self.autista = IntVar()
self.b3 = Checkbutton(self.pulsanti_spunta)
self.b3.configure(
  text = Autista sobrio,
  variable = self.autista,
  relief = FLAT
  )
self.b3.pack(
  side = TOP,
  pady = 2,
  anchor = W
  )
self.dialogo = None
  def mostraVariabili(self, *argomenti):
self.dialogo = Toplevel()
self.dialogo.wm_title(Valori delle variabili)
self.dialogo.quadro_grande = Frame(self.dialogo)
self.dialogo.quadro_grande.pack(expand = YES, fill = BOTH)
self.dialogo.titolo = Label(self.dialogo.quadro_grande)
self.dialogo.titolo.configure(
  text = Valori delle variabili:,
  width = 20,
  font = self.fonteVar
  )
self.dialogo.titolo.pack(side = TOP, fill = X)
lung = 1
for i in argomenti:
  if len(i)  lung:
lung = len(i)
self.dialogo.dq = {}
self.dialogo.dn = {}
self.dialogo.dv = {}
for i in argomenti:
  self.dialogo.dq[i] = Frame(self.dialogo.quadro_grande)
  self.dialogo.dq[i].pack(
side = TOP,
anchor = W,
fill = X
)
  self.dialogo.dn[i] = Label(self.dialogo.dq[i])
  self.dialogo.dn[i].configure(
text = i + : ,
width = lung + 2,
anchor = W
)
  self.dialogo.dn[i].pack(
side = LEFT
)
  self.dialogo.dv[i] = Label(self.dialogo.dq[i])
  self.dialogo.dv[i].configure(
textvariable = self.freni,  ### FIXME
anchor = W
)
  self.dialogo.dv[i].pack(
side = LEFT

Re: passing keyword args as a parameter

2005-03-29 Thread max(01)*
Fredrik Lundh wrote:
max(01)* [EMAIL PROTECTED] wrote:

see what i mean?

not really, but maybe
arg = {pc2: 666, pc1: Addio...}
fun_con_pc(**arg)
is what you want?
precisely! thanks a lot!
macs
--
http://mail.python.org/mailman/listinfo/python-list


problem with tkinter

2005-03-29 Thread max(01)*
hello.
the following code:
  1 from Tkinter import *
  2
  3 class MiaApp:
  4   def __init__(self, genitore):
  5 self.mioGenitore = genitore
  6 self.i = IntVar()
  7 self.i.set(42)
  8 self.s = StringVar()
  9 self.s.set(Baobab)
 10 self.lab = {}
 11 self.lab[self.i] = Label(self.mioGenitore)
 12 self.lab[self.i].configure(width = 30, relief = RIDGE,
 13   text = [vuota])
 14 self.lab[self.i].pack()
 15 self.lab[self.s] = Label(self.mioGenitore)
 16 self.lab[self.s].configure(width = 30, relief = RIDGE,
 17   text = [vuota])
 18 self.lab[self.s].pack()
 19 self.but = Button(self.mioGenitore)
 20 self.but.configure(text = Vai!, command = self.procedi)
 21 self.but.pack()
 22   def procedi(self):
 23 for var in (self.i, self.s):
 24   self.lab[var].configure(textvariable = var)
 25
 26 radice = Tk()
 27 miaApp = MiaApp(radice)
 28 radice.mainloop()
is intended
--
http://mail.python.org/mailman/listinfo/python-list


problem with tkinter

2005-03-29 Thread max(01)*
hello.
the following code:
  1 from Tkinter import *
  2
  3 class MiaApp:
  4   def __init__(self, genitore):
  5 self.mioGenitore = genitore
  6 self.i = IntVar()
  7 self.i.set(42)
  8 self.s = StringVar()
  9 self.s.set(Baobab)
 10 self.lab = {}
 11 self.lab[self.i] = Label(self.mioGenitore)
 12 self.lab[self.i].configure(width = 30, relief = RIDGE,
 13   text = [vuota])
 14 self.lab[self.i].pack()
 15 self.lab[self.s] = Label(self.mioGenitore)
 16 self.lab[self.s].configure(width = 30, relief = RIDGE,
 17   text = [vuota])
 18 self.lab[self.s].pack()
 19 self.but = Button(self.mioGenitore)
 20 self.but.configure(text = Vai!, command = self.procedi)
 21 self.but.pack()
 22   def procedi(self):
 23 for var in (self.i, self.s):
 24   self.lab[var].configure(textvariable = var)
 25
 26 radice = Tk()
 27 miaApp = MiaApp(radice)
 28 radice.mainloop()
is intended to make a window with 2 labels and a button, such that 
pressin the button you get the labels display the content of two 
variables. it does not work, of course, as intended. is there anybody 
who can point me in the right direction? (the problem seems to be that 
the command option wants a variable name, not a string containing that 
name).

hopefully
macs
--
http://mail.python.org/mailman/listinfo/python-list


tkinter and textvariable option

2005-03-28 Thread max(01)*
hello everybody.
i am a a bit of a newbie in python/tkinter,and i am experimenting a bit 
with widgets like checkbuttons.

in python, you can create a checkbutton instance like this:

self.tergicristalli = IntVar()
self.b1 = Checkbutton(self.pulsanti_spunta)
self.b1.configure(
  text = Tergicristalli a posto,
  variable = self.tergicristalli  ### (1)
  )
self.b1.pack()

where you bind the widget to a variable 'self.tergicristalli', which 
will be updated as the user checks/unchecks the checkbutton.

maybe i interpret the question incorrectly, but the syntax (1) seems 
like assigning the *value* of 'self.tergicristalli' to the variable
variable, while it is more like an aliasing instead...

my question is: how can i embed the above code inside a function body, 
such that the function accepts as a parameter the variable to bind the 
option 'variable' to (not the value, mind you!)? like this:

def acceptName(name):
  
  self.tergicristalli = IntVar()
  self.b1 = Checkbutton(self.pulsanti_spunta)
  self.b1.configure(
text = Tergicristalli a posto,
variable = name ### --- THIS IS NOT WHAT I MEAN, OF COURSE!
)
  self.b1.pack()
  
bye bye
macs
--
http://mail.python.org/mailman/listinfo/python-list