home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / python2.5 / site-packages / unohelper.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-04-29  |  12.0 KB  |  316 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. import uno
  5. import pyuno
  6. import os
  7. import sys
  8. from com.sun.star.lang import XTypeProvider, XSingleComponentFactory, XServiceInfo
  9. from com.sun.star.uno import RuntimeException, XCurrentContext
  10. from com.sun.star.beans.MethodConcept import ALL as METHOD_CONCEPT_ALL
  11. from com.sun.star.beans.PropertyConcept import ALL as PROPERTY_CONCEPT_ALL
  12. from com.sun.star.reflection.ParamMode import IN as PARAM_MODE_IN, OUT as PARAM_MODE_OUT, INOUT as PARAM_MODE_INOUT
  13. from com.sun.star.beans.PropertyAttribute import MAYBEVOID as PROP_ATTR_MAYBEVOID, BOUND as PROP_ATTR_BOUND, CONSTRAINED as PROP_ATTR_CONSTRAINED, TRANSIENT as PROP_ATTR_TRANSIENT, READONLY as PROP_ATTR_READONLY, MAYBEAMBIGUOUS as PROP_ATTR_MAYBEAMBIGUOUS, MAYBEDEFAULT as PROP_ATTR_MAYBEDEFAULT, REMOVEABLE as PROP_ATTR_REMOVEABLE
  14.  
  15. def _mode_to_str(mode):
  16.     ret = '[]'
  17.     if mode == PARAM_MODE_INOUT:
  18.         ret = '[inout]'
  19.     elif mode == PARAM_MODE_OUT:
  20.         ret = '[out]'
  21.     elif mode == PARAM_MODE_IN:
  22.         ret = '[in]'
  23.     
  24.     return ret
  25.  
  26.  
  27. def _propertymode_to_str(mode):
  28.     ret = ''
  29.     if PROP_ATTR_REMOVEABLE & mode:
  30.         ret = ret + 'removeable '
  31.     
  32.     if PROP_ATTR_MAYBEDEFAULT & mode:
  33.         ret = ret + 'maybedefault '
  34.     
  35.     if PROP_ATTR_MAYBEAMBIGUOUS & mode:
  36.         ret = ret + 'maybeambigous '
  37.     
  38.     if PROP_ATTR_READONLY & mode:
  39.         ret = ret + 'readonly '
  40.     
  41.     if PROP_ATTR_TRANSIENT & mode:
  42.         ret = ret + 'tranient '
  43.     
  44.     if PROP_ATTR_CONSTRAINED & mode:
  45.         ret = ret + 'constrained '
  46.     
  47.     if PROP_ATTR_BOUND & mode:
  48.         ret = ret + 'bound '
  49.     
  50.     if PROP_ATTR_MAYBEVOID & mode:
  51.         ret = ret + 'maybevoid '
  52.     
  53.     return ret.rstrip()
  54.  
  55.  
  56. def inspect(obj, out):
  57.     ctx = uno.getComponentContext()
  58.     introspection = ctx.ServiceManager.createInstanceWithContext('com.sun.star.beans.Introspection', ctx)
  59.     out.write('Supported services:\n')
  60.     if hasattr(obj, 'getSupportedServiceNames'):
  61.         names = obj.getSupportedServiceNames()
  62.         for ii in names:
  63.             out.write('  ' + ii + '\n')
  64.         
  65.     else:
  66.         out.write('  unknown\n')
  67.     out.write('Interfaces:\n')
  68.     if hasattr(obj, 'getTypes'):
  69.         interfaces = obj.getTypes()
  70.         for ii in interfaces:
  71.             out.write('  ' + ii.typeName + '\n')
  72.         
  73.     else:
  74.         out.write('  unknown\n')
  75.     access = introspection.inspect(obj)
  76.     methods = access.getMethods(METHOD_CONCEPT_ALL)
  77.     out.write('Methods:\n')
  78.     for ii in methods:
  79.         out.write('  ' + ii.ReturnType.Name + ' ' + ii.Name)
  80.         args = ii.ParameterTypes
  81.         infos = ii.ParameterInfos
  82.         out.write('( ')
  83.         for i in range(0, len(args)):
  84.             if i > 0:
  85.                 out.write(', ')
  86.             
  87.             out.write(_mode_to_str(infos[i].aMode) + ' ' + args[i].Name + ' ' + infos[i].aName)
  88.         
  89.         out.write(' )\n')
  90.     
  91.     props = access.getProperties(PROPERTY_CONCEPT_ALL)
  92.     out.write('Properties:\n')
  93.     for ii in props:
  94.         out.write('  (' + _propertymode_to_str(ii.Attributes) + ') ' + ii.Type.typeName + ' ' + ii.Name + '\n')
  95.     
  96.  
  97.  
  98. def createSingleServiceFactory(clazz, implementationName, serviceNames):
  99.     return _FactoryHelper_(clazz, implementationName, serviceNames)
  100.  
  101.  
  102. class _ImplementationHelperEntry:
  103.     
  104.     def __init__(self, ctor, serviceNames):
  105.         self.ctor = ctor
  106.         self.serviceNames = serviceNames
  107.  
  108.  
  109.  
  110. class ImplementationHelper:
  111.     
  112.     def __init__(self):
  113.         self.impls = { }
  114.  
  115.     
  116.     def addImplementation(self, ctor, implementationName, serviceNames):
  117.         self.impls[implementationName] = _ImplementationHelperEntry(ctor, serviceNames)
  118.  
  119.     
  120.     def writeRegistryInfo(self, regKey, smgr):
  121.         for i in self.impls.items():
  122.             keyName = '/' + i[0] + '/UNO/SERVICES'
  123.             key = regKey.createKey(keyName)
  124.             for serviceName in i[1].serviceNames:
  125.                 key.createKey(serviceName)
  126.             
  127.         
  128.         return 1
  129.  
  130.     
  131.     def getComponentFactory(self, implementationName, regKey, smgr):
  132.         entry = self.impls.get(implementationName, None)
  133.         if entry == None:
  134.             raise RuntimeException(implementationName + ' is unknown', None)
  135.         
  136.         return createSingleServiceFactory(entry.ctor, implementationName, entry.serviceNames)
  137.  
  138.     
  139.     def getSupportedServiceNames(self, implementationName):
  140.         entry = self.impls.get(implementationName, None)
  141.         if entry == None:
  142.             raise RuntimeException(implementationName + ' is unknown', None)
  143.         
  144.         return entry.serviceNames
  145.  
  146.     
  147.     def supportsService(self, implementationName, serviceName):
  148.         entry = self.impls.get(implementationName, None)
  149.         if entry == None:
  150.             raise RuntimeException(implementationName + ' is unknown', None)
  151.         
  152.         return serviceName in entry.serviceNames
  153.  
  154.  
  155.  
  156. class ImplementationEntry:
  157.     
  158.     def __init__(self, implName, supportedServices, clazz):
  159.         self.implName = implName
  160.         self.supportedServices = supportedServices
  161.         self.clazz = clazz
  162.  
  163.  
  164.  
  165. def writeRegistryInfoHelper(smgr, regKey, seqEntries):
  166.     for entry in seqEntries:
  167.         keyName = '/' + entry.implName + '/UNO/SERVICES'
  168.         key = regKey.createKey(keyName)
  169.         for serviceName in entry.supportedServices:
  170.             key.createKey(serviceName)
  171.         
  172.     
  173.  
  174.  
  175. def systemPathToFileUrl(systemPath):
  176.     '''returns a file-url for the given system path'''
  177.     return pyuno.systemPathToFileUrl(systemPath)
  178.  
  179.  
  180. def fileUrlToSystemPath(url):
  181.     '''returns a system path (determined by the system, the python interpreter is running on)'''
  182.     return pyuno.fileUrlToSystemPath(url)
  183.  
  184.  
  185. def absolutize(path, relativeUrl):
  186.     '''returns an absolute file url from the given urls'''
  187.     return pyuno.absolutize(path, relativeUrl)
  188.  
  189.  
  190. def getComponentFactoryHelper(implementationName, smgr, regKey, seqEntries):
  191.     for x in seqEntries:
  192.         if x.implName == implementationName:
  193.             return createSingleServiceFactory(x.clazz, implementationName, x.supportedServices)
  194.             continue
  195.     
  196.  
  197.  
  198. def addComponentsToContext(toBeExtendedContext, contextRuntime, componentUrls, loaderName):
  199.     smgr = contextRuntime.ServiceManager
  200.     loader = smgr.createInstanceWithContext(loaderName, contextRuntime)
  201.     implReg = smgr.createInstanceWithContext('com.sun.star.registry.ImplementationRegistration', contextRuntime)
  202.     if not os.name == 'nt':
  203.         pass
  204.     isWin = os.name == 'dos'
  205.     isMac = sys.platform == 'darwin'
  206.     for componentUrl in componentUrls:
  207.         reg = smgr.createInstanceWithContext('com.sun.star.registry.SimpleRegistry', contextRuntime)
  208.         reg.open('', 0, 1)
  209.         if not isWin and componentUrl.endswith('.uno'):
  210.             if isMac:
  211.                 componentUrl = componentUrl + '.dylib'
  212.             else:
  213.                 componentUrl = componentUrl + '.so'
  214.         
  215.         implReg.registerImplementation(loaderName, componentUrl, reg)
  216.         rootKey = reg.getRootKey()
  217.         implementationKey = rootKey.openKey('IMPLEMENTATIONS')
  218.         implNames = implementationKey.getKeyNames()
  219.         extSMGR = toBeExtendedContext.ServiceManager
  220.         for x in implNames:
  221.             fac = loader.activate(max(x.split('/')), '', componentUrl, rootKey)
  222.             extSMGR.insert(fac)
  223.         
  224.         reg.close()
  225.     
  226.  
  227. _g_typeTable = { }
  228.  
  229. def _unohelper_getHandle(self):
  230.     ret = None
  231.     if _g_typeTable.has_key(self.__class__):
  232.         ret = _g_typeTable[self.__class__]
  233.     else:
  234.         names = { }
  235.         traverse = list(self.__class__.__bases__)
  236.         while len(traverse) > 0:
  237.             item = traverse.pop()
  238.             bases = item.__bases__
  239.             if uno.isInterface(item):
  240.                 names[item.__pyunointerface__] = None
  241.                 continue
  242.             if len(bases) > 0:
  243.                 traverse = traverse + list(bases)
  244.                 continue
  245.         lst = names.keys()
  246.         types = []
  247.         for x in lst:
  248.             t = uno.getTypeByName(x)
  249.             types.append(t)
  250.         
  251.         ret = (tuple(types), uno.generateUuid())
  252.         _g_typeTable[self.__class__] = ret
  253.     return ret
  254.  
  255.  
  256. class Base(XTypeProvider):
  257.     
  258.     def getTypes(self):
  259.         return _unohelper_getHandle(self)[0]
  260.  
  261.     
  262.     def getImplementationId(self):
  263.         return _unohelper_getHandle(self)[1]
  264.  
  265.  
  266.  
  267. class CurrentContext(XCurrentContext, Base):
  268.     '''a current context implementation, which first does a lookup in the given
  269.        hashmap and if the key cannot be found, it delegates to the predecessor
  270.        if available
  271.     '''
  272.     
  273.     def __init__(self, oldContext, hashMap):
  274.         self.hashMap = hashMap
  275.         self.oldContext = oldContext
  276.  
  277.     
  278.     def getValueByName(self, name):
  279.         if name in self.hashMap:
  280.             return self.hashMap[name]
  281.         elif self.oldContext != None:
  282.             return self.oldContext.getValueByName(name)
  283.         else:
  284.             return None
  285.  
  286.  
  287.  
  288. class _FactoryHelper_(XSingleComponentFactory, XServiceInfo, Base):
  289.     
  290.     def __init__(self, clazz, implementationName, serviceNames):
  291.         self.clazz = clazz
  292.         self.implementationName = implementationName
  293.         self.serviceNames = serviceNames
  294.  
  295.     
  296.     def getImplementationName(self):
  297.         return self.implementationName
  298.  
  299.     
  300.     def supportsService(self, ServiceName):
  301.         return ServiceName in serviceNames
  302.  
  303.     
  304.     def getSupportedServiceNames(self):
  305.         return self.serviceNames
  306.  
  307.     
  308.     def createInstanceWithContext(self, context):
  309.         return self.clazz(context)
  310.  
  311.     
  312.     def createInstanceWithArgumentsAndContext(self, args, context):
  313.         return self.clazz(context, *args)
  314.  
  315.  
  316.