Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Spectrum Analyzer #365

Merged
merged 17 commits into from
Nov 26, 2017
Merged
2 changes: 1 addition & 1 deletion src/urh/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class color:

PIXELS_PER_PATH = 5000

SPECTRUM_BUFFER_SIZE = 10 ** 5
SPECTRUM_BUFFER_SIZE = 10 ** 4
SNIFF_BUFFER_SIZE = 5 * 10 ** 7

PAUSE_TRESHOLD = 10
Expand Down
11 changes: 7 additions & 4 deletions src/urh/controller/SendRecvDialogController.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ def device(self) -> VirtualDevice:
def device(self, value):
self.__device = value

def _eliminate_graphic_view(self):
if self.graphics_view is not None:
self.graphics_view.eliminate()

self.graphics_view = None

def hide_send_ui_items(self):
for item in ("spinBoxNRepeat", "labelNRepeat", "lblCurrentRepeatValue", "progressBarMessage",
"lblRepeatText", "lSamplesSentText", "progressBarSample", "labelCurrentMessage"):
Expand Down Expand Up @@ -640,10 +646,7 @@ def closeEvent(self, event: QCloseEvent):

self.scene_manager.eliminate()

if self.graphics_view is not None:
self.graphics_view.eliminate()

self.graphics_view = None
self._eliminate_graphic_view()

super().closeEvent(event)

Expand Down
51 changes: 46 additions & 5 deletions src/urh/controller/SpectrumDialogController.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
from PyQt5.QtCore import QTimer, pyqtSlot
from PyQt5.QtGui import QWheelEvent, QIcon
from PyQt5.QtGui import QWheelEvent, QIcon, QPixmap, QResizeEvent
from PyQt5.QtWidgets import QGraphicsScene

from urh.controller.SendRecvDialogController import SendRecvDialogController
from urh.dev.VirtualDevice import VirtualDevice, Mode
from urh.signalprocessing.Spectrogram import Spectrogram
from urh.ui.painting.FFTSceneManager import FFTSceneManager


class SpectrumDialogController(SendRecvDialogController):
def __init__(self, project_manager, parent=None, testing_mode=False):
super().__init__(project_manager, is_tx=False, parent=parent, testing_mode=testing_mode)

self.graphics_view = self.ui.graphicsViewReceive
self.graphics_view = self.ui.graphicsViewFFT
self.update_interval = 1
self.ui.stackedWidget.setCurrentWidget(self.ui.page_receive)
self.ui.stackedWidget.setCurrentWidget(self.ui.page_spectrum)
self.hide_receive_ui_items()
self.hide_send_ui_items()

Expand All @@ -26,6 +28,9 @@ def __init__(self, project_manager, parent=None, testing_mode=False):
self.graphics_view.setScene(self.scene_manager.scene)
self.graphics_view.scene_manager = self.scene_manager

self.ui.graphicsViewSpectrogram.setScene(QGraphicsScene())
self.__clear_spectrogram()

self.init_device()
self.set_bandwidth_status()

Expand All @@ -43,11 +48,44 @@ def __init__(self, project_manager, parent=None, testing_mode=False):

self.create_connects()

def __clear_spectrogram(self):
self.ui.graphicsViewSpectrogram.scene().clear()
window_size = Spectrogram.DEFAULT_FFT_WINDOW_SIZE
self.ui.graphicsViewSpectrogram.scene().setSceneRect(0, 0, window_size, 20 * window_size)
self.spectrogram_y_pos = 0
self.ui.graphicsViewSpectrogram.fitInView(self.ui.graphicsViewSpectrogram.sceneRect())

def __update_spectrogram(self):
spectrogram = Spectrogram(self.device.data)
spectrogram.data_min = -70
spectrogram.data_max = 10
scene = self.ui.graphicsViewSpectrogram.scene()
pixmap = QPixmap.fromImage(spectrogram.create_spectrogram_image(transpose=True))
scene.addPixmap(pixmap).moveBy(0, self.spectrogram_y_pos)
self.spectrogram_y_pos += pixmap.height()
if self.spectrogram_y_pos >= scene.sceneRect().height():
scene.setSceneRect(0, 0, Spectrogram.DEFAULT_FFT_WINDOW_SIZE, self.spectrogram_y_pos)
self.ui.graphicsViewSpectrogram.verticalScrollBar().setValue(
self.ui.graphicsViewSpectrogram.verticalScrollBar().maximum())

def _eliminate_graphic_view(self):
super()._eliminate_graphic_view()
if self.ui.graphicsViewSpectrogram.scene() is not None:
self.ui.graphicsViewSpectrogram.scene().clear()
self.ui.graphicsViewSpectrogram.scene().setParent(None)
self.ui.graphicsViewSpectrogram.setScene(None)

self.ui.graphicsViewSpectrogram = None

def create_connects(self):
super().create_connects()
self.graphics_view.freq_clicked.connect(self.on_graphics_view_freq_clicked)
self.graphics_view.wheel_event_triggered.connect(self.on_graphics_view_wheel_event_triggered)

def resizeEvent(self, event: QResizeEvent):
if self.ui.graphicsViewSpectrogram and self.ui.graphicsViewSpectrogram.sceneRect():
self.ui.graphicsViewSpectrogram.fitInView(self.ui.graphicsViewSpectrogram.sceneRect())

def update_view(self):
if super().update_view():
x, y = self.device.spectrum
Expand All @@ -57,7 +95,9 @@ def update_view(self):
self.scene_manager.plot_data = y
self.scene_manager.init_scene()
self.scene_manager.show_full_scene()
self.graphics_view.update()
self.graphics_view.fitInView(self.graphics_view.sceneRect())

self.__update_spectrogram()

def init_device(self):
device_name = self.ui.cbDevice.currentText()
Expand Down Expand Up @@ -88,6 +128,7 @@ def on_start_clicked(self):

@pyqtSlot()
def on_device_started(self):
self.ui.graphicsViewSpectrogram.fitInView(self.ui.graphicsViewSpectrogram.scene().sceneRect())
super().on_device_started()
self.ui.btnClear.setEnabled(True)
self.ui.spinBoxPort.setEnabled(False)
Expand All @@ -96,6 +137,7 @@ def on_device_started(self):

@pyqtSlot()
def on_clear_clicked(self):
self.__clear_spectrogram()
self.scene_manager.clear_path()
self.scene_manager.clear_peak()

Expand All @@ -113,4 +155,3 @@ def on_slider_if_gain_value_changed(self, value: int):
def on_slider_baseband_gain_value_changed(self, value: int):
super().on_slider_baseband_gain_value_changed(value)
self.bb_gain_timer.start(250)

Loading