Reenable changing column order for all listviews

svn: r14179
This commit is contained in:
Benny Malengier
2010-02-01 13:04:19 +00:00
parent 377b0937f6
commit 140c7c6f7d
7 changed files with 108 additions and 161 deletions

View File

@@ -18,7 +18,6 @@ dist_pkgdata_DATA = \
displaystate.glade \
addmedia.glade \
questiondialog.glade \
columnorder.glade \
configure.glade \
dateedit.glade \
editsource.glade \

View File

@@ -1,94 +0,0 @@
<?xml version="1.0"?>
<interface>
<!-- interface-requires gtk+ 2.12 -->
<!-- interface-naming-policy project-wide -->
<object class="GtkDialog" id="columnorder">
<property name="visible">True</property>
<property name="type_hint">dialog</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox15">
<property name="visible">True</property>
<child>
<object class="GtkTable" id="table46">
<property name="visible">True</property>
<property name="border_width">12</property>
<property name="n_rows">3</property>
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow77">
<property name="width_request">400</property>
<property name="height_request">300</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="list">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="reorderable">True</property>
</object>
</child>
</object>
<packing>
<property name="bottom_attach">3</property>
</packing>
</child>
</object>
<packing>
<property name="padding">6</property>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area15">
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="cancelbutton">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="okbutton">
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">cancelbutton</action-widget>
<action-widget response="-5">okbutton</action-widget>
</action-widgets>
</object>
</interface>

View File

@@ -55,23 +55,50 @@ from glade import Glade
#-------------------------------------------------------------------------
__LOG = logging.getLogger(".ColumnOrder")
class ColumnOrder(ManagedWindow.ManagedWindow):
class ColumnOrder(gtk.VBox):
"""
Column ordering selection dialog
Column ordering selection widget
"""
def __init__(self, win_name, uistate, arglist, column_names, callback):
def __init__(self, config, column_names, on_apply, tree=False):
"""
Create the Column Ordering dialog
"""
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self)
Create the Column Ordering widget based on config
self.glade = Glade()
self.set_window(self.glade.toplevel, None, win_name)
config: a configuration file with column data
column_names: translated names for the possible columns
on_apply: function to run when apply is clicked
tree: are the columns for a treeview, if so, the first columns is not
changable
"""
gtk.VBox.__init__(self)
self.tree = self.glade.get_object('list')
self.arglist = arglist
self.callback = callback
self.treeview = tree
self.colnames = column_names
self.config = config
self.on_apply = on_apply
self.startrow = 0
if self.treeview:
label = gtk.Label(
_('Tree View: first column "%s" cannot be changed') %
column_names[0])
self.startrow = 1
self.pack_start(label, expand=False, fill=False)
hbox = gtk.HBox()
hbox.set_spacing(10)
scroll = gtk.ScrolledWindow()
scroll.set_size_request(250,300)
hbox.pack_start(scroll)
self.tree = gtk.TreeView()
self.tree.set_reorderable(True)
scroll.add(self.tree)
self.apply_button = gtk.Button(stock='gtk-apply')
btns = gtk.HButtonBox()
btns.set_layout(gtk.BUTTONBOX_END)
btns.pack_start(self.apply_button)
hbox.pack_start(btns, expand=False)
self.pack_start(hbox)
self.model = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING,
gobject.TYPE_INT, object)
@@ -90,45 +117,53 @@ class ColumnOrder(ManagedWindow.ManagedWindow):
column_n.set_min_width(225)
self.tree.append_column(column_n)
self.glade.get_object('okbutton').connect('clicked',
self.ok_clicked)
self.glade.get_object('cancelbutton').connect('clicked',
self.cancel_clicked)
self.apply_button.connect('clicked', self.__on_apply)
for item in self.arglist:
#obtain the columns from config file
self.oldorder = self.config.get('columns.order')
self.oldsize = self.config.get('columns.sizecol')
self.oldvis = self.config.get('columns.visible')
colord = []
for val, size in zip(self.oldorder, self.oldsize):
if val in self.oldvis:
colord.append((1, val, size))
else:
colord.append((0, val, size))
for item in colord[self.startrow:]:
node = self.model.append()
self.model.set(node,
0, item[0],
1, column_names[item[1]],
2, item[1],
3, item)
3, item[2])
def build_menu_names(self, obj):
"""
Build the information for the Managed Window menu entries
"""
return (_('Column Editor'), _('Column Editor'))
def ok_clicked(self, obj):
def __on_apply(self, obj):
"""
called with the OK button is pressed
"""
newlist = []
for i in range(0, len(self.arglist)):
neworder = []
newsize = []
newvis = []
if self.treeview:
#first row is fixed
neworder.append(self.oldorder[0])
newvis.append(self.oldvis[0])
newsize.append(self.oldsize[0])
for i in range(0, len(self.colnames[self.startrow:])):
node = self.model.get_iter((int(i), ))
enable = self.model.get_value(node, 0)
index = self.model.get_value(node, 2)
value = self.model.get_value(node, 3)
newlist.append((enable, index, value[2]))
self.callback(newlist)
self.close()
def cancel_clicked(self, obj):
"""
Called with the Cancel button is pressed.
"""
self.close()
size = self.model.get_value(node, 3)
if enable:
newvis.append(index)
neworder.append(index)
newsize.append(size)
self.config.set('columns.order', neworder)
self.config.set('columns.sizecol', newsize)
self.config.set('columns.visible', newvis)
self.config.save()
if self.on_apply:
self.on_apply()
def toggled(cell, path, model):
"""

