Re: making a clock face
Tim Roberts <[email protected]> Fri, 27 Nov 2020 11:40:05 -0800
| Newsgroups | gmane.comp.python.wxpython |
|---|---|
| Message-ID | <[email protected]> |
On Nov 27, 2020, at 3:32 AM, Nathan smith <[email protected]> wrote: > > I have a follow up question though regarding the drawing of a clock. > > Unfortunately, the time being displayed may not always be the time of the system itself, and from what I have read the wx.AnalogClock does not support time being passed to it? Correct. Remember, you have the complete source code. As published, it pulls the current time at the beginning of the “draw” function that handles painting. However, because Python is such a magical language, you are free to derive your own class from it that pulls the time from a member variable, which you can supply. > On the subject of drawing though I wanted to ask, I've had limited exposure to the wx.PaintDC and only been drawing to a frame rather than a panel. > > So drawing to a panel should work as well? You can draw to any window. Neither a frame nor a panel has any content of its own, so you don’t have to worry about sharing the space. > Finally if I did something like: > > self.dc = wx.PaintDC(panel) No. You only do this inside the EVT_PAINT handler. You can’t cache it. One of the responsibilities of a “paint” handler is to tell the system “OK, I’ve finished”, so the system knows that any dirty regions have been repainted. The PaintDC handles that little bit of overhead on your behalf in its destructor. If you don’t do that, when your paint handler returns, the system thinks there are still dirty regions that need to be repainted, and it will trigger another EVT_PAINT. If you need to draw on your panel outside of a paint handler, you’d use wx.ClientDC. > hbox1 = wx.BoxSizer(wx.HORIZONTAL) > hbox1.Add(self.dc, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5) No. A DC is not a window. A DC merely stores the current set of things you can draw with: fonts, colors, brushes, pens, bitmaps, and so on. The only things you can add to a sizer are windows. You’d add the panel to the sizer. Or, if the panel is the only thing in the frame, you don’t need the sizer — the panel will automatically expand to fill the frame. > Later if I did self.dc.Clear() And drew something else using that same self.dc instance, it woudl draw it in the space given to it by the sizer hbox1, is that right? Nope. A sizer is not a window — you cannot draw on a sizer. You can draw on a panel, using a DC, and the sizer merely manages the size of the panel. > I realise to you these questions probably seem obvious and you're wondering why I ask such simple things, but I'm trying to get the theory straight in my mind before I put pen to paper or, in this case, brush to panel :) Have you read through the wxWidgets documentation on windows, sizers, and DCs? You’re confusing some pretty fundamental topics here. Those guys went to all the trouble of writing it, hoping people would read it. There are some great wxPython tutorials explaining the basics, and there’s also Robin’s excellent book on wxPython. > In my application for drawing that I have been working on I am using size calculations to work out where the middle of the screen is for my central point and just working around that. > Would that still work with inclusion of the sizers? When you say “screen”, do you mean “window”? All you have to do is keep track of which window you’re drawing into. If you want to find the center of your panel, then that’s what you do: size = sell.clockPanel.GetClientSize() # Center is at size.x // 2 and size.y // 2 And if you’re using a DC for the panel, then the upper left is at (0,0) and you just start drawing. — Tim Roberts, [email protected] Providenza & Boekelheide, Inc. -- You received this message because you are subscribed to the Google Groups "wxPython-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/DB8DBDBC-E3FB-4266-AC2D-8DC773F475CB%40probo.com.