Ejemplo n.º 1
0
 def _getCommandInfo(self):
     commands = {}
     commands['getCommandInfo'] = getCommandInfo('getCommandInfo')
     commands['getPropertySetInfo'] = getCommandInfo('getPropertySetInfo')
     t1 = uno.getTypeByName('[]com.sun.star.beans.Property')
     commands['getPropertyValues'] = getCommandInfo('getPropertyValues', t1)
     t2 = uno.getTypeByName('[]com.sun.star.beans.PropertyValue')
     commands['setPropertyValues'] = getCommandInfo('setPropertyValues', t2)
     try:
         t3 = uno.getTypeByName('com.sun.star.ucb.OpenCommandArgument3')
     except RuntimeError as e:
         t3 = uno.getTypeByName('com.sun.star.ucb.OpenCommandArgument2')
     commands['open'] = getCommandInfo('open', t3)
     try:
         t4 = uno.getTypeByName('com.sun.star.ucb.InsertCommandArgument2')
     except RuntimeError as e:
         t4 = uno.getTypeByName('com.sun.star.ucb.InsertCommandArgument')
     commands['insert'] = getCommandInfo('insert', t4)
     if not self.Identifier.isRoot():
         commands['delete'] = getCommandInfo('delete', uno.getTypeByName('boolean'))
     if self.CanAddChild:
         t5 = uno.getTypeByName('com.sun.star.ucb.ContentInfo')
         commands['createNewContent'] = getCommandInfo('createNewContent', t5)
         try:
             t6 = uno.getTypeByName('com.sun.star.ucb.TransferInfo2')
         except RuntimeError as e:
             t6 = uno.getTypeByName('com.sun.star.ucb.TransferInfo')
         commands['transfer'] = getCommandInfo('transfer', t6)
         commands['flush'] = getCommandInfo('flush')
     return commands
Ejemplo n.º 2
0
 def testType(self ):
     t1 = uno.getTypeByName( "com.sun.star.lang.XComponent" )
     t2 = uno.getTypeByName( "com.sun.star.lang.XComponent" )
     t3 = uno.getTypeByName( "com.sun.star.lang.EventObject" )
     self.failUnless( t1.typeClass == \
         uno.Enum( "com.sun.star.uno.TypeClass", "INTERFACE" ), "typeclass of type test" )
     self.failUnless( t3.typeClass == \
         uno.Enum( "com.sun.star.uno.TypeClass", "STRUCT" ), "typeclass of type test")
     self.failUnless( t1 == t2 , "equal type test" )
     self.failUnless( t1 == t2 , "equal type test" )
     self.failUnless( t1 == self.tobj.transportAny( t1 ), "type rountrip test" )
Ejemplo n.º 3
0
Archivo: test.py Proyecto: hanya/pyuno3
 def test_Type(self):
     repr_base = "<Type instance {type_name} ({type_class})>"
     
     type_name = "boolean"
     type_class = uno.Enum("com.sun.star.uno.TypeClass", "BOOLEAN")
     repr_desired = repr_base.format(type_name=type_name, type_class=type_class)
     t = uno.Type(type_name, type_class)
     self.assertTrue(t == uno.getTypeByName(type_name))
     self.assertFalse(t == uno.getTypeByName("void"))
     self.assertEqual(repr(t), repr_desired)
     self.assertEqual(hash(t), hash(type_name))
Ejemplo n.º 4
0
    def test_Type(self):

        STRING_TYPE = uno.getTypeByName("string")
        LONG_TYPE = uno.getTypeByName("long")
        string_type = uno.Type("string", STRING)
        long_type = uno.Type("long", LONG)
        self.assertEqual(STRING_TYPE, STRING_TYPE)
        self.assertEqual(STRING_TYPE, string_type)
        self.assertFalse((STRING_TYPE != string_type))
        self.assertNotEqual(STRING_TYPE, LONG)
        self.assertEqual(LONG_TYPE, long_type)
