1
1
import numpy as np
2
- from PyQt5 .QtCore import QRectF , QLineF , QPointF
2
+ from PyQt5 .QtCore import QRectF , QLineF , QPointF , Qt
3
3
from PyQt5 .QtGui import QPainter , QFont , QFontMetrics , QPen , QTransform , QBrush
4
4
5
5
from urh import settings
@@ -16,10 +16,9 @@ def __init__(self, parent=None):
16
16
self .frequencies = []
17
17
self .frequency_marker = None
18
18
super ().__init__ (parent )
19
- self .setSceneRect (0 ,0 , 10 ,10 )
19
+ self .setSceneRect (0 , 0 , 10 , 10 )
20
20
21
21
def drawBackground (self , painter : QPainter , rect : QRectF ):
22
- # freqs = np.fft.fftfreq(len(w), 1 / self.sample_rate)
23
22
if self .draw_grid and len (self .frequencies ) > 0 :
24
23
painter .setPen (QPen (painter .pen ().color (), 0 ))
25
24
parent_width = self .parent ().width () if hasattr (self .parent (), "width" ) else 750
@@ -39,29 +38,30 @@ def drawBackground(self, painter: QPainter, rect: QRectF):
39
38
bottom = rect .bottom () - (rect .bottom () % y_grid_size )
40
39
right_border = int (rect .right ()) if rect .right () < len (self .frequencies ) else len (self .frequencies )
41
40
41
+ scale_x , scale_y = util .calc_x_y_scale (rect , self .parent ())
42
+
43
+ fh = self .font_metrics .height ()
42
44
x_range = list (range (x_mid , left , - x_grid_size )) + list (range (x_mid , right_border , x_grid_size ))
43
- lines = [QLineF (x , rect .top (), x , bottom ) for x in x_range ] \
45
+ lines = [QLineF (x , rect .top (), x , bottom - fh * scale_y ) for x in x_range ] \
44
46
+ [QLineF (rect .left (), y , rect .right (), y ) for y in np .arange (top , bottom , y_grid_size )]
45
47
48
+ pen = painter .pen ()
49
+ pen .setStyle (Qt .DotLine )
50
+ painter .setPen (pen )
46
51
painter .drawLines (lines )
47
- scale_x , scale_y = util .calc_x_y_scale (rect , self .parent ())
48
-
49
52
painter .scale (scale_x , scale_y )
50
53
counter = - 1 # Counter for Label for every second line
51
54
52
55
for x in x_range :
53
56
freq = self .frequencies [x ]
54
57
counter += 1
58
+ if freq == 0 :
59
+ counter = 0
55
60
56
- if freq != 0 and (counter % 2 != 0 ): # Label for every second line
61
+ if freq != 0 and (counter % 2 != 0 ): # Label for every second line
57
62
continue
58
63
59
- if freq != 0 :
60
- prefix = "+" if freq > 0 else ""
61
- value = prefix + Formatter .big_value_with_suffix (freq , 2 )
62
- else :
63
- counter = 0
64
- value = Formatter .big_value_with_suffix (self .center_freq )
64
+ value = Formatter .big_value_with_suffix (self .center_freq + freq , 2 )
65
65
font_width = self .font_metrics .width (value )
66
66
painter .drawText (QPointF (x / scale_x - font_width / 2 , bottom / scale_y ), value )
67
67
0 commit comments