Example #1
0
    def __init__(self, parent, model, view, session):
        super(CollectionPresenter, self).__init__(model, view)
        self.parent_ref = weakref.ref(parent)
        self.session = session
        self.refresh_view()

        self.assign_simple_handler("collector_entry", "collector", editor.UnicodeOrNoneValidator())
        self.assign_simple_handler("locale_entry", "locale", editor.UnicodeOrNoneValidator())
        self.assign_simple_handler("collid_entry", "collectors_code", editor.UnicodeOrNoneValidator())
        self.assign_simple_handler("geoacc_entry", "geo_accy", editor.IntOrNoneStringValidator())
        self.assign_simple_handler("alt_entry", "elevation", editor.FloatOrNoneStringValidator())
        self.assign_simple_handler("altacc_entry", "elevation_accy", editor.FloatOrNoneStringValidator())
        self.assign_simple_handler("habitat_textview", "habitat", editor.UnicodeOrNoneValidator())
        self.assign_simple_handler("coll_notes_textview", "notes", editor.UnicodeOrNoneValidator())
        # the list of completions are added in AccessionEditorView.__init__

        def on_match(completion, model, iter, data=None):
            value = model[iter][0]
            validator = editor.UnicodeOrNoneValidator()
            self.set_model_attr("gps_data", value, validator)
            completion.get_entry().set_text(value)

        completion = self.view.widgets.datum_entry.get_completion()
        self.view.connect(completion, "match-selected", on_match)
        self.assign_simple_handler("datum_entry", "gps_datum", editor.UnicodeOrNoneValidator())

        self.view.connect("lat_entry", "changed", self.on_lat_entry_changed)
        self.view.connect("lon_entry", "changed", self.on_lon_entry_changed)

        self.view.connect("coll_date_entry", "changed", self.on_date_entry_changed)

        utils.setup_date_button(view, "coll_date_entry", "coll_date_button")

        # don't need to connection to south/west since they are in the same
        # groups as north/east
        self.north_toggle_signal_id = self.view.connect("north_radio", "toggled", self.on_north_south_radio_toggled)
        self.east_toggle_signal_id = self.view.connect("east_radio", "toggled", self.on_east_west_radio_toggled)

        self.view.widgets.add_region_button.set_sensitive(False)

        def on_add_button_pressed(button, event):
            self.geo_menu.popup(None, None, None, event.button, event.time)

        self.view.connect("add_region_button", "button-press-event", on_add_button_pressed)

        def _init_geo():
            add_button = self.view.widgets.add_region_button
            self.geo_menu = GeographyMenu(self.set_region)
            self.geo_menu.attach_to_widget(add_button, None)
            add_button.set_sensitive(True)

        gobject.idle_add(_init_geo)

        self._dirty = False
    def __init__(self, model, view):
        '''
        :param model: an instance of class Propagation
        :param view: an instance of PropagationEditorView
        '''
        super(PropagationPresenter, self).__init__(model, view)
        self.session = object_session(model)

        # initialize the propagation type combo and set the initial value
        self.view.connect('prop_type_combo', 'changed',
                          self.on_prop_type_changed)
        if self.model.prop_type:
            self.view.widget_set_value('prop_type_combo', self.model.prop_type)

        self._cutting_presenter = CuttingPresenter(self, self.model, self.view,
                                                   self.session)
        self._seed_presenter = SeedPresenter(self, self.model, self.view,
                                             self.session)

        if not self.model.prop_type:
            view.widgets.prop_details_box.props.visible = False

        if self.model.date:
            format = prefs.prefs[prefs.date_format_pref]
            date = self.model.date.strftime(format)
            self.view.widget_set_value(self.view.widgets.prop_date_entry, date)
        else:
            self.view.widget_set_value(self.view.widgets.prop_date_entry,
                                       utils.today_str())

        self.view.widget_set_value(self.view.widgets.notes_textview,
                                   self.model.notes)

        self._dirty = False
        utils.setup_date_button(self.view, 'prop_date_entry',
                                'prop_date_button')
        self.assign_simple_handler('prop_date_entry', 'date',
                                   editor.DateValidator())
        self.assign_simple_handler('notes_textview', 'notes',
                                   editor.UnicodeOrNoneValidator())

        def on_expanded(*args):
            if self.model.prop_type == u'Other':
                # i don't really understand why setting the expanded
                # property to false here cause the notes_expander to
                # always stay expanded but it works
                self.view.widgets.notes_expander.props.expanded = False

        self.view.connect('notes_expander', 'activate', on_expanded)
    def __init__(self, model, view):
        '''
        :param model: an instance of class Propagation
        :param view: an instance of PropagationEditorView
        '''
        super(PropagationPresenter, self).__init__(model, view)
        self.session = object_session(model)

        # initialize the propagation type combo and set the initial value
        self.view.connect('prop_type_combo', 'changed',
                          self.on_prop_type_changed)
        if self.model.prop_type:
            self.view.set_widget_value('prop_type_combo', self.model.prop_type)

        self._cutting_presenter = CuttingPresenter(self, self.model, self.view,
                                                   self.session)
        self._seed_presenter = SeedPresenter(self, self.model, self.view,
                                                   self.session)

        if not self.model.prop_type:
            view.widgets.prop_details_box.props.visible = False

        if self.model.date:
            format = prefs.prefs[prefs.date_format_pref]
            date = self.model.date.strftime(format)
            self.view.set_widget_value(self.view.widgets.prop_date_entry, date)
        else:
            self.view.set_widget_value(self.view.widgets.prop_date_entry,
                                       utils.today_str())

        self.view.set_widget_value(self.view.widgets.notes_textview,
                                   self.model.notes)


        self._dirty = False
        utils.setup_date_button(self.view, 'prop_date_entry',
                                'prop_date_button')
        self.assign_simple_handler('prop_date_entry', 'date',
                                   editor.DateValidator())
        self.assign_simple_handler('notes_textview', 'notes',
                                   editor.UnicodeOrNoneValidator())

        def on_expanded(*args):
            if self.model.prop_type == u'Other':
                # i don't really understand why setting the expanded
                # property to false here cause the notes_expander to
                # always stay expanded but it works
                self.view.widgets.notes_expander.props.expanded = False
        self.view.connect('notes_expander', 'activate', on_expanded)
 def __init__(self, parent=None):
     glade_file = os.path.join(paths.lib_dir(), 'plugins', 'garden',
                               'plant_editor.glade')
     super(PlantEditorView, self).__init__(glade_file, parent=parent)
     self.widgets.pad_ok_button.set_sensitive(False)
     self.widgets.pad_next_button.set_sensitive(False)
     def acc_cell_data_func(column, renderer, model, treeiter, data=None):
         v = model[treeiter][0]
         renderer.set_property('text', '%s (%s)' % (str(v), str(v.species)))
     self.attach_completion('plant_acc_entry', acc_cell_data_func,
                            minimum_key_length=2)
     self.init_translatable_combo('plant_acc_type_combo', acc_type_values)
     self.init_translatable_combo('reason_combo', change_reasons)
     utils.setup_date_button(self, 'plant_date_entry', 'plant_date_button')
     self.widgets.plant_notebook.set_current_page(0)
    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, 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')
