def __init__(self, parent=None): QWidget.__init__(self, parent) self.setObjectName("MainBox") self.__on_intern_change = False boxLayout = QFormLayout() boxLayout.setVerticalSpacing(0) self.setLayout(boxLayout)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setObjectName("MainBox") self.__on_intern_change = False boxLayout = QFormLayout() boxLayout.setVerticalSpacing(0) self.setLayout(boxLayout)
class PackageDialog(QDialog): def __init__(self, masteruri, parent=None): QDialog.__init__(self, parent) self.setWindowTitle('Select Binary') self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.content = QWidget() self.contentLayout = QFormLayout(self.content) self.contentLayout.setVerticalSpacing(0) self.verticalLayout.addWidget(self.content) self.packages = None self.masteruri = "ROS_MASTER_URI" if masteruri is None else masteruri package_label = QLabel("Package:", self.content) self.package_field = QComboBox(self.content) self.package_field.setInsertPolicy(QComboBox.InsertAlphabetically) self.package_field.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)) self.package_field.setEditable(True) self.contentLayout.addRow(package_label, self.package_field) binary_label = QLabel("Binary:", self.content) self.binary_field = QComboBox(self.content) self.binary_field.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)) self.binary_field.setEditable(True) self.contentLayout.addRow(binary_label, self.binary_field) self.buttonBox = QDialogButtonBox(self) self.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setObjectName("buttonBox") self.verticalLayout.addWidget(self.buttonBox) self.package_field.setFocus(Qt.TabFocusReason) self.package = '' self.binary = '' self._request_bin_thread = None if self.packages is None: self.package_field.addItems(['packages searching...']) self.package_field.setCurrentIndex(0) # fill the input fields self.packages = { name: path for path, name in nm.nmd().file.get_packages( nmdurl.nmduri(masteruri)).items() } packages = self.packages.keys() packages.sort() self.package_field.clear() self.package_field.clearEditText() self.package_field.addItems(packages) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) QMetaObject.connectSlotsByName(self) self.package_field.activated[str].connect(self.on_package_selected) if hasattr(self.package_field, "textChanged"): # qt compatibility self.package_field.textChanged.connect(self.on_package_selected) self.binary_field.textChanged.connect(self.on_binary_selected) else: self.package_field.editTextChanged.connect( self.on_package_selected) self.binary_field.editTextChanged.connect(self.on_binary_selected) def on_package_selected(self, package): getnew = False if self._request_bin_thread is None: getnew = True else: if self._request_bin_thread.pkgname != package: self._request_bin_thread.cancel() getnew = True if self._request_bin_thread is not None and self._request_bin_thread.pkgname == package: # use already got data self._request_bin_thread.reemit() elif getnew: self.binary_field.clear() if self.packages and package in self.packages: self.binary_field.setEnabled(True) self._request_bin_thread = RequestBinariesThread( package, nmdurl.nmduri(self.masteruri)) self._request_bin_thread.binaries_signal.connect( self._on_new_binaries) self._request_bin_thread.start() def _on_new_binaries(self, pkgname, binaries): # update the binaries binaries = [os.path.basename(item) for item in binaries.keys()] binaries = list(set(binaries)) binaries.sort() self.binary_field.addItems(binaries) self.package = pkgname self.binary = self.binary_field.currentText() def on_binary_selected(self, binary): self.binary = binary
class PackageDialog(QDialog): def __init__(self, parent=None): QDialog.__init__(self, parent) self.setWindowTitle('Select Binary') self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.content = QWidget() self.contentLayout = QFormLayout(self.content) self.contentLayout.setVerticalSpacing(0) self.verticalLayout.addWidget(self.content) self.packages = None package_label = QLabel("Package:", self.content) self.package_field = QComboBox(self.content) self.package_field.setInsertPolicy(QComboBox.InsertAlphabetically) self.package_field.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)) self.package_field.setEditable(True) self.contentLayout.addRow(package_label, self.package_field) binary_label = QLabel("Binary:", self.content) self.binary_field = QComboBox(self.content) # self.binary_field.setSizeAdjustPolicy(QComboBox.AdjustToContents) self.binary_field.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)) self.binary_field.setEditable(True) self.contentLayout.addRow(binary_label, self.binary_field) self.buttonBox = QDialogButtonBox(self) self.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setObjectName("buttonBox") self.verticalLayout.addWidget(self.buttonBox) self.package_field.setFocus(Qt.TabFocusReason) self.package = '' self.binary = '' if self.packages is None: self.package_field.addItems(['packages searching...']) self.package_field.setCurrentIndex(0) self._fill_packages_thread = PackagesThread() self._fill_packages_thread.packages.connect(self._fill_packages) self._fill_packages_thread.start() self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) QMetaObject.connectSlotsByName(self) self.package_field.activated[str].connect(self.on_package_selected) if hasattr(self.package_field, "textChanged"): # qt compatibility self.package_field.textChanged.connect(self.on_package_selected) self.binary_field.textChanged.connect(self.on_binary_selected) else: self.package_field.editTextChanged.connect(self.on_package_selected) self.binary_field.editTextChanged.connect(self.on_binary_selected) def _fill_packages(self, packages): # fill the input fields self.packages = packages packages = packages.keys() packages.sort() self.package_field.clear() self.package_field.clearEditText() self.package_field.addItems(packages) def _getBinaries(self, path): result = {} if os.path.isdir(path): fileList = os.listdir(path) for f in fileList: if f and f[0] != '.' and f not in ['build'] and not f.endswith('.cfg') and not f.endswith('.so'): ret = self._getBinaries(os.path.join(path, f)) result = dict(ret.items() + result.items()) elif os.path.isfile(path) and os.access(path, os.X_OK): # create a selection for binaries return {os.path.basename(path): path} return result def on_package_selected(self, package): self.binary_field.clear() if self.packages and package in self.packages: self.binary_field.setEnabled(True) path = self.packages[package] binaries = self._getBinaries(path).keys() try: # find binaries in catkin workspace from catkin.find_in_workspaces import find_in_workspaces as catkin_find search_paths = catkin_find(search_dirs=['libexec', 'share'], project=package, first_matching_workspace_only=True) for p in search_paths: binaries += self._getBinaries(p).keys() except: pass binaries = list(set(binaries)) binaries.sort() self.binary_field.addItems(binaries) self.package = package self.binary = self.binary_field.currentText() def on_binary_selected(self, binary): self.binary = binary