def start_taxonomy_check(): '''run the batch taxonomy check (BTC) ''' view = GenericEditorView( os.path.join(paths.lib_dir(), 'plugins', 'plants', 'taxonomy_check.glade'), parent=None, root_widget_name='dialog1') model = type('BTCStatus', (object,), {})() model.page = 1 model.selection = view.get_selection() model.tick_off = None model.report = None model.file_path = '' if model.selection is None: return from sqlalchemy.orm import object_session presenter = BatchTaxonomicCheckPresenter( model, view, refresh_view=True, session=object_session(model.selection[0])) error_state = presenter.start() if error_state: presenter.session.rollback() else: presenter.commit_changes() from bauble import gui view = gui.get_view() if hasattr(view, 'update'): view.update() presenter.cleanup() return error_state
def start_taxonomy_check(): """run the batch taxonomy check (BTC) """ view = GenericEditorView( os.path.join(paths.lib_dir(), "plugins", "plants", "taxonomy_check.glade"), parent=None, root_widget_name="dialog1", ) model = type("BTCStatus", (object,), {})() model.page = 1 model.selection = view.get_selection() model.tick_off = None model.report = None model.file_path = "" if model.selection is None: return from sqlalchemy.orm import object_session presenter = BatchTaxonomicCheckPresenter(model, view, refresh_view=True, session=object_session(model.selection[0])) error_state = presenter.start() if error_state: presenter.session.rollback() else: presenter.commit_changes() from bauble import gui view = gui.get_view() if hasattr(view, "update"): view.update() presenter.cleanup() return error_state
def test_set_sensitive(self): filename = os.path.join(paths.lib_dir(), "connmgr.glade") view = GenericEditorView(filename, root_widget_name="main_dialog") view.widget_set_sensitive("cancel_button", True) self.assertTrue(view.widgets.cancel_button.get_sensitive()) view.widget_set_sensitive("cancel_button", False) self.assertFalse(view.widgets.cancel_button.get_sensitive())
def test_add_widget(self): import gtk filename = os.path.join(paths.lib_dir(), "bauble.glade") view = GenericEditorView(filename) label = gtk.Label("testing") view.widget_add("statusbar", label)
def __init__(self, parent=None): GenericEditorView.__init__( self, os.path.join(paths.lib_dir(), "plugins", "garden", "loc_editor.glade"), parent=parent ) self.use_ok_and_add = True self.set_accept_buttons_sensitive(False) # if the parent isn't the main bauble window then we assume # that the LocationEditor was opened from the PlantEditor and # so we shouldn't enable adding more plants...this is a bit of # a hack but it serves our purposes if bauble.gui and parent != bauble.gui.window: self.use_ok_and_add = False
def __init__(self, parent=None): GenericEditorView.__init__(self, os.path.join(paths.lib_dir(), 'plugins', 'garden', 'loc_editor.glade'), parent=parent) self.use_ok_and_add = True self.set_accept_buttons_sensitive(False) # if the parent isn't the main bauble window then we assume # that the LocationEditor was opened from the PlantEditor and # so we shouldn't enable adding more plants...this is a bit of # a hack but it serves our purposes if bauble.gui and parent != bauble.gui.window: self.use_ok_and_add = False
def test_can_programmatically_connect_signals(self): from bauble.editor import (GenericEditorPresenter, GenericEditorView) class HandlerDefiningPresenter(GenericEditorPresenter): def on_tag_desc_textbuffer_changed(self, *args): pass model = db.History() import tempfile ntf = tempfile.NamedTemporaryFile() ntf.write('''\ <interface> <requires lib="gtk+" version="2.24"/> <!-- interface-naming-policy toplevel-contextual --> <object class="GtkTextBuffer" id="tag_desc_textbuffer"> <signal name="changed" handler="on_tag_desc_textbuffer_changed" swapped="no"/> </object> </interface> ''') ntf.flush() fn = ntf.name view = GenericEditorView(fn) presenter = HandlerDefiningPresenter(model, view) self.assertEquals( len(presenter.view._GenericEditorView__attached_signals), 1)
def test_set_visible_get_visible(self): filename = os.path.join(paths.lib_dir(), 'connmgr.glade') view = GenericEditorView(filename, root_widget_name='main_dialog') view.widget_set_visible('noconnectionlabel', True) self.assertTrue(view.widget_get_visible('noconnectionlabel')) self.assertTrue(view.widgets.noconnectionlabel.get_visible()) view.widget_set_visible('noconnectionlabel', False) self.assertFalse(view.widget_get_visible('noconnectionlabel')) self.assertFalse(view.widgets.noconnectionlabel.get_visible())
def test_set_visible_get_visible(self): filename = os.path.join(paths.lib_dir(), "connmgr.glade") view = GenericEditorView(filename, root_widget_name="main_dialog") view.widget_set_visible("noconnectionlabel", True) self.assertTrue(view.widget_get_visible("noconnectionlabel")) self.assertTrue(view.widgets.noconnectionlabel.get_visible()) view.widget_set_visible("noconnectionlabel", False) self.assertFalse(view.widget_get_visible("noconnectionlabel")) self.assertFalse(view.widgets.noconnectionlabel.get_visible())
def test_set_sensitive(self): filename = os.path.join(paths.lib_dir(), 'connmgr.glade') view = GenericEditorView(filename, root_widget_name='main_dialog') view.widget_set_sensitive('cancel_button', True) self.assertTrue(view.widgets.cancel_button.get_sensitive()) view.widget_set_sensitive('cancel_button', False) self.assertFalse(view.widgets.cancel_button.get_sensitive())
def start_connection_manager(default_conn=None): '''activate connection manager and return connection name and uri ''' glade_path = os.path.join(paths.lib_dir(), "connmgr.glade") view = GenericEditorView(glade_path, parent=None, root_widget_name='main_dialog') cm = ConnMgrPresenter(view) result = cm.start() if result == gtk.RESPONSE_OK: return cm.connection_name, cm.connection_uri else: return None, None
def edit_callback(tags): tag = tags[0] if tag is None: tag = Tag() view = GenericEditorView(os.path.join(paths.lib_dir(), 'plugins', 'tag', 'tag.glade'), parent=None, root_widget_name='tag_dialog') presenter = TagEditorPresenter(tag, view, refresh_view=True) error_state = presenter.start() if error_state: presenter.session.rollback() else: presenter.commit_changes() presenter.cleanup() return error_state
def start_institution_editor(): glade_path = os.path.join(paths.lib_dir(), "plugins", "garden", "institution.glade") from bauble import prefs from bauble.editor import GenericEditorView, MockView if prefs.testing: view = MockView() else: view = GenericEditorView(glade_path, parent=None, root_widget_name='inst_dialog') view._tooltips = { 'inst_name': _('The full name of the institution.'), 'inst_abbr': _('The standard abbreviation of the ' 'institution.'), 'inst_code': _('The intitution code should be unique among ' 'all institions.'), 'inst_contact': _('The name of the person to contact for ' 'information related to the institution.'), 'inst_tech': _('The email address or phone number of the ' 'person to contact for technical ' 'information related to the institution.'), 'inst_email': _('The email address of the institution.'), 'inst_tel': _('The telephone number of the institution.'), 'inst_fax': _('The fax number of the institution.'), 'inst_addr': _('The mailing address of the institition.') } o = Institution() inst_pres = InstitutionPresenter(o, view) response = inst_pres.start() if response == gtk.RESPONSE_OK: o.write() inst_pres.commit_changes() else: inst_pres.session.rollback() inst_pres.session.close()
def test_add_widget(self): import gtk filename = os.path.join(paths.lib_dir(), 'bauble.glade') view = GenericEditorView(filename) label = gtk.Label('testing') view.widget_add('statusbar', label)
def test_set_title_ok(self): filename = os.path.join(paths.lib_dir(), "bauble.glade") view = GenericEditorView(filename, root_widget_name="main_window") title = "testing" view.set_title(title) self.assertEquals(view.get_window().get_title(), title)
def test_create_generic_view(self): filename = os.path.join(paths.lib_dir(), 'bauble.glade') view = GenericEditorView(filename) print type(view.widgets) self.assertTrue(type(view.widgets) is utils.BuilderWidgets)
def test_set_title_ok(self): filename = os.path.join(paths.lib_dir(), 'bauble.glade') view = GenericEditorView(filename, root_widget_name='main_window') title = 'testing' view.set_title(title) self.assertEquals(view.get_window().get_title(), title)
def test_set_icon_no_root(self): filename = os.path.join(paths.lib_dir(), 'bauble.glade') view = GenericEditorView(filename) title = 'testing' self.assertRaises(NotImplementedError, view.set_icon, title)
def test_set_accept_buttons_sensitive_not_set(self): 'it is a task of the presenter to indicate the accept buttons' filename = os.path.join(paths.lib_dir(), 'connmgr.glade') view = GenericEditorView(filename, root_widget_name='main_dialog') self.assertRaises(AttributeError, view.set_accept_buttons_sensitive, True)