home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1205 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.2 KB  |  76 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. __license__ = 'GPL v3'
  6. __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
  7. __docformat__ = 'restructuredtext en'
  8. import re
  9. from calibre.gui2.convert.structure_detection_ui import Ui_Form
  10. from calibre.gui2.convert import Widget
  11. from calibre.gui2 import error_dialog
  12.  
  13. class StructureDetectionWidget(Widget, Ui_Form):
  14.     TITLE = _('Structure\nDetection')
  15.     ICON = I('chapters.svg')
  16.     HELP = _('Fine tune the detection of chapter headings and other document structure.')
  17.     
  18.     def __init__(self, parent, get_option, get_help, db = None, book_id = None):
  19.         Widget.__init__(self, parent, 'structure_detection', [
  20.             'chapter',
  21.             'chapter_mark',
  22.             'remove_first_image',
  23.             'insert_metadata',
  24.             'page_breaks_before',
  25.             'preprocess_html',
  26.             'remove_header',
  27.             'header_regex',
  28.             'remove_footer',
  29.             'footer_regex'])
  30.         self.db = db
  31.         self.book_id = book_id
  32.         for x in ('pagebreak', 'rule', 'both', 'none'):
  33.             self.opt_chapter_mark.addItem(x)
  34.         
  35.         self.initialize_options(get_option, get_help, db, book_id)
  36.         self.opt_chapter.set_msg(_('Detect chapters at (XPath expression):'))
  37.         self.opt_page_breaks_before.set_msg(_('Insert page breaks before (XPath expression):'))
  38.         self.opt_header_regex.set_msg(_('Header regular expression:'))
  39.         self.opt_header_regex.set_book_id(book_id)
  40.         self.opt_header_regex.set_db(db)
  41.         self.opt_footer_regex.set_msg(_('Footer regular expression:'))
  42.         self.opt_footer_regex.set_book_id(book_id)
  43.         self.opt_footer_regex.set_db(db)
  44.  
  45.     
  46.     def break_cycles(self):
  47.         Widget.break_cycles(self)
  48.         self.opt_header_regex.break_cycles()
  49.         self.opt_footer_regex.break_cycles()
  50.  
  51.     
  52.     def pre_commit_check(self):
  53.         for x in ('header_regex', 'footer_regex'):
  54.             x = getattr(self, 'opt_' + x)
  55.             
  56.             try:
  57.                 pat = unicode(x.regex)
  58.                 re.compile(pat)
  59.             continue
  60.             except Exception:
  61.                 err = None
  62.                 error_dialog(self, _('Invalid regular expression'), _('Invalid regular expression: %s') % err).exec_()
  63.                 return False
  64.             
  65.  
  66.         
  67.         for x in ('chapter', 'page_breaks_before'):
  68.             x = getattr(self, 'opt_' + x)
  69.             if not x.check():
  70.                 error_dialog(self, _('Invalid XPath'), _('The XPath expression %s is invalid.') % x.text).exec_()
  71.                 return False
  72.         
  73.         return True
  74.  
  75.  
  76.