Draw an elliptic arc (Phoenix)

Keywords : EllipticArc, Drawing, PaintDC, GCDC.


Demonstrating :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

Test, modify, correct, complete, improve and share your discoveries ! (!)


First example

img_sample_one.png

   1 # sample_one.py
   2 
   3 import wx
   4 
   5 # class MyPanel
   6 # class MyFrame
   7 # class MyApp
   8 
   9 #---------------------------------------------------------------------------
  10 
  11 class MyPanel(wx.Panel):
  12     def __init__(self, *args, **kwargs):
  13         wx.Panel.__init__(self, *args, **kwargs)
  14 
  15         self.Bind(wx.EVT_PAINT, self.OnPaint)
  16 
  17     #-----------------------------------------------------------------------
  18 
  19     def OnPaint(self, event):
  20         """
  21         ...
  22         """
  23 
  24         pdc = wx.PaintDC(self)
  25         gc = wx.GCDC(pdc)
  26         gc.Clear()
  27 
  28         pen = wx.Pen("black", 2, wx.SOLID)
  29         pen.SetCap(wx.CAP_BUTT)
  30         gc.SetPen(pen)
  31         gc.SetBrush(wx.RED_BRUSH)
  32 
  33         x = 100
  34         y = 30
  35         w = 50
  36         h = 50
  37 
  38         for radius in [0, 90, 180, 270, -90, -180, -270]:
  39             # x, y , width, height, start, end
  40             gc.DrawEllipticArc(x, y, w, h, 0, radius)
  41             gc.DrawText(str(radius), int(x+w+10), int(y+h/2))
  42             y+=100
  43 
  44 #---------------------------------------------------------------------------
  45 
  46 class MyFrame(wx.Frame):
  47     def __init__(self, *args, **kwargs):
  48         wx.Frame.__init__(self, *args, **kwargs)
  49 
  50         #------------
  51 
  52         frameicon = wx.Icon("icon_wxWidgets.ico")
  53         self.SetIcon(frameicon)
  54 
  55         #------------
  56 
  57         self.Panel = MyPanel(self)
  58 
  59 #---------------------------------------------------------------------------
  60 
  61 class MyApp(wx.App):
  62     """
  63     ...
  64     """
  65     def OnInit(self):
  66 
  67         #------------
  68 
  69         frame = MyFrame(None, title="Sample_one - A", size=(270, 750))
  70         self.SetTopWindow(frame)
  71         frame.Show(True)
  72 
  73         return True
  74 
  75 #---------------------------------------------------------------------------
  76 
  77 def main():
  78     app = MyApp(False)
  79     app.MainLoop()
  80 
  81 #---------------------------------------------------------------------------
  82 
  83 if __name__ == "__main__" :
  84     main()


Download source

source.zip


Additional Information

Link :

http://zetcode.com/wxpython/gdi/

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

Chris Barker (sample_one.py coding), the wxPython community...


About this page

Date(d/m/y) Person (bot) Comments :

14/12/19 - Ecco (Created page for wxPython Phoenix).


Comments

- blah, blah, blah....

Draw an elliptic arc (Phoenix) (last edited 2020-10-07 09:49:10 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.