diff --git a/ChangeLog b/ChangeLog index b61ea4939..debba5777 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2003-06-10 Alex Roitman + * src/Plugins.py: Add more values for book item registration. + * src/plugins/FtmStyleDescendants.py: Comply with book changes. + * src/plugins/FtmStyleAncestors.py: Likewise. + * src/plugins/BookReport.py: Rewrite most of the code using new classes: + BookItem, Book, BookList, BookParser, BookListDisplay. Add + open/save/edit functionality. + * src/plugins/book.glade: Add new dialog for BookListDisplay. Also add + a text entry field for saving book and new buttons: Open, Edit, Save. + 2003-06-10 Tim Waugh * src/styles.glade: - scrolling fix * src/dialog.glade: - scrolling fix diff --git a/src/Plugins.py b/src/Plugins.py index f7b75bea7..0480a6584 100644 --- a/src/Plugins.py +++ b/src/Plugins.py @@ -523,13 +523,13 @@ def relationship_function(): # Book item registration # #------------------------------------------------------------------------- -def register_book_item(name,category,options_dialog,write_book_item,options,style): +def register_book_item(name,category,options_dialog,write_book_item,options,style_name,style_file,make_default_style): """Register a book item""" for n in _bkitems: if n[0] == name: return - _bkitems.append((name,category,options_dialog,write_book_item,options,style)) + _bkitems.append((name,category,options_dialog,write_book_item,options,style_name,style_file,make_default_style)) #------------------------------------------------------------------------- # diff --git a/src/plugins/BookReport.py b/src/plugins/BookReport.py index db0833347..0489dbcba 100644 --- a/src/plugins/BookReport.py +++ b/src/plugins/BookReport.py @@ -65,9 +65,380 @@ import GrampsCfg import Plugins import Report +#def get_registered_item(name): +# the_item = None +# for item in Plugins._bkitems: +# if item[0] == name: +# the_item = item +# return the_item + +#------------------------------------------------------------------------ +# +# Book Item class +# +#------------------------------------------------------------------------ +class BookItem: + """ + Interface into the book item -- a smallest element of the book. + """ + + def __init__(self,name=None): + """ + Creates a new empty BookItem. + """ + + self.name = "" + self.category = "" + self.dialog = None + self.write_item = None + self.options = [] + self.style_file = "" + self.style_name = "default" + self.make_default_style = None + if name: + self.get_registered_item(name) + + def clear(self): + self.name = "" + self.category = "" + self.dialog = None + self.write_item = None + self.options = [] + self.style_file = "" + self.style_name = "default" + self.make_default_style = None + + def get_registered_item(self,name): + self.clear() + for item in Plugins._bkitems: + if item[0] == name: + self.name = item[0] + self.category = item[1] + self.dialog = item[2] + self.write_item = item[3] + self.options = item[4] + self.style_name = item[5] + self.style_file = item[6] + self.make_default_style = item[7] + + def get_name(self): + return self.name + + def get_category(self): + return self.category + + def get_dialog(self): + return self.dialog + + def get_write_item(self): + return self.write_item + + def set_options(self,options): + self.options = options + + def get_options(self): + return self.options + + def set_style_name(self,style_name): + self.style_name = style_name + + def get_style_name(self): + return self.style_name + + def get_style_file(self): + return self.style_file + + def get_make_default_style(self): + return self.make_default_style + +#------------------------------------------------------------------------ +# +# Book class +# +#------------------------------------------------------------------------ +class Book: + """ + Interface into the user's defined book -- a collection of book items. + """ + + def __init__(self,obj=None): + """ + Creates a new empty Book. + + obj - if not None, creates the Book from the values in + obj, instead of creating an empty Book. + """ + + self.name = "" + self.dbname = "" + if obj: + self.item_list = obj.item_list + else: + self.item_list = [] + + def set_name(self,name): + self.name = name + + def get_name(self): + return self.name + + def get_dbname(self): + return self.dbname + + def set_dbname(self,name): + self.dbname = name + + def clear(self): + self.item_list = [] + + def append_item(self,item): + self.item_list.append(item) + + def insert_item(self,index,item): + self.item_list.insert(index,item) + + def pop_item(self,index): + self.item_list.pop(index) + + def get_item(self,index): + return self.item_list[index] + + def set_item(self,index,item): + self.item_list[index] = item + + def get_item_list(self): + return self.item_list + +#------------------------------------------------------------------------ +# +# BookList class +# +#------------------------------------------------------------------------ +class BookList: + """ + Interface into the user's defined list of books. + BookList is loaded from a specified XML file if it exists. + """ + + def __init__(self,file): + """ + Creates a new BookList from the books that may be defined in the + specified file. + + file - XML file that contains style definitions + """ + + self.bookmap = {} + self.file = os.path.expanduser("~/.gramps/" + file) + self.parse() + + def delete_book(self,name): + """ + Removes a book from the list. Since each book must have a + unique name, the name is used to delete the book. + + name - Name of the book to delete + """ + del self.bookmap[name] + + def get_book_map(self): + """ + Returns the map of names to books. + """ + return self.bookmap + + def get_book(self,name): + """ + Returns the Book associated with the name + + name - name associated with the desired Book. + """ + return self.bookmap[name] + + def get_book_names(self): + "Returns a list of all the book names in the BookList" + return self.bookmap.keys() + + def set_book(self,name,book): + """ + Adds or replaces a Book in the BookList. + + name - name assocated with the Book to add or replace. + style - definition of the Book + """ + self.bookmap[name] = book + + def save(self): + """ + Saves the current BookList to the associated file. + """ + f = open(self.file,"w") + f.write("\n") + f.write('\n') + + for name in self.bookmap.keys(): + book = self.get_book(name) + dbname = book.get_dbname() + f.write('\n' % (name,dbname) ) + for item in book.get_item_list(): + f.write(' \n' % item.get_name() ) + options = item.get_options() + for opt_index in range(len(options)): + f.write('