Пример #1
0
 def rtree_time_edited_cb(self, renderer, path_string, text, colnum,
                          attribute):
     if not text: secs = 0
     else:
         secs = self.rg.conv.timestring_to_seconds(text)
         if not secs:
             #self.message(_("Unable to recognize %s as a time."%text))
             return
     indices = path_string.split(':')
     path = tuple(map(int, indices))
     store = self.rectree.get_model()
     iter = store.get_iter(path)
     #self.rmodel.set_value(iter,colnum,secs)
     rec = self.get_rec_from_iter(iter)
     if convert.seconds_to_timestring(getattr(rec, attribute)) != text:
         self.rd.undoable_modify_rec(
             rec,
             {attribute: secs},
             self.history,
             get_current_rec_method=lambda *args: self.
             get_selected_recs_from_rec_tree()[0],
         )
         self.update_modified_recipe(rec, attribute, secs)
     # Is this really stupid? I don't know, but I did it before so
     # perhaps I had a reason.
     #self.rmodel.row_changed(path,iter)
     self.rmodel.update_iter(iter)
     self.rd.save()
Пример #2
0
 def rtree_time_edited_cb (self, renderer, path_string, text, colnum, attribute):
     if not text: secs = 0
     else:
         secs = self.rg.conv.timestring_to_seconds(text)
         if not secs:
             #self.message(_("Unable to recognize %s as a time."%text))
             return
     indices = path_string.split(':')
     path = tuple( map(int, indices))
     store = self.rectree.get_model()
     iter = store.get_iter(path)
     #self.rmodel.set_value(iter,colnum,secs)
     rec = self.get_rec_from_iter(iter)
     if convert.seconds_to_timestring(getattr(rec,attribute))!=text:
         self.rd.undoable_modify_rec(rec,
                                     {attribute:secs},
                                     self.history,
                                     get_current_rec_method=lambda *args: self.get_selected_recs_from_rec_tree()[0],
                                     )
         self.update_modified_recipe(rec,attribute,secs)
     # Is this really stupid? I don't know, but I did it before so
     # perhaps I had a reason.
     #self.rmodel.row_changed(path,iter)
     self.rmodel.update_iter(iter)
     self.rd.save()
Пример #3
0
    def setup_reccolumns(self):
        """Setup the columns of our recipe index TreeView"""
        renderer = gtk.CellRendererPixbuf()
        cssu = pageable_store.ColumnSortSetterUpper(self.rmodel)
        col = gtk.TreeViewColumn("", renderer, pixbuf=1)
        col.set_min_width(-1)
        self.rectree.append_column(col)
        n = 2
        crc = True
        if not hasattr(gtk, 'CellRendererCombo'):
            print 'CellRendererCombo not yet supported'
            print 'Update pygtk/gtk for lovely comboboxes'
            print 'in your treemodels!'
            print '(but don\'t worry, Gourmet will still work'
            print 'fine with what you have)'
        _title_to_num_ = {}
        for c in self.rtcols:
            if c == 'rating':
                # special case -- for ratings we set up our lovely
                # star widget
                twsm = ratingWidget.TreeWithStarMaker(
                    self.rectree,
                    self.rg.star_generator,
                    data_col=n,
                    col_title='_%s' % self.rtcolsdic[c],
                    handlers=[self.star_change_cb],
                    properties={
                        'reorderable': True,
                        'resizable': True
                    },
                )
                cssu.set_sort_column_id(twsm.col, twsm.data_col)
                n += 1
                twsm.col.set_min_width(110)
                continue
            # And we also special case our time column
            elif c in ['preptime', 'cooktime']:
                _title_to_num_[self.rtcolsdic[c]] = n
                renderer = gtk.CellRendererText()
                renderer.set_property('editable', True)
                renderer.connect('edited', self.rtree_time_edited_cb, n, c)

                def get_colnum(tc):
                    try:
                        t = tc.get_title()
                        if t:
                            return _title_to_num_[t.replace('_', '')]
                        else:
                            print 'wtf, no title for ', tc
                            return -1
                    except:
                        print 'problem with ', tc
                        raise

                ncols = self.rectree.insert_column_with_data_func(
                    -1,
                    '_%s'%self.rtcolsdic[c],
                    renderer,
                    lambda tc,cell,mod,titr: \
                    cell.set_property(
                    'text',
                    convert.seconds_to_timestring(mod.get_value(
                    titr,
                    get_colnum(tc),
                    #_title_to_num_[tc.get_title().replace('_','')],
                    ))
                    )
                    )
                col = self.rectree.get_column(ncols - 1)
                cssu.set_sort_column_id(col, n)
                col.set_property('reorderable', True)
                col.set_property('resizable', True)
                n += 1
                continue
            elif self.editable and self.rtwidgdic[c] == 'Combo':
                renderer = gtk.CellRendererCombo()
                model = gtk.ListStore(str)
                if c == 'category':
                    map(
                        lambda i: model.append([i]),
                        self.rg.rd.get_unique_values(
                            c, self.rg.rd.categories_table))
                else:
                    map(lambda i: model.append([i]),
                        self.rg.rd.get_unique_values(c))
                renderer.set_property('model', model)
                renderer.set_property('text-column', 0)
            else:
                renderer = gtk.CellRendererText()
                if c == 'link':
                    renderer.set_property('ellipsize', pango.ELLIPSIZE_END)
                else:
                    # If we have gtk > 2.8, set up text-wrapping
                    try:
                        renderer.get_property('wrap-width')
                    except TypeError:
                        pass
                    else:
                        renderer.set_property('wrap-mode', pango.WRAP_WORD)
                        if c == 'title':
                            renderer.set_property('wrap-width', 200)
                        else:
                            renderer.set_property('wrap-width', 150)
            renderer.set_property('editable', self.editable)
            renderer.connect('edited', self.rtree_edited_cb, n, c)
            titl = self.rtcolsdic[c]
            col = gtk.TreeViewColumn('_%s' % titl, renderer, text=n)
            # Ensure that the columns aren't really narrow on initialising.
            #if c=='title':            # Adjust these two to be even bigger
            #    col.set_min_width(200)
            #else:
            #    col.set_min_width(60)
            if c == 'title':
                col.set_property('expand', True)
            col.set_reorderable(True)
            col.set_resizable(True)
            col.set_clickable(True)
            #col.connect('clicked', self.column_sort)
            self.rectree.append_column(col)
            cssu.set_sort_column_id(col, n)
            debug("Column %s is %s->%s" % (n, c, self.rtcolsdic[c]), 5)
            n += 1
