473,778 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxPython - drawing without paint event

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 drawing calls to
make. But how do I make it all happen? After I call MainLoop, none of
my code gets called unless there is an event. And there is no event,
so my code doesn't get called. What do I do?

Aug 10 '07 #1
12 6314
On Aug 9, 7:46 pm, Matt Bitten <mbitte...@yaho o.comwrote:
I've got a wxPython program that needs to do some drawing on a DC on a
regular basis.... And there is no event,
so my code doesn't get called. What do I do?
Then the event is: "on a regular basis", i.e. the passage of time.
You can use a wx.Timer to create events at regular intervals, which
your code can respond to:

-------
import wx

class MyFrame(wx.Fram e):
def __init__(self):
wx.Frame.__init __(self, None, -1, "My Window")

panel = wx.Panel(self, -1)
self.text = wx.StaticText(p anel, -1, "hello", pos=(40, 40) )

self.timer = wx.Timer(self)
self.Bind(wx.EV T_TIMER, self.on_timer_e vent)
self.timer.Star t(milliseconds= 1000, oneShot=False)

def on_timer_event( self, event):
if self.text.GetLa bel() == "hello":
self.text.SetLa bel("goodbye")
else:
self.text.SetLa bel("hello")
app = wx.App(redirect =False)

win = MyFrame()
win.Show()

app.MainLoop()
----------------

Make sure you save the timer in self so that you have a permanent
reference to the object, otherwise the timer will be destroyed when
__init_ returns.


Aug 10 '07 #2
On Aug 10, 1:40 am, 7stud <bbxx789_0...@y ahoo.comwrote:
On Aug 9, 7:46 pm, Matt Bitten <mbitte...@yaho o.comwrote:
I've got a wxPython program that needs to do some drawing on a DC on a
regular basis.... And there is no event,
so my code doesn't get called. What do I do?

Then the event is: "on a regular basis", i.e. the passage of time.
You can use a wx.Timer to create events at regular intervals, which
your code can respond to:
...
Thanks!

On a related topic, it seems like it would be nice to do *all* drawing
in
response to paint events. When I get an event from the timer, I would
just tell wx that part of the window needs redrawing, and depend on it
to give me a paint even when nothing of higher priority needs to be
done.
I've seen this kind of logic recommended in other GUI tookits. Is it a
good idea in wxPython, and, if so, how does one do it?

Aug 11 '07 #3
gl************@ gmail.com wrote:
On a related topic, it seems like it would be nice to do *all*
drawing in
response to paint events. When I get an event from the timer, I
would just tell wx that part of the window needs redrawing, and
depend on it to give me a paint even when nothing of higher
priority needs to be done.
I've seen this kind of logic recommended in other GUI tookits. Is
it a good idea in wxPython, and, if so, how does one do it?
At least it is not required -- there are device contexts for use
inside and outside of paint events.

One nice strategy from an example in "wxPython in Action" is the
following:

* the frame has Draw methods that draw into a BufferedDC, which is
chained to a bitmap member

* inside the paint method, the bitmap member is drawn to screen

Regards,
Björn

--
BOFH excuse #393:

Interference from the Van Allen Belt.

Aug 11 '07 #4
On Aug 11, 3:31 am, Bjoern Schliessmann <usenet-
mail-0306.20.chr0n.. .@spamgourmet.c omwrote:
glenn.chapp...@ gmail.com wrote:
On a related topic, it seems like it would be nice to do *all*
drawing in
response topaintevents. When I get aneventfrom the timer, I
would just tell wx that part of the window needs redrawing, and
depend on it to give me apainteven when nothing of higher
priority needs to be done.

One nice strategy from an example in "wxPython in Action" is the
following:

* the frame has Draw methods that draw into a BufferedDC, which is
chained to a bitmap member

* inside thepaintmethod, the bitmap member is drawn to screen
Okay, but how do I tell wx that it needs to send me a paint event?

Aug 12 '07 #5
On Aug 11, 7:59 pm, glenn.chapp...@ gmail.com wrote:
On Aug 11, 3:31 am, Bjoern Schliessmann <usenet-

mail-0306.20.chr0n.. .@spamgourmet.c omwrote:
glenn.chapp...@ gmail.com wrote:
On a related topic, it seems like it would be nice to do *all*
drawing in
response topaintevents. When I get aneventfrom the timer, I
would just tell wx that part of the window needs redrawing, and
depend on it to give me apainteven when nothing of higher
priority needs to be done.
One nice strategy from an example in "wxPython in Action" is the
following:
* the frame has Draw methods that draw into a BufferedDC, which is
chained to a bitmap member
* inside thepaintmethod, the bitmap member is drawn to screen

Okay, but how do I tell wx that it needs to send me a paint event?
Try this:

--------------
import wx

class MyFrame(wx.Fram e):
def __init__(self):
wx.Frame.__init __(self, None, -1, "My Window")

panel = wx.Panel(self, -1)
self.text = wx.StaticText(p anel, -1, "hello", pos=(40, 40) )

