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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import re
  6. from PyQt4.uic.Compiler.indenter import write_code
  7. from PyQt4.uic.Compiler.misc import Literal, moduleMember
  8. if sys.hexversion >= 50331648:
  9.     from PyQt4.uic.port_v3.proxy_base import ProxyBase
  10.     from PyQt4.uic.port_v3.encode_utf8 import encode_utf8
  11. else:
  12.     from PyQt4.uic.port_v2.proxy_base import ProxyBase
  13.     from PyQt4.uic.port_v2.encode_utf8 import encode_utf8
  14. i18n_strings = []
  15. i18n_context = ''
  16.  
  17. def i18n_print(string):
  18.     i18n_strings.append(string)
  19.  
  20.  
  21. def obj_to_argument(obj):
  22.     if isinstance(obj, str):
  23.         arg = '"' + escape(obj) + '"'
  24.     else:
  25.         arg = str(obj)
  26.     return arg
  27.  
  28.  
  29. def i18n_void_func(name):
  30.     
  31.     def _printer(self, *args):
  32.         i18n_print('%s.%s(%s)' % (self, name, ', '.join(map(obj_to_argument, args))))
  33.  
  34.     return _printer
  35.  
  36.  
  37. def i18n_func(name):
  38.     
  39.     def _printer(self, rname, *args):
  40.         i18n_print('%s = %s.%s(%s)' % (rname, self, name, ', '.join(map(obj_to_argument, args))))
  41.         return Literal(rname)
  42.  
  43.     return _printer
  44.  
  45.  
  46. def strict_getattr(module, clsname):
  47.     cls = getattr(module, clsname)
  48.     if issubclass(cls, LiteralProxyClass):
  49.         raise AttributeError(cls)
  50.     issubclass(cls, LiteralProxyClass)
  51.     return cls
  52.  
  53. _esc_regex = re.compile('(\\"|\\\'|\\\\)')
  54.  
  55. def escape(text):
  56.     x = _esc_regex.sub('\\\\\\1', text)
  57.     return re.sub('\\n', '\\\\n"\\n"', x)
  58.  
  59.  
  60. class i18n_string(object):
  61.     
  62.     def __init__(self, string):
  63.         self.string = string
  64.  
  65.     
  66.     def __str__(self):
  67.         return 'QtGui.QApplication.translate("%s", "%s", None, QtGui.QApplication.UnicodeUTF8)' % (i18n_context, escape(encode_utf8(self.string)))
  68.  
  69.  
  70. AS_ARGUMENT = 2
  71.  
  72. class ProxyClassMember(object):
  73.     
  74.     def __init__(self, proxy, function_name, flags):
  75.         self.proxy = proxy
  76.         self.function_name = function_name
  77.         self.flags = flags
  78.  
  79.     
  80.     def __str__(self):
  81.         return '%s.%s' % (self.proxy, self.function_name)
  82.  
  83.     
  84.     def __call__(self, *args):
  85.         func_call = '%s.%s(%s)' % (self.proxy, self.function_name, ', '.join(map(obj_to_argument, args)))
  86.         if self.flags & AS_ARGUMENT:
  87.             self.proxy._uic_name = func_call
  88.             return self.proxy
  89.         needs_translation = False
  90.         for arg in args:
  91.             if isinstance(arg, i18n_string):
  92.                 needs_translation = True
  93.                 continue
  94.             self.flags & AS_ARGUMENT
  95.         
  96.         if needs_translation:
  97.             i18n_print(func_call)
  98.         else:
  99.             write_code(func_call)
  100.  
  101.  
  102.  
  103. class ProxyClass(ProxyBase):
  104.     flags = 0
  105.     
  106.     def __init__(self, objectname, is_attribute, args = (), noInstantiation = False):
  107.         if objectname:
  108.             if is_attribute:
  109.                 objectname = 'self.' + objectname
  110.             
  111.             self._uic_name = objectname
  112.         else:
  113.             self._uic_name = 'Unnamed'
  114.         if not noInstantiation:
  115.             funcall = '%s(%s)' % (moduleMember(self.module, self.__class__.__name__), ', '.join(map(str, args)))
  116.             if objectname:
  117.                 funcall = '%s = %s' % (objectname, funcall)
  118.             
  119.             write_code(funcall)
  120.         
  121.  
  122.     
  123.     def __str__(self):
  124.         return self._uic_name
  125.  
  126.     
  127.     def __getattribute__(self, attribute):
  128.         
  129.         try:
  130.             return object.__getattribute__(self, attribute)
  131.         except AttributeError:
  132.             return ProxyClassMember(self, attribute, self.flags)
  133.  
  134.  
  135.  
  136.  
  137. class LiteralProxyClass(ProxyClass):
  138.     flags = AS_ARGUMENT
  139.     
  140.     def __init__(self, *args):
  141.         self._uic_name = '%s(%s)' % (moduleMember(self.module, self.__class__.__name__), ', '.join(map(obj_to_argument, args)))
  142.  
  143.  
  144.  
  145. class ProxyNamespace(ProxyBase):
  146.     pass
  147.  
  148.  
  149. class QtCore(ProxyNamespace):
  150.     
  151.     class Qt(ProxyNamespace):
  152.         pass
  153.  
  154.     
  155.     class QMetaObject(ProxyClass):
  156.         
  157.         def connectSlotsByName(cls, *args):
  158.             ProxyClassMember(cls, 'connectSlotsByName', 0)(*args)
  159.  
  160.         connectSlotsByName = classmethod(connectSlotsByName)
  161.  
  162.     
  163.     class QObject(ProxyClass):
  164.         
  165.         def metaObject(self):
  166.             
  167.             class _FakeMetaObject((object,)):
  168.                 
  169.                 def className(*args):
  170.                     return self.__class__.__name__
  171.  
  172.  
  173.             return _FakeMetaObject()
  174.  
  175.         
  176.         def objectName(self):
  177.             return self._uic_name.split('.')[-1]
  178.  
  179.         
  180.         def connect(cls, *args):
  181.             slot_name = str(args[-1])
  182.             if slot_name.endswith('.raise'):
  183.                 args = list(args[:-1])
  184.                 args.append(Literal(slot_name + '_'))
  185.             
  186.             ProxyClassMember(cls, 'connect', 0)(*args)
  187.  
  188.         connect = classmethod(connect)
  189.  
  190.  
  191. _qwidgets = ('QAbstractItemView', 'QCalendarWidget', 'QColumnView', 'QCommandLinkButton', 'QDateEdit', 'QDateTimeEdit', 'QDial', 'QDialog', 'QDialogButtonBox', 'QDockWidget', 'QDoubleSpinBox', 'QFrame', 'QGraphicsView', 'QGroupBox', 'QLabel', 'QLCDNumber', 'QLineEdit', 'QListView', 'QMainWindow', 'QMdiArea', 'QMenuBar', 'QPlainTextEdit', 'QProgressBar', 'QScrollArea', 'QScrollBar', 'QSlider', 'QSpinBox', 'QSplitter', 'QStackedWidget', 'QStatusBar', 'QTextBrowser', 'QTextEdit', 'QTimeEdit', 'QToolBar', 'QWizard', 'QWizardPage')
  192.  
  193. class QtGui(ProxyNamespace):
  194.     
  195.     class QApplication(QtCore.QObject):
  196.         
  197.         def translate(uiname, text, context, encoding):
  198.             if not text:
  199.                 pass
  200.             return i18n_string('')
  201.  
  202.         translate = staticmethod(translate)
  203.  
  204.     
  205.     class QIcon(ProxyClass):
  206.         pass
  207.  
  208.     
  209.     class QConicalGradient(ProxyClass):
  210.         pass
  211.  
  212.     
  213.     class QLinearGradient(ProxyClass):
  214.         pass
  215.  
  216.     
  217.     class QRadialGradient(ProxyClass):
  218.         pass
  219.  
  220.     
  221.     class QBrush(ProxyClass):
  222.         pass
  223.  
  224.     
  225.     class QPalette(ProxyClass):
  226.         pass
  227.  
  228.     
  229.     class QFont(ProxyClass):
  230.         pass
  231.  
  232.     
  233.     class QSpacerItem(ProxyClass):
  234.         pass
  235.  
  236.     
  237.     class QSizePolicy(ProxyClass):
  238.         pass
  239.  
  240.     
  241.     class QAction(QtCore.QObject):
  242.         pass
  243.  
  244.     
  245.     class QActionGroup(QtCore.QObject):
  246.         pass
  247.  
  248.     
  249.     class QButtonGroup(QtCore.QObject):
  250.         pass
  251.  
  252.     
  253.     class QLayout(QtCore.QObject):
  254.         pass
  255.  
  256.     
  257.     class QGridLayout(QLayout):
  258.         pass
  259.  
  260.     
  261.     class QBoxLayout(QLayout):
  262.         pass
  263.  
  264.     
  265.     class QHBoxLayout(QBoxLayout):
  266.         pass
  267.  
  268.     
  269.     class QVBoxLayout(QBoxLayout):
  270.         pass
  271.  
  272.     
  273.     class QFormLayout(QLayout):
  274.         pass
  275.  
  276.     
  277.     class QWidget(QtCore.QObject):
  278.         
  279.         def font(self):
  280.             return Literal('%s.font()' % self)
  281.  
  282.         
  283.         def minimumSizeHint(self):
  284.             return Literal('%s.minimumSizeHint()' % self)
  285.  
  286.         
  287.         def sizePolicy(self):
  288.             sp = LiteralProxyClass()
  289.             sp._uic_name = '%s.sizePolicy()' % self
  290.             return sp
  291.  
  292.  
  293.     
  294.     class QHeaderView(ProxyClass):
  295.         pass
  296.  
  297.     
  298.     class QListWidgetItem(ProxyClass):
  299.         pass
  300.  
  301.     
  302.     class QListWidget(QWidget):
  303.         isSortingEnabled = i18n_func('isSortingEnabled')
  304.         setSortingEnabled = i18n_void_func('setSortingEnabled')
  305.         
  306.         def item(self, row):
  307.             return QtGui.QListWidgetItem('%s.item(%i)' % (self, row), False, (), noInstantiation = True)
  308.  
  309.  
  310.     
  311.     class QTreeView(QWidget):
  312.         
  313.         def header(self):
  314.             return QtGui.QHeaderView('%s.header()' % self, False, (), noInstantiation = True)
  315.  
  316.  
  317.     
  318.     class QTreeWidgetItem(ProxyClass):
  319.         
  320.         def child(self, index):
  321.             return QtGui.QTreeWidgetItem('%s.child(%i)' % (self, index), False, (), noInstantiation = True)
  322.  
  323.  
  324.     
  325.     class QTreeWidget(QTreeView):
  326.         isSortingEnabled = i18n_func('isSortingEnabled')
  327.         setSortingEnabled = i18n_void_func('setSortingEnabled')
  328.         
  329.         def headerItem(self):
  330.             return QtGui.QWidget('%s.headerItem()' % self, False, (), noInstantiation = True)
  331.  
  332.         
  333.         def topLevelItem(self, index):
  334.             return QtGui.QTreeWidgetItem('%s.topLevelItem(%i)' % (self, index), False, (), noInstantiation = True)
  335.  
  336.  
  337.     
  338.     class QTableView(QWidget):
  339.         
  340.         def horizontalHeader(self):
  341.             return QtGui.QHeaderView('%s.horizontalHeader()' % self, False, (), noInstantiation = True)
  342.  
  343.         
  344.         def verticalHeader(self):
  345.             return QtGui.QHeaderView('%s.verticalHeader()' % self, False, (), noInstantiation = True)
  346.  
  347.  
  348.     
  349.     class QTableWidgetItem(ProxyClass):
  350.         pass
  351.  
  352.     
  353.     class QTableWidget(QTableView):
  354.         isSortingEnabled = i18n_func('isSortingEnabled')
  355.         setSortingEnabled = i18n_void_func('setSortingEnabled')
  356.         
  357.         def item(self, row, col):
  358.             return QtGui.QTableWidgetItem('%s.item(%i, %i)' % (self, row, col), False, (), noInstantiation = True)
  359.  
  360.         
  361.         def horizontalHeaderItem(self, col):
  362.             return QtGui.QTableWidgetItem('%s.horizontalHeaderItem(%i)' % (self, col), False, (), noInstantiation = True)
  363.  
  364.         
  365.         def verticalHeaderItem(self, row):
  366.             return QtGui.QTableWidgetItem('%s.verticalHeaderItem(%i)' % (self, row), False, (), noInstantiation = True)
  367.  
  368.  
  369.     
  370.     class QMenu(QWidget):
  371.         
  372.         def menuAction(self):
  373.             return Literal('%s.menuAction()' % self)
  374.  
  375.  
  376.     
  377.     class QTabWidget(QWidget):
  378.         
  379.         def addTab(self, *args):
  380.             i18n_print('%s.setTabText(%s.indexOf(%s), %s)' % (self._uic_name, self._uic_name, args[0], args[-1]))
  381.             pargs = args[:-1] + ('',)
  382.             ProxyClassMember(self, 'addTab', 0)(*pargs)
  383.  
  384.         
  385.         def indexOf(self, page):
  386.             return Literal('%s.indexOf(%s)' % (self, page))
  387.  
  388.  
  389.     
  390.     class QToolBox(QWidget):
  391.         
  392.         def addItem(self, *args):
  393.             i18n_print('%s.setItemText(%s.indexOf(%s), %s)' % (self._uic_name, self._uic_name, args[0], args[-1]))
  394.             pargs = args[:-1] + ('',)
  395.             ProxyClassMember(self, 'addItem', 0)(*pargs)
  396.  
  397.         
  398.         def indexOf(self, page):
  399.             return Literal('%s.indexOf(%s)' % (self, page))
  400.  
  401.  
  402.     
  403.     class QComboBox(QWidget):
  404.         pass
  405.  
  406.     
  407.     class QFontComboBox(QComboBox):
  408.         pass
  409.  
  410.     
  411.     class QAbstractButton(QWidget):
  412.         pass
  413.  
  414.     
  415.     class QCheckBox(QAbstractButton):
  416.         pass
  417.  
  418.     
  419.     class QPushButton(QAbstractButton):
  420.         pass
  421.  
  422.     
  423.     class QRadioButton(QAbstractButton):
  424.         pass
  425.  
  426.     
  427.     class QToolButton(QAbstractButton):
  428.         pass
  429.  
  430.     for _class in _qwidgets:
  431.         if _class not in locals():
  432.             locals()[_class] = type(_class, (QWidget,), { })
  433.             continue
  434.     
  435.  
  436.