Skip to content

Commit

Permalink
Merge pull request #46 from ke5gdb/pyqt6
Browse files Browse the repository at this point in the history
Update Horus GUI to PyQt6
  • Loading branch information
darksidelemm authored Jan 30, 2025
2 parents a9d5033 + c415802 commit 6fec273
Show file tree
Hide file tree
Showing 13 changed files with 1,487 additions and 1,613 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ $ cd horusdemodlib && mkdir build && cd build
$ cmake ..
$ make
$ sudo make install
$ sudo ldconfig
```

### Grab this Repo
Expand Down
2 changes: 1 addition & 1 deletion horusgui/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.19"
__version__ = "0.4.0"
19 changes: 16 additions & 3 deletions horusgui/audio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Audio Interfacing
import logging
import pyaudio
import time


# Global PyAudio object
Expand Down Expand Up @@ -125,8 +126,14 @@ def __init__(self, audio_device, fs, block_size=8192, fft_input=None, modem=None
self.modem = modem
self.stats_callback = stats_callback

# Start audio stream
self.audio_thread_running = True

self.audio = pyaudio.PyAudio()

def start_stream(self, info_callback=None):
if info_callback:
self.stats_callback = info_callback

self.stream = self.audio.open(
format=pyaudio.paInt16,
channels=1,
Expand All @@ -138,6 +145,11 @@ def __init__(self, audio_device, fs, block_size=8192, fft_input=None, modem=None
stream_callback=self.handle_samples,
)

while self.audio_thread_running:
time.sleep(0.5)

logging.debug("Stopped audio stream thread")

def handle_samples(self, data, frame_count, time_info="", status_flags=""):
""" Handle incoming samples from pyaudio """

Expand All @@ -151,10 +163,11 @@ def handle_samples(self, data, frame_count, time_info="", status_flags=""):
# Send any stats data back to the stats callback
if _stats:
if self.stats_callback:
self.stats_callback(_stats)
self.stats_callback.emit(_stats)

return (None, pyaudio.paContinue)

def stop(self):
""" Halt stream """
self.stream.close()
self.audio_thread_running = False
self.stream.close()
9 changes: 8 additions & 1 deletion horusgui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
"rotator_type": "rotctld",
"rotator_host": "localhost",
"rotator_port": 4533,
"rotator_rangeinhibit": True,
"logging_enabled": False,
"log_format": "CSV",
"log_directory": "",
"fft_smoothing": False,
"payload_list": json.dumps(horusdemodlib.payloads.HORUS_PAYLOAD_LIST),
"custom_field_list": json.dumps({})
}
Expand Down Expand Up @@ -76,7 +78,7 @@ def read_config(widgets):
global qt_settings, default_config

# This is getting a bit ridiculous, need to re-think this approach.
OK_VERSIONS = [__version__, '0.3.18', '0.3.17', '0.3.16', '0.3.15', '0.3.14', '0.3.13', '0.3.12', '0.3.11', '0.3.10', '0.3.9', '0.3.8', '0.3.7', '0.3.6', '0.3.5', '0.3.4', '0.3.1', '0.2.1']
OK_VERSIONS = [__version__,'0.3.19', '0.3.18', '0.3.17', '0.3.16', '0.3.15', '0.3.14', '0.3.13', '0.3.12', '0.3.11', '0.3.10', '0.3.9', '0.3.8', '0.3.7', '0.3.6', '0.3.5', '0.3.4', '0.3.1', '0.2.1']

# Try and read in the version parameter from QSettings
if qt_settings.value("version") not in OK_VERSIONS:
Expand Down Expand Up @@ -124,12 +126,15 @@ def read_config(widgets):
widgets["rotatorTypeSelector"].setCurrentText(default_config["rotator_type"])
widgets["rotatorHostEntry"].setText(str(default_config["rotator_host"]))
widgets["rotatorPortEntry"].setText(str(default_config["rotator_port"]))
widgets["rotatorRangeInhibit"].setChecked(ValueToBool(default_config["rotator_rangeinhibit"]))

# Logging Settings
widgets["loggingPathEntry"].setText(str(default_config["log_directory"]))
widgets["loggingFormatSelector"].setCurrentText(default_config["log_format"])
widgets["enableLoggingSelector"].setChecked(ValueToBool(default_config["logging_enabled"]))

widgets["fftSmoothingSelector"].setChecked(ValueToBool(default_config["fft_smoothing"]))

if default_config['baud_rate'] != -1:
widgets["horusModemRateSelector"].setCurrentText(str(default_config['baud_rate']))

Expand Down Expand Up @@ -173,9 +178,11 @@ def save_config(widgets):
default_config["rotator_type"] = widgets["rotatorTypeSelector"].currentText()
default_config["rotator_host"] = widgets["rotatorHostEntry"].text()
default_config["rotator_port"] = int(widgets["rotatorPortEntry"].text())
default_config["rotator_rangeinhibit"] = widgets["rotatorRangeInhibit"].isChecked()
default_config["logging_enabled"] = widgets["enableLoggingSelector"].isChecked()
default_config["log_directory"] = widgets["loggingPathEntry"].text()
default_config["log_format"] = widgets["loggingFormatSelector"].currentText()
default_config["fft_smoothing"] = widgets["fftSmoothingSelector"].isChecked()

default_config["payload_list"] = json.dumps(horusdemodlib.payloads.HORUS_PAYLOAD_LIST)
default_config["custom_field_list"] = json.dumps(horusdemodlib.payloads.HORUS_CUSTOM_FIELDS)
Expand Down
14 changes: 9 additions & 5 deletions horusgui/fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
import numpy as np
from queue import Queue
from threading import Thread
#from threading import Thread


class FFTProcess(object):
Expand Down Expand Up @@ -37,8 +37,8 @@ def __init__(

self.processing_thread_running = True

self.t = Thread(target=self.processing_thread)
self.t.start()
#self.t = Thread(target=self.processing_thread)
#self.t.start()

def init_window(self):
""" Initialise Window functions and FFT scales. """
Expand Down Expand Up @@ -74,7 +74,7 @@ def perform_fft(self):

if self.callback != None:
if self.update_counter % self.update_decimation == 0:
self.callback({"fft": _fft[self.mask], "scale": self.fft_scale[self.mask], 'dbfs': _dbfs})
self.callback.emit({"fft": _fft[self.mask], "scale": self.fft_scale[self.mask], 'dbfs': _dbfs})

self.update_counter += 1

Expand All @@ -86,7 +86,9 @@ def process_block(self, samples):
while len(self.sample_buffer) > self.nfft * self.sample_width:
self.perform_fft()

def processing_thread(self):
def processing_thread(self, info_callback=None):
if info_callback:
self.callback = info_callback

while self.processing_thread_running:
if self.input_queue.qsize() > 0:
Expand All @@ -95,6 +97,8 @@ def processing_thread(self):
else:
time.sleep(0.01)

logging.debug("Stopped FFT processing thread")

def add_samples(self, samples):
""" Add a block of samples to the input queue """
try:
Expand Down
Loading

0 comments on commit 6fec273

Please sign in to comment.