self.timer = wx.Timer(self)
self.Bind(wx.EV T_TIMER, self.on_timer_e vent)
self.timer.Star t(milliseconds= 1000, oneShot=False)

self.Bind(wx.EV T_PAINT, self.on_paint)

def on_timer_event( self, event):
self.GetEventHa ndler().Process Event(wx.PaintE vent())

def on_paint(self, event):
print "execution entered on_paint"

app = wx.App(redirect =False)

win = MyFrame()
win.Show()

app.MainLoop()
------------

I'm not sure why the call should be
self.GetEventHa ndler().Process Event() instead of just
self.ProcessEve nt().

Aug 12 '07 #6
gl************@ gmail.com wrote:
Okay, but how do I tell wx that it needs to send me a paint event?
It will send it on its own. You just need to bind your OnPaint (or
similar) method to it like 7stud demonstrates.

I really recommend reading "wxPython in Action", or at least the
tutorial.

Regards,
Björn

--
BOFH excuse #273:

The cord jumped over and hit the power switch.

Aug 12 '07 #7
On Aug 12, 6:06 am, Bjoern Schliessmann <usenet-
mail-0306.20.chr0n.. .@spamgourmet.c omwrote:
I really recommend reading "wxPython in Action", or at least the
tutorial.
I don't. "wxPython in Action" is by far the worst computer book I've
ever purchased. It's poorly organized, poorly written, and full of
mistakes--and it's expensive. The fact that the authors foist that
piece of junk on unsuspecting newbies is a crime.

Aug 12 '07 #8
On Aug 12, 2:20 pm, Bjoern Schliessmann <usenet-
mail-0306.20.chr0n.. .@spamgourmet.c omwrote:
But any suggestions what's
better for a beginner? The (incomplete) tutorial surely not.
Another GUI toolkit.
Aug 12 '07 #9
7stud wrote:
On Aug 12, 2:20 pm, Bjoern Schliessmann <usenet-
>But any suggestions what's
better for a beginner? The (incomplete) tutorial surely not.
Another GUI toolkit.
So it seems your dislike is not for the book, but for the toolkit.

Regards,
Björn

--
BOFH excuse #414:

tachyon emissions overloading the system

Aug 12 '07 #10

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

Similar topics

2
5984
by: Rene | last post by:
Currently, the paint even will only acknowledge painting going on inside of the ClipRectangle, any of the drawing that is outside of the ClipRectangle is ignored. How can I get the paint event to redraw Everything?
7
1689
by: Schorschi | last post by:
I know there is a way to do this, but I don't know how. Via a custom event? I have some code that I only want to run during a paint event. I could build a form instance that has the code and inherit it in all my other forms, but a simple event link? if that is the right term would be easier? Thx.
5
2011
by: active | last post by:
This is what I do in a PictureBox New: b1 = New Drawing.Bitmap(Width, Height, Me.CreateGraphics()) g1 = Graphics.FromImage(b1) Someplace I do g1.DrawString.........
4
11699
by: Aaron Smith | last post by:
I have a panel that I have in the paint event to draw a Raised 3d border around it.. The problem is, if a msgbox is popped up or a tooltip is displayed, it leaves lines on the panel. I've tried invalidate after the msgbox to no avail... Here is the event: Private Sub Panel2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint ControlPaint.DrawBorder3D(e.Graphics, e.ClipRectangle,...
7
2024
by: Dennis | last post by:
I am trying to implement drawing on a bitmap and using bitblt to transfer it to the control graphics object in the paint event. It seems to draw on the bitmap ok but doesn't get transferred to the control graphics object in the paint event. Any help would be appreciated. Here is my code: public class as mycontrol Private Declare Auto Function BitBlt Lib "GDI32.DLL" (ByVal hdcDest As IntPtr, ByVal nxDest As Integer, ByVal nyDest As...
1
1983
by: edi sol | last post by:
Hi, I have a user control and panel in this control. I write a paint event of the panel control. When I strat the application (windows form with this control only) the paint event executes twice. Why is this? Thanks.
4
2543
by: Sam | last post by:
Hai, I use a paintbox paint event to draw some images in a paintbox. I call the paint event by refreshing the paintbox using paintboxname.refresh() or paintboxname.update(). Problem with this kind of paint event is that the event is not raised when the application is run in a minimized state. So, my question is: How can you make sure that the paint event is called even when the application is running in the minimized state.
1
2517
by: ehabzaky | last post by:
Hi, I'm using some low level Win 32 API for some drawing functions on a picture box. I'm putting the drawing code in a method and call this method from the picture box paint event. The problem is that when the application starts the drawings is appeared instantly on the picture box then it is cleared using the background color of the picture box. I have to force the paint event to fire by dragging the window outside the screen edges...
4
4901
by: Kürþat | last post by:
Hi all, I do some drawing in a form's paint event handler and I have a button on that form. Whenever the mouse enters or leaves the button Form's paint event occurs. Isn't that a strange behavior? Is it possible to prevent that? Thanks.
0
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10292
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.