Ejemplo n.º 1
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)
Ejemplo n.º 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
Ejemplo n.º 3
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
Ejemplo n.º 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
Ejemplo n.º 5
0
class MainWindow(gtk.Window):
    def __init__(self):
        gtk.Window.__init__(self)

        self.set_default_size(500, 150)
        self.set_title('DockGroup Demo')
        self.set_border_width(4)
        self.file_counter = 1

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

        ########################################################################
        # Docking
        ########################################################################
        self.dg = DockGroup()
        vbox.pack_start(self.dg)

        ########################################################################
        # 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)

        self.show_all()

    def _on_add_di_button_clicked(self, button):
        examples = [('calc', 'calculator', '#!/usr/bin/env python\n\nprint \'Hello!\''),
                    ('file-manager', 'Hi!', 'Hello!'),
                    ('fonts', 'ABC', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
                    ('style', 'abc', 'abcdefghijklmnopqrstuvwxyz'),
                    ('web-browser', 'browser', '0123456789'),
                    ('date', 'today', '9876543210')]

        for i in range(random.randrange(1, 10, 1)):
            icon_name, tooltip_text, text = random.choice(examples)

            # 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)

            # Create a DockItem and add our TextView
            di = DockItem(icon_name=icon_name, title='New %s' % self.file_counter, title_tooltip_text=tooltip_text)
            di.add(scrolledwindow)
            di.show_all()

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

            # Increment file counter
            self.file_counter += 1
Ejemplo n.º 6
0
    def test_add(self):
        dockgroup = DockGroup()
        dockpaned = DockPaned()
        dockpaned.add(dockgroup)

        self.assertTrue(dockgroup in dockpaned)

        dockgroup.destroy()
        dockpaned.destroy()
Ejemplo n.º 7
0
    def test_add(self):
        dockitem = DockItem()
        dockgroup = DockGroup()
        dockgroup.add(dockitem)

        self.assertTrue(dockitem in dockgroup)

        dockitem.destroy()
        dockgroup.destroy()
Ejemplo n.º 8
0
    def test_append_item(self):
        dockitem = DockItem()
        dockgroup = DockGroup()
        index = dockgroup.append_item(dockitem)

        self.assertTrue(index == 0)
        self.assertTrue(dockgroup.get_nth_item(0) is dockitem)

        dockitem.destroy()
        dockgroup.destroy()
Ejemplo n.º 9
0
    def test_remove(self):
        dockgroup = DockGroup()
        dockpaned = DockPaned()
        dockpaned.add(dockgroup)
        dockpaned.remove(dockgroup)

        self.assertTrue(dockgroup not in dockpaned)

        dockgroup.destroy()
        dockpaned.destroy()
Ejemplo n.º 10
0
    def test_add_signal(self):
        events = []
        item_in = []
        item_in_after = []
        def event_handler(self, w):
            events.append(w)
            item_in.append(w in self.items)

        def event_handler_after(self, w):
            item_in_after.append(w in self.items)


        dockgroup = DockGroup()
        dockgroup.connect('add', event_handler)
        dockgroup.connect_after('add', event_handler_after)

        dockitem1 = DockItem()
        dockgroup.add(dockitem1)
        self.assertEquals([dockitem1], events)
        self.assertEquals([True], item_in)
        self.assertEquals([True], item_in_after)

        dockitem2 = DockItem()
        dockgroup.insert_item(dockitem2)
        self.assertEquals([dockitem1], events)
        self.assertEquals([True], item_in)
        self.assertEquals([True], item_in_after)
Ejemplo n.º 11
0
    def test_child_destroy(self):
        dockgroup = DockGroup()
        dockpaned = DockPaned()
        dockpaned.add(dockgroup)

        self.assertTrue(len(dockpaned) == len(dockpaned._items) == 1)

        dockgroup.destroy()

        self.assertTrue(len(dockpaned) == len(dockpaned._items) == 0)

        dockgroup.destroy()
        dockpaned.destroy()
Ejemplo n.º 12
0
    def test_drag_begin(self):
        dockitem1 = DockItem()
        dockitem2 = DockItem()
        dockitem3 = DockItem()
        dockgroup = DockGroup()
        dockgroup.add(dockitem1)
        dockgroup.add(dockitem2)
        dockgroup.add(dockitem3)

        window = gtk.Window()
        window.add(dockgroup)
        window.set_size_request(200, 200)

        self.assertEquals(dockitem3, dockgroup._current_tab.item)
Ejemplo n.º 13
0
def dock_group_factory(parent, weight=None, name=None):
    group = DockGroup()

    if name:
        group.set_name(name)

    if weight is not None:
        parent.insert_item(group, weight=float(weight) / 100.)
    else:
        parent.add(group)

    group.show()

    return group
Ejemplo n.º 14
0
    def test_add_signal(self):
        add_events = []

        def on_add(self, widget):
            add_events.append(widget)

        dockgroup = DockGroup()
        dockpaned = DockPaned()
        dockpaned.connect('add', on_add)
        dockpaned.add(dockgroup)

        self.assertTrue(dockgroup in add_events)

        dockgroup.destroy()
        dockpaned.destroy()
Ejemplo n.º 15
0
    def test_item_destroy(self):
        win = gtk.Window()
        dockitem = DockItem()
        dockgroup = DockGroup()
        dockgroup.add(dockitem)
        win.add(dockgroup)
        win.show_all()

        assert len(dockgroup.items) == 1
        dockitem.destroy()

        self.assertTrue(dockitem not in dockgroup)
        assert len(dockgroup.items) == 0

        win.destroy()
        dockgroup.destroy()
Ejemplo n.º 16
0
    def test_delitem(self):
        dg = DockGroup()
        dockpaned = DockPaned()
        dockpaned.add(DockGroup())
        dockpaned.add(dg)
        dockpaned.add(DockGroup())
        
        assert dg in dockpaned
        assert len(dockpaned) == 3
        assert dg is dockpaned[1]
        del dockpaned[1]
        assert len(dockpaned) == 2
        assert dg not in dockpaned

        dg.destroy()
        dockpaned.destroy()
Ejemplo n.º 17
0
    def __init__(self):
        gtk.Window.__init__(self)

        self.set_default_size(500, 150)
        self.set_title('DockGroup Demo')
        self.set_border_width(4)
        self.file_counter = 1

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

        ########################################################################
        # Docking
        ########################################################################
        self.dg = DockGroup()
        vbox.pack_start(self.dg)

        ########################################################################
        # 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)

        self.show_all()
Ejemplo n.º 18
0
    def test_get_current_item(self):
        dockitem = DockItem()
        dockgroup = DockGroup()
        self.assertTrue(dockgroup.get_current_item() is None)

        index = dockgroup.append_item(dockitem)
        self.assertTrue(dockgroup.get_current_item() == index)

        dockgroup.remove(dockitem)
        self.assertTrue(dockgroup.get_current_item() is None)

        dockitem.destroy()
        dockgroup.destroy()
Ejemplo n.º 19
0
    def test_item_closed_event_is_emited_on_close(self):
        dockitem = DockItem()
        dockgroup = DockGroup()
        dockgroup.add(dockitem)

        tab = dockgroup._tabs[0]

        item_closed = []
        def item_closed_handler(item):
            item_closed.append(item)

        dockitem.connect('close', item_closed_handler)

        # Simulate clicking the close button
        tab.button.emit('clicked')

        assert [dockitem] == item_closed
Ejemplo n.º 20
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)
Ejemplo n.º 21
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)
Ejemplo n.º 22
0
    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
