How do I draw a semicircle?

34 views
Skip to first unread message

Phil

unread,
May 13, 2021, 12:50:37 AM5/13/21
to wxPython-users
Thank you for reading this.

I'm trying to create an analogue meter. So far I have a pointer that
moves and now I'm trying to create a dial face. Just for the sake of
simplicity, the dial face is a semicircle.

I've spent a lot of time experimenting and searching for an answer
without success. The following is based on something that I found, it
runs but doesn't draw anything:

    def OnPaint(self, e):

        #pdc = wx.PaintDC(self)
        #gc = wx.GCDC(pdc)

        gc = wx.GraphicsContext.Create(wx.PaintDC(self))

        path = gc.CreatePath()

        path.AddArc(450, 100, 30, math.radians(180), math.radians(0))
        pen = wx.Pen('#ffffff', 1)
        gc.SetBrush(wx.Brush('#CC7F32', wx.SOLID))
        gc.SetPen(pen)

        gc.DrawPath(path)

--
Regards,
Phil

Andrea Gavana

unread,
May 13, 2021, 2:31:01 AM5/13/21
to wxpytho...@googlegroups.com
Hi,

Maybe you could take some inspiration from wx.lib.agw.speedometer:

?

Andrea.



--
Regards,
Phil

--
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 wxpython-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/123c0aed-fbfe-012f-091f-7521a9abada8%40gmail.com.

Phil

unread,
May 13, 2021, 5:55:43 PM5/13/21
to wxpytho...@googlegroups.com
On 13/5/21 4:30 pm, Andrea Gavana wrote:
>
> Maybe you could take some inspiration from wx.lib.agw.speedometer:

Thank you Andrea,

Speedometer is rather complex plus the demo will not run because of an
invalid encoding error. I posted a question about this quite some time
ago but didn't receive a reply.

I now have my meter working and now have to sort out how to incorporate
it into it's own class. I have no idea how to do this, at the moment.

--

Regards,
Phil

Chris Barker

unread,
Jul 3, 2021, 12:46:15 PM7/3/21
to wxpython-users
On Thu, May 13, 2021 at 2:55 PM Phil <phil...@gmail.com> wrote:
Speedometer is rather complex plus the demo will not run because of an
invalid encoding error.

an issue on gitHub might be good for that. -- but looking at the code may be helpful nonetheless.
 
I now have my meter working and now have to sort out how to incorporate
it into it's own class. I have no idea how to do this, at the moment.

look at the wiki and various demos, but in short:

create a subclass of wxPanel

Create a method to draw the dial.

Call that method from The OnPaint handler to a method that draws your dial.

When the data changes, call Refesh() on your panel -- that will trigger a Paint event, which will re-draw the dial.

You may want to have the dial itself be pre-saved to a bitmap, and then you can just re-draw the needle on top of it when things change.

These are a bit old, but may help:


-CHB


--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris....@noaa.gov

Phil

unread,
Jul 3, 2021, 8:02:58 PM7/3/21
to wxpytho...@googlegroups.com
On 4/7/21 2:45 am, 'Chris Barker' via wxPython-users wrote:
>
> I now have my meter working and now have to sort out how to
> incorporate
> it into it's own class. I have no idea how to do this, at the moment.
>
>
> create a subclass of wxPanel
>
> Create a method to draw the dial.
>
> Call that method from The OnPaint handler to a method that draws your
> dial.
>
> When the data changes, call Refesh() on your panel -- that will
> trigger a Paint event, which will re-draw the dial.
>
> You may want to have the dial itself be pre-saved to a bitmap, and
> then you can just re-draw the needle on top of it when things change.
>
Thank you Chris,

Perhaps I should have delayed my question until I'd had a good night's
sleep. I completed this project over a few days. Creating the dial in a
drawing programme was a far neater idea and saved a lot of coding.

--

Regards,
Phil

Reply all
Reply to author
Forward
0 new messages