def create_ui(self): columns = [ Column('name', str), Column('surname', str), Column('email', str, editable=True), ] self.objects = ObjectList(columns) self.widget.add(self.objects)
def test_make_cells(self): col = Column(title='Test', cells=[ Cell('name', int), Cell('name2', int), ]) view_col = col.create_treecolumn(None) self.assertEqual(len(view_col.get_cells()), 2)
def test_tooltip_image_size(self): c = Column('test', tooltip_attr='attr', tooltip_type='iconname', tooltip_image_size=Gtk.IconSize.MENU) t = MockTooltip() o = Fruit() c.render_tooltip(t, o) self.assertEqual(t.iconname, 'value') self.assertEqual(t.size, Gtk.IconSize.MENU)
def get_trace_view(self, exc, tb): olist = ObjectList([Column('markup', use_markup=True)]) olist.set_headers_visible(False) while tb is not None: olist.append(TracebackEntry(tb)) tb = tb.tb_next return olist
def test_column_title(self): col = Column("name") view_col = col.create_treecolumn(None) self.assertEqual(view_col.get_title(), "Name") title_col = Column(title="Test", cells=[]) title_view_col = title_col.create_treecolumn(None) self.assertEqual(title_view_col.get_title(), 'Test') self.assertEqual(len(title_view_col.get_cells()), 0)
def create_ui(self): self.widget = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) columns = [ Column(attr=self.column_name, sortable=True, editable=False, resizeable=True) ] self.list_box = ObjectList(columns) for item in self.items: self.add_item(item) s = self.list_box.get_selection() s.set_mode(Gtk.SelectionMode.MULTIPLE) self.list_box.show_all() self.widget.pack_start(self.list_box)
def test_tooltip_type_pixbuf_attr(self): c = Column('test', tooltip_attr='attr', tooltip_type='pixbuf') t = MockTooltip() o = Fruit() c.render_tooltip(t, o) self.assertEqual(t.pixbuf, 'value')
class User(object): def __init__(self, name, age, sex, hair='brown', clever=False): self.name = name self.age = age assert sex in ('m', 'f') self.sex = sex self.hair = hair self.clever = clever def __str__(self): return '<User: name=%r age=%r sex=%r hair=%r clever=%r>' % ( self.name, self.age, self.sex, self.hair, self.clever) listing = ObjectTree([ Column('name', str, editable=True, searchable=True), Column('age', int, editable=True), Column('sex', str, expander=True, choices=[ ('m', 'Male'), ('f', 'Female'), ]), Column('hair', str, choices=['brown', 'blonde'], tooltip_attr='name'), Column('clever', bool, use_checkbox=True, editable=True), Column('age', int, use_spin=True, editable=True), Column('age', int, use_progress=True), Column('age', int, use_progress=True, progress_text='static_text'), Column('age', int, use_progress=True, mapped={'text': 'name'}), ])
def test_tooltip_type_text_attr(self): c = Column('test', tooltip_attr='attr') t = MockTooltip() o = Fruit() c.render_tooltip(t, o) self.assertEqual(t.text, 'value')
def test_column_expandable(self): col = Column('name', expand=True) tree_view_column = col.create_treecolumn(None) self.assertTrue(tree_view_column.props.expand)
from pyGtkHelpers.ui.objectlist import ObjectList, ObjectTree, Column class User(object): def __init__(self, name, age): self.name = name self.age = age def __eq__(self, other): return self.name == other.name and self.age == other.age items = [ Column('name', str, editable=True, searchable=True), Column('age', int), Column('expander', expander=True), ] def pytest_generate_tests(metafunc): if ('items' in metafunc.funcargnames or 'searchcheck' in metafunc.funcargnames): if not hasattr(metafunc.function, 'tree_only'): metafunc.addcall(id='list', param=ObjectList) if not hasattr(metafunc.function, 'list_only'): metafunc.addcall(id='tree', param=ObjectTree) def pytest_funcarg__items(request): return request.param(items)
def test_column_invisiblility(self): col = Column('test', visible=False) view_col = col.create_treecolumn(None) self.assertFalse(view_col.get_visible())
def test_column_width(self): col = Column('test', width=30) view_col = col.create_treecolumn(None) refresh_gui() self.assertEqual(view_col.get_sizing(), Gtk.TreeViewColumnSizing.FIXED) self.assertEqual(view_col.get_fixed_width(), 30)
def test_tooltip_type_markup_value(self): c = Column('test', tooltip_value='banana', tooltip_type='markup') t = MockTooltip() o = Fruit() c.render_tooltip(t, o) self.assertEqual(t.markup, 'banana')
def test_column_visiblility(self): col = Column('test') view_col = col.create_treecolumn(None) self.assertTrue(view_col.get_visible())
def test_tooltip_type_markup_attr(self): c = Column('test', tooltip_attr='attr', tooltip_type='markup') t = MockTooltip() o = Fruit() c.render_tooltip(t, o) self.assertEqual(t.markup, 'value')
def test_tooltip_type_custom_value(self): c = Column('test', tooltip_value='banana', tooltip_type='custom') t = MockTooltip() o = Fruit() c.render_tooltip(t, o) self.assertEqual(t.custom, 'banana')
def test_tooltip_type_pixbuf_value(self): c = Column('test', tooltip_value='banana', tooltip_type='pixbuf') t = MockTooltip() o = Fruit() c.render_tooltip(t, o) self.assertEqual(t.pixbuf, 'banana')
def test_tooltip_type_iconname_attr(self): c = Column('test', tooltip_attr='attr', tooltip_type='iconname') t = MockTooltip() o = Fruit() c.render_tooltip(t, o) self.assertEqual(t.iconname, 'value')
def test_tooltip_type_iconname_value(self): c = Column('test', tooltip_value='banana', tooltip_type='iconname') t = MockTooltip() o = Fruit() c.render_tooltip(t, o) self.assertEqual(t.iconname, 'banana')
def test_tooltip_type_stock_attr(self): c = Column('test', tooltip_attr='attr', tooltip_type='stock') t = MockTooltip() o = Fruit() c.render_tooltip(t, o) self.assertEqual(t.stock, 'value')
def test_tooltip_type_stock_value(self): c = Column('test', tooltip_value='banana', tooltip_type='stock') t = MockTooltip() o = Fruit() c.render_tooltip(t, o) self.assertEqual(t.stock, 'banana')
class User(object): def __init__(self, name, age, sex): self.name = name self.age = age assert sex in ('m', 'f') self.sex = sex def __str__(self): return '<User: name=%r age=%r sex=%r>' % (self.name, self.age, self.sex) listing = ObjectList([ Column('name', str, editable=False, resizable=True), Column('age', int, editable=True), Column('sex', str, choices=[ ('m', 'Male'), ('f', 'Female'), ]), ]) def _on_left_clicked(ol, item, event): print 'Left clicked', item def _on_right_clicked(ol, item, event): print 'Right clicked', item
class IconInfo(object): def __init__(self, stock_name, name): self.stock_name = stock_name self._name = name @property def name(self): return '<b>%s</b>' % self._name icons = ObjectList([ Column(title='Stock Data', cells=[ Cell('stock_name', gtk.Pixmap, use_stock=True), Cell('stock_name', str), ], sorted=False), Column('name', str, 'Name', use_markup=True), ], sortable=True) for id in gtk.stock_list_ids(): lookup = gtk.stock_lookup(id) if lookup is None: continue stock_name, name = gtk.stock_lookup(id)[:2] name = name.replace('_', '') icons.append(IconInfo(stock_name, name)) scroll = gtk.ScrolledWindow()