home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1214 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.9 KB  |  127 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. from PyQt4.Qt import QDialog, QWidget, SIGNAL, Qt, QDialogButtonBox, QVBoxLayout
  9. from calibre.gui2.convert.xpath_wizard_ui import Ui_Form
  10. from calibre.gui2.convert.xexp_edit_ui import Ui_Form as Ui_Edit
  11.  
  12. class WizardWidget(QWidget, Ui_Form):
  13.     
  14.     def __init__(self, parent = None):
  15.         QWidget.__init__(self, parent)
  16.         self.setupUi(self)
  17.  
  18.     
  19.     def xpath(self):
  20.         tag = unicode(self.tag.currentText()).strip()
  21.         if tag != '*':
  22.             tag = 'h:' + tag
  23.         
  24.         (attr, val) = map(unicode, (self.attribute.text(), self.value.text()))
  25.         attr = attr.strip()
  26.         val = val.strip()
  27.         q = ''
  28.         if attr:
  29.             if val:
  30.                 q = '[re:test(@%s, "%s", "i")]' % (attr, val)
  31.             else:
  32.                 q = '[@%s]' % attr
  33.         elif val:
  34.             q = '[re:test(., "%s", "i")]' % val
  35.         
  36.         expr = '//' + tag + q
  37.         return expr
  38.  
  39.     xpath = property(xpath)
  40.  
  41.  
  42. class Wizard(QDialog):
  43.     
  44.     def __init__(self, parent = None):
  45.         QDialog.__init__(self, parent)
  46.         self.resize(440, 480)
  47.         self.verticalLayout = QVBoxLayout(self)
  48.         self.widget = WizardWidget(self)
  49.         self.verticalLayout.addWidget(self.widget)
  50.         self.buttonBox = QDialogButtonBox(self)
  51.         self.buttonBox.setOrientation(Qt.Horizontal)
  52.         self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok)
  53.         self.verticalLayout.addWidget(self.buttonBox)
  54.         self.connect(self.buttonBox, SIGNAL('accepted()'), self.accept)
  55.         self.connect(self.buttonBox, SIGNAL('rejected()'), self.reject)
  56.         self.setModal(Qt.WindowModal)
  57.  
  58.     
  59.     def xpath(self):
  60.         return self.widget.xpath
  61.  
  62.     xpath = property(xpath)
  63.  
  64.  
  65. class XPathEdit(QWidget, Ui_Edit):
  66.     
  67.     def __init__(self, parent = None):
  68.         QWidget.__init__(self, parent)
  69.         self.setupUi(self)
  70.         self.connect(self.button, SIGNAL('clicked()'), self.wizard)
  71.  
  72.     
  73.     def wizard(self):
  74.         wiz = Wizard(self)
  75.         if wiz.exec_() == wiz.Accepted:
  76.             self.edit.setText(wiz.xpath)
  77.         
  78.  
  79.     
  80.     def setObjectName(self, *args):
  81.         QWidget.setObjectName(self, *args)
  82.         if hasattr(self, 'edit'):
  83.             self.edit.initialize('xpath_edit_' + unicode(self.objectName()))
  84.         
  85.  
  86.     
  87.     def set_msg(self, msg):
  88.         self.msg.setText(msg)
  89.  
  90.     
  91.     def text(self):
  92.         return unicode(self.edit.text())
  93.  
  94.     text = property(text)
  95.     
  96.     def xpath(self):
  97.         return self.text
  98.  
  99.     xpath = property(xpath)
  100.     
  101.     def check(self):
  102.         XPNSMAP = XPNSMAP
  103.         import calibre.ebooks.oeb.base
  104.         XPath = XPath
  105.         import lxml.etree
  106.         
  107.         try:
  108.             if self.text.strip():
  109.                 XPath(self.text, namespaces = XPNSMAP)
  110.         except:
  111.             import traceback
  112.             traceback.print_exc()
  113.             return False
  114.  
  115.         return True
  116.  
  117.  
  118. if __name__ == '__main__':
  119.     from PyQt4.Qt import QApplication
  120.     app = QApplication([])
  121.     w = XPathEdit()
  122.     w.setObjectName('test')
  123.     w.show()
  124.     app.exec_()
  125.     print w.xpath
  126.  
  127.