示例#1
0
    def test_construction_after_setting_layout(self):
        win = gtk.Window(gtk.WINDOW_TOPLEVEL)
        frame = DockFrame()
        paned = DockPaned()
        group = DockGroup()
        item = DockItem()

        layout = DockLayout()

        layout.add(frame)

        win.add(frame)
        frame.add(paned)
        paned.add(group)
        group.add(item)

        assert frame in layout.frames
        self.assertEquals(4, len(layout._signal_handlers))
        self.assertEquals(9, len(layout._signal_handlers[frame]))

        paned.remove(group)

        self.assertEquals(2, len(layout._signal_handlers), layout._signal_handlers)
        assert frame in layout._signal_handlers.keys(), layout._signal_handlers
        assert paned in layout._signal_handlers.keys(), layout._signal_handlers
        assert group not in layout._signal_handlers.keys(), layout._signal_handlers
        assert item not in layout._signal_handlers.keys(), layout._signal_handlers
        assert frame in layout.frames
示例#2
0
    def test_get_widgets(self):
        win = gtk.Window(gtk.WINDOW_TOPLEVEL)
        frame = DockFrame()
        paned = DockPaned()
        group = DockGroup()
        item = DockItem()
        label = gtk.Label()

        layout = DockLayout()

        layout.add(frame)

        win.add(frame)
        frame.add(paned)
        paned.add(group)
        group.add(item)
        item.add(label)

        group2 = DockGroup()
        paned.add(group2)

        paned.set_name('foo')

        widgets = list(layout.get_widgets('foo'))
        assert len(widgets) == 1
        assert widgets[0] is paned

        widgets = list(layout.get_widgets('EtkDockGroup'))
        assert len(widgets) == 2
        assert widgets[0] is group
        assert widgets[1] is group2
示例#3
0
    def test_remove_empty_groups_recursively(self):
        win = gtk.Window(gtk.WINDOW_TOPLEVEL)
        frame = DockFrame()
        paneds = (DockPaned(), DockPaned(), DockPaned())
        group = DockGroup()
        item = DockItem()

        layout = self.layout

        layout.add(frame)

        win.add(frame)
        frame.add(paneds[0])
        paneds[0].add(paneds[1])
        paneds[1].add(paneds[2])
        paneds[2].add(group)

        win.set_default_size(200, 200)
        win.show_all()

        context = StubContext(group, None)
        layout.on_widget_drag_end(group, context)

        # TODO: check is paned[0]
        assert not paneds[0].get_parent()
示例#4
0
    def test_construction(self):
        win = gtk.Window(gtk.WINDOW_TOPLEVEL)
        frame = DockFrame()
        paned = DockPaned()
        group = DockGroup()
        item = DockItem()

        win.add(frame)
        frame.add(paned)
        paned.add(group)
        group.add(item)

        layout = DockLayout()

        layout.add(frame)

        assert frame in layout.frames
        print layout._signal_handlers
        self.assertEquals(4, len(layout._signal_handlers))
        self.assertEquals(9, len(layout._signal_handlers[frame]))

        layout.remove(frame)

        assert not layout._signal_handlers, layout._signal_handlers
        assert frame not in layout.frames
示例#5
0
    def test_remove_paned_with_one_child(self):
        win = gtk.Window(gtk.WINDOW_TOPLEVEL)
        frame = DockFrame()
        paned = DockPaned()
        groups = (DockGroup(), DockGroup())
        item = DockItem()

        layout = self.layout

        layout.add(frame)

        win.add(frame)
        frame.add(paned)
        map(paned.add, groups)
        #groups[0].add(item)

        win.set_default_size(200, 200)
        win.show_all()

        # simulate end of DnD on group
        context = StubContext(groups[0], None)
        layout.on_widget_drag_end(groups[0], context)

        assert not paned.get_parent()
        assert groups[1].get_parent() is frame
