def unbold_boldrow(self, row): if row > -1: try: for i in range(len(self.currentdata[row]) - 1): self.currentdata[row][i + 1] = misc.unbold(self.currentdata[row][i + 1]) except: pass
def unbold_boldrow(self, row): if row > -1: try: for i in range(len(self.currentdata[row]) - 1): self.currentdata[row][i + 1] = misc.unbold( self.currentdata[row][i + 1]) except: pass
def searchfilter_loop(self): while self.filterbox_visible: # copy the last command or pattern safely self.filterbox_cond.acquire() try: while self.filterbox_cmd_buf == "$$$DONE###": self.filterbox_cond.wait() todo = self.filterbox_cmd_buf self.filterbox_cond.release() except: todo = self.filterbox_cmd_buf self.current.freeze_child_notify() matches = gtk.ListStore(*([int] + [str] * len(self.columnformat))) matches.clear() filterposition = self.current.get_visible_rect()[1] _model, selected = self.current_selection.get_selected_rows() filterselected = [] for path in selected: filterselected.append(path) rownum = 0 # Store previous rownums in temporary list, in case we are # about to populate the songfilter with a subset of the # current filter. This will allow us to preserve the mapping. prev_rownums = [] for song in self.filter_row_mapping: prev_rownums.append(song) self.filter_row_mapping = [] if todo == "$$$QUIT###": gobject.idle_add(self.searchfilter_revert_model) return elif len(todo) == 0: for row in self.currentdata: self.filter_row_mapping.append(rownum) rownum = rownum + 1 song_info = [row[0]] for i in range(len(self.columnformat)): song_info.append(misc.unbold(row[i + 1])) matches.append(song_info) else: # this make take some seconds... and we'll escape the search text because # we'll be searching for a match in items that are also escaped. todo = misc.escape_html(todo) todo = re.escape(todo) todo = ".*" + todo.replace(" ", " .*").lower() regexp = re.compile(todo) rownum = 0 if self.prevtodo in todo and len(self.prevtodo) > 0: # If the user's current filter is a subset of the # previous selection (e.g. "h" -> "ha"), search # for files only in the current model, not the # entire self.currentdata subset = True use_data = self.current.get_model() if len(use_data) != len(prev_rownums): # Not exactly sure why this happens sometimes # so lets just revert to prevent a possible, but # infrequent, crash. The only downside is speed. subset = False use_data = self.currentdata else: subset = False use_data = self.currentdata for row in use_data: song_info = [row[0]] for i in range(len(self.columnformat)): song_info.append(misc.unbold(row[i + 1])) # Search for matches in all columns: for i in range(len(self.columnformat)): if regexp.match(unicode(song_info[i + 1]).lower()): matches.append(song_info) if subset: self.filter_row_mapping.append(prev_rownums[rownum]) else: self.filter_row_mapping.append(rownum) break rownum = rownum + 1 if self.prevtodo == todo or self.prevtodo == "RETAIN_POS_AND_SEL": # mpd update, retain view of treeview: retain_position_and_selection = True if self.plpos: filterposition = self.plpos self.plpos = None else: retain_position_and_selection = False self.filterbox_cond.acquire() self.filterbox_cmd_buf = "$$$DONE###" try: self.filterbox_cond.release() except: pass gobject.idle_add( self.searchfilter_set_matches, matches, filterposition, filterselected, retain_position_and_selection ) self.prevtodo = todo
def sort(self, mode, column=None): if self.connected(): if not self.currentdata: return while gtk.events_pending(): gtk.main_iteration() songs = [] track_num = 0 if mode[0:3] == "col": col_num = int(mode.replace("col", "")) if column.get_sort_indicator(): # If this column was already sorted, reverse list: self.column_sorted = (column, self.column_sorted[1]) self.on_sort_reverse(None) return else: self.column_sorted = (column, gtk.SORT_DESCENDING) mode = "col" # If the first tag in the format is song length, we will make sure to compare # the same number of items in the song length string (e.g. always use # ##:##:##) and pad the first item to two (e.g. #:##:## -> ##:##:##) custom_sort = False if mode == "col": custom_sort, custom_pos = self.sort_get_first_format_tag(self.config.currentformat, col_num, "L") for track in self.current_songs: record = {} # Those items that don't have the specified tag will be put at # the end of the list (hence the 'zzzzzzz'): zzz = "zzzzzzzz" if mode == "artist": record["sortby"] = ( misc.lower_no_the(mpdh.get(track, "artist", zzz)), mpdh.get(track, "album", zzz).lower(), mpdh.getnum(track, "disc", "0", True, 0), mpdh.getnum(track, "track", "0", True, 0), ) elif mode == "album": record["sortby"] = ( mpdh.get(track, "album", zzz).lower(), mpdh.getnum(track, "disc", "0", True, 0), mpdh.getnum(track, "track", "0", True, 0), ) elif mode == "file": record["sortby"] = mpdh.get(track, "file", zzz).lower().split("/")[-1] elif mode == "dirfile": record["sortby"] = mpdh.get(track, "file", zzz).lower() elif mode == "col": # Sort by column: record["sortby"] = misc.unbold( self.currentdata.get_value(self.currentdata.get_iter((track_num, 0)), col_num).lower() ) if custom_sort: record["sortby"] = self.sanitize_songlen_for_sorting(record["sortby"], custom_pos) else: record["sortby"] = mpdh.get(track, mode, zzz).lower() record["id"] = int(track["id"]) songs.append(record) track_num = track_num + 1 songs.sort(key=lambda x: x["sortby"]) pos = 0 mpdh.call(self.client, "command_list_ok_begin") for item in songs: mpdh.call(self.client, "moveid", item["id"], pos) pos += 1 mpdh.call(self.client, "command_list_end") self.iterate_now() self.header_update_column_indicators()
def searchfilter_loop(self): while self.filterbox_visible: # copy the last command or pattern safely self.filterbox_cond.acquire() try: while (self.filterbox_cmd_buf == '$$$DONE###'): self.filterbox_cond.wait() todo = self.filterbox_cmd_buf self.filterbox_cond.release() except: todo = self.filterbox_cmd_buf self.current.freeze_child_notify() matches = gtk.ListStore(*([int] + [str] * len(self.columnformat))) matches.clear() filterposition = self.current.get_visible_rect()[1] _model, selected = self.current_selection.get_selected_rows() filterselected = [] for path in selected: filterselected.append(path) rownum = 0 # Store previous rownums in temporary list, in case we are # about to populate the songfilter with a subset of the # current filter. This will allow us to preserve the mapping. prev_rownums = [] for song in self.filter_row_mapping: prev_rownums.append(song) self.filter_row_mapping = [] if todo == '$$$QUIT###': gobject.idle_add(self.searchfilter_revert_model) return elif len(todo) == 0: for row in self.currentdata: self.filter_row_mapping.append(rownum) rownum = rownum + 1 song_info = [row[0]] for i in range(len(self.columnformat)): song_info.append(misc.unbold(row[i + 1])) matches.append(song_info) else: # this make take some seconds... and we'll escape the search text because # we'll be searching for a match in items that are also escaped. todo = misc.escape_html(todo) todo = re.escape(todo) todo = '.*' + todo.replace(' ', ' .*').lower() regexp = re.compile(todo) rownum = 0 if self.prevtodo in todo and len(self.prevtodo) > 0: # If the user's current filter is a subset of the # previous selection (e.g. "h" -> "ha"), search # for files only in the current model, not the # entire self.currentdata subset = True use_data = self.current.get_model() if len(use_data) != len(prev_rownums): # Not exactly sure why this happens sometimes # so lets just revert to prevent a possible, but # infrequent, crash. The only downside is speed. subset = False use_data = self.currentdata else: subset = False use_data = self.currentdata for row in use_data: song_info = [row[0]] for i in range(len(self.columnformat)): song_info.append(misc.unbold(row[i + 1])) # Search for matches in all columns: for i in range(len(self.columnformat)): if regexp.match(unicode(song_info[i + 1]).lower()): matches.append(song_info) if subset: self.filter_row_mapping.append( prev_rownums[rownum]) else: self.filter_row_mapping.append(rownum) break rownum = rownum + 1 if self.prevtodo == todo or self.prevtodo == "RETAIN_POS_AND_SEL": # mpd update, retain view of treeview: retain_position_and_selection = True if self.plpos: filterposition = self.plpos self.plpos = None else: retain_position_and_selection = False self.filterbox_cond.acquire() self.filterbox_cmd_buf = '$$$DONE###' try: self.filterbox_cond.release() except: pass gobject.idle_add(self.searchfilter_set_matches, matches, filterposition, filterselected, retain_position_and_selection) self.prevtodo = todo
def sort(self, mode, column=None): if self.connected(): if not self.currentdata: return while gtk.events_pending(): gtk.main_iteration() songs = [] track_num = 0 if mode[0:3] == 'col': col_num = int(mode.replace('col', '')) if column.get_sort_indicator(): # If this column was already sorted, reverse list: self.column_sorted = (column, self.column_sorted[1]) self.on_sort_reverse(None) return else: self.column_sorted = (column, gtk.SORT_DESCENDING) mode = "col" # If the first tag in the format is song length, we will make sure to compare # the same number of items in the song length string (e.g. always use # ##:##:##) and pad the first item to two (e.g. #:##:## -> ##:##:##) custom_sort = False if mode == 'col': custom_sort, custom_pos = self.sort_get_first_format_tag( self.config.currentformat, col_num, 'L') for track in self.current_songs: record = {} # Those items that don't have the specified tag will be put at # the end of the list (hence the 'zzzzzzz'): zzz = 'zzzzzzzz' if mode == 'artist': record["sortby"] = (misc.lower_no_the( mpdh.get(track, 'artist', zzz)), mpdh.get(track, 'album', zzz).lower(), mpdh.getnum(track, 'disc', '0', True, 0), mpdh.getnum(track, 'track', '0', True, 0)) elif mode == 'album': record["sortby"] = (mpdh.get(track, 'album', zzz).lower(), mpdh.getnum(track, 'disc', '0', True, 0), mpdh.getnum(track, 'track', '0', True, 0)) elif mode == 'file': record["sortby"] = mpdh.get(track, 'file', zzz).lower().split('/')[-1] elif mode == 'dirfile': record["sortby"] = mpdh.get(track, 'file', zzz).lower() elif mode == 'col': # Sort by column: record["sortby"] = misc.unbold( self.currentdata.get_value( self.currentdata.get_iter((track_num, 0)), col_num).lower()) if custom_sort: record["sortby"] = self.sanitize_songlen_for_sorting( record["sortby"], custom_pos) else: record["sortby"] = mpdh.get(track, mode, zzz).lower() record["id"] = int(track["id"]) songs.append(record) track_num = track_num + 1 songs.sort(key=lambda x: x["sortby"]) pos = 0 mpdh.call(self.client, 'command_list_ok_begin') for item in songs: mpdh.call(self.client, 'moveid', item["id"], pos) pos += 1 mpdh.call(self.client, 'command_list_end') self.iterate_now() self.header_update_column_indicators()