예제 #1
0
 def __init__(self, parent=None):
     super(XTermWidget, self).__init__(parent)
     self.setObjectName('XTermWidget')
     self._process = QProcess(self)
     self._process.finished.connect(self.close_signal)
     # let the widget finish init before embedding xterm
     QTimer.singleShot(100, self._embed_xterm)
예제 #2
0
 def __init__(self, parent=None, script_path=None):
     # possible use os to do better justice to script path??
     if script_path:
         xterm_cmd += " -e $SHELL -c 'source %s; $SHELL'" % os.path.abspath(
             script_path)
     super(XTermWidget, self).__init__(parent)
     self.setObjectName('XTermWidget')
     self._process = QProcess(self)
     self._process.finished.connect(self.close_signal)
     # let the widget finish init before embedding xterm
     QTimer.singleShot(100, self._embed_xterm)
예제 #3
0
    def on_select_type(self, id, index):
        """Callback for change selection in dropdown lists.

        Adds and removes dropdown list to/from the dialog that are used to filter subtypes based on the current selection.

        Args:
            id (int): Number of the combobox that dispatched the callback
            index (int): Number of the selected item in the current combobox (id)
        """
        # log.debug(self.__class__.__name__, 'Selected {}: {}'.format(id, index))

        # clear filters after selected
        while id < len(self._comboBoxes) - 1:
            # log.debug(self.__class__.__name__, 'Delete {}'.format(id+1))
            label = self.formLayout.labelForField(self._comboBoxes[id + 1])
            label.deleteLater()
            self._comboBoxes[id + 1].deleteLater()
            del self._comboBoxes[id + 1]

        # get current selection
        if index > 0:  # if not 'All' is selected
            selected = self._comboBoxes[id].itemData(self._comboBoxes[id].currentIndex())
        elif id > 0:  # if 'All' is selected and it is not the first combo box
            selected = self._comboBoxes[id - 1].itemData(self._comboBoxes[id - 1].currentIndex())
        else:  # if 'All' is selected and it is the first combo box
            selected = self.default_type
        # log.debug(self.__class__.__name__, 'Selected type {}'.format(selected))

        # create new combo box if not 'All' is selected
        if index > 0:
            self.create_comboBox(selected)
            # log.debug(self.__class__.__name__, 'Created {}'.format(len(self._comboBoxes)-1))

        # update list of individuals
        self.comboBox_individual.clear()
        if index > 0 or (id > 0 and index == 0):
            self.comboBox_individual.addItem('new ' + utils.ontology_type2name(selected), selected)
        [self.comboBox_individual.addItem(l, d) for l, d in self.get_individuals(selected).iteritems()]
        QTimer.singleShot(0, self.adjustSize)
