예제 #1
0
class VoiceIndicator:
    def __init__(self, voiceParticipant):
        self._voiceParticipant = voiceParticipant
        if self._voiceParticipant is not None:
            self._voiceParticipant.connect("StartSpeaking()",
                                           self.onStartSpeaking)
            self._voiceParticipant.connect("StopSpeaking()",
                                           self.onStopSpeaking)

        self._entity = self._getAvatarEntity(
            self._voiceParticipant.AvatarUUID())
        self._billboard = None
        if self._entity is not None:
            self._setupBillboard()
        else:
            pass

    def getEntity(self):
        return self._entity

    def setEntity(self, ent):
        self._entity = ent
        self._setupBillboard()

    def onStartSpeaking(self):
        if self._billboard is not None:
            self._billboard.SetVisible(True)

    def onStopSpeaking(self):
        if self._billboard is not None:
            self._billboard.SetVisible(False)

    def _setupBillboard(self):
        self._createBillboardWidgets()
        self._billboard = self._entity.GetOrCreateComponentRaw(
            "EC_BillboardWidget", "voiceIndicator",
            PythonQt.private.AttributeChange.Disconnected, False)
        self._billboard.SetPosition(0, 0, 2.5)
        self._billboard.SetWidth(1.45)
        self._billboard.SetHeight(1)
        self._billboard.SetWidget(self._voiceBillboardWidget)
        self._billboard.SetVisible(False)

    def _createBillboardWidgets(self):
        self.pixmap_label = QLabel()
        self.pixmap_label.size = QSize(512, 352)
        self.pixmap_label.scaledContents = True
        self.pixmap_label.setPixmap(
            QPixmap('./data/ui/images/comm/voiceindicator.png'))
        self._voiceBillboardWidget = self.pixmap_label

    def _getAvatarEntity(self, uuid):
        entities = naali.getDefaultScene().GetEntitiesWithComponentRaw(
            "EC_OpensimPresence")
        for e in entities:
            presence = e.GetComponentRaw("EC_OpenSimPresence")
            if presence is not None:
                if presence.QGetUUIDString() == uuid:
                    return e
        return None
예제 #2
0
파일: voiceindicator.py 프로젝트: A-K/naali
class VoiceIndicator:
    def __init__(self, voiceParticipant):
        self._voiceParticipant = voiceParticipant
        if self._voiceParticipant is not None:
            self._voiceParticipant.connect("StartSpeaking()", self.onStartSpeaking)
            self._voiceParticipant.connect("StopSpeaking()", self.onStopSpeaking)

        self._entity = self._getAvatarEntity(self._voiceParticipant.AvatarUUID())
        self._billboard = None
        if self._entity is not None:
            self._setupBillboard()
        else:
            pass

    def getEntity(self):
        return self._entity

    def setEntity(self, ent):
        self._entity = ent
        self._setupBillboard()

    def onStartSpeaking(self):
        if self._billboard is not None:
            self._billboard.SetVisible(True)

    def onStopSpeaking(self):
        if self._billboard is not None:        
            self._billboard.SetVisible(False) 

    def _setupBillboard(self):       
        self._createBillboardWidgets()
        self._billboard = self._entity.GetOrCreateComponentRaw("EC_BillboardWidget", "voiceIndicator", PythonQt.private.AttributeChange.Disconnected, False)        
        self._billboard.SetPosition(0,0,2.5)
        self._billboard.SetWidth(1.45)
        self._billboard.SetHeight(1)
        self._billboard.SetWidget(self._voiceBillboardWidget)
        self._billboard.SetVisible(False) 

    def _createBillboardWidgets(self):
        self.pixmap_label = QLabel()
        self.pixmap_label.size = QSize(512,352)
        self.pixmap_label.scaledContents = True
        self.pixmap_label.setPixmap(QPixmap('./data/ui/images/comm/voiceindicator.png'))
        self._voiceBillboardWidget = self.pixmap_label 

    def _getAvatarEntity(self, uuid):
        entities = naali.getDefaultScene().GetEntitiesWithComponentRaw("EC_OpensimPresence")
        for e in entities:
            presence = e.GetComponentRaw("EC_OpenSimPresence")
            if presence is not None:
                if presence.QGetUUIDString() == uuid:
                    return e
        return None
예제 #3
0
    def onTextMessageEvent(self, schid, targetMode, toID, fromID, fromName, fromUniqueIdentifier, message, ffIgnored):
        if self.status:
            (error, myid) = ts3.getClientID(schid)
            
            # get plain url from bbcode url
            # https://github.com/DerLuemmel/pyTSon_ts3_linkinfo/blob/master/__init__.py
            message = message.lower()
            if not myid == fromID and ("[url]" in message or "[url=" in message):
                start = message.find("[url]")
                if not start == -1:                   
                    end = message.find("[/url]")
                    message = message[start + 5:end]
                else:
                    start = message.find("[url=")
                    end = message.find("]")
                    message = message[start + 5:end]

                # Open stream and read content type
                stream = urllib.request.urlopen(message)
                contenttype = stream.info().get_content_type()                

                # if contenttype is png, gif, jpeg
                if contenttype in self.contenttypes:
                    
                    # get image data
                    data = stream.read()
                    
                    # label and pixmap
                    image = QLabel("image")   
                    pixmap = QPixmap()
                    
                    # load url data to pixmap
                    pixmap.loadFromData(data)      

                    # set max width to self.imageMaxHeight
                    pixmap = pixmap.scaledToHeight(self.imageMaxHeight, Qt.FastTransformation)
                    
                    # set image to label
                    image.setPixmap(pixmap)  
                    
                    # set margins for better looking
                    image.setStyleSheet("QLabel{margin: 10px;}")
                    
                    # Get chatlayout
                    chatlayout = self.getWidgetByObjectName("MainWindowChatWidget").layout()
                    
                    # Add image to chatlayout
                    chatlayout.addWidget(image)
                    
                    # Deletes image label after self.showTime
                    QTimer.singleShot(self.showTime, lambda : self.removeImage(chatlayout, image)) 
