Re: Use threads or Tkinter event loop?

2007-03-27 Thread Kevin Walzer
Kevin Walzer wrote:
> I'm trying to decide whether I need threads in my Tkinter application or 
> not. My app is a front end to a command-line tool; it feeds commands to 
> the command-line program, then reads its output and displays it in a 
> Tkinter text widget. Some of the commands are long-running and/or return 
> thousands of lines of output.
> 
> I initially thought I needed to use threading, because the GUI would 
> block when reading the output, even when I configured the blocking to be 
> non-blocking. I got threading to work, but it seemed a bit complicated. 
> So, I decided to try something simpler, by using the Tkinter event loop 
> to force the output to update/display.
> 
> it seems to work well enough. Here is my threaded code:
> 
> non-threaded:
> 
> def insertDump(self):
>  self.finkinstalled = os.popen('/sw/bin/fink list', 'r', os.O_NONBLOCK)
> for line in self.finkinstalled:
> self.t.insert(END, line)
> self.update()
> self.t.see(END)
> 
> And here is my non-threaded code (needs two functions to work)
> 
>  def insertDump(self):
> try:
> data = self.dataQueue.get(block=False)
> for line in data:
> self.t.insert(END, line)
> self.t.see(END)
> self.update()
> 
> 
> except:
> print "error"
> raise
> 
> def getDump(self):
> 
> self.file = os.popen('/sw/bin/fink list', 'r', os.O_NONBLOCK)
> self.dataQueue.put(self.file)
> 
> This brings me to a design, as opposed to coding, question. The 
> non-threaded version seems to work just as well as the threaded one, in 
> terms of speed. Moreover, it is simpler to code and debug, because I 
> don't have to check to make sure the thread queue has data (I sometimes 
> get an 'Empty' error message when I first start the thread).  Simply 
> using the Tk event loop (self.update) is also how I would have coded 
> this in Tcl.
> 
> So my question is this: under what circumstances in Python are threads 
> considered "best practice"? Am I wrong to use the Tk event loop instead 
> of threads?
> 

D'oh, I got the code snippets mixed up:

non-threaded:

def insertDump(self):
  self.finkinstalled = os.popen('/sw/bin/fink list', 'r', os.O_NONBLOCK)
 for line in self.finkinstalled:
 self.t.insert(END, line)
 self.update()
 self.t.see(END)

threaded:

  def insertDump(self):
 try:
 data = self.dataQueue.get(block=False)
 for line in data:
 self.t.insert(END, line)
 self.t.see(END)
 self.update()


 except:
 print "error"
 raise

 def getDump(self):

 self.file = os.popen('/sw/bin/fink list', 'r', os.O_NONBLOCK)
 self.dataQueue.put(self.file)

Sorry!
-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Use threads or Tkinter event loop?

2007-03-27 Thread Kevin Walzer
I'm trying to decide whether I need threads in my Tkinter application or 
not. My app is a front end to a command-line tool; it feeds commands to 
the command-line program, then reads its output and displays it in a 
Tkinter text widget. Some of the commands are long-running and/or return 
thousands of lines of output.

I initially thought I needed to use threading, because the GUI would 
block when reading the output, even when I configured the blocking to be 
non-blocking. I got threading to work, but it seemed a bit complicated. 
So, I decided to try something simpler, by using the Tkinter event loop 
to force the output to update/display.

it seems to work well enough. Here is my threaded code:

non-threaded:

def insertDump(self):
  self.finkinstalled = os.popen('/sw/bin/fink list', 'r', os.O_NONBLOCK)
 for line in self.finkinstalled:
 self.t.insert(END, line)
 self.update()
 self.t.see(END)

And here is my non-threaded code (needs two functions to work)

  def insertDump(self):
 try:
 data = self.dataQueue.get(block=False)
 for line in data:
 self.t.insert(END, line)
 self.t.see(END)
 self.update()


 except:
 print "error"
 raise

 def getDump(self):

 self.file = os.popen('/sw/bin/fink list', 'r', os.O_NONBLOCK)
 self.dataQueue.put(self.file)

This brings me to a design, as opposed to coding, question. The 
non-threaded version seems to work just as well as the threaded one, in 
terms of speed. Moreover, it is simpler to code and debug, because I 
don't have to check to make sure the thread queue has data (I sometimes 
get an 'Empty' error message when I first start the thread).  Simply 
using the Tk event loop (self.update) is also how I would have coded 
this in Tcl.

So my question is this: under what circumstances in Python are threads 
considered "best practice"? Am I wrong to use the Tk event loop instead 
of threads?

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: enumerating processes

