Fixes in treeview broke listview, now fixed

simplified unicode/str casting
columnorder working


svn: r19990
This commit is contained in:
Benny Malengier 2012-07-11 17:50:51 +00:00
parent 4c5470492f
commit 9e400a2ca3
10 changed files with 51 additions and 42 deletions

View File

@ -62,7 +62,7 @@ from gen.db import (DbBsddbRead, DbWriteBase, BSDDBTxn,
find_surname_name, DbUndoBSDDB as DbUndo)
from gen.db.dbconst import *
from gen.utils.callback import Callback
from gen.utils.cast import (conv_unicode_tosrtkey_ongtk, conv_dbstr_to_unicode)
from gen.utils.cast import (conv_unicode_tosrtkey, conv_dbstr_to_unicode)
from gen.updatecallback import UpdateCallback
from gen.errors import DbError
from gen.constfunc import win
@ -1428,7 +1428,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
self.emit('person-groupname-rebuild', (name, grouppar))
def sort_surname_list(self):
self.surname_list.sort(key=conv_unicode_tosrtkey_ongtk)
self.surname_list.sort(key=conv_unicode_tosrtkey)
@catch_db_error
def build_surname_list(self):
@ -1440,7 +1440,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
#TODO GTK3: Why double conversion? Convert to a list of str objects!
self.surname_list = sorted(
map(conv_dbstr_to_unicode, set(self.surnames.keys())),
key=conv_unicode_tosrtkey_ongtk)
key=conv_unicode_tosrtkey)
def add_to_surname_list(self, person, batch_transaction):
"""

View File

@ -43,15 +43,22 @@ from gen.datehandler import codeset
"""
strxfrm needs it's unicode argument correctly cast before used.
"""
conv_unicode_tosrtkey = lambda x: locale.strxfrm(x.encode('utf-8', 'replace'))
conv_unicode_tosrtkey_ongtk = lambda x: locale.strxfrm(x.encode(
conv_unicode_tosrtkey = lambda x: locale.strxfrm(x.encode(codeset, 'replace'))
if codeset == 'UTF-8':
conv_str_tosrtkey = lambda x: locale.strxfrm(x)
else:
conv_str_tosrtkey = lambda x: locale.strxfrm(unicode(x,'UTF-8').encode(
codeset, 'replace'))
conv_str_tosrtkey_ongtk = lambda x: locale.strxfrm(unicode(x,'utf-8').encode(
codeset, 'replace'))
def conv_tosrtkey(value):
if isinstance(value, unicode):
return conv_unicode_tosrtkey(value)
return conv_str_tosrtkey(value)
conv_dbstr_to_unicode = lambda x: unicode(x, 'utf-8')
#strings in database are utf-8
conv_dbstr_to_unicode = lambda x: unicode(x, 'UTF-8')
def cast_to_bool(val):
if val == str(True):

View File

@ -82,7 +82,7 @@ class ColumnOrder(Gtk.VBox):
self.config = config
self.on_apply = on_apply
self.pack_start(Gtk.Label(' ', True, True, 0), expand=False, fill=False)
self.pack_start(Gtk.Label(label=' '), False, False, 0)
self.startrow = 0
if self.treeview:
@ -90,15 +90,15 @@ class ColumnOrder(Gtk.VBox):
_('Tree View: first column "%s" cannot be changed') %
column_names[0])
self.startrow = 1
self.pack_start(label, expand=False, fill=False)
self.pack_start(Gtk.Label(' ', True, True, 0), expand=False, fill=False)
self.pack_start(label, False, False, 0)
self.pack_start(Gtk.Label(label=' '), False, False, 0)
self.pack_start(Gtk.Label(_('Drag and drop the columns to change'
' the order', True, True, 0)), expand=False, fill=False)
self.pack_start(Gtk.Label(' ', True, True, 0), expand=False, fill=False)
self.pack_start(Gtk.Label(label=_('Drag and drop the columns to change'
' the order')), False, False, 0)
self.pack_start(Gtk.Label(label=' '), False, False,0)
hbox = Gtk.HBox()
hbox.set_spacing(10)
hbox.pack_start(Gtk.Label(' ', True, True, 0))
hbox.pack_start(Gtk.Label(label=' '), True, True, 0)
scroll = Gtk.ScrolledWindow()
scroll.set_size_request(300,300)
hbox.pack_start(scroll, True, True, 0)

View File

@ -176,10 +176,10 @@ class SurnameTab(EmbeddedList):
for idx in range(len(self.model)):
node = self.model.get_iter(idx)
surn = self.model.get_value(node, 5)
surn.set_prefix(unicode(self.model.get_value(node, 0)))
surn.set_surname(unicode(self.model.get_value(node, 1)))
surn.set_connector(unicode(self.model.get_value(node, 2)))
surn.get_origintype().set(unicode(self.model.get_value(node, 3)))
surn.set_prefix(unicode(self.model.get_value(node, 0), 'UTF-8'))
surn.set_surname(unicode(self.model.get_value(node, 1), 'UTF-8'))
surn.set_connector(unicode(self.model.get_value(node, 2), 'UTF-8'))
surn.get_origintype().set(unicode(self.model.get_value(node, 3), 'UTF-8'))
surn.set_primary(self.model.get_value(node, 4))
new_list += [surn]
return new_list
@ -203,7 +203,7 @@ class SurnameTab(EmbeddedList):
prim = False
if len(self.obj.get_surname_list()) == 0:
prim = True
node = self.model.append(row=['', '', '', NameOriginType(), prim,
node = self.model.append(row=['', '', '', str(NameOriginType()), prim,
Surname()])
self.selection.select_iter(node)
path = self.model.get_path(node)

View File

@ -378,7 +378,7 @@ class ListView(NavigationView):
if self.type_list() == LISTFLAT:
# Flat
iter = self.model.nodemap.new_iter(handle)
iter = self.model.node_map.new_iter(handle)
try:
path = self.model.do_get_path(iter)
except:
@ -543,7 +543,7 @@ class ListView(NavigationView):
construct a list sel_list with all selected handles
'''
if store.do_get_flags() & Gtk.TreeModelFlags.LIST_ONLY:
handle = store.node_map.get_handle(path)
handle = store.node_map.get_handle(path.get_indices()[0])
else:
handle = store.get_handle(store.get_node_from_iter(iter))
@ -1100,9 +1100,9 @@ class ListView(NavigationView):
self.uistate.status_text(_("Updating display..."))
self.uistate.set_busy_cursor(True)
selected = self.selection.get_selected_rows()
for path in selected[1]:
self.list.expand_row(path, True)
store, selected = self.selection.get_selected_rows()
for path in selected:
self.list.expand_row(path, False)
self.uistate.set_busy_cursor(False)
self.uistate.modify_statusbar(self.dbstate)
@ -1113,8 +1113,8 @@ class ListView(NavigationView):
: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]:
store, selected = self.selection.get_selected_rows()
for path in selected:
self.list.collapse_row(path)
def can_configure(self):

View File

@ -74,7 +74,7 @@ from gi.repository import Gtk
#
#-------------------------------------------------------------------------
from gen.filters import SearchFilter, ExactSearchFilter
from gen.utils.cast import conv_unicode_tosrtkey_ongtk
from gen.utils.cast import conv_unicode_tosrtkey, conv_tosrtkey
#-------------------------------------------------------------------------
#
@ -107,7 +107,7 @@ class FlatNodeMap(object):
the path, and a dictionary mapping hndl to index.
To obtain index given a path, method real_index() is available
..Note: If a string sortkey is used, apply conv_unicode_tosrtkey_ongtk
..Note: If a string sortkey is used, apply conv_unicode_tosrtkey
on it , so as to have localized sort
"""
@ -563,13 +563,13 @@ class FlatBaseModel(GObject.Object, Gtk.TreeModel):
Return the (sort_key, handle) list of all data that can maximally
be shown.
This list is sorted ascending, via localized string sort.
conv_unicode_tosrtkey_ongtk which uses strxfrm
conv_unicode_tosrtkey which uses strxfrm
"""
# use cursor as a context manager
with self.gen_cursor() as cursor:
#loop over database and store the sort field, and the handle, and
#allow for a third iter
return sorted((map(conv_unicode_tosrtkey_ongtk,
return sorted((map(conv_tosrtkey,
self.sort_func(data)), key) for key, data in cursor)
def _rebuild_search(self, ignore=None):
@ -639,7 +639,7 @@ class FlatBaseModel(GObject.Object, Gtk.TreeModel):
if self.node_map.get_path_from_handle(handle) is not None:
return # row is already displayed
data = self.map(handle)
insert_val = (map(conv_unicode_tosrtkey_ongtk, self.sort_func(data)),
insert_val = (map(conv_tosrtkey, self.sort_func(data)),
handle)
if not self.search or \
(self.search and self.search.match(handle, self.db)):
@ -673,7 +673,7 @@ class FlatBaseModel(GObject.Object, Gtk.TreeModel):
return # row is not currently displayed
self.clear_cache(handle)
oldsortkey = self.node_map.get_sortkey(handle)
newsortkey = map(conv_unicode_tosrtkey_ongtk, self.sort_func(self.map(
newsortkey = map(conv_tosrtkey, self.sort_func(self.map(
handle)))
if oldsortkey is None or oldsortkey != newsortkey:
#or the changed object is not present in the view due to filtering

View File

@ -55,7 +55,7 @@ from gi.repository import Gtk
# GRAMPS modules
#
#-------------------------------------------------------------------------
from gen.utils.cast import conv_str_tosrtkey_ongtk, conv_unicode_tosrtkey_ongtk
from gen.utils.cast import conv_str_tosrtkey, conv_unicode_tosrtkey
import gui.widgets.progressdialog as progressdlg
from lru import LRU
from bisect import bisect_right
@ -91,11 +91,11 @@ class Node(object):
if isinstance(sortkey, unicode):
self.name = sortkey.encode('utf-8')
#sortkey must be localized sort, so
self.sortkey = conv_unicode_tosrtkey_ongtk(sortkey)
self.sortkey = conv_unicode_tosrtkey(sortkey)
else:
self.name = sortkey
#sortkey must be localized sort, so
self.sortkey = conv_str_tosrtkey_ongtk(sortkey)
self.sortkey = conv_str_tosrtkey(sortkey)
else:
self.name = ''
self.sortkey = None

View File

@ -76,7 +76,8 @@ class MenuToolButtonAction(Gtk.Action):
@type tooltip: str
"""
GObject.GObject.__init__(self, name, label, tooltip, None)
GObject.GObject.__init__(self, name=name, label=label, tooltip=tooltip,
stock_id=None)
##TODO GTK3: following is deprecated, must be replaced by
## Gtk.MenuToolButton.set_related_action(MenuToolButtonAction) in calling class?
## self.set_tool_item_type(Gtk.MenuToolButton)

