Ejemplo n.º 1
0
    def setUp(self):
        self._menuBar = MenuBar()
        self._menuFile = self._menuBar.addItem('File', self)
        self._menuEdit = self._menuBar.addItem('Edit', self)
        self._menuEditCopy = self._menuEdit.addItem('Copy', self)
        self._menuEditCut = self._menuEdit.addItem('Cut', self)
        self._menuEditPaste = self._menuEdit.addItem('Paste', self)
        self._menuEdit.addSeparator()
        self._menuEditFind = self._menuEdit.addItem('Find...', self)
        self._menuFileOpen = self._menuFile.addItem('Open', self)
        self._menuFileSave = self._menuFile.addItem('Save', self)
        self._menuFile.addSeparator()
        self._menuFileExit = self._menuFile.addItem('Exit', self)

        self._menuItems = set()
        self._menuItems.add(self._menuFile)
        self._menuItems.add(self._menuEdit)
        self._menuItems.add(self._menuEditCopy)
        self._menuItems.add(self._menuEditCut)
        self._menuItems.add(self._menuEditPaste)
        self._menuItems.add(self._menuEditFind)
        self._menuItems.add(self._menuFileOpen)
        self._menuItems.add(self._menuFileSave)
        self._menuItems.add(self._menuFileExit)

        self._lastSelectedItem = None
Ejemplo n.º 2
0
class MenuBarItemStylesExample(VerticalLayout):

    def __init__(self):
        super(MenuBarItemStylesExample, self).__init__()

        self._menubar = MenuBar()

        menuCommand = MenuCommand(self)

        # Save reference to individual items so we can add sub-menu items to
        # them
        f = self._menubar.addItem('File', None)
        newItem = f.addItem('New', None)
        f.addItem('Open f...', menuCommand)
        f.addSeparator()
        # Add a style name for a menu item, then use CSS to alter the visuals
        f.setStyleName('file')
        newItem.addItem('File', menuCommand)
        newItem.addItem('Folder', menuCommand)
        newItem.addItem('Project...', menuCommand)
        f.addItem('Close', menuCommand)
        f.addItem('Close All', menuCommand).setStyleName('close-all')
        f.addSeparator()
        f.addItem('Save', menuCommand)
        f.addItem('Save As...', menuCommand)
        f.addItem('Save All', menuCommand)

        edit = self._menubar.addItem('Edit', None)
        edit.addItem('Undo', menuCommand)
        edit.addItem('Redo', menuCommand).setEnabled(False)
        edit.addSeparator()
        edit.addItem('Cut', menuCommand)
        edit.addItem('Copy', menuCommand)
        edit.addItem('Paste', menuCommand)
        edit.addSeparator()

        find = edit.addItem('Find/Replace', menuCommand)

        # Actions can be added inline as well, of course
        find.addItem('Google Search', SearchCommand(self))
        find.addSeparator()
        find.addItem('Find/Replace...', menuCommand)
        find.addItem('Find Next', menuCommand)
        find.addItem('Find Previous', menuCommand)

        view = self._menubar.addItem('View', None)
        view.addItem('Show/Hide Status Bar', menuCommand)
        view.addItem('Customize Toolbar...', menuCommand)
        view.addSeparator()
        view.addItem('Actual Size', menuCommand)
        view.addItem('Zoom In', menuCommand)
        view.addItem('Zoom Out', menuCommand)

        self.addComponent(self._menubar)
Ejemplo n.º 3
0
class MenuBarItemStylesExample(VerticalLayout):
    def __init__(self):
        super(MenuBarItemStylesExample, self).__init__()

        self._menubar = MenuBar()

        menuCommand = MenuCommand(self)

        # Save reference to individual items so we can add sub-menu items to
        # them
        f = self._menubar.addItem('File', None)
        newItem = f.addItem('New', None)
        f.addItem('Open f...', menuCommand)
        f.addSeparator()
        # Add a style name for a menu item, then use CSS to alter the visuals
        f.setStyleName('file')
        newItem.addItem('File', menuCommand)
        newItem.addItem('Folder', menuCommand)
        newItem.addItem('Project...', menuCommand)
        f.addItem('Close', menuCommand)
        f.addItem('Close All', menuCommand).setStyleName('close-all')
        f.addSeparator()
        f.addItem('Save', menuCommand)
        f.addItem('Save As...', menuCommand)
        f.addItem('Save All', menuCommand)

        edit = self._menubar.addItem('Edit', None)
        edit.addItem('Undo', menuCommand)
        edit.addItem('Redo', menuCommand).setEnabled(False)
        edit.addSeparator()
        edit.addItem('Cut', menuCommand)
        edit.addItem('Copy', menuCommand)
        edit.addItem('Paste', menuCommand)
        edit.addSeparator()

        find = edit.addItem('Find/Replace', menuCommand)

        # Actions can be added inline as well, of course
        find.addItem('Google Search', SearchCommand(self))
        find.addSeparator()
        find.addItem('Find/Replace...', menuCommand)
        find.addItem('Find Next', menuCommand)
        find.addItem('Find Previous', menuCommand)

        view = self._menubar.addItem('View', None)
        view.addItem('Show/Hide Status Bar', menuCommand)
        view.addItem('Customize Toolbar...', menuCommand)
        view.addSeparator()
        view.addItem('Actual Size', menuCommand)
        view.addItem('Zoom In', menuCommand)
        view.addItem('Zoom Out', menuCommand)

        self.addComponent(self._menubar)
Ejemplo n.º 4
0
    def setUp(self):
        self._menuBar = MenuBar()
        self._menuFile = self._menuBar.addItem('File', self)
        self._menuEdit = self._menuBar.addItem('Edit', self)
        self._menuEditCopy = self._menuEdit.addItem('Copy', self)
        self._menuEditCut = self._menuEdit.addItem('Cut', self)
        self._menuEditPaste = self._menuEdit.addItem('Paste', self)
        self._menuEdit.addSeparator()
        self._menuEditFind = self._menuEdit.addItem('Find...', self)
        self._menuFileOpen = self._menuFile.addItem('Open', self)
        self._menuFileSave = self._menuFile.addItem('Save', self)
        self._menuFile.addSeparator()
        self._menuFileExit = self._menuFile.addItem('Exit', self)

        self._menuItems = set()
        self._menuItems.add(self._menuFile)
        self._menuItems.add(self._menuEdit)
        self._menuItems.add(self._menuEditCopy)
        self._menuItems.add(self._menuEditCut)
        self._menuItems.add(self._menuEditPaste)
        self._menuItems.add(self._menuEditFind)
        self._menuItems.add(self._menuFileOpen)
        self._menuItems.add(self._menuFileSave)
        self._menuItems.add(self._menuFileExit)

        self._lastSelectedItem = None
Ejemplo n.º 5
0
    def setUp(self):
        self._menuBar = MenuBar()
        self._menuFile = self._menuBar.addItem("File", self)
        self._menuEdit = self._menuBar.addItem("Edit", self)
        self._menuEditCopy = self._menuEdit.addItem("Copy", self)
        self._menuEditCut = self._menuEdit.addItem("Cut", self)
        self._menuEditPaste = self._menuEdit.addItem("Paste", self)
        self._menuEdit.addSeparator()
        self._menuEditFind = self._menuEdit.addItem("Find...", self)
        self._menuFileOpen = self._menuFile.addItem("Open", self)
        self._menuFileSave = self._menuFile.addItem("Save", self)
        self._menuFile.addSeparator()
        self._menuFileExit = self._menuFile.addItem("Exit", self)

        self._menuItems = set()
        self._menuItems.add(self._menuFile)
        self._menuItems.add(self._menuEdit)
        self._menuItems.add(self._menuEditCopy)
        self._menuItems.add(self._menuEditCut)
        self._menuItems.add(self._menuEditPaste)
        self._menuItems.add(self._menuEditFind)
        self._menuItems.add(self._menuFileOpen)
        self._menuItems.add(self._menuFileSave)
        self._menuItems.add(self._menuFileExit)

        self._lastSelectedItem = None
Ejemplo n.º 6
0
class MenuBarIds(TestCase, ICommand):

    def setUp(self):
        self._menuBar = MenuBar()
        self._menuFile = self._menuBar.addItem('File', self)
        self._menuEdit = self._menuBar.addItem('Edit', self)
        self._menuEditCopy = self._menuEdit.addItem('Copy', self)
        self._menuEditCut = self._menuEdit.addItem('Cut', self)
        self._menuEditPaste = self._menuEdit.addItem('Paste', self)
        self._menuEdit.addSeparator()
        self._menuEditFind = self._menuEdit.addItem('Find...', self)
        self._menuFileOpen = self._menuFile.addItem('Open', self)
        self._menuFileSave = self._menuFile.addItem('Save', self)
        self._menuFile.addSeparator()
        self._menuFileExit = self._menuFile.addItem('Exit', self)

        self._menuItems = set()
        self._menuItems.add(self._menuFile)
        self._menuItems.add(self._menuEdit)
        self._menuItems.add(self._menuEditCopy)
        self._menuItems.add(self._menuEditCut)
        self._menuItems.add(self._menuEditPaste)
        self._menuItems.add(self._menuEditFind)
        self._menuItems.add(self._menuFileOpen)
        self._menuItems.add(self._menuFileSave)
        self._menuItems.add(self._menuFileExit)

        self._lastSelectedItem = None


    def testMenubarIdUniqueness(self):
        # Ids within a menubar must be unique
        self.assertUniqueIds(self._menuBar)

        self._menuBar.removeItem(self._menuFile)
        file2 = self._menuBar.addItem('File2', self)
        file3 = self._menuBar.addItem('File3', self)
        file2sub = file2.addItem('File2 sub menu', self)
        self._menuItems.add(file2)
        self._menuItems.add(file2sub)
        self._menuItems.add(file3)

        self.assertUniqueIds(self._menuBar)


    @classmethod
    def assertUniqueIds(cls, *args):
        nargs = len(args)
        if nargs == 1:
            menuBar, = args
            ids = set()
            for item in menuBar.getItems():
                cls.assertUniqueIds(ids, item)
        elif nargs == 2:
            ids, item = args
            idd = item.getId()
            print 'Item ' + item.getText() + ', id: ' + str(idd)
            assert idd not in ids
            ids.add(idd)
            if item.getChildren() is not None:
                for subItem in item.getChildren():
                    cls.assertUniqueIds(ids, subItem)
        else:
            raise ValueError


    def menuSelected(self, selectedItem):
        self.assertEquals(('lastSelectedItem was not cleared before '
                'selecting an item'), self._lastSelectedItem)
        self._lastSelectedItem = selectedItem
