示例#1
0
 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
示例#2
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
示例#3
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
示例#4
0
    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)
示例#5
0
    def initWidget(self):
        mainBox = QVBoxLayout(self)

        mainBox.addWidget(QLabel("Press " + self.action.shortcut.toString() + " to " +\
                                 self.action.text))
        self.widgets = [_GraspMode(self), _PlacementMode(self)]
        mainBox.addWidget(self.widgets[0])
        mainBox.addWidget(self.widgets[1])
        self.widgets[1].hide()
示例#6
0
    def createWidget(self):
        box = QVBoxLayout(self)
        self.text = "You're in grasp/pregrasp mode.\n" +\
        "In this mode, you can select two object.\n" +\
        "To do so, click on it.\n" +\
        "Once you choose one, press :\n"

        self.addActions(self.actionsList)
        for a in self.actionsList:
            self.text += "  - " + a.shortcut.toString() + " to " + a.text + ".\n"

        box.addWidget(QLabel(self.text, self))
        fBox = QFormLayout()
        self.handleLabel = QLabel("None selected", self)
        fBox.addRow("Current handle", self.handleLabel)
        self.gripperLabel = QLabel("None selected", self)
        fBox.addRow("Current gripper", self.gripperLabel)
        box.addLayout(fBox)

        self.mainWindow.connect("selectJointFromBodyName(QString)", self.changeSelected)
示例#7
0
    def createWidget(self):
        box = QVBoxLayout(self)

        text = "You are in placement mode.\n" +\
               "In this mode you can place an object\non an environment surface.\n" +\
               "The object and the environment must\nhave contact surface defined.\n" +\
               "Press :\n" +\
               "  - " + self.action.shortcut.toString() + " to " + self.action.text + "\n\n" +\
               "First selected body will be\nconsidered as the object.\n" +\
               "Second selected body will be\nconsidered as the environment.\n" +\
               "The object will be place where\nyou clicked on the environment."
        box.addWidget(QLabel(text, self))
示例#8
0
    def __init__(self, title, label1, label2, parent=None):
        super().__init__(parent)
        self.setWindowTitle(title)
        self.lay = QVBoxLayout(self)

        self.lay1 = QHBoxLayout()
        self.label1 = QLabel(label1, self)
        self.lay1.addWidget(self.label1)
        self.input1 = QLineEdit(self)
        self.lay1.addWidget(self.input1)
        self.lay.addLayout(self.lay1)

        self.lay2 = QHBoxLayout()
        self.label2 = QLabel(label2, self)
        self.lay2.addWidget(self.label2)
        self.input2 = QLineEdit(self)
        self.lay2.addWidget(self.input2)
        self.lay.addLayout(self.lay2)

        bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
                                self)
        bbox.connect("accepted()", self.accept)
        bbox.connect("rejected()", self.reject)
        self.lay.addWidget(bbox)
示例#9
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)) 
示例#10
0
    def initWidget(self):
        # Main layout
        mainBox = QVBoxLayout(self)

        # Add text edit to write regex by hand
        box = QVBoxLayout()
        mainBox.addLayout(box)
        self.textEdit = QLineEdit(self)
        box.addWidget(QLabel("You can write your regexp here", self))
        box.addWidget(self.textEdit)
        button = QPushButton("Find", self)
        button.connect("clicked()", self.applyRegex)
        box.addWidget(button)

        # Add grippers list
        self.grippersList = QListWidget(self)
        mainBox.addWidget(self.grippersList)

        # Sub layout for the action type
        box = QHBoxLayout()
        mainBox.addLayout(box)
        self.graspCheck = QCheckBox("Grasp", self)
        box.addWidget(self.graspCheck)
        self.pregraspCheck = QCheckBox("Pregrasp", self)
        box.addWidget(self.pregraspCheck)

        # Add handle list
        self.handlesList = QListWidget(self)
        mainBox.addWidget(self.handlesList)

        # Add a table to display results
        self.resultList = QListWidget(self)
        mainBox.addWidget(self.resultList)

        # Add button to refresh
        button = QPushButton(self)
        button.setText("Refresh")
        button.connect("clicked()", self.refresh)
        mainBox.addWidget(button)

        # Get the grippers and handles names
        # Connect the widget to functions
        self.addConnection()
示例#11
0
	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)
示例#12
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()
示例#13
0
    def __init__(self, cfg, parent):
        super().__init__(parent)
        self.setAttribute(Qt.WA_DeleteOnClose)
        self.setWindowTitle("Eventlog")

        self.cfg = cfg

        self.pauseButton = QPushButton("Pause", self)
        self.pauseButton.setCheckable(True)
        self.pauseButton.connect("toggled(bool)", self.onPauseButtonToggled)
        self.spacer = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                  QSizePolicy.Minimum)
        self.maxLabel = QLabel("Maximum Events:", self)
        self.maxSpin = QSpinBox(self)
        self.maxSpin.setMaximum(10000)
        self.maxSpin.setToolTip("Set to 0 to not shrink events at all")
        self.maxSpin.setValue(cfg.getint("maximumEvents"))
        self.maxSpin.connect("valueChanged(int)", self.onMaxSpinChanged)

        self.sublay1 = QHBoxLayout()
        self.sublay1.addWidget(self.pauseButton)
        self.sublay1.addItem(self.spacer)
        self.sublay1.addWidget(self.maxLabel)
        self.sublay1.addWidget(self.maxSpin)

        self.filterLabel = QLabel("Filter:", self)
        self.filterEdit = QLineEdit(self)
        self.filterEdit.connect("textChanged(QString)",
                                self.onFilterEditChanged)
        self.filterButton = QToolButton(self)
        self.filterButton.connect("clicked()", self.filterEdit.clear)
        try:
            ico = ts3client.IconPack.current()
            ico.open()
            self.filterButton.setIcon(QIcon(ico.icon("ERROR")))
            ico.close()
        except Exception as e:
            self.filterButton.setText("X")

        self.sublay2 = QHBoxLayout()
        self.sublay2.addWidget(self.filterLabel)
        self.sublay2.addWidget(self.filterEdit)
        self.sublay2.addWidget(self.filterButton)

        self.model = EventlogModel(self)
        self.model.maximumEvents = cfg.getint("maximumEvents")
        self.proxy = QSortFilterProxyModel(self)
        self.proxy.setFilterRole(Qt.UserRole)
        self.proxy.setSourceModel(self.model)

        self.tree = QTreeView(self)
        self.tree.header().hide()
        self.tree.setModel(self.proxy)

        self.lay = QVBoxLayout(self)
        self.lay.addLayout(self.sublay1)
        self.lay.addLayout(self.sublay2)
        self.lay.addWidget(self.tree)

        self.resize(cfg.getint("width"), cfg.getint("height"))

        self.connect("finished(int)", self.onFinished)
示例#14
0
    #~ thingie.delete()

    #~ r.pw.show()

if 0:
    box = r.formwidget.findChild("QGridLayout", "gridLayout")
    print box.rowCount()

if 0:
    from PythonQt.QtCore import QFile, QSize
    from PythonQt.QtGui import QLineEdit, QHBoxLayout, QComboBox, QLabel, QPushButton, QSizePolicy, QIcon

    box = r.formwidget.findChild("QGridLayout", "gridLayout")
    #print box.rowCount()

    label = QLabel()
    label.text = "n/a"

    row = 3

    box.addWidget(label, row, 0)
    #print r.c.materialDialogFormWidget
    line = QLineEdit()  #QLineEdit()
    line.text = "whee"
    line.name = "whee"

    box.addWidget(line, row, 1)

    button = QPushButton()
    icon = QIcon("pymodules/editgui/ok.png")
    icon.actualSize(QSize(16, 16))
