[Tutor] Python and wx questions

Magnus Lyckå magnus@thinkware.se
Tue Jun 17 07:56:40 2003


At 10:53 2003-06-17 +0200, Krisztian Kepes wrote:
>I want to port an Delphi program to wxPython/Python.

For wxPython questions, the wxPython web site and mailing
list are probably better than tutor...

>1.
>When I write an wx application that is making a long time
>process of datas, how I avoid the blank windows, how I refresh ?
>I think the solution is thread, but I don't know (in Python).

First of all. Remember that only one thread can interact with
wxPython, or you will get into trouble. Secondly, look at
http://wiki.wxpython.org/index.cgi/LongRunningTasks

As you notice, there are several ways to do it, and threads
is not the only solution.

>2.
>How I allocate a fixed length list in one command ?
>Have the Python a command to allocate in one step ?
>Like:
>  SetLength(List,50);
>I want more efficiency than this:
>List=[];for i in range(0,50):List.Add(None)

That's not Python. I think you mean ".append()"

>or a shorter code.

"You have to unlearn what you have learnt" as Yoda said.
Python is not as complicated as Pascal you know... ;)

l = [None] * 50

But be careful with mutable objects when you do things like
that.

 >>> l = [0]*3
 >>> m = [l]*3

(This is the same as "m = [[0]*3]*3", except that we
also define the name "l".)

 >>> print m
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
 >>> m[1][1] = 5
 >>> print m
[[0, 5, 0], [0, 5, 0], [0, 5, 0]]

You see? It's the same list 'l' referenced three times inside 'm'.

I this case, you could instead do:

 >>> m = [[0]*3 for x in range(3)]
 >>> m
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
 >>> m[1][1] = 5
 >>> m
[[0, 0, 0], [0, 5, 0], [0, 0, 0]]

Here, you create a new list object with three 0's for each
loop in the list comprehension.

>3.
>Have the wx an timer or a dummy procedure ?
>I want it to use to periodically get the process thread's datas
>(report), and write it to log memo.
>Have I register my owned dummy proc ?

Sure. Look under "Process and Events" in the wxPython demo.
Both threads and timers are shown there.


--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The Agile Programming Language