def __init__(self): self.widgets = utils.load_widgets(os.path.join(paths.lib_dir(), "plugins", "report", 'report.glade')) self.dialog = self.widgets.report_dialog self.dialog.set_transient_for(bauble.gui.window) utils.setup_text_combobox(self.widgets.names_combo) utils.setup_text_combobox(self.widgets.formatter_combo) self._delete_sid = self.dialog.connect('delete-event', self.on_dialog_close_or_delete) self._close_sid = self.dialog.connect('close', self.on_dialog_close_or_delete) self._response_sid = self.dialog.connect('response', self.on_dialog_response)
def __init__(self): self.widgets = utils.load_widgets( os.path.join(paths.lib_dir(), "plugins", "report", 'report.glade')) self.dialog = self.widgets.report_dialog self.dialog.set_transient_for(bauble.gui.window) self.builder = self.widgets.builder utils.setup_text_combobox(self.widgets.names_combo) utils.setup_text_combobox(self.widgets.formatter_combo) self._delete_sid = self.dialog.connect( 'delete-event', self.on_dialog_close_or_delete) self._close_sid = self.dialog.connect( 'close', self.on_dialog_close_or_delete) self._response_sid = self.dialog.connect( 'response', self.on_dialog_response)
def init_enum_combo(self, widget_name, field): """ Initialize a gtk.ComboBox widget with name widget_name from enum values in self.model.field :param widget_name: :param field: """ combo = self.view.widgets[widget_name] mapper = object_mapper(self.model) values = sorted(mapper.c[field].type.values) # WARNING: this is really dangerous since it might mean that a # value is stored in the column that is not in the Enum # #if None in values: # values.remove(None) # values.insert(0, '') utils.setup_text_combobox(combo, values)
def __init__(self, report_dialog=None, *args): super(XSLFormatterSettingsBox, self).__init__(*args) filename = os.path.join(paths.lib_dir(), "plugins", "report", 'xsl', 'gui.glade') self.widgets = utils.load_widgets(filename) utils.setup_text_combobox(self.widgets.renderer_combo) combo = self.widgets.source_type_combo values = [_('Accession'), _('Plant/Clone'), _('Species')] utils.setup_text_combobox(combo, values=values) # keep a refefence to settings box so it doesn't get destroyed in # remove_parent() self.settings_box = self.widgets.settings_box self.widgets.remove_parent(self.widgets.settings_box) self.pack_start(self.settings_box) self.presenter = SettingsBoxPresenter(self.widgets) self.stylesheet_chooser = FileChooserButton(dialog_parent=report_dialog) self.widgets.stylesheet_alignment.add(self.stylesheet_chooser)
def __init__(self, parent, model, view, session): ''' :param model: an instance of class Propagation :param view: an instance of PropagationEditorView ''' super(SeedPresenter, self).__init__(model, view) self._dirty = False self.parent_ref = weakref.ref(parent) self.session = session self.propagation = self.model if not self.propagation._seed: self.propagation._seed = PropSeed() self.model = self.model._seed # TODO: if % germinated is not entered and nseeds and # # germinated are then automatically calculate the % germinated widgets = self.view.widgets distinct = lambda c: utils.get_distinct_values(c, self.session) # TODO: should also setup a completion on the entry utils.setup_text_combobox(self.view.widgets.seed_media_comboentry, distinct(PropSeed.media)) utils.setup_text_combobox(self.view.widgets.seed_container_comboentry, distinct(PropSeed.container)) utils.setup_text_combobox(self.view.widgets.seed_location_comboentry, distinct(PropSeed.location)) self.refresh_view() self.assign_simple_handler('seed_pretreatment_textview', 'pretreatment', editor.UnicodeOrNoneValidator()) # TODO: this should validate to an integer self.assign_simple_handler('seed_nseeds_entry', 'nseeds', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('seed_sown_entry', 'date_sown', editor.DateValidator()) utils.setup_date_button(self.view, 'seed_sown_entry', 'seed_sown_button') self.assign_simple_handler('seed_container_comboentry', 'container', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('seed_media_comboentry', 'media', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('seed_location_comboentry', 'location', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('seed_mvdfrom_entry', 'moved_from', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('seed_mvdto_entry', 'moved_to', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('seed_germdate_entry', 'germ_date', editor.DateValidator()) utils.setup_date_button(self.view, 'seed_germdate_entry', 'seed_germdate_button') self.assign_simple_handler('seed_ngerm_entry', 'nseedlings') self.assign_simple_handler('seed_pctgerm_entry', 'germ_pct') self.assign_simple_handler('seed_date_planted_entry', 'date_planted', editor.DateValidator()) utils.setup_date_button(self.view, 'seed_date_planted_entry', 'seed_date_planted_button')
def __init__(self, report_dialog=None, *args): super(XSLFormatterSettingsBox, self).__init__(*args) filename = os.path.join(paths.lib_dir(), "plugins", "report", 'xsl', 'gui.glade') self.widgets = utils.load_widgets(filename) utils.setup_text_combobox(self.widgets.renderer_combo) combo = self.widgets.source_type_combo values = [_('Accession'), _('Plant/Clone'), _('Species')] utils.setup_text_combobox(combo, values=values) # keep a refefence to settings box so it doesn't get destroyed in # remove_parent() self.settings_box = self.widgets.settings_box self.widgets.remove_parent(self.widgets.settings_box) self.pack_start(self.settings_box) self.presenter = SettingsBoxPresenter(self.widgets) self.stylesheet_chooser = FileChooserButton( dialog_parent=report_dialog) self.widgets.stylesheet_alignment.add(self.stylesheet_chooser)
def __init__(self, parent, model, view, session): ''' :param model: an instance of class Propagation :param view: an instance of PropagationEditorView ''' super(CuttingPresenter, self).__init__(model, view) self.parent_ref = weakref.ref(parent) self.session = session self._dirty = False # make the model for the presenter a PropCutting instead of a # Propagation self.propagation = self.model if not self.propagation._cutting: self.propagation._cutting = PropCutting() self.model = self.model._cutting init_combo = self.view.init_translatable_combo init_combo('cutting_type_combo', cutting_type_values, editor.UnicodeOrNoneValidator()) init_combo('cutting_length_unit_combo', length_unit_values) init_combo('cutting_tip_combo', tip_values) init_combo('cutting_leaves_combo', leaves_values) init_combo('cutting_buds_combo', flower_buds_values) init_combo('cutting_wound_combo', wound_values) init_combo('cutting_heat_unit_combo', bottom_heat_unit_values) widgets = self.view.widgets distinct = lambda c: utils.get_distinct_values(c, self.session) utils.setup_text_combobox(widgets.cutting_hormone_comboentry, distinct(PropCutting.hormone)) utils.setup_text_combobox(widgets.cutting_cover_comboentry, distinct(PropCutting.cover)) utils.setup_text_combobox(widgets.cutting_fungal_comboentry, distinct(PropCutting.fungicide)) utils.setup_text_combobox(widgets.cutting_location_comboentry, distinct(PropCutting.location)) utils.setup_text_combobox(widgets.cutting_container_comboentry, distinct(PropCutting.container)) utils.setup_text_combobox(widgets.cutting_media_comboentry, distinct(PropCutting.media)) # set default units units = prefs.prefs[prefs.units_pref] if units == u'imperial': self.model.length_unit = u'in' self.model.bottom_heat_unit = u'F' else: self.model.length_unit = u'mm' self.model.bottom_heat_unit = u'C' self.refresh_view() self.assign_simple_handler('cutting_type_combo', 'cutting_type') self.assign_simple_handler('cutting_length_entry', 'length') self.assign_simple_handler('cutting_length_unit_combo', 'length_unit') self.assign_simple_handler('cutting_tip_combo', 'tip') self.assign_simple_handler('cutting_leaves_combo', 'leaves') self.assign_simple_handler('cutting_lvs_reduced_entry', 'leaves_reduced_pct') self.assign_simple_handler('cutting_media_comboentry', 'media', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('cutting_container_comboentry', 'container', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('cutting_buds_combo', 'flower_buds') self.assign_simple_handler('cutting_wound_combo', 'wound') self.assign_simple_handler('cutting_fungal_comboentry', 'fungicide', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('cutting_hormone_comboentry', 'hormone', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('cutting_location_comboentry', 'location', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('cutting_cover_comboentry', 'cover', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('cutting_heat_entry', 'bottom_heat_temp') self.assign_simple_handler('cutting_heat_unit_combo', 'bottom_heat_unit') self.assign_simple_handler('cutting_rooted_pct_entry', 'rooted_pct') model = gtk.ListStore(object) self.view.widgets.rooted_treeview.set_model(model) def _rooted_data_func(column, cell, model, treeiter, prop): v = model[treeiter][0] cell.set_property('text', getattr(v, prop)) cell = self.view.widgets.rooted_date_cell cell.props.editable = True self.view.connect(cell, 'edited', self.on_rooted_cell_edited, 'date') self.view.widgets.rooted_date_column.\ set_cell_data_func(cell, _rooted_data_func, 'date') cell = self.view.widgets.rooted_quantity_cell cell.props.editable = True self.view.connect(cell, 'edited', self.on_rooted_cell_edited, 'quantity') self.view.widgets.rooted_quantity_column.\ set_cell_data_func(cell, _rooted_data_func, 'quantity') self.view.connect('rooted_add_button', "clicked", self.on_rooted_add_clicked) self.view.connect('rooted_remove_button', "clicked", self.on_rooted_remove_clicked)
def __init__(self, model, view): super(SpeciesEditorPresenter, self).__init__(model, view) self.session = object_session(model) self._dirty = False self.omonym_box = None self.init_fullname_widgets() self.vern_presenter = VernacularNamePresenter(self) self.synonyms_presenter = SynonymsPresenter(self) self.dist_presenter = DistributionPresenter(self) self.infrasp_presenter = InfraspPresenter(self) notes_parent = self.view.widgets.notes_parent_box notes_parent.foreach(notes_parent.remove) self.notes_presenter = editor.NotesPresenter( self, 'notes', notes_parent) pictures_parent = self.view.widgets.pictures_parent_box pictures_parent.foreach(pictures_parent.remove) self.pictures_presenter = editor.PicturesPresenter( self, 'notes', pictures_parent) self.init_enum_combo('sp_spqual_combo', 'sp_qual') def cell_data_func(column, cell, model, treeiter, data=None): cell.props.text = utils.utf8(model[treeiter][0]) combo = self.view.widgets.sp_habit_comboentry model = gtk.ListStore(str, object) map(lambda p: model.append(p), [(str(h), h) for h in self.session.query(Habit)]) utils.setup_text_combobox(combo, model) def on_focus_out(entry, event): # check if the combo has a problem then check if the value # in the entry matches one of the habit codes and if so # then change the value to the habit code = entry.props.text try: utils.set_combo_from_value( combo, code.lower(), cmp=lambda r, v: str(r[1].code).lower() == v) except ValueError: pass combo.child.connect('focus-out-event', on_focus_out) # set the model values in the widgets self.refresh_view() # connect habit comboentry widget and child entry self.view.connect('sp_habit_comboentry', 'changed', self.on_habit_comboentry_changed) # connect signals def gen_get_completions(text): clause = utils.ilike(Genus.genus, '%s%%' % unicode(text)) return self.session.query(Genus).filter(clause).\ order_by(Genus.genus) # called when a genus is selected from the genus completions def on_select(value): #debug('on select: %s' % value) for kid in self.view.widgets.message_box_parent.get_children(): self.view.widgets.remove_parent(kid) self.set_model_attr('genus', value) if value: ## is value considered a synonym? syn = self.session.query(GenusSynonym).filter( GenusSynonym.synonym_id == value.id).first() if not value or not syn: ## no value or value is not a synonym: fine return ## value is a synonym: user alert needed msg = _('The genus <b>%(synonym)s</b> is a synonym of ' '<b>%(genus)s</b>.\n\nWould you like to choose ' '<b>%(genus)s</b> instead?' % {'synonym': syn.synonym, 'genus': syn.genus}) box = None def on_response(button, response): self.view.remove_box(box) if response: self.view.widgets.sp_genus_entry.\ set_text(utils.utf8(syn.genus)) self.set_model_attr('genus', syn.genus) else: self.set_model_attr('genus', value) box = self.view.add_message_box(utils.MESSAGE_BOX_YESNO) box.message = msg box.on_response = on_response box.show() self.view.add_box(box) self.assign_completions_handler('sp_genus_entry', # 'genus', gen_get_completions, on_select=on_select) self.assign_simple_handler('sp_cvgroup_entry', 'cv_group', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('sp_spqual_combo', 'sp_qual', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('sp_label_dist_entry', 'label_distribution', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('sp_awards_entry', 'awards', editor.UnicodeOrNoneValidator()) try: import bauble.plugins.garden bauble.plugins.garden # fake its usage if self.model not in self.model.new: self.view.widgets.sp_ok_and_add_button.set_sensitive(True) except Exception: pass
def __init__(self, model, view): super(SpeciesEditorPresenter, self).__init__(model, view) self.session = object_session(model) self._dirty = False self.omonym_box = None self.init_fullname_widgets() self.vern_presenter = VernacularNamePresenter(self) self.synonyms_presenter = SynonymsPresenter(self) self.dist_presenter = DistributionPresenter(self) self.infrasp_presenter = InfraspPresenter(self) notes_parent = self.view.widgets.notes_parent_box notes_parent.foreach(notes_parent.remove) self.notes_presenter = editor.NotesPresenter(self, 'notes', notes_parent) pictures_parent = self.view.widgets.pictures_parent_box pictures_parent.foreach(pictures_parent.remove) self.pictures_presenter = editor.PicturesPresenter( self, 'notes', pictures_parent) self.init_enum_combo('sp_spqual_combo', 'sp_qual') def cell_data_func(column, cell, model, treeiter, data=None): cell.props.text = utils.utf8(model[treeiter][0]) combo = self.view.widgets.sp_habit_comboentry model = gtk.ListStore(str, object) map(lambda p: model.append(p), [(str(h), h) for h in self.session.query(Habit)]) utils.setup_text_combobox(combo, model) def on_focus_out(entry, event): # check if the combo has a problem then check if the value # in the entry matches one of the habit codes and if so # then change the value to the habit code = entry.props.text try: utils.set_combo_from_value( combo, code.lower(), cmp=lambda r, v: str(r[1].code).lower() == v) except ValueError: pass combo.child.connect('focus-out-event', on_focus_out) # set the model values in the widgets self.refresh_view() # connect habit comboentry widget and child entry self.view.connect('sp_habit_comboentry', 'changed', self.on_habit_comboentry_changed) # connect signals def gen_get_completions(text): clause = utils.ilike(Genus.genus, '%s%%' % unicode(text)) return self.session.query(Genus).filter(clause).\ order_by(Genus.genus) # called when a genus is selected from the genus completions def on_select(value): #debug('on select: %s' % value) for kid in self.view.widgets.message_box_parent.get_children(): self.view.widgets.remove_parent(kid) self.set_model_attr('genus', value) if value: ## is value considered a synonym? syn = self.session.query(GenusSynonym).filter( GenusSynonym.synonym_id == value.id).first() if not value or not syn: ## no value or value is not a synonym: fine return ## value is a synonym: user alert needed msg = _('The genus <b>%(synonym)s</b> is a synonym of ' '<b>%(genus)s</b>.\n\nWould you like to choose ' '<b>%(genus)s</b> instead?' % { 'synonym': syn.synonym, 'genus': syn.genus }) box = None def on_response(button, response): self.view.remove_box(box) if response: self.view.widgets.sp_genus_entry.\ set_text(utils.utf8(syn.genus)) self.set_model_attr('genus', syn.genus) else: self.set_model_attr('genus', value) box = self.view.add_message_box(utils.MESSAGE_BOX_YESNO) box.message = msg box.on_response = on_response box.show() self.view.add_box(box) self.assign_completions_handler( 'sp_genus_entry', # 'genus', gen_get_completions, on_select=on_select) self.assign_simple_handler('sp_cvgroup_entry', 'cv_group', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('sp_spqual_combo', 'sp_qual', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('sp_label_dist_entry', 'label_distribution', editor.UnicodeOrNoneValidator()) self.assign_simple_handler('sp_awards_entry', 'awards', editor.UnicodeOrNoneValidator()) try: import bauble.plugins.garden bauble.plugins.garden # fake its usage if self.model not in self.model.new: self.view.widgets.sp_ok_and_add_button.set_sensitive(True) except Exception: pass
def create_gui(self): if self.working_dbtypes is None or len(self.working_dbtypes) == 0: msg = _("No Python database connectors installed.\n" "Please consult the documentation for the " "prerequesites for installing Bauble.") utils.message_dialog(msg, gtk.MESSAGE_ERROR) raise Exception(msg) glade_path = os.path.join(paths.lib_dir(), "connmgr.glade") self.widgets = utils.BuilderWidgets(glade_path) self.builder = self.widgets._builder_ self.dialog = self.widgets.main_dialog title = '%s %s' % ('Bauble', bauble.version) self.dialog.set_title(title) try: pixbuf = gtk.gdk.pixbuf_new_from_file(bauble.default_icon) self.dialog.set_icon(pixbuf) except Exception: logger.warning( _('Could not load icon from %s' % bauble.default_icon)) logger.warning(traceback.format_exc()) if bauble.gui is not None and bauble.gui.window is not None: self.dialog.set_transient_for(bauble.gui.window) if not bauble.gui.window.get_property('visible'): self.dialog.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.dialog.set_property('skip-taskbar-hint', False) self.builder.connect_signals(self) # set the logo image manually, it's hard to depend on glade to # get this right since the image paths may change logo = self.widgets.logo_image logo_path = os.path.join(paths.lib_dir(), "images", "bauble_logo.png") logo.set_from_file(logo_path) self.params_box = None self.expander_box = self.widgets.expander_box # setup the type combo self.type_combo = self.widgets.type_combo def type_combo_cell_data_func(combo, renderer, model, iter, data=None): """ if the database type is not in self.working_dbtypes then make it not sensitive """ dbtype = model[iter][0] sensitive = dbtype in self.working_dbtypes renderer.set_property('sensitive', sensitive) renderer.set_property('text', dbtype) utils.setup_text_combobox(self.type_combo, self._dbtypes, type_combo_cell_data_func) self.type_combo.connect("changed", self.on_changed_type_combo) # setup the name combo self.name_combo = self.widgets.name_combo utils.setup_text_combobox(self.name_combo) self.name_combo.connect("changed", self.on_changed_name_combo) self.dialog.set_focus(self.widgets.connect_button)
def create_gui(self): if self.working_dbtypes is None or len(self.working_dbtypes) == 0: msg = _("No Python database connectors installed.\n" "Please consult the documentation for the " "prerequesites for installing Bauble.") utils.message_dialog(msg, gtk.MESSAGE_ERROR) raise Exception(msg) glade_path = os.path.join(paths.lib_dir(), "connmgr.glade") self.widgets = utils.BuilderWidgets(glade_path) self.builder = self.widgets._builder_ self.dialog = self.widgets.main_dialog title = '%s %s' % ('Bauble', bauble.version) self.dialog.set_title(title) try: pixbuf = gtk.gdk.pixbuf_new_from_file(bauble.default_icon) self.dialog.set_icon(pixbuf) except Exception: logger.warning(_('Could not load icon from %s' % bauble.default_icon)) logger.warning(traceback.format_exc()) if bauble.gui is not None and bauble.gui.window is not None: self.dialog.set_transient_for(bauble.gui.window) if not bauble.gui.window.get_property('visible'): self.dialog.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.dialog.set_property('skip-taskbar-hint', False) self.builder.connect_signals(self) # set the logo image manually, it's hard to depend on glade to # get this right since the image paths may change logo = self.widgets.logo_image logo_path = os.path.join(paths.lib_dir(), "images", "bauble_logo.png") logo.set_from_file(logo_path) self.params_box = None self.expander_box = self.widgets.expander_box # setup the type combo self.type_combo = self.widgets.type_combo def type_combo_cell_data_func(combo, renderer, model, iter, data=None): """ if the database type is not in self.working_dbtypes then make it not sensitive """ dbtype = model[iter][0] sensitive = dbtype in self.working_dbtypes renderer.set_property('sensitive', sensitive) renderer.set_property('text', dbtype) utils.setup_text_combobox(self.type_combo, self._dbtypes, type_combo_cell_data_func) self.type_combo.connect("changed", self.on_changed_type_combo) # setup the name combo self.name_combo = self.widgets.name_combo utils.setup_text_combobox(self.name_combo) self.name_combo.connect("changed", self.on_changed_name_combo) self.dialog.set_focus(self.widgets.connect_button)
def __init__(self, parent, model, view, session): """ :param model: an instance of class Propagation :param view: an instance of PropagationEditorView """ super(CuttingPresenter, self).__init__(model, view) self.parent_ref = weakref.ref(parent) self.session = session self._dirty = False # make the model for the presenter a PropCutting instead of a # Propagation self.propagation = self.model if not self.propagation._cutting: self.propagation._cutting = PropCutting() self.model = self.model._cutting init_combo = self.view.init_translatable_combo init_combo("cutting_type_combo", cutting_type_values, editor.UnicodeOrNoneValidator()) init_combo("cutting_length_unit_combo", length_unit_values) init_combo("cutting_tip_combo", tip_values) init_combo("cutting_leaves_combo", leaves_values) init_combo("cutting_buds_combo", flower_buds_values) init_combo("cutting_wound_combo", wound_values) init_combo("cutting_heat_unit_combo", bottom_heat_unit_values) widgets = self.view.widgets distinct = lambda c: utils.get_distinct_values(c, self.session) utils.setup_text_combobox(widgets.cutting_hormone_comboentry, distinct(PropCutting.hormone)) utils.setup_text_combobox(widgets.cutting_cover_comboentry, distinct(PropCutting.cover)) utils.setup_text_combobox(widgets.cutting_fungal_comboentry, distinct(PropCutting.fungicide)) utils.setup_text_combobox(widgets.cutting_location_comboentry, distinct(PropCutting.location)) utils.setup_text_combobox(widgets.cutting_container_comboentry, distinct(PropCutting.container)) utils.setup_text_combobox(widgets.cutting_media_comboentry, distinct(PropCutting.media)) # set default units units = prefs.prefs[prefs.units_pref] if units == u"imperial": self.model.length_unit = u"in" self.model.bottom_heat_unit = u"F" else: self.model.length_unit = u"mm" self.model.bottom_heat_unit = u"C" self.refresh_view() self.assign_simple_handler("cutting_type_combo", "cutting_type") self.assign_simple_handler("cutting_length_entry", "length") self.assign_simple_handler("cutting_length_unit_combo", "length_unit") self.assign_simple_handler("cutting_tip_combo", "tip") self.assign_simple_handler("cutting_leaves_combo", "leaves") self.assign_simple_handler("cutting_lvs_reduced_entry", "leaves_reduced_pct") self.assign_simple_handler("cutting_media_comboentry", "media", editor.UnicodeOrNoneValidator()) self.assign_simple_handler("cutting_container_comboentry", "container", editor.UnicodeOrNoneValidator()) self.assign_simple_handler("cutting_buds_combo", "flower_buds") self.assign_simple_handler("cutting_wound_combo", "wound") self.assign_simple_handler("cutting_fungal_comboentry", "fungicide", editor.UnicodeOrNoneValidator()) self.assign_simple_handler("cutting_hormone_comboentry", "hormone", editor.UnicodeOrNoneValidator()) self.assign_simple_handler("cutting_location_comboentry", "location", editor.UnicodeOrNoneValidator()) self.assign_simple_handler("cutting_cover_comboentry", "cover", editor.UnicodeOrNoneValidator()) self.assign_simple_handler("cutting_heat_entry", "bottom_heat_temp") self.assign_simple_handler("cutting_heat_unit_combo", "bottom_heat_unit") self.assign_simple_handler("cutting_rooted_pct_entry", "rooted_pct") model = gtk.ListStore(object) self.view.widgets.rooted_treeview.set_model(model) def _rooted_data_func(column, cell, model, treeiter, prop): v = model[treeiter][0] cell.set_property("text", getattr(v, prop)) cell = self.view.widgets.rooted_date_cell cell.props.editable = True self.view.connect(cell, "edited", self.on_rooted_cell_edited, "date") self.view.widgets.rooted_date_column.set_cell_data_func(cell, _rooted_data_func, "date") cell = self.view.widgets.rooted_quantity_cell cell.props.editable = True self.view.connect(cell, "edited", self.on_rooted_cell_edited, "quantity") self.view.widgets.rooted_quantity_column.set_cell_data_func(cell, _rooted_data_func, "quantity") self.view.connect("rooted_add_button", "clicked", self.on_rooted_add_clicked) self.view.connect("rooted_remove_button", "clicked", self.on_rooted_remove_clicked)
def __init__(self, presenter, model=None): super(NotesPresenter.NoteBox, self).__init__() # open the glade file and extract the markup that the # expander will use filename = os.path.join(paths.lib_dir(), 'notes.glade') xml = etree.parse(filename) el = xml.find("//object[@id='notes_box']") builder = gtk.Builder() s = '<interface>%s</interface>' % etree.tostring(el) if sys.platform == 'win32': # NOTE: PyGTK for Win32 is broken so we have to include # this little hack # # TODO: is this only a specific set of version of # PyGTK/GTK...it was only tested with PyGTK 2.12 builder.add_from_string(s, -1) else: builder.add_from_string(s) self.widgets = utils.BuilderWidgets(builder) notes_box = self.widgets.notes_box self.widgets.remove_parent(notes_box) self.pack_start(notes_box, expand=True, fill=True) self.session = object_session(presenter.model) self.presenter = presenter if model: self.model = model else: self.model = presenter.note_cls() self.widgets.notes_expander.props.use_markup = True self.widgets.notes_expander.props.label = '' self.widgets.notes_expander.props.label_widget.\ ellipsize = pango.ELLIPSIZE_END # set the model values on the widgets mapper = object_mapper(self.model) values = utils.get_distinct_values(mapper.c['category'], self.session) utils.setup_text_combobox(self.widgets.category_comboentry, values) utils.set_widget_value(self.widgets.category_comboentry, self.model.category or '') utils.setup_date_button(None, self.widgets.date_entry, self.widgets.date_button) date_str = utils.today_str() if self.model.date: format = prefs.prefs[prefs.date_format_pref] date_str = self.model.date.strftime(format) utils.set_widget_value(self.widgets.date_entry, date_str) utils.set_widget_value(self.widgets.user_entry, self.model.user or '') buff = gtk.TextBuffer() self.widgets.note_textview.set_buffer(buff) utils.set_widget_value(self.widgets.note_textview, self.model.note or '') # connect the signal handlers self.widgets.date_entry.connect('changed', self.on_date_entry_changed) self.widgets.user_entry.connect('changed', self.on_user_entry_changed) # connect category comboentry widget and child entry self.widgets.category_comboentry.connect('changed', self.on_category_combo_changed) self.widgets.category_comboentry.child.connect('changed', self.on_category_entry_changed) buff.connect('changed', self.on_note_buffer_changed) self.widgets.notes_remove_button.connect('clicked', self.on_notes_remove_button) self.update_label() self.show_all()
self.params_box = None self.expander_box = self.widgets.expander_box # setup the type combo self.type_combo = self.widgets.type_combo def type_combo_cell_data_func(combo, renderer, model, iter, data=None): """ if the database type is not in self.working_dbtypes then make it not sensitive """ dbtype = model[iter][0] sensitive = dbtype in self.working_dbtypes renderer.set_property('sensitive', sensitive) renderer.set_property('text', dbtype) utils.setup_text_combobox(self.type_combo, self._dbtypes, type_combo_cell_data_func) self.type_combo.connect("changed", self.on_changed_type_combo) # setup the name combo self.name_combo = self.widgets.name_combo utils.setup_text_combobox(self.name_combo) self.name_combo.connect("changed", self.on_changed_name_combo) self.dialog.set_focus(self.widgets.connect_button) def set_active_connection_by_name(self, name): """ sets the name of the connection in the name combo, this causes on_changed_name_combo to be fired which changes the param box type and set the connection parameters