Re: making a clock face

Tim Roberts <[email protected]> Sun, 22 Nov 2020 16:38:46 -0800
Newsgroups gmane.comp.python.wxpython
Message-ID <[email protected]>
On Nov 22, 2020, at 1:39 PM, Nathan smith <[email protected]> wrote:
> 
> In something I am working on I have the desire to create a screen which has in the top a button and a text box,
> ...
> I know for the most part how to implement this and almost have the confidence to say I could draw a clock, at least a basic clock, using the wx.PaintDC but can this be drawn on a panel?

As opposed to what?  I mean, what else would you use to make a space for drawing on?


> Related to this I looked into wx.lib.analogclock but did not see a way to update it with the time?
> So I'd want to make it so that the hands appear to show what the current time is, and shift in relation to this for each second.

Did you even look at the module?  An analog clock wouldn’t be much good if it didn’t display the time.  You have the full source code for this module in your wxPython distribution, so you can go look at it.  If you do that, you’ll see that the HandSet _draw function, which gets called one a second, fetches the current time to decide how to draw the hands.  The module even include a test so you can run it standalone.


> I figured I'd have:
> 
> sizer 1 at the top for the button and text box.
> sizer 2 with wx.ALIGN_CENTER for the clock
> And sizer 3 for the long date bar at the bottom.

No.  You’d have one vertical sizer to hold everything.  The top thing in the vertical sizer would be a horizontal sizer to hold the button and the text box.  The center thing in the vertical sizer would be the clock face.  The bottom thin in the vertical sizer would be the text box for the date.


> On that topic though how can I stretch out a text box to make it, if not the length of the bottom of the screen, than at least align itself to the same width as the clock itself?

If you specify wx.EXPAND when adding an item to a sizer, the item will grow to fill the borders of the sizer.  For a vertical sizer, EXPAND causes the items to expand horizontally, and vice versa.


> Having written this, I admit to wondering if I'm simply going to have to draw it by hand, using calculations off of the screen size to roughly place things and hope for the best.

Well, that’s exactly how to draw it, but you don’t “hope for the best”.  You create a polygon for each hand, scale it to match the panel size, and rotate it using trigonometry for the time.
— 
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/E67D027C-775F-4945-87D7-8503B94FA9CD%40probo.com.