Re: making a clock face

Nathan smith <[email protected]> Fri, 27 Nov 2020 11:32:21 +0000
Newsgroups gmane.comp.python.wxpython
Message-ID <[email protected]>
Hi Tim,


Thanks for your advice.

I admit, looking at my questions again they did seem rather obvious!

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?

I guess I could make some slight modifications though and do a custom 
module for this purpose..


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?

Finally if I did something like:

self.dc = wx.PaintDC(panel)

hbox1 = wx.BoxSizer(wx.HORIZONTAL)

hbox1.Add(self.dc, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)


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?

Instead of clearing and then going over other sizers or widgets added.


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 :)


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?


Thanks in advance

Nathan

On 23/11/2020 00:38, Tim Roberts wrote:
> 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/216299cc-e963-9122-b796-c4c72d034710%40gmail.com.