示例#6
0
    def test_remove_nested_paned_with_one_child(self):
        win = gtk.Window(gtk.WINDOW_TOPLEVEL)
        frame = DockFrame()
        paneds = (DockPaned(), DockPaned())
        groups = (DockGroup(), DockGroup())
        item = DockItem()

        layout = self.layout

        layout.add(frame)

        win.add(frame)
        frame.add(paneds[0])
        paneds[0].add(groups[0])
        paneds[0].add(paneds[1])
        paneds[1].add(groups[1])
        #groups[0].add(item)

        win.set_default_size(200, 200)
        win.show_all()

        # simulate end of DnD on group, where group is removed and only one
        # paned remains.
        context = StubContext(groups[0], None)
        layout.on_widget_drag_end(paneds[1], context)

        assert not paneds[1].get_parent()
        assert groups[1].get_parent() is paneds[0], (paneds, groups[1].get_parent())
示例#7
0
    def test_drag_drop_on_paned(self):
        win = gtk.Window(gtk.WINDOW_TOPLEVEL)
        frame = DockFrame()
        paned = DockPaned()
        groups = (DockGroup(), DockGroup())
        item = DockItem()

        layout = self.layout

        layout.add(frame)

        win.add(frame)
        frame.add(paned)
        map(paned.add, groups)
        groups[0].add(item)

        win.set_default_size(200, 200)
        win.show_all()


        x, y = 10, 10
        context = StubContext(groups[0], [groups[0].items[0]])
        layout.on_widget_drag_motion(paned, context, x, y, 0)

        assert layout._drag_data
        assert layout._drag_data.drop_widget is paned, '%s != %s' % (layout._drag_data.drop_widget, paned)
示例#8
0
    def test_drag_drop_on_group(self):
        win = gtk.Window(gtk.WINDOW_TOPLEVEL)
        frame = DockFrame()
        paned = DockPaned()
        group = DockGroup()
        item = DockItem()

        layout = self.layout

        layout.add(frame)

        win.add(frame)
        frame.add(paned)
        paned.add(group)
        group.add(item)

        win.set_default_size(200, 200)
        win.show_all()

        while gtk.events_pending():
            gtk.main_iteration()


        context = StubContext(group, [group.items[0]])

        group.do_drag_begin(context)
        x, y = 30, 30
        layout.on_widget_drag_motion(group, context, x, y, 0)

        assert layout._drag_data
        assert layout._drag_data.drop_widget is group

        layout.on_widget_drag_drop(group, context, x, y, 0)
示例#9
0
文件: layout.py 项目: Nyox/gaphor
def dock_frame_factory(parent, width, height, floating=None, x=None, y=None):
    frame = DockFrame()
    frame.set_size_request(int(width), int(height))

    if floating == 'true':
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        #self.window.set_type_hint(gdk.WINDOW_TYPE_HINT_UTILITY)
        window.set_property('skip-taskbar-hint', True)
        window.move(int(x), int(y))
        window.add(frame)
        window.set_transient_for(parent)
        window.show()
    else:
        parent.add(frame)
    
    frame.show()

    return frame
示例#10
0
    def setUp(self):
        self.layout = DockLayout()
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.frame = DockFrame()
        self.group = DockGroup()

        self.layout.add(self.frame)
        self.window.add(self.frame)
        self.frame.add(self.group)
示例#11
0
    def test_serialize(self):
        win = gtk.Window(gtk.WINDOW_TOPLEVEL)
        layout = DockLayout()
        frame = DockFrame()
        win.add(frame)
        layout.add(frame)
        paned = DockPaned()
        frame.add(paned)
        group = DockGroup()
        paned.add(group)
        item = DockItem(title='t', title_tooltip_text='xx', icon_name='icon', stock_id="")
        item.set_name('fillme')
        group.add(item)

        s = serialize(layout)
        assert '<layout><dockframe height="1" width="1">'\
        '<dockpaned orientation="horizontal">'\
        '<dockgroup weight="100">'\
        '<dockitem icon_name="icon" title="t" tooltip="xx" />'\
        '</dockgroup></dockpaned></dockframe></layout>' == s, s
