473,378 Members | 1,429 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to write GUI and event separately in wxPython??

HI all

I am making an application with wxpython.
But I got a problem when I want to change the display string
according to process status.

I passed the frame to the processing function and use the
frame.txtobj to change displaying strings.

I found it is a bad method to do that.
Can any one tell me how to do that usually?
( How to separate GUI and Control code? )

Thank you.

Jul 30 '07 #1
11 1423
On Sun, 29 Jul 2007 23:34:14 -0700, Jia Lu wrote:
I am making an application with wxpython.
But I got a problem when I want to change the display string
according to process status.

I passed the frame to the processing function and use the
frame.txtobj to change displaying strings.

I found it is a bad method to do that.
Can any one tell me how to do that usually?
( How to separate GUI and Control code? )
One possibility here is to give a callback function into the worker
function that gets called while the function does it's work. Simple
example:

def do_work(arguments, callback=lambda msg: None):
callback('Start processing.')
for percent in xrange(0, 101):
callback('finished %d%%...' % percent)
callback('Done.')

Ciao,
Marc 'BlackJack' Rintsch
Jul 30 '07 #2
Marc 'BlackJack' Rintsch wrote:
On Sun, 29 Jul 2007 23:34:14 -0700, Jia Lu wrote:
> I am making an application with wxpython.
But I got a problem when I want to change the display string
according to process status.

I passed the frame to the processing function and use the
frame.txtobj to change displaying strings.

I found it is a bad method to do that.
Can any one tell me how to do that usually?
( How to separate GUI and Control code? )

One possibility here is to give a callback function into the worker
function that gets called while the function does it's work. Simple
example:

def do_work(arguments, callback=lambda msg: None):
callback('Start processing.')
for percent in xrange(0, 101):
callback('finished %d%%...' % percent)
callback('Done.')
>>[x for x in xrange(0, 101)] == [y for y in xrange(101)]
True
>>>
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Jul 30 '07 #3
On Mon, 30 Jul 2007 06:32:55 -0400, Steve Holden wrote:
>>[x for x in xrange(0, 101)] == [y for y in xrange(101)]
True
First I thought: Why the unnecessary list comprehension but to my surprise:

In [33]: xrange(42) == xrange(42)
Out[33]: False

That's strange.

Ciao,
Marc 'BlackJack' Rintsch
Jul 30 '07 #4
On Jul 30, 1:34 am, Jia Lu <Roka...@gmail.comwrote:
HI all

I am making an application with wxpython.
But I got a problem when I want to change the display string
according to process status.

I passed the frame to the processing function and use the
frame.txtobj to change displaying strings.

I found it is a bad method to do that.
Can any one tell me how to do that usually?
( How to separate GUI and Control code? )

Thank you.
If you're doing a long running task that needs to send data
periodically to the GUI front-end for status, there's some good ways
listed here: http://wiki.wxpython.org/LongRunningTasks

The wiki seems down right now (8:40 CST 07/30/2007), but hopefully
it'll be up soon.

Mike

Jul 30 '07 #5
Marc 'BlackJack' Rintsch wrote:
On Mon, 30 Jul 2007 06:32:55 -0400, Steve Holden wrote:
> >>[x for x in xrange(0, 101)] == [y for y in xrange(101)]
True

First I thought: Why the unnecessary list comprehension but to my surprise:

In [33]: xrange(42) == xrange(42)
Out[33]: False

