custom widget on windows

To trigger a real paint event you should use Refresh. This will allow the paint event to happen naturally, as the system normally would for any other repaint situation. To cause it to be sent immediately (instead of when the system decides it is a good time to send it) then also call Update.

custombutton.py (4.53 KB)

···

On 7/27/11 8:06 AM, Neacsa Bogdan Valentin wrote:

hello,

I've created a custom widget working on MacOS. However when I try to run
it on windows it gives the following error:

wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed at
..\..\src\m
sw\dcclient.cpp(219) in wxPaintDC::wxPaintDC(): wxPaintDC may be created
only in
EVT_PAINT handler!

Now I've atached the widget to this email as well as the look on MacOS
and what it becomes on windows. Now if I remove the:

event = wx.CommandEvent(wx.wxEVT_PAINT, self.GetId())
event.SetInt(0)
event.SetEventObject(self)
self.GetEventHandler().ProcessEvent(event)

From the __init__ the error is gone however this also causes the
following: On MacOS the widget isn't displayed at all, and on widows
it's still not displayed properly. Any suggestions ?

--
Robin Dunn
Software Craftsman

Do not Refresh() from within the paint event handler. That will trigger another paint event ASAP, and then there is another Refresh and the cycle continues. This is the cause of the flicker, because everything is being redrawn as fast as it can. It's also the cause of the other buttons not being drawn because they never get a chance to process their own paint events.

Also it would be nice if you would send runnable samples to this list so whoever helps you does not have to write that code themselves. Use the "if __name__ == '__main__':" trick if you don't want the test code to be executed when the module is imported from other modules. MakingSampleApps - wxPyWiki

···

On 7/28/11 12:31 AM, Neacsa Bogdan Valentin wrote:

Ok, I've used Refresh to trigger the paint and did some changes to
DoGetBestSize(). Now the buttons have the correct size and on MacOS
everything works but something is still wrong on windows. Now the
situation is really strange so I've atached two pics to show the problem.

The "withDefault" shows the menu using only standard wx.Buttons.

In the "withCustom" the 4 left side buttons are CustomButton and the
right side button is a standard wxButton.

Now with the standard buttons you can see everthing works fine, but when
I try to add my custom buttons:

- Only the first button is actually drawn but with VERY strong flickering.
- The following custom buttons are there but instead of being actualy
drawn something from the background is shown (In the print I put up a
terminal was running behind the application)
- Even standard buttons from wxButton are not drawn properly after
adding a CustomButton (the rigth side button from "withCustom" is a
wx.Button.

Any suggestions ?

--
Robin Dunn
Software Craftsman