Commit 4fab7189 authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Handle errors better

parent 1e2500f2
......@@ -91,9 +91,17 @@ class HPIBGui(QWidget):
def updateValues(self):
if not self.lo_textbox.hasFocus():
self.lo_textbox.setText("{:.6f}".format(self.lo.frequency.to(u.MHz)))
try:
lo_freq = "{:.6f}".format(self.lo.frequency.to(u.MHz))
except RuntimeError:
lo_freq = "???"
self.lo_textbox.setText(lo_freq)
if not self.receiver_textbox.hasFocus():
self.receiver_textbox.setText("{:.3f}".format(self.receiver.frequency.to(u.MHz)))
try:
receiver_freq = "{:.6f}".format(self.receiver.frequency.to(u.MHz))
except RuntimeError:
receiver_freq = "???"
self.receiver_textbox.setText(receiver_freq)
def parse_input(self, new_freq_txt):
"""
......@@ -126,6 +134,7 @@ class HPIBGui(QWidget):
try:
new_freq = self.parse_input(self.lo_textbox.text())
except (ValueError, TypeError):
# parse_input will already display an error
return
try:
......@@ -133,6 +142,8 @@ class HPIBGui(QWidget):
except RuntimeError:
self.help_label.setText("Could not set LO to {}".format(new_freq))
return
except ValueError:
self.help_label.setText("LO did not accept frequency {}".format(new_freq))
self.lo_textbox.clearFocus()
self.help_label.setText("")
......@@ -141,6 +152,7 @@ class HPIBGui(QWidget):
try:
new_freq = self.parse_input(self.receiver_textbox.text())
except (ValueError, TypeError):
# parse_input will already display an error
return
try:
......@@ -148,6 +160,8 @@ class HPIBGui(QWidget):
except RuntimeError:
self.help_label.setText("Could not set LO to {}".format(new_freq))
return
except ValueError:
self.help_label.setText("Receiver did not accept frequency {}".format(new_freq))
self.receiver_textbox.clearFocus()
self.help_label.setText("")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment