Example #1
0
 def new(self):
     """ Opens a new empty window
     """
     editor = Editor()
     self.editor_area.add_editor(editor)
     self.editor_area.activate_editor(editor)
     self.activated()
    def test_persistence(self):
        """ Tests whether get_layout/set_layout work correctly by setting a
        given layout and getting back the obtained layout.
        """
        # setup the test layout - one horizontal split and one vertical split
        # on the rightchild of horizontal split, where the top tabwidget of
        # the vertical split is empty.
        layout = Splitter(Tabbed(PaneItem(id=0, width=600, height=600),
                                 active_tab=0),
                          Splitter(Tabbed(PaneItem(id=-1,
                                                   width=600,
                                                   height=300),
                                          active_tab=0),
                                   Tabbed(PaneItem(id=1, width=600,
                                                   height=300),
                                          PaneItem(id=2, width=600,
                                                   height=300),
                                          active_tab=0),
                                   orientation='vertical'),
                          orientation='horizontal')
        # a total of 3 files are needed to give this layout - one on the
        # leftchild of horizontal split, and the other two on the bottom
        # tabwidget of the rightchild's vertical split
        file0 = open(os.path.join(tempfile.gettempdir(), 'file0'), 'w+b')
        file1 = open(os.path.join(tempfile.gettempdir(), 'file1'), 'w+b')
        file2 = open(os.path.join(tempfile.gettempdir(), 'file2'), 'w+b')

        # adding the editors
        editor_area = SplitEditorAreaPane()
        editor_area.create(parent=None)
        editor_area.add_editor(Editor(obj=file0, tooltip="test_tooltip0"))
        editor_area.add_editor(Editor(obj=file1, tooltip="test_tooltip1"))
        editor_area.add_editor(Editor(obj=file2, tooltip="test_tooltip2"))

        ######## test tooltips #############

        self.assertEqual(editor_area.active_tabwidget.tabToolTip(0),
                         "test_tooltip0")
        self.assertEqual(editor_area.active_tabwidget.tabToolTip(1),
                         "test_tooltip1")
        self.assertEqual(editor_area.active_tabwidget.tabToolTip(2),
                         "test_tooltip2")

        ######## test set_layout #############

        # set the layout
        editor_area.set_layout(layout)

        # file0 goes to left pane?
        left = editor_area.control.leftchild
        editor = editor_area._get_editor(left.tabwidget().widget(0))
        self.assertEqual(editor.obj, file0)

        # right pane is a splitter made of two panes?
        right = editor_area.control.rightchild
        self.assertFalse(right.is_leaf())

        # right pane is vertical splitter?
        self.assertEqual(right.orientation(), QtCore.Qt.Vertical)

        # top pane of this vertical split is empty?
        right_top = right.leftchild
        self.assertTrue(right_top.is_empty())

        # bottom pane is not empty?
        right_bottom = right.rightchild
        self.assertFalse(right_bottom.is_empty())

        # file1 goes first on bottom pane?
        editor = editor_area._get_editor(right_bottom.tabwidget().widget(0))
        self.assertEqual(editor.obj, file1)

        # file2 goes second on bottom pane?
        editor = editor_area._get_editor(right_bottom.tabwidget().widget(1))
        self.assertEqual(editor.obj, file2)

        # file1 tab is active?
        self.assertEqual(right_bottom.tabwidget().currentIndex(), 0)

        ######### test get_layout #############

        # obtain layout
        layout_new = editor_area.get_layout()

        # is the top level a horizontal splitter?
        self.assertIsInstance(layout_new, Splitter)
        self.assertEqual(layout_new.orientation, 'horizontal')

        # tests on left child
        left = layout_new.items[0]
        self.assertIsInstance(left, Tabbed)
        self.assertEqual(left.items[0].id, 0)

        # tests on right child
        right = layout_new.items[1]
        self.assertIsInstance(right, Splitter)
        self.assertEqual(right.orientation, 'vertical')

        # tests on top pane of right child
        right_top = right.items[0]
        self.assertIsInstance(right_top, Tabbed)
        self.assertEqual(right_top.items[0].id, -1)

        # tests on bottom pane of right child
        right_bottom = right.items[1]
        self.assertIsInstance(right_bottom, Tabbed)
        self.assertEqual(right_bottom.items[0].id, 1)
        self.assertEqual(right_bottom.items[1].id, 2)