Ejemplo n.º 5
0
 def testType(self ):
     t1 = uno.getTypeByName( "com.sun.star.lang.XComponent" )
     t2 = uno.getTypeByName( "com.sun.star.lang.XComponent" )
     t3 = uno.getTypeByName( "com.sun.star.lang.EventObject" )
     self.failUnless( t1.typeClass == \
         uno.Enum( "com.sun.star.uno.TypeClass", "INTERFACE" ), "typeclass of type test" )
     self.failUnless( t3.typeClass == \
         uno.Enum( "com.sun.star.uno.TypeClass", "STRUCT" ), "typeclass of type test")
     self.failUnless( t1 == t2 , "equal type test" )
     self.failUnless( t1 == t2 , "equal type test" )
     self.failUnless( t1 == self.tobj.transportAny( t1 ), "type roundtrip test" )
Ejemplo n.º 6
0
    def test_Type(self):

        STRING_TYPE = uno.getTypeByName("string")
        LONG_TYPE = uno.getTypeByName("long")
        string_type = uno.Type("string", STRING)
        long_type = uno.Type("long", LONG)
        self.assertEqual(STRING_TYPE, STRING_TYPE)
        self.assertEqual(STRING_TYPE, string_type)
        self.assertFalse((STRING_TYPE != string_type))
        self.assertNotEqual(STRING_TYPE, LONG)
        self.assertEqual(LONG_TYPE, long_type)
Ejemplo n.º 7
0
    def getTransferDataFlavors(self):
        df_rdf = DataFlavor()
        df_rdf.MimeType = self._rdf_type
        df_rdf.HumanPresentableName = ""
        #df_rdf.DataType = uno.getTypeByName("[]byte")
        df_rdf.DataType = uno.getTypeByName("string")

        df_img = DataFlavor()
        df_img.MimeType = self._img_type
        df_img.HumanPresentableName = ""
        df_img.DataType = uno.getTypeByName("[]byte")

        return (df_rdf, df_img)
    def getTransferDataFlavors(self):
        df_rdf = DataFlavor()
        df_rdf.MimeType = self._rdf_type
        df_rdf.HumanPresentableName = ""
        #df_rdf.DataType = uno.getTypeByName("[]byte")
        df_rdf.DataType = uno.getTypeByName("string")

        df_img = DataFlavor()
        df_img.MimeType = self._img_type
        df_img.HumanPresentableName = ""
        df_img.DataType = uno.getTypeByName("[]byte")

        return (df_rdf, df_img)
def _unohelper_getHandle( self):
    ret = None
    if self.__class__ in _g_typeTable:
        ret = _g_typeTable[self.__class__]
    else:
        names = {}
        traverse = list(self.__class__.__bases__)
        while len( traverse ) > 0:
            item = traverse.pop()
            bases = item.__bases__
            if uno.isInterface( item ):
                names[item.__pyunointerface__] = None
            elif len(bases) > 0:
                # the "else if", because we only need the most derived interface
                traverse = traverse + list(bases)#

        lst = list(names.keys())
        types = []
        for x in lst:
            t = uno.getTypeByName( x )
            types.append( t )

        ret = tuple(types) , uno.generateUuid()
        _g_typeTable[self.__class__] = ret
    return ret
Ejemplo n.º 10
0
Archivo: engine.py Proyecto: kikili/MRI
 def get_value(self, value, type_name, type_class):
     """ Converts string value to specified type. """
     # ToDo check value range as UNO type
     if type_class in TypeClassGroups.INT:
         ret = long(value)
     elif type_class in TypeClassGroups.FLOATING:
         ret = float(value)
     elif type_class == TypeClass.BOOLEAN:
         ret = (value.lower() == 'true' or value.strip() == '1')
     elif type_class == TypeClass.STRING:
         ret = value
     elif type_class == TypeClass.ENUM:
         try:
             ret = uno.Enum(str(type_name), str(value).upper())
         except:
             ret = None
     elif type_class == TypeClass.TYPE:
         ret = uno.getTypeByName(value)
     elif type_class == TypeClass.VOID:
         ret = None
     elif isinstance(value, EntryBase):
         ret = value
     else:
         ret = str(value)
     return ret
Ejemplo n.º 11
0
 def testInspect(self):
     dev = NullDevice()
     #            dev = sys.stdout
     unohelper.inspect(uno.getComponentContext(), dev)
     unohelper.inspect(uno.getComponentContext().ServiceManager, dev)
     unohelper.inspect(uno.getTypeByName("com.sun.star.lang.XComponent"),
                       dev)
