home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_1292 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  2.7 KB  |  71 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
  6. import re
  7. from PyQt4.QtGui import QDialog
  8. from calibre.gui2.dialogs.search_ui import Ui_Dialog
  9. from calibre.library.caches import CONTAINS_MATCH, EQUALS_MATCH
  10.  
  11. class SearchDialog(QDialog, Ui_Dialog):
  12.     
  13.     def __init__(self, *args):
  14.         QDialog.__init__(self, *args)
  15.         self.setupUi(self)
  16.         self.mc = ''
  17.  
  18.     
  19.     def tokens(self, raw):
  20.         phrases = re.findall('\\s*".*?"\\s*', raw)
  21.         for f in phrases:
  22.             raw = raw.replace(f, ' ')
  23.         
  24.         phrases = [ t.strip('" ') for t in phrases ]
  25.         return [ '"' + self.mc + t + '"' for t in [] + [ r.strip() for r in raw.split() ] ]
  26.  
  27.     
  28.     def search_string(self):
  29.         mk = self.matchkind.currentIndex()
  30.         if mk == CONTAINS_MATCH:
  31.             self.mc = ''
  32.         elif mk == EQUALS_MATCH:
  33.             self.mc = '='
  34.         else:
  35.             self.mc = '~'
  36.         (all, any, phrase, none) = map((lambda x: unicode(x.text())), (self.all, self.any, self.phrase, self.none))
  37.         (all, any, none) = map(self.tokens, (all, any, none))
  38.         phrase = phrase.strip()
  39.         all = ' and '.join(all)
  40.         any = ' or '.join(any)
  41.         none = ' and not '.join(none)
  42.         ans = ''
  43.         if phrase:
  44.             ans += '"%s"' % phrase
  45.         
  46.         if all:
  47.             None += ans if ans else '' + all
  48.         
  49.         if none:
  50.             None += ans if ans else 'not ' + none
  51.         
  52.         if any:
  53.             None += ans if ans else '' + any
  54.         
  55.         return ans
  56.  
  57.     
  58.     def token(self):
  59.         txt = unicode(self.text.text()).strip()
  60.         if txt:
  61.             if self.negate.isChecked():
  62.                 txt = '!' + txt
  63.             
  64.             tok = self.FIELDS[unicode(self.field.currentText())] + txt
  65.             if re.search('\\s', tok):
  66.                 tok = '"%s"' % tok
  67.             
  68.             return tok
  69.  
  70.  
  71.