def path2mastername(self, grpc_path):
     try:
         muri = nmdurl.masteruri(grpc_path)
         return self._masteruri2name[muri.rstrip(os.path.sep)]
     except Exception as _:
         pass
     return ''
Exemplo n.º 2
0
 def set_current_master(self, masteruri, mastername):
     self.launchlist_model.set_current_master(masteruri, mastername)
     self._masteruri2name[masteruri.rstrip(os.path.sep)] = mastername
     try:
         color = QColor.fromRgb(nm.settings().host_color(
             self._masteruri2name[nmdurl.masteruri(
                 self.launchlist_model.current_path)],
             self._default_color.rgb()))
         self._new_color(color)
     except Exception as _:
         pass
Exemplo n.º 3
0
 def on_launch_selection_activated(self, activated):
     '''
     Tries to load the launch file, if one was activated.
     '''
     selected = self._pathItemsFromIndexes(
         self.ui_file_view.selectionModel().selectedIndexes(), False)
     for item in selected:
         try:
             self.ui_search_line.set_process_active(True)
             lfile = self.launchlist_model.expand_item(item.path, item.id)
             # self.ui_search_line.setText('')
             if lfile is not None:
                 self.ui_search_line.set_process_active(False)
                 if item.is_launch_file():
                     nm.settings().launch_history_add(item.path)
                     self.load_signal.emit(item.path, {}, None)
                 elif item.is_profile_file():
                     nm.settings().launch_history_add(item.path)
                     self.load_profile_signal.emit(item.path)
                 elif item.is_config_file():
                     self.edit_signal.emit(lfile)
             if self.launchlist_model.current_path:
                 self.setWindowTitle(
                     'Launch @%s' %
                     get_hostname(self.launchlist_model.current_grpc))
             else:
                 self.setWindowTitle('Launch files')
         except Exception as e:
             import traceback
             print(traceback.format_exc())
             rospy.logwarn("Error while load launch file %s: %s" %
                           (item, utf8(e)))
             MessageBox.warning(
                 self, "Load error",
                 'Error while load launch file:\n%s' % item.name,
                 "%s" % utf8(e))
     try:
         color = QColor.fromRgb(nm.settings().host_color(
             self._masteruri2name[nmdurl.masteruri(
                 self.launchlist_model.current_path)],
             self._default_color.rgb()))
         self._new_color(color)
     except Exception as _:
         pass
Exemplo n.º 4
0
 def is_current_nmd(self, url):
     return nmdurl.equal_uri(nmdurl.masteruri(url),
                             nmdurl.masteruri(self._current_path))
Exemplo n.º 5
0
 def open_screen(cls,
                 node,
                 grpc_url,
                 auto_item_request=False,
                 use_log_widget=False,
                 user=None,
                 pw=None,
                 items=[],
                 use_nmd=True):
     '''
     Searches for the screen associated with the given node and open the screen
     output in a new terminal.
     :param str node: the name of the node those screen output to show
     :param str grpc_url: the url of node manager daemon where the screen is running
     :raise Exception: on errors while resolving host
     :see: L{open_screen_terminal()}
     '''
     if node is None or len(node) == 0:
         return False
     try:
         host = get_hostname(grpc_url)
         try:
             muri = url.masteruri(grpc_url)
         except ValueError:
             muri = host
         if items:
             for item in items:
                 # open the selected screen
                 cls.open_screen_terminal(muri, item, node, use_log_widget,
                                          user)
         else:
             # get the available screens
             screens = {}
             try:
                 if use_nmd:
                     screens = nm.nmd().screen.get_screens(grpc_url, node)
                 else:
                     screens = cls._bc_get_active_screens(host,
                                                          node,
                                                          False,
                                                          user=user,
                                                          pwd=pw)
             except grpc.RpcError as e:
                 rospy.logwarn(
                     "can not connect to node manager daemon, detect screens using ssh..."
                 )
                 screens = cls._bc_get_active_screens(host,
                                                      node,
                                                      False,
                                                      user=user,
                                                      pwd=pw)
             if len(screens) == 1:
                 cls.open_screen_terminal(muri,
                                          list(screens.keys())[0], node,
                                          use_log_widget, user)
             else:
                 # create a list to let the user make a choice, which screen must be open
                 choices = {}
                 for sname, _nname in screens.items():
                     pid, session_name = screen.split_session_name(sname)
                     choices['%s [%d]' % (session_name, pid)] = sname
                 # Open selection
                 if len(choices) > 0:
                     if len(choices) == 1:
                         cls.open_screen_terminal(muri,
                                                  choices[0],
                                                  node,
                                                  use_log_widget=False,
                                                  user=user)
                     elif auto_item_request:
                         from select_dialog import SelectDialog
                         items, _ = SelectDialog.getValue(
                             'Show screen',
                             '',
                             list(choices.keys()),
                             False,
                             store_geometry='show_screens')
                         for item in items:
                             # open the selected screen
                             cls.open_screen_terminal(muri,
                                                      choices[item],
                                                      node,
                                                      use_log_widget=False,
                                                      user=user)
                     else:
                         raise ScreenSelectionRequest(
                             choices, 'Show screen')
                 else:
                     if use_log_widget:
                         nm._MAIN_FORM.open_screen_dock(
                             muri, '', node, user)
                     raise nm.InteractionNeededError(
                         NoScreenOpenLogRequest(node, host),
                         nm.starter().openLog, (node, host, user))
             return len(screens) > 0
     except nm.AuthenticationRequest as e:
         raise nm.InteractionNeededError(
             e, cls.open_screen,
             (node, grpc_url, auto_item_request, use_log_widget))
     except ScreenSelectionRequest as e:
         # set use_log_widget to False on multiple screens for same node
         raise nm.InteractionNeededError(
             e, cls.open_screen,
             (node, grpc_url, auto_item_request, False, user, pw))
Exemplo n.º 6
0
 def _get_package_dialog(self):
     muri = masteruri_from_ros()
     if self.init_filenames:
         muri = nmdurl.masteruri(self.init_filenames[0])
     return PackageDialog(muri)