Пример #1
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')
Пример #2
0
 def on_date_entry_changed(self, entry, data=None):
     from bauble.editor import ValidatorError
     value = None
     PROBLEM = 'INVALID_DATE'
     try:
         value = editor.DateValidator().to_python(entry.props.text)
     except ValidatorError, e:
         logger.debug(e)
         self.parent_ref().add_problem(PROBLEM, entry)
Пример #3
0
    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)