#
#   PyGUI - Canvas primitives test
#

from GUI import Window, View, Menu, application
from GUI.StdMenus import basic_menus
from GUI.StdColors import black, white


class LineTest:

    menu_item = "Line/^L"
    
    def draw(self, c):
        c.newpath()
        c.moveto(10, 10)
        c.lineto(90, 290)
        c.stroke()


class RectTest:

    menu_item = "Rect/^R"
    
    def draw(self, c):
        c.stroke_rect((20, 30, 80, 70))
        c.frame_rect((20, 130, 80, 170))
        c.fill_rect((20, 230, 80, 270))


class OvalTest:

    menu_item = "Oval/^O"
    
    def draw(self, c):
        c.stroke_oval((20, 30, 80, 70))
        c.frame_oval((20, 130, 80, 170))
        c.fill_oval((20, 230, 80, 270))


class ArcTest:

    menu_item = "Arc/^A"
    
    def draw(self, c):
        r = 40
        sa = 60
        aa = 240
        c.stroke_arc((50, 50), r, sa, aa)
        c.frame_arc((50, 150), r, sa, aa)
        c.fill_arc((50, 250), r, sa, aa)


tests = [
    LineTest(),
    RectTest(),
    OvalTest(),
    ArcTest(),
]


test_menu = Menu("Shape", [
    ([t.menu_item for t in tests], 'test_cmd')
])


class CTV(View):

    test = None

    def draw(self, c, r):
        c.forecolor = white
        c.fill_rect(r)
        c.forecolor = black
        c.pensize = 10
        if self.test:
            self.test.draw(c)
    
    def setup_menus(self, m):
        m.test_cmd.enabled = True
    
    def test_cmd(self, i):
        self.test = tests[i]
        self.invalidate()


def main():
    view = CTV(size = (100, 300))
    win = Window(title = "Canvas")
    win.add(view)
    win.shrink_wrap()
    view.become_target()
    win.show()
    app = application()
    app.menus = basic_menus() + [test_menu]
    app.run()

instructions = """
The Line test should draw a straight diagonal line.
The Rect, Oval and Arc tests  should each produce three shapes, one
stroked, one framed and one filled.
"""

print instructions
main()
