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
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
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)
def test_add(self): dockitem = DockItem() dockgroup = DockGroup() dockgroup.add(dockitem) self.assertTrue(dockitem in dockgroup) dockitem.destroy() dockgroup.destroy()
def test_add(self): button = gtk.Button() dockitem = DockItem() dockitem.add(button) self.assertTrue(dockitem.child is button) button.destroy() dockitem.destroy()
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()
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()
def test_item_num(self): dockitem1 = DockItem() dockitem2 = DockItem() dockgroup = DockGroup() dockgroup.add(dockitem1) self.assertTrue(dockgroup.item_num(dockitem1) == 0) self.assertTrue(dockgroup.item_num(dockitem2) is None) dockitem1.destroy() dockgroup.destroy()
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()
def test_item_added_signal(self): add_events = [] item_added_events = [] def on_add(self, widget): add_events.append(widget) def on_item_added(dockgroup, child): item_added_events.append(child) dockitem1 = DockItem() dockitem2 = DockItem() dockgroup = DockGroup() dockgroup.connect('add', on_add) dockgroup.connect('item-added', on_item_added) dockgroup.add(dockitem1) dockgroup.insert_item(dockitem2) self.assertTrue(dockitem1 in item_added_events) self.assertTrue(dockitem1 in add_events) self.assertTrue(dockitem2 in item_added_events) self.assertFalse(dockitem2 in add_events) dockitem2.destroy() dockitem1.destroy() dockgroup.destroy()
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)
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()
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
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())
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()
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) list(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
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) list(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)
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)
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 list( layout._signal_handlers.keys()), layout._signal_handlers assert paned in list( layout._signal_handlers.keys()), layout._signal_handlers assert group not in list( layout._signal_handlers.keys()), layout._signal_handlers assert item not in list( layout._signal_handlers.keys()), layout._signal_handlers assert frame in layout.frames
def test_remove(self): button = gtk.Button() dockitem = DockItem() dockitem.add(button) dockitem.remove(button) self.assertTrue(dockitem.child is None) button.destroy() dockitem.destroy()
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
def test_remove(self): win = gtk.Window() dockitem = DockItem() dockgroup = DockGroup() dockgroup.add(dockitem) win.add(dockgroup) win.show_all() assert dockitem.flags() & gtk.REALIZED dockgroup.remove(dockitem) self.assertTrue(dockitem not in dockgroup) win.destroy() assert not dockitem.flags() & gtk.REALIZED assert not dockgroup.flags() & gtk.REALIZED
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()
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) print(s) assert bytes(b'<layout><dockframe height="1" width="1">' b'<dockpaned orientation="horizontal">' b'<dockgroup weight="100">' b'<dockitem icon_name="icon" title="t" tooltip="xx" />' b'</dockgroup></dockpaned></dockframe></layout>' ) == s, s
def test_prepend_item(self): dockitem1 = DockItem() dockitem2 = DockItem() dockgroup = DockGroup() index1 = dockgroup.append_item(dockitem1) index2 = dockgroup.prepend_item(dockitem2) self.assertTrue(index1 == 0) self.assertTrue(index2 == 0) self.assertTrue(dockgroup.get_nth_item(0) is dockitem2) self.assertTrue(dockgroup.get_nth_item(1) is dockitem1) dockitem1.destroy() dockitem2.destroy() dockgroup.destroy()
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()
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()
def test_reorder_item(self): dockitem1 = DockItem() dockitem2 = DockItem() dockitem3 = DockItem() dockgroup = DockGroup() dockgroup.add(dockitem1) dockgroup.add(dockitem2) dockgroup.add(dockitem3) dockgroup.reorder_item(dockitem3, 0) dockgroup.reorder_item(dockitem1, 2) self.assertTrue(dockgroup.item_num(dockitem1) == 2) self.assertTrue(dockgroup.item_num(dockitem2) == 1) self.assertTrue(dockgroup.item_num(dockitem3) == 0) dockitem1.destroy() dockitem2.destroy() dockitem3.destroy() dockgroup.destroy()
def test_remove_signal(self): remove_events = [] item_removed_events = [] def on_remove(self, widget): remove_events.append(widget) def on_item_removed(dockgroup, child): item_removed_events.append(child) dockitem = DockItem() dockitem.add(gtk.Button()) dockgroup = DockGroup() dockgroup.connect('remove', on_remove) dockgroup.connect('item-removed', on_item_removed) dockgroup.add(dockitem) dockgroup.remove(dockitem) self.assertTrue(dockitem in remove_events) self.assertTrue(dockitem in item_removed_events) dockitem.destroy() dockgroup.destroy()
def test_prev_item(self): dockitem1 = DockItem() dockitem2 = DockItem() dockgroup = DockGroup() dockgroup.add(dockitem1) dockgroup.add(dockitem2) self.assertTrue(dockgroup.get_current_item() == 1) dockgroup.prev_item() self.assertTrue(dockgroup.get_current_item() == 0) dockgroup.prev_item() self.assertTrue(dockgroup.get_current_item() == 0) dockitem1.destroy() dockitem2.destroy() dockgroup.destroy()
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
def test_set_current_item(self): dockitem1 = DockItem() dockitem2 = DockItem() dockgroup = DockGroup() self.assertTrue(dockgroup.get_current_item() is None) index = dockgroup.append_item(dockitem1) self.assertTrue(dockgroup.get_current_item() == index) index = dockgroup.append_item(dockitem2) self.assertTrue(dockgroup.get_current_item() == index) dockgroup.set_current_item(0) self.assertTrue(dockgroup.get_current_item() == 0) dockgroup.set_current_item(len(dockgroup) + 10) self.assertTrue(dockgroup.get_current_item() == len(dockgroup) - 1) dockgroup.set_current_item(-1) self.assertTrue(dockgroup.get_current_item() == 0) dockitem1.destroy() dockitem2.destroy() dockgroup.destroy()
def test_prop_title_tooltip_text(self): global notify_called def _on_notify(gobject, pspec): global notify_called notify_called = True dockitem = DockItem() dockitem.connect('notify::title-tooltip-text', _on_notify) notify_called = False dockitem.set_title_tooltip_text('sometext') self.assertEquals(dockitem.get_title_tooltip_text(), 'sometext', msg='get_title_tooltip_text method did not return expected value') self.assertTrue(notify_called, msg='title-tooltip-text property change notification failed when using set_title_tooltip_text method') notify_called = False dockitem.set_property('title-tooltip-text', 'anothertext') self.assertEquals(dockitem.get_property('title-tooltip-text'), 'anothertext', msg='get_property method did not return expected value') self.assertTrue(notify_called, msg='title-tooltip-text property change notification failed when using set_title_tooltip_text method') notify_called = False dockitem.props.title_tooltip_text = 'hello' self.assertEquals(dockitem.props.title_tooltip_text, 'hello', msg='.props attribute did not return expected value') self.assertTrue(notify_called, msg='title-tooltip-text property change notification failed when using .props attribute') dockitem.destroy()
def test_prop_image(self): # TODO: is there a way to check we actually received the image we expect? dockitem = DockItem() dockitem.set_icon_name('someicon') self.assertTrue(isinstance(dockitem.get_image(), gtk.Image)) self.assertTrue(isinstance(dockitem.props.image, gtk.Image)) self.assertTrue(isinstance(dockitem.get_property('image'), gtk.Image)) dockitem.destroy() dockitem = DockItem() dockitem.set_stock(gtk.STOCK_ABOUT) self.assertTrue(isinstance(dockitem.get_image(), gtk.Image)) self.assertTrue(isinstance(dockitem.props.image, gtk.Image)) self.assertTrue(isinstance(dockitem.get_property('image'), gtk.Image)) dockitem.destroy()
def test_prop_stock(self): global notify_called def _on_notify(gobject, pspec): global notify_called notify_called = True dockitem = DockItem() dockitem.connect('notify::stock', _on_notify) notify_called = False dockitem.set_stock(gtk.STOCK_ABOUT) self.assertEquals(dockitem.get_stock(), gtk.STOCK_ABOUT, msg='get_stock method did not return expected value') self.assertTrue(notify_called, msg='stock property change notification failed when using set_stock method') notify_called = False dockitem.set_property('stock', gtk.STOCK_ADD) self.assertEquals(dockitem.get_property('stock'), gtk.STOCK_ADD, msg='get_property method did not return expected value') self.assertTrue(notify_called, msg='stock property change notification failed when using set_property method') notify_called = False dockitem.props.stock = gtk.STOCK_APPLY self.assertEquals(dockitem.props.stock, gtk.STOCK_APPLY, msg='.props attribute did not return expected value') self.assertTrue(notify_called, msg='stock property change notification failed when using .props attribute') dockitem.destroy()
def test_prop_icon_name(self): global notify_called def _on_notify(gobject, pspec): global notify_called notify_called = True dockitem = DockItem() dockitem.connect('notify::icon-name', _on_notify) notify_called = False dockitem.set_icon_name('someicon') self.assertEquals(dockitem.get_icon_name(), 'someicon', msg='get_icon_name method did not return expected value') self.assertTrue(notify_called, msg='icon-name property change notification failed when using set_icon_name method') notify_called = False dockitem.set_property('icon-name', 'anothericon') self.assertEquals(dockitem.get_property('icon-name'), 'anothericon', msg='get_property method did not return expected value') self.assertTrue(notify_called, msg='icon-name property change notification failed when using set_property method') notify_called = False dockitem.props.icon_name = 'niceicon' self.assertEquals(dockitem.props.icon_name, 'niceicon', msg='.props attribute did not return expected value') self.assertTrue(notify_called, msg='icon-name property change notification failed when using .props attribute') dockitem.destroy()