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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import logging
  6. from PyQt4.uic import compileUi, loadUi
  7.  
  8. class Driver(object):
  9.     LOGGER_NAME = 'PyQt4.uic'
  10.     
  11.     def __init__(self, opts, ui_file):
  12.         if opts.debug:
  13.             logger = logging.getLogger(self.LOGGER_NAME)
  14.             handler = logging.StreamHandler()
  15.             handler.setFormatter(logging.Formatter('%(name)s: %(message)s'))
  16.             logger.addHandler(handler)
  17.             logger.setLevel(logging.DEBUG)
  18.         
  19.         self._opts = opts
  20.         self._ui_file = ui_file
  21.  
  22.     
  23.     def invoke(self):
  24.         if self._opts.preview:
  25.             return self._preview()
  26.         self._generate()
  27.         return 0
  28.  
  29.     
  30.     def _preview(self):
  31.         QtGui = QtGui
  32.         import PyQt4
  33.         app = QtGui.QApplication([
  34.             self._ui_file])
  35.         widget = loadUi(self._ui_file)
  36.         widget.show()
  37.         return app.exec_()
  38.  
  39.     
  40.     def _generate(self):
  41.         if self._opts.output == '-':
  42.             pyfile = sys.stdout
  43.         else:
  44.             pyfile = open(self._opts.output, 'wt')
  45.         compileUi(self._ui_file, pyfile, self._opts.execute, self._opts.indent, self._opts.pyqt3_wrapper)
  46.  
  47.     
  48.     def on_IOError(self, e):
  49.         sys.stderr.write('Error: %s: "%s"\n' % (e.strerror, e.filename))
  50.  
  51.     
  52.     def on_SyntaxError(self, e):
  53.         sys.stderr.write('Error in input file: %s\n' % e)
  54.  
  55.     
  56.     def on_NoSuchWidgetError(self, e):
  57.         if e.args[0].startswith('Q3'):
  58.             sys.stderr.write('Error: Q3Support widgets are not supported by PyQt4.\n')
  59.         else:
  60.             sys.stderr.write(str(e) + '\n')
  61.  
  62.     
  63.     def on_Exception(self, e):
  64.         if logging.getLogger(self.LOGGER_NAME).level == logging.DEBUG:
  65.             import traceback
  66.             traceback.print_exception(*sys.exc_info())
  67.         else:
  68.             QtCore = QtCore
  69.             import PyQt4
  70.             sys.stderr.write('An unexpected error occurred.\nCheck that you are using the latest version of PyQt and send an error report to\nsupport@riverbankcomputing.com, including the following information:\n\n  * your version of PyQt (%s)\n  * the UI file that caused this error\n  * the debug output of pyuic4 (use the -d flag when calling pyuic4)\n' % QtCore.PYQT_VERSION_STR)
  71.  
  72.  
  73.