def lastShot(self): """ Get the latest shot number """ from pyxpad.xpadsource import XPadSource try: source = self.sources.sources[0] except IndexError: source = XPadSource() try: last_shot_number = source.last_shot_number except AttributeError: self.statusbar.showMessage( "Last shot number not available for {source.label}", 1500) return # Append the shot number to any existing shot numbers current_text = self.shotInput.text() if current_text == "": new_text = str(last_shot_number) else: new_text = ", ".join([current_text, str(last_shot_number)]) self.shotInput.setText(new_text) return last_shot_number
def addXPADtree(self): """Add an XPad tree as a data source, if UDA is available""" try: from pyxpad.xpadsource import XPadSource except ImportError: self.main.write("Sorry, no XPAD tree support") self.main.write(str(sys.exc_info())) return try: # Select the directory tr = self.main.tr dname = QFileDialog.getExistingDirectory(self.main, tr("Open XPAD directory"), QDir.currentPath()) if (dname == "") or (dname is None): return # Create data source s = XPadSource.from_tree(dname) # Add data source and update self.addSource(s) self.updateDisplay() except: self.main.write("Error creating XPadSource") self.main.write(str(sys.exc_info())) raise
def test_get_last_shot(mock_uda, copy_tree_data, pyxpadbot, qtbot): main = pyxpadbot main.sources.addSource(XPadSource.from_tree(copy_tree_data)) main.sources.updateDisplay() main.lastShotButton.setEnabled(True) qtbot.mouseClick(main.lastShotButton, QtCore.Qt.LeftButton) assert str(main.shotInput.text()).strip() == MOCK_LAST_SHOT
def getAvailableSignals(self): """Add the available signals for listed shots as new sources""" from pyxpad.xpadsource import XPadSource shot_text = self.shotInput.text().split(",") shots = set(map(str.strip, shot_text)) if shots == {""}: shots = {str(self.lastShot())} existing_sources = shots.intersection(self.sources.names) new_shots = shots.difference(self.sources.names) if existing_sources: plural = "s" if len(existing_sources) > 1 else "" grammar = "" if len(existing_sources) > 1 else "s" self.statusbar.showMessage( f"Skipping shot{plural} {', '.join(existing_sources)}; already exist{grammar} as source{plural}", 1000, ) for shot in new_shots: self.sources.addSource(XPadSource.from_signals(shot)) self.sources.updateDisplay()
def test_init_with_tree(copy_tree_data): source = XPadSource.from_tree(copy_tree_data) assert list(source.variables.keys()) == EXPECTED_VARIABLE_NAMES assert source.variables["second_signal"].desc == "a description"
def test_from_signals(mock_uda): source = XPadSource.from_signals(1) assert list(source.variables.keys()) == EXPECTED_VARIABLE_NAMES
def test_latest_shot(mock_uda): source = XPadSource() assert source.last_shot_number == int(MOCK_LAST_SHOT)
def test_read(copy_tree_data, mock_uda): source = XPadSource.from_tree(copy_tree_data) data = source.read("something", 42) assert data.name == "something"