示例#12
0
def default_window(n_groups):
    world.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    world.window.set_default_size(800, 150)
    world.frame = DockFrame()
    world.window.add(world.frame)
    world.layout = DockLayout()
    world.layout.add(world.frame)
    paned = DockPaned()
    world.frame.add(paned)
    world.window.show()
    world.frame.show()
    paned.show()
    world.groups = []
    for i in range(int(n_groups)):
        group = DockGroup()
        paned.add(group)
        group.show()
        world.groups.append(group)
示例#13
0
文件: layout.py 项目: xqbumu/gaphor
def dock_frame_factory(parent, width, height, floating=None, x=None, y=None):
    frame = DockFrame()
    frame.set_size_request(int(width), int(height))

    if floating == 'true':
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        #self.window.set_type_hint(gdk.WINDOW_TYPE_HINT_UTILITY)
        window.set_property('skip-taskbar-hint', True)
        window.move(int(x), int(y))
        window.add(frame)
        window.set_transient_for(parent)
        window.show()
    else:
        parent.add(frame)

    frame.show()

    return frame
示例#14
0
class PlacementTest(unittest.TestCase):

    def setUp(self):
        self.layout = DockLayout()
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.frame = DockFrame()
        self.group = DockGroup()

        self.layout.add(self.frame)
        self.window.add(self.frame)
        self.frame.add(self.group)

    def test_placement_left(self):

        g1, g2 = DockGroup(), DockGroup()

        docklayout.add_new_group_left(self.group, g1)

        paned = g1.get_parent()
        assert isinstance(paned, DockPaned), paned
        assert self.group.get_parent() is paned
        assert paned.get_nth_item(0) is g1
        assert paned.get_nth_item(1) is self.group

        docklayout.add_new_group_left(self.group, g2)
        assert self.group.get_parent() is paned
        assert g2.get_parent() is paned
        assert paned.get_nth_item(0) is g1
        assert paned.get_nth_item(1) is g2
        assert paned.get_nth_item(2) is self.group

    def test_placement_right(self):

        g1, g2 = DockGroup(), DockGroup()

        docklayout.add_new_group_right(self.group, g1)

        paned = g1.get_parent()
        assert isinstance(paned, DockPaned), paned
        assert self.group.get_parent() is paned
        assert paned.get_nth_item(0) is self.group
        assert paned.get_nth_item(1) is g1

        docklayout.add_new_group_right(self.group, g2)
        assert self.group.get_parent() is paned
        assert g2.get_parent() is paned
        assert paned.get_nth_item(0) is self.group
        assert paned.get_nth_item(1) is g2
        assert paned.get_nth_item(2) is g1


    def test_placement_above(self):

        g1, g2 = DockGroup(), DockGroup()

        docklayout.add_new_group_above(self.group, g1)

        paned = g1.get_parent()
        assert isinstance(paned, DockPaned), paned
        assert self.group.get_parent() is paned
        assert paned.get_nth_item(0) is g1
        assert paned.get_nth_item(1) is self.group

        docklayout.add_new_group_above(self.group, g2)
        assert self.group.get_parent() is paned
        assert g2.get_parent() is paned
        assert paned.get_nth_item(0) is g1
        assert paned.get_nth_item(1) is g2
        assert paned.get_nth_item(2) is self.group

    def test_placement_below(self):

        g1, g2 = DockGroup(), DockGroup()

        docklayout.add_new_group_below(self.group, g1)

        paned = g1.get_parent()
        assert isinstance(paned, DockPaned), paned
        assert self.group.get_parent() is paned
        assert paned.get_nth_item(0) is self.group
        assert paned.get_nth_item(1) is g1

        docklayout.add_new_group_below(self.group, g2)
        assert self.group.get_parent() is paned
        assert g2.get_parent() is paned
        assert paned.get_nth_item(0) is self.group
        assert paned.get_nth_item(1) is g2
        assert paned.get_nth_item(2) is g1