예제 #4
0
 def on_load_profile_file(self, path):
     '''
     Load the profile file.
     :param path: the path of the profile file.
     :type path: str
     '''
     rospy.loginfo("Load profile %s" % path)
     self.progressBar.setValue(0)
     self.setVisible(True)
     self.setWindowTitle("%s profile started" %
                         os.path.basename(path).rstrip('.nmprofile'))
     hasstart = False
     if path:
         try:
             import yaml
             with open(path, 'r') as f:
                 # print yaml.load(f.read())
                 content = yaml.load(f.read())
                 if not isinstance(content, dict):
                     raise Exception("Mailformed profile: %s" %
                                     os.path.basename(path))
                 for muri, master_dict in content.items():
                     local_hostname = get_hostname(
                         self._main_window.getMasteruri())
                     rmuri = muri.replace('$LOCAL$', local_hostname)
                     master = self._main_window.getMaster(rmuri)
                     running_nodes = master.getRunningNodesIfLocal()
                     usr = None
                     self._current_profile[rmuri] = set()
                     if 'user' in master_dict:
                         usr = master_dict['user']
                     if master_dict['mastername'] and master_dict[
                             'mastername']:
                         nm.nameres().add_master_entry(
                             master.masteruri, master_dict['mastername'],
                             master_dict['address'])
                     hostname = master_dict['address'].replace(
                         '$LOCAL$', local_hostname)
                     if 'master_discovery' in master_dict:
                         self._start_node_from_profile(
                             master,
                             hostname,
                             'master_discovery_fkie',
                             'master_discovery',
                             usr,
                             cfg=master_dict['master_discovery'])
                         self._current_profile[rmuri].add(
                             '/master_discovery')
                     if 'master_sync' in master_dict:
                         self._start_node_from_profile(
                             master,
                             hostname,
                             'master_sync_fkie',
                             'master_sync',
                             usr,
                             cfg=master_dict['master_sync'])
                         self._current_profile[rmuri].add('/master_sync')
                     if 'zeroconf' in master_dict:
                         self._start_node_from_profile(
                             master,
                             hostname,
                             'master_discovery_fkie',
                             'zeroconf',
                             usr,
                             cfg=master_dict['zeroconf'])
                         self._current_profile[rmuri].add('/zeroconf')
                     try:
                         do_start = []
                         do_not_stop = {
                             '/rosout',
                             rospy.get_name(), '/node_manager',
                             '/master_discovery', '/master_sync',
                             '*default_cfg', '/zeroconf'
                         }
                         configs = master_dict['configs']
                         conf_set = set()
                         for cfg_name, cmdict in configs.items():
                             cfg_name = cfg_name.replace(
                                 '$LOCAL$', local_hostname)
                             if cfg_name.startswith("pkg://"):
                                 cfg_name = os.path.abspath(
                                     resolve_url(cfg_name))
                             conf_set.add(cfg_name)
                             reload_launch = True
                             argv = []
                             is_default = False
                             if 'default' in cmdict:
                                 if cmdict['default']:
                                     # it is a default configuration, test for load or not
                                     is_default = True
                                     if 'argv_used' in cmdict['params']:
                                         argv = cmdict['params'][
                                             'argv_used']
                                     if cfg_name in master.default_cfgs:
                                         reload_launch = False
                                         if argv:
                                             params = get_rosparam(
                                                 cfg_name, rmuri)
                                             if 'argv_used' in params:
                                                 reload_launch = set(
                                                     params['argv_used']
                                                 ) != set(argv)
                                     if reload_launch:
                                         self._main_window.on_load_launch_as_default_bypkg(
                                             cmdict['params']['package'],
                                             cmdict['params']
                                             ['launch_file'], master, argv,
                                             local_hostname)
                                     else:
                                         do_not_stop.add(cfg_name)
                             elif 'argv' in cmdict:
                                 if 'argv' in cmdict:
                                     argv = cmdict['argv']
                                 # do we need to load to load/reload launch file
                                 if cfg_name in master.launchfiles:
                                     reload_launch = set(
                                         master.launchfiles[cfg_name].argv
                                     ) != set(argv)
                             if reload_launch:
                                 self._main_window.launch_dock.load_file(
                                     cfg_name, argv, master.masteruri)
                             if 'nodes' in cmdict:
                                 self._current_profile[rmuri].update(
                                     cmdict['nodes'])
                                 force_start = True
                                 cfg = cfg_name if not is_default else roslib.names.ns_join(
                                     cfg_name, 'run')
                                 if not reload_launch:
                                     force_start = False
                                     do_not_stop.update(set(
                                         cmdict['nodes']))
                                     do_start.append(
                                         (reload_launch, cfg,
                                          cmdict['nodes'], force_start))
                                 else:
                                     do_start.append(
                                         (reload_launch, cfg,
                                          cmdict['nodes'], force_start))
                         # close unused configurations
                         for lfile in set(
                                 master.launchfiles.keys()) - conf_set:
                             master._close_cfg(lfile)
                         master.stop_nodes_by_name(running_nodes.keys(),
                                                   True, do_not_stop)
                         for reload_launch, cfg, nodes, force_start in do_start:
                             if nodes:
                                 hasstart = True
                             if reload_launch:
                                 master.start_nodes_after_load_cfg(
                                     cfg.rstrip('/run'), list(nodes),
                                     force_start)
                             else:
                                 master.start_nodes_by_name(
                                     list(nodes), cfg, force_start)
                     except Exception as ml:
                         import traceback
                         print traceback.format_exc(1)
                         rospy.logwarn(
                             "Can not load launch file for %s: %s" %
                             (muri, ml))
         except Exception as e:
             import traceback
             print traceback.format_exc(1)
             WarningMessageBox(QMessageBox.Warning, "Load profile error",
                               'Error while load profile', str(e)).exec_()
         if not hasstart:
             self.update_progress()
         else:
             QTimer.singleShot(1000, self.update_progress)