Ejemplo n.º 12
0
    def test_basic(self):
        import uno
        from unokit.adapters import InputStreamFromFileLike
        from hwp5_uno import StorageFromInputStream
        from hwp5.hwp5odt import ODTPackage

        zipname = self.id()+'.zip'

        pkg = ODTPackage(zipname)
        try:
            from StringIO import StringIO
            data = StringIO('hello')
            pkg.insert_stream(data, 'abc.txt', 'text/plain')
        finally:
            pkg.close()

        with file(zipname, 'rb') as f:
            inputstream = InputStreamFromFileLike(f, dontclose=True)
            storage = StorageFromInputStream(inputstream)
            try:
                self.assertTrue(uno.getTypeByName('com.sun.star.embed.XStorage')
                                in storage.Types)
                self.assertEqual(set(['abc.txt']), set(storage.ElementNames))
            finally:
                storage.dispose()
Ejemplo n.º 13
0
def _unohelper_getHandle(self):
    ret = None
    if _g_typeTable.has_key(self.__class__):
        ret = _g_typeTable[self.__class__]
    else:
        names = {}
        traverse = list(self.__class__.__bases__)
        while len(traverse) > 0:
            item = traverse.pop()
            bases = item.__bases__
            if uno.isInterface(item):
                names[item.__pyunointerface__] = None
            elif len(bases) > 0:
                # the "else if", because we only need the most derived interface
                traverse = traverse + list(bases)  #

        lst = names.keys()
        types = []
        for x in lst:
            t = uno.getTypeByName(x)
            types.append(t)

        ret = tuple(types), uno.generateUuid()
        _g_typeTable[self.__class__] = ret
    return ret
Ejemplo n.º 14
0
def getAllShapesFromElement(element, headingLevel):
	for index in range(element.Count):
		child = element.getByIndex(index)
		if child.getElementType() == uno.getTypeByName("com.sun.star.drawing.XShape"):
			arrayImageData.append([headingLevel, child.getPropertyValue("Title"),child.getPropertyValue("Description")])
			if child.Count > 0:
				getAllShapesFromElement(child, headingLevel+1)
Ejemplo n.º 15
0
 def testInvoke( self ):
     self.failUnless( 5 == uno.invoke( self.tobj , "transportAny" , (uno.Any("byte", 5),) ) )
     self.failUnless( 5 == uno.invoke(
         PythonTransporter(), "transportAny" , (uno.Any( "byte", 5 ),) ) )
     t = uno.getTypeByName( "long" )
     mystruct = uno.createUnoStruct(
         "com.sun.star.beans.PropertyValue", "foo",0,uno.Any(t,2),0 )
     mystruct.Value = uno.Any(t, 1)
Ejemplo n.º 16
0
 def testInvoke( self ):
     self.failUnless( 5 == uno.invoke( self.tobj , "transportAny" , (uno.Any("byte", 5),) ) )
     self.failUnless( 5 == uno.invoke(
         PythonTransporter(), "transportAny" , (uno.Any( "byte", 5 ),) ) )
     t = uno.getTypeByName( "long" )
     mystruct = uno.createUnoStruct(
         "com.sun.star.beans.PropertyValue", "foo",0,uno.Any(t,2),0 )
     mystruct.Value = uno.Any(t, 1)
Ejemplo n.º 17
0
 def grid_check_interface(self):
     """ Chedk legacy interface is used or not. """
     import uno
     try:
         d = uno.getTypeByName("com.sun.star.awt.grid.XGridRowSelection")
     except:
         self._get_selected_rows = self.foo_get_selected_rows
         self._is_row_selected = self.foo_is_row_selected
         self._has_selected_rows = self.foo_has_selected_rows
Ejemplo n.º 18
0
 def grid_check_interface(self):
     """ Chedk legacy interface is used or not. """
     import uno
     try:
         d = uno.getTypeByName("com.sun.star.awt.grid.XGridRowSelection")
     except:
         self._get_selected_rows = self.foo_get_selected_rows
         self._is_row_selected = self.foo_is_row_selected
         self._has_selected_rows = self.foo_has_selected_rows
Ejemplo n.º 19
0
 def getPropertySetInfo(self):
     try:
         bool_type = uno.getTypeByName("boolean")
         return PropertySetInfo((("ShowName", -1, bool_type,
                                  16), ("ShowTags", -1, bool_type,
                                        0), ("ShowValue", -1, bool_type, 0),
                                 ("ShowDescription", -1, bool_type, 0)))
     except Exception as e:
         print(e)
     return None