示例#15
0
    def __init__(self, docklayout=None, dockframe=None):
        gtk.Window.__init__(self)

        self.set_default_size(500, 150)
        self.set_title("etk.docking demo")
        self.set_border_width(4)
        self.file_counter = 1
        self.subwindows = []

        vbox = gtk.VBox()
        vbox.set_spacing(4)
        self.add(vbox)

        ########################################################################
        # Docking
        ########################################################################
        if docklayout and dockframe:
            self.dockframe = dockframe
            self.docklayout = docklayout
        else:
            self.dockframe = DockFrame()
            self.dockframe.set_border_width(8)
            g = DockGroup()
            g.set_name("main")
            self.dockframe.add(g)
            self.docklayout = DockLayout()
            self.docklayout.add(self.dockframe)

        settings["main"].auto_remove = False
        settings["main"].can_float = True
        settings["main"].inherit_settings = False
        settings["main"].expand = False

        # To change default group behaviour:
        # self.docklayout.settings[None].inherit_settings = False

        vbox.pack_start(self.dockframe)

        def on_item_closed(layout, group, item):
            item.destroy()
            print "closed item:", item.title

        self.docklayout.connect("item-closed", on_item_closed)

        def on_item_selected(layout, group, item):
            print "Selected item:", item.title

        self.docklayout.connect("item-selected", on_item_selected)

        ########################################################################
        # Testing Tools
        ########################################################################
        adddibutton = gtk.Button("Create docked items")
        adddibutton.child.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        adddibutton.connect("clicked", self._on_add_di_button_clicked)
        vbox.pack_start(adddibutton, False, False)

        orientationbutton = gtk.Button("Switch Orientation")
        orientationbutton.child.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        orientationbutton.connect("clicked", self._on_orientation_button_clicked)
        vbox.pack_start(orientationbutton, False, False)

        hbox = gtk.HBox()

        savebutton = gtk.Button("Save layout")
        savebutton.child.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        savebutton.connect("clicked", self._on_save_button_clicked)
        hbox.pack_start(savebutton, True, True)

        loadbutton = gtk.Button("Load layout")
        loadbutton.child.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        loadbutton.connect("clicked", self._on_load_button_clicked)
        hbox.pack_start(loadbutton, True, True)

        vbox.pack_start(hbox, False, False)

        self.show_all()