예제 #5
0
    def on_load_profile_file(self, grpc_url):
        '''
        Load the profile file.

        :param str grpc_url: the path of the profile file.
        '''
        _url, path = nmdurl.split(grpc_url)
        rospy.loginfo("Load profile %s" % path)
        self.progressBar.setValue(0)
        self.setVisible(True)
        self.setWindowTitle("%s profile started" %
                            os.path.basename(path).rstrip('.nmprofile'))
        hasstart = False
        if path:
            try:
                with open(path, 'r') as f:
                    content = ruamel.yaml.load(f.read(),
                                               Loader=ruamel.yaml.Loader)
                    if not isinstance(content, dict):
                        raise Exception("Mailformed profile: %s" %
                                        os.path.basename(path))
                    for muri, master_dict in content.items():
                        local_hostname = get_hostname(
                            self._main_window.getMasteruri())
                        rmuri = muri.replace('$LOCAL$', local_hostname)
                        master = self._main_window.getMaster(rmuri)
                        running_nodes = master.get_nodes_runningIfLocal()
                        usr = None
                        self._current_profile[rmuri] = set()
                        if 'user' in master_dict:
                            usr = master_dict['user']
                        if master_dict['mastername'] and master_dict[
                                'mastername']:
                            nm.nameres().add_master_entry(
                                master.masteruri, master_dict['mastername'],
                                master_dict['address'])
                        hostname = master_dict['address'].replace(
                            '$LOCAL$', local_hostname)
                        if 'master_discovery' in master_dict:
                            self._start_node_from_profile(
                                master,
                                hostname,
                                'fkie_master_discovery',
                                'master_discovery',
                                usr,
                                cfg=master_dict['master_discovery'])
                            self._current_profile[rmuri].add(
                                '/master_discovery')
                        if 'master_sync' in master_dict:
                            self._start_node_from_profile(
                                master,
                                hostname,
                                'fkie_master_sync',
                                'master_sync',
                                usr,
                                cfg=master_dict['master_sync'])
                            self._current_profile[rmuri].add('/master_sync')
                        if 'zeroconf' in master_dict:
                            self._start_node_from_profile(
                                master,
                                hostname,
                                'fkie_master_discovery',
                                'zeroconf',
                                usr,
                                cfg=master_dict['zeroconf'])
                            self._current_profile[rmuri].add('/zeroconf')
                        if 'node_manager_daemon' in master_dict:
                            self._start_node_from_profile(
                                master,
                                hostname,
                                'fkie_node_manager_daemon',
                                'node_manager_daemon',
                                usr,
                                cfg=master_dict['node_manager_daemon'])
                            self._current_profile[rmuri].add(
                                '/node_manager_daemon')
                        try:
                            do_start = []
                            do_not_stop = {
                                '/rosout',
                                rospy.get_name(), '/node_manager',
                                '/master_discovery', '/master_sync',
                                '*default_cfg', '/zeroconf',
                                '/node_manager_daemon'
                            }
                            configs = master_dict['configs']
                            conf_set = set()
                            for cfg_name, cmdict in configs.items():
                                cfg_name = cfg_name.replace(
                                    '$LOCAL$', local_hostname)
                                if cfg_name.startswith("pkg://"):
                                    cfg_name = resolve_pkg(
                                        cfg_name, nmdurl.nmduri(rmuri))
                                conf_set.add(cfg_name)
                                reload_launch = True
                                args = {}
                                if 'args' in cmdict:
                                    if 'args' in cmdict:
                                        args = cmdict['args']
                                    # do we need to load to load/reload launch file
                                    if cfg_name in master.launchfiles:
                                        reload_launch = set(
                                            master.launchfiles[cfg_name].args.
                                            itervalues()) != set(
                                                args.itervalues())
                                if reload_launch:
                                    self._main_window.launch_dock.load_file(
                                        cfg_name, args, master.masteruri)
                                if 'nodes' in cmdict:
                                    self._current_profile[rmuri].update(
                                        cmdict['nodes'])
                                    force_start = True
                                    cfg = cfg_name
                                    if not reload_launch:
                                        force_start = False
                                        do_not_stop.update(set(
                                            cmdict['nodes']))
                                        do_start.append(
                                            (reload_launch, cfg,
                                             cmdict['nodes'], force_start))
                                    else:
                                        do_start.append(
                                            (reload_launch, cfg,
                                             cmdict['nodes'], force_start))
                            # close unused configurations
                            for lfile in set(
                                    master.launchfiles.keys()) - conf_set:
                                master._close_cfg(lfile)
                            master.stop_nodes_by_name(running_nodes.keys(),
                                                      True, do_not_stop)
                            for reload_launch, cfg, nodes, force_start in do_start:
                                if nodes:
                                    hasstart = True
                                if reload_launch:
                                    master.start_nodes_after_load_cfg(
                                        cfg, list(nodes), force_start)
                                else:
                                    master.start_nodes_by_name(
                                        list(nodes), cfg, force_start)
                        except Exception as ml:
                            import traceback
                            print(utf8(traceback.format_exc(1)))
                            rospy.logwarn(
                                "Can not load launch file for %s: %s" %
                                (muri, utf8(ml)))
            except Exception as e:
                import traceback
                print(traceback.format_exc(1))
                MessageBox.warning(self, "Load profile error",
                                   'Error while load profile', utf8(e))
            if not hasstart:
                self.update_progress()
            else:
                QTimer.singleShot(1000, self.update_progress)
 def on_load_profile_file(self, path):
     '''
     Load the profile file.
     :param path: the path of the profile file.
     :type path: str
     '''
     rospy.loginfo("Load profile %s" % path)
     self.progressBar.setValue(0)
     self.setVisible(True)
     self.setWindowTitle("%s profile started" % os.path.basename(path).rstrip('.nmprofile'))
     hasstart = False
     if path:
         try:
             import yaml
             with open(path, 'r') as f:
                 # print yaml.load(f.read())
                 content = yaml.load(f.read())
                 if not isinstance(content, dict):
                     raise Exception("Mailformed profile: %s" % os.path.basename(path))
                 for muri, master_dict in content.items():
                     local_hostname = get_hostname(self._main_window.getMasteruri())
                     rmuri = muri.replace('$LOCAL$', local_hostname)
                     master = self._main_window.getMaster(rmuri)
                     running_nodes = master.getRunningNodesIfLocal()
                     usr = None
                     self._current_profile[rmuri] = set()
                     if 'user' in master_dict:
                         usr = master_dict['user']
                     if master_dict['mastername'] and master_dict['mastername']:
                         nm.nameres().add_master_entry(master.masteruri, master_dict['mastername'], master_dict['address'])
                     hostname = master_dict['address'].replace('$LOCAL$', local_hostname)
                     if 'master_discovery' in master_dict:
                         self._start_node_from_profile(master, hostname, 'master_discovery_fkie', 'master_discovery', usr, cfg=master_dict['master_discovery'])
                         self._current_profile[rmuri].add('/master_discovery')
                     if 'master_sync' in master_dict:
                         self._start_node_from_profile(master, hostname, 'master_sync_fkie', 'master_sync', usr, cfg=master_dict['master_sync'])
                         self._current_profile[rmuri].add('/master_sync')
                     if 'zeroconf' in master_dict:
                         self._start_node_from_profile(master, hostname, 'master_discovery_fkie', 'zeroconf', usr, cfg=master_dict['zeroconf'])
                         self._current_profile[rmuri].add('/zeroconf')
                     try:
                         do_start = []
                         do_not_stop = {'/rosout', rospy.get_name(), '/node_manager', '/master_discovery', '/master_sync', '*default_cfg', '/zeroconf'}
                         configs = master_dict['configs']
                         conf_set = set()
                         for cfg_name, cmdict in configs.items():
                             cfg_name = cfg_name.replace('$LOCAL$', local_hostname)
                             if cfg_name.startswith("pkg://"):
                                 cfg_name = os.path.abspath(resolve_url(cfg_name))
                             conf_set.add(cfg_name)
                             reload_launch = True
                             argv = []
                             is_default = False
                             if 'default' in cmdict:
                                 if cmdict['default']:
                                     # it is a default configuration, test for load or not
                                     is_default = True
                                     if 'argv_used' in cmdict['params']:
                                         argv = cmdict['params']['argv_used']
                                     if cfg_name in master.default_cfgs:
                                         reload_launch = False
                                         if argv:
                                             params = get_rosparam(cfg_name, rmuri)
                                             if 'argv_used' in params:
                                                 reload_launch = set(params['argv_used']) != set(argv)
                                     if reload_launch:
                                         self._main_window.on_load_launch_as_default_bypkg(cmdict['params']['package'], cmdict['params']['launch_file'], master, argv, local_hostname)
                                     else:
                                         do_not_stop.add(cfg_name)
                             elif 'argv' in cmdict:
                                 if 'argv' in cmdict:
                                     argv = cmdict['argv']
                                 # do we need to load to load/reload launch file
                                 if cfg_name in master.launchfiles:
                                     reload_launch = set(master.launchfiles[cfg_name].argv) != set(argv)
                             if reload_launch:
                                 self._main_window.launch_dock.load_file(cfg_name, argv, master.masteruri)
                             if 'nodes' in cmdict:
                                 self._current_profile[rmuri].update(cmdict['nodes'])
                                 force_start = True
                                 cfg = cfg_name if not is_default else roslib.names.ns_join(cfg_name, 'run')
                                 if not reload_launch:
                                     force_start = False
                                     do_not_stop.update(set(cmdict['nodes']))
                                     do_start.append((reload_launch, cfg, cmdict['nodes'], force_start))
                                 else:
                                     do_start.append((reload_launch, cfg, cmdict['nodes'], force_start))
                         # close unused configurations
                         for lfile in set(master.launchfiles.keys()) - conf_set:
                             master._close_cfg(lfile)
                         master.stop_nodes_by_name(running_nodes.keys(), True, do_not_stop)
                         for reload_launch, cfg, nodes, force_start in do_start:
                             if nodes:
                                 hasstart = True
                             if reload_launch:
                                 master.start_nodes_after_load_cfg(cfg.rstrip('/run'), list(nodes), force_start)
                             else:
                                 master.start_nodes_by_name(list(nodes), cfg, force_start)
                     except Exception as ml:
                         import traceback
                         print utf8(traceback.format_exc(1))
                         rospy.logwarn("Can not load launch file for %s: %s" % (muri, utf8(ml)))
         except Exception as e:
             import traceback
             print traceback.format_exc(1)
             MessageBox.warning(self, "Load profile error",
                                'Error while load profile',
                                utf8(e))
         if not hasstart:
             self.update_progress()
         else:
             QTimer.singleShot(1000, self.update_progress)
	def autoScrollLog(self):
		QTimer.singleShot(0, self._widget.logList.scrollToBottom)
