summaryrefslogtreecommitdiff
path: root/gr-qtgui/python/qtgui/digitalnumbercontrol.py
diff options
context:
space:
mode:
Diffstat (limited to 'gr-qtgui/python/qtgui/digitalnumbercontrol.py')
-rw-r--r--gr-qtgui/python/qtgui/digitalnumbercontrol.py59
1 files changed, 34 insertions, 25 deletions
diff --git a/gr-qtgui/python/qtgui/digitalnumbercontrol.py b/gr-qtgui/python/qtgui/digitalnumbercontrol.py
index 44ddfbd8ca..cbaf322b7d 100644
--- a/gr-qtgui/python/qtgui/digitalnumbercontrol.py
+++ b/gr-qtgui/python/qtgui/digitalnumbercontrol.py
@@ -23,13 +23,14 @@ import pmt
#
#
+
class LabeledDigitalNumberControl(QFrame):
def __init__(self, lbl='', min_freq_hz=0, max_freq_hz=6000000000, parent=None,
thousands_separator=',', background_color='black', fontColor='white',
click_callback=None):
QFrame.__init__(self, parent)
self.numberControl = DigitalNumberControl(min_freq_hz, max_freq_hz, self,
- thousands_separator, background_color, fontColor, click_callback)
+ thousands_separator, background_color, fontColor, click_callback)
layout = QVBoxLayout()
@@ -47,9 +48,9 @@ class LabeledDigitalNumberControl(QFrame):
def minimumSizeHint(self):
if self.hasLabel:
- return QSize(self.numberControl.minimumWidth()+10, 100)
+ return QSize(self.numberControl.minimumWidth() + 10, 100)
else:
- return QSize(self.numberControl.minimumWidth()+10, 50)
+ return QSize(self.numberControl.minimumWidth() + 10, 50)
def setReadOnly(self, b_read_only):
self.numberControl.setReadOnly(b_read_only)
@@ -60,6 +61,7 @@ class LabeledDigitalNumberControl(QFrame):
def getFrequency(self):
return self.numberControl.getFrequency()
+
class DigitalNumberControl(QFrame):
# Notifies to avoid thread conflicts on paints
updateInt = pyqtSignal(int)
@@ -96,7 +98,7 @@ class DigitalNumberControl(QFrame):
fm = QFontMetrics(self.numberFont)
if len(self.thousands_separator) > 0:
# The -1 makes sure we don't count an extra for 123,456,789. Answer should be 2 not 3.
- numgroups = int(float(self.numDigitsInFreq-1) / 3.0)
+ numgroups = int(float(self.numDigitsInFreq - 1) / 3.0)
if numgroups > 0:
for i in range(0, numgroups):
teststr += self.thousands_separator
@@ -129,7 +131,8 @@ class DigitalNumberControl(QFrame):
if self.read_only:
if self.debug_click:
- gr.log.info("click received but read-only. Not changing frequency.")
+ gr.log.info(
+ "click received but read-only. Not changing frequency.")
return
fm = QFontMetrics(self.numberFont)
@@ -154,12 +157,12 @@ class DigitalNumberControl(QFrame):
found_number = False
clicked_thousands = False
- for i in range(1, len(textstr)+1):
+ for i in range(1, len(textstr) + 1):
width = fm.width(textstr[-i:])
charstr = textstr[-i:]
widthchar = fm.width(charstr[0])
- if clickpos >= (width-widthchar) and clickpos <= width:
- clicked_char = i-1
+ if clickpos >= (width - widthchar) and clickpos <= width:
+ clicked_char = i - 1
clicked_num_index = clicked_char
@@ -170,7 +173,8 @@ class DigitalNumberControl(QFrame):
numSeps = charstr.count(self.thousands_separator)
clicked_num_index -= numSeps
if self.debug_click:
- gr.log.info("clicked number: " + str(clicked_num_index))
+ gr.log.info("clicked number: " +
+ str(clicked_num_index))
else:
clicked_thousands = True
if self.debug_click:
@@ -181,7 +185,7 @@ class DigitalNumberControl(QFrame):
# Remember y=0 is at the top so this is reversed
clicked_up = False
- if self.offset.y() > self.size().height()/2:
+ if self.offset.y() > self.size().height() / 2:
if self.debug_click:
gr.log.info('clicked down')
else:
@@ -200,7 +204,7 @@ class DigitalNumberControl(QFrame):
# Cannot call setFrequency to emit. Change must happen now for
# paint event when clicked.
self.setFrequencyNow(cur_freq)
-
+
if self.click_callback is not None:
self.click_callback(self.getFrequency())
break
@@ -208,7 +212,7 @@ class DigitalNumberControl(QFrame):
if (not found_number) and (not clicked_thousands):
# See if we clicked in the high area, if so, increment there.
clicked_up = False
- if self.offset.y() > self.size().height()/2:
+ if self.offset.y() > self.size().height() / 2:
if self.debug_click:
gr.log.info('clicked down in the high area')
else:
@@ -228,16 +232,17 @@ class DigitalNumberControl(QFrame):
# Cannot call setFrequency to emit. Change must happen now for
# paint event when clicked.
self.setFrequencyNow(cur_freq)
-
+
if self.click_callback is not None:
if self.debug_click:
gr.log.info('Calling self.click_callback')
-
+
self.click_callback(self.getFrequency())
else:
if self.debug_click:
- gr.log.info('self.click_callback is None. Not calling callback.')
-
+ gr.log.info(
+ 'self.click_callback is None. Not calling callback.')
+
def setColors(self, background, fontColor):
self.background_color = background
self.fontColor = fontColor
@@ -265,7 +270,7 @@ class DigitalNumberControl(QFrame):
if (new_freq >= self.min_freq) and (new_freq <= self.max_freq):
self.cur_freq = int(new_freq)
self.update()
-
+
def setFrequency(self, new_freq):
if type(new_freq) == int:
self.updateInt.emit(new_freq)
@@ -290,7 +295,7 @@ class DigitalNumberControl(QFrame):
brush = QBrush()
brush.setColor(self.background_color)
brush.setStyle(Qt.SolidPattern)
- rect = QtCore.QRect(2, 2, size.width()-4, size.height()-4)
+ rect = QtCore.QRect(2, 2, size.width() - 4, size.height() - 4)
painter.fillRect(rect, brush)
self.numberFont.setPixelSize(0.9 * size.height())
@@ -307,13 +312,15 @@ class DigitalNumberControl(QFrame):
else:
textstr = str(self.getFrequency())
- rect = QtCore.QRect(0, 0, size.width()-4, size.height())
-
+ rect = QtCore.QRect(0, 0, size.width() - 4, size.height())
+
painter.drawText(rect, Qt.AlignRight + Qt.AlignVCenter, textstr)
# ################################################################################
# GNU Radio Class
+
+
class MsgDigitalNumberControl(gr.sync_block, LabeledDigitalNumberControl):
def __init__(self, lbl='', min_freq_hz=0, max_freq_hz=6000000000, parent=None,
thousands_separator=',', background_color='black', fontColor='white',
@@ -321,7 +328,7 @@ class MsgDigitalNumberControl(gr.sync_block, LabeledDigitalNumberControl):
gr.sync_block.__init__(self, name="MsgDigitalNumberControl",
in_sig=None, out_sig=None)
LabeledDigitalNumberControl.__init__(self, lbl, min_freq_hz, max_freq_hz, parent,
- thousands_separator, background_color, fontColor, self.click_callback)
+ thousands_separator, background_color, fontColor, self.click_callback)
self.var_callback = var_callback
self.outputmsgname = outputmsgname
@@ -339,7 +346,8 @@ class MsgDigitalNumberControl(gr.sync_block, LabeledDigitalNumberControl):
self.setValue(new_val)
else:
- gr.log.error("Value received was not an int or a float. %s" % str(type(new_val)))
+ gr.log.error(
+ "Value received was not an int or a float. %s" % str(type(new_val)))
except Exception as e:
gr.log.error("Error with message conversion: %s" % str(e))
@@ -354,16 +362,17 @@ class MsgDigitalNumberControl(gr.sync_block, LabeledDigitalNumberControl):
def click_callback(self, new_value):
self.call_var_callback(new_value)
- self.message_port_pub(pmt.intern("valueout"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_double(float(new_value))))
+ self.message_port_pub(pmt.intern("valueout"), pmt.cons(
+ pmt.intern(self.outputmsgname), pmt.from_double(float(new_value))))
def setValue(self, new_val):
self.setFrequency(new_val)
- self.message_port_pub(pmt.intern("valueout"), pmt.cons(pmt.intern(self.outputmsgname), pmt.from_double(float(self.getFrequency()))))
+ self.message_port_pub(pmt.intern("valueout"), pmt.cons(pmt.intern(
+ self.outputmsgname), pmt.from_double(float(self.getFrequency()))))
def getValue(self):
self.getFrequency()
def setReadOnly(self, b_read_only):
super().setReadOnly(b_read_only)
-