示例#1
0
 def init_from_template(self, template):
     self.editor.load_text(template, syntax=self.syntax, process_template=True, doc_name=editor_name(self))
示例#2
0
 def fset(self, val):
     self.editor.load_text(val, syntax=self.syntax, doc_name=editor_name(self))
示例#3
0
 def fset(self, val):
     self.editor.load_text(val, syntax=self.syntax, doc_name=editor_name(self))
示例#4
0
 def init_from_template(self, template):
     self.editor.load_text(template, syntax=self.syntax, process_template=True, doc_name=editor_name(self))
示例#5
0
    def dispatcher(self):
        container = self.current_container  # The book being edited as a container object
        if not container:
            return QMessageBox.information(self.gui, "Success",
                                           "لطفا اول یک کتاب را باز کنید")

        if self.parse_current:
            name = editor_name(self.gui.central.current_editor)
            if not name or container.mime_map[name] not in OEB_DOCS:
                return QMessageBox.information(
                    self.gui, "Success", "لطفا اول یک فایل html را باز کنید")

        self.cleanasawhistle = True
        self.changed_files = []

        # criteria1 = ('rtl', 'normal', 'span', 'dir', 'delete', None, '', False)
        # criteria2 = ('ltr', 'normal', 'span', 'dir', 'delete', None, '', False)
        # criteria3 = ('', 'normal', 'span', None, 'delete', None, '', False)

        self.boss.commit_all_editors_to_container()
        self.boss.add_savepoint(_('Before: Span Div Edit'))

        attrs = []
        for name, media_type in container.mime_map.iteritems():
            if media_type in OEB_DOCS:
                for node in container.parsed(name).getroottree().iter():
                    for x in node.keys():
                        if x != 'class' and x != 'style' and x != 'id':
                            attrs.append(x)

        attrs = sorted(set(attrs))

        criterias = []
        for x in attrs:
            criterias.append(
                ('.*', 'regex', 'span', str(x), 'delete', None, '', False))
        criterias.append(
            (None, 'normal', 'span', None, 'delete', None, '', False))
        criterias.append(
            ('.*', 'regex', 'table', 'class', 'delete', None, '', False))
        criterias.append(
            (None, 'normal', 'tr', None, 'delete', None, '', False))
        criterias.append(
            (None, 'normal', 'tbody', None, 'delete', None, '', False))
        criterias.append(
            ('.*', 'regex', 'td', 'class', 'delete', None, '', False))

        try:
            for cri in criterias:
                self.process_files(cri)

            # Craw same tags to combining
            # !important: the below crowing is sorted by tag priorities
            marge_done = self.remove_extra_tags("br") | \
                         self.combine_same_tags("b") | \
                         self.combine_same_tags("span") | \
                         self.remove_last_empty_paragraph()

            if marge_done:
                QMessageBox.information(
                    self.gui, "Combine Same Tags",
                    "Garbage extra tags collector is completed")
        except Exception:
            # Something bad happened report the error to the user
            import traceback
            error_dialog(self.gui,
                         _('خطا'),
                         _('ویرایش تگ ها انچام نشد.'),
                         det_msg=traceback.format_exc(),
                         show=True)
            # Revert to the saved restore point
            self.boss.revert_requested(
                self.boss.global_undo.previous_container)
        else:
            if not self.cleanasawhistle:
                # Show the user what changes we have made,
                # allowing then to revert them if necessary
                self.boss.show_current_diff()

                # Update the editor UI to take into account all the changes we
                # have made
                self.boss.apply_container_update_to_gui()
            else:
                QMessageBox.information(self.gui, "Success", "موردی پیدا نشد")