How to write GUI and event separately in wxPython??

Discussion in 'Python' started by Jia Lu, Jul 30, 2007.

  1. Jia Lu

    Jia Lu Guest

    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.
    Jia Lu, Jul 30, 2007
    #1
    1. Advertising

  2. 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
    Marc 'BlackJack' Rintsch, Jul 30, 2007
    #2
    1. Advertising

  3. Jia Lu

    Steve Holden Guest

    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 -------------
    Steve Holden, Jul 30, 2007
    #3
  4. 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
    Marc 'BlackJack' Rintsch, Jul 30, 2007
    #4
  5. Jia Lu

    Guest

    On Jul 30, 1:34 am, Jia Lu <> wrote:
    > 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, 2007
    #5
  6. Jia Lu

    Steve Holden Guest

    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 -------------
    Steve Holden, Jul 30, 2007
    #6
  7. Jia Lu

    Chris Mellon Guest

    On 7/30/07, Steve Holden <> wrote:
    > 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..
    Chris Mellon, Jul 30, 2007
    #7
  8. Jia Lu

    Steve Holden Guest

    Chris Mellon wrote:
    > On 7/30/07, Steve Holden <> wrote:
    >> 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 -------------
    Steve Holden, Jul 30, 2007
    #8
  9. 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
    Marc 'BlackJack' Rintsch, Jul 30, 2007
    #9
  10. Jia Lu

    Guest

    On Jul 30, 11:42 am, "Chris Mellon" <> 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


    > 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, 2007
    #10
  11. Jia Lu

    Steve Holden Guest

    wrote:
    > On Jul 30, 11:42 am, "Chris Mellon" <> 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

    >
    >> 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 -------------
    Steve Holden, Jul 30, 2007
    #11
  12. Jia Lu

    Steve Holden Guest

    wrote:
    > On Jul 30, 11:42 am, "Chris Mellon" <> 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

    >
    >> 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 -------------
    Steve Holden, Jul 30, 2007
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ladygrinningsoul

    Reading stdout and stderr separately

    ladygrinningsoul, Nov 18, 2004, in forum: Perl
    Replies:
    3
    Views:
    1,031
    Alexey A. Kiritchun
    Apr 25, 2005
  2. BH
    Replies:
    4
    Views:
    1,078
  3. ulysses
    Replies:
    4
    Views:
    757
    Werner Schiendl
    Oct 22, 2003
  4. Davy
    Replies:
    2
    Views:
    206
  5. yoodavid
    Replies:
    64
    Views:
    585
    Tim Rentsch
    Oct 24, 2013
Loading...

Share This Page