def on_power_on(self): try: power = rospy.ServiceProxy("/RobotHardwareServiceROSBridge/power", OpenHRP_RobotHardwareService_power) power(OpenHRP_RobotHardwareService_powerRequest("all", 0)) except Exception, e: mb = QMessageBox(QMessageBox.NoIcon, "Error", "Failed to power on: %s" % (e), QMessageBox.Ok, self.parent()) mb.exec_()
def __init__(self, context): super(NodeManager, self).__init__(context) # Give QObjects reasonable names self.setObjectName('NodeManagerFKIE') # Process standalone plugin command-line arguments from argparse import ArgumentParser parser = ArgumentParser() # Add argument(s) to the parser. parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", help="Put plugin in silent mode") args, unknowns = parser.parse_known_args(context.argv()) if not args.quiet: print 'arguments: ', args print 'unknowns: ', unknowns node_manager_fkie.init_settings() masteruri = node_manager_fkie.settings().masteruri() node_manager_fkie.init_globals(masteruri) # Create QWidget try: self._widget = MainWindow() # self._widget.read_view_history() except Exception, e: msgBox = QMessageBox() msgBox.setText(str(e)) msgBox.exec_() raise
def on_servo_on(self): try: if self.start_command: Popen(['bash', '-c', self.start_command]) elif self.use_hrpsys_configurator: execHrpsysConfiguratorCommand("hcf.servoOn()") else: servo = rospy.ServiceProxy( "/RobotHardwareServiceROSBridge/servo", OpenHRP_RobotHardwareService_servo) power = rospy.ServiceProxy( "/RobotHardwareServiceROSBridge/power", OpenHRP_RobotHardwareService_power) actual = rospy.ServiceProxy( "/StateHolderServiceROSBridge/goActual", OpenHRP_StateHolderService_goActual) power(OpenHRP_RobotHardwareService_powerRequest("all", 0)) time.sleep(1) actual(OpenHRP_StateHolderService_goActualRequest()) time.sleep(2) servo(OpenHRP_RobotHardwareService_servoRequest("all", 0)) except Exception, e: mb = QMessageBox(QMessageBox.NoIcon, "Error", "Failed to servo on: %s" % (e), QMessageBox.Ok, self.parent()) mb.exec_()
def on_power_off(self): try: power = rospy.ServiceProxy("/RobotHardwareServiceROSBridge/power", OpenHRP_RobotHardwareService_power ) power(OpenHRP_RobotHardwareService_powerRequest("all",1)) except Exception, e: mb = QMessageBox(QMessageBox.NoIcon, "Error", "Failed to power off: %s"%(e), QMessageBox.Ok, self.parent()) mb.exec_()
def _showWarning(self, title, body): if threading.current_thread().name != "MainThread": rospy.logwarn("{}: {}".format(title, body)) else: msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setWindowTitle(title) msg.setText(body) msg.setStandardButtons(QMessageBox.Ok) msg.exec_()
def show(self): # append folder of 'qt_gui_cpp/lib' to module search path qt_gui_cpp_path = os.path.realpath(get_package_path("qt_gui_cpp")) sys.path.append(os.path.join(qt_gui_cpp_path, "lib")) sys.path.append(os.path.join(qt_gui_cpp_path, "src")) from qt_gui_cpp.cpp_binding_helper import qt_gui_cpp import rospkg _rospkg_version = getattr(rospkg, "__version__", "< 0.2.4") logo = os.path.join(self._qtgui_path, "resource", "ros_org_vertical.png") text = '<img src="%s" width="56" height="200" style="float: left;"/>' % logo text += '<h3 style="margin-top: 1px;">%s</h3>' % self.tr("rqt") text += "<p>%s %s</p>" % ( self.tr("rqt is a framework for graphical user interfaces."), self.tr("It is extensible with plugins which can be written in either Python or C++."), ) text += "<p>%s</p>" % ( self.tr( 'Please see the <a href="%s">Wiki</a> for more information on rqt and available plugins.' % "http://wiki.ros.org/rqt" ) ) text += "<p>%s: " % self.tr("Utilized libraries:") text += "Python %s, " % platform.python_version() text += "rospkg %s, " % _rospkg_version if QT_BINDING == "pyside": text += "PySide" elif QT_BINDING == "pyqt": text += "PyQt" text += " %s (%s), " % (QT_BINDING_VERSION, ", ".join(sorted(QT_BINDING_MODULES))) text += "Qt %s, " % qVersion() if qt_gui_cpp is not None: if QT_BINDING == "pyside": text += "%s" % (self.tr("%s C++ bindings available") % "Shiboken") elif QT_BINDING == "pyqt": text += "%s" % (self.tr("%s C++ bindings available") % "SIP") else: text += "%s" % self.tr("C++ bindings available") else: text += "%s" % self.tr("no C++ bindings found - no C++ plugins available") text += ".</p>" mb = QMessageBox(QMessageBox.NoIcon, self.tr("About rqt"), text, QMessageBox.Ok, self.parent()) mb.exec_()
def on_download(self): try: hrpsys_save = rospy.ServiceProxy("/DataLoggerServiceROSBridge/save", OpenHRP_DataLoggerService_save ) name = "/tmp/rtclog-" + time.strftime("%Y%m%d%H%M%S") print "Writing log data to ",name hrpsys_save(OpenHRP_DataLoggerService_saveRequest(name)) print "Done writing",name except rospy.ServiceException, e: mb = QMessageBox(QMessageBox.NoIcon, "Error", "Failed to save rtcd log: service call failed with error: %s"%(e), QMessageBox.Ok, self.parent()) mb.exec_()
class DialogService(QWidget): ''' Provides popup windows for information and error messages ''' #---------------------------------- # Initializer #-------------- def __init__(self, parent=None): super(DialogService, self).__init__(parent); # All-purpose error popup message: # Used by self.showErrorMsgByErrorCode(<errorCode>), # or self.showErrorMsg(<string>). Returns a # QErrorMessage without parent, but with QWindowFlags set # properly to be a dialog popup box: self.errorMsgPopup = QErrorMessage.qtHandler(); # Re-parent the popup, retaining the window flags set # by the qtHandler: self.errorMsgPopup.setParent(parent, self.errorMsgPopup.windowFlags()); #self.errorMsgPopup.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); self.infoMsg = QMessageBox(parent=parent); #self.infoMsg.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); #---------------------------------- # showErrorMsg #-------------- QErrorMessage def showErrorMsg(self,errMsg): ''' Given a string, pop up an error dialog on top of the application window. @param errMsg: The message @type errMsg: string ''' self.errorMsgPopup.showMessage(errMsg); #---------------------------------- # showInfoMsg #-------------- def showInfoMsg(self, text): ''' Display a message window with an OK button on top of the application window. @param text: text to display @type text: string ''' self.infoMsg.setText(text); self.infoMsg.exec_();
def on_servo_off(self): try: if self.stop_command: Popen(['bash', '-c', self.stop_command]) else: power = rospy.ServiceProxy("/RobotHardwareServiceROSBridge/power", OpenHRP_RobotHardwareService_power ) servo = rospy.ServiceProxy("/RobotHardwareServiceROSBridge/servo", OpenHRP_RobotHardwareService_servo ) servo(OpenHRP_RobotHardwareService_servoRequest("all", 1)) time.sleep(1) power(OpenHRP_RobotHardwareService_powerRequest("all",1)) except Exception, e: mb = QMessageBox(QMessageBox.NoIcon, "Error", "Failed to servo off: %s"%(e), QMessageBox.Ok, self.parent()) mb.exec_()
def on_servo_off(self): try: if self.stop_command: Popen(["bash", "-c", self.stop_command]) elif self.use_hrpsys_configurator: execHrpsysConfiguratorCommand("hcf.servoOff()") else: power = rospy.ServiceProxy("/RobotHardwareServiceROSBridge/power", OpenHRP_RobotHardwareService_power) servo = rospy.ServiceProxy("/RobotHardwareServiceROSBridge/servo", OpenHRP_RobotHardwareService_servo) servo(OpenHRP_RobotHardwareService_servoRequest("all", 1)) time.sleep(1) power(OpenHRP_RobotHardwareService_powerRequest("all", 1)) except Exception, e: mb = QMessageBox( QMessageBox.NoIcon, "Error", "Failed to servo off: %s" % (e), QMessageBox.Ok, self.parent() ) mb.exec_()
def on_servo_off(self): try: if self.stop_command: Popen(['bash', '-c', self.stop_command]) elif self.use_hrpsys_configurator: execHrpsysConfiguratorCommand("hcf.servoOff()") else: power = rospy.ServiceProxy("/RobotHardwareServiceROSBridge/power", OpenHRP_RobotHardwareService_power ) servo = rospy.ServiceProxy("/RobotHardwareServiceROSBridge/servo", OpenHRP_RobotHardwareService_servo ) servo(OpenHRP_RobotHardwareService_servoRequest("all", 1)) time.sleep(1) power(OpenHRP_RobotHardwareService_powerRequest("all",1)) except Exception, e: mb = QMessageBox(QMessageBox.NoIcon, "Error", "Failed to servo off: %s"%(e), QMessageBox.Ok, self.parent()) mb.exec_()
def show(self): # append folder of 'qt_gui_cpp/lib' to module search path qt_gui_cpp_path = os.path.realpath(get_package_path('qt_gui_cpp')) sys.path.append(os.path.join(qt_gui_cpp_path, 'lib')) sys.path.append(os.path.join(qt_gui_cpp_path, 'src')) from qt_gui_cpp.cpp_binding_helper import qt_gui_cpp import rospkg _rospkg_version = getattr(rospkg, '__version__', '< 0.2.4') logo = os.path.join(self._qtgui_path, 'resource', 'ros_org_vertical.png') text = '<img src="%s" width="56" height="200" style="float: left;"/>' % logo text += '<h3 style="margin-top: 1px;">%s</h3>' % self.tr('rqt') text += '<p>%s %s</p>' % (self.tr('rqt is a framework for graphical user interfaces.'), self.tr('It is extensible with plugins which can be written in either Python or C++.')) text += '<p>%s</p>' % (self.tr('Please see the <a href="%s">Wiki</a> for more information on rqt and available plugins.' % 'http://wiki.ros.org/rqt')) text += '<p>%s: ' % self.tr('Utilized libraries:') text += 'Python %s, ' % platform.python_version() text += 'rospkg %s, ' % _rospkg_version if QT_BINDING == 'pyside': text += 'PySide' elif QT_BINDING == 'pyqt': text += 'PyQt' text += ' %s (%s), ' % (QT_BINDING_VERSION, ', '.join(sorted(QT_BINDING_MODULES))) text += 'Qt %s, ' % qVersion() if qt_gui_cpp is not None: if QT_BINDING == 'pyside': text += '%s' % (self.tr('%s C++ bindings available') % 'Shiboken') elif QT_BINDING == 'pyqt': text += '%s' % (self.tr('%s C++ bindings available') % 'SIP') else: text += '%s' % self.tr('C++ bindings available') else: text += '%s' % self.tr('no C++ bindings found - no C++ plugins available') text += '.</p>' mb = QMessageBox(QMessageBox.NoIcon, self.tr('About rqt'), text, QMessageBox.Ok, self.parent()) mb.exec_()
def on_servo_on(self): try: if self.start_command: Popen(['bash', '-c', self.start_command]) else: servo = rospy.ServiceProxy("/RobotHardwareServiceROSBridge/servo", OpenHRP_RobotHardwareService_servo ) power = rospy.ServiceProxy("/RobotHardwareServiceROSBridge/power", OpenHRP_RobotHardwareService_power ) actual = rospy.ServiceProxy("/StateHolderServiceROSBridge/goActual", OpenHRP_StateHolderService_goActual ) power(OpenHRP_RobotHardwareService_powerRequest("all",0)) time.sleep(1) actual(OpenHRP_StateHolderService_goActualRequest()) time.sleep(2) servo(OpenHRP_RobotHardwareService_servoRequest("all",0)) except Exception, e: mb = QMessageBox(QMessageBox.NoIcon, "Error", "Failed to servo on: %s"%(e), QMessageBox.Ok, self.parent()) mb.exec_()
class RosPyPluginProvider(CompositePluginProvider): _master_found_signal = Signal(int) def __init__(self): super(RosPyPluginProvider, self).__init__([RospkgPluginProvider('rqt_gui', 'rqt_gui_py::Plugin')]) self.setObjectName('RosPyPluginProvider') self._node_initialized = False self._wait_for_master_dialog = None self._wait_for_master_thread = None def load(self, plugin_id, plugin_context): self._check_for_master() self._init_node() return super(RosPyPluginProvider, self).load(plugin_id, plugin_context) def _check_for_master(self): # check if master is available try: rospy.get_master().getSystemState() return except Exception: pass # spawn thread to detect when master becomes available self._wait_for_master_thread = threading.Thread(target=self._wait_for_master) self._wait_for_master_thread.start() self._wait_for_master_dialog = QMessageBox(QMessageBox.Question, self.tr('Waiting for ROS master'), self.tr("Could not find ROS master. Either start a 'roscore' or abort loading the plugin."), QMessageBox.Abort) self._master_found_signal.connect(self._wait_for_master_dialog.done, Qt.QueuedConnection) button = self._wait_for_master_dialog.exec_() # check if master existence was not detected by background thread no_master = button != QMessageBox.Ok self._wait_for_master_dialog.deleteLater() self._wait_for_master_dialog = None if no_master: raise PluginLoadError('RosPyPluginProvider._init_node() could not find ROS master') def _wait_for_master(self): while True: time.sleep(0.1) if not self._wait_for_master_dialog: break try: rospy.get_master().getSystemState() except Exception: continue self._master_found_signal.emit(QMessageBox.Ok) break def _init_node(self): # initialize node once if not self._node_initialized: name = 'rqt_gui_py_node_%d' % os.getpid() qDebug('RosPyPluginProvider._init_node() initialize ROS node "%s"' % name) rospy.init_node(name, disable_signals=True) self._node_initialized = True
def newButtonSetOrUpdateCurrent(self): ''' Asks user whether saving of button set is to be to a new file, or an update to the current file. Cancel is offered as well. @return: ButtonSaveResult.NEW_SET, ButtonSaveResult.UPDATE_CURRENT, or ButtonSaveResult.CANCEL @rtype: DialogService.ButtonSaveResult ''' msgBox = QMessageBox() msgBox.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); msgBox.setText('Create new button set, or update current set?') updateCurrButton = QPushButton('Update current') msgBox.addButton(updateCurrButton, QMessageBox.NoRole) newSetButton = QPushButton('Create new set') msgBox.addButton(newSetButton, QMessageBox.YesRole) cancelButton = QPushButton('Cancel'); msgBox.addButton(cancelButton, QMessageBox.RejectRole) value = msgBox.exec_(); return value;
class RosPyPluginProvider(CompositePluginProvider): _master_found_signal = Signal(int) def __init__(self): super(RosPyPluginProvider, self).__init__( [RospkgPluginProvider('rqt_gui', 'rqt_gui_py::Plugin')]) self.setObjectName('RosPyPluginProvider') self._node_initialized = False self._wait_for_master_dialog = None self._wait_for_master_thread = None def load(self, plugin_id, plugin_context): self._check_for_master() self._init_node() return super(RosPyPluginProvider, self).load(plugin_id, plugin_context) def _check_for_master(self): # check if master is available try: rospy.get_master().getSystemState() return except Exception: pass # spawn thread to detect when master becomes available self._wait_for_master_thread = threading.Thread( target=self._wait_for_master) self._wait_for_master_thread.start() self._wait_for_master_dialog = QMessageBox( QMessageBox.Question, self.tr('Waiting for ROS master'), self. tr("Could not find ROS master. Either start a 'roscore' or abort loading the plugin." ), QMessageBox.Abort) self._master_found_signal.connect(self._wait_for_master_dialog.done, Qt.QueuedConnection) button = self._wait_for_master_dialog.exec_() # check if master existence was not detected by background thread no_master = button != QMessageBox.Ok self._wait_for_master_dialog.deleteLater() self._wait_for_master_dialog = None if no_master: raise PluginLoadError( 'RosPyPluginProvider._init_node() could not find ROS master') def _wait_for_master(self): while True: time.sleep(0.1) if not self._wait_for_master_dialog: break try: rospy.get_master().getSystemState() except Exception: continue self._master_found_signal.emit(QMessageBox.Ok) break def _init_node(self): # initialize node once if not self._node_initialized: name = 'rqt_gui_py_node_%d' % os.getpid() qDebug( 'RosPyPluginProvider._init_node() initialize ROS node "%s"' % name) rospy.init_node(name, disable_signals=True) self._node_initialized = True
def show_warning(self, text): qWarning(text) msgBox = QMessageBox() msgBox.setText(text) msgBox.exec_()
class DialogService(object): class ButtonSaveResult: UPDATE_CURRENT = 0; NEW_SET = 1; CANCEL = 2; #---------------------------------- # Initializer #-------------- def __init__(self, parent=None): # All-purpose error popup message: # Used by self.showErrorMsgByErrorCode(<errorCode>), # or self.showErrorMsg(<string>). Returns a # QErrorMessage without parent, but with QWindowFlags set # properly to be a dialog popup box: self.errorMsgPopup = QErrorMessage.qtHandler(); # Re-parent the popup, retaining the window flags set # by the qtHandler: self.errorMsgPopup.setParent(parent, self.errorMsgPopup.windowFlags()); self.errorMsgPopup.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); self.infoMsg = QMessageBox(parent=parent); self.infoMsg.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); #---------------------------------- # showErrorMsg #-------------- QErrorMessage def showErrorMsg(self,errMsg): ''' Given a string, pop up an error dialog. @param errMsg: The message @type errMsg: string ''' self.errorMsgPopup.showMessage(errMsg); #---------------------------------- # showInfoMsg #-------------- def showInfoMessage(self, text): self.infoMsg.setText(text); self.infoMsg.exec_(); #---------------------------------- # newButtonSetOrUpdateCurrent #-------------- def newButtonSetOrUpdateCurrent(self): ''' Asks user whether saving of button set is to be to a new file, or an update to the current file. Cancel is offered as well. @return: ButtonSaveResult.NEW_SET, ButtonSaveResult.UPDATE_CURRENT, or ButtonSaveResult.CANCEL @rtype: DialogService.ButtonSaveResult ''' msgBox = QMessageBox() msgBox.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); msgBox.setText('Create new button set, or update current set?') updateCurrButton = QPushButton('Update current') msgBox.addButton(updateCurrButton, QMessageBox.NoRole) newSetButton = QPushButton('Create new set') msgBox.addButton(newSetButton, QMessageBox.YesRole) cancelButton = QPushButton('Cancel'); msgBox.addButton(cancelButton, QMessageBox.RejectRole) value = msgBox.exec_(); return value;