Update comment and flake8 listview.py
This commit is contained in:
parent
881da401e1
commit
5e2f6b0f40
|
@ -38,17 +38,15 @@ import logging
|
||||||
import pygtk
|
import pygtk
|
||||||
pygtk.require('2.0')
|
pygtk.require('2.0')
|
||||||
import gtk
|
import gtk
|
||||||
|
from gobject import signal_new, SIGNAL_RUN_LAST, TYPE_NONE
|
||||||
|
|
||||||
import deluge.common
|
|
||||||
from deluge.ui.gtkui.common import save_pickled_state_file, load_pickled_state_file
|
from deluge.ui.gtkui.common import save_pickled_state_file, load_pickled_state_file
|
||||||
|
|
||||||
from gobject import signal_new, SIGNAL_RUN_LAST, TYPE_NONE
|
signal_new('button-press-event', gtk.TreeViewColumn, SIGNAL_RUN_LAST, TYPE_NONE, (gtk.gdk.Event,))
|
||||||
from gtk import gdk
|
|
||||||
signal_new('button-press-event', gtk.TreeViewColumn,
|
|
||||||
SIGNAL_RUN_LAST, TYPE_NONE, (gdk.Event,))
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ListViewColumnState:
|
class ListViewColumnState:
|
||||||
"""Used for saving/loading column state"""
|
"""Used for saving/loading column state"""
|
||||||
def __init__(self, name, position, width, visible, sort, sort_order):
|
def __init__(self, name, position, width, visible, sort, sort_order):
|
||||||
|
@ -59,6 +57,7 @@ class ListViewColumnState:
|
||||||
self.sort = sort
|
self.sort = sort
|
||||||
self.sort_order = sort_order
|
self.sort_order = sort_order
|
||||||
|
|
||||||
|
|
||||||
class ListView:
|
class ListView:
|
||||||
"""ListView is used to make custom GtkTreeViews. It supports the adding
|
"""ListView is used to make custom GtkTreeViews. It supports the adding
|
||||||
and removing of columns, creating a menu for a column toggle list and
|
and removing of columns, creating a menu for a column toggle list and
|
||||||
|
@ -213,6 +212,7 @@ class ListView:
|
||||||
def on_model_sort_changed(self, model):
|
def on_model_sort_changed(self, model):
|
||||||
if self.unique_column_id:
|
if self.unique_column_id:
|
||||||
self.last_sort_order = {}
|
self.last_sort_order = {}
|
||||||
|
|
||||||
def record_position(model, path, iter, data):
|
def record_position(model, path, iter, data):
|
||||||
self.last_sort_order[model[iter][self.unique_column_id]] = path[0]
|
self.last_sort_order[model[iter][self.unique_column_id]] = path[0]
|
||||||
model.foreach(record_position, None)
|
model.foreach(record_position, None)
|
||||||
|
@ -262,9 +262,8 @@ class ListView:
|
||||||
if self.get_column_name(sort_id) == column.get_title():
|
if self.get_column_name(sort_id) == column.get_title():
|
||||||
sort = sort_id
|
sort = sort_id
|
||||||
|
|
||||||
return ListViewColumnState(column.get_title(), position,
|
return ListViewColumnState(column.get_title(), position, column.get_width(),
|
||||||
column.get_width(), column.get_visible(),
|
column.get_visible(), sort, int(column.get_sort_order()))
|
||||||
sort, int(column.get_sort_order()))
|
|
||||||
|
|
||||||
def save_state(self, filename):
|
def save_state(self, filename):
|
||||||
"""Saves the listview state (column positions and visibility) to
|
"""Saves the listview state (column positions and visibility) to
|
||||||
|
@ -273,7 +272,8 @@ class ListView:
|
||||||
state = []
|
state = []
|
||||||
|
|
||||||
# Workaround for all zero widths after removing column on shutdown
|
# Workaround for all zero widths after removing column on shutdown
|
||||||
if not any(c.get_width() for c in self.treeview.get_columns()): return
|
if not any(c.get_width() for c in self.treeview.get_columns()):
|
||||||
|
return
|
||||||
|
|
||||||
# Get the list of TreeViewColumns from the TreeView
|
# Get the list of TreeViewColumns from the TreeView
|
||||||
for counter, column in enumerate(self.treeview.get_columns()):
|
for counter, column in enumerate(self.treeview.get_columns()):
|
||||||
|
@ -308,7 +308,7 @@ class ListView:
|
||||||
def get_state_field_column(self, field):
|
def get_state_field_column(self, field):
|
||||||
"""Returns the column number for the state field"""
|
"""Returns the column number for the state field"""
|
||||||
for column in self.columns.keys():
|
for column in self.columns.keys():
|
||||||
if self.columns[column].status_field == None:
|
if self.columns[column].status_field is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for f in self.columns[column].status_field:
|
for f in self.columns[column].status_field:
|
||||||
|
@ -332,7 +332,6 @@ class ListView:
|
||||||
if event.button == 3:
|
if event.button == 3:
|
||||||
self.menu.popup(None, None, None, event.button, event.get_time())
|
self.menu.popup(None, None, None, event.button, event.get_time())
|
||||||
|
|
||||||
|
|
||||||
def register_checklist_menu(self, menu):
|
def register_checklist_menu(self, menu):
|
||||||
"""Register a checklist menu with the listview. It will automatically
|
"""Register a checklist menu with the listview. It will automatically
|
||||||
attach any new checklist menu it makes to this menu.
|
attach any new checklist menu it makes to this menu.
|
||||||
|
@ -423,9 +422,9 @@ class ListView:
|
||||||
return
|
return
|
||||||
|
|
||||||
def add_column(self, header, render, col_types, hidden, position,
|
def add_column(self, header, render, col_types, hidden, position,
|
||||||
status_field, sortid, text=0, value=0, pixbuf=0, function=None,
|
status_field, sortid, text=0, value=0, pixbuf=0, function=None,
|
||||||
column_type=None, sort_func=None, tooltip=None, default=True,
|
column_type=None, sort_func=None, tooltip=None, default=True,
|
||||||
unique=False, default_sort=False):
|
unique=False, default_sort=False):
|
||||||
"""Adds a column to the ListView"""
|
"""Adds a column to the ListView"""
|
||||||
# Add the column types to liststore_columns
|
# Add the column types to liststore_columns
|
||||||
column_indices = []
|
column_indices = []
|
||||||
|
@ -466,39 +465,31 @@ class ListView:
|
||||||
|
|
||||||
if column_type == "text":
|
if column_type == "text":
|
||||||
column.pack_start(render)
|
column.pack_start(render)
|
||||||
column.add_attribute(render, "text",
|
column.add_attribute(render, "text", self.columns[header].column_indices[text])
|
||||||
self.columns[header].column_indices[text])
|
|
||||||
elif column_type == "bool":
|
elif column_type == "bool":
|
||||||
column.pack_start(render)
|
column.pack_start(render)
|
||||||
column.add_attribute(render, "active",
|
column.add_attribute(render, "active", self.columns[header].column_indices[0])
|
||||||
self.columns[header].column_indices[0])
|
|
||||||
elif column_type == "func":
|
elif column_type == "func":
|
||||||
column.pack_start(render, True)
|
column.pack_start(render, True)
|
||||||
if len(self.columns[header].column_indices) > 1:
|
if len(self.columns[header].column_indices) > 1:
|
||||||
column.set_cell_data_func_attributes(render, function,
|
column.set_cell_data_func_attributes(render, function, tuple(self.columns[header].column_indices))
|
||||||
tuple(self.columns[header].column_indices))
|
|
||||||
else:
|
else:
|
||||||
column.set_cell_data_func_attributes(render, function,
|
column.set_cell_data_func_attributes(render, function, self.columns[header].column_indices[0])
|
||||||
self.columns[header].column_indices[0])
|
|
||||||
elif column_type == "progress":
|
elif column_type == "progress":
|
||||||
column.pack_start(render)
|
column.pack_start(render)
|
||||||
if function is None:
|
if function is None:
|
||||||
column.add_attribute(render, "text",
|
column.add_attribute(render, "text", self.columns[header].column_indices[text])
|
||||||
self.columns[header].column_indices[text])
|
column.add_attribute(render, "value", self.columns[header].column_indices[value])
|
||||||
column.add_attribute(render, "value",
|
|
||||||
self.columns[header].column_indices[value])
|
|
||||||
else:
|
else:
|
||||||
column.set_cell_data_func_attributes(render, function,
|
column.set_cell_data_func_attributes(render, function, tuple(self.columns[header].column_indices))
|
||||||
tuple(self.columns[header].column_indices))
|
|
||||||
elif column_type == "texticon":
|
elif column_type == "texticon":
|
||||||
column.pack_start(render[pixbuf], False)
|
column.pack_start(render[pixbuf], False)
|
||||||
if function is not None:
|
if function is not None:
|
||||||
column.set_cell_data_func_attributes(render[pixbuf], function,
|
column.set_cell_data_func_attributes(render[pixbuf], function,
|
||||||
self.columns[header].column_indices[pixbuf])
|
self.columns[header].column_indices[pixbuf])
|
||||||
column.pack_start(render[text], True)
|
column.pack_start(render[text], True)
|
||||||
column.add_attribute(render[text], "text",
|
column.add_attribute(render[text], "text", self.columns[header].column_indices[text])
|
||||||
self.columns[header].column_indices[text])
|
elif column_type is None:
|
||||||
elif column_type == None:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
column.set_sort_column_id(self.columns[header].column_indices[sortid])
|
column.set_sort_column_id(self.columns[header].column_indices[sortid])
|
||||||
|
@ -516,7 +507,7 @@ class ListView:
|
||||||
|
|
||||||
# Check for loaded state and apply
|
# Check for loaded state and apply
|
||||||
column_in_state = False
|
column_in_state = False
|
||||||
if self.state != None:
|
if self.state is not None:
|
||||||
for column_state in self.state:
|
for column_state in self.state:
|
||||||
if header == column_state.name:
|
if header == column_state.name:
|
||||||
# We found a loaded state
|
# We found a loaded state
|
||||||
|
@ -622,6 +613,7 @@ class ListView:
|
||||||
# No state file exists, so, no reordering can be done
|
# No state file exists, so, no reordering can be done
|
||||||
return
|
return
|
||||||
columns = self.treeview.get_columns()
|
columns = self.treeview.get_columns()
|
||||||
|
|
||||||
def find_column(header):
|
def find_column(header):
|
||||||
for column in columns:
|
for column in columns:
|
||||||
if column.get_title() == header:
|
if column.get_title() == header:
|
||||||
|
@ -639,9 +631,7 @@ class ListView:
|
||||||
try:
|
try:
|
||||||
column_at_position = columns[col_state.position]
|
column_at_position = columns[col_state.position]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
# While updating the multiuser branch, which adds a new column
|
# Ignore extra columns from Plugins in col_state
|
||||||
# an IndexError was raised, just continue processing, once
|
|
||||||
# deluge is restarted, it all should be good
|
|
||||||
continue
|
continue
|
||||||
if col_state.name == column_at_position.get_title():
|
if col_state.name == column_at_position.get_title():
|
||||||
# It's in the right position
|
# It's in the right position
|
||||||
|
|
Loading…
Reference in New Issue