示例#15
0
文件: window.py 项目: A-K/naali
class ObjectEditWindow:
    UIFILE = "pymodules/objectedit/editobject.ui"
    
    ICON_FOLDER = "pymodules/objectedit/folder.png"
    ICON_OK = "pymodules/objectedit/ok-small.png"
    ICON_CANCEL = "pymodules/objectedit/cancel-small.png" 
    
    def __init__(self, controller):
        self.controller = controller
        loader = QUiLoader()
        loader.setLanguageChangeEnabled(True)
        uifile = QFile(self.UIFILE)

        ui = loader.load(uifile)
        width = ui.size.width()
        height = ui.size.height()
        
        uism = naali.ui

        self.widget = ui

        # Material/Texture widgets
        self.materialTabFormWidget = ui.findChild("QWidget", "MaterialsTab").formLayoutWidget

        # Mesh line edit and buttons
        self.meshline = lines.MeshAssetidEditline(controller) 
        self.meshline.name = "meshLineEdit"

        button_ok = self.getButton("Apply", self.ICON_OK, self.meshline, self.meshline.applyAction)
        button_cancel = self.getButton("Cancel", self.ICON_CANCEL, self.meshline, self.meshline.cancelAction)
        button_browse = self.getButton("Browse", self.ICON_FOLDER, None, None)
        
        box = QHBoxLayout()
        box.setContentsMargins(0,0,0,0)
        box.addWidget(self.meshline)
        box.addWidget(button_browse)
        box.addWidget(button_ok)
        box.addWidget(button_cancel)
        self.mesh_widget = QWidget()
        self.mesh_widget.setLayout(box)
        
        # Sound line edit and buttons
        self.soundline = lines.SoundAssetidEditline(controller) 
        self.soundline.name = "soundLineEdit"
        soundbutton_ok = self.getButton("Apply", self.ICON_OK, self.soundline, self.soundline.applyAction)
        soundbutton_cancel = self.getButton("Cancel", self.ICON_CANCEL, self.soundline, self.soundline.cancelAction)
        soundbutton_browse = self.getButton("Browse", self.ICON_FOLDER, None, None)
        soundRadius = self.getDoubleSpinBox("soundRadius", "Set sound radius", self.soundline)
        soundVolume = self.getDoubleSpinBox("soundVolume", "Set sound volume", self.soundline)
        
        main_box = QVBoxLayout()
        main_box.setContentsMargins(0,0,0,0)
        box_buttons = QHBoxLayout()
        box_buttons.setContentsMargins(0,0,0,0)
        
        # TODO no need for self?
        # crashed always if didnt put self to second label :P you can try to remove them...
        # basically the qwidget ptr must stay somewhere in py otherwise will crash when gets to painting -Pforce
        self.label_radius = QLabel("Radius")
        self.label_radius.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)
        self.label_volume = QLabel("Volume")
        self.label_volume.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)

        box_buttons.addWidget(self.label_radius)
        box_buttons.addWidget(soundRadius)
        box_buttons.addWidget(self.label_volume)
        box_buttons.addWidget(soundVolume)
        box_buttons.addWidget(soundbutton_browse)        
        box_buttons.addWidget(soundbutton_ok)
        box_buttons.addWidget(soundbutton_cancel)

        main_box.addWidget(self.soundline)
        main_box.addLayout(box_buttons)
        self.sound_widget = QWidget()
        self.sound_widget.setLayout(main_box)

        # Animation line edit and buttons
        self.animation_title = QLabel("Skeleton Animation")
        self.animation_title.setStyleSheet("font-size:18px;font-weight:bold;padding-top:5px;")
        self.animation_title.setIndent(0)
        self.animationline = lines.AnimationAssetidEditline(controller)
        self.animationline.name = "animationLineEdit"
        animation_combobox = self.getCombobox("AnimationName", "Animation Name", self.animationline)
        animationbutton_ok = self.getButton("Apply", self.ICON_OK, self.animationline, self.animationline.applyAction)
        animationbutton_cancel = self.getButton("Cancel", self.ICON_CANCEL, self.animationline, self.animationline.cancelAction)
        animationbutton_browse = self.getButton("Browse", self.ICON_FOLDER, None, None)
        animationRate = self.getDoubleSpinBox("animationRate", "Set animation rate", self.animationline)

        animationbox = QVBoxLayout()
        animationbox.setContentsMargins(0,0,0,0)
        self.anim_box_buttons = QHBoxLayout()
        self.anim_box_buttons.name = "AnimBoxButtons"
        self.anim_box_buttons.setContentsMargins(0,0,0,0)

        label_rate = QLabel("Rate")
        label_rate.name = "Animation Rate"
        label_rate.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)

        self.anim_box_buttons.addWidget(animation_combobox)
        self.anim_box_buttons.addWidget(label_rate)
        self.anim_box_buttons.addWidget(animationRate)
        self.anim_box_buttons.addWidget(animationbutton_browse)
        self.anim_box_buttons.addWidget(animationbutton_ok)
        self.anim_box_buttons.addWidget(animationbutton_cancel)

        animationbox.addWidget(self.animation_title)
        animationbox.addWidget(self.animationline)
        animationbox.addLayout(self.anim_box_buttons)
        self.animation_widget = QWidget()
        self.animation_widget.setLayout(animationbox)
        self.animation_widget.hide()

        self.updatingSelection = False
        
        # mesh buttons
        self.meshline.connect('textEdited(QString)', button_ok.lineValueChanged)
        self.meshline.connect('textEdited(QString)', button_cancel.lineValueChanged)

        # audio buttons
        self.soundline.connect('textEdited(QString)', soundbutton_ok.lineValueChanged)
        self.soundline.connect('textEdited(QString)', soundbutton_cancel.lineValueChanged)
        soundRadius.connect('valueChanged(double)', soundbutton_ok.lineValueChanged)
        soundRadius.connect('valueChanged(double)', soundbutton_cancel.lineValueChanged)
        soundVolume.connect('valueChanged(double)', soundbutton_ok.lineValueChanged)
        soundVolume.connect('valueChanged(double)', soundbutton_cancel.lineValueChanged)

        # animation buttons
        self.animationline.connect('textEdited(QString)', animationbutton_ok.lineValueChanged)
        self.animationline.connect('textEdited(QString)', animationbutton_cancel.lineValueChanged)
        animationRate.connect('valueChanged(double)', animationbutton_ok.lineValueChanged)
        animationRate.connect('valueChanged(double)', animationbutton_cancel.lineValueChanged)
        animation_combobox.connect('currentIndexChanged(int)', animationbutton_ok.lineValueChanged)
        animation_combobox.connect('currentIndexChanged(int)', animationbutton_cancel.lineValueChanged)

        self.mainTabList = {}
        self.currentlySelectedTreeWidgetItem = []

    def selected(self, ent, keepold=False):
        self.meshline.update_text(ent.prim.MeshID)
        self.soundline.update_text(ent.prim.SoundID)
        self.soundline.update_soundradius(ent.prim.SoundRadius)
        self.soundline.update_soundvolume(ent.prim.SoundVolume)
        self.updateAnimation(ent)
        self.updateMaterialTab(ent)
        self.updatingSelection = True
        self.update_guivals(ent)
        self.updatingSelection = False
        self.controller.soundRuler(ent)
        
    def deselected(self):
        self.meshline.update_text("")
        self.soundline.update_text("")
        self.updateAnimation()
        
    def update_guivals(self, ent):
        if ent is not None:
            self.update_posvals(ent.placeable.Position)
            self.update_scalevals(ent.placeable.Scale)
            self.update_rotvals(ent.placeable)
            #self.controller.updateSelectionBox(ent) #PositionAndOrientation(ent)
        
    def update_scalevals(self, scale):
        if self.controller.cpp_python_handler != None:
            self.controller.cpp_python_handler.SetScaleValues(scale.x(), scale.y(), scale.z())

    def update_posvals(self, pos):
        if self.controller.cpp_python_handler != None:
            self.controller.cpp_python_handler.SetPosValues(pos.x(), pos.y(), pos.z())

    def update_rotvals(self, placeable):
        # We use now pitch, yaw and roll we get directly from placeable
        # this ensures we don't have to do weird conversions with all
        # potential problems :)
        # TODO: figure out this shift - Looks like we need to give Ogre-style
        # info. Yaw in viewer is around z axis, but placeable gets
        # directly Ogre orientation
        x_val = math.degrees(placeable.Pitch)
        y_val = math.degrees(placeable.Yaw)
        z_val = math.degrees(placeable.Roll)
        if self.controller.cpp_python_handler != None:
            self.controller.cpp_python_handler.SetRotateValues(x_val, y_val, z_val)
    
    def updateAnimation(self, ent = None):
        # Hide by default
        self.animation_widget.setVisible(False)
        self.animationline.update_text("")
        self.animationline.update_animationrate(0.0)
        combobox = self.animationline.combobox
        combobox.clear()
        # Return if no mesh
        if not ent:
            return
        try:
            ent.mesh
        except:
            return
        # Show, update animation id and rate
        self.animation_widget.setVisible(True)
        self.animationline.update_text(ent.prim.AnimationPackageID)
        self.animationline.update_animationrate(ent.prim.AnimationRate)
        # Down update other elements if no asset ref in place
        if ent.prim.AnimationPackageID in (u'', '00000000-0000-0000-0000-000000000000'):
            return
        # Get anim component
        try:
            ac = ent.animationcontroller
        except:
            ent.GetOrCreateComponentRaw('EC_AnimationController')
            ac = ent.animationcontroller
            ac.SetNetworkSyncEnabled(False)
            ac.SetMeshEntity(ent.mesh)
        # Update rest of the ui
        current_animation = ent.prim.AnimationName
        available_animations = ac.GetAvailableAnimations()
        for anim in available_animations:
            combobox.addItem(anim)
        if current_animation in available_animations:
            idx = combobox.findText(current_animation)
            combobox.setCurrentIndex(idx)
        # Deactivate as this is the current data, no changes made
        self.animationline.deactivateButtons()

    def updateMaterialTab(self, ent):
        #ent = self.controller.active
        if ent is not None:
            self.clearDialogForm()
            qprim = ent.prim
            mats = qprim.Materials

            for i in range(len(mats)):
                index = str(i)
                tuple = mats[index]
                line = lines.UUIDEditLine(self.controller)
                line.update_text(tuple[1])
                line.name = index
                asset_type = tuple[0]
                    
                combobox = QComboBox()
                for text in PRIMTYPES.itervalues():
                    combobox.addItem(text)
                
                if PRIMTYPES.has_key(asset_type):
                    realIndex = combobox.findText(PRIMTYPES[asset_type])
                    combobox.setCurrentIndex(realIndex)
                
                applyButton = self.getButton("materialApplyButton", self.ICON_OK, line, line.applyAction)
                cancelButton = self.getButton("materialCancelButton", self.ICON_CANCEL, line, line.cancelAction)
                line.index = index
                line.combobox = combobox
                line.connect('textEdited(QString)', applyButton.lineValueChanged)
                line.connect('textEdited(QString)', cancelButton.lineValueChanged)
                
                box = QHBoxLayout()
                box.addWidget(line)
                box.addWidget(applyButton)
                box.addWidget(cancelButton)
                
                self.materialTabFormWidget.materialFormLayout.addRow(combobox, box)

    def clearDialogForm(self):
        children = self.materialTabFormWidget.children()
        for child in children:
            if child.name != "materialFormLayout": #dont want to remove the actual form layout from the widget
                self.materialTabFormWidget.materialFormLayout.removeWidget(child)
                child.delete()
        
        children = self.materialTabFormWidget.findChildren("QHBoxLayout")
        for child in children:
            self.materialTabFormWidget.materialFormLayout.removeItem(child)
            child.delete()

    def getButton(self, name, iconname, line, action):
        size = QSize(20, 20)
        button = buttons.PyPushButton()
        icon = QIcon(QPixmap(iconname).scaled(size))
        button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        button.setMaximumSize(size)
        button.setMinimumSize(size)
        button.text = ""
        button.name = name
        button.setIcon(icon)
        button.setFlat(True)
        if action != None:
            button.connect('clicked()', action)
        if line != None:
            button.setEnabled(False)
            line.buttons.append(button)
        return button

    def getDoubleSpinBox(self, name, tooltip, line):
        spinner = QDoubleSpinBox()
        spinner.setValue(0.0)
        spinner.name = name
        spinner.toolTip = tooltip
        spinner.setEnabled(True)
        line.spinners.append(spinner)
        return spinner

    def getCombobox(self, name, tooltip, line):
        combobox = QComboBox()
        combobox.name = name
        combobox.toolTip = tooltip
        combobox.setEnabled(True)
        line.combobox = combobox
        return combobox
