From 51402bd486047f555cd51a63c8c29a3fdbd86ccc Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Wed, 27 May 2015 18:13:44 -0400 Subject: [PATCH] PlaceName constructor shortcut; Place.set_name type check; bug fixes for testcasegenerator 1. Added PlaceName(value=..., lang=...) shortcut; will add to others 2. Added an instance check on Place.set_name() to make sure it is a PlaceName 3. Fixed Testcasegenerator to make proper fake places, and a bug in handling windows --- gramps/gen/lib/place.py | 2 ++ gramps/gen/lib/placename.py | 7 ++++++- gramps/plugins/tool/testcasegenerator.py | 5 +++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/gramps/gen/lib/place.py b/gramps/gen/lib/place.py index ff9b3b4fc..14d81d697 100644 --- a/gramps/gen/lib/place.py +++ b/gramps/gen/lib/place.py @@ -314,6 +314,8 @@ class Place(CitationBase, NoteBase, MediaBase, UrlBase, PrimaryObject): :param name: name to assign to the Place :type name: PlaceName """ + if not isinstance(name, PlaceName): + raise ValueError("Place.set_name(name) requires a PlaceName()") self.name = name def get_name(self): diff --git a/gramps/gen/lib/placename.py b/gramps/gen/lib/placename.py index fb815cfa5..6be44ca11 100644 --- a/gramps/gen/lib/placename.py +++ b/gramps/gen/lib/placename.py @@ -45,7 +45,7 @@ class PlaceName(SecondaryObject, DateBase): This class is for keeping information about place names. """ - def __init__(self, source=None): + def __init__(self, source=None, **kwargs): """ Create a new PlaceName instance, copying from the source if present. """ @@ -56,6 +56,11 @@ class PlaceName(SecondaryObject, DateBase): else: self.value = '' self.lang = '' + for key in kwargs: + if key in ["value", "lang"]: + setattr(self, key, kwargs[key]) + else: + raise AttributeError("PlaceName does not have property '%s'" % key) def serialize(self): """ diff --git a/gramps/plugins/tool/testcasegenerator.py b/gramps/plugins/tool/testcasegenerator.py index da401a300..8d09f217a 100644 --- a/gramps/plugins/tool/testcasegenerator.py +++ b/gramps/plugins/tool/testcasegenerator.py @@ -50,7 +50,7 @@ from gramps.gen.lib import (Address, Attribute, AttributeType, ChildRef, ChildRefType, Citation, Date, Event, EventRef, EventRoleType, EventType, Family, FamilyRelType, GrampsType, LdsOrd, Location, MediaObject, MediaRef, Name, NameOriginType, NameType, Note, - NoteType, Person, PersonRef, Place, PlaceType, PlaceRef, + NoteType, Person, PersonRef, Place, PlaceType, PlaceRef, PlaceName, RepoRef, Repository, RepositoryType, Source, SourceMediaType, SrcAttribute, SrcAttributeType, Surname, Tag, Url, UrlType) from gramps.gen.lib.addressbase import AddressBase @@ -194,6 +194,7 @@ class TestcaseGenerator(tool.BatchTool): def init_gui(self,uistate): title = "%s - Gramps" % _("Generate testcases") self.top = Gtk.Dialog(title, parent=uistate.window) + self.window = uistate.window self.top.set_default_size(400,150) self.top.vbox.set_spacing(5) label = Gtk.Label(label='%s' % _("Generate testcases")) @@ -1670,7 +1671,7 @@ class TestcaseGenerator(tool.BatchTool): if isinstance(o, Place): o.set_title(self.rand_text(self.LONG)) - o.set_name(self.rand_text(self.SHORT)) + o.set_name(PlaceName(value=self.rand_text(self.SHORT))) o.set_code(self.rand_text(self.SHORT)) if randint(0, 1) == 1: if randint(0, 4) == 1: