mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-12 12:34:43 +00:00
[#2670] [GTKUI] optimize file trees according to pygtk tips
Use a context manager to wrap the common steps: 1) disconnect the treestore from the listview 2) disable treestore sorting 3) add rows (different in add dialog vs files tab) 4) enable treestore sorting 5) connect model to listview
This commit is contained in:
parent
ea028c7531
commit
cdeb3c211b
@ -24,7 +24,7 @@ from deluge.configmanager import ConfigManager
|
|||||||
from deluge.httpdownloader import download_file
|
from deluge.httpdownloader import download_file
|
||||||
from deluge.ui.client import client
|
from deluge.ui.client import client
|
||||||
from deluge.ui.common import TorrentInfo
|
from deluge.ui.common import TorrentInfo
|
||||||
from deluge.ui.gtkui.common import reparent_iter
|
from deluge.ui.gtkui.common import listview_replace_treestore, reparent_iter
|
||||||
from deluge.ui.gtkui.dialogs import ErrorDialog
|
from deluge.ui.gtkui.dialogs import ErrorDialog
|
||||||
from deluge.ui.gtkui.path_chooser import PathChooser
|
from deluge.ui.gtkui.path_chooser import PathChooser
|
||||||
from deluge.ui.gtkui.torrentview_data_funcs import cell_data_size
|
from deluge.ui.gtkui.torrentview_data_funcs import cell_data_size
|
||||||
@ -275,17 +275,13 @@ class AddTorrentDialog(component.Component):
|
|||||||
self.save_torrent_options()
|
self.save_torrent_options()
|
||||||
|
|
||||||
def prepare_file_store(self, files):
|
def prepare_file_store(self, files):
|
||||||
self.listview_files.set_model(None)
|
with listview_replace_treestore(self.listview_files):
|
||||||
self.files_treestore.clear()
|
|
||||||
split_files = {}
|
split_files = {}
|
||||||
i = 0
|
for i, file in enumerate(files):
|
||||||
for file in files:
|
|
||||||
self.prepare_file(
|
self.prepare_file(
|
||||||
file, file["path"], i, file["download"], split_files
|
file, file["path"], i, file["download"], split_files
|
||||||
)
|
)
|
||||||
i += 1
|
|
||||||
self.add_files(None, split_files)
|
self.add_files(None, split_files)
|
||||||
self.listview_files.set_model(self.files_treestore)
|
|
||||||
self.listview_files.expand_row("0", False)
|
self.listview_files.expand_row("0", False)
|
||||||
|
|
||||||
def prepare_file(self, file, file_name, file_num, download, files_storage):
|
def prepare_file(self, file, file_name, file_num, download, files_storage):
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#
|
#
|
||||||
"""Common functions for various parts of gtkui to use."""
|
"""Common functions for various parts of gtkui to use."""
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import cPickle
|
import cPickle
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -267,3 +268,29 @@ def load_pickled_state_file(filename):
|
|||||||
else:
|
else:
|
||||||
log.info("Successfully loaded %s: %s", filename, _filepath)
|
log.info("Successfully loaded %s: %s", filename, _filepath)
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def listview_replace_treestore(listview):
|
||||||
|
"""Prepare a listview's treestore to be entirely replaced.
|
||||||
|
|
||||||
|
Params:
|
||||||
|
listview: a listview backed by a treestore
|
||||||
|
"""
|
||||||
|
# From http://faq.pygtk.org/index.py?req=show&file=faq13.043.htp
|
||||||
|
# "tips for improving performance when adding many rows to a Treeview"
|
||||||
|
listview.freeze_child_notify()
|
||||||
|
treestore = listview.get_model()
|
||||||
|
listview.set_model(None)
|
||||||
|
treestore.clear()
|
||||||
|
treestore.set_default_sort_func(lambda *args: 0)
|
||||||
|
original_sort = treestore.get_sort_column_id()
|
||||||
|
treestore.set_sort_column_id(-1, gtk.SORT_ASCENDING)
|
||||||
|
|
||||||
|
yield
|
||||||
|
|
||||||
|
if original_sort != (None, None):
|
||||||
|
treestore.set_sort_column_id(*original_sort)
|
||||||
|
|
||||||
|
listview.set_model(treestore)
|
||||||
|
listview.thaw_child_notify()
|
||||||
|
@ -18,7 +18,8 @@ import gtk.gdk
|
|||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
from deluge.common import FILE_PRIORITY, open_file, show_file
|
from deluge.common import FILE_PRIORITY, open_file, show_file
|
||||||
from deluge.ui.client import client
|
from deluge.ui.client import client
|
||||||
from deluge.ui.gtkui.common import load_pickled_state_file, reparent_iter, save_pickled_state_file
|
from deluge.ui.gtkui.common import (listview_replace_treestore, load_pickled_state_file, reparent_iter,
|
||||||
|
save_pickled_state_file)
|
||||||
from deluge.ui.gtkui.torrentdetails import Tab
|
from deluge.ui.gtkui.torrentdetails import Tab
|
||||||
from deluge.ui.gtkui.torrentview_data_funcs import cell_data_size
|
from deluge.ui.gtkui.torrentview_data_funcs import cell_data_size
|
||||||
|
|
||||||
@ -376,7 +377,7 @@ class FilesTab(Tab):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def update_files(self):
|
def update_files(self):
|
||||||
self.treestore.clear()
|
with listview_replace_treestore(self.listview):
|
||||||
self.prepare_file_store(self.files_list[self.torrent_id])
|
self.prepare_file_store(self.files_list[self.torrent_id])
|
||||||
self.listview.expand_row("0", False)
|
self.listview.expand_row("0", False)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user