示例#16
0
class _GraspMode(QWidget):
    def __init__(self, parent):
        super(_GraspMode, self).__init__(parent)
        self.parentInstance = parent
        self.mainWindow = parent.mainWindow
        self.selectedHandles = []
        self.selectedGrippers = []
        self.grippers = []
        self.handles = []
        self.locked = []
        self.groupName = ""
        self.currentGripper = 0
        self.currentHandle = 0
        self.actionsList = []

        self.initActions()
        self.createWidget()

    def initActions(self):
        action = QAction("Choose as gripper", self)
        action.connect("triggered()", self.selectGripper)
        action.setShortcut(QKeySequence(QNamespace.Key_R))
        self.addAction(action)
        self.actionsList.append(action)
        self.mainWindow.registerShortcut(self.parentInstance.plugin.windowTitle, "Choose as gripper", action)

        action = QAction("Choose handle", self)
        action.connect("triggered()", self.selectHandle)
        action.setShortcut(QKeySequence(QNamespace.Key_H))
        self.addAction(action)
        self.actionsList.append(action)
        self.mainWindow.registerShortcut(self.parentInstance.plugin.windowTitle, "Choose as handle", action)

        action = QAction("Grasp from current", self.parentInstance)
        action.connect("triggered()", self.graspCurrent)
        action.setShortcut(QKeySequence(QNamespace.Key_G))
        self.mainWindow.registerShortcut(self.parentInstance.plugin.windowTitle, action)
        self.actionsList.append(action)

        action = QAction("Grasp from random", self.parentInstance)
        action.connect("triggered()", self.graspRandom)
        action.setShortcut(QKeySequence(QNamespace.ShiftModifier + QNamespace.Key_G))
        self.mainWindow.registerShortcut(self.parentInstance.plugin.windowTitle, action)
        self.actionsList.append(action)

        action = QAction("Pregrasp from current", self.parentInstance)
        action.connect("triggered()", self.pregraspCurrent)
        action.setShortcut(QKeySequence(QNamespace.Key_P))
        self.mainWindow.registerShortcut(self.parentInstance.plugin.windowTitle, action)
        self.actionsList.append(action)

        action = QAction("Pregrasp from random", self.parentInstance)
        action.connect("triggered()", self.pregraspRandom)
        action.setShortcut(QKeySequence(QNamespace.ShiftModifier + QNamespace.Key_P))
        self.mainWindow.registerShortcut(self.parentInstance.plugin.windowTitle, action)
        self.actionsList.append(action)

        action = QAction("Change handle used", self.parentInstance)
        action.connect("triggered()", self.changeHandle)
        action.setShortcut(QKeySequence(QNamespace.Key_F1))
        self.mainWindow.registerShortcut(self.parentInstance.plugin.windowTitle, action)
        self.actionsList.append(action)

        action = QAction("Change gripper used", self.parentInstance)
        action.connect("triggered()", self.changeGripper)
        action.setShortcut(QKeySequence(QNamespace.Key_F2))
        self.mainWindow.registerShortcut(self.parentInstance.plugin.windowTitle, action)
        self.actionsList.append(action)

        action = QAction("Lock current object", self.parentInstance)
        action.connect("triggered()", self.lock)
        action.setShortcut(QKeySequence(QNamespace.Key_L))
        self.mainWindow.registerShortcut(self.parentInstance.windowTitle, action)
        self.actionsList.append(action)

    def createWidget(self):
        box = QVBoxLayout(self)
        self.text = "You're in grasp/pregrasp mode.\n" +\
        "In this mode, you can select two object.\n" +\
        "To do so, click on it.\n" +\
        "Once you choose one, press :\n"

        self.addActions(self.actionsList)
        for a in self.actionsList:
            self.text += "  - " + a.shortcut.toString() + " to " + a.text + ".\n"

        box.addWidget(QLabel(self.text, self))
        fBox = QFormLayout()
        self.handleLabel = QLabel("None selected", self)
        fBox.addRow("Current handle", self.handleLabel)
        self.gripperLabel = QLabel("None selected", self)
        fBox.addRow("Current gripper", self.gripperLabel)
        box.addLayout(fBox)

        self.mainWindow.connect("selectJointFromBodyName(QString)", self.changeSelected)

    def changeSelected(self, name):
        self.selected = name.split("/")[0]

    def selectHandle(self):
        if (self.selected != ""):
            self.addHandle(self.selected)

    def selectGripper(self):
        if (self.selected != ""):
            self.addGripper(self.selected)

    def addHandle(self, handleName):
        if (len(self.selectedHandles) == 1):
            self.parentInstance.plugin.client.viewer.gui.deleteNode(self.groupName, True)
        self.selectedHandles = [str(handleName)]
        self.handles = self.getAvailable(handleName + "/", "handle")
        self.currentHandle = 0
        if (len(self.handles)):
            config = self.parentInstance.plugin.client.manipulation.robot.getHandlePositionInJoint(self.handles[self.currentHandle])
            self.handleLabel.setText(self.handles[self.currentHandle])
            self.drawXYZAxis("handle_"+self.handles[self.currentHandle].replace("/", "_"), config)
        else:
            self.handleLabel.setText("None selected")

    def addGripper(self, gripperName):
        if (len(self.selectedGrippers) == 1):
            self.parentInstance.plugin.client.viewer.gui.deleteNode(self.groupName, True)
        self.selectedGrippers = [str(gripperName)]
        self.grippers = self.getAvailable(gripperName + "/", "gripper")
        self.currentGripper = 0
        self.locked = []
        if (len(self.grippers) > 0):
            self.gripperLabel.setText(self.grippers[self.currentGripper])
            config = self.parentInstance.plugin.client.manipulation.robot.getGripperPositionInJoint(self.grippers[self.currentGripper])
            self.drawXYZAxis("gripper_"+self.grippers[self.currentGripper].replace("/", "_"), config)
        else:
            self.gripperLabel.setText("None selected")

    def getAvailable(self, comp, t):
        l = self.parentInstance.plugin.client.manipulation.problem.getAvailable(t)
        ret = []
        for name in l:
            if (name.startswith(comp)):
                ret.append(name)
        return ret
        
    def drawXYZAxis(self, name, config):
        obj = self.mainWindow.getFromSlot("requestCreateJointGroup")
        self.groupName = str(obj.requestCreateJointGroup(config[0]))
        self.parentInstance.plugin.client.viewer.gui.addXYZaxis(name, [0, 1, 0, 1], 0.005, 0.015)
        self.parentInstance.plugin.client.viewer.gui.applyConfiguration(name, fromHPP(config[1])) # XYZW -> WXYZ
        self.parentInstance.plugin.client.viewer.gui.addToGroup(name, self.groupName)
        self.parentInstance.plugin.client.viewer.gui.refresh()

    def changeHandle(self):
        if (len(self.handles) > 0):
            previous = self.currentHandle
            self.currentHandle += 1
            if (self.currentHandle == len(self.handles)):
                self.currentHandle = 0
            self.handleLabel.setText(self.handles[self.currentHandle])
            if (previous != self.currentHandle):
                self.parentInstance.plugin.client.viewer.gui.deleteNode(self.groupName, True)
                config = self.parentInstance.plugin.client.manipulation.robot.getHandlePositionInJoint(self.handles[self.currentHandle])
                self.drawXYZAxis("handle_"+self.handles[self.currentHandle].replace("/", "_"), config)

    def changeGripper(self):
        if (len(self.grippers) > 0):
            previous = self.currentGripper
            self.currentGripper += 1
            if (self.currentGripper == len(self.grippers)):
                self.currentGripper = 0
            self.gripperLabel.setText(self.grippers[self.currentGripper])
            if (self.currentGripper != previous):
                self.parentInstance.plugin.client.viewer.gui.deleteNode(self.groupName, True)
                config = self.parentInstance.plugin.client.manipulation.robot.getGripperPositionInJoint(self.grippers[self.currentGripper])
                self.drawXYZAxis("gripper_"+self.grippers[self.currentGripper].replace("/", "_"), config)

    def graspCurrent(self):
        if (len(self.handles) > 0 and len(self.grippers) > 0):
            self.grasp(self.parentInstance.plugin.client.basic.robot.getCurrentConfig())

    def graspRandom(self):
        if (len(self.handles) > 0 and len(self.grippers) > 0):
            self.grasp(self.parentInstance.plugin.client.basic.robot.shootRandomConfig())

    def grasp(self, config):
        self.parentInstance.plugin.client.basic.problem.resetConstraints()
        for j in self.locked:
            self.parentInstance.plugin.client.basic.problem.lockJoint(j, self.parentInstance.plugin.client.basic.robot.getJointConfig(j))
        name = self.grippers[self.currentGripper] + " grasps " + self.handles[self.currentHandle]
        self.parentInstance.plugin.client.manipulation.problem.createGrasp(name, self.grippers[self.currentGripper], self.handles[self.currentHandle])
        self.parentInstance.plugin.client.basic.problem.addNumericalConstraints("constraints", [name,], [0,])
        res = self.parentInstance.plugin.client.basic.problem.applyConstraints(config)
        if res[0] == True:
            self.parentInstance.plugin.client.basic.robot.setCurrentConfig(res[1])
            self.mainWindow.requestApplyCurrentConfiguration()

    def pregraspCurrent(self):
        if (len(self.handles) > 0 and len(self.grippers) > 0):
            self.pregrasp(self.parentInstance.plugin.client.basic.robot.getCurrentConfig())

    def pregraspRandom(self):
        if (len(self.handles) > 0 and len(self.grippers) > 0):
            self.pregrasp(self.parentInstance.plugin.client.basic.robot.shootRandomConfig())

    def pregrasp(self, config):
        self.parentInstance.plugin.client.basic.problem.resetConstraints()
        for j in self.locked:
            self.parentInstance.plugin.client.basic.problem.lockJoint(name, self.parentInstance.plugin.client.basic.robot.getJointConfig())
        name = self.grippers[self.currentGripper] + " pregrasps " + self.handles[self.currentHandle]
        self.parentInstance.plugin.client.manipulation.problem.createGrasp(name, self.grippers[self.currentGripper], self.handles[self.currentHandle])
        self.parentInstance.plugin.client.basic.problem.addNumericalConstraints("constraints", [name], [True])
        res = self.parentInstance.plugin.client.basic.problem.applyConstraints(self.parentInstance.plugin.client.basic.robot.getCurrentConfig())
        if (res[0] == True):
            self.parentInstance.plugin.client.basic.robot.setCurrentConfig(res[1])
            self.mainWindow.requestApplyCurrentConfiguration()

    def lock(self):
        if (self.selected != ""):
            self.locked = []
            joints = self.parentInstance.plugin.client.basic.robot.getAllJointNames()
            name = self.selected + "/"
            for j in joints:
                if j.startswith(name):
                    self.locked.append(j)
