[Sugar-devel] Bug in Sugar Commander, Fun With The Journal needs review

James Simmons nicestep at gmail.com
Mon Apr 12 11:17:35 EDT 2010


The version of Sugar Commander I released this weekend works.
However, I woke up Sunday morning realizing that it was not necessary
to reload the whole ListStore I was using to show Journal objects
every time I changed anything.  I could update the ListStore in place
and the TreeView would redraw itself to show the latest contents
automatically, or so I thought.  Well, deleting rows that way works,
but not updating a row.

This is the code is use for the callbacks:

    def datastore_updated_cb(self,  uid):
        iter = self.ls_journal.get_iter_first()
        for row in self.ls_journal:
            jobject = row[COLUMN_JOBJECT]
            if jobject.object_id == uid:
                title = jobject.metadata['title']
                self.ls_journal.set(iter, COLUMN_TITLE, title)
                mime = jobject.metadata['mime_type']
                self.ls_journal.set(iter, COLUMN_MIME, mime)
                break
            iter = self.ls_journal.iter_next(iter)
        object_id = self.selected_journal_entry.object_id
        if object_id == uid:
            jobject = datastore.get(object_id)
            self.set_form_fields(jobject)

    def datastore_deleted_cb(self,  uid):
        save_path = self.selected_path
        iter = self.ls_journal.get_iter_first()
        for row in self.ls_journal:
            jobject = row[COLUMN_JOBJECT]
            if jobject.object_id == uid:
                self.ls_journal.remove(iter)
                break
            iter = self.ls_journal.iter_next(iter)

        if not save_path is None:
            self.selection_journal.select_path(save_path)
        else:
            self.title_entry.set_text('')
            description_textbuffer = self.description_textview.get_buffer()
            description_textbuffer.set_text('')
            tags_textbuffer = self.tags_textview.get_buffer()
            tags_textbuffer.set_text('')
            self.btn_save.props.sensitive = False
            self.btn_delete.props.sensitive = False
            self.image.clear()
            self.image.show()

The whole thing is here:

http://git.sugarlabs.org/projects/sugar-commander/repos/mainline/blobs/raw/630b5dc8dcaf90dbbc7bf2eaaf2f80606eff16e5/sugarcommander.py

For reasons I won't go into I was convinced that this code actually
worked so I updated the "Fun With The Journal" chapter of "Make Your
Own Sugar Activities!" with the new code, plus I mode other changes to
explain things like how to add your own preview to a Journal entry.
The revised chapter is here:

http://en.flossmanuals.net/bin/view/ActivitiesGuideSugar/FunWithTheJournal

I was hoping to just ask for a review of the revised chapter this
morning but I'm really stuck on the TreeView issue.  I can't
understand why updating the ListStore doesn't cause the cells in the
TreeView to be redrawn with the new content.

James Simmons


More information about the Sugar-devel mailing list