Fix #602 re-did files/peers tab state saving/loading
This commit is contained in:
parent
d64f8c3d93
commit
e759d61266
|
@ -76,14 +76,6 @@ def cell_progress(column, cell, model, row, data):
|
||||||
cell.set_property("text", text)
|
cell.set_property("text", text)
|
||||||
cell.set_property("value", value)
|
cell.set_property("value", value)
|
||||||
|
|
||||||
class ColumnState:
|
|
||||||
def __init__(self, name, position, width, sort, sort_order):
|
|
||||||
self.name = name
|
|
||||||
self.position = position
|
|
||||||
self.width = width
|
|
||||||
self.sort = sort
|
|
||||||
self.sort_order = sort_order
|
|
||||||
|
|
||||||
class FilesTab(Tab):
|
class FilesTab(Tab):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Tab.__init__(self)
|
Tab.__init__(self)
|
||||||
|
@ -203,10 +195,21 @@ class FilesTab(Tab):
|
||||||
|
|
||||||
def save_state(self):
|
def save_state(self):
|
||||||
filename = "files_tab.state"
|
filename = "files_tab.state"
|
||||||
state = []
|
# Get the current sort order of the view
|
||||||
|
column_id, sort_order = self.treestore.get_sort_column_id()
|
||||||
|
|
||||||
|
# Setup state dict
|
||||||
|
state = {
|
||||||
|
"columns": {},
|
||||||
|
"sort_id": column_id,
|
||||||
|
"sort_order": sort_order
|
||||||
|
}
|
||||||
|
|
||||||
for index, column in enumerate(self.listview.get_columns()):
|
for index, column in enumerate(self.listview.get_columns()):
|
||||||
state.append(ColumnState(column.get_title(), index, column.get_width(),
|
state["columns"][column.get_title()] = {
|
||||||
column.get_sort_indicator(), int(column.get_sort_order())))
|
"position": index,
|
||||||
|
"width": column.get_width()
|
||||||
|
}
|
||||||
|
|
||||||
# Get the config location for saving the state file
|
# Get the config location for saving the state file
|
||||||
config_location = ConfigManager("gtkui.conf")["config_location"]
|
config_location = ConfigManager("gtkui.conf")["config_location"]
|
||||||
|
@ -230,28 +233,30 @@ class FilesTab(Tab):
|
||||||
state_file = open(os.path.join(config_location, filename), "rb")
|
state_file = open(os.path.join(config_location, filename), "rb")
|
||||||
state = cPickle.load(state_file)
|
state = cPickle.load(state_file)
|
||||||
state_file.close()
|
state_file.close()
|
||||||
except (EOFError, IOError), e:
|
except (EOFError, IOError, AttributeError), e:
|
||||||
log.warning("Unable to load state file: %s", e)
|
log.warning("Unable to load state file: %s", e)
|
||||||
|
|
||||||
if state == None:
|
if state == None:
|
||||||
return
|
return
|
||||||
|
|
||||||
for column_state in state:
|
if state["sort_id"] and state["sort_order"]:
|
||||||
# Find matching columns in the listview
|
self.treestore.set_sort_column_id(state["sort_id"], state["sort_order"])
|
||||||
for (index, column) in enumerate(self.listview.get_columns()):
|
|
||||||
if column_state.name == column.get_title():
|
for (index, column) in enumerate(self.listview.get_columns()):
|
||||||
# We have a match, so set options that were saved in state
|
cname = column.get_title()
|
||||||
if column_state.width > 0:
|
if state["columns"].has_key(cname):
|
||||||
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
cstate = state["columns"][cname]
|
||||||
column.set_fixed_width(column_state.width)
|
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||||
column.set_sort_indicator(column_state.sort)
|
column.set_fixed_width(cstate["width"])
|
||||||
column.set_sort_order(column_state.sort_order)
|
if state["sort_id"] == index:
|
||||||
if column_state.position != index:
|
column.set_sort_indicator(True)
|
||||||
# Column is in wrong position
|
column.set_sort_order(state["sort_order"])
|
||||||
if column_state.position == 0:
|
if cstate["position"] != index:
|
||||||
self.listview.move_column_after(column, None)
|
# Column is in wrong position
|
||||||
else:
|
if cstate["position"] == 0:
|
||||||
self.listview.move_column_after(column, self.listview.get_columns()[column_state.position - 1])
|
self.listview.move_column_after(column, None)
|
||||||
|
elif self.listview.get_columns()[cstate["position"] - 1].get_title() != cname:
|
||||||
|
self.listview.move_column_after(column, self.listview.get_columns()[cstate["position"] - 1])
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
# Get the first selected torrent
|
# Get the first selected torrent
|
||||||
|
@ -661,4 +666,3 @@ class FilesTab(Tab):
|
||||||
model.foreach(find_file, None)
|
model.foreach(find_file, None)
|
||||||
log.debug("to_rename: %s", to_rename)
|
log.debug("to_rename: %s", to_rename)
|
||||||
client.rename_files(self.torrent_id, to_rename)
|
client.rename_files(self.torrent_id, to_rename)
|
||||||
|
|
||||||
|
|
|
@ -44,14 +44,6 @@ def cell_data_progress(column, cell, model, row, data):
|
||||||
cell.set_property("value", value * 100)
|
cell.set_property("value", value * 100)
|
||||||
cell.set_property("text", "%.2f%%" % (value * 100))
|
cell.set_property("text", "%.2f%%" % (value * 100))
|
||||||
|
|
||||||
class ColumnState:
|
|
||||||
def __init__(self, name, position, width, sort, sort_order):
|
|
||||||
self.name = name
|
|
||||||
self.position = position
|
|
||||||
self.width = width
|
|
||||||
self.sort = sort
|
|
||||||
self.sort_order = sort_order
|
|
||||||
|
|
||||||
class PeersTab(Tab):
|
class PeersTab(Tab):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Tab.__init__(self)
|
Tab.__init__(self)
|
||||||
|
@ -166,10 +158,21 @@ class PeersTab(Tab):
|
||||||
|
|
||||||
def save_state(self):
|
def save_state(self):
|
||||||
filename = "peers_tab.state"
|
filename = "peers_tab.state"
|
||||||
state = []
|
# Get the current sort order of the view
|
||||||
|
column_id, sort_order = self.liststore.get_sort_column_id()
|
||||||
|
|
||||||
|
# Setup state dict
|
||||||
|
state = {
|
||||||
|
"columns": {},
|
||||||
|
"sort_id": column_id,
|
||||||
|
"sort_order": sort_order
|
||||||
|
}
|
||||||
|
|
||||||
for index, column in enumerate(self.listview.get_columns()):
|
for index, column in enumerate(self.listview.get_columns()):
|
||||||
state.append(ColumnState(column.get_title(), index, column.get_width(),
|
state["columns"][column.get_title()] = {
|
||||||
column.get_sort_indicator(), int(column.get_sort_order())))
|
"position": index,
|
||||||
|
"width": column.get_width()
|
||||||
|
}
|
||||||
|
|
||||||
# Get the config location for saving the state file
|
# Get the config location for saving the state file
|
||||||
config_location = ConfigManager("gtkui.conf")["config_location"]
|
config_location = ConfigManager("gtkui.conf")["config_location"]
|
||||||
|
@ -193,32 +196,34 @@ class PeersTab(Tab):
|
||||||
state_file = open(os.path.join(config_location, filename), "rb")
|
state_file = open(os.path.join(config_location, filename), "rb")
|
||||||
state = cPickle.load(state_file)
|
state = cPickle.load(state_file)
|
||||||
state_file.close()
|
state_file.close()
|
||||||
except (EOFError, IOError), e:
|
except (EOFError, IOError, AttributeError), e:
|
||||||
log.warning("Unable to load state file: %s", e)
|
log.warning("Unable to load state file: %s", e)
|
||||||
|
|
||||||
if state == None:
|
if state == None:
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(state) != len(self.listview.get_columns()):
|
if len(state["columns"]) != len(self.listview.get_columns()):
|
||||||
log.warning("peers_tab.state is not compatible! rejecting..")
|
log.warning("peers_tab.state is not compatible! rejecting..")
|
||||||
return
|
return
|
||||||
|
|
||||||
for column_state in state:
|
if state["sort_id"] and state["sort_order"]:
|
||||||
# Find matching columns in the listview
|
self.treestore.set_sort_column_id(state["sort_id"], state["sort_order"])
|
||||||
for (index, column) in enumerate(self.listview.get_columns()):
|
|
||||||
if column_state.name == column.get_title():
|
for (index, column) in enumerate(self.listview.get_columns()):
|
||||||
# We have a match, so set options that were saved in state
|
cname = column.get_title()
|
||||||
if column_state.width > 0:
|
if state["columns"].has_key(cname):
|
||||||
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
cstate = state["columns"][cname]
|
||||||
column.set_fixed_width(column_state.width)
|
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||||
column.set_sort_indicator(column_state.sort)
|
column.set_fixed_width(cstate["width"])
|
||||||
column.set_sort_order(column_state.sort_order)
|
if state["sort_id"] == index:
|
||||||
if column_state.position != index:
|
column.set_sort_indicator(True)
|
||||||
# Column is in wrong position
|
column.set_sort_order(state["sort_order"])
|
||||||
if column_state.position == 0:
|
if cstate["position"] != index:
|
||||||
self.listview.move_column_after(column, None)
|
# Column is in wrong position
|
||||||
else:
|
if cstate["position"] == 0:
|
||||||
self.listview.move_column_after(column, self.listview.get_columns()[column_state.position - 1])
|
self.listview.move_column_after(column, None)
|
||||||
|
elif self.listview.get_columns()[cstate["position"] - 1].get_title() != cname:
|
||||||
|
self.listview.move_column_after(column, self.listview.get_columns()[cstate["position"] - 1])
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
# Get the first selected torrent
|
# Get the first selected torrent
|
||||||
|
|
Loading…
Reference in New Issue