2007-03-27 Thread kyosohma
On Mar 27, 12:15 am, Shane Geiger <[EMAIL PROTECTED]> wrote:
> I believe you are looking for os.getpid()
>
> 李现民 wrote:
> > hi ,all
> >any one knows how to enumerate the current running processes , or
> > how to obtain a specific process by its name or process id. I know I
> > can do this in many  programming languages , but how in python? any
> > one know?
> >  Thanks for any guidance.
>
> > --
> > li xianmin
>
> >[EMAIL PROTECTED] 
>
> --
> Shane Geiger
> IT Director
> National Council on Economic Education
> [EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net
>
> Leading the Campaign for Economic and Financial Literacy
>
>  sgeiger.vcf
> 1KDownload

You can also use Golden's WMI to grab a list. As I understand it, the
WMI module relies on the win32 modules, but it's a nice wrapper. Check
out the cookbook at:

http://tgolden.sc.sabren.com/python/wmi_cookbook.html#running_processes

Mike

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

Re: Python Error :(

2007-03-27 Thread kyosohma
On Mar 27, 8:19 am, "Legend" <[EMAIL PROTECTED]> wrote:
> I wasn't able to run a Python script. But then later I was able to run
> it through the Shell. I was experimenting with cron jobs and set up
> the python execution in as a cron. The first time it ran, It was fine
> but then after that, it started giving me some errors. Now when I try
> to run the script directly, I get the following error:
>
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "userbot.py", line 637, in ?
> con = connect()
>   File "userbot.py", line 607, in connect
> con.requestRoster()
>   File "user.py", line 531, in requestRoster
> self.SendAndWaitForResponse(rost_iq)
>   File "user.py", line 326, in SendAndWaitForResponse
> return self.waitForResponse(ID)
>   File "user.py", line 300, in waitForResponse
> self.process(1)
>   File "xmlstream.py", line 459, in process
> if not len(self.read()): # length of 0 means disconnect
>   File "xmlstream.py", line 398, in read
> data_in=data_in+self._sslObj.read(BLOCK_SIZE).decode('utf-8')
> socket.sslerror: (6, 'TLS/SSL connection has been closed')
>
> Any help please?

I'll hazard a guess: Are you opening the socket explicitly when you
run this script?  If not, be sure to do so. And when you are finished
doing whatever it is you're doing, be sure to close it as well. You
may need to put in some kind of logic to check if the socket is still
open if you are transferring large files.

Mike

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


Re: socket read timeout

2007-03-27 Thread Steve Holden
Jarek Zgoda wrote:
> hg napisał(a):
> 
>> I am looking for the most efficient / cleanest way to implement a socket
>> read with timeout (Windows mainly but would be great if the same code
>> worked under *nix)
> 
> Did you see http://www.timo-tasi.org/python/timeoutsocket.py ?
> 
Note that since 2.4, I believe, sockets in the standard library allow 
you to specify a timeout parameter.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings   http://holdenweb.blogspot.com

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


Re: Modules & positive surprises

2007-03-27 Thread kyosohma
On Mar 27, 8:30 am, Jan Danielsson <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> 
>
>Although I have encountered many modules that have impressed me with
> regards to what they can actually do -- too be perfectly honest, it's
> very rare that I become impressed by the _interfaces_ to the modules.
>
>Using a new module is normally, with my - admittedly - limited
> experience, a pain. It's not just about reading the reference material,
> and then just use it. You have to figure out how the developer who wrote
> the module was thinking. Often there's a (more or less) natural way to
> do things, and unfortunately that's not how module developers do it.
> It's not a major issue to me personally, since the important part is
> that the module can perform its function.
>
>But then there are a few modules that I just love to use, because
> they are so "clean" from interface to function. Among them I can't help
> mentioning optparse.
>
>Yesterday I found another module which I fell in love with: Python
> Cryptography Toolkit (http://www.amk.ca/python/writing/pycrypt/).
>
>It's just so ... elegant, and functional.
>
> 
>
> --
> Kind regards,
> Jan Danielsson

Yeah. I've noticed that myself. There are tons of good modules, but a
lot of the docs are lousy. What's really annoying is that everyone
says that so-and-so is well documented. I love Python, but I wish when
they said some module was well documented, they meant that the docs
were understandable (to n00bs) as well.

Mike

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


Modules & positive surprises

2007-03-27 Thread Jan Danielsson
Hello all,



   Although I have encountered many modules that have impressed me with
regards to what they can actually do -- too be perfectly honest, it's
very rare that I become impressed by the _interfaces_ to the modules.

   Using a new module is normally, with my - admittedly - limited
experience, a pain. It's not just about reading the reference material,
and then just use it. You have to figure out how the developer who wrote
the module was thinking. Often there's a (more or less) natural way to
do things, and unfortunately that's not how module developers do it.
It's not a major issue to me personally, since the important part is
that the module can perform its function.

   But then there are a few modules that I just love to use, because
they are so "clean" from interface to function. Among them I can't help
mentioning optparse.

   Yesterday I found another module which I fell in love with: Python
Cryptography Toolkit (http://www.amk.ca/python/writing/pycrypt/).

   It's just so ... elegant, and functional.



-- 
Kind regards,
Jan Danielsson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket read timeout

2007-03-27 Thread Jarek Zgoda
hg napisał(a):

> I am looking for the most efficient / cleanest way to implement a socket
> read with timeout (Windows mainly but would be great if the same code
> worked under *nix)

Did you see http://www.timo-tasi.org/python/timeoutsocket.py ?

-- 
Jarek Zgoda

"We read Knuth so you don't have to."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Error :(

2007-03-27 Thread Jarek Zgoda
Legend napisał(a):

> I wasn't able to run a Python script. But then later I was able to run
> it through the Shell. I was experimenting with cron jobs and set up
> the python execution in as a cron. The first time it ran, It was fine
> but then after that, it started giving me some errors. Now when I try
> to run the script directly, I get the following error:
> 
> 
> 
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "userbot.py", line 637, in ?
> con = connect()
>   File "userbot.py", line 607, in connect
> con.requestRoster()
>   File "user.py", line 531, in requestRoster
> self.SendAndWaitForResponse(rost_iq)
>   File "user.py", line 326, in SendAndWaitForResponse
> return self.waitForResponse(ID)
>   File "user.py", line 300, in waitForResponse
> self.process(1)
>   File "xmlstream.py", line 459, in process
> if not len(self.read()): # length of 0 means disconnect
>   File "xmlstream.py", line 398, in read
> data_in=data_in+self._sslObj.read(BLOCK_SIZE).decode('utf-8')
> socket.sslerror: (6, 'TLS/SSL connection has been closed')
> 
> 
> Any help please?

Yes.

-- 
Jarek Zgoda

"We read Knuth so you don't have to."
-- 
http://mail.python.org/mailman/listinfo/python-list


socket read timeout

2007-03-27 Thread hg
Hi,

I am looking for the most efficient / cleanest way to implement a socket
read with timeout (Windows mainly but would be great if the same code
worked under *nix)

Tanks,

hg

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


Re: Mastering Python

2007-03-27 Thread Bruno Desthuilliers
Dennis Lee Bieber a écrit :
> On Wed, 21 Mar 2007 21:40:51 +0100, Bruno Desthuilliers
> <[EMAIL PROTECTED]> declaimed the following in
> comp.lang.python:
> 
>> It will actually do something: rebind name 'a' to the method lower() of 
>> the string previously binded to 'a'
>>
>   For future reference, and I hope you don't mind the lesson,

I don't.

> the past
> tense of "bind" is "bound"

err... I knew that, of course.

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


Re: tkinter popup

2007-03-27 Thread Gigs_
Eric Brunel wrote:
> On Tue, 27 Mar 2007 12:05:07 +0200, Gigs_ <[EMAIL PROTECTED]> wrote:
> 
>> Hi all
>>
>> I cant figure out how to disable resizing of my popup window?
> 
> myPopupWindow.wm_resizable(0, 0)
> 
> It may or may not make resize controls disappear depending on your 
> platform and/or window manager. But the resizing will be impossible in 
> any case.
> 
>> How to put this popup window to show in the middle of my text editor?
>> It is writen with Toplevel.
> 
> A bit trickier. For example (untested):
> 
> myPopupWindow.after_idle(centerPopupWindow)
> 
> with:
> 
> def centerPopupWindow():
>   x, y = editorWindow.winfo_rootx(), editorWindow.winfo_rooty()
>   w, h = editorWindow.winfo_width(), editorWindow.winfo_height()
>   ww, hh = myPopupWindow.winfo_width(), myPopupWindow.winfo_height()
>   myPopupWindow.geometry('%sx%s+%s+%s', ww, hh, x + w/2 - ww/2, y + h/2 
> - hh/2)
> 
> The after_idle trick is needed since the dimensions for the popup window 
> will only be known when the window is actually displayed. In theory, 
> myPopupWindow.update_idletasks() should update the display so that the 
> window dimensions are known, but there are cases where it doesn't work. 
> So the after_idle trick is surer.
> 
> HTH
> --python -c "print ''.join([chr(154 - ord(c)) for c in 
> 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

thanks for both replay, they are very helpful. specially this one, it 
will took some times for me to figure this. i was completely forgot that 
this can be done like that

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


Python Error :(

2007-03-27 Thread Legend
I wasn't able to run a Python script. But then later I was able to run
it through the Shell. I was experimenting with cron jobs and set up
the python execution in as a cron. The first time it ran, It was fine
but then after that, it started giving me some errors. Now when I try
to run the script directly, I get the following error:



Traceback (most recent call last):
  File "", line 1, in ?
  File "userbot.py", line 637, in ?
con = connect()
  File "userbot.py", line 607, in connect
con.requestRoster()
  File "user.py", line 531, in requestRoster
self.SendAndWaitForResponse(rost_iq)
  File "user.py", line 326, in SendAndWaitForResponse
return self.waitForResponse(ID)
  File "user.py", line 300, in waitForResponse
self.process(1)
  File "xmlstream.py", line 459, in process
if not len(self.read()): # length of 0 means disconnect
  File "xmlstream.py", line 398, in read
data_in=data_in+self._sslObj.read(BLOCK_SIZE).decode('utf-8')
socket.sslerror: (6, 'TLS/SSL connection has been closed')


Any help please?

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


Re: PMW widget - skip tabbing to it

2007-03-27 Thread jp
On Mar 26, 5:41 pm, John McMonagle <[EMAIL PROTECTED]> wrote:
> jp wrote:
> >>> On Mar 26, 10:51 am, "jp" <[EMAIL PROTECTED]> wrote:
>  I have multiple PMW widgets (EntryFields, ScrolledField etc), how can
>  I skip over these widgets when using the tab key?
>  Thank you,
>  John
>
> What version of Pmw are you using ?  Tabbing between widgets works fine
> on my system (Pmw 1.2,  tk 8.4, KDE)
>
> I can change the focus behaviour by using the takefocus option.  You
> were on the right track, you just did it wrong (see code below):
>
> 
> from Tkinter import *
> import Pmw
>
> root = Tk()
> entry = Pmw.EntryField(root, labelpos=W, value="", label_text='Name:')
> entry.grid(row=1)
> entry.component('entry').configure(takefocus=0)
>
> Button(root,text='test1').grid(row=2)
> Button(root,text='test2').grid(row=3)
> Button(root,text='test3').grid(row=4)
>
> root.mainloop()
> #
>
> Regards,
>
> John


Thank you for pointing out my error, John and James.  I had the syntax
of the command messed up.  Using the following does cause the field to
be skipped when tabbing:
entry.component('entry').configure(takefocus=0)

John

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


Re: shutil.copy Problem

2007-03-27 Thread Facundo Batista
David Nicolson wrote:

> Thanks, but it's definitely not the print. In original the code the  
> print statements are replaced by a call to a log method.
>
> Besides, the exception would be different if it was thrown outside of  
> the try block.

The best you can do is take the piece of code that has the problem, show
it to us, and then copy the traceback.

Regards,

-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


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


Re: tkinter MVC

2007-03-27 Thread Eric Brunel
On Tue, 27 Mar 2007 13:29:25 +0200, Gigs_ <[EMAIL PROTECTED]> wrote:

> Can someone give me example how to write text editor in tkintter with  
> model-view-controler?
> What goes to controler and what goes to model?
>
> thanks in advance

Others may have a different opinion, but I think using MVC to do a text  
editor is a bit overkill. Basically, the only operation needed on the  
model are reading and writing of the file, so a basic Python file object  
will be OK. Considering that, and since the Tkinter Text widget is  
basically already a full-featured text editor, the controller part is also  
quite limited. You could do it however, but it would just be a matter of  
moving the methods called by the bindings to a secondary class. If what  
you're doing is just a text editor, it may not be worth the effort.

Having an MVC architecture for a text editor may be a good idea if the  
file objects have to interact with other objects at a "functional" level,  
i.e without any impact on the GUI. If what you're doing is only a text  
editor, i.e only managing text files, the advantages of such an  
architecture won't really show up...

My [$£€¥]0.02...
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Fortran vs Python - Newbie Question

2007-03-27 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Beliavsky <[EMAIL PROTECTED]> wrote:
.
.
.
>Your experience with Fortran is dated -- see below.
>
>>
>> I'll be more clear:  Fortran itself is a distinguished
>> language with many meritorious implementations.  It can be
>> costly, though, finding the implementation you want/need
>> for any specific environment.
>
>Gfortran, which supports Fortran 95 and a little of Fortran 2003, is
>part of GCC and is thus widely available. Binaries for g95, also based
>on GCC, are available for more than a dozen platforms, including
>Windows, Mac OS X, and Linux. I use both and consider only g95 mature,
>but gfortran does produce faster programs. Intel's Fortran compilers
>cost about $500 on Windows and Mac OS and $700 on Linux. It's not
>free, but I would not call it costly for professional developers.
>
>Speaking of money, gfortran and g95 have free manuals, the latter
>available in six languages
>http://ftp.g95.org/ . Final drafts of Fortran standards, identical to
>the official ISO standards, are freely available. The manual for Numpy
>costs $40 per copy.
>

My experience with Fortran is indeed dated.  However,
I still work with university groups that balk at $500
for valuable software--sometimes because of admini-
strative conflicts with licensing (example:  the group
needs an educational license that fits its team 
perfectly, but educational license have to be approved
by a campus-wide office that involves the group in
expenses uncovered by its grants, and ... complications
ensue).  Intel's compiler, for example, is a great deal,
and recognized as a trivial expense sometimes--but
judged utterly impossible by a research group down a
different corridor.

My summary:  practical success depends on specific
details, and specific details in the Fortran and Python
worlds differ.

Also, Beliavsky, thanks for your report on the pertinent
Fortran compilers.  There *are* other proprietary Fortan
compilers extant; do you expect them to fade away,
leaving only g* and Intel, or are you simply remarking
on those two as the (intellectual) market leaders?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter popup

2007-03-27 Thread Eric Brunel
On Tue, 27 Mar 2007 12:05:07 +0200, Gigs_ <[EMAIL PROTECTED]> wrote:

> Hi all
>
> I cant figure out how to disable resizing of my popup window?

myPopupWindow.wm_resizable(0, 0)

It may or may not make resize controls disappear depending on your  
platform and/or window manager. But the resizing will be impossible in any  
case.

> How to put this popup window to show in the middle of my text editor?
> It is writen with Toplevel.

A bit trickier. For example (untested):

myPopupWindow.after_idle(centerPopupWindow)

with:

def centerPopupWindow():
   x, y = editorWindow.winfo_rootx(), editorWindow.winfo_rooty()
   w, h = editorWindow.winfo_width(), editorWindow.winfo_height()
   ww, hh = myPopupWindow.winfo_width(), myPopupWindow.winfo_height()
   myPopupWindow.geometry('%sx%s+%s+%s', ww, hh, x + w/2 - ww/2, y + h/2 -  
hh/2)

The after_idle trick is needed since the dimensions for the popup window  
will only be known when the window is actually displayed. In theory,  
myPopupWindow.update_idletasks() should update the display so that the  
window dimensions are known, but there are cases where it doesn't work. So  
the after_idle trick is surer.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


correction : Re: pygtk button event

2007-03-27 Thread [EMAIL PROTECTED]
Oups a small mistake:

bt=application.get_widget('button1')

[EMAIL PROTECTED] wrote:
> Hi
>
>
> i am trying to implement the following:
>
> I want to be able to press a button, perform a task and return a
> value.
>
> my button is named button1 and I used glade to build the gui.
>
> so, something like this should work
>
>
> application=gtk.glade.XML('app.glade','app')
> bt=app.get_widget('button1')
> bt.connect('clicked',on_btClicked)
> def on_btClicked(widget,event):
>   if data==0:
>  P=1
>   else:
>  P=2
>   return P
>
> How can I get P?
>
> Something like this doesn't work:
>
> bt.connect('clicked',P=on_btClicked)
>
> How can I return P???
>
>
> Thanks!
>
> Nick

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


Re: SPE question

2007-03-27 Thread [EMAIL PROTECTED]
I believe that just deleting the folders should work

Dick Moores wrote:
> At 03:37 AM 3/27/2007, [EMAIL PROTECTED] wrote:
> >On Mar 27, 11:39 am, "alain" <[EMAIL PROTECTED]> wrote:
> > > Hi,
> > >
> > > Could someone tell me how to uninstall SPE under windows?
> > >
> > > Alain
> >
> >Dunno about SPE, but most Python modules I've installed can
> >be uninstalled from control panel/add remove programs.
>
> SPE doesn't show up on my win XP add/remove programs list.
>
> Dick Moores

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


pygtk button event

2007-03-27 Thread [EMAIL PROTECTED]
Hi


i am trying to implement the following:

I want to be able to press a button, perform a task and return a
value.

my button is named button1 and I used glade to build the gui.

so, something like this should work


application=gtk.glade.XML('app.glade','app')
bt=app.get_widget('button1')
bt.connect('clicked',on_btClicked)
def on_btClicked(widget,event):
  if data==0:
 P=1
  else:
 P=2
  return P

How can I get P?

Something like this doesn't work:

bt.connect('clicked',P=on_btClicked)

How can I return P???


Thanks!

Nick

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


Re: plot dendrogram with python

2007-03-27 Thread martin . laloux
I use pycluster

http://bonsai.ims.u-tokyo.ac.jp/~mdehoon/software/cluster/software.htm#pycluster

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


Re: plot dendrogram with python

2007-03-27 Thread bearophileHUGS
Frank:
> does anyone know if there is a way to plot a dendrogram with python.
> Pylab or matplotlib do not provide such a function.

An ASCII solution:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/139422

Some graphics:
http://plone.org/products/phylogenetictree
http://www.bioinformatics.org/mavric/

Bye,
bearophile

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


tkinter MVC

2007-03-27 Thread Gigs_
Can someone give me example how to write text editor in tkintter with 
model-view-controler?
What goes to controler and what goes to model?



thanks in advance
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SPE question

2007-03-27 Thread Dick Moores
At 03:37 AM 3/27/2007, [EMAIL PROTECTED] wrote:
>On Mar 27, 11:39 am, "alain" <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > Could someone tell me how to uninstall SPE under windows?
> >
> > Alain
>
>Dunno about SPE, but most Python modules I've installed can
>be uninstalled from control panel/add remove programs.

SPE doesn't show up on my win XP add/remove programs list.

Dick Moores


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


Re: SPE question

2007-03-27 Thread irstas
On Mar 27, 11:39 am, "alain" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Could someone tell me how to uninstall SPE under windows?
>
> Alain

Dunno about SPE, but most Python modules I've installed can
be uninstalled from control panel/add remove programs.

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


Re: SPE question

2007-03-27 Thread Dick Moores
At 01:39 AM 3/27/2007, alain wrote:
>Hi,
>
>Could someone tell me how to uninstall SPE under windows?

Well, mine is in E:\Python25\Lib\site-packages\_spe, so I'd try 
deleting that folder.

Dick Moores 

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


sys.excepthook and threads

2007-03-27 Thread ian
Hi,

sys.excepthook don't work if an exception come in a thread...
It's normal or its a bug ? There are any tip ? look here :
http://spyced.blogspot.com/2005_06_01_archive.html

Thx


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


tkinter popup

2007-03-27 Thread Gigs_
Hi all

I cant figure out how to disable resizing of my popup window?
How to put this popup window to show in the middle of my text editor?
It is writen with Toplevel.


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


Re: Sending ECHO_REQUEST (pinging) with python

2007-03-27 Thread Jorgen Grahn
On Mon, 26 Mar 2007 16:50:09 +0200, Thomas Dybdahl Ahle <[EMAIL PROTECTED]> 
wrote:
> Den Mon, 26 Mar 2007 11:24:34 +0200 skrev Michal 'vorner' Vaner:
>> On Mon, Mar 26, 2007 at 08:30:16AM +0200, Thomas Dybdahl Ahle wrote:
>
>>> Do anybody know how to do this in python?
>
>> You need root for that and the ping command is allowed to have them by
>> suid bit. You can execute ping from inside python and use ping as is, if
>> you need.
>
> Yeah, I could execute ping, but it would lock me harder to the platform.

True; Linux ping and Solaris ping have incompatible flags and output.
I even believe several implementations are in use on Linux. Then add
Windows to the mix ...

-Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PDB does not allow jumping to first statement?

2007-03-27 Thread [EMAIL PROTECTED]
On Mar 26, 6:06 pm, "Chris Lasher" <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I have a simple script:
>
> ---
> #!/usr/bin/envpython
>
> a = 1
> b = 2
>
> c = a + b
>
> print c
> ---
>
> I launch said script withpdb:
>
> python-mpdbsimple.py
>
> I noticed that I absolutely cannot jump back to the first statement
> (line 3, "a = 1") using the jump command. I can jump to any other line
> BUT the first statement's using the "jump " command. I
> experience the same behavior with Winpdb and rpdb2. Why is this?
>
> Stumped,
> Chris

I tried on GNU/Linux and Python versions 2.4 and 2.5 and get the same
behavior. Best as I can tell, it looks like a bug in Python. pdb,
pydb, rpdb2 all handle the "jump" command by changing the frame
f_lineno value. When the corresponding code pointer has offset 0 (or
equivalently and more simlply as you put it, is the first statement)
this doesn't seem to work properly. But this also implies that all you
need to do is add something as the first statement. A docstring
comment, e.g.
"this is what my program does..."
comes to mind :-)

Lastly, I'll mention that I what most folks want to do is not jump to
the beginning of the program but rather *restart* it. The difference
here as applied to your example is seen in the way variables (e.g. a,
b, and c) are handled. In a "restart", those names would go back to
being undefined and referring to them before assigning to them would
cause a NameError exception. With "jump", they retain their existing
values.

In pydb (http://bashdb.sf.net/pydb) there are two variations of
restarting a program, one which preserves debugger state ("run") and
one which doesn't ("restart") as it is just a re-exec of the program.
In the presence of multiple threads the exec restart the only reliable
way I know of to force a restart.

Recently in Python's SVN the patch I submitted over a year ago was
applied, so if you prefer pdb and want the "run"-like restart, you can
use that.

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


Re: PDB does not allow jumping to first statement?

2007-03-27 Thread Duncan Booth
Peter Otten <[EMAIL PROTECTED]> wrote:

>> Which version of Python, and what happens when you try it?
>> 
>> It works fine for me with Python 2.5 on Windows:
>> 
>> C:\Temp>\python25\python -m pdb t.py
>>> c:\temp\t.py(3)()
>> -> a = 1
>> (Pdb) s
>>> c:\temp\t.py(4)()
>> -> b = 2
>> (Pdb) j 3
>>> c:\temp\t.py(3)()
>> -> a = 1
>> (Pdb)
> 
> It looks like you successfully jumped to the first line, but it will 
be
> skipped if you try to execute it:
> 

That's why I asked what actually happened. Yes, you and the OP seem to 
be correct, jumping to the first executable line in a module appears not 
to execute the line.

I verified (with a print statement in pdb) that assigning to 
self.curframe.f_lineno sets self.curframe.f_lineno and 
sel.curframe.f_lasti incorrectly:

C:\Temp>\python25\python -m pdb t.py
> c:\temp\t.py(3)()
-> a = 1
(Pdb) s
> c:\temp\t.py(4)()
-> b = 2
(Pdb) s
> c:\temp\t.py(5)()
-> a = 3
(Pdb) l
  1 #!/usr/bin/env python
  2
  3 a = 1
  4 b = 2
  5  -> a = 3
  6 c = a + b
  7 import dis, sys
  8 dis.dis(sys._getframe().f_code)
  9 print c
[EOF]
(Pdb) j 4
f_lineno 4 f_lasti 6
> c:\temp\t.py(4)()
-> b = 2
(Pdb) j 3
f_lineno 4 f_lasti 6
> c:\temp\t.py(3)()
-> a = 1
(Pdb) j 5
f_lineno 5 f_lasti 12
> c:\temp\t.py(5)()
-> a = 3
(Pdb) j 3
f_lineno 4 f_lasti 6
> c:\temp\t.py(3)()
-> a = 1
(Pdb)

The problem looks to be in frameobject.c:

addr = 0;
line = f->f_code->co_firstlineno;
new_lasti = -1;
for (offset = 0; offset < lnotab_len; offset += 2) {
addr += lnotab[offset];
line += lnotab[offset+1];
if (line >= new_lineno) {
new_lasti = addr;
new_lineno = line;
break;
}
}

The first bytes in lnotab are the length and line increment for line 3 
(i.e. 6, 1). If line==f->f_code->co_firstlineno it should set new_lasti=
0, new_lineno=line but the loop still executes once which increments 
new_lasti and new_lineno to the next line (6, 4).


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


plot dendrogram with python

2007-03-27 Thread Frank
Hi,

does anyone know if there is a way to plot a dendrogram with python.
Pylab or matplotlib do not provide such a function.

Thanks!

Frank

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


Re: __init__.py

2007-03-27 Thread Steve Holden
Jorgen Grahn wrote:
> On Mon, 26 Mar 2007 08:27:19 +0200, Tina I <[EMAIL PROTECTED]> wrote:
>> Tina I wrote:
>>> When looking at other peoples code (to learn from it) I keep seeing an 
>>> empty file named "__init__.py". What's the purpose of this?
>>>
>>> Thanks
>>> Tina
>> Duh! Never mind... found it.
>> Kinda neat actually :)
> 
> /What/ was neat? It's polite in cases like this to explain what the
> answer or solution was.
> 
> I have never seen an empty __init__.py, and I'd like to know what its
> purpose could be.
> 
> BR,
> /Jorgen
> 
The presence of an __init__.py marks a directory as the root of a Python 
package, which means other modules can be found in it. This allows you 
to import names with multiple levels of dots, which are modules within 
packages.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings   http://holdenweb.blogspot.com

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


Re: __init__.py

2007-03-27 Thread Jorgen Grahn
On Mon, 26 Mar 2007 08:27:19 +0200, Tina I <[EMAIL PROTECTED]> wrote:
> Tina I wrote:
>> When looking at other peoples code (to learn from it) I keep seeing an 
>> empty file named "__init__.py". What's the purpose of this?
>> 
>> Thanks
>> Tina
>
> Duh! Never mind... found it.
> Kinda neat actually :)

/What/ was neat? It's polite in cases like this to explain what the
answer or solution was.

I have never seen an empty __init__.py, and I'd like to know what its
purpose could be.

BR,
/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter Toplevel geometry

2007-03-27 Thread Chris

> A TRULY good way to show your thanks for help like this
> is to write up what you learned at theTkinterWiki 
> http://tkinter.unpythonic.net/wiki/>.  Note:
> A.  You have to log in to edit pages
> on this particular Wiki.  If you
> decide to join us, then, you'll
> first need to create an account.

I'll do that, yes. I guess I should create a 'Toplevel' page and put
the information on there? Unless someone can suggest something better.

I also wonder if I should have posted this question to the tkinter-
discuss mailing list (see http://tkinter.unpythonic.net/wiki/TkinterDiscuss)
instead of to comp.lang.python. However, I wasn't aware of that list
before, and it's not linked to from the python.org 'community' page
(as far as I can see - and in fact, the python.org pages imply that
tkinter questions should be asked on comp.lang.python). I'm new to
tkinter, so it wasn't immediately clear where to get help.

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


SPE question

2007-03-27 Thread alain
Hi,

Could someone tell me how to uninstall SPE under windows?

Alain

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


Re: fetch html page via isa proxy

2007-03-27 Thread Radek
> So you have already tried NTLM Authorization Proxy 
> Server?http://ntlmaps.sourceforge.net/
> This used to work fine for me but that was at least 3-4 years ago.

Actually NTLM proxy server works for most intranet addresses. Not for
the outside Internet ones, though.

Radek

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


Re: with timeout(...):

2007-03-27 Thread Nick Craig-Wood
Hendrik van Rooyen <[EMAIL PROTECTED]> wrote:
>  so Diez is probably right that the way to go is to put the timer in the
>  python interpreter loop, as its the only thing around that you could 
>  more or less trust to run all the time.
> 
>  But then it will not read as nice as Nick's wish, but more like this:
> 
>  id = setup_callback(error_routine, timeout_in_milliseconds)
>  long_running_stuff_that_can_block_on_IO(foo, bar, baz)
>  cancel_callback(id)
>  print "Hooray it worked !! "
>  sys.exit()
> 
>  def error_routine():
>  print "toughies it took too long - your chocolate is toast"
>  attempt_at_recovery_or_explanation(foo, bar, baz)
> 
>  Much more ugly.

I could live with that!

It could be made to work I'm sure by getting the interpreter to check
for timeouts every few hundred bytecodes (like it does for thread
switching).

>  But would be useful to be able to do without messing with
>  threads and GUI and imports. 
>  Could be hard to implement as the interpreter would have 
>  to be assured of getting control back periodically, so a 
>  ticker interrupt routine is called for - begins to sound more 
>  like a kernel function to me.  
>  Isn't there something available that could be got at via ctypes?

I think if we aren't executing python bytecodes (ie are blocked in the
kernel or running in some C extension) then we shouldn't try to
interrupt.  It may be possible - under unix you'd send a signal -
which python would act upon next time it got control back to the
interpreter, but I don't think it would buy us anything except a whole
host of problems!

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: with timeout(...):

2007-03-27 Thread Nick Craig-Wood
Klaas <[EMAIL PROTECTED]> wrote:
>  On Mar 26, 3:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
> > Did anyone write a contextmanager implementing a timeout for
> > python2.5?
> >
> > I'd love to be able to write something like
> >
> > with timeout(5.0) as exceeded:
> > some_long_running_stuff()
> > if exceeded:
> > print "Oops - took too long!"
> >
> > And have it work reliably and in a cross platform way!
> 
>  Doubt it.  But you could try:
> 
>  class TimeoutException(BaseException):
> pass
> 
>  class timeout(object):
> def __init__(self, limit_t):
> self.limit_t = limit
> self.timer = None
> self.timed_out = False
> def __nonzero__(self):
> return self.timed_out
> def __enter__(self):
> self.timer = threading.Timer(self.limit_t, ...)
> self.timer.start()
> return self
> def __exit__(self, exc_c, exc, tb):
> if exc_c is TimeoutException:
>self.timed_out = True
>return True # suppress exception
> return False # raise exception (maybe)
> 
>  where '...' is a ctypes call to raise the given exception in the
>  current thread (the capi call PyThreadState_SetAsyncExc)
> 
>  Definitely not fool-proof, as it relies on thread switching.  Also,
>  lock acquisition can't be interrupted, anyway.  Also, this style of
>  programming is rather unsafe.
> 
>  But I bet it would work frequently.

Here is my effort...  You'll note from the comments that there are
lots of tricky bits.

It isn't perfect though as it sometimes leaves behind threads (see the
FIXME).  I don't think it crashes any more though!



"""
General purpose timeout mechanism not using alarm(), ie cross platform

Eg

from timeout import Timeout, TimeoutError

def might_infinite_loop(arg):
while 1:
pass

try:
Timeout(10, might_infinite_loop, "some arg")
except TimeoutError:
print "Oops took too long"
else:
print "Ran just fine"

"""

import threading
import time
import sys
import ctypes
import os

class TimeoutError(Exception):
"""Thrown on a timeout"""
PyThreadState_SetAsyncExc = ctypes.pythonapi.PyThreadState_SetAsyncExc
_c_TimeoutError = ctypes.py_object(TimeoutError)

class Timeout(threading.Thread):
"""
A General purpose timeout class
timeout is int/float in seconds
action is a callable
*args, **kwargs are passed to the callable
"""
def __init__(self, timeout, action, *args, **kwargs):
threading.Thread.__init__(self)
self.action = action
self.args = args
self.kwargs = kwargs
self.stopped = False
self.exc_value = None
self.end_lock = threading.Lock()
# start subtask
self.setDaemon(True)# FIXME this shouldn't be needed 
but is, indicating sub tasks aren't ending
self.start()
# Wait for subtask to end naturally
self.join(timeout)
# Use end_lock to kill the thread in a non-racy
# fashion. (Using isAlive is racy).  Poking exceptions into
# the Thread cleanup code isn't a good idea either
if self.end_lock.acquire(False):
# gained end_lock => sub thread is still running
# sub thread is still running so kill it with a TimeoutError
self.exc_value = TimeoutError()
PyThreadState_SetAsyncExc(self.id, _c_TimeoutError)
# release the lock so it can progress into thread cleanup
self.end_lock.release()
# shouldn't block since we've killed the thread
self.join()
# re-raise any exception
if self.exc_value:
raise self.exc_value
def run(self):
self.id = threading._get_ident()
try:
self.action(*self.args, **self.kwargs)
except:
self.exc_value = sys.exc_value
# only end if we can acquire the end_lock
self.end_lock.acquire()

if __name__ == "__main__":

def _spin(t):
"""Spins for t seconds"""
start = time.time()
end = start + t
while time.time() < end:
pass

def _test_time_limit(name, expecting_time_out, t_limit, fn, *args, 
**kwargs):
"""Test Timeout"""
start = time.time()

if expecting_time_out:
print "Test",name,"should timeout"
else:
print "Test",name,"shouldn't timeout"

try:
Timeout(t_limit, fn, *args, **kwargs)
except TimeoutError, e:
if expecting_time_out:
print "Timeout generated OK"
else:
raise RuntimeError("Wasn't expecting TimeoutError Here")
else:
if expecting_time_out:
raise RuntimeError("Was expecting TimeoutError Here")
else:
print "No TimeoutError generated OK"

elapsed = time.time() - start
print "Th

<    1   2