Skip to content

Commit

Permalink
Allow last shot to work without an existing source
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedThree committed Aug 23, 2021
1 parent 6389803 commit 81ae091
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pyxpad/pyxpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,20 +728,20 @@ def lastShot(self):
"""
Get the latest shot number
"""

# Find an XPadSource in the list of sources
from pyxpad.xpadsource import XPadSource

source = None
for _source in self.sources.sources:
if isinstance(_source, XPadSource):
source = _source
if source is None:
# None available
return
try:
source = self.sources.sources[0]
except IndexError:
source = XPadSource()

# Now ask for the lastshot
last_shot_number = source.last_shot_number
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()
Expand Down
8 changes: 8 additions & 0 deletions tests/test_pyxpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ def test_get_last_shot(mock_uda, copy_tree_data, pyxpadbot, qtbot):
assert str(main.shotInput.text()).strip() == MOCK_LAST_SHOT


def test_get_last_shot_no_source(mock_uda, pyxpadbot, qtbot):
main = pyxpadbot

main.lastShotButton.setEnabled(True)
qtbot.mouseClick(main.lastShotButton, QtCore.Qt.LeftButton)
assert str(main.shotInput.text()).strip() == MOCK_LAST_SHOT


def test_get_available_signals(mock_uda, pyxpadbot, qtbot):
main = pyxpadbot

Expand Down

0 comments on commit 81ae091

Please sign in to comment.