From: Benny M. <ben...@gm...> - 2010-01-11 08:24:21
|
2010/1/10 Brian Matherly <br...@gr...>: > As part of GEP008, I'm trying to figure out what to do with the DateDisplay and NameDisplay classes. > > Here is my suggestion: > > 1) Create a new directory in gen called "display". This directory will be for code that facilitates the formatting of data for display (like DateDisplay and NameDisplay) > > Initially, we will have gen.display.date and gen.display.name. But I can imagine that eventually we will have displayers for other objects. I already know of some code in a random "utils" file somewhere that formats Places for display. That code could ultimately find a home in gen.display.place. > > 2) Create a DisplayerFactory class which can do the work of figuring out the right displayer to use. Right now, most code accesses the global BasicUtils.name_displayer and DateHandler.displayer objects. This is bad programming practice. With the new factories, you can call: > gen.display.factory.get_displayer("Date") > and the factory will make sure that you get the right displayer for the current locale and user preferences. > Similarly, calling: > gen.display.factory.get_displayer("Name") > would return a NameDisplay object properly initialized to the current user settings. > This way, the Displayer classes themselves would not depend on config and we could remove code like this: > global WITH_GRAMP_CONFIG > self.name_formats = {} > self.set_name_format(self.STANDARD_FORMATS) > > if WITH_GRAMPS_CONFIG: > self.default_format = config.get('preferences.name-format') > if self.default_format == 0: > self.default_format = Name.LNFN > config.set('preferences.name-format', self.default_format) > else: > self.default_format = 1 > > I would appreciate you comments. If I can move forward with this scheme, I'll add it to the GEP008 wiki page. If I understand correctly, factory will depend on config, and call displayer with correct settings? For me your suggestion sound ok. The idea of Doug with str is nice, but what we do is a bit more versatile than just giving a nice str reprensation of an object, so I would stick with specific display classes, with str in the object being more low level. Benny |