File: test_lib_agw_flatmenu.py

package info (click to toggle)
wxpython4.0 4.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 232,540 kB
  • sloc: cpp: 958,937; python: 233,059; ansic: 150,441; makefile: 51,662; sh: 8,687; perl: 1,563; javascript: 584; php: 326; xml: 200
file content (107 lines) | stat: -rw-r--r-- 3,510 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import unittest
from unittests import wtc
import wx

import wx.lib.agw.flatmenu as FM

#---------------------------------------------------------------------------

class lib_agw_flatmenu_Tests(wtc.WidgetTestCase):

    def setUp(self):
        '''
        Monkey patch some methods which don't behave well without
        a MainLoop.  We could restore them in tearDown, but there's
        no need because self.frame will be destroyed in tearDown.
        '''
        super(lib_agw_flatmenu_Tests, self).setUp()

        self.realPushEventHandlerMethod = self.frame.PushEventHandler
        def MockPushEventHandler(handler): pass
        self.frame.PushEventHandler = MockPushEventHandler

        self.realPopEventHandlerMethod = self.frame.PopEventHandler
        def MockPopEventHandler(deleteHandler=False): pass
        self.frame.PopEventHandler = MockPopEventHandler

    def test_lib_agw_flatmenuCtor(self):
        self._popUpMenu = FM.FlatMenu()

        # First we create the sub-menu item
        subMenu = FM.FlatMenu()
        subSubMenu = FM.FlatMenu()

        # Create the menu items
        menuItem = FM.FlatMenuItem(self._popUpMenu, 20001, "First Menu Item", "", wx.ITEM_CHECK)
        self._popUpMenu.AppendItem(menuItem)

        menuItem = FM.FlatMenuItem(self._popUpMenu, 20002, "Sec&ond Menu Item", "", wx.ITEM_CHECK)
        self._popUpMenu.AppendItem(menuItem)

        menuItem = FM.FlatMenuItem(self._popUpMenu, wx.ID_ANY, "Checkable-Disabled Item", "", wx.ITEM_CHECK)
        menuItem.Enable(False)
        self._popUpMenu.AppendItem(menuItem)

        menuItem = FM.FlatMenuItem(self._popUpMenu, 20003, "Third Menu Item", "", wx.ITEM_CHECK)
        self._popUpMenu.AppendItem(menuItem)

        self._popUpMenu.AppendSeparator()


    def test_lib_agw_flatmenuOpen(self):
        def CreateLongPopupMenu(self):
            popMenu = FM.FlatMenu()
            sub = FM.FlatMenu()

            #-----------------------------------------------
            # Flat Menu test
            #-----------------------------------------------

            for ii in range(30):
                if ii == 0:
                    menuItem = FM.FlatMenuItem(popMenu, wx.ID_ANY, "Menu Item #%ld"%(ii+1), "", wx.ITEM_NORMAL, sub)
                    popMenu.AppendItem(menuItem)

                    for k in range(5):

                        menuItem = FM.FlatMenuItem(sub, wx.ID_ANY, "Sub Menu Item #%ld"%(k+1))
                        sub.AppendItem(menuItem)

                else:

                    menuItem = FM.FlatMenuItem(popMenu, wx.ID_ANY, "Menu Item #%ld"%(ii+1))
                    popMenu.AppendItem(menuItem)

            return popMenu

        popMenu = CreateLongPopupMenu(self)

        fPt = self.frame.GetPosition()
        popMenu.Popup(wx.Point(fPt.x, fPt.y), self.frame)
        popMenu.Dismiss(True, True)

        # Clear the capture since the test won't do a normal shudown of the flatmenu
        cap = wx.Window.GetCapture()
        if cap:
            cap.ReleaseMouse()


    def test_lib_agw_flatmenuConstantsExist(self):

        FM.FM_OPT_IS_LCD
        FM.FM_OPT_MINIBAR
        FM.FM_OPT_SHOW_CUSTOMIZE
        FM.FM_OPT_SHOW_TOOLBAR

    def test_lib_agw_flatmenuEvents(self):

        FM.EVT_FLAT_MENU_DISMISSED
        FM.EVT_FLAT_MENU_ITEM_MOUSE_OUT
        FM.EVT_FLAT_MENU_ITEM_MOUSE_OVER
        FM.EVT_FLAT_MENU_SELECTED


#---------------------------------------------------------------------------

if __name__ == '__main__':
    unittest.main()