Ejemplo n.º 7
0
class MenuBarIds(TestCase, ICommand):
    def setUp(self):
        self._menuBar = MenuBar()
        self._menuFile = self._menuBar.addItem('File', self)
        self._menuEdit = self._menuBar.addItem('Edit', self)
        self._menuEditCopy = self._menuEdit.addItem('Copy', self)
        self._menuEditCut = self._menuEdit.addItem('Cut', self)
        self._menuEditPaste = self._menuEdit.addItem('Paste', self)
        self._menuEdit.addSeparator()
        self._menuEditFind = self._menuEdit.addItem('Find...', self)
        self._menuFileOpen = self._menuFile.addItem('Open', self)
        self._menuFileSave = self._menuFile.addItem('Save', self)
        self._menuFile.addSeparator()
        self._menuFileExit = self._menuFile.addItem('Exit', self)

        self._menuItems = set()
        self._menuItems.add(self._menuFile)
        self._menuItems.add(self._menuEdit)
        self._menuItems.add(self._menuEditCopy)
        self._menuItems.add(self._menuEditCut)
        self._menuItems.add(self._menuEditPaste)
        self._menuItems.add(self._menuEditFind)
        self._menuItems.add(self._menuFileOpen)
        self._menuItems.add(self._menuFileSave)
        self._menuItems.add(self._menuFileExit)

        self._lastSelectedItem = None

    def testMenubarIdUniqueness(self):
        # Ids within a menubar must be unique
        self.assertUniqueIds(self._menuBar)

        self._menuBar.removeItem(self._menuFile)
        file2 = self._menuBar.addItem('File2', self)
        file3 = self._menuBar.addItem('File3', self)
        file2sub = file2.addItem('File2 sub menu', self)
        self._menuItems.add(file2)
        self._menuItems.add(file2sub)
        self._menuItems.add(file3)

        self.assertUniqueIds(self._menuBar)

    @classmethod
    def assertUniqueIds(cls, *args):
        nargs = len(args)
        if nargs == 1:
            menuBar, = args
            ids = set()
            for item in menuBar.getItems():
                cls.assertUniqueIds(ids, item)
        elif nargs == 2:
            ids, item = args
            idd = item.getId()
            print 'Item ' + item.getText() + ', id: ' + str(idd)
            assert idd not in ids
            ids.add(idd)
            if item.getChildren() is not None:
                for subItem in item.getChildren():
                    cls.assertUniqueIds(ids, subItem)
        else:
            raise ValueError

    def menuSelected(self, selectedItem):
        self.assertEquals(('lastSelectedItem was not cleared before '
                           'selecting an item'), self._lastSelectedItem)
        self._lastSelectedItem = selectedItem
Ejemplo n.º 8
0
    def __init__(self):
        super(MenuBarCollapsingExample, self).__init__()

        self._menubar = MenuBar()

        menuCommand = MenuCommand(self)

        # In order to collapse items, the MenuBar must have a specified width
        self._menubar.setWidth('50%')

        # Save reference to individual items so we can add sub-menu items to
        # them
        f = self._menubar.addItem('File', None)
        newItem = f.addItem('New', None)
        f.addItem('Open f...', menuCommand)
        f.addSeparator()
        newItem.addItem('File', menuCommand)
        newItem.addItem('Folder', menuCommand)
        newItem.addItem('Project...', menuCommand)
        f.addItem('Close', menuCommand)
        f.addItem('Close All', menuCommand)
        f.addSeparator()
        f.addItem('Save', menuCommand)
        f.addItem('Save As...', menuCommand)
        f.addItem('Save All', menuCommand)

        # Generate bogus items so we can show the collapsing
        for i in range(5):
            self._menubar.addItem('Item %d' % i, menuCommand).setEnabled(False)

        edit = self._menubar.addItem('Edit', None)
        edit.addItem('Undo', menuCommand)
        edit.addItem('Redo', menuCommand).setEnabled(False)
        edit.addSeparator()
        edit.addItem('Cut', menuCommand)
        edit.addItem('Copy', menuCommand)
        edit.addItem('Paste', menuCommand)
        edit.addSeparator()

        find = edit.addItem('Find/Replace', menuCommand)

        # Actions can be added inline as well, of course
        find.addItem('Google Search', SearchCommand(self))
        find.addSeparator()
        find.addItem('Find/Replace...', menuCommand)
        find.addItem('Find Next', menuCommand)
        find.addItem('Find Previous', menuCommand)

        view = self._menubar.addItem('View', None)
        view.addItem('Show/Hide Status Bar', menuCommand)
        view.addItem('Customize Toolbar...', menuCommand)
        view.addSeparator()
        view.addItem('Actual Size', menuCommand)
        view.addItem('Zoom In', menuCommand)
        view.addItem('Zoom Out', menuCommand)

        # Generate bogus items so we can show the collapsing
        for i in range(5):
            self._menubar.addItem('Item %d' % i, menuCommand).setEnabled(False)

        self.addComponent(self._menubar)