示例#17
0
    def __init__(self, controller):
        self.controller = controller
        loader = QUiLoader()
        loader.setLanguageChangeEnabled(True)
        uifile = QFile(self.UIFILE)

        ui = loader.load(uifile)
        width = ui.size.width()
        height = ui.size.height()

        uism = naali.ui

        self.widget = ui

        # Material/Texture widgets
        self.materialTabFormWidget = ui.findChild(
            "QWidget", "MaterialsTab").formLayoutWidget

        # Mesh line edit and buttons
        self.meshline = lines.MeshAssetidEditline(controller)
        self.meshline.name = "meshLineEdit"

        button_ok = self.getButton("Apply", self.ICON_OK, self.meshline,
                                   self.meshline.applyAction)
        button_cancel = self.getButton("Cancel", self.ICON_CANCEL,
                                       self.meshline,
                                       self.meshline.cancelAction)
        button_browse = self.getButton("Browse", self.ICON_FOLDER, None, None)

        box = QHBoxLayout()
        box.setContentsMargins(0, 0, 0, 0)
        box.addWidget(self.meshline)
        box.addWidget(button_browse)
        box.addWidget(button_ok)
        box.addWidget(button_cancel)
        self.mesh_widget = QWidget()
        self.mesh_widget.setLayout(box)

        # Sound line edit and buttons
        self.soundline = lines.SoundAssetidEditline(controller)
        self.soundline.name = "soundLineEdit"
        soundbutton_ok = self.getButton("Apply", self.ICON_OK, self.soundline,
                                        self.soundline.applyAction)
        soundbutton_cancel = self.getButton("Cancel", self.ICON_CANCEL,
                                            self.soundline,
                                            self.soundline.cancelAction)
        soundbutton_browse = self.getButton("Browse", self.ICON_FOLDER, None,
                                            None)
        soundRadius = self.getDoubleSpinBox("soundRadius", "Set sound radius",
                                            self.soundline)
        soundVolume = self.getDoubleSpinBox("soundVolume", "Set sound volume",
                                            self.soundline)

        main_box = QVBoxLayout()
        main_box.setContentsMargins(0, 0, 0, 0)
        box_buttons = QHBoxLayout()
        box_buttons.setContentsMargins(0, 0, 0, 0)

        # TODO no need for self?
        # crashed always if didnt put self to second label :P you can try to remove them...
        # basically the qwidget ptr must stay somewhere in py otherwise will crash when gets to painting -Pforce
        self.label_radius = QLabel("Radius")
        self.label_radius.setSizePolicy(QSizePolicy.Fixed,
                                        QSizePolicy.Preferred)
        self.label_volume = QLabel("Volume")
        self.label_volume.setSizePolicy(QSizePolicy.Fixed,
                                        QSizePolicy.Preferred)

        box_buttons.addWidget(self.label_radius)
        box_buttons.addWidget(soundRadius)
        box_buttons.addWidget(self.label_volume)
        box_buttons.addWidget(soundVolume)
        box_buttons.addWidget(soundbutton_browse)
        box_buttons.addWidget(soundbutton_ok)
        box_buttons.addWidget(soundbutton_cancel)

        main_box.addWidget(self.soundline)
        main_box.addLayout(box_buttons)
        self.sound_widget = QWidget()
        self.sound_widget.setLayout(main_box)

        # Animation line edit and buttons
        self.animation_title = QLabel("Skeleton Animation")
        self.animation_title.setStyleSheet(
            "font-size:18px;font-weight:bold;padding-top:5px;")
        self.animation_title.setIndent(0)
        self.animationline = lines.AnimationAssetidEditline(controller)
        self.animationline.name = "animationLineEdit"
        animation_combobox = self.getCombobox("AnimationName",
                                              "Animation Name",
                                              self.animationline)
        animationbutton_ok = self.getButton("Apply", self.ICON_OK,
                                            self.animationline,
                                            self.animationline.applyAction)
        animationbutton_cancel = self.getButton(
            "Cancel", self.ICON_CANCEL, self.animationline,
            self.animationline.cancelAction)
        animationbutton_browse = self.getButton("Browse", self.ICON_FOLDER,
                                                None, None)
        animationRate = self.getDoubleSpinBox("animationRate",
                                              "Set animation rate",
                                              self.animationline)

        animationbox = QVBoxLayout()
        animationbox.setContentsMargins(0, 0, 0, 0)
        self.anim_box_buttons = QHBoxLayout()
        self.anim_box_buttons.name = "AnimBoxButtons"
        self.anim_box_buttons.setContentsMargins(0, 0, 0, 0)

        label_rate = QLabel("Rate")
        label_rate.name = "Animation Rate"
        label_rate.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)

        self.anim_box_buttons.addWidget(animation_combobox)
        self.anim_box_buttons.addWidget(label_rate)
        self.anim_box_buttons.addWidget(animationRate)
        self.anim_box_buttons.addWidget(animationbutton_browse)
        self.anim_box_buttons.addWidget(animationbutton_ok)
        self.anim_box_buttons.addWidget(animationbutton_cancel)

        animationbox.addWidget(self.animation_title)
        animationbox.addWidget(self.animationline)
        animationbox.addLayout(self.anim_box_buttons)
        self.animation_widget = QWidget()
        self.animation_widget.setLayout(animationbox)
        self.animation_widget.hide()

        self.updatingSelection = False

        # mesh buttons
        self.meshline.connect('textEdited(QString)',
                              button_ok.lineValueChanged)
        self.meshline.connect('textEdited(QString)',
                              button_cancel.lineValueChanged)

        # audio buttons
        self.soundline.connect('textEdited(QString)',
                               soundbutton_ok.lineValueChanged)
        self.soundline.connect('textEdited(QString)',
                               soundbutton_cancel.lineValueChanged)
        soundRadius.connect('valueChanged(double)',
                            soundbutton_ok.lineValueChanged)
        soundRadius.connect('valueChanged(double)',
                            soundbutton_cancel.lineValueChanged)
        soundVolume.connect('valueChanged(double)',
                            soundbutton_ok.lineValueChanged)
        soundVolume.connect('valueChanged(double)',
                            soundbutton_cancel.lineValueChanged)

        # animation buttons
        self.animationline.connect('textEdited(QString)',
                                   animationbutton_ok.lineValueChanged)
        self.animationline.connect('textEdited(QString)',
                                   animationbutton_cancel.lineValueChanged)
        animationRate.connect('valueChanged(double)',
                              animationbutton_ok.lineValueChanged)
        animationRate.connect('valueChanged(double)',
                              animationbutton_cancel.lineValueChanged)
        animation_combobox.connect('currentIndexChanged(int)',
                                   animationbutton_ok.lineValueChanged)
        animation_combobox.connect('currentIndexChanged(int)',
                                   animationbutton_cancel.lineValueChanged)

        self.mainTabList = {}
        self.currentlySelectedTreeWidgetItem = []
