예제 #1
0
 def searchable_names(self):
     ans = {
         'text': OrderedDict(),
         'styles': OrderedDict(),
         'selected': OrderedDict(),
         'open': OrderedDict()
     }
     for item in self.all_files:
         category = unicode(item.data(0, CATEGORY_ROLE) or '')
         mime = unicode(item.data(0, MIME_ROLE) or '')
         name = unicode(item.data(0, NAME_ROLE) or '')
         ok = category in {'text', 'styles'}
         if ok:
             ans[category][name] = syntax_from_mime(name, mime)
         if not ok and category == 'misc':
             ok = mime in {
                 guess_type('a.' + x)
                 for x in ('opf', 'ncx', 'txt', 'xml')
             }
         if ok:
             cats = []
             if item.isSelected():
                 cats.append('selected')
             if name in editors:
                 cats.append('open')
             for cat in cats:
                 ans[cat][name] = syntax_from_mime(name, mime)
     return ans
예제 #2
0
파일: file_list.py 프로젝트: Xliff/calibre
 def searchable_names(self):
     ans = {"text": OrderedDict(), "styles": OrderedDict(), "selected": OrderedDict()}
     for item in self.all_files:
         category = unicode(item.data(0, CATEGORY_ROLE) or "")
         mime = unicode(item.data(0, MIME_ROLE) or "")
         name = unicode(item.data(0, NAME_ROLE) or "")
         ok = category in {"text", "styles"}
         if ok:
             ans[category][name] = syntax_from_mime(name, mime)
         if not ok and category == "misc":
             ok = mime in {guess_type("a." + x) for x in ("opf", "ncx", "txt", "xml")}
         if ok and item.isSelected():
             ans["selected"][name] = syntax_from_mime(name, mime)
     return ans
예제 #3
0
파일: file_list.py 프로젝트: Ralnoc/calibre
 def searchable_names(self):
     ans = {'text':OrderedDict(), 'styles':OrderedDict(), 'selected':OrderedDict()}
     for item in self.all_files:
         category = unicode(item.data(0, CATEGORY_ROLE) or '')
         mime = unicode(item.data(0, MIME_ROLE) or '')
         name = unicode(item.data(0, NAME_ROLE) or '')
         ok = category in {'text', 'styles'}
         if ok:
             ans[category][name] = syntax_from_mime(name, mime)
         if not ok and category == 'misc':
             ok = mime in {guess_type('a.'+x) for x in ('opf', 'ncx', 'txt', 'xml')}
         if ok and item.isSelected():
             ans['selected'][name] = syntax_from_mime(name, mime)
     return ans
예제 #4
0
파일: main.py 프로젝트: nospy/calibre
def get_decoded_raw(name):
    from calibre.ebooks.chardet import xml_to_unicode, force_encoding
    with open(name, 'rb') as f:
        raw = f.read()
    syntax = syntax_from_mime(name, guess_type(name))
    if syntax is None:
        try:
            raw = raw.decode('utf-8')
        except ValueError:
            pass
    elif syntax != 'raster_image':
        if syntax in {'html', 'xml'}:
            raw = xml_to_unicode(raw, verbose=True)[0]
        else:
            m = re.search(br"coding[:=]\s*([-\w.]+)", raw[:1024], flags=re.I)
            if m is not None and m.group(1) != '8bit':
                enc = m.group(1)
                if enc == b'unicode':
                    enc = 'utf-8'
            else:
                enc = force_encoding(raw, verbose=True)
            try:
                raw = raw.decode(enc)
            except (LookupError, ValueError):
                try:
                    raw = raw.decode('utf-8')
                except ValueError:
                    pass
    return raw, syntax
예제 #5
0
 def add_file(self):
     if not self.check_opf_dirtied():
         return
     d = NewFileDialog(self.gui)
     if d.exec_() != d.Accepted:
         return
     self.add_savepoint(_('Add file %s') % self.gui.elided_text(d.file_name))
     c = current_container()
     data = d.file_data
     if d.using_template:
         data = data.replace(b'%CURSOR%', b'')
     try:
         c.add_file(d.file_name, data)
     except:
         self.rewind_savepoint()
         raise
     self.gui.file_list.build(c)
     self.gui.file_list.select_name(d.file_name)
     if c.opf_name in editors:
         editors[c.opf_name].replace_data(c.raw_data(c.opf_name))
     mt = c.mime_map[d.file_name]
     syntax = syntax_from_mime(mt)
     if syntax:
         if d.using_template:
             self.edit_file(d.file_name, syntax, use_template=d.file_data.decode('utf-8'))
         else:
             self.edit_file(d.file_name, syntax)
