def on_save_clicked(self, obj): """ Save the current book in the xml booklist file. """ if not self.book.get_item_list(): WarningDialog(_('No items'), _('This book has no items.'), parent=self.window) return name = str(self.name_entry.get_text()) if not name: WarningDialog( _('No book name'), _('You are about to save away a book with no name.\n\n' 'Please give it a name before saving it away.'), parent=self.window) return if name in self.book_list.get_book_names(): qqq = QuestionDialog2( _('Book name already exists'), _('You are about to save away a ' 'book with a name which already exists.'), _('Proceed'), _('Cancel'), parent=self.window) if not qqq.run(): return # previously, the same book could be added to the booklist # under multiple names, which became different books once the # booklist was saved into a file so everything was fine, but # this created a problem once the paper settings were added # to the Book object in the BookDialog, since those settings # were retrieved from the Book object in BookList.save, so mutiple # books (differentiated by their names) were assigned the # same paper values, so the solution is to make each Book be # unique in the booklist, so if multiple copies are saved away # only the last one will get the paper values assigned to it # (although when the earlier books are then eventually run, # they'll be assigned paper values also) self.book.set_name(name) self.book.set_dbname(self._db.get_save_path()) self.book_list.set_book(name, self.book) self.book_list.set_needs_saving(True) # user clicked on save self.book = Book(self.book, exact_copy=False) # regenerate old items self.book.set_name(name) self.book.set_dbname(self._db.get_save_path())
def __init__(self, dbstate, uistate): self._db = dbstate.db self.dbstate = dbstate self.uistate = uistate self.title = _('Manage Books') self.file = "books.xml" ManagedWindow.__init__(self, uistate, [], self.__class__) self.xml = Glade('book.glade', toplevel="top") window = self.xml.toplevel title_label = self.xml.get_object('title') self.set_window(window, title_label, self.title) window.show() self.xml.connect_signals({ "on_add_clicked" : self.on_add_clicked, "on_remove_clicked" : self.on_remove_clicked, "on_up_clicked" : self.on_up_clicked, "on_down_clicked" : self.on_down_clicked, "on_setup_clicked" : self.on_setup_clicked, "on_clear_clicked" : self.on_clear_clicked, "on_save_clicked" : self.on_save_clicked, "on_open_clicked" : self.on_open_clicked, "on_edit_clicked" : self.on_edit_clicked, "on_book_ok_clicked" : self.on_book_ok_clicked, "destroy_passed_object" : self.on_close_clicked, # Insert dummy handlers for second top level in the glade file "on_booklist_ok_clicked" : lambda _: None, "on_booklist_delete_clicked" : lambda _: None, "on_booklist_cancel_clicked" : lambda _: None, "on_booklist_ok_clicked" : lambda _: None, "on_booklist_ok_clicked" : lambda _: None, }) self.avail_tree = self.xml.get_object("avail_tree") self.book_tree = self.xml.get_object("book_tree") self.avail_tree.connect('button-press-event', self.avail_button_press) self.book_tree.connect('button-press-event', self.book_button_press) self.name_entry = self.xml.get_object("name_entry") self.name_entry.set_text(_('New Book')) avail_label = self.xml.get_object('avail_label') avail_label.set_text("<b>%s</b>" % _("_Available items")) avail_label.set_use_markup(True) avail_label.set_use_underline(True) book_label = self.xml.get_object('book_label') book_label.set_text("<b>%s</b>" % _("Current _book")) book_label.set_use_underline(True) book_label.set_use_markup(True) avail_titles = [(_('Name'), 0, 230), (_('Type'), 1, 80), ('', -1, 0)] book_titles = [(_('Item name'), -1, 230), (_('Type'), -1, 80), ('', -1, 0), (_('Subject'), -1, 50)] self.avail_nr_cols = len(avail_titles) self.book_nr_cols = len(book_titles) self.avail_model = ListModel(self.avail_tree, avail_titles) self.book_model = ListModel(self.book_tree, book_titles) self.draw_avail_list() self.book = Book() self.book_list = BookList(self.file, self._db) self.book_list.set_needs_saving(False) # just read in: no need to save