Changeset 3737
- Timestamp:
- 08/22/08 08:11:15 (5 months ago)
- Location:
- trunk
- Files:
-
- 3 modified
-
ChangeLog (modified) (1 diff)
-
deluge/ui/gtkui/listview.py (modified) (7 diffs)
-
deluge/ui/gtkui/torrentview.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ChangeLog
r3688 r3737 8 8 * Add peer progress to the peers tab 9 9 * Add 'edit' to edit trackers dialog 10 * Sorting # column will place downloaders above seeds -
trunk/deluge/ui/gtkui/listview.py
r3722 r3737 120 120 # show up in any menu listing; it cannot be shown ever. 121 121 self.hidden = False 122 # If this is set, it is used to sort the model 123 self.sort_func = None 124 self.sort_id = None 122 125 123 126 def __init__(self, treeview_widget=None, state_file=None): … … 169 172 self.columns["filter"].column_indices[0]) 170 173 self.model_filter = gtk.TreeModelSort(model_filter) 174 self.set_sort_functions() 171 175 self.treeview.set_model(self.model_filter) 172 176 if sort_column and sort_column != (None, None): 173 177 self.model_filter.set_sort_column_id(*sort_column) 174 178 179 def set_sort_functions(self): 180 for column in self.columns.values(): 181 if column.sort_func: 182 log.debug("sort_func: %s sort_id: %s", column.sort_func, column.sort_id) 183 self.model_filter.set_sort_func( 184 column.sort_id, 185 column.sort_func, 186 column.sort_id) 187 175 188 def save_state(self, filename): 176 189 """Saves the listview state (column positions and visibility) to … … 355 368 def add_column(self, header, render, col_types, hidden, position, 356 369 status_field, sortid, text=0, value=0, pixbuf=0, function=None, 357 column_type=None ):370 column_type=None, sort_func=None): 358 371 """Adds a column to the ListView""" 359 372 # Add the column types to liststore_columns … … 377 390 378 391 self.columns[header].status_field = status_field 392 self.columns[header].sort_func = sort_func 393 self.columns[header].sort_id = column_indices[sortid] 379 394 380 395 # Create a new list with the added column … … 458 473 status_field=None, 459 474 sortid=0, 460 column_type="text"): 475 column_type="text", 476 sort_func=None): 461 477 """Add a text column to the listview. Only the header name is required. 462 478 """ 463 479 render = gtk.CellRendererText() 464 480 self.add_column(header, render, col_type, hidden, position, 465 status_field, sortid, column_type=column_type )481 status_field, sortid, column_type=column_type, sort_func=sort_func) 466 482 467 483 return True … … 480 496 def add_func_column(self, header, function, col_types, sortid=0, 481 497 hidden=False, position=None, status_field=None, 482 column_type="func" ):498 column_type="func", sort_func=None): 483 499 """Add a function column to the listview. Need a header name, the 484 500 function and the column types.""" … … 487 503 self.add_column(header, render, col_types, hidden, position, 488 504 status_field, sortid, column_type=column_type, 489 function=function )505 function=function, sort_func=sort_func) 490 506 491 507 return True -
trunk/deluge/ui/gtkui/torrentview.py
r3733 r3737 101 101 cell.set_property("text", value + 1) 102 102 103 def queue_column_sort(model, iter1, iter2, data): 104 v1 = model[iter1][data] 105 v2 = model[iter2][data] 106 if v1 == v2: 107 return 0 108 if v2 < 0: 109 return -1 110 if v1 < 0: 111 return 1 112 if v1 > v2: 113 return 1 114 if v2 > v1: 115 return -1 116 103 117 class TorrentView(listview.ListView, component.Component): 104 118 """TorrentView handles the listing of torrents.""" … … 123 137 self.add_text_column("torrent_id", hidden=True) 124 138 self.add_bool_column("dirty", hidden=True) 125 self.add_func_column("#", cell_data_queue, [int], status_field=["queue"] )139 self.add_func_column("#", cell_data_queue, [int], status_field=["queue"], sort_func=queue_column_sort) 126 140 self.add_texticon_column(_("Name"), status_field=["state", "name"], 127 141 function=cell_data_statusicon) … … 180 194 181 195 self.treeview.connect("drag-drop", self.on_drag_drop) 182 196 183 197 def start(self): 184 198 """Start the torrentview""" … … 188 202 189 203 def _on_session_state(self, state): 204 self.treeview.freeze_child_notify() 205 model = self.treeview.get_model() 190 206 for torrent_id in state: 191 207 self.add_row(torrent_id, update=False) 192 208 self.mark_dirty(torrent_id) 209 self.treeview.set_model(model) 210 self.treeview.thaw_child_notify() 193 211 self.update() 194 212 … … 254 272 """ 255 273 filter_column = self.columns["filter"].column_indices[0] 256 257 274 # Update the torrent view model with data we've received 258 275 status = self.status 276 (sort_id, sort_type) = self.treeview.get_model().get_sort_column_id() 277 self.treeview.get_model().set_sort_column_id(-1, gtk.SORT_ASCENDING) 259 278 for row in self.liststore: 260 279 torrent_id = row[self.columns["torrent_id"].column_indices[0]] … … 272 291 try: 273 292 # Only update if different 274 if row[column_index] != \ 275 status[torrent_id][self.columns[column].status_field[0]]: 276 row[column_index] = status[torrent_id][ 277 self.columns[column].status_field[0]] 293 row_value = status[torrent_id][self.columns[column].status_field[0]] 294 if row[column_index] != row_value: 295 row[column_index] = row_value 278 296 except (TypeError, KeyError), e: 279 297 log.warning("Unable to update column %s: %s", … … 285 303 try: 286 304 # Only update if different 287 if row[index] != \ 288 status[torrent_id][ 289 self.columns[column].status_field[ 290 column_index.index(index)]]: 291 292 row[index] = \ 293 status[torrent_id][ 294 self.columns[column].status_field[ 295 column_index.index(index)]] 305 row_value = status[torrent_id][self.columns[column].status_field[column_index.index(index)]] 306 if row[index] != row_value: 307 row[index] = row_value 296 308 except: 297 309 pass 310 self.treeview.get_model().set_sort_column_id(sort_id, sort_type) 298 311 # Update the toolbar buttons just in case some state has changed 299 312 component.get("ToolBar").update_buttons() … … 416 429 def on_drag_drop(self, widget, drag_context, x, y, timestamp): 417 430 widget.stop_emission("drag-drop") 418