예제 #6
0
파일: busy.py 프로젝트: MValaguz/MGrep
def get_decoded_raw(name):
    from calibre.ebooks.chardet import xml_to_unicode, force_encoding
    with open(name, 'rb') as f:
        raw = f.read()
    syntax = syntax_from_mime(name, guess_type(name))
    if syntax is None:
        try:
            raw = raw.decode('utf-8')
        except ValueError:
            pass
    elif syntax != 'raster_image':
        if syntax in {'html', 'xml'}:
            raw = xml_to_unicode(raw, verbose=True)[0]
        else:
            m = re.search(br"coding[:=]\s*([-\w.]+)", raw[:1024], flags=re.I)
            if m is not None and m.group(1) != '8bit':
                enc = m.group(1)
                if enc == b'unicode':
                    enc = 'utf-8'
            else:
                enc = force_encoding(raw, verbose=True)
            try:
                raw = raw.decode(enc)
            except (LookupError, ValueError):
                try:
                    raw = raw.decode('utf-8')
                except ValueError:
                    pass
    return raw, syntax
예제 #7
0
파일: boss.py 프로젝트: CharlesSong/calibre
    def add_file(self):
        if current_container() is None:
            return error_dialog(self.gui, _('No open book'), _(
                'You must first open a book to tweak, before trying to create new files'
                ' in it.'), show=True)

        self.commit_dirty_opf()
        d = NewFileDialog(self.gui)
        if d.exec_() != d.Accepted:
            return
        self.add_savepoint(_('Add file %s') % self.gui.elided_text(d.file_name))
        c = current_container()
        data = d.file_data
        if d.using_template:
            data = data.replace(b'%CURSOR%', b'')
        try:
            c.add_file(d.file_name, data)
        except:
            self.rewind_savepoint()
            raise
        self.gui.file_list.build(c)
        self.gui.file_list.select_name(d.file_name)
        if c.opf_name in editors:
            editors[c.opf_name].replace_data(c.raw_data(c.opf_name))
        mt = c.mime_map[d.file_name]
        syntax = syntax_from_mime(d.file_name, mt)
        if syntax:
            if d.using_template:
                self.edit_file(d.file_name, syntax, use_template=d.file_data.decode('utf-8'))
            else:
                self.edit_file(d.file_name, syntax)
예제 #8
0
파일: boss.py 프로젝트: CyberTech/calibre
 def link_clicked(self, name, anchor):
     if not name:
         return
     if name in editors:
         editor = editors[name]
         self.gui.central.show_editor(editor)
     else:
         try:
             mt = current_container().mime_map[name]
         except KeyError:
             return error_dialog(
                 self.gui,
                 _("Does not exist"),
                 _(
                     "The file %s does not exist. If you were trying to click a"
                     " the Table of Contents, you may"
                     ' need to refresh it by right-clicking and choosing "Refresh".'
                 )
                 % name,
                 show=True,
             )
         syntax = syntax_from_mime(name, mt)
         editor = self.edit_file(name, syntax)
     if anchor:
         editor.go_to_anchor(anchor)
예제 #9
0
파일: boss.py 프로젝트: terra666/calibre
 def link_clicked(self, name, anchor):
     if name in editors:
         editor = editors[name]
         self.gui.central.show_editor(editor)
     else:
         syntax = syntax_from_mime(name, current_container().mime_map[name])
         editor = self.edit_file(name, syntax)
     if anchor:
         editor.go_to_anchor(anchor)
예제 #10
0
파일: boss.py 프로젝트: CharlesSong/calibre
 def edit_file_requested(self, name, syntax, mime):
     if name in editors:
         self.gui.central.show_editor(editors[name])
         return
     syntax = syntax or syntax_from_mime(name, mime)
     if not syntax:
         return error_dialog(
             self.gui, _('Unsupported file format'),
             _('Editing files of type %s is not supported' % mime), show=True)
     return self.edit_file(name, syntax)
예제 #11
0
파일: boss.py 프로젝트: kutanari/calibre
 def check_item_activated(self, item):
     name = item.name
     if name in editors:
         editor = editors[name]
         self.gui.central.show_editor(editor)
     else:
         syntax = syntax_from_mime(name, current_container().mime_map[name])
         editor = self.edit_file(name, syntax)
     if editor.has_line_numbers:
         editor.go_to_line(item.line, item.col)
         editor.set_focus()
