Remove column config from db, move to the plugins
Start with reuse of preferences for all configuration Allow all view plugins to set configuration dialog TODO: activate the column reorder in config of listviews svn: r14176
This commit is contained in:
@@ -13,6 +13,8 @@ pkgdatadir = $(datadir)/@PACKAGE@/gui
|
||||
|
||||
pkgdata_PYTHON = \
|
||||
__init__.py \
|
||||
columnorder.py \
|
||||
configure.py \
|
||||
dbguielement.py \
|
||||
dbloader.py \
|
||||
dbman.py \
|
||||
|
140
src/gui/columnorder.py
Normal file
140
src/gui/columnorder.py
Normal file
@@ -0,0 +1,140 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2003 Donald N. Allingham
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
Handle the column ordering
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gen.ggettext import gettext as _
|
||||
import logging
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GTK modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
import gobject
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import const
|
||||
import ManagedWindow
|
||||
from glade import Glade
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# set up logging
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
__LOG = logging.getLogger(".ColumnOrder")
|
||||
|
||||
class ColumnOrder(ManagedWindow.ManagedWindow):
|
||||
"""
|
||||
Column ordering selection dialog
|
||||
"""
|
||||
|
||||
def __init__(self, win_name, uistate, arglist, column_names, callback):
|
||||
"""
|
||||
Create the Column Ordering dialog
|
||||
"""
|
||||
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self)
|
||||
|
||||
self.glade = Glade()
|
||||
self.set_window(self.glade.toplevel, None, win_name)
|
||||
|
||||
self.tree = self.glade.get_object('list')
|
||||
self.arglist = arglist
|
||||
self.callback = callback
|
||||
|
||||
self.model = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING,
|
||||
gobject.TYPE_INT, object)
|
||||
|
||||
self.tree.set_model(self.model)
|
||||
|
||||
checkbox = gtk.CellRendererToggle()
|
||||
checkbox.connect('toggled', toggled, self.model)
|
||||
renderer = gtk.CellRendererText()
|
||||
|
||||
column_n = gtk.TreeViewColumn(_('Display'), checkbox, active=0)
|
||||
column_n.set_min_width(50)
|
||||
self.tree.append_column(column_n)
|
||||
|
||||
column_n = gtk.TreeViewColumn(_('Column Name'), renderer, text=1)
|
||||
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)
|
||||
|
||||
for item in self.arglist:
|
||||
node = self.model.append()
|
||||
self.model.set(node,
|
||||
0, item[0],
|
||||
1, column_names[item[1]],
|
||||
2, item[1],
|
||||
3, item)
|
||||
|
||||
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):
|
||||
"""
|
||||
called with the OK button is pressed
|
||||
"""
|
||||
newlist = []
|
||||
for i in range(0, len(self.arglist)):
|
||||
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()
|
||||
|
||||
def toggled(cell, path, model):
|
||||
"""
|
||||
Called when the cell information is changed, updating the
|
||||
data model so the that change occurs.
|
||||
"""
|
||||
node = model.get_iter((int(path), ))
|
||||
value = not model.get_value(node, 0)
|
||||
model.set(node, 0, value)
|
1166
src/gui/configure.py
Normal file
1166
src/gui/configure.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -67,7 +67,6 @@ import ReportBase
|
||||
import DisplayState
|
||||
import const
|
||||
import config
|
||||
import GrampsCfg
|
||||
import Errors
|
||||
from QuestionDialog import (ErrorDialog, WarningDialog, QuestionDialog2,
|
||||
InfoDialog)
|
||||
@@ -76,6 +75,7 @@ import UndoHistory
|
||||
from gui.dbloader import DbLoader
|
||||
import GrampsDisplay
|
||||
from gui.widgets.progressdialog import ProgressMonitor, GtkProgressDialog
|
||||
from gui.configure import GrampsPreferences
|
||||
from gen.db.backup import backup
|
||||
from gen.db.exceptions import DbException
|
||||
from GrampsAboutDialog import GrampsAboutDialog
|
||||
@@ -762,7 +762,7 @@ class ViewManager(CLIManager):
|
||||
Open the preferences dialog.
|
||||
"""
|
||||
try:
|
||||
GrampsCfg.GrampsPreferences(self.uistate, self.dbstate)
|
||||
GrampsPreferences(self.uistate, self.dbstate)
|
||||
self._key = self.uistate.connect('nameformat-changed',
|
||||
self.active_page.build_tree)
|
||||
except Errors.WindowActiveError:
|
||||
@@ -885,6 +885,7 @@ class ViewManager(CLIManager):
|
||||
page = page_def(self.dbstate, self.uistate)
|
||||
# Category is (string, trans):
|
||||
page.set_category(pdata.category)
|
||||
page.set_ident(page.get_category() + '_' + pdata.id)
|
||||
page_title = page.get_title()
|
||||
page_category = page.get_category()
|
||||
page_translated_category = page.get_translated_category()
|
||||
@@ -1103,6 +1104,12 @@ class ViewManager(CLIManager):
|
||||
mergeid = self.uimanager.add_ui_from_string(self.ui_category[
|
||||
category_page])
|
||||
self.merge_ids.append(mergeid)
|
||||
|
||||
configaction = self.actiongroup.get_action('ConfigView')
|
||||
if self.active_page.can_configure():
|
||||
configaction.set_sensitive(True)
|
||||
else:
|
||||
configaction.set_sensitive(False)
|
||||
|
||||
def change_category(self, obj, page, num=-1):
|
||||
"""
|
||||
@@ -1330,7 +1337,7 @@ class ViewManager(CLIManager):
|
||||
"""
|
||||
Displays the configuration dialog for the active view
|
||||
"""
|
||||
pass
|
||||
self.active_page.configure()
|
||||
|
||||
def undo(self, obj):
|
||||
"""
|
||||
|
@@ -51,6 +51,7 @@ import pango
|
||||
#
|
||||
#----------------------------------------------------------------
|
||||
from gui.views.navigationview import NavigationView
|
||||
from gui.columnorder import ColumnOrder
|
||||
import config
|
||||
import TreeTips
|
||||
import Errors
|
||||
@@ -80,7 +81,13 @@ LISTTREE = 1
|
||||
#
|
||||
#----------------------------------------------------------------
|
||||
class ListView(NavigationView):
|
||||
|
||||
COLUMN_NAMES = []
|
||||
#listview config settings that are always present related to the columns
|
||||
CONFIGSETTINGS = (
|
||||
('columns.visible', []),
|
||||
('columns.order', []),
|
||||
('columns.sizecol', [])
|
||||
)
|
||||
ADD_MSG = ""
|
||||
EDIT_MSG = ""
|
||||
DEL_MSG = ""
|
||||
@@ -127,6 +134,7 @@ class ListView(NavigationView):
|
||||
contains the interface. This containter will be inserted into
|
||||
a gtk.Notebook page.
|
||||
"""
|
||||
self.init_config()
|
||||
self.vbox = gtk.VBox()
|
||||
self.vbox.set_border_width(4)
|
||||
self.vbox.set_spacing(4)
|
||||
@@ -469,10 +477,24 @@ class ListView(NavigationView):
|
||||
|
||||
def column_order(self):
|
||||
"""
|
||||
Must be set by children. The method that obtains the column order
|
||||
to be used. Format: see ColumnOrder.
|
||||
Column order is obtained from the config file of the listview.
|
||||
A column order is a list of 3-tuples. The order in the list is the
|
||||
order the columns must appear in.
|
||||
For a column, the 3-tuple should be (enable, modelcol, sizecol), where
|
||||
enable: show this column or don't show it
|
||||
modelcol: column in the datamodel this column is build of
|
||||
size: size the column should have
|
||||
"""
|
||||
raise NotImplementedError
|
||||
order = self._config.get('columns.order')
|
||||
size = self._config.get('columns.sizecol')
|
||||
vis = self._config.get('columns.visible')
|
||||
colord = []
|
||||
for val, size in zip(order, size):
|
||||
if val in vis:
|
||||
colord.append((1, val, size))
|
||||
else:
|
||||
colord.append((0, val, size))
|
||||
return colord
|
||||
|
||||
def column_ord_setfunc(self, clist):
|
||||
"""
|
||||
@@ -1038,8 +1060,38 @@ class ListView(NavigationView):
|
||||
def close_branch(self, obj):
|
||||
"""
|
||||
Collapse the selected branches.
|
||||
obj: for use of method in event callback
|
||||
:param obj: not used, present only to allow the use of the method in
|
||||
event callback
|
||||
"""
|
||||
selected = self.selection.get_selected_rows()
|
||||
for path in selected[1]:
|
||||
self.list.collapse_row(path)
|
||||
|
||||
def can_configure(self):
|
||||
"""
|
||||
See :class:`~gui.views.pageview.PageView
|
||||
:return: bool
|
||||
"""
|
||||
return True
|
||||
|
||||
def config_connect(self):
|
||||
"""
|
||||
Overwriten from :class:`~gui.views.pageview.PageView method
|
||||
This method will be called after the ini file is initialized
|
||||
"""
|
||||
#func = self.config_callback(self.build_tree)
|
||||
#self._config.connect('columns.visible', func)
|
||||
#self._config.connect('columns.order', func)
|
||||
pass
|
||||
|
||||
def _get_configure_page_funcs(self):
|
||||
"""
|
||||
Return a list of functions that create gtk elements to use in the
|
||||
notebook pages of the Configure dialog
|
||||
|
||||
:return: list of functions
|
||||
"""
|
||||
def columnpage():
|
||||
return _('Columns', ColumnOrder(self._config, COLUMN_NAMES,
|
||||
tree=False))
|
||||
return [columnpage]
|
||||
|
@@ -46,8 +46,11 @@ from gen.ggettext import gettext as _
|
||||
# GRAMPS
|
||||
#
|
||||
#----------------------------------------------------------------
|
||||
import Errors
|
||||
from gui.dbguielement import DbGUIElement
|
||||
from gui.widgets.menutoolbuttonaction import MenuToolButtonAction
|
||||
from gui.configure import ConfigureDialog
|
||||
from config import config
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
#
|
||||
@@ -84,6 +87,8 @@ class PageView(DbGUIElement):
|
||||
placed behind the same button in the sidebar
|
||||
"""
|
||||
|
||||
CONFIGSETTINGS = []
|
||||
|
||||
def __init__(self, title, dbstate, uistate):
|
||||
self.title = title
|
||||
self.dbstate = dbstate
|
||||
@@ -102,6 +107,7 @@ class PageView(DbGUIElement):
|
||||
self._dirty_on_change_inactive = True
|
||||
self.func_list = {}
|
||||
self.category = "Miscellaneous"
|
||||
self.ident = None
|
||||
self.translated_category = _("Miscellaneous")
|
||||
|
||||
self.dbstate.connect('no-database', self.disable_action_group)
|
||||
@@ -110,6 +116,9 @@ class PageView(DbGUIElement):
|
||||
self.model = None
|
||||
self.selection = None
|
||||
self.handle_col = 0
|
||||
|
||||
self._config = None
|
||||
self.__configure_content = None
|
||||
|
||||
DbGUIElement.__init__(self, dbstate.db)
|
||||
|
||||
@@ -232,6 +241,12 @@ class PageView(DbGUIElement):
|
||||
"""
|
||||
return self.translated_category
|
||||
|
||||
def set_ident(self, ident):
|
||||
"""
|
||||
Set the id of the view. This is an unique ident
|
||||
"""
|
||||
self.ident = ident
|
||||
|
||||
def get_display(self):
|
||||
"""
|
||||
Builds the graphical display, returning the top level widget.
|
||||
@@ -373,3 +388,73 @@ class PageView(DbGUIElement):
|
||||
that should be called when quiting the main application.
|
||||
"""
|
||||
pass
|
||||
|
||||
def init_config(self):
|
||||
"""
|
||||
If you need a view with a config, then call this method in the
|
||||
build_tree method. It will set up a config file for the
|
||||
view, and use CONFIGSETTINGS to set the config defaults.
|
||||
The config is later accessbile via self._config
|
||||
So you can do
|
||||
self._config.get("section.variable1")
|
||||
self._config.set("section.variable1", value)
|
||||
self._config.save()
|
||||
|
||||
CONFIGSETTINGS should be a list with tuples like
|
||||
("section.variable1", value)
|
||||
"""
|
||||
if self._config:
|
||||
return
|
||||
self._config = config.register_manager(self.ident,
|
||||
use_config_path=True)
|
||||
for section, value in self.CONFIGSETTINGS:
|
||||
self._config.register(section, value)
|
||||
self._config.init()
|
||||
self.config_connect()
|
||||
|
||||
def config_connect(self):
|
||||
"""
|
||||
Overwrite this method to set connects to the config file to monitor
|
||||
changes. This method will be called after the ini file is initialized
|
||||
Eg:
|
||||
self.config.connect("section.option", self.callback)
|
||||
"""
|
||||
pass
|
||||
|
||||
def config_callback(self, callback):
|
||||
"""
|
||||
Convenience wrappen to create a callback for a config setting
|
||||
:param callback: a callback function to call.
|
||||
"""
|
||||
return lambda arg1, arg2, arg3, arg4: callback()
|
||||
|
||||
def can_configure(self):
|
||||
"""
|
||||
Inheriting classes should set if the view has a configure window or not
|
||||
:return: bool
|
||||
"""
|
||||
return False
|
||||
|
||||
def configure(self):
|
||||
"""
|
||||
Open the configure dialog for the view.
|
||||
"""
|
||||
if not self.__configure_content:
|
||||
self.__configure_content = self._get_configure_page_funcs()
|
||||
title = _("Configure %(cat)s - %(view)s") % \
|
||||
{'cat': self.get_category(), 'view': self.get_title()}
|
||||
try:
|
||||
ConfigureDialog(self.uistate, self.dbstate,
|
||||
self.__configure_content,
|
||||
self, self._config, dialogtitle=title)
|
||||
except Errors.WindowActiveError:
|
||||
return
|
||||
|
||||
def _get_configure_page_funcs(self):
|
||||
"""
|
||||
Return a list of functions that create gtk elements to use in the
|
||||
notebook pages of the Configure view
|
||||
|
||||
:return: list of functions
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
@@ -70,7 +70,21 @@ from gen.ggettext import gettext as _
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class PlaceBaseView(ListView):
|
||||
|
||||
""" base view class for place views, be they flat list or tree
|
||||
"""
|
||||
COL_NAME = 0
|
||||
COL_ID = 1
|
||||
COL_PARISH = 2
|
||||
COL_ZIP = 3
|
||||
COL_CITY = 4
|
||||
COL_COUNTY = 5
|
||||
COL_STATE = 6
|
||||
COL_COUNTRY = 7
|
||||
COL_LAT = 8
|
||||
COL_LON = 9
|
||||
COL_CHAN = 10
|
||||
COL_STREET = 11
|
||||
# name of the columns
|
||||
COLUMN_NAMES = [
|
||||
_('Place Name'),
|
||||
_('ID'),
|
||||
@@ -85,7 +99,16 @@ class PlaceBaseView(ListView):
|
||||
_('Last Changed'),
|
||||
_('Street'),
|
||||
]
|
||||
|
||||
# default setting with visible columns, order of the col, and their size
|
||||
CONFIGSETTINGS = (
|
||||
('columns.visible', [COL_NAME, COL_ID, COL_STREET, COL_CITY, COL_STATE
|
||||
]),
|
||||
('columns.order', [COL_NAME, COL_ID, COL_STREET, COL_ZIP, COL_CITY,
|
||||
COL_COUNTY, COL_STATE, COL_COUNTRY, COL_LAT,
|
||||
COL_LON, COL_PARISH, COL_CHAN]),
|
||||
('columns.sizecol', [250, 75, 100, 100, 100, 100, 150, 150, 150,
|
||||
150, 150, 100])
|
||||
)
|
||||
ADD_MSG = _("Add a new place")
|
||||
EDIT_MSG = _("Edit the selected place")
|
||||
DEL_MSG = _("Delete the selected place")
|
||||
@@ -124,17 +147,12 @@ class PlaceBaseView(ListView):
|
||||
|
||||
def navigation_type(self):
|
||||
return 'Place'
|
||||
|
||||
def column_ord_setfunc(self, clist):
|
||||
self.dbstate.db.set_place_column_order(clist)
|
||||
|
||||
def get_bookmarks(self):
|
||||
return self.dbstate.db.get_place_bookmarks()
|
||||
|
||||
def define_actions(self):
|
||||
ListView.define_actions(self)
|
||||
self._add_action('ColumnEdit', gtk.STOCK_PROPERTIES,
|
||||
_('_Column Editor'), callback=self._column_editor)
|
||||
self._add_action('FastMerge', None, _('_Merge...'),
|
||||
callback=self.fast_merge)
|
||||
self._add_toolmenu_action('MapsList', _('Loading...'),
|
||||
@@ -268,19 +286,6 @@ class PlaceBaseView(ListView):
|
||||
def drag_info(self):
|
||||
return DdTargets.PLACE_LINK
|
||||
|
||||
def _column_editor(self, obj):
|
||||
import ColumnOrder
|
||||
|
||||
ColumnOrder.ColumnOrder(
|
||||
_('Select Place Columns'),
|
||||
self.uistate,
|
||||
self.dbstate.db.get_place_column_order(),
|
||||
PlaceBaseView.COLUMN_NAMES,
|
||||
self.set_column_order)
|
||||
|
||||
def column_order(self):
|
||||
return self.dbstate.db.get_place_column_order()
|
||||
|
||||
def get_stock(self):
|
||||
return 'gramps-place'
|
||||
|
||||
@@ -311,7 +316,6 @@ class PlaceBaseView(ListView):
|
||||
<menuitem action="Edit"/>
|
||||
<menuitem action="Remove"/>
|
||||
</placeholder>
|
||||
<menuitem action="ColumnEdit"/>
|
||||
<menuitem action="FilterEdit"/>
|
||||
<placeholder name="Merge">
|
||||
<menuitem action="FastMerge"/>
|
||||
|
@@ -60,6 +60,7 @@ class NoteModel(FlatBaseModel):
|
||||
self.column_id,
|
||||
self.column_type,
|
||||
self.column_marker,
|
||||
self.column_change,
|
||||
self.column_handle,
|
||||
self.column_marker_color
|
||||
]
|
||||
@@ -68,10 +69,11 @@ class NoteModel(FlatBaseModel):
|
||||
self.column_id,
|
||||
self.column_type,
|
||||
self.column_marker,
|
||||
self.column_change,
|
||||
self.column_handle,
|
||||
self.column_marker_color
|
||||
]
|
||||
self.marker_color_column = 5
|
||||
self.marker_color_column = 6
|
||||
FlatBaseModel.__init__(self, db, scol, order, search=search,
|
||||
skip=skip, sort_map=sort_map)
|
||||
|
||||
@@ -124,3 +126,7 @@ class NoteModel(FlatBaseModel):
|
||||
return None
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
def column_change(self,data):
|
||||
return unicode(time.strftime('%x %X',time.localtime(
|
||||
data[Note.POS_CHANGE])), GrampsLocale.codeset)
|
||||
|
Reference in New Issue
Block a user