#
#   PyGUI - Mouse event test

from GUI import Window, application
from TestViews import TestDrawing
from TestScrollableViews import TestScrollableDrawing
from TestInput import TestMouseEvents


class TestView(TestMouseEvents, TestDrawing):

    def __init__(self, name, **kwds):
        self.name = name
        TestDrawing.__init__(self, **kwds)
    
    def mouse_down(self, event):
        #self.become_target()
        TestMouseEvents.mouse_down(self, event)
    
    def report_mouse_event(self, mess):
        print "%s: %s" % (self.name, mess)


class TestScrollableView(TestMouseEvents, TestScrollableDrawing):

    def __init__(self, name, **kwds):
        self.name = name
        TestScrollableDrawing.__init__(self, scrolling = 'hv', **kwds)
    
    def mouse_down(self, event):
        #self.become_target()
        TestMouseEvents.mouse_down(self, event)
    
    def report_mouse_event(self, mess):
        print "%s: %s" % (self.name, mess)


win = Window()
view1 = TestView("View 1", width = 320, height = 200)
view2 = TestScrollableView("View 2", width = 320, height = 200)
win.place_row([view1, view2], left = 20, top = 20, spacing = 20)
view2.hstretch = 1
view2.vstretch = 1
win.shrink_wrap(padding = (20, 20))
win.show()
view1.become_target()

print """
There should be two views. The following events should be reported
in either view: mouse_down, mouse_drag, mouse_up, mouse_enter,
mouse_leave.

The right-hand view should resize with the window. Check that
mouse_enter and mouse_leave events are still reported correctly
after resizing and after scrolling the view.
"""

application().run()