Ejemplo n.º 23
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)
Ejemplo n.º 24
0
    def test_remove_item(self):
        dockitem1 = DockItem()
        dockitem2 = DockItem()
        dockgroup = DockGroup()
        dockgroup.add(dockitem1)
        dockgroup.add(dockitem2)
        dockgroup.remove_item(0)
        dockgroup.remove_item(None)

        self.assertTrue(dockitem1 not in dockgroup)
        self.assertTrue(dockitem2 not in dockgroup)

        dockitem1.destroy()
        dockitem2.destroy()
        dockgroup.destroy()
Ejemplo n.º 25
0
    def test_child_prop_weight(self):
        global child_notify_called

        def _on_child_notify(gobject, pspec):
            global child_notify_called
            child_notify_called = True

        dockpaned = DockPaned()
        dockgroup = DockGroup()
        dockgroup.connect('child-notify::weight', _on_child_notify)
        dockpaned.add(dockgroup)

        child_notify_called = False
        dockpaned.child_set_property(dockgroup, 'weight', 0.3)
        self.assertTrue(child_notify_called,
                        msg='weight child property change notification failed')

        dockgroup.destroy()
        dockpaned.destroy()
Ejemplo n.º 26
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
Ejemplo n.º 27
0
    def test_insert_item(self):
        dockitem1 = DockItem()
        dockitem2 = DockItem()
        dockitem3 = DockItem()
        dockgroup = DockGroup()
        dockgroup.insert_item(dockitem1, None)
        dockgroup.insert_item(dockitem2, 0)
        dockgroup.insert_item(dockitem3, 1)

        self.assertTrue(dockgroup.get_nth_item(0) is dockitem2)
        self.assertTrue(dockgroup.get_nth_item(1) is dockitem3)
        self.assertTrue(dockgroup.get_nth_item(2) is dockitem1)

        dockitem1.destroy()
        dockitem2.destroy()
        dockitem3.destroy()
        dockgroup.destroy()
