def _create_ui(self): hbox = Gtk.HBox() self.main.remove(self.main.get_child()) self.main.add(hbox) hbox.show() self.forms = ObjectList( [Column('description', title=_('Description'), sorted=True, expand=True, format_func=stoqlib_gettext)], self.store.find(UIForm), Gtk.SelectionMode.BROWSE) self.forms.connect('selection-changed', self._on_forms__selection_changed) self.forms.set_headers_visible(False) self.forms.set_size_request(200, -1) hbox.pack_start(self.forms, False, False, 0) self.forms.show() box = Gtk.VBox() hbox.pack_start(box, True, True, 0) box.show() self.fields = ObjectList(self._get_columns(), [], Gtk.SelectionMode.BROWSE) box.pack_start(self.fields, True, True, 0) self.fields.show() box.show()
def _create_list(self, column_title): object_list = ObjectList([ KanbanObjectListColumn('markup', title=column_title, data_type=str, use_markup=True, expand=True), ]) object_list.connect('row-activated', self._on_row_activated) object_list.connect('right-click', self._on_right_click) sw = object_list.get_scrolled_window() sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) sw.set_shadow_type(Gtk.ShadowType.NONE) treeview = object_list.get_treeview() treeview.set_name(column_title) treeview.connect( "button-press-event", self._on_button_press_event) treeview.set_rules_hint(False) column = object_list.get_column_by_name('markup') column.treeview_column.set_clickable(False) white = Gdk.color_parse('white') treeview.modify_base(Gtk.StateType.ACTIVE, white) treeview.modify_base(Gtk.StateType.SELECTED, white) object_list.set_cell_data_func(self._on_results__cell_data_func) return object_list
def _create_ui(self): hbox = gtk.HBox() self.klist = ObjectList([Column('name')]) self.klist.set_size_request(150, -1) self.klist.get_treeview().set_headers_visible(False) self.klist.connect('selection-changed', self._on_klist__selection_changed) hbox.pack_start(self.klist) hbox.show() for name, ctype in [(_(u'Units'), DeviceConstant.TYPE_UNIT), (_(u'Tax'), DeviceConstant.TYPE_TAX), (_(u'Payments'), DeviceConstant.TYPE_PAYMENT)]: self.klist.append(Settable(name=name, type=ctype)) self.klist.show() self._constant_slave = _DeviceConstantsList(self.store, self.printer) self._constant_slave.switch(DeviceConstant.TYPE_UNIT) hbox.pack_start(self._constant_slave.get_toplevel()) # FIXME: redesign BasicDialog self.main.remove(self.main_label) self.main.add(hbox) hbox.show_all()
def test(): # pragma no cover from nose.exc import SkipTest try: import gi gi # workaround pyflakes except ImportError: raise SkipTest("can't run test without pygobject installed") from kiwi.ui.objectlist import ObjectList from stoq.api import api as stoq_api from stoqlib.api import api from stoq.gui.sales import SalesApp from stoqlib.domain.sale import SaleView stoq_api.prepare_test() store = api.new_store() class Foo(SalesApp): def __init__(self): pass a = Foo() ol = ObjectList(a.get_columns()) data = store.find(SaleView) r = SalesReport('teste.pdf', ol, list(data)) r.save_html('teste.html') r.save()
def setUp(self): self.klist = ObjectList() self.klist.connect('has-rows', self._on_klist__has_rows) self.klist.connect('selection-changed', self._on_klist__selection_changed) self.rows = None self.selected = None
def create_list(self): self._list = ObjectList([ Column('done', title=_('Done'), data_type=bool, editable=True), Column('title', title=_('Title'), data_type=str, editable=True, expand=True), Column('priority', title=_('Priority'), data_type=ChecklistStatus, editable=True) ]) self._list.connect('cell-edited', self._on_item_edit) self._list.connect('selection-changed', self._on_item_selected) self._list.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self._vbox.add(self._list) self._sort_combo = AttrSortCombo(self._list, [ ('done', _('Done')), ('title', _('Title')), ('priority', _('Priority')), ], 'title') self._vbox.pack_start(self._sort_combo, expand=False) self._list.show_all() self._sort_combo.show_all()
def test_export_from_object_list(self): from kiwi.ui.objectlist import ObjectList, Column fruits = ObjectList( [Column('name', data_type=str), Column('price', data_type=int)]) for name, price in [('Apple', 4), ('Pineapple', 2), ('Kiwi', 8), ('Banana', 3), ('Melon', 5)]: fruits.append(Fruit(name, price)) ofx = XLSExporter() ofx.add_from_object_list(fruits) try: temp_file = ofx.save() with open(temp_file.name, 'rb') as f: data = f.read() # We should use xlrd to 're-open' the spreadsheet and parse its content. self.assertTrue(len(data) > 0) finally: temp_file.close() os.unlink(temp_file.name)
def _setup_widgets(self): self.set_ok_label(_(u'Activate'), gtk.STOCK_APPLY) self.ok_button.set_sensitive(False) plugins = [] for name in sorted(self._manager.available_plugins_names): # FIXME: Remove when magento plugin is functional for end users if not is_developer_mode() and name == 'magento': continue if platform.system() == 'Windows': if name in ['ecf', 'tef']: continue desc = self._manager.get_description_by_name(name) plugins.append( _PluginModel(name, name in self._manager.installed_plugins_names, desc)) self.klist = ObjectList(self._get_columns(), plugins, gtk.SELECTION_BROWSE) self.klist.set_headers_visible(False) self.klist.connect("selection-changed", self._on_klist__selection_changed) self.main.remove(self.main.get_child()) self.main.add(self.klist) self.klist.show()
def setup_slaves(self): self.delivery_items = ObjectList( columns=self._get_delivery_items_columns(), objects=self.model.delivery_items, ) self.delivery_items_holder.add(self.delivery_items) self.delivery_items.show()
def __init__(self, model, parent): super(DetailsTab, self).__init__() self.model = model self._parent = parent self.set_spacing(6) self.set_border_width(6) self.klist = ObjectList(self.get_columns()) self.klist.add_list(self.populate()) self.pack_start(self.klist) self.klist.show() if len(self.klist) and self.get_details_dialog_class(): self.button_box = gtk.HButtonBox() self.button_box.set_layout(gtk.BUTTONBOX_START) details_button = gtk.Button(self.details_lbl) self.button_box.pack_start(details_button) details_button.set_sensitive(bool(self.klist.get_selected())) details_button.show() self.pack_end(self.button_box, False, False) self.button_box.show() self.button_box.details_button = details_button details_button.connect('clicked', self._on_details_button__clicked) self.klist.connect('row-activated', self._on_klist__row_activated) self.klist.connect('selection-changed', self._on_klist__selection_changed) self.setup_widgets()
def testOneColumn(self): # column's attribute can not contain spaces self.assertRaises(AttributeError, Column, 'test column') mylist = ObjectList(Column('test_column')) self.win.add(mylist) refresh_gui() self.assertEqual(1, len(mylist.get_columns()))
def __init__(self, parent): self.parent = parent self.news_list = ObjectList([ Column('title', 'Title of article', str), Column('author', 'Author of article', str), Column('url', 'Address of article', str)]) SlaveDelegate.__init__(self, toplevel=self.news_list) self.news_list.add_list(news) self.news_list.select(self.news_list[0])
def add_tab(self, name): box = gtk.HBox() box.set_border_width(6) box.show() olist = ObjectList() box.pack_start(olist) olist.show() self.history_notebook.append_page(box, gtk.Label(name)) return olist
def create_objectlist(self, icon_name, text): l = ObjectList([Column('title', use_markup=True)]) l.connect('row-activated', self._on_item_activated) l.connect('selection-changed', self._on_item_selected) l.set_headers_visible(False) l.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self._books.append_page(l, tab_label=self.create_tab_label( icon_name, text)) return l
def _run_exporter(self, sse): objectlist = ObjectList() path = 'stoqlib.gui.dialogs.spreadsheetexporterdialog.Gio.app_info_get_default_for_type' with mock.patch(path) as Gio: app_info = mock.Mock() app_info.get_name.return_value = 'App Name' Gio.return_value = app_info sse.export(object_list=objectlist, name='Title', filename_prefix='name-prefix')
def _setup_list(self): methods = PaymentMethod.get_editable_methods(self.store) self.klist = ObjectList(self._get_columns(), methods, Gtk.SelectionMode.BROWSE) self.klist.connect("selection-changed", self._on_klist__selection_changed) self.klist.connect("row-activated", self._on_klist__row_activated) self.klist.connect("cell-edited", self.on_cell_edited) self.main.remove(self.main.get_child()) self.main.add(self.klist) self.klist.show()
def testRadioWithoutTrue(self): olist = ObjectList( [Column('foo', radio=True, data_type=bool, editable=True)]) column = olist.get_treeview().get_column(0) renderer = column.get_cells()[0] items = [Settable(foo=False) for i in range(5)] olist.add_list(items) self.assertEqual(items[0].foo, False) renderer.emit('toggled', 0) self.assertEqual(items[0].foo, True)
def __init__(self): self.entries = ObjectList([Column("title", width=120, sorted=True), Column("period", width=80), Column("text", expand=True, visible=False)]) ProxyDelegate.__init__(self, DiaryEntry(), ['title', 'period', 'text', 'chars', 'words'], gladefile="diary2.ui", delete_handler=self.quit_if_last) self.hbox.pack_start(self.entries) self.entries.show() self.entries.grab_focus() self.set_editable(False)
def haveWidgetTree(self): self.widget = gtk.VBox() self.widget.set_border_width(6) self.properties = ObjectList( [Column('name'), Column('value')]) self.properties.set_size_request(-1, 200) self.widget.pack_start(self.properties, False, False) self.properties.show() self._reloadProperties(self.state.get('config')['properties']) return self.widget
def _create_ui(self): self.cancel_button.hide() hbox = Gtk.HBox(spacing=6) self.main.remove(self.main.get_child()) self.main.add(hbox) hbox.show() self.categories = ObjectList( [Column('label', sorted=True, expand=True)], get_binding_categories(), Gtk.SelectionMode.BROWSE) self.categories.connect('selection-changed', self._on_categories__selection_changed) self.categories.set_headers_visible(False) self.categories.set_size_request(200, -1) hbox.pack_start(self.categories, False, False, 0) self.categories.show() box = Gtk.VBox(spacing=6) hbox.pack_start(box, True, True, 0) box.show() self.shortcuts = ObjectList(self._get_columns(), [], Gtk.SelectionMode.BROWSE) box.pack_start(self.shortcuts, True, True, 0) self.shortcuts.show() self._label = Gtk.Label( label=_("You need to restart Stoq for the changes to take effect")) box.pack_start(self._label, False, False, 6) box.show() defaults_button = Gtk.Button(_("Reset defaults")) defaults_button.connect('clicked', self._on_defaults_button__clicked) self.action_area.pack_start(defaults_button, False, False, 6) self.action_area.reorder_child(defaults_button, 0) defaults_button.show()
def __init__(self, store, columns=None, editor_class=None, klist_objects=None, visual_mode=False, restore_name=None, tree=False): """ Creates a new AdditionListSlave object :param store: a store :param columns: column definitions :type columns: sequence of :class:`kiwi.ui.objectlist.Columns` :param editor_class: the window that is going to be open when user clicks on add_button or edit_button. :type: editor_class: a :class:`stoqlib.gui.editors.BaseEditor` subclass :param klist_objects: initial objects to insert into the list :param visual_mode: if we are working on visual mode, that means, not possible to edit the model on this object type visual_mode: bool :param restore_name: the name used to save and restore the columns on a cache system (e.g. pickle) :type restore_name: basestring :param tree: Indication of which kind of list we are adding. If `True` ObjectTree otherwise ObjectList will be added """ columns = columns or self.get_columns() SearchSlave.__init__(self, columns=columns, restore_name=restore_name, store=store) self.tree = tree self.klist = ObjectTree() if tree else ObjectList() self.list_vbox.add(self.klist) self.list_vbox.show_all() if not self.columns: raise StoqlibError("columns must be specified") self.visual_mode = visual_mode self.store = store self.set_editor(editor_class) self._can_edit = True self._callback_id = None if self.visual_mode: self.hide_add_button() self.hide_edit_button() self.hide_del_button() items = klist_objects or self.get_items() self._setup_klist(items) self._update_sensitivity()
def __init__(self): self.entries = ObjectList([ Column("title", width=120), Column("period", width=80), Column("text", expand=True) ]) ProxyDelegate.__init__(self, DiaryEntry(), ['title', 'period', 'text'], gladefile="diary.ui", delete_handler=self.quit_if_last) self.hbox.pack_start(self.entries, True, True, 0) self.entries.show() self.entries.grab_focus()
def buildObjectList(self, mediaList): """ This method builds and initialize the ObjectList. """ self.mediaList = ObjectList(media_list_columns) self.mediaList.connect('selection_changed', self.media_selected) self.mediaList.connect('double-click', self.double_click) for media in mediaList: mf = MediaFile(media.getFilename(), uri=media.getURI(), length=media.getLengthSec()) mf.lastPlayed = media.getLastPlayed() self.mediaList.append(mf)
def testInsert(self): self.klist = ObjectList([Column('name')]) self.assertEqual(list(self.klist), []) self.klist.insert(0, Settable(name='one')) self.assertEqual(self.klist[0].name, 'one') self.klist.insert(0, Settable(name='two')) self.assertEqual(self.klist[0].name, 'two') self.assertEqual(self.klist[1].name, 'one') self.klist.insert(1, Settable(name='three')) self.assertEqual(self.klist[0].name, 'two') self.assertEqual(self.klist[1].name, 'three') self.assertEqual(self.klist[2].name, 'one')
def testExportFromObjectList(self): fruits = ObjectList( [Column('name', data_type=str), Column('price', data_type=int)]) for name, price in [('Apple', 4), ('Pineapple', 2), ('Kiwi', 8), ('Banana', 3), ('Melon', 5)]: fruits.append(Fruit(name, price)) ofx = XLSExporter() ofx.add_from_object_list(fruits) temp_file = ofx.save() data = open(temp_file.name).read() # We should use xlrd to 're-open' the spreadsheet and parse its content. self.assertTrue(len(data) > 0)
def test(): from kiwi.ui.objectlist import ObjectList from stoqlib.api import api from stoq.gui.sales import SalesApp from stoqlib.domain.sale import SaleView api.prepare_test() store = api.new_store() class Foo(SalesApp): def __init__(self): pass a = Foo() ol = ObjectList(a.get_columns()) data = store.find(SaleView) r = SalesReport('teste.pdf', ol, list(data)) r.save_html('teste.html') r.save()
def _setup_widgets(self): self.set_ok_label(_(u'Activate'), Gtk.STOCK_APPLY) self.ok_button.set_sensitive(False) plugins = [] for name in sorted(self._manager.available_plugins_names): desc = self._manager.get_description_by_name(name) plugins.append( _PluginModel(name, name in self._manager.installed_plugins_names, desc)) self.klist = ObjectList(self._get_columns(), plugins, Gtk.SelectionMode.BROWSE) self.klist.set_headers_visible(False) self.klist.connect("selection-changed", self._on_klist__selection_changed) self.main.remove(self.main.get_child()) self.main.add(self.klist) self.klist.show()
def _create_field_list(self): items = ObjectList([ Column('description', width=200), Column('len', data_type=int, editable=True) ]) items.enable_dnd() items.set_size_request(200, -1) descriptions = {} invoice_fields = get_invoice_fields() for invoice_field in sorted(invoice_fields, key=operator.attrgetter('name')): items.append( Settable(description=invoice_field.get_description(), name=invoice_field.name, len=invoice_field.length)) descriptions[invoice_field.name] = invoice_field.description self._field_descriptions = descriptions self.left_vbox.pack_end(items, True, True) items.show()
def __init__(self): self._js_data = None self._js_options = None self._current = None gtk.Window.__init__(self) self.set_size_request(800, 480) self.vbox = gtk.VBox() self.add(self.vbox) self.vbox.show() hbox = gtk.HBox() self.vbox.pack_start(hbox, False, False, 6) hbox.show() label = gtk.Label('Period:') hbox.pack_start(label, False, False, 6) label.show() self.chart_type = ProxyComboBox() self.chart_type.connect('content-changed', self._on_chart_type__content_changed) hbox.pack_start(self.chart_type, False, False, 6) self.chart_type.show() self.period_values = ProxyComboBox() self.period_values.connect('content-changed', self._on_period_values__content_changed) hbox.pack_start(self.period_values, False, False, 6) self.period_values.show() self._view = WebView() self._view.get_view().connect('load-finished', self._on_view__document_load_finished) self.vbox.pack_start(self._view, True, True) self.results = ObjectList() self.results.connect('row-activated', self._on_results__row_activated) self.vbox.pack_start(self.results, True, True) self._setup_daemon()
def __init__(self): Delegate.__init__(self, gladefile="news_shell.ui", delete_handler=self.quit_if_last) # paint header and footer; they are eventboxes that hold a # label and buttonbox respectively gadgets.set_background(self.header, "white") gadgets.set_background(self.footer, "#A0A0A0") gadgets.set_foreground(self.title, "blue") # Create the delegate and set it up objectlist = ObjectList(my_columns, news) objectlist.connect('selection-changed', self.news_selected) objectlist.connect('double-click', self.double_click) slave = SlaveDelegate(toplevel=objectlist) self.attach_slave("placeholder", slave) slave.focus_toplevel() # Must be done after attach self.slave = slave