Ejemplo n.º 20
0
def getProperty(name, type=None, attributes=None, handle=-1):
    property = uno.createUnoStruct('com.sun.star.beans.Property')
    property.Name = name
    property.Handle = handle
    if isinstance(type, uno.Type):
        property.Type = type
    elif type is not None:
        property.Type = uno.getTypeByName(type)
    if attributes is not None:
        property.Attributes = attributes
    return property
Ejemplo n.º 21
0
def getAllShapesFromElement(element, headingLevel):
    for index in range(element.Count):
        child = element.getByIndex(index)
        if child.getElementType() == uno.getTypeByName(
                "com.sun.star.drawing.XShape"):
            arrayImageData.append([
                headingLevel,
                child.getPropertyValue("Title"),
                child.getPropertyValue("Description")
            ])
            if child.Count > 0:
                getAllShapesFromElement(child, headingLevel + 1)
Ejemplo n.º 22
0
 def getPropertySetInfo(self):
     try:
         bool_type = uno.getTypeByName("boolean")
         return PropertySetInfo(
             (
                 ("ShowName", -1, bool_type, 16), 
                 ("ShowTags", -1, bool_type, 0), 
                 ("ShowValue", -1, bool_type, 0), 
                 ("ShowDescription", -1, bool_type, 0)
             )
         )
     except Exception as e:
         print(e)
     return None
Ejemplo n.º 23
0
 def initialize(self, args):
     if not isinstance(args, tuple) or len(args) != 2:
         raise self._getIllegalArgumentException(0, 101)
     paths = args[0]
     controller = args[1]
     if not isinstance(paths, tuple) or len(paths) < 2:
         raise self._getIllegalArgumentException(0, 102)
     unotype = uno.getTypeByName(
         'com.sun.star.ui.dialogs.XWizardController')
     if unotype not in getInterfaceTypes(controller):
         raise self._getIllegalArgumentException(0, 103)
     self._paths = paths
     self._multiPaths = isinstance(paths[0], tuple)
     self._controller = controller
Ejemplo n.º 24
0
 def handle(self, request):
     message = request.getRequest()
     if not isinstance(message, str):
         message = message.Message
     try:
         n = self.act.query(message)
         if n == 1:
             type_name = "com.sun.star.task.XInteractionApprove"
         else:
             type_name = "com.sun.star.task.XInteractionAbort"
         for continuation in request.getContinuations():
             if continuation.queryInterface(uno.getTypeByName(type_name)):
                 continuation.select()
     except Exception as e:
         print(e)
Ejemplo n.º 25
0
def _unohelper_getHandle( self):
    ret = None
    if self.__class__ in _g_typeTable:
        ret = _g_typeTable[self.__class__]
    else:
        names = set()
        traverse = list(self.__class__.__bases__)
        while len( traverse ) > 0:
            item = traverse.pop()
            bases = item.__bases__
            if uno.isInterface( item ):
                names.add(item.__pyunointerface__)
            elif bases:
                # the "else if", because we only need the most derived interface
                traverse = traverse + list(bases)#

        types = [uno.getTypeByName(name) for name in names]
        ret = tuple(types) , uno.generateUuid()
        _g_typeTable[self.__class__] = ret
    return ret
Ejemplo n.º 26
0
Archivo: engine.py Proyecto: hanya/MRI
 def get_value(self, value, type_name, type_class):
     if type_class in TypeClassGroups.INT:
         ret = long(value)
     elif type_class in TypeClassGroups.FLOATING:
         ret = float(value)
     elif type_class == TypeClass.BOOLEAN:
         if value.lower() == 'true' or value.strip() == '1':
             ret = True
         else:
             ret = False
     elif type_class == TypeClass.STRING:
         ret = value
     elif type_class == TypeClass.ENUM:
         try:
             ret = uno.Enum(str(type_name), str(value).upper())
         except:
             ret = None
     elif type_class == TypeClass.TYPE:
         ret = uno.getTypeByName(value)
     else:
         ret = str(value)
     return ret
