Esempio n. 1
0
 def test_cutting_editor(self):
     loc = Location(name=u'name', code=u'code')
     plant = Plant(accession=self.accession, location=loc, code=u'1',
                   quantity=1)
     propagation = Propagation()
     plant.propagations.append(propagation)
     self.editor = PropagationEditor(model=propagation)
     widgets = self.editor.presenter.view.widgets
     view = self.editor.presenter.view
     view.set_widget_value('prop_type_combo', u'UnrootedCutting')
     view.set_widget_value('prop_date_entry', utils.today_str())
     cutting_presenter = self.editor.presenter._cutting_presenter
     for widget, attr in cutting_presenter.widget_to_field_map.iteritems():
         #debug('%s=%s' % (widget, default_cutting_values[attr]))
         view.set_widget_value(widget, default_cutting_values[attr])
     update_gui()
     self.editor.handle_response(gtk.RESPONSE_OK)
     self.editor.commit_changes()
     model = self.editor.model
     s = object_session(model)
     s.expire(model)
     self.assert_(model.prop_type == u'UnrootedCutting')
     for attr, value in default_cutting_values.iteritems():
         v = getattr(model._cutting, attr)
         self.assert_(v==value, '%s = %s(%s)' % (attr, value, v))
     self.editor.session.close()
 def on_rooted_add_clicked(self, button, *args):
     """
     """
     tree = self.view.widgets.rooted_treeview
     model = tree.get_model()
     rooted = PropRooted()
     rooted.cutting = self.model
     rooted.date = utils.today_str()
     treeiter = model.insert(0, [rooted])
     path = model.get_path(treeiter)
     column = tree.get_column(0)
     tree.set_cursor(path, column, start_editing=True)
 def on_rooted_add_clicked(self, button, *args):
     """
     """
     tree = self.view.widgets.rooted_treeview
     model = tree.get_model()
     rooted = PropRooted()
     rooted.cutting = self.model
     rooted.date = utils.today_str()
     treeiter = model.insert(0, [rooted])
     path = model.get_path(treeiter)
     column = tree.get_column(0)
     tree.set_cursor(path, column, start_editing=True)
Esempio n. 4
0
    def test_accession_source_editor(self, accession=None):
        acc = self.create(Accession, species=self.species, code=u'parent')
        plant = self.create(Plant, accession=acc, quantity=1,
                            location=Location(name=u'site', code=u'STE'),
                            code=u'1')
        # creating a dummy propagtion without a related seed/cutting
        prop = self.create(Propagation, prop_type='Seed')
        plant.propagations.append(prop)
        self.session.commit()
        plant_prop_id = prop.id
        assert plant_prop_id # assert we got a valid id after the commit

        acc = Accession(code=u'code', species=self.species)
        self.editor = AccessionEditor(acc)
        # normally called by editor.presenter.start() but we don't call it here
        self.editor.presenter.source_presenter.start()
        widgets = self.editor.presenter.view.widgets
        update_gui()

        # set the date so the presenter will be "dirty"
        widgets.acc_date_recvd_entry.props.text = utils.today_str()

        # set the source type as "Garden Propagation"
        widgets.acc_source_comboentry.child.props.text = \
            SourcePresenter.garden_prop_str
        assert not self.editor.presenter.problems

        # set the source plant
        widgets.source_prop_plant_entry.props.text = str(plant)
        update_gui()
        comp = widgets.source_prop_plant_entry.get_completion()
        comp.emit('match-selected', comp.get_model(),
                  comp.get_model().get_iter_first())

        # assert that the propagations were added to the treevide
        treeview = widgets.source_prop_treeview
        assert treeview.get_model()

        # select the first/only propagation in the treeview
        toggle_cell = widgets.prop_toggle_cell.emit('toggled', 0)

        # commit the changes and cleanup
        import gtk
        self.editor.handle_response(gtk.RESPONSE_OK)
        self.editor.session.close()

        # open a seperate session and make sure everything committed
        session = db.Session()
        acc = session.query(Accession).filter_by(code=u'code')[0]
        parent = session.query(Accession).filter_by(code=u'parent')[0]
        assert acc.source.plant_propagation_id == plant_prop_id
    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, 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()