示例#18
0
class ObjectEditWindow:
    UIFILE = "pymodules/objectedit/editobject.ui"

    ICON_FOLDER = "pymodules/objectedit/folder.png"
    ICON_OK = "pymodules/objectedit/ok-small.png"
    ICON_CANCEL = "pymodules/objectedit/cancel-small.png"

    def __init__(self, controller):
        self.controller = controller
        loader = QUiLoader()
        loader.setLanguageChangeEnabled(True)
        uifile = QFile(self.UIFILE)

        ui = loader.load(uifile)
        width = ui.size.width()
        height = ui.size.height()

        uism = naali.ui

        self.widget = ui

        # Material/Texture widgets
        self.materialTabFormWidget = ui.findChild(
            "QWidget", "MaterialsTab").formLayoutWidget

        # Mesh line edit and buttons
        self.meshline = lines.MeshAssetidEditline(controller)
        self.meshline.name = "meshLineEdit"

        button_ok = self.getButton("Apply", self.ICON_OK, self.meshline,
                                   self.meshline.applyAction)
        button_cancel = self.getButton("Cancel", self.ICON_CANCEL,
                                       self.meshline,
                                       self.meshline.cancelAction)
        button_browse = self.getButton("Browse", self.ICON_FOLDER, None, None)

        box = QHBoxLayout()
        box.setContentsMargins(0, 0, 0, 0)
        box.addWidget(self.meshline)
        box.addWidget(button_browse)
        box.addWidget(button_ok)
        box.addWidget(button_cancel)
        self.mesh_widget = QWidget()
        self.mesh_widget.setLayout(box)

        # Sound line edit and buttons
        self.soundline = lines.SoundAssetidEditline(controller)
        self.soundline.name = "soundLineEdit"
        soundbutton_ok = self.getButton("Apply", self.ICON_OK, self.soundline,
                                        self.soundline.applyAction)
        soundbutton_cancel = self.getButton("Cancel", self.ICON_CANCEL,
                                            self.soundline,
                                            self.soundline.cancelAction)
        soundbutton_browse = self.getButton("Browse", self.ICON_FOLDER, None,
                                            None)
        soundRadius = self.getDoubleSpinBox("soundRadius", "Set sound radius",
                                            self.soundline)
        soundVolume = self.getDoubleSpinBox("soundVolume", "Set sound volume",
                                            self.soundline)

        main_box = QVBoxLayout()
        main_box.setContentsMargins(0, 0, 0, 0)
        box_buttons = QHBoxLayout()
        box_buttons.setContentsMargins(0, 0, 0, 0)

        # TODO no need for self?
        # crashed always if didnt put self to second label :P you can try to remove them...
        # basically the qwidget ptr must stay somewhere in py otherwise will crash when gets to painting -Pforce
        self.label_radius = QLabel("Radius")
        self.label_radius.setSizePolicy(QSizePolicy.Fixed,
                                        QSizePolicy.Preferred)
        self.label_volume = QLabel("Volume")
        self.label_volume.setSizePolicy(QSizePolicy.Fixed,
                                        QSizePolicy.Preferred)

        box_buttons.addWidget(self.label_radius)
        box_buttons.addWidget(soundRadius)
        box_buttons.addWidget(self.label_volume)
        box_buttons.addWidget(soundVolume)
        box_buttons.addWidget(soundbutton_browse)
        box_buttons.addWidget(soundbutton_ok)
        box_buttons.addWidget(soundbutton_cancel)

        main_box.addWidget(self.soundline)
        main_box.addLayout(box_buttons)
        self.sound_widget = QWidget()
        self.sound_widget.setLayout(main_box)

        # Animation line edit and buttons
        self.animation_title = QLabel("Skeleton Animation")
        self.animation_title.setStyleSheet(
            "font-size:18px;font-weight:bold;padding-top:5px;")
        self.animation_title.setIndent(0)
        self.animationline = lines.AnimationAssetidEditline(controller)
        self.animationline.name = "animationLineEdit"
        animation_combobox = self.getCombobox("AnimationName",
                                              "Animation Name",
                                              self.animationline)
        animationbutton_ok = self.getButton("Apply", self.ICON_OK,
                                            self.animationline,
                                            self.animationline.applyAction)
        animationbutton_cancel = self.getButton(
            "Cancel", self.ICON_CANCEL, self.animationline,
            self.animationline.cancelAction)
        animationbutton_browse = self.getButton("Browse", self.ICON_FOLDER,
                                                None, None)
        animationRate = self.getDoubleSpinBox("animationRate",
                                              "Set animation rate",
                                              self.animationline)

        animationbox = QVBoxLayout()
        animationbox.setContentsMargins(0, 0, 0, 0)
        self.anim_box_buttons = QHBoxLayout()
        self.anim_box_buttons.name = "AnimBoxButtons"
        self.anim_box_buttons.setContentsMargins(0, 0, 0, 0)

        label_rate = QLabel("Rate")
        label_rate.name = "Animation Rate"
        label_rate.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)

        self.anim_box_buttons.addWidget(animation_combobox)
        self.anim_box_buttons.addWidget(label_rate)
        self.anim_box_buttons.addWidget(animationRate)
        self.anim_box_buttons.addWidget(animationbutton_browse)
        self.anim_box_buttons.addWidget(animationbutton_ok)
        self.anim_box_buttons.addWidget(animationbutton_cancel)

        animationbox.addWidget(self.animation_title)
        animationbox.addWidget(self.animationline)
        animationbox.addLayout(self.anim_box_buttons)
        self.animation_widget = QWidget()
        self.animation_widget.setLayout(animationbox)
        self.animation_widget.hide()

        self.updatingSelection = False

        # mesh buttons
        self.meshline.connect('textEdited(QString)',
                              button_ok.lineValueChanged)
        self.meshline.connect('textEdited(QString)',
                              button_cancel.lineValueChanged)

        # audio buttons
        self.soundline.connect('textEdited(QString)',
                               soundbutton_ok.lineValueChanged)
        self.soundline.connect('textEdited(QString)',
                               soundbutton_cancel.lineValueChanged)
        soundRadius.connect('valueChanged(double)',
                            soundbutton_ok.lineValueChanged)
        soundRadius.connect('valueChanged(double)',
                            soundbutton_cancel.lineValueChanged)
        soundVolume.connect('valueChanged(double)',
                            soundbutton_ok.lineValueChanged)
        soundVolume.connect('valueChanged(double)',
                            soundbutton_cancel.lineValueChanged)

        # animation buttons
        self.animationline.connect('textEdited(QString)',
                                   animationbutton_ok.lineValueChanged)
        self.animationline.connect('textEdited(QString)',
                                   animationbutton_cancel.lineValueChanged)
        animationRate.connect('valueChanged(double)',
                              animationbutton_ok.lineValueChanged)
        animationRate.connect('valueChanged(double)',
                              animationbutton_cancel.lineValueChanged)
        animation_combobox.connect('currentIndexChanged(int)',
                                   animationbutton_ok.lineValueChanged)
        animation_combobox.connect('currentIndexChanged(int)',
                                   animationbutton_cancel.lineValueChanged)

        self.mainTabList = {}
        self.currentlySelectedTreeWidgetItem = []

    def selected(self, ent, keepold=False):
        self.meshline.update_text(ent.prim.MeshID)
        self.soundline.update_text(ent.prim.SoundID)
        self.soundline.update_soundradius(ent.prim.SoundRadius)
        self.soundline.update_soundvolume(ent.prim.SoundVolume)
        self.updateAnimation(ent)
        self.updateMaterialTab(ent)
        self.updatingSelection = True
        self.update_guivals(ent)
        self.updatingSelection = False
        self.controller.soundRuler(ent)

    def deselected(self):
        self.meshline.update_text("")
        self.soundline.update_text("")
        self.updateAnimation()

    def update_guivals(self, ent):
        if ent is not None:
            self.update_posvals(ent.placeable.Position)
            self.update_scalevals(ent.placeable.Scale)
            self.update_rotvals(ent.placeable)
            #self.controller.updateSelectionBox(ent) #PositionAndOrientation(ent)

    def update_scalevals(self, scale):
        if self.controller.cpp_python_handler != None:
            self.controller.cpp_python_handler.SetScaleValues(
                scale.x(), scale.y(), scale.z())

    def update_posvals(self, pos):
        if self.controller.cpp_python_handler != None:
            self.controller.cpp_python_handler.SetPosValues(
                pos.x(), pos.y(), pos.z())

    def update_rotvals(self, placeable):
        # We use now pitch, yaw and roll we get directly from placeable
        # this ensures we don't have to do weird conversions with all
        # potential problems :)
        # TODO: figure out this shift - Looks like we need to give Ogre-style
        # info. Yaw in viewer is around z axis, but placeable gets
        # directly Ogre orientation
        x_val = math.degrees(placeable.Pitch)
        y_val = math.degrees(placeable.Yaw)
        z_val = math.degrees(placeable.Roll)
        if self.controller.cpp_python_handler != None:
            self.controller.cpp_python_handler.SetRotateValues(
                x_val, y_val, z_val)

    def updateAnimation(self, ent=None):
        # Hide by default
        self.animation_widget.setVisible(False)
        self.animationline.update_text("")
        self.animationline.update_animationrate(0.0)
        combobox = self.animationline.combobox
        combobox.clear()
        # Return if no mesh
        if not ent:
            return
        try:
            ent.mesh
        except:
            return
        # Show, update animation id and rate
        self.animation_widget.setVisible(True)
        self.animationline.update_text(ent.prim.AnimationPackageID)
        self.animationline.update_animationrate(ent.prim.AnimationRate)
        # Down update other elements if no asset ref in place
        if ent.prim.AnimationPackageID in (
                u'', '00000000-0000-0000-0000-000000000000'):
            return
        # Get anim component
        try:
            ac = ent.animationcontroller
        except:
            ent.GetOrCreateComponentRaw('EC_AnimationController')
            ac = ent.animationcontroller
            ac.SetNetworkSyncEnabled(False)
            ac.SetMeshEntity(ent.mesh)
        # Update rest of the ui
        current_animation = ent.prim.AnimationName
        available_animations = ac.GetAvailableAnimations()
        for anim in available_animations:
            combobox.addItem(anim)
        if current_animation in available_animations:
            idx = combobox.findText(current_animation)
            combobox.setCurrentIndex(idx)
        # Deactivate as this is the current data, no changes made
        self.animationline.deactivateButtons()

    def updateMaterialTab(self, ent):
        #ent = self.controller.active
        if ent is not None:
            self.clearDialogForm()
            qprim = ent.prim
            mats = qprim.Materials

            for i in range(len(mats)):
                index = str(i)
                tuple = mats[index]
                line = lines.UUIDEditLine(self.controller)
                line.update_text(tuple[1])
                line.name = index
                asset_type = tuple[0]

                combobox = QComboBox()
                for text in PRIMTYPES.itervalues():
                    combobox.addItem(text)

                if PRIMTYPES.has_key(asset_type):
                    realIndex = combobox.findText(PRIMTYPES[asset_type])
                    combobox.setCurrentIndex(realIndex)

                applyButton = self.getButton("materialApplyButton",
                                             self.ICON_OK, line,
                                             line.applyAction)
                cancelButton = self.getButton("materialCancelButton",
                                              self.ICON_CANCEL, line,
                                              line.cancelAction)
                line.index = index
                line.combobox = combobox
                line.connect('textEdited(QString)',
                             applyButton.lineValueChanged)
                line.connect('textEdited(QString)',
                             cancelButton.lineValueChanged)

                box = QHBoxLayout()
                box.addWidget(line)
                box.addWidget(applyButton)
                box.addWidget(cancelButton)

                self.materialTabFormWidget.materialFormLayout.addRow(
                    combobox, box)

    def clearDialogForm(self):
        children = self.materialTabFormWidget.children()
        for child in children:
            if child.name != "materialFormLayout":  #dont want to remove the actual form layout from the widget
                self.materialTabFormWidget.materialFormLayout.removeWidget(
                    child)
                child.delete()

        children = self.materialTabFormWidget.findChildren("QHBoxLayout")
        for child in children:
            self.materialTabFormWidget.materialFormLayout.removeItem(child)
            child.delete()

    def getButton(self, name, iconname, line, action):
        size = QSize(20, 20)
        button = buttons.PyPushButton()
        icon = QIcon(QPixmap(iconname).scaled(size))
        button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        button.setMaximumSize(size)
        button.setMinimumSize(size)
        button.text = ""
        button.name = name
        button.setIcon(icon)
        button.setFlat(True)
        if action != None:
            button.connect('clicked()', action)
        if line != None:
            button.setEnabled(False)
            line.buttons.append(button)
        return button

    def getDoubleSpinBox(self, name, tooltip, line):
        spinner = QDoubleSpinBox()
        spinner.setValue(0.0)
        spinner.name = name
        spinner.toolTip = tooltip
        spinner.setEnabled(True)
        line.spinners.append(spinner)
        return spinner

    def getCombobox(self, name, tooltip, line):
        combobox = QComboBox()
        combobox.name = name
        combobox.toolTip = tooltip
        combobox.setEnabled(True)
        line.combobox = combobox
        return combobox