Ejemplo n.º 27
0
 def get_value(self, value, type_name, type_class):
     if type_class in TypeClassGroups.INT:
         ret = long(value)
     elif type_class in TypeClassGroups.FLOATING:
         ret = float(value)
     elif type_class == TypeClass.BOOLEAN:
         if value.lower() == 'true' or value.strip() == '1':
             ret = True
         else:
             ret = False
     elif type_class == TypeClass.STRING:
         ret = value
     elif type_class == TypeClass.ENUM:
         try:
             ret = uno.Enum(str(type_name), str(value).upper())
         except:
             ret = None
     elif type_class == TypeClass.TYPE:
         ret = uno.getTypeByName(value)
     else:
         ret = str(value)
     return ret
Ejemplo n.º 28
0
	def getTypes (self):
		global g_TypeTable
		
		if g_TypeTable.has_key (self.__class__):
			ret = g_TypeTable[self.__class__]
		else:
			ret = (
				uno.getTypeByName( "org.openoffice.sheet.addin.MymmsAddin" ),
				uno.getTypeByName( "com.sun.star.sheet.XAddIn" ),
				uno.getTypeByName( "com.sun.star.lang.XLocalizable" ),
				uno.getTypeByName( "com.sun.star.lang.XServiceName" ),
				uno.getTypeByName( "com.sun.star.lang.XServiceInfo" ),
				uno.getTypeByName( "com.sun.star.lang.XTypeProvider" ),
				)
			g_TypeTable[self.__class__] = ret
			
		return ret