View File

@@ -461,11 +461,11 @@ class ListView(NavigationView):
sel_data.set(sel_data.target, 8 , pickle.dumps(data))
return True
def set_column_order(self, clist):
def set_column_order(self):
"""
change the order of the columns to that given in clist
change the order of the columns to that given in config file
after config file changed. We reset the sort to the first column
"""
self.column_ord_setfunc(clist)
#now we need to rebuild the model so it contains correct column info
self.dirty = True
#make sure we sort on first column. We have no idea where the
@@ -496,20 +496,6 @@ class ListView(NavigationView):
colord.append((0, val, size))
return colord
def column_ord_setfunc(self, clist):
"""
Must be set by children. The method that stores the column order
given by clist (result of ColumnOrder class).
"""
raise NotImplementedError
def _column_editor(self, obj):
"""
Causes the View to display a column editor. This should be overridden
by any class that provides columns (such as a list based view)
"""
raise NotImplemented
def remove_selected_objects(self):
"""
Function to remove selected objects
@@ -1077,7 +1063,8 @@ class ListView(NavigationView):
def config_connect(self):
"""
Overwriten from :class:`~gui.views.pageview.PageView method
This method will be called after the ini file is initialized
This method will be called after the ini file is initialized,
use it to monitor changes in the ini file
"""
#func = self.config_callback(self.build_tree)
#self._config.connect('columns.visible', func)
@@ -1092,6 +1079,7 @@ class ListView(NavigationView):
:return: list of functions
"""
def columnpage():
return _('Columns', ColumnOrder(self._config, COLUMN_NAMES,
tree=False))
return _('Columns'), ColumnOrder(self._config, self.COLUMN_NAMES,
self.set_column_order,
tree=self.type_list()==LISTTREE)
return [columnpage]

View File

@@ -444,9 +444,12 @@ class PageView(DbGUIElement):
title = _("Configure %(cat)s - %(view)s") % \
{'cat': self.get_category(), 'view': self.get_title()}
try:
ConfigureDialog(self.uistate, self.dbstate,
ViewConfigureDialog(self.uistate, self.dbstate,
self.__configure_content,
self, self._config, dialogtitle=title)
self, self._config, dialogtitle=title,
ident=_("%(cat)s - %(view)s") %
{'cat': self.get_category(),
'view': self.get_title()})
except Errors.WindowActiveError:
return
@@ -458,3 +461,18 @@ class PageView(DbGUIElement):
:return: list of functions
"""
raise NotImplementedError
class ViewConfigureDialog(ConfigureDialog):
"""
All PageViews can have their own configuration dialog
"""
def __init__(self, uistate, dbstate, configure_page_funcs, configobj,
configmanager,
dialogtitle=_("Preferences"), on_close=None, ident=''):
self.ident = ident
ConfigureDialog.__init__(self, uistate, dbstate, configure_page_funcs,
configobj, configmanager,
dialogtitle=dialogtitle, on_close=on_close)
def build_menu_names(self, obj):
return (_('Configure %s View') % self.ident, None)