Ejemplo n.º 28
0
    def test_get_n_items(self):
        dockgroup = DockGroup()
        self.assertTrue(dockgroup.get_n_items() == len(dockgroup) == 0)

        dockitem = DockItem()
        dockgroup.add(dockitem)
        self.assertTrue(dockgroup.get_n_items() == len(dockgroup) == 1)

        dockitem.destroy()
        dockgroup.destroy()
Ejemplo n.º 29
0
 def create_item(self, ui_component):  #, widget, title, placement=None):
     """
     Create an item for a ui component. This method can be called from UIComponents.
     """
     item = DockItem(ui_component.title)
     item.add(ui_component.open())
     group = DockGroup()
     group.insert_item(item)
     placement = ui_component.placement
     if placement:
         if placement == 'floating':
             add_new_group_floating(group, self.layout, ui_component.size)
         else:
             location = self.layout.get_widgets(placement[1])[0]
             {
                 'left': add_new_group_left,
                 'right': add_new_group_right,
                 'above': add_new_group_above,
                 'below': add_new_group_below
             }[placement[0]](location, group)
     else:
         add_new_group_floating(group)
     item.show()
     item.ui_component = ui_component
     group.show()
Ejemplo n.º 30
0
    def test_item_removed_signal(self):
        remove_events = []
        item_removed_events = []

        def on_remove(self, widget):
            remove_events.append(widget)

        def on_item_removed(dockpaned, child):
            item_removed_events.append(child)

        dockgroup1 = DockGroup()
        dockgroup2 = DockGroup()
        dockpaned = DockPaned()
        dockpaned.connect('remove', on_remove)
        dockpaned.connect('item-removed', on_item_removed)
        dockpaned.add(dockgroup1)
        dockpaned.add(dockgroup2)
        dockpaned.remove(dockgroup1)
        dockpaned.remove_item(0)

        self.assertTrue(dockgroup1 in item_removed_events)
        self.assertTrue(dockgroup1 in remove_events)
        self.assertTrue(dockgroup2 in item_removed_events)
        self.assertFalse(dockgroup2 in remove_events)

        dockgroup1.destroy()
        dockgroup2.destroy()
        dockpaned.destroy()
Ejemplo n.º 31
0
    def test_item_added_signal(self):
        add_events = []
        item_added_events = []

        def on_add(self, widget):
            add_events.append(widget)

        def on_item_added(dockpaned, child):
            item_added_events.append(child)

        dockgroup1 = DockGroup()
        dockgroup2 = DockGroup()
        dockpaned = DockPaned()
        dockpaned.connect('add', on_add)
        dockpaned.connect('item-added', on_item_added)
        dockpaned.add(dockgroup1)
        dockpaned.insert_item(dockgroup2)

        self.assertTrue(dockgroup1 in item_added_events)
        self.assertTrue(dockgroup1 in add_events)
        self.assertTrue(dockgroup2 in item_added_events)
        self.assertFalse(dockgroup2 in add_events)

        dockgroup2.destroy()
        dockgroup1.destroy()
        dockpaned.destroy()
Ejemplo n.º 32
0
    def test_get_nth_item(self):
        dockitem1 = DockItem()
        dockitem2 = DockItem()
        dockgroup = DockGroup()
        dockgroup.add(dockitem1)
        dockgroup.add(dockitem2)

        self.assertTrue(dockgroup.get_nth_item(0) is dockitem1)
        self.assertTrue(dockgroup.get_nth_item(1) is dockitem2)
        self.assertTrue(dockgroup.get_nth_item(2) is None)
        self.assertTrue(dockgroup.get_nth_item(-1) is None)

        dockitem1.destroy()
        dockitem2.destroy()
        dockgroup.destroy()
Ejemplo n.º 33
0
def dock_group_factory(parent, weight=None, name=None):
    group = DockGroup()

    if name:
        group.set_name(name)

    if weight is not None:
        parent.insert_item(group, weight=float(weight) / 100.)
    else:
        parent.add(group)

    group.show()

    return group