예제 #4
0
파일: billboardtest.py 프로젝트: A-K/naali
class MyTest():
	def __init__(self):
		pass
		
	def testBillboard(self):	
		avatar = naali.getUserAvatar()
		avatar_pos = avatar.GetComponentRaw("EC_Placeable")
		
		self.pixmap_label = QLabel()
		self.pixmap_label.size = QSize(200,200)
		self.pixmap_label.scaledContents = True
		self.pixmap_label.setPixmap(QPixmap('./data/ui/images/naali_icon.png'))

		self.text_label = QLabel()
		self.text_label.size = QSize(300,50)
		self.text_label.text = "Hello world"

		self.my_widget = QWidget()
		self.my_widget.setLayout(QVBoxLayout())
		self.my_widget.layout().addWidget(self.pixmap_label)
		self.my_widget.layout().addWidget(self.text_label)
		
		if self.my_widget is None:
			print("Cannot find image file.")
			return
			
		self.my_entity = naali.createEntity()
		position = self.my_entity.GetOrCreateComponentRaw("EC_Placeable", "pos", PythonQt.private.AttributeChange.Disconnected, False)
		position.position = avatar_pos.position
		
		self.ec_billboard = self.my_entity.GetOrCreateComponentRaw("EC_BillboardWidget", "test", PythonQt.private.AttributeChange.Disconnected, False)
		if self.ec_billboard is None:
			print("Cannot create EC_Billboard component.")
			return
	
		self.ec_billboard.SetPosition(0,0,1)
		self.ec_billboard.SetWidth(1)
		self.ec_billboard.SetHeight(1)
		self.ec_billboard.SetWidget(self.my_widget)
		
		self.size_timer = QTimer()
		self.size_timer.connect("timeout()", self.animateSize)
		self.size_timer.start(100)
		 
		self.text_timer = QTimer()
		self.text_timer.connect("timeout()", self.animateText)
		self.text_timer.start(1000)
		
	def animateSize(self):
		min_width = 1.0
		max_width = 2.0
		min_height = 1.0
		max_height = 2.0
		delta_width = max_width-min_width
		delta_height = max_height-min_height
		width = min_width + 0.5*delta_width + 0.5*delta_width*math.sin(time.time()*1.324)
		height = min_height + 0.5*delta_height + 0.5*delta_height*math.cos(time.time()*2.232)
		self.ec_billboard.SetSize(width, height)
		
	def animateText(self):	
		text = str(float(time.time()))
		self.text_label.text = text
		self.ec_billboard.Refresh()
예제 #5
0
class MyTest():
    def __init__(self):
        pass

    def testBillboard(self):
        avatar = naali.getUserAvatar()
        avatar_pos = avatar.GetComponentRaw("EC_Placeable")

        self.pixmap_label = QLabel()
        self.pixmap_label.size = QSize(200, 200)
        self.pixmap_label.scaledContents = True
        self.pixmap_label.setPixmap(QPixmap('./data/ui/images/naali_icon.png'))

        self.text_label = QLabel()
        self.text_label.size = QSize(300, 50)
        self.text_label.text = "Hello world"

        self.my_widget = QWidget()
        self.my_widget.setLayout(QVBoxLayout())
        self.my_widget.layout().addWidget(self.pixmap_label)
        self.my_widget.layout().addWidget(self.text_label)

        if self.my_widget is None:
            print("Cannot find image file.")
            return

        self.my_entity = naali.createEntity()
        position = self.my_entity.GetOrCreateComponentRaw(
            "EC_Placeable", "pos",
            PythonQt.private.AttributeChange.Disconnected, False)
        position.position = avatar_pos.position

        self.ec_billboard = self.my_entity.GetOrCreateComponentRaw(
            "EC_BillboardWidget", "test",
            PythonQt.private.AttributeChange.Disconnected, False)
        if self.ec_billboard is None:
            print("Cannot create EC_Billboard component.")
            return

        self.ec_billboard.SetPosition(0, 0, 1)
        self.ec_billboard.SetWidth(1)
        self.ec_billboard.SetHeight(1)
        self.ec_billboard.SetWidget(self.my_widget)

        self.size_timer = QTimer()
        self.size_timer.connect("timeout()", self.animateSize)
        self.size_timer.start(100)

        self.text_timer = QTimer()
        self.text_timer.connect("timeout()", self.animateText)
        self.text_timer.start(1000)

    def animateSize(self):
        min_width = 1.0
        max_width = 2.0
        min_height = 1.0
        max_height = 2.0
        delta_width = max_width - min_width
        delta_height = max_height - min_height
        width = min_width + 0.5 * delta_width + 0.5 * delta_width * math.sin(
            time.time() * 1.324)
        height = min_height + 0.5 * delta_height + 0.5 * delta_height * math.cos(
            time.time() * 2.232)
        self.ec_billboard.SetSize(width, height)

    def animateText(self):
        text = str(float(time.time()))
        self.text_label.text = text
        self.ec_billboard.Refresh()