def expandItem(self, path_item, path, item_id): ''' Returns for the given item and path the file path if this is a file. Otherwise the folder will be expanded and None will be returned. @param path_item: the list item @type path_item: C{str} @param path: the real path of the item @type path: C{str} @return: path of the launch file or None @rtype: C{str} @raise Exception if no path to given item was found ''' if path_item == '..': goto_path = os.path.dirname(path) key_mod = QApplication.keyboardModifiers() if key_mod & Qt.ControlModifier: goto_path = None root_path, items = self._moveUp(goto_path) elif os.path.isfile(path): return path elif item_id == LaunchItem.RECENT_FILE or item_id == LaunchItem.LAUNCH_FILE: raise Exception("Invalid file path: %s", path) else: key_mod = QApplication.keyboardModifiers() onestep = False if key_mod & Qt.ControlModifier: onestep = True root_path, items = self._moveDown(path, onestep) self._setNewList((root_path, items)) return None
def expandItem(self, path_item, path, item_id): ''' Returns for the given item and path the file path if this is a file. Otherwise the folder will be expanded and None will be returned. @param path_item: the list item @type path_item: C{str} @param path: the real path of the item @type path: C{str} @return: path of the launch file or None @rtype: C{str} @raise Exception if no path to given item was found ''' if path_item == '..': goto_path = os.path.dirname(path) key_mod = QApplication.keyboardModifiers() if key_mod & Qt.ControlModifier: goto_path = None root_path, items = self._moveUp(goto_path) elif os.path.isfile(path): return path elif item_id == LaunchItem.RECENT_FILE or item_id == LaunchItem.LAUNCH_FILE: raise Exception("Invalid file path: %s", path) else: key_mod = QApplication.keyboardModifiers() onestep = False if key_mod & Qt.ControlModifier: onestep = True root_path, items = self._moveDown(path, onestep) self._setNewList((root_path, items)) return None
def on_launch_selection_activated(self, activated): ''' Tries to load the launch file, if one was activated. ''' selected = self._launchItemsFromIndexes(self.xmlFileView.selectionModel().selectedIndexes(), False) for item in selected: try: lfile = self.launchlist_model.expandItem(item.name, item.path, item.id) self.searchPackageLine.setText('') if lfile is not None: if item.isLaunchFile(): nm.settings().launch_history_add(item.path) key_mod = QApplication.keyboardModifiers() if key_mod & Qt.ShiftModifier: self.load_as_default_signal.emit(item.path, None) elif key_mod & Qt.ControlModifier: self.launchlist_model.setPath(os.path.dirname(item.path)) else: self.load_signal.emit(item.path, [], None) elif item.isProfileFile(): nm.settings().launch_history_add(item.path) key_mod = QApplication.keyboardModifiers() if key_mod & Qt.ControlModifier: self.launchlist_model.setPath(os.path.dirname(item.path)) else: self.load_profile_signal.emit(item.path) elif item.isConfigFile(): self.edit_signal.emit([lfile]) except Exception as e: 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))
def on_launch_selection_activated(self, activated): ''' Tries to load the launch file, if one was activated. ''' selected = self._launchItemsFromIndexes(self.xmlFileView.selectionModel().selectedIndexes(), False) for item in selected: try: lfile = self.launchlist_model.expandItem(item.name, item.path, item.id) self.searchPackageLine.setText('') if lfile is not None: if item.isLaunchFile(): nm.settings().launch_history_add(item.path) key_mod = QApplication.keyboardModifiers() if key_mod & Qt.ShiftModifier: self.load_as_default_signal.emit(item.path, None) elif key_mod & Qt.ControlModifier: self.launchlist_model.setPath(os.path.dirname(item.path)) else: self.load_signal.emit(item.path, [], None) elif item.isProfileFile(): nm.settings().launch_history_add(item.path) key_mod = QApplication.keyboardModifiers() if key_mod & Qt.ControlModifier: self.launchlist_model.setPath(os.path.dirname(item.path)) else: self.load_profile_signal.emit(item.path) elif item.isConfigFile(): self.edit_signal.emit([lfile]) except Exception as e: rospy.logwarn("Error while load launch file %s: %s" % (item, e)) WarningMessageBox(QMessageBox.Warning, "Load error", 'Error while load launch file:\n%s' % item.name, "%s" % e).exec_()
def keyPressEvent(self, event): ''' Defines some of shortcuts for navigation/management in launch list view or topics view. ''' key_mod = QApplication.keyboardModifiers() if not self.xmlFileView.state() == QAbstractItemView.EditingState: # remove history file from list by pressing DEL if event == QKeySequence.Delete: selected = self._launchItemsFromIndexes(self.xmlFileView.selectionModel().selectedIndexes(), False) for item in selected: nm.settings().launch_history_remove(item.path) self.launchlist_model.reloadCurrentPath() elif not key_mod and event.key() == Qt.Key_F4 and self.editXmlButton.isEnabled(): # open selected launch file in xml editor by F4 self.on_edit_xml_clicked() elif event == QKeySequence.Find: # set focus to filter box for packages self.searchPackageLine.setFocus(Qt.ActiveWindowFocusReason) elif event == QKeySequence.Paste: # paste files from clipboard self.launchlist_model.paste_from_clipboard() elif event == QKeySequence.Copy: # copy the selected items as file paths into clipboard selected = self.xmlFileView.selectionModel().selectedIndexes() indexes = [] for s in selected: indexes.append(self.launchlist_proxyModel.mapToSource(s)) self.launchlist_model.copy_to_clipboard(indexes) if self.searchPackageLine.hasFocus() and event.key() == Qt.Key_Escape: # cancel package filtering on pressing ESC self.launchlist_model.show_packages(False) self.searchPackageLine.setText('') self.xmlFileView.setFocus(Qt.ActiveWindowFocusReason) QDockWidget.keyReleaseEvent(self, event)
def keyPressEvent(self, event): ''' Defines some of shortcuts for navigation/management in launch list view or topics view. ''' key_mod = QApplication.keyboardModifiers() if not self.xmlFileView.state() == QAbstractItemView.EditingState: # remove history file from list by pressing DEL if event == QKeySequence.Delete: selected = self._launchItemsFromIndexes(self.xmlFileView.selectionModel().selectedIndexes(), False) for item in selected: nm.settings().launch_history_remove(item.path) self.launchlist_model.reloadCurrentPath() elif not key_mod and event.key() == Qt.Key_F4 and self.editXmlButton.isEnabled(): # open selected launch file in xml editor by F4 self.on_edit_xml_clicked() elif event == QKeySequence.Find: # set focus to filter box for packages self.searchPackageLine.setFocus(Qt.ActiveWindowFocusReason) elif event == QKeySequence.Paste: # paste files from clipboard self.launchlist_model.paste_from_clipboard() elif event == QKeySequence.Copy: # copy the selected items as file paths into clipboard selected = self.xmlFileView.selectionModel().selectedIndexes() indexes = [] for s in selected: indexes.append(self.launchlist_proxyModel.mapToSource(s)) self.launchlist_model.copy_to_clipboard(indexes) if self.searchPackageLine.hasFocus() and event.key() == Qt.Key_Escape: # cancel package filtering on pressing ESC self.launchlist_model.show_packages(False) self.searchPackageLine.setText('') self.xmlFileView.setFocus(Qt.ActiveWindowFocusReason) QDockWidget.keyReleaseEvent(self, event)
def expand_item(self, path, path_id, clear_cache=False): ''' Returns for the given item and path the file path if this is a file. Otherwise the folder will be expanded and None will be returned. :param str path: the real path of the item :param int path_id: the id of the path :param bool clear_cache: clear cache before reload :return: path of the launch file or None :rtype: str :raise Exception: if no path to given item was found ''' if path_id in [PathItem.NOTHING]: return None has_shift_mod = Qt.ShiftModifier & QApplication.keyboardModifiers() if path_id in [ PathItem.LAUNCH_FILE, PathItem.CFG_FILE, PathItem.PROFILE, PathItem.FILE, PathItem.RECENT_FILE, PathItem.LAUNCH_FILE ]: if not has_shift_mod: return path root = self.invisibleRootItem() while root.rowCount(): root.removeRow(0) self.pyqt_workaround.clear() if has_shift_mod: if path_id in [ PathItem.LAUNCH_FILE, PathItem.CFG_FILE, PathItem.PROFILE, PathItem.FILE, PathItem.RECENT_FILE, PathItem.LAUNCH_FILE ]: self._current_path = os.path.dirname(path) else: self._current_path = nmdurl.nmduri() else: if path_id in [PathItem.ROOT]: surl, spath = nmdurl.split(path, with_scheme=True) if self._is_root(path) or spath in ['', os.path.sep]: self._current_path = nmdurl.nmduri() elif self._is_ros_root(path): self._current_path = surl else: dir_path = os.path.dirname(spath) self._current_path = nmdurl.join(surl, dir_path) elif self._current_path != path: self._current_path = path self._add_path(self._current_path, PathItem.ROOT, 0, 0, 'loading...') nm.nmd().file.list_path_threaded(self._current_path, clear_cache) # TODO: add functionality to go deep automatically # else: # key_mod = QApplication.keyboardModifiers() # onestep = False # if key_mod & Qt.ControlModifier: # onestep = True # root_path, items = self._moveDown(path, onestep) # self._setNewList((root_path, items)) return None
def on_load_as_default(self): ''' Tries to load the selected launch file as default configuration. The button is only enabled and this method is called, if the button was enabled by on_launch_selection_clicked() ''' key_mod = QApplication.keyboardModifiers() if (key_mod & Qt.ShiftModifier): self.loadXmlAsDefaultButton.showMenu() else: selected = self._launchItemsFromIndexes(self.xmlFileView.selectionModel().selectedIndexes(), False) for item in selected: path = self.launchlist_model.expandItem(item.name, item.path, item.id) if path is not None: rospy.loginfo("LOAD the launch file as default: %s", path) self.launchlist_model.add2LoadHistory(path) self.load_as_default_signal.emit(path, None)
def keyPressEvent(self, event): ''' Defines some of shortcuts for navigation/management in launch list view or topics view. ''' key_mod = QApplication.keyboardModifiers() if not self.ui_file_view.state() == QAbstractItemView.EditingState: # remove history file from list by pressing DEL if event == QKeySequence.Delete or (event.key() == Qt.Key_Delete and key_mod & Qt.ShiftModifier): selected = self._pathItemsFromIndexes( self.ui_file_view.selectionModel().selectedIndexes(), False) for item in selected: if item in nm.settings().launch_history: nm.settings().launch_history_remove(item.path) self.launchlist_model.reload_current_path() elif not self.launchlist_model.is_in_root: if key_mod & Qt.ShiftModifier: rem_uri, rem_path = nmdurl.split(item.path) host = rem_uri.split(':') result = MessageBox.question( self, "Delete Question", "Delete %s\n@ %s" % (rem_path, host[0]), buttons=MessageBox.No | MessageBox.Yes) if result == MessageBox.Yes: try: nm.nmd().file.delete(item.path) self.launchlist_model.reload_current_path( clear_cache=True) except Exception as e: rospy.logwarn("Error while delete %s: %s" % (item.path, utf8(e))) MessageBox.warning( self, "Delete error", 'Error while delete:\n%s' % item.name, "%s" % utf8(e)) else: MessageBox.information( self, "Delete Info", "Use Shift+Del to delete files or directories", buttons=MessageBox.Ok) elif not key_mod and event.key( ) == Qt.Key_F4 and self.ui_button_edit.isEnabled(): # open selected launch file in xml editor by F4 self.on_edit_xml_clicked() elif event == QKeySequence.Find: # set focus to filter box for packages self.ui_search_line.setFocus(Qt.ActiveWindowFocusReason) elif event == QKeySequence.Paste: # paste files from clipboard self.launchlist_model.paste_from_clipboard() elif event == QKeySequence.Copy: # copy the selected items as file paths into clipboard selected = self.ui_file_view.selectionModel().selectedIndexes() indexes = [] for s in selected: indexes.append(self.launchlist_proxy_model.mapToSource(s)) self.launchlist_model.copy_to_clipboard(indexes) if self.ui_search_line.hasFocus() and event.key() == Qt.Key_Escape: # cancel package filtering on pressing ESC self.launchlist_model.reload_current_path() self.ui_search_line.setText('') self.ui_file_view.setFocus(Qt.ActiveWindowFocusReason) QDockWidget.keyReleaseEvent(self, event)