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()
class DoorHandler(circuits.BaseComponent): GUINAME = "Door Handler" ADDMENU = True def __init__(self, entity, comp, changetype): self.comp = comp circuits.BaseComponent.__init__(self) comp.connect("OnChanged()", self.onChanged) self.inworld_inited = False #a cheap hackish substitute for some initing system self.initgui() def initgui(self): #qt widget ui group = QGroupBox() box = QVBoxLayout(group) self.openbut = QPushButton("init", group) self.lockbut = QPushButton("init", group) box.addWidget(self.openbut) box.addWidget(self.lockbut) self.openbut.connect('clicked()', self.open) self.lockbut.connect('clicked()', self.lock) self.widget = group self.forcepos = None #naali proxywidget boilerplate uism = r.getUiSceneManager() self.proxywidget = r.createUiProxyWidget(self.widget) self.proxywidget.setWindowTitle(self.GUINAME) if not uism.AddWidgetToScene(self.proxywidget): print "Adding the ProxyWidget to the bar failed." uism.AddWidgetToMenu(self.proxywidget, self.GUINAME, "Developer Tools") def onChanged(self): try: ent = r.getEntity(self.comp.GetParentEntityId()) except ValueError: #the entity has been removed or something return print "door data changed" if not self.inworld_inited: #if hasattr(self.comp, 'touchable') try: t = ent.touchable except AttributeError: print "no touchable in door? it doesn't persist yet? adding..", ent.id ent.createComponent("EC_Touchable") t = ent.touchable else: print "touchable pre-existed in door." t.connect('Clicked()', self.open) t.connect('MouseHoverIn()', self.hover_in) t.connect('MouseHoverOut()', self.hover_out) self.inworld_inited = True opened = self.opened locked = self.locked newpos = OPENPOS if opened else CLOSEPOS ent.placeable.Position = newpos #print opened, type(opened), ent.placeable.Position self.openbut.text = "Close" if opened else "Open" self.lockbut.text = "Unlock" if locked else "Lock" if locked and not opened: self.openbut.enabled = False else: self.openbut.enabled = True """NOTE: this code doesn't now sync the normal ob pos to server at all. the object is moved in all clients only. when logging back to a server, wasn't seeing the right positions, probably because server send pos update after the comp sync.""" self.forcepos = ent.placeable.Position def get_opened(self): if self.comp is not None: return self.comp.GetAttribute("opened") else: return None def set_opened(self, newval): self.comp.SetAttribute("opened", newval) self.comp.OnChanged() opened = property(get_opened, set_opened) def get_locked(self): if self.comp is not None: return self.comp.GetAttribute("locked") else: return None def set_locked(self, newval): self.comp.SetAttribute("locked", newval) self.comp.OnChanged() locked = property(get_locked, set_locked) def open(self): #print "open" if self.opened or not self.locked: self.opened = not self.opened print self.opened else: print "Can't open a locked door!" def lock(self): #\todo if has key self.locked = not self.locked def hover_in(self): #XXX add locked check too ctype = 1 if self.opened else 2 setcursor(ctype) def hover_out(self): curr_cursor = qapp.overrideCursor() while curr_cursor != None: qapp.restoreOverrideCursor() curr_cursor = qapp.overrideCursor() @circuits.handler("update") def update(self, t): try: ent = r.getEntity(self.comp.GetParentEntityId()) except ValueError: #the entity has been removed or something return # nothing useful to do anyway if self.forcepos is not None: ent.placeable.Position = self.forcepos @circuits.handler("on_logout") def removegui(self, evid): self.proxywidget.hide() uism = r.getUiSceneManager() uism.RemoveWidgetFromMenu(self.proxywidget) uism.RemoveWidgetFromScene(self.proxywidget)
class EventlogDialog(QDialog): 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) def onMaxSpinChanged(self, val): self.model.maximumEvents = val self.cfg["maximumEvents"] = str(val) def onFilterEditChanged(self, txt): self.proxy.setFilterRegExp(txt) def onPauseButtonToggled(self, checked): if checked: self.model.pause() else: self.model.unpause() def onFinished(self, result): self.cfg["width"] = str(self.width) self.cfg["height"] = str(self.height) def callback(self, name, *args): self.model.callback(name, *args)
class DoorHandler(circuits.BaseComponent): GUINAME = "Door Handler" ADDMENU = True def __init__(self, entity, comp, changetype): self.comp = comp circuits.BaseComponent.__init__(self) comp.connect("OnChanged()", self.onChanged) self.inworld_inited = False #a cheap hackish substitute for some initing system self.initgui() def initgui(self): #qt widget ui group = QGroupBox() box = QVBoxLayout(group) self.openbut = QPushButton("init", group) self.lockbut = QPushButton("init", group) box.addWidget(self.openbut) box.addWidget(self.lockbut) self.openbut.connect('clicked()', self.open) self.lockbut.connect('clicked()', self.lock) self.widget = group self.forcepos = None #naali proxywidget boilerplate uism = r.getUiSceneManager() self.proxywidget = r.createUiProxyWidget(self.widget) self.proxywidget.setWindowTitle(self.GUINAME) if not uism.AddWidgetToScene(self.proxywidget): print "Adding the ProxyWidget to the bar failed." uism.AddWidgetToMenu(self.proxywidget, self.GUINAME, "Developer Tools") def onChanged(self): try: ent = r.getEntity(self.comp.GetParentEntityId()) except ValueError: #the entity has been removed or something return print "door data changed" if not self.inworld_inited: #if hasattr(self.comp, 'touchable') try: t = ent.touchable except AttributeError: print "no touchable in door? it doesn't persist yet? adding..", ent.id ent.createComponent("EC_Touchable") t = ent.touchable else: print "touchable pre-existed in door." t.connect('Clicked()', self.open) t.connect('MouseHoverIn()', self.hover_in) t.connect('MouseHoverOut()', self.hover_out) self.inworld_inited = True opened = self.opened locked = self.locked newpos = OPENPOS if opened else CLOSEPOS ent.placeable.Position = newpos #print opened, type(opened), ent.placeable.Position self.openbut.text = "Close" if opened else "Open" self.lockbut.text = "Unlock" if locked else "Lock" if locked and not opened: self.openbut.enabled = False else: self.openbut.enabled = True """NOTE: this code doesn't now sync the normal ob pos to server at all. the object is moved in all clients only. when logging back to a server, wasn't seeing the right positions, probably because server send pos update after the comp sync.""" self.forcepos = ent.placeable.Position def get_opened(self): if self.comp is not None: return self.comp.GetAttribute("opened") else: return None def set_opened(self, newval): self.comp.SetAttribute("opened", newval) self.comp.OnChanged() opened = property(get_opened, set_opened) def get_locked(self): if self.comp is not None: return self.comp.GetAttribute("locked") else: return None def set_locked(self, newval): self.comp.SetAttribute("locked", newval) self.comp.OnChanged() locked = property(get_locked, set_locked) def open(self): #print "open" if self.opened or not self.locked: self.opened = not self.opened print self.opened else: print "Can't open a locked door!" def lock(self): #\todo if has key self.locked = not self.locked def hover_in(self): #XXX add locked check too ctype = 1 if self.opened else 2 setcursor(ctype) def hover_out(self): curr_cursor = qapp.overrideCursor() while curr_cursor != None: qapp.restoreOverrideCursor() curr_cursor = qapp.overrideCursor() @circuits.handler("update") def update(self, t): try: ent = r.getEntity(self.comp.GetParentEntityId()) except ValueError: #the entity has been removed or something return # nothing useful to do anyway if self.forcepos is not None: ent.placeable.Position = self.forcepos @circuits.handler("on_logout") def removegui(self, evid): self.proxywidget.hide() uism = r.getUiSceneManager() uism.RemoveWidgetFromMenu(self.proxywidget) uism.RemoveWidgetFromScene(self.proxywidget)