View File

@ -55,7 +55,7 @@ from PySide import QtOpenGL
#
#-------------------------------------------------------------------------
from gen.const import ROOT_DIR
from gui.views.treemodels import conv_unicode_tosrtkey_ongtk
from gui.views.treemodels import conv_unicode_tosrtkey
from gen.ggettext import gettext as _
from gen.display.name import displayer as name_displayer
from gen.lib import Name
@ -124,14 +124,14 @@ class QMLPersonListModel(QtCore.QAbstractListModel):
Return the (sort_key, handle) list of all data that can maximally
be shown.
This list is sorted ascending, via localized string sort.
conv_unicode_tosrtkey_ongtk which uses strxfrm, which is apparently
conv_unicode_tosrtkey which uses strxfrm, which is apparently
broken in Win ?? --> they should fix base lib, we need strxfrm, fix it
in the Utils module.
"""
# use cursor as a context manager
with self.gen_cursor() as cursor:
#loop over database and store the sort field, and the handle
return sorted((map(conv_unicode_tosrtkey_ongtk,
return sorted((map(conv_unicode_tosrtkey,
self.sort_func(data)), key) for key, data in cursor)
def sort_name(self, data):

View File

@ -38,6 +38,7 @@ Base view for Place Views
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
from gi.repository import Gdk
from gi.repository import Gtk
#-------------------------------------------------------------------------
@ -212,7 +213,7 @@ class PlaceBaseView(ListView):
widget.set_stock_id(Gtk.STOCK_JUMP_TO)
if self.drag_info():
self.list.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK,
[('text/plain', 0, 0), self.drag_info().target()],
[('text/plain', 0, 0), self.drag_info().target_data()],
Gdk.DragAction.COPY)
def __create_maps_menu_actions(self):