Commit bc6b1b4f authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Make gui work with actual devices

parent fdb5f458
#!/usr/bin/env python3
#!/usr/bin/env python
import sys
......@@ -8,6 +8,8 @@ from PyQt5.QtCore import QTimer, Qt
from PyQt5 import QtCore
from PyQt5.QtGui import QColor, QFont, QIcon
from threading import Event, Thread
import webbrowser
import os.path
......@@ -17,12 +19,23 @@ import numpy as np
import astropy.units as u
from astropy.units import Quantity
from track_doppler import track_doppler
from telescope import telescope
from astroplan import Observer
import camrasdevices
class HPIBGui(QWidget):
def __init__(self, argv, app: QApplication):
super().__init__()
def __init__(self, argv, app):
super(HPIBGui, self).__init__()
self.doppler_exit_event = Event()
self.dt = telescope()
self.doppler_thread = None
self.lo = camrasdevices.LocalOscillator()
self.receiver = camrasdevices.Receiver()
self.lo_textbox = QLineEdit(self)
self.lo_textbox.setText("lo freq")
......@@ -55,6 +68,12 @@ class HPIBGui(QWidget):
self.show()
def closeEvent(self, event):
self.doppler_exit_event.set()
if self.doppler_thread:
self.doppler_thread.join()
event.accept()
def focus_changed(self, old, new):
if new in (self.lo_textbox, self.receiver_textbox):
self.help_label.setText("Press Enter to confirm or Escape to cancel")
......@@ -71,11 +90,10 @@ class HPIBGui(QWidget):
self.receiver_textbox.setText("")
def updateValues(self):
self.i += 1
if not self.lo_textbox.hasFocus():
self.lo_textbox.setText(str(self.i))
self.lo_textbox.setText("{:.6f}".format(self.lo.frequency.to(u.MHz)))
if not self.receiver_textbox.hasFocus():
self.receiver_textbox.setText(str(self.i))
self.receiver_textbox.setText("{:.3f}".format(self.receiver.frequency.to(u.MHz)))
def parse_input(self, new_freq_txt):
"""
......@@ -111,8 +129,8 @@ class HPIBGui(QWidget):
return
try:
print("Set LO to {}".format(new_freq))
except ValueError:
self.lo.frequency = new_freq
except RuntimeError:
self.help_label.setText("Could not set LO to {}".format(new_freq))
return
......@@ -121,13 +139,13 @@ class HPIBGui(QWidget):
def setReceiverFreq(self):
try:
new_freq = self.parse_input(self.lo_textbox.text())
new_freq = self.parse_input(self.receiver_textbox.text())
except (ValueError, TypeError):
return
try:
print("Set receiver to {}".format(new_freq))
except ValueError:
self.receiver.frequency = new_freq
except RuntimeError:
self.help_label.setText("Could not set LO to {}".format(new_freq))
return
......@@ -138,6 +156,12 @@ class HPIBGui(QWidget):
self.lo_textbox.setDisabled(self.doppler_checkbox.isChecked())
self.lo_textbox.clearFocus()
self.receiver_textbox.clearFocus()
if self.doppler_checkbox.isChecked():
self.doppler_thread = Thread(target=track_doppler, args=(self.dt, self.lo), kwargs={'exit_event': self.doppler_exit_event})
self.doppler_thread.start()
else:
self.doppler_exit_event.set()
self.doppler_thread.join()
def init_ui(self):
vbox = QVBoxLayout()
......
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