Ejemplo n.º 29
0
 def execute(self, command, id, environment):
     url = self.getIdentifier().getContentIdentifier()
     print("Content.execute() %s - %s - %s" % (command.Name, url, self.getIdentifier().Id))
     msg = "command.Name: %s" % command.Name
     logMessage(self.ctx, INFO, msg, "Content", "execute()")
     if command.Name == 'getCommandInfo':
         return CommandInfo(self._commandInfo)
     elif command.Name == 'getPropertySetInfo':
         return PropertySetInfo(self.Identifier._propertySetInfo)
     elif command.Name == 'getPropertyValues':
         namedvalues = getPropertiesValues(self.ctx, self, command.Argument)
         return Row(namedvalues)
     elif command.Name == 'setPropertyValues':
         return setPropertiesValues(self.ctx, self, environment, command.Argument)
     elif command.Name == 'delete':
         self.MetaData.insertValue('Trashed', True)
         user = self.Identifier.User
         user.DataBase.updateContent(user.Id, self.Identifier.Id, 'Trashed', True)
     elif command.Name == 'open':
         if self.IsFolder:
             print("Content.execute() open 1")
             # Not Used: command.Argument.Properties - Implement me ;-)
             select = self.Identifier.getFolderContent(self.MetaData)
             print("Content.execute() open 2")
             msg += " IsFolder: %s" % self.IsFolder
             logMessage(self.ctx, INFO, msg, "Content", "execute()")
             print("Content.execute() open 3")
             return DynamicResultSet(self.ctx, select)
         elif self.IsDocument:
             print("Content.execute() open 4")
             sf = getSimpleFile(self.ctx)
             url, size = self.Identifier.getDocumentContent(sf, self.MetaData, 0)
             if not size:
                 title = self.MetaData.getValue('Title')
                 msg = "Error while downloading file: %s" % title
                 print("Content.execute() %s" % msg)
                 raise CommandAbortedException(msg, self)
             sink = command.Argument.Sink
             interfaces = getInterfaceTypes(sink)
             datasink = uno.getTypeByName('com.sun.star.io.XActiveDataSink')
             datastream = uno.getTypeByName('com.sun.star.io.XActiveDataStreamer')
             isreadonly = self.MetaData.getValue('IsReadOnly')
             if datasink in interfaces:
                 sink.setInputStream(sf.openFileRead(url))
             elif not isreadonly and datastream in interfaces:
                 sink.setStream(sf.openFileReadWrite(url))
     elif command.Name == 'insert':
         # The Insert command is only used to create a new folder or a new document
         # (ie: File Save As).
         # It saves the content created by 'createNewContent' from the parent folder
         print("Content.execute() insert 1 - %s - %s - %s" % (self.IsFolder,
                                                                 self.Identifier.Id,
                                                                 self.MetaData.getValue('Title')))
         if self.IsFolder:
             mediatype = self.Identifier.User.Provider.Folder
             self.MetaData.insertValue('MediaType', mediatype)
             print("Content.execute() insert 2 ************** %s" % mediatype)
             if self.Identifier.insertNewContent(self.MetaData):
                 # Need to consum the new Identifier if needed...
                 self.Identifier.deleteNewIdentifier()
             print("Content.execute() insert 3")
         elif self.IsDocument:
             stream = command.Argument.Data
             replace = command.Argument.ReplaceExisting
             sf = getSimpleFile(self.ctx)
             url = self.Identifier.User.Provider.SourceURL
             target = '%s/%s' % (url, self.Identifier.Id)
             if sf.exists(target) and not replace:
                 return
             inputstream = uno.getTypeByName('com.sun.star.io.XInputStream')
             if inputstream in getInterfaceTypes(stream):
                 sf.writeFile(target, stream)
                 mediatype = getMimeType(self.ctx, stream)
                 self.MetaData.insertValue('MediaType', mediatype)
                 stream.closeInput()
                 print("Content.execute() insert 2 ************** %s" % mediatype)
                 if self.Identifier.insertNewContent(self.MetaData):
                     # Need to consum the new Identifier if needed...
                     self.Identifier.deleteNewIdentifier()
                     print("Content.execute() insert 3")
     elif command.Name == 'createNewContent' and self.IsFolder:
         return self.createNewContent(command.Argument)
     elif command.Name == 'transfer' and self.IsFolder:
         # Transfer command is used for document 'File Save' or 'File Save As'
         # NewTitle come from:
         # - Last segment path of 'XContent.getIdentifier().getContentIdentifier()' for OpenOffice
         # - Property 'Title' of 'XContent' for LibreOffice
         # If the content has been renamed, the last segment is the new Title of the content
         title = command.Argument.NewTitle
         source = command.Argument.SourceURL
         move = command.Argument.MoveData
         clash = command.Argument.NameClash
         print("Content.execute() transfert 1 %s - %s -%s - %s" % (title, source, move, clash))
         # We check if 'NewTitle' is a child of this folder by recovering its ItemId
         user = self.Identifier.User
         itemid = user.DataBase.getChildId(user.Id, self.Identifier.Id, title)
         if itemid is None:
             print("Content.execute() transfert 2 %s" % itemid)
             # ItemId could not be found: 'NewTitle' does not exist in the folder...
             # For new document (File Save As) we use commands:
             # - createNewContent: for creating an empty new Content
             # - Insert at new Content for committing change
             # To execute these commands, we must throw an exception
             msg = "Couln't handle Url: %s" % source
             raise InteractiveBadTransferURLException(msg, self)
         print("Content.execute() transfert 3 %s - %s" % (itemid, source))
         sf = getSimpleFile(self.ctx)
         if not sf.exists(source):
             raise CommandAbortedException("Error while saving file: %s" % source, self)
         inputstream = sf.openFileRead(source)
         target = '%s/%s' % (user.Provider.SourceURL, itemid)
         sf.writeFile(target, inputstream)
         inputstream.closeInput()
         # We need to update the Size
         user.DataBase.updateContent(user.Id, itemid, 'Size', sf.getSize(target))
         if move:
             pass #must delete object
     elif command.Name == 'flush' and self.IsFolder:
         pass
Ejemplo n.º 30
0
Archivo: test.py Proyecto: hanya/pyuno3
 def test_import_typeOf(self):
     from com.sun.star.container import typeOfXNameAccess
     t = uno.getTypeByName("com.sun.star.container.XNameAccess")
     self.assertEqual(typeOfXNameAccess, t)
Ejemplo n.º 31
0
def getProperty(name, typename, attributes, handle=-1):
    return uno.createUnoStruct('com.sun.star.beans.Property', name, handle,
                               uno.getTypeByName(typename), attributes)
Ejemplo n.º 32
0
Archivo: test.py Proyecto: hanya/pyuno3
 def test_type(self):
     vt = self.create_value_test(TypeValue=uno.getTypeByName("[]long"))
     self.assertEqual(vt.getType(), uno.getTypeByName("[]long"))
     vt.setType(uno.getTypeByName("com.sun.star.awt.Rectangle"))
     self.assertEqual(vt.getType(), uno.getTypeByName("com.sun.star.awt.Rectangle"))