예제 #12
0
파일: boss.py 프로젝트: kmshi/calibre
 def link_clicked(self, name, anchor):
     if not name:
         return
     if name in editors:
         editor = editors[name]
         self.gui.central.show_editor(editor)
     else:
         syntax = syntax_from_mime(name, current_container().mime_map[name])
         editor = self.edit_file(name, syntax)
     if anchor:
         editor.go_to_anchor(anchor)
예제 #13
0
 def searchable_names(self):
     ans = {
         'text': OrderedDict(),
         'styles': OrderedDict(),
         'selected': OrderedDict()
     }
     for item in self.all_files:
         category = unicode(item.data(0, CATEGORY_ROLE).toString())
         mime = unicode(item.data(0, MIME_ROLE).toString())
         name = unicode(item.data(0, NAME_ROLE).toString())
         ok = category in {'text', 'styles'}
         if ok:
             ans[category][name] = syntax_from_mime(name, mime)
         if not ok and category == 'misc':
             ok = mime in {
                 guess_type('a.' + x)
                 for x in ('opf', 'ncx', 'txt', 'xml')
             }
         if ok and item.isSelected():
             ans['selected'][name] = syntax_from_mime(name, mime)
     return ans
예제 #14
0
파일: boss.py 프로젝트: kmshi/calibre
 def edit_file_requested(self, name, syntax, mime):
     if name in editors:
         self.gui.central.show_editor(editors[name])
         return
     syntax = syntax or syntax_from_mime(name, mime)
     if not syntax:
         return error_dialog(self.gui,
                             _('Unsupported file format'),
                             _('Editing files of type %s is not supported' %
                               mime),
                             show=True)
     return self.edit_file(name, syntax)
예제 #15
0
 def searchable_names(self):
     ans = {'text':OrderedDict(), 'styles':OrderedDict(), 'selected':OrderedDict(), 'open':OrderedDict()}
     for item in self.all_files:
         category = unicode(item.data(0, CATEGORY_ROLE) or '')
         mime = unicode(item.data(0, MIME_ROLE) or '')
         name = unicode(item.data(0, NAME_ROLE) or '')
         ok = category in {'text', 'styles'}
         if ok:
             ans[category][name] = syntax_from_mime(name, mime)
         if not ok:
             if category == 'misc':
                 ok = mime in {guess_type('a.'+x) for x in ('opf', 'ncx', 'txt', 'xml')}
             elif category == 'images':
                 ok = mime == guess_type('a.svg')
         if ok:
             cats = []
             if item.isSelected():
                 cats.append('selected')
             if name in editors:
                 cats.append('open')
             for cat in cats:
                 ans[cat][name] = syntax_from_mime(name, mime)
     return ans
예제 #16
0
파일: boss.py 프로젝트: kmshi/calibre
    def add_file(self):
        if current_container() is None:
            return error_dialog(
                self.gui,
                _('No open book'),
                _('You must first open a book to tweak, before trying to create new files'
                  ' in it.'),
                show=True)

        self.commit_dirty_opf()
        d = NewFileDialog(self.gui)
        if d.exec_() != d.Accepted:
            return
        self.add_savepoint(
            _('Add file %s') % self.gui.elided_text(d.file_name))
        c = current_container()
        data = d.file_data
        if d.using_template:
            data = data.replace(b'%CURSOR%', b'')
        try:
            c.add_file(d.file_name, data)
        except:
            self.rewind_savepoint()
            raise
        self.gui.file_list.build(c)
        self.gui.file_list.select_name(d.file_name)
        if c.opf_name in editors:
            editors[c.opf_name].replace_data(c.raw_data(c.opf_name))
        mt = c.mime_map[d.file_name]
        syntax = syntax_from_mime(d.file_name, mt)
        if syntax:
            if d.using_template:
                self.edit_file(d.file_name,
                               syntax,
                               use_template=d.file_data.decode('utf-8'))
            else:
                self.edit_file(d.file_name, syntax)
예제 #17
0
파일: main.py 프로젝트: JackonYang/calibre
 def syntax(container, name):
     mt = container.mime_map[name]
     return syntax_from_mime(name, mt)
예제 #18
0
파일: busy.py 프로젝트: MValaguz/MGrep
 def syntax(container, name):
     mt = container.mime_map[name]
     return syntax_from_mime(name, mt)