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

avoid graph overlapping legend in spectrum analyzer #816

Merged
merged 2 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/urh/simulator/Simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def process_message(self):
self.last_sent_message = msg
else:
# we have to receive a message
self.log_message("<i>Waiting for message {}</i>".format(msg.index()))
self.log_message("Waiting for message {}...".format(msg.index()))
sniffer = self.sniffer
if sniffer is None:
self.log_message("Fatal: No sniffer configured")
Expand All @@ -334,6 +334,7 @@ def process_message(self):
max_retries = self.project_manager.simulator_retries
while self.is_simulating and not self.simulation_is_finished() and retry < max_retries:
received_msg = self.receive_message(sniffer)
self.log_message(" Received {} data bits".format(len(received_msg)))

if not self.is_simulating:
return
Expand All @@ -353,7 +354,7 @@ def process_message(self):
received_msg.decoder = new_message.decoder
received_msg.message_type = new_message.message_type

self.log_message("Message {}: Check whether received data matches".format(msg.index()))
self.log_message(" Check whether received data matches")
check_result, error_msg = self.check_message(received_msg, new_message, retry=retry,
msg_index=msg.index())

Expand Down
4 changes: 1 addition & 3 deletions src/urh/ui/painting/FFTSceneManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ def show_scene_section(self, x1: float, x2: float, subpath_ranges=None, colors=N

def init_scene(self, draw_grid=True):
self.scene.draw_grid = draw_grid
minimum = -4.5
maximum = 2

self.peak = self.plot_data if len(self.peak) < self.num_samples else np.maximum(self.peak, self.plot_data)
self.scene.setSceneRect(0, minimum, self.num_samples, maximum - minimum)
self.scene.setSceneRect(0, -5, self.num_samples, 10)

def clear_path(self):
for item in self.scene.items():
Expand Down
26 changes: 13 additions & 13 deletions src/urh/ui/painting/GridScene.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from PyQt5.QtCore import QRectF, QLineF, QPointF
from PyQt5.QtCore import QRectF, QLineF, QPointF, Qt
from PyQt5.QtGui import QPainter, QFont, QFontMetrics, QPen, QTransform, QBrush

from urh import settings
Expand All @@ -16,10 +16,9 @@ def __init__(self, parent=None):
self.frequencies = []
self.frequency_marker = None
super().__init__(parent)
self.setSceneRect(0,0,10,10)
self.setSceneRect(0, 0, 10, 10)

def drawBackground(self, painter: QPainter, rect: QRectF):
# freqs = np.fft.fftfreq(len(w), 1 / self.sample_rate)
if self.draw_grid and len(self.frequencies) > 0:
painter.setPen(QPen(painter.pen().color(), 0))
parent_width = self.parent().width() if hasattr(self.parent(), "width") else 750
Expand All @@ -39,29 +38,30 @@ def drawBackground(self, painter: QPainter, rect: QRectF):
bottom = rect.bottom() - (rect.bottom() % y_grid_size)
right_border = int(rect.right()) if rect.right() < len(self.frequencies) else len(self.frequencies)

scale_x, scale_y = util.calc_x_y_scale(rect, self.parent())

fh = self.font_metrics.height()
x_range = list(range(x_mid, left, -x_grid_size)) + list(range(x_mid, right_border, x_grid_size))
lines = [QLineF(x, rect.top(), x, bottom) for x in x_range] \
lines = [QLineF(x, rect.top(), x, bottom-fh*scale_y) for x in x_range] \
+ [QLineF(rect.left(), y, rect.right(), y) for y in np.arange(top, bottom, y_grid_size)]

pen = painter.pen()
pen.setStyle(Qt.DotLine)
painter.setPen(pen)
painter.drawLines(lines)
scale_x, scale_y = util.calc_x_y_scale(rect, self.parent())

painter.scale(scale_x, scale_y)
counter = -1 # Counter for Label for every second line

for x in x_range:
freq = self.frequencies[x]
counter += 1
if freq == 0:
counter = 0

if freq != 0 and (counter % 2 != 0): # Label for every second line
if freq != 0 and (counter % 2 != 0): # Label for every second line
continue

if freq != 0:
prefix = "+" if freq > 0 else ""
value = prefix+Formatter.big_value_with_suffix(freq, 2)
else:
counter = 0
value = Formatter.big_value_with_suffix(self.center_freq)
value = Formatter.big_value_with_suffix(self.center_freq + freq, 2)
font_width = self.font_metrics.width(value)
painter.drawText(QPointF(x / scale_x - font_width / 2, bottom / scale_y), value)

Expand Down