Re: any(), all() and empty iterable

2009-04-20 Thread Jani Hakala
Raymond Hettinger  writes:

> FWIW, I wrote the docs.  The pure python forms were put in
> as an integral part of the documentation.  The first
> sentence of prose was not meant to stand alone.  It is a
> lead-in to the code which makes explicit the short-circuiting
> behavior and the behavior when the input is empty.
>
Someone else seems to have written "What's new in Python 2.5"
documention which states:

 "Two new built-in functions, any() and all(), evaluate whether an
  iterator contains any true or false values. any() returns True if any
  value returned by the iterator is true; otherwise it will return
  False. all() returns True only if all of the values returned by the
  iterator evaluate as true."

This description of all() doesn't seem to be correct.

> I will probably leave the lead-in sentence as-is but may
> add another sentence specifically covering the case for
> an empty iterable.
>
Does this change cover the documentation returned by help(all) and 
help(any)?

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


Re: Threading and tkinter

2009-03-07 Thread Jani Hakala
gert  writes:

> After reading the docs and seeing a few examples i think this should
> work ?
> Am I forgetting something here or am I doing something stupid ?
> Anyway I see my yellow screen, that has to count for something :)
>
I have been using the following scheme:
  - Pass the root object to the thread object when creating the object
  - Define a event_handler: root.bind('<>', evt_handler) in
the main thread.

  - When the thread has done something that the GUI part should now
about, signal an event in the thread:
root.event_generate('<>')(no other arguments)

  - Call a method of the thread object in the event handler e.g. to get
some data from a queue object.

This ensures that only the main thread accesses Tkinter-related things.

from Tkinter import *
from threading import Thread

import Queue
import time

class Weegbrug(Thread):
def __init__(self, gui, file_name):
Thread.__init__(self)
self.gui = gui
self.queue = Queue.Queue()
self.file_name = file_name

def run(self):
while True:
with open(self.file_name, 'r') as f:
for line in f:
self.queue.put(line)
self.gui.event_generate('<>')
time.sleep(0.5)

def get_line(self):
return self.queue.get()

root = Tk()
v = StringVar()
v.set("0")
w = Weegbrug(root, '/tmp/test.py')

def evt_handler(*args):
v.set(w.get_line())
root.bind('<>', evt_handler)

tx = Label(root, textvariable=v, width=100, bg="yellow", font=("Helvetica", 20))
tx.pack(expand=YES, fill=BOTH)
root.title("Weegbrug")

# root.overrideredirect(1)
# root.geometry("%dx%d+0+0" % (root.winfo_screenwidth(),
# root.winfo_screenheight()))

# Don't start before there's a handler installed
w.start()
root.mainloop() 

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


Re: Tkinter--does anyone use it for sophisticated GUI development?

2006-10-21 Thread Jani Hakala
Kevin Walzer <[EMAIL PROTECTED]> writes:

> For instance, I've developed several Tcl
> applications that use the core Tk widgets, the Tile theming package, the
> Bwidget set (great tree widget and listbox, which allows you to embed
> images), and tablelist (an extremely flexible muti-column listbox
> display). 
> 
I tried to look for a python-library when I started using
tablelist. The only link I found was quite dead.

I spent a day or two while learning how to do a minimal (i.e. only
those methods that I have needed) implementation from scratch :(
It seems to work quite well for my purposes.

> I've found Python wrappers for some of this stuff, but almost
> no documentation on how to use them
>
Is there sufficient documentation for the Tcl/Tk libraries that the
wrappers have been coded for? At least with Tkinter and Tix it is
usually quite obvious what is the corresponding python method if you
know the Tcl/Tk counterpart.

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