示例#19
0
文件: command.py 项目: Chiru/naali

    #~ r.pw.show()

if 0:
    box = r.formwidget.findChild("QGridLayout", "gridLayout")
    print box.rowCount()
    
if 0:
    from PythonQt.QtCore import QFile, QSize
    from PythonQt.QtGui import QLineEdit, QHBoxLayout, QComboBox, QLabel, QPushButton, QSizePolicy, QIcon
    
    box = r.formwidget.findChild("QGridLayout", "gridLayout")
    #print box.rowCount()

    label = QLabel()
    label.text = "n/a"
    
    row = 3
    
    box.addWidget(label, row, 0)
    #print r.c.materialDialogFormWidget
    line = QLineEdit()#QLineEdit()
    line.text = "whee"
    line.name = "whee"
    
    box.addWidget(line, row, 1)


    button = QPushButton()
    icon = QIcon("pymodules/editgui/ok.png")
示例#20
0
 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 
示例#21
0
文件: window.py 项目: A-K/naali
    def __init__(self, controller):
        self.controller = controller
        loader = QUiLoader()
        loader.setLanguageChangeEnabled(True)
        uifile = QFile(self.UIFILE)

        ui = loader.load(uifile)
        width = ui.size.width()
        height = ui.size.height()
        
        uism = naali.ui

        self.widget = ui

        # Material/Texture widgets
        self.materialTabFormWidget = ui.findChild("QWidget", "MaterialsTab").formLayoutWidget

        # Mesh line edit and buttons
        self.meshline = lines.MeshAssetidEditline(controller) 
        self.meshline.name = "meshLineEdit"

        button_ok = self.getButton("Apply", self.ICON_OK, self.meshline, self.meshline.applyAction)
        button_cancel = self.getButton("Cancel", self.ICON_CANCEL, self.meshline, self.meshline.cancelAction)
        button_browse = self.getButton("Browse", self.ICON_FOLDER, None, None)
        
        box = QHBoxLayout()
        box.setContentsMargins(0,0,0,0)
        box.addWidget(self.meshline)
        box.addWidget(button_browse)
        box.addWidget(button_ok)
        box.addWidget(button_cancel)
        self.mesh_widget = QWidget()
        self.mesh_widget.setLayout(box)
        
        # Sound line edit and buttons
        self.soundline = lines.SoundAssetidEditline(controller) 
        self.soundline.name = "soundLineEdit"
        soundbutton_ok = self.getButton("Apply", self.ICON_OK, self.soundline, self.soundline.applyAction)
        soundbutton_cancel = self.getButton("Cancel", self.ICON_CANCEL, self.soundline, self.soundline.cancelAction)
        soundbutton_browse = self.getButton("Browse", self.ICON_FOLDER, None, None)
        soundRadius = self.getDoubleSpinBox("soundRadius", "Set sound radius", self.soundline)
        soundVolume = self.getDoubleSpinBox("soundVolume", "Set sound volume", self.soundline)
        
        main_box = QVBoxLayout()
        main_box.setContentsMargins(0,0,0,0)
        box_buttons = QHBoxLayout()
        box_buttons.setContentsMargins(0,0,0,0)
        
        # TODO no need for self?
        # crashed always if didnt put self to second label :P you can try to remove them...
        # basically the qwidget ptr must stay somewhere in py otherwise will crash when gets to painting -Pforce
        self.label_radius = QLabel("Radius")
        self.label_radius.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)
        self.label_volume = QLabel("Volume")
        self.label_volume.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)

        box_buttons.addWidget(self.label_radius)
        box_buttons.addWidget(soundRadius)
        box_buttons.addWidget(self.label_volume)
        box_buttons.addWidget(soundVolume)
        box_buttons.addWidget(soundbutton_browse)        
        box_buttons.addWidget(soundbutton_ok)
        box_buttons.addWidget(soundbutton_cancel)

        main_box.addWidget(self.soundline)
        main_box.addLayout(box_buttons)
        self.sound_widget = QWidget()
        self.sound_widget.setLayout(main_box)

        # Animation line edit and buttons
        self.animation_title = QLabel("Skeleton Animation")
        self.animation_title.setStyleSheet("font-size:18px;font-weight:bold;padding-top:5px;")
        self.animation_title.setIndent(0)
        self.animationline = lines.AnimationAssetidEditline(controller)
        self.animationline.name = "animationLineEdit"
        animation_combobox = self.getCombobox("AnimationName", "Animation Name", self.animationline)
        animationbutton_ok = self.getButton("Apply", self.ICON_OK, self.animationline, self.animationline.applyAction)
        animationbutton_cancel = self.getButton("Cancel", self.ICON_CANCEL, self.animationline, self.animationline.cancelAction)
        animationbutton_browse = self.getButton("Browse", self.ICON_FOLDER, None, None)
        animationRate = self.getDoubleSpinBox("animationRate", "Set animation rate", self.animationline)

        animationbox = QVBoxLayout()
        animationbox.setContentsMargins(0,0,0,0)
        self.anim_box_buttons = QHBoxLayout()
        self.anim_box_buttons.name = "AnimBoxButtons"
        self.anim_box_buttons.setContentsMargins(0,0,0,0)

        label_rate = QLabel("Rate")
        label_rate.name = "Animation Rate"
        label_rate.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)

        self.anim_box_buttons.addWidget(animation_combobox)
        self.anim_box_buttons.addWidget(label_rate)
        self.anim_box_buttons.addWidget(animationRate)
        self.anim_box_buttons.addWidget(animationbutton_browse)
        self.anim_box_buttons.addWidget(animationbutton_ok)
        self.anim_box_buttons.addWidget(animationbutton_cancel)

        animationbox.addWidget(self.animation_title)
        animationbox.addWidget(self.animationline)
        animationbox.addLayout(self.anim_box_buttons)
        self.animation_widget = QWidget()
        self.animation_widget.setLayout(animationbox)
        self.animation_widget.hide()

        self.updatingSelection = False
        
        # mesh buttons
        self.meshline.connect('textEdited(QString)', button_ok.lineValueChanged)
        self.meshline.connect('textEdited(QString)', button_cancel.lineValueChanged)

        # audio buttons
        self.soundline.connect('textEdited(QString)', soundbutton_ok.lineValueChanged)
        self.soundline.connect('textEdited(QString)', soundbutton_cancel.lineValueChanged)
        soundRadius.connect('valueChanged(double)', soundbutton_ok.lineValueChanged)
        soundRadius.connect('valueChanged(double)', soundbutton_cancel.lineValueChanged)
        soundVolume.connect('valueChanged(double)', soundbutton_ok.lineValueChanged)
        soundVolume.connect('valueChanged(double)', soundbutton_cancel.lineValueChanged)

        # animation buttons
        self.animationline.connect('textEdited(QString)', animationbutton_ok.lineValueChanged)
        self.animationline.connect('textEdited(QString)', animationbutton_cancel.lineValueChanged)
        animationRate.connect('valueChanged(double)', animationbutton_ok.lineValueChanged)
        animationRate.connect('valueChanged(double)', animationbutton_cancel.lineValueChanged)
        animation_combobox.connect('currentIndexChanged(int)', animationbutton_ok.lineValueChanged)
        animation_combobox.connect('currentIndexChanged(int)', animationbutton_cancel.lineValueChanged)

        self.mainTabList = {}
        self.currentlySelectedTreeWidgetItem = []
示例#22
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()