Ejemplo n.º 33
0
Archivo: test.py Proyecto: hanya/pyuno3
 def test(type_name, type_class):
     t = uno.getTypeByName(type_name)
     self.assertTrue(isinstance(t, uno.Type))
     self.assertEqual(t.typeName, type_name)
     self.assertTrue(isinstance(t.typeClass, uno.Enum))
     self.assertEqual(t.typeClass.value, type_class)
Ejemplo n.º 34
0
 def getElementType(self):
     log.debug("getElementType called")
     return uno.getTypeByName("void")
Ejemplo n.º 35
0
 def getElementType(self):
     return uno.getTypeByName('string')
Ejemplo n.º 36
0
 def testInspect(self):
     dev = NullDevice()
     #            dev = sys.stdout
     unohelper.inspect(uno.getComponentContext(), dev)
     unohelper.inspect(uno.getComponentContext().ServiceManager, dev)
     unohelper.inspect(uno.getTypeByName("com.sun.star.lang.XComponent"), dev)
Ejemplo n.º 37
0
 def getElementType( self ):
     log.debug( "getElementType called" )
     return uno.getTypeByName( "void" )
Ejemplo n.º 38
0
 def getElementType(self):
     return uno.getTypeByName("any")
Ejemplo n.º 39
0
 def execute(self, command, id, environment):
     try:
         msg = "command.Name: %s" % command.Name
         print("Content.execute() %s **********************************" %
               msg)
         logMessage(self.ctx, INFO, msg, 'Content', 'execute()')
         if command.Name == 'getCommandInfo':
             msg = "command.Name: %s ******************************************" % command.Name
             logMessage(self.ctx, INFO, msg, 'Content', 'execute()')
             return CommandInfo(self._commandInfo)
         elif command.Name == 'getPropertySetInfo':
             return PropertySetInfo(self._propertySetInfo)
         elif command.Name == 'getPropertyValues':
             namedvalues = getPropertiesValues(self.ctx, self,
                                               command.Argument)
             return Row(namedvalues)
         elif command.Name == 'setPropertyValues':
             return setPropertiesValues(self.ctx, self, environment,
                                        command.Argument)
         elif command.Name == 'delete':
             self.MetaData.insertValue(
                 'Trashed', self.Identifier.updateTrashed(True, False))
         elif command.Name == 'open':
             print("Content.execute() open 1")
             if self.IsFolder:
                 print("Content.execute() open 2")
                 # Not Used: command.Argument.Properties - Implement me ;-)
                 select = self.Identifier.getFolderContent(self.MetaData)
                 msg += " IsFolder: %s" % self.IsFolder
                 logMessage(self.ctx, INFO, msg, 'Content', 'execute()')
                 return DynamicResultSet(self.ctx, select)
             elif self.IsDocument:
                 print("Content.execute() open 3")
                 sf = getSimpleFile(self.ctx)
                 url, size = self.Identifier.getDocumentContent(
                     sf, self.MetaData, 0)
                 if not size:
                     print("Content.execute() open 4")
                     title = self.MetaData.getValue('Title')
                     msg = "Error while downloading file: %s" % title
                     raise CommandAbortedException(msg, self)
                 print("Content.execute() open 5")
                 s = command.Argument.Sink
                 sink = uno.getTypeByName('com.sun.star.io.XActiveDataSink')
                 stream = uno.getTypeByName(
                     'com.sun.star.io.XActiveDataStreamer')
                 isreadonly = self.MetaData.getValue('IsReadOnly')
                 if s.queryInterface(sink):
                     s.setInputStream(sf.openFileRead(url))
                 elif not isreadonly and s.queryInterface(stream):
                     s.setStream(sf.openFileReadWrite(url))
                 print("Content.execute() open 6")
         elif command.Name == 'insert':
             if self.IsFolder:
                 mediatype = self.Identifier.DataSource.Provider.Folder
                 self.MetaData.insertValue('MediaType', mediatype)
                 if self.Identifier.insertNewFolder(self.MetaData):
                     pass
                 #identifier = self.getIdentifier()
                 #ucp = getUcp(self.ctx, identifier.getContentProviderScheme())
                 #self.addPropertiesChangeListener(('Id', 'Name', 'Size', 'Trashed', 'Loaded'), ucp)
                 #propertyChange(self, 'Id', identifier.Id, CREATED | FOLDER)
                 #parent = identifier.getParent()
                 #event = getContentEvent(self, INSERTED, self, parent)
                 #ucp.queryContent(parent).notify(event)
             elif self.IsDocument:
                 # The Insert command is only used to create a new document (File Save As)
                 # it saves content from createNewContent from the parent folder
                 stream = command.Argument.Data
                 replace = command.Argument.ReplaceExisting
                 sf = getSimpleFile(self.ctx)
                 url = self.Identifier.DataSource.Provider.SourceURL
                 target = '%s/%s' % (url, self.Identifier.Id)
                 if sf.exists(target) and not replace:
                     pass
                 elif stream.queryInterface(
                         uno.getTypeByName('com.sun.star.io.XInputStream')):
                     sf.writeFile(target, stream)
                     mediatype = getMimeType(self.ctx, stream)
                     self.MetaData.insertValue('MediaType', mediatype)
                     stream.closeInput()
                     if self.Identifier.insertNewDocument(self.MetaData):
                         pass
                     #ucp = getUcp(self.ctx, identifier.getContentProviderScheme())
                     #self.addPropertiesChangeListener(('Id', 'Name', 'Size', 'Trashed', 'Loaded'), ucp)
                     #propertyChange(self, 'Id', identifier.Id, CREATED | FILE)
                     #parent = identifier.getParent()
                     #event = getContentEvent(self, INSERTED, self, parent)
                     #ucp.queryContent(parent).notify(event)
         elif command.Name == 'createNewContent' and self.IsFolder:
             return self.createNewContent(command.Argument)
         elif command.Name == 'transfer' and self.IsFolder:
             # Transfer command is used for document 'File Save' or 'File Save As'
             # NewTitle come from:
             # - Last segment path of 'XContent.getIdentifier().getContentIdentifier()' for OpenOffice
             # - Property 'Title' of 'XContent' for LibreOffice
             # If the content has been renamed, the last segment is the new Title of the content
             title = command.Argument.NewTitle
             source = command.Argument.SourceURL
             move = command.Argument.MoveData
             clash = command.Argument.NameClash
             # We check if 'command.Argument.NewTitle' is an Id
             if self.Identifier.isChildId(title):
                 id = title
             else:
                 # It appears that 'command.Argument.NewTitle' is not an Id but a Title...
                 # If 'NewTitle' exist and is unique in the folder, we can retrieve its Id
                 id = self.Identifier.selectChildId(title)
                 if not id:
                     # Id could not be found: NewTitle does not exist in the folder...
                     # For new document (File Save As) we use commands:
                     # - createNewContent: for creating an empty new Content
                     # - Insert at new Content for committing change
                     # To execute these commands, we must throw an exception
                     msg = "Couln't handle Url: %s" % source
                     raise InteractiveBadTransferURLException(msg, self)
             sf = getSimpleFile(self.ctx)
             if not sf.exists(source):
                 raise CommandAbortedException(
                     "Error while saving file: %s" % source, self)
             inputstream = sf.openFileRead(source)
             target = '%s/%s' % (
                 self.Identifier.DataSource.Provider.SourceURL, id)
             sf.writeFile(target, inputstream)
             inputstream.closeInput()
             # We need to commit change: Size is the property chainning all DataSource change
             if not self.Identifier.updateSize(id, self.Identifier.Id,
                                               sf.getSize(target)):
                 raise CommandAbortedException(
                     "Error while saving file: %s" % source, self)
             #ucb = getUcb(self.ctx)
             #identifier = ucb.createContentIdentifier('%s/%s' % (self.Identifier.BaseURL, title))
             #data = getPropertyValueSet({'Size': sf.getSize(target)})
             #content = ucb.queryContent(identifier)
             #executeContentCommand(content, 'setPropertyValues', data, environment)
             if move:
                 pass  #must delete object
         elif command.Name == 'flush' and self.IsFolder:
             pass
     except CommandAbortedException as e:
         raise e
     except InteractiveBadTransferURLException as e:
         raise e
     except Exception as e:
         msg += " ERROR: %s" % e
         print("Content.execute() ERROR: %s" % msg)
         logMessage(self.ctx, SEVERE, msg, 'Content', 'execute()')
Ejemplo n.º 40
0
 def getElementType(self):
     print("DataContainer.getElementType()")
     return uno.getTypeByName(self._typename)