示例#16
0
class MainWindow(gtk.Window):
    def __init__(self, docklayout=None, dockframe=None):
        gtk.Window.__init__(self)

        self.set_default_size(500, 150)
        self.set_title("etk.docking demo")
        self.set_border_width(4)
        self.file_counter = 1
        self.subwindows = []

        vbox = gtk.VBox()
        vbox.set_spacing(4)
        self.add(vbox)

        ########################################################################
        # Docking
        ########################################################################
        if docklayout and dockframe:
            self.dockframe = dockframe
            self.docklayout = docklayout
        else:
            self.dockframe = DockFrame()
            self.dockframe.set_border_width(8)
            g = DockGroup()
            g.set_name("main")
            self.dockframe.add(g)
            self.docklayout = DockLayout()
            self.docklayout.add(self.dockframe)

        settings["main"].auto_remove = False
        settings["main"].can_float = True
        settings["main"].inherit_settings = False
        settings["main"].expand = False

        # To change default group behaviour:
        # self.docklayout.settings[None].inherit_settings = False

        vbox.pack_start(self.dockframe)

        def on_item_closed(layout, group, item):
            item.destroy()
            print "closed item:", item.title

        self.docklayout.connect("item-closed", on_item_closed)

        def on_item_selected(layout, group, item):
            print "Selected item:", item.title

        self.docklayout.connect("item-selected", on_item_selected)

        ########################################################################
        # Testing Tools
        ########################################################################
        adddibutton = gtk.Button("Create docked items")
        adddibutton.child.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        adddibutton.connect("clicked", self._on_add_di_button_clicked)
        vbox.pack_start(adddibutton, False, False)

        orientationbutton = gtk.Button("Switch Orientation")
        orientationbutton.child.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        orientationbutton.connect("clicked", self._on_orientation_button_clicked)
        vbox.pack_start(orientationbutton, False, False)

        hbox = gtk.HBox()

        savebutton = gtk.Button("Save layout")
        savebutton.child.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        savebutton.connect("clicked", self._on_save_button_clicked)
        hbox.pack_start(savebutton, True, True)

        loadbutton = gtk.Button("Load layout")
        loadbutton.child.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        loadbutton.connect("clicked", self._on_load_button_clicked)
        hbox.pack_start(loadbutton, True, True)

        vbox.pack_start(hbox, False, False)

        self.show_all()

        # def on_has_toplevel_focus(window, pspec):
        #    print 'Has toplevel focus', window, pspec
        #    print 'Focus widget is', window.get_focus()

        # self.connect('notify::has-toplevel-focus', on_has_toplevel_focus)

    def _on_add_di_button_clicked(self, button):
        def add_dockitems(child):
            if isinstance(child, DockGroup):
                self._add_dockitems(child)
            elif isinstance(child, DockPaned):
                for child in child:
                    add_dockitems(child)

        for child in self.dockframe:
            add_dockitems(child)

    def _on_orientation_button_clicked(self, button):
        def switch_orientation(paned):
            if isinstance(paned, DockPaned):
                if paned.get_orientation() == gtk.ORIENTATION_HORIZONTAL:
                    paned.set_orientation(gtk.ORIENTATION_VERTICAL)
                else:
                    paned.set_orientation(gtk.ORIENTATION_HORIZONTAL)

                for child in paned.get_children():
                    switch_orientation(child)

        paned = self.dockframe.get_children()[0]
        switch_orientation(paned)

    def _on_save_button_clicked(self, button):
        file = "demo.sav"
        s = dockstore.serialize(self.docklayout)

        with open(file, "w") as f:
            f.write(s)

    def _on_load_button_clicked(self, button):
        file = "demo.sav"

        with open(file) as f:
            s = f.read()

        newlayout = dockstore.deserialize(s, self._create_content)
        main_frames = list(dockstore.get_main_frames(newlayout))
        assert len(main_frames) == 1, main_frames
        subwindow = MainWindow(newlayout, main_frames[0])
        self.subwindows.append(subwindow)
        dockstore.finish(newlayout, main_frames[0])

        for f in newlayout.frames:
            f.get_toplevel().show_all()

    def _create_content(self, text=None):
        # Create a TextView and set some example text
        scrolledwindow = gtk.ScrolledWindow()
        scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        textview = gtk.TextView()
        textview.get_buffer().set_text(text)
        scrolledwindow.add(textview)
        return scrolledwindow

    def _add_dockitems(self, dockgroup):
        examples = [
            (gtk.STOCK_EXECUTE, "calculator", "#!/usr/bin/env python\n\nprint 'Hello!'"),
            (gtk.STOCK_OPEN, "Hi!", "Hello!"),
            (gtk.STOCK_FILE, "ABC", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"),
            (gtk.STOCK_FIND, "abc", "abcdefghijklmnopqrstuvwxyz"),
            (gtk.STOCK_HARDDISK, "browser", "0123456789"),
            (gtk.STOCK_HOME, "today", "9876543210"),
            gtk.Notebook,
        ]

        for i in [1]:  # range(random.randrange(1, 10, 1)):
            example = random.choice(examples)

            if example is gtk.Notebook:
                child = gtk.Notebook()
                child.append_page(gtk.Button("Click me"), gtk.Label("New %s" % self.file_counter))
                stock_id = ""
                tooltip_text = "notebook"
            else:
                stock_id, tooltip_text, text = example
                child = self._create_content(text)
                child.set_name(stock_id)

            # Create a DockItem and add our TextView
            di = DockItem(title="New %s" % self.file_counter, title_tooltip_text=tooltip_text, stock_id=stock_id)

            def on_close(item):
                print "close:", item

            di.connect("close", on_close)
            di.add(child)
            di.show_all()

            # Add out DockItem to the DockGroup
            dockgroup.add(di)

            # Increment file counter
            self.file_counter += 1