Threads

In my program I am creating a thread, running it, and from within the thread adding a button to the parent window (more specifically addding it to the parent window's sizer). For whatever reason, the new button is "invisible." Space is made for it by the sizer, but it just doesnt show up. Do I need to do something special if I am adding to a window from a thread?

Gilad

Gilad Suberri wrote:

In my program I am creating a thread, running it, and from within the
thread adding a button to the parent window (more specifically
addding it to the parent window's sizer). For whatever reason, the
new button is "invisible." Space is made for it by the sizer, but it
just doesnt show up. Do I need to do something special if I am adding
to a window from a thread?

Yes. *Don't*

All GUI objects must be created and accessed from the main GUI thread. You need to have your thread send a message or event that will cause the GUI to be updated in the context of the main thread. Using wxCallAfter to later call some function to do the work is an easy way to do it.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

i've made a wxwindow
and i paint some things on the dc with onpaint event
to refresh the content, when i need to do it, i use the method Refresh()
everythings works like a charm ...

BUT ...

i find that, it's flash a lot the redraw (we can see, with eyes, that there are some horizontal lines while the redrawing process ... (on a p4 3ghz))
it makes not good ... it seems the screen flashs ...

is there a way, to synchronize the redraw process with a "vertical top" of the screen ?
or is there a way to do a double buffering system to make it more smoother ?
in an common way : is it possible to make it less flashy ? more smoother ? (i'd like not to see the redraw process) how to do that ? does wxpython provide a method to prevent that ?

i'm pretty sure it's possible ... because wxpython is wonderful !
and many thanks to robin for its wonderful work !!!

i find that, it's flash a lot the redraw

Use double buffering:

http://wiki.wxpython.org/index.cgi/DoubleBufferedDrawing

By default before you get asked to paint, the area you will
paint will be erased to the background colour. This is necessary
for example if you are only going to write some text on top.
If you will be drawing every pixel then there is no need to
erase the background (the buffered dc redraws every pixel).

Add wxNO_FULL_REPAINT_ON_RESIZE to your window style. Also
add a do nothing background eraser:

    EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)

def OnEraseBackground(self, _):
        pass

Roger

Roger Binns wrote:

> i find that, it's flash a lot the redraw

Use double buffering:

http://wiki.wxpython.org/index.cgi/DoubleBufferedDrawing

You'll probably figure it out from that fabulous Wiki page (I wrote it
:wink: ). There are a coupl eof other relevant Wiki pages that you should
take a look at as well. I have an added note:

Only use OnPaint and a wxPaintDC when the system calls it (an Paint
event). If you need to update what's in the window because of something
that happened inside your program, use a wxClientDC. Generally, you want
to have a Draw(self, dc) method that takes a dc as input and draws to
it. In your OnPaint method, you create the wxPaintDC and pass it to
self.Draw(). If you want to re-draw any other time, you create a
wxClientDC, and pass that to self.Draw().

You're flashing is caused by the Refresh() call: it clears the window
first, then calls OnPaint. If your drawing is fairly simple, there may
be no reason to double buffer.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

thanx a lot for this tip

Roger Binns a écrit :

···

i find that, it's flash a lot the redraw
   
Use double buffering:

http://wiki.wxpython.org/index.cgi/DoubleBufferedDrawing

By default before you get asked to paint, the area you will
paint will be erased to the background colour. This is necessary
for example if you are only going to write some text on top.
If you will be drawing every pixel then there is no need to
erase the background (the buffered dc redraws every pixel).

Add wxNO_FULL_REPAINT_ON_RESIZE to your window style. Also
add a do nothing background eraser:

   EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)

def OnEraseBackground(self, _):
       pass

Roger

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org