示例#1
0
    def set_title(self, title, auto_save=True):
        """Set the title : Find the right element and set the text
        """
        title_el = self._get_title_el()
        old_title = title_el.text
        if title == old_title:
            #no change
            return

        title_el.text = title

        if self.href is not None:
            old_href = self.href
            new_filename = self.opf.find_free_filename(
                EPUBPackage.sanitize_for_filename(title), ".xhtml")
            dirname = os.path.dirname(self.opf.href)
            current_path = os.path.join(dirname, self.href)
            new_path = os.path.join(dirname, new_filename)
            if new_path != current_path:
                os.rename(current_path, new_path)
                #now set the href link properly
                self.opf.handle_item_renamed(old_href, new_filename)
                title_el.set("href", new_filename)

        self.opf.set_package_changed()

        if auto_save:
            self.opf.get_navigation().save()
示例#2
0
 def set_title(self, title, auto_save = True):
     """Set the title : Find the right element and set the text
     """
     title_el = self._get_title_el()
     old_title = title_el.text
     if title == old_title:
         #no change
         return
     
     title_el.text = title
     
     if self.href is not None:
         old_href = self.href
         new_filename = self.opf.find_free_filename(EPUBPackage.sanitize_for_filename(title), ".xhtml")
         dirname = os.path.dirname(self.opf.href)
         current_path = os.path.join(dirname, self.href)
         new_path = os.path.join(dirname, new_filename)
         if new_path != current_path:
             os.rename(current_path, new_path)
             #now set the href link properly
             self.opf.handle_item_renamed(old_href, new_filename)
             title_el.set("href", new_filename)
     
     self.opf.set_package_changed()
     
     if auto_save:
         self.opf.get_navigation().save()