Example #7
0
    def __init__(self, parent, model, view, session):
        super(CollectionPresenter, self).__init__(model, view)
        self.parent_ref = weakref.ref(parent)
        self.session = session
        self.refresh_view()

        self.assign_simple_handler('collector_entry', 'collector',
                                   editor.UnicodeOrNoneValidator())
        self.assign_simple_handler('locale_entry', 'locale',
                                   editor.UnicodeOrNoneValidator())
        self.assign_simple_handler('collid_entry', 'collectors_code',
                                   editor.UnicodeOrNoneValidator())
        self.assign_simple_handler('geoacc_entry', 'geo_accy',
                                   editor.IntOrNoneStringValidator())
        self.assign_simple_handler('alt_entry', 'elevation',
                                   editor.FloatOrNoneStringValidator())
        self.assign_simple_handler('altacc_entry', 'elevation_accy',
                                   editor.FloatOrNoneStringValidator())
        self.assign_simple_handler('habitat_textview', 'habitat',
                                   editor.UnicodeOrNoneValidator())
        self.assign_simple_handler('coll_notes_textview', 'notes',
                                   editor.UnicodeOrNoneValidator())

        # the list of completions are added in AccessionEditorView.__init__

        def on_match(completion, model, iter, data=None):
            value = model[iter][0]
            validator = editor.UnicodeOrNoneValidator()
            self.set_model_attr('gps_data', value, validator)
            completion.get_entry().set_text(value)

        completion = self.view.widgets.datum_entry.get_completion()
        self.view.connect(completion, 'match-selected', on_match)
        self.assign_simple_handler('datum_entry', 'gps_datum',
                                   editor.UnicodeOrNoneValidator())

        self.view.connect('lat_entry', 'changed', self.on_lat_entry_changed)
        self.view.connect('lon_entry', 'changed', self.on_lon_entry_changed)

        self.view.connect('coll_date_entry', 'changed',
                          self.on_date_entry_changed)

        utils.setup_date_button(view, 'coll_date_entry', 'coll_date_button')

        # don't need to connection to south/west since they are in the same
        # groups as north/east
        self.north_toggle_signal_id = \
            self.view.connect('north_radio', 'toggled',
                              self.on_north_south_radio_toggled)
        self.east_toggle_signal_id = \
            self.view.connect('east_radio', 'toggled',
                              self.on_east_west_radio_toggled)

        self.view.widgets.add_region_button.set_sensitive(False)

        def on_add_button_pressed(button, event):
            self.geo_menu.popup(None, None, None, event.button, event.time)

        self.view.connect('add_region_button', 'button-press-event',
                          on_add_button_pressed)

        def _init_geo():
            add_button = self.view.widgets.add_region_button
            self.geo_menu = GeographyMenu(self.set_region)
            self.geo_menu.attach_to_widget(add_button, None)
            add_button.set_sensitive(True)

        gobject.idle_add(_init_geo)

        self._dirty = False
        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()