Пример #4
0
 def setup_reccolumns (self):
     """Setup the columns of our recipe index TreeView"""
     renderer = gtk.CellRendererPixbuf()
     cssu=pageable_store.ColumnSortSetterUpper(self.rmodel)
     col = gtk.TreeViewColumn("",renderer,pixbuf=1)
     col.set_min_width(-1)
     self.rectree.append_column(col)
     n = 2
     _title_to_num_ = {}
     for c in self.rtcols:
         if c=='rating':
             # special case -- for ratings we set up our lovely
             # star widget
             twsm = ratingWidget.TreeWithStarMaker(
                 self.rectree,
                 self.rg.star_generator,
                 data_col=n,
                 col_title='_%s'%self.rtcolsdic[c],
                 handlers=[self.star_change_cb],
                 properties={'reorderable':True,
                             'resizable':True},
                 )
             cssu.set_sort_column_id(twsm.col,twsm.data_col)
             n += 1
             twsm.col.set_min_width(110)
             continue
         # And we also special case our time column
         elif c in ['preptime','cooktime']:
             _title_to_num_[self.rtcolsdic[c]]=n
             renderer=gtk.CellRendererText()
             renderer.set_property('editable',True)
             renderer.connect('edited',self.rtree_time_edited_cb,n,c)
             def get_colnum (tc):
                 try:
                     t = tc.get_title()
                     if t:
                         return _title_to_num_[t.replace('_','')]
                     else:
                         print 'wtf, no title for ',tc
                         return -1
                 except:
                     print 'problem with ',tc
                     raise
                 
             ncols = self.rectree.insert_column_with_data_func(
                 -1,
                 '_%s'%self.rtcolsdic[c],
                 renderer,
                 lambda tc,cell,mod,titr: \
                 cell.set_property(
                 'text',
                 convert.seconds_to_timestring(mod.get_value(
                 titr,
                 get_colnum(tc),
                 #_title_to_num_[tc.get_title().replace('_','')],
                 ))
                 )
                 )
             col=self.rectree.get_column(ncols-1)
             cssu.set_sort_column_id(col,n)
             col.set_property('reorderable',True)
             col.set_property('resizable',True)
             n+=1
             continue
         elif self.editable and self.rtwidgdic[c]=='Combo':
             renderer = gtk.CellRendererCombo()
             model = gtk.ListStore(str)
             if c=='category':
                 map(lambda i: model.append([i]),self.rg.rd.get_unique_values(c,self.rg.rd.categories_table)
                     )
             else:
                 map(lambda i: model.append([i]),self.rg.rd.get_unique_values(c))
             renderer.set_property('model',model)
             renderer.set_property('text-column',0)
         else:
             renderer = gtk.CellRendererText()
             if c=='link':
                 renderer.set_property('ellipsize',pango.ELLIPSIZE_END)
             else:
                 renderer.get_property('wrap-width')
                 renderer.set_property('wrap-mode',pango.WRAP_WORD)
                 if c == 'title': renderer.set_property('wrap-width',200)
                 else: renderer.set_property('wrap-width',150)
         renderer.set_property('editable',self.editable)
         renderer.connect('edited',self.rtree_edited_cb,n, c)
         titl = self.rtcolsdic[c]
         col = gtk.TreeViewColumn('_%s'%titl,renderer, text=n)
         # Ensure that the columns aren't really narrow on initialising.
         #if c=='title':            # Adjust these two to be even bigger
         #    col.set_min_width(200)
         #else:
         #    col.set_min_width(60)
         if c=='title':
             col.set_property('expand',True)
         col.set_reorderable(True)
         col.set_resizable(True)
         col.set_clickable(True)
         #col.connect('clicked', self.column_sort)
         self.rectree.append_column(col)
         cssu.set_sort_column_id(col,n)
         debug("Column %s is %s->%s"%(n,c,self.rtcolsdic[c]),5)
         n += 1