That's strange.
Not so strange really. The two xrange objects are different (though I
confess I haven't looked to see how they implement comparisons), but
iterating over them produces the same result.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Jul 30 '07 #6
On 7/30/07, Steve Holden <st***@holdenweb.comwrote:
Marc 'BlackJack' Rintsch wrote:
On Mon, 30 Jul 2007 06:32:55 -0400, Steve Holden wrote:
>>[x for x in xrange(0, 101)] == [y for y in xrange(101)]
True
First I thought: Why the unnecessary list comprehension but to my surprise:

In [33]: xrange(42) == xrange(42)
Out[33]: False

That's strange.
Not so strange really. The two xrange objects are different (though I
confess I haven't looked to see how they implement comparisons), but
iterating over them produces the same result.

nitpick: list(xrange(42)) == list(xrange(42)) is slightly more concise
than the list comp..
Jul 30 '07 #7
Chris Mellon wrote:
On 7/30/07, Steve Holden <st***@holdenweb.comwrote:
>Marc 'BlackJack' Rintsch wrote:
>>On Mon, 30 Jul 2007 06:32:55 -0400, Steve Holden wrote:

>>[x for x in xrange(0, 101)] == [y for y in xrange(101)]
True
First I thought: Why the unnecessary list comprehension but to my surprise:

In [33]: xrange(42) == xrange(42)
Out[33]: False

That's strange.
Not so strange really. The two xrange objects are different (though I
confess I haven't looked to see how they implement comparisons), but
iterating over them produces the same result.


nitpick: list(xrange(42)) == list(xrange(42)) is slightly more concise
than the list comp..
Indeed. I wonder if anyone will pick a nit with the nit you picked on my
nitpick ...

nitty-gritti-ly y'rs - steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Jul 30 '07 #8
On Mon, 30 Jul 2007 11:16:01 -0400, Steve Holden wrote:
Marc 'BlackJack' Rintsch wrote:
>First I thought: Why the unnecessary list comprehension but to my surprise:

In [33]: xrange(42) == xrange(42)
Out[33]: False

That's strange.
Not so strange really. The two xrange objects are different (though I
confess I haven't looked to see how they implement comparisons), but
iterating over them produces the same result.
They are different objects, so are range(23) and another range(23) but
those compare equal. Somehow I expected two seemingly equal `xrange`
objects compare equal too.

Ciao,
Marc 'BlackJack' Rintsch
Jul 30 '07 #9
On Jul 30, 11:42 am, "Chris Mellon" <arka...@gmail.comwrote:
On Mon, 30 Jul 2007 06:32:55 -0400, Steve Holden wrote:
> >>[x for x in xrange(0, 101)] == [y for y in xrange(101)]
>True
nitpick: list(xrange(42)) == list(xrange(42)) is slightly more concise
than the list comp..
Not that it has anything to do with this topic anymore, but I find the
list comp a bit clearer for expressing the thought 'each element in
one is the same as the coresponding element in the other, or: the
sequences are identical' -- the list() version would proabably have
had me going 'huh?' even longer ^_^.
--
[star for star in weaver]

Jul 30 '07 #10
st*********@gmail.com wrote:
On Jul 30, 11:42 am, "Chris Mellon" <arka...@gmail.comwrote:
>>>On Mon, 30 Jul 2007 06:32:55 -0400, Steve Holden wrote:
>>[x for x in xrange(0, 101)] == [y for y in xrange(101)]
True
>nitpick: list(xrange(42)) == list(xrange(42)) is slightly more concise
than the list comp..

Not that it has anything to do with this topic anymore, but I find the
list comp a bit clearer for expressing the thought 'each element in
one is the same as the coresponding element in the other, or: the
sequences are identical' -- the list() version would proabably have
had me going 'huh?' even longer ^_^.
--
[star for star in weaver]
Here's another one, a little more obscure still, but only valid in 2.5
because of all():
>>all(x==y for (x, y) in zip(xrange(0, 101), xrange(101)))
True
>>>
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
Jul 30 '07 #11
st*********@gmail.com wrote:
On Jul 30, 11:42 am, "Chris Mellon" <arka...@gmail.comwrote:
>>>On Mon, 30 Jul 2007 06:32:55 -0400, Steve Holden wrote:
>>[x for x in xrange(0, 101)] == [y for y in xrange(101)]
True
>nitpick: list(xrange(42)) == list(xrange(42)) is slightly more concise
than the list comp..

Not that it has anything to do with this topic anymore, but I find the
list comp a bit clearer for expressing the thought 'each element in
one is the same as the coresponding element in the other, or: the
sequences are identical' -- the list() version would proabably have
had me going 'huh?' even longer ^_^.
--
[star for star in weaver]
Here's another one, a little more obscure still, but only valid in 2.5
because of all():
>>all(x==y for (x, y) in zip(xrange(0, 101), xrange(101)))
True
>>>
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Jul 30 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: wang xiaoyu | last post by:
Hello: i want use activex in wxpython program,but when i use MakeActiveXClass an exception occurs. this is my source code dealing the DICOM ocx.I must note that in this program "hwtxcontrol" is...
3
by: Robert | last post by:
Hello list, could somebody point me to a good reference about wxPython event handling? I have seen many examples but which one is the best. Waht are the advantages and disadvantages? Can you...
2
by: Daniel Bickett | last post by:
Hello, I am writing an application using two event-driven libraries: wxPython, and twisted. The first problem I encountered in the program is the confliction between the two all-consuming...
22
by: Glurt Wuntal | last post by:
I am a newbie with Python. It's a great language, but I would like to be able to present a simple gui menu for some of my scripts; something better than using 'raw_input' prompts. Any...
2
by: Kevin Walzer | last post by:
I'm porting a Tkinter application to wxPython and had a question about wxPython's event loop. The Tkinter app provides a GUI to a command-line tool. It gathers user input, and opens an...
1
by: defireman | last post by:
Hi, Sorry for asking a newbie question, but I am currently using wxPython 2.6, and I don't know how to get the properties of an event object in wxPython when handling events. Is there some sort of...
12
by: Matt Bitten | last post by:
I've got a wxPython program that needs to do some drawing on a DC on a regular basis, whether or not a paint event happens. I know how to make a ClientDC to do the drawing in, and I know what...
7
by: Erik Lind | last post by:
I'd appreciate any pointer on a simple way to tell within an event handler where the event came from. I want to have "while" condition in a handler to stop or change processing if an event occurs...
3
by: lee.walczak | last post by:
Hi, I have just started writing a GUI using wxpython after finding a limitation using Tkinter. I have read most tutorials on wxpython and slowly becoming accustomed considering I started with...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.