예제 #8
0
 def move_marker():
     global time, interval
     time += interval
     if time < 10.0:
         marker.set_time(time)
         QTimer.singleShot(int(interval * 1000), move_marker)
    def __init__(self, context):
        """初期化処理"""

        super(RqtParamManagerPlugin, self).__init__(context)

        # クラス変数初期化
        self._title = "rqt_param_manager"
        self._get_interval = 1000
        self._monitor_timer = QTimer()
        self._conf_file_path_list = FILE_DEFAULT_PM_CONFS
        self._dump_yaml_file_path = ""
        self._config_items = []
        self._ros_namespace = os.environ.get(KEY_ENV_ROS_NAMESPACE, "")
        self._table_input_item_map = {}
        self._topic_listeners = []
        self._topic_data_map = {}
        self._prm_writer = None
        self._monitor_param_nms = []
        self._param_values = {}

        self.setObjectName('RqtParamManagerPlugin')

        args = {}
        self._parse_args(sys.argv, args)

        if (ARG_CONF in args):
            self._conf_file_path_list = args[ARG_CONF]

        if (len(self._ros_namespace) > 0 and self._ros_namespace[:-1] != "/"):
            self._ros_namespace = self._ros_namespace + "/"

        # Create QWidget
        self._widget = QWidget()
        self.ui = Ui_rqt_param_manager_main()
        self.ui.setupUi(self._widget)
        context.add_widget(self._widget)

        tblMon = self.ui.tblMonitor
        tblMon.initUI()
        tblMon.invoke_topic_pub.connect(self._on_topic_publish_invoke)

        self._initEnv(args)

        result_load_conf = self._parse_conf_file(self._conf_file_path_list,
                                                 self._config_items,
                                                 self._topic_data_map)
        QTimer.singleShot(0, self._update_window_title)

        self.ui.btnClose.clicked.connect(self._app_close)

        if not result_load_conf:
            self.ui.btnSave.setEnabled(False)
        else:
            self.ui.btnSave.clicked.connect(self._on_exec_save)
            self._monitor_timer.timeout.connect(self._on_period_monitoring)

            tblMon.load_items(self._config_items)
            self._monitor_param_nms = tblMon.get_monitor_param_nms()

            # 定期監視処理の開始
            if self._get_interval > 0:
                self._on_period_monitoring()
                rospy.loginfo("start monitor. interval =%d sec",
                              self._get_interval)
                self._monitor_timer.start(self._get_interval)

            self._start_topic_listen(self._config_items)