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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __all__ = ('compileUi', 'loadUiType', 'loadUi')
  5. from PyQt4.uic.Compiler import indenter, compiler
  6. _header = "# -*- coding: utf-8 -*-\n\n# Form implementation generated from reading ui file '%s'\n#\n# Created: %s\n#      by: PyQt4 UI code generator %s\n#\n# WARNING! All changes made in this file will be lost!\n\n"
  7. _pyqt3_wrapper_code = '\nclass %(widgetname)s(QtGui.%(baseclass)s, %(uiclass)s):\n\tdef __init__(self, parent=None, f=QtCore.Qt.WindowFlags()):\n\t\tQtGui.%(baseclass)s.__init__(self, parent, f)\n\n\t\tself.setupUi(self)\n'
  8. _display_code = '\nif __name__ == "__main__":\n\timport sys\n\tapp = QtGui.QApplication(sys.argv)\n\t%(widgetname)s = QtGui.%(baseclass)s()\n\tui = %(uiclass)s()\n\tui.setupUi(%(widgetname)s)\n\t%(widgetname)s.show()\n\tsys.exit(app.exec_())\n'
  9.  
  10. def compileUiDir(dir, recurse = False, map = None, **compileUi_args):
  11.     import os
  12.     
  13.     def compile_ui(ui_dir, ui_file):
  14.         if ui_file.endswith('.ui'):
  15.             py_dir = ui_dir
  16.             py_file = ui_file[:-3] + '.py'
  17.             if map is not None:
  18.                 (py_dir, py_file) = map(py_dir, py_file)
  19.             
  20.             
  21.             try:
  22.                 os.makedirs(py_dir)
  23.             except:
  24.                 pass
  25.  
  26.             ui_path = os.path.join(ui_dir, ui_file)
  27.             py_path = os.path.join(py_dir, py_file)
  28.             ui_file = open(ui_path, 'r')
  29.             py_file = open(py_path, 'w')
  30.             
  31.             try:
  32.                 compileUi(ui_file, py_file, **compileUi_args)
  33.             finally:
  34.                 ui_file.close()
  35.                 py_file.close()
  36.  
  37.         
  38.  
  39.     if recurse:
  40.         for root, _, files in os.walk(dir):
  41.             for ui in files:
  42.                 compile_ui(root, ui)
  43.             
  44.         
  45.     else:
  46.         for ui in os.listdir(dir):
  47.             if os.path.isfile(os.path.join(dir, ui)):
  48.                 compile_ui(dir, ui)
  49.                 continue
  50.         
  51.  
  52.  
  53. def compileUi(uifile, pyfile, execute = False, indent = 4, pyqt3_wrapper = False):
  54.     ctime = ctime
  55.     import time
  56.     PYQT_VERSION_STR = PYQT_VERSION_STR
  57.     import PyQt4.QtCore
  58.     
  59.     try:
  60.         uifname = uifile.name
  61.     except AttributeError:
  62.         uifname = uifile
  63.  
  64.     indenter.indentwidth = indent
  65.     pyfile.write(_header % (uifname, ctime(), PYQT_VERSION_STR))
  66.     winfo = compiler.UICompiler().compileUi(uifile, pyfile)
  67.     if pyqt3_wrapper:
  68.         indenter.write_code(_pyqt3_wrapper_code % winfo)
  69.     
  70.     if execute:
  71.         indenter.write_code(_display_code % winfo)
  72.     
  73.  
  74.  
  75. def loadUiType(uifile):
  76.     import sys
  77.     QtGui = QtGui
  78.     import PyQt4
  79.     if sys.hexversion >= 50331648:
  80.         StringIO = StringIO
  81.         import PyQt4.uic.port_v3.string_io
  82.     else:
  83.         StringIO = StringIO
  84.         import PyQt4.uic.port_v2.string_io
  85.     code_string = StringIO()
  86.     winfo = compiler.UICompiler().compileUi(uifile, code_string)
  87.     ui_globals = { }
  88.     exec (code_string.getvalue(), ui_globals)
  89.     return (ui_globals[winfo['uiclass']], getattr(QtGui, winfo['baseclass']))
  90.  
  91.  
  92. def loadUi(uifile, baseinstance = None):
  93.     DynamicUILoader = DynamicUILoader
  94.     import PyQt4.uic.Loader.loader
  95.     return DynamicUILoader().loadUi(uifile, baseinstance)
  96.  
  97. from PyQt4.uic.objcreator import widgetPluginPath
  98.