Example #1
0
 def on_save_clicked(self, obj):
     """
     Save the current book in the xml booklist file. 
     """
     self.book_list = BookList(self.file, self.db)
     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():
         from ...dialog import QuestionDialog2
         q = 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 q.run():
             self.book.set_name(name)
         else:
             return
     else:
         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.save()
Example #2
0
    def __init__(self, name, dbase):
        ReportOptions.__init__(self, name, dbase)

        # Options specific for this report
        self.options_dict = {
            'bookname': '',
        }
        self.options_help = {
            'bookname': ("=name", _("Name of the book. MANDATORY"),
                         BookList('books.xml', dbase).get_book_names(), False),
        }
Example #3
0
 def on_edit_clicked(self, obj):
     """
     Run the BookListDisplay dialog to present the choice of books to delete. 
     """
     self.book_list = BookList(self.file, self.db)
     booklistdisplay = BookListDisplay(self.book_list, 0, 1)
     booklistdisplay.top.destroy()
     book = booklistdisplay.selection
     if book:
         self.open_book(book)
         self.name_entry.set_text(book.get_name())
         self.book.set_name(book.get_name())
Example #4
0
    def __init__(self, name, dbase):
        ReportOptions.__init__(self, name, dbase)

        # Options specific for this report
        self.options_dict = {
            'bookname': '',
        }
        # TODO since the CLI code for the "book" generates its own "help" now,
        # the GUI code would be faster if it didn't list all the possible books
        self.options_help = {
            'bookname': ("=name", _("Name of the book. MANDATORY"),
                         BookList('books.xml', dbase).get_book_names(), False),
        }
Example #5
0
    def cl_action(self, action, options_str):
        """
        Command-line action routine. Try to perform specified action.
        """
        pmgr = BasePluginManager.get_instance()
        if action == "report":
            try:
                options_str_dict = _split_options(options_str)
            except:
                options_str_dict = {}
                print(_("Ignoring invalid options string."), file=sys.stderr)

            name = options_str_dict.pop('name', None)
            _cl_list = pmgr.get_reg_reports(gui=False)
            if name:
                for pdata in _cl_list:
                    if name == pdata.id:
                        mod = pmgr.load_plugin(pdata)
                        if not mod:
                            #import of plugin failed
                            return
                        category = pdata.category
                        report_class = eval('mod.' + pdata.reportclass)
                        options_class = eval('mod.' + pdata.optionclass)
                        if category in (CATEGORY_BOOK, CATEGORY_CODE):
                            options_class(self.dbstate.db, name, category,
                                          options_str_dict)
                        else:
                            cl_report(self.dbstate.db, name, category,
                                      report_class, options_class,
                                      options_str_dict)
                        return
                # name exists, but is not in the list of valid report names
                msg = _("Unknown report name.")
            else:
                msg = _("Report name not given. "
                        "Please use one of %(donottranslate)s=reportname") % \
                        {'donottranslate' : '[-p|--options] name'}

            print(_("%s\n Available names are:") % msg, file=sys.stderr)
            for pdata in sorted(_cl_list, key=lambda pdata: pdata.id.lower()):
                # Print cli report name ([item[0]), GUI report name (item[4])
                if len(pdata.id) <= 25:
                    print("   %s%s- %s" % (pdata.id, " " *
                                           (26 - len(pdata.id)), pdata.name),
                          file=sys.stderr)
                else:
                    print("   %s\t- %s" % (pdata.id, pdata.name),
                          file=sys.stderr)

        elif action == "tool":
            from gramps.gui.plug import tool
            try:
                options_str_dict = dict([
                    tuple(chunk.split('=')) for chunk in options_str.split(',')
                ])
            except:
                options_str_dict = {}
                print(_("Ignoring invalid options string."), file=sys.stderr)

            name = options_str_dict.pop('name', None)
            _cli_tool_list = pmgr.get_reg_tools(gui=False)
            if name:
                for pdata in _cli_tool_list:
                    if name == pdata.id:
                        mod = pmgr.load_plugin(pdata)
                        if not mod:
                            #import of plugin failed
                            return
                        category = pdata.category
                        tool_class = eval('mod.' + pdata.toolclass)
                        options_class = eval('mod.' + pdata.optionclass)
                        tool.cli_tool(dbstate=self.dbstate,
                                      name=name,
                                      category=category,
                                      tool_class=tool_class,
                                      options_class=options_class,
                                      options_str_dict=options_str_dict,
                                      user=self.user)
                        return
                msg = _("Unknown tool name.")
            else:
                msg = _("Tool name not given. "
                        "Please use one of %(donottranslate)s=toolname.") % \
                        {'donottranslate' : '[-p|--options] name'}

            print(_("%s\n Available names are:") % msg, file=sys.stderr)
            for pdata in sorted(_cli_tool_list,
                                key=lambda pdata: pdata.id.lower()):
                # Print cli report name ([item[0]), GUI report name (item[4])
                if len(pdata.id) <= 25:
                    print("   %s%s- %s" % (pdata.id, " " *
                                           (26 - len(pdata.id)), pdata.name),
                          file=sys.stderr)
                else:
                    print("   %s\t- %s" % (pdata.id, pdata.name),
                          file=sys.stderr)

        elif action == "book":
            try:
                options_str_dict = _split_options(options_str)
            except:
                options_str_dict = {}
                print(_("Ignoring invalid options string."), file=sys.stderr)

            name = options_str_dict.pop('name', None)
            book_list = BookList('books.xml', self.dbstate.db)
            if name:
                if name in book_list.get_book_names():
                    cl_book(self.dbstate.db, name, book_list.get_book(name),
                            options_str_dict)
                    return
                msg = _("Unknown book name.")
            else:
                msg = _("Book name not given. "
                        "Please use one of %(donottranslate)s=bookname.") % \
                        {'donottranslate' : '[-p|--options] name'}

            print(_("%s\n Available names are:") % msg, file=sys.stderr)
            for name in sorted(book_list.get_book_names()):
                print("   %s" % name, file=sys.stderr)

        else:
            print(_("Unknown action: %s.") % action, file=sys.stderr)
            sys.exit(0)
Example #6
0
    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