def load(gsql, widgets, field_names): name = widgets['cb_name'].get_active_text().decode('utf-8') if not name: log.debug("search rule name is empty") return False cond = sql.load_conditions(gsql, name) if cond: return set_conditions(widgets, cond, field_names) else: return False
def populate(self, movies=None, where=None, qf=True):#{{{ if self.initialized is False: # dont try to fill movie list if Griffith is not initialized yet return False if qf and not movies or isinstance(movies, Select): # if ".execute().fetchall()" not invoked on movies yet if not where: # due to possible 'seen', 'loaned', 'collection_id' in where import advfilter # saved in advfilter name = self.widgets['filter']['advfilter'].get_active_text()[:-3].decode('utf-8') # :-3 due to additional ' ' in the name if name: from sql import load_conditions cond = load_conditions(self.db, name) if not cond: cond = advfilter.get_def_conditions() else: cond = advfilter.get_def_conditions() # seen / loaned if self.widgets['menu']['loaned_movies'].get_active(): cond['loaned'] = True if self.widgets['menu']['not_seen_movies'].get_active(): cond["seen"] = False # collection pos = self.widgets['filter']['collection'].get_active() if pos >= 0: col_id = self.collection_combo_ids[pos] if col_id > 0: cond["collections"].add(col_id) movies = advfilter.create_select_query(self, None, cond, movies) # select sort column sort_column_name = self.config.get('sortby', 'number', section='mainlist') sort_reverse = self.config.get('sortby_reverse', False, section='mainlist') for i in sort_column_name.split(','): if db.movies_table.columns.has_key(i): if sort_reverse: movies.append_order_by(desc(db.movies_table.columns[i])) else: movies.append_order_by(db.movies_table.columns[i]) # additional whereclause (volume_id, collection_id, ...) if where: for i in where: if i in db.Movie: movies.append_whereclause(db.Movie[i]==where[i]) movies = movies.execute().fetchall() self.total = len(movies) # disable refreshing while inserting self.widgets['treeview'].freeze_child_notify() self.widgets['treeview'].set_model(None) # save user sort column sort_column_id, order = self.treemodel.get_sort_column_id() # new treemodel (faster and prevents some problems) self.treemodel = gtk.TreeStore(str, gtk.gdk.Pixbuf, str, str, str, str, bool, str, str, int) # check preferences to hide or show columns if self.config.get('number', True, 'mainlist') == True: self.number_column.set_visible(True) else: self.number_column.set_visible(False) if self.config.get('otitle', True, 'mainlist') == True: self.otitle_column.set_visible(True) else: self.otitle_column.set_visible(False) if self.config.get('title', True, 'mainlist') == True: self.title_column.set_visible(True) else: self.title_column.set_visible(False) if self.config.get('director', True, 'mainlist') == True: self.director_column.set_visible(True) else: self.director_column.set_visible(False) if self.config.get('image', True, 'mainlist') == True: self.image_column.set_visible(True) else: self.image_column.set_visible(False) if self.config.get('genre', True, 'mainlist') == True: self.genre_column.set_visible(True) else: self.genre_column.set_visible(False) if self.config.get('seen', True, 'mainlist') == True: self.seen_column.set_visible(True) else: self.seen_column.set_visible(False) if self.config.get('year', True, 'mainlist') == True: self.year_column.set_visible(True) else: self.year_column.set_visible(False) if self.config.get('runtime', True, 'mainlist') == True: self.runtime_column.set_visible(True) else: self.runtime_column.set_visible(False) if self.config.get('rating', True, 'mainlist') == True: self.rating_column.set_visible(True) else: self.rating_column.set_visible(False) for movie in movies: myiter = self.treemodel.append(None) self.treemodel.set_value(myiter,0,'%004d' % int(movie.number)) if self.config.get('image', True, section='mainlist') == True: filename = None if movie.poster_md5: filename = gutils.get_image_fname(movie.poster_md5, self.db, "s") if not filename: filename = os.path.join(self.locations['images'], 'default_thumbnail.png') self.Image.set_from_file(filename) pixbuf = self.Image.get_pixbuf() self.treemodel.set_value(myiter, 1, pixbuf) self.treemodel.set_value(myiter,2,movie.o_title) self.treemodel.set_value(myiter,3,movie.title) self.treemodel.set_value(myiter,4,movie.director) self.treemodel.set_value(myiter,5,movie.genre) self.treemodel.set_value(myiter,6,movie.seen) if movie.year is not None and (isinstance(movie.year, int) or isinstance(movie.year, long)): self.treemodel.set_value(myiter,7,movie.year) if movie.runtime is not None and (isinstance(movie.runtime, int) or isinstance(movie.runtime, long)): self.treemodel.set_value(myiter,8, '%003d' % movie.runtime + _(' min')) if movie.rating is not None and (isinstance(movie.rating, int) or isinstance(movie.rating, long)): self.treemodel.set_value(myiter,9,movie.rating) # restore user sort column if sort_column_id is not None: self.treemodel.set_sort_column_id(sort_column_id, gtk.SORT_ASCENDING) # add new treemodel and allow refreshs again self.widgets['treeview'].set_model(self.treemodel) self.widgets['treeview'].thaw_child_notify() self.widgets['treeview'].set_cursor_on_cell(0) self.count_statusbar()