Skip to content

Commit

Permalink
Preview: Minor additions
Browse files Browse the repository at this point in the history
  • Loading branch information
EarToEarOak committed Sep 18, 2014
1 parent 0544bf8 commit e0af449
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/dialogs_help.py
Expand Up @@ -65,6 +65,13 @@ def __populate_versions(self, control):
imageType = 'PIL'
imageVer = Image.VERSION


try:
import visvis as vv
visvisVer = vv.__version__
except ImportError:
visvisVer = 'Not installed'

versions = ('Hardware:\n'
'\tProcessor: {}, {} cores\n\n'
'Software:\n'
Expand All @@ -74,6 +81,7 @@ def __populate_versions(self, control):
'\tNumPy: {}\n'
'\t{}: {}\n'
'\tpySerial: {}\n'
'\tvisvis: {}\n'
'\twxPython: {}\n'
).format(platform.processor(), multiprocessing.cpu_count(),
platform.platform(), platform.machine(),
Expand All @@ -82,6 +90,7 @@ def __populate_versions(self, control):
numpy.version.version,
imageType, imageVer,
serial.VERSION,
visvisVer,
wx.version())

control.SetValue(versions)
Expand Down
2 changes: 2 additions & 0 deletions src/panels.py
Expand Up @@ -143,6 +143,8 @@ def __on_press(self, event):
if self.settings.clickTune and matplotlib.__version__ >= '1.2' and event.dblclick:
frequency = int(event.xdata * 1e6)
self.remoteControl.tune(frequency)
elif isinstance(self.plot, PlotterPreview):
self.plot.to_front()

def __on_enter(self, _event):
self.toolTip.Enable(False)
Expand Down
41 changes: 34 additions & 7 deletions src/plot_preview.py
Expand Up @@ -30,14 +30,15 @@
from visvis.core.line import Line
app = vv.use('wx')
vvPresent = True
except ImportError as error:
except ImportError:
vvPresent = False


class PlotterPreview(object):
def __init__(self, notify, figure, _settings):
def __init__(self, notify, figure, settings):
self.notify = notify
self.figure = figure
self.settings = settings
self.axes = None
self.window = None
self.preview = None
Expand All @@ -49,13 +50,16 @@ def __init__(self, notify, figure, _settings):
def __setup_plot(self):
self.axes = self.figure.add_subplot(111)
self.axes.set_axis_off()
if not vvPresent:
if vvPresent:
self.axes.text(0.5, 0.5, 'Click for preview',
ha='center', va='center')
else:
self.axes.text(0.5, 0.5, '"visvis" is not installed',
ha='center', va='center')

def __setup_window(self):
if vvPresent:
self.preview = DialogPreview(self.window)
self.preview = DialogPreview(self.window, self.settings)
self.preview.Show()

def draw_measure(self, _measure, _show):
Expand Down Expand Up @@ -97,6 +101,10 @@ def clear_plots(self):
def set_grid(self, _on):
pass

def to_front(self):
if self.preview is not None:
self.preview.to_front()

def close(self):
if self.preview is not None:
self.preview.Destroy()
Expand All @@ -105,7 +113,9 @@ def close(self):


class DialogPreview(wx.Dialog):
def __init__(self, parent):
def __init__(self, parent, settings):
self.settings = settings

wx.Dialog.__init__(self, parent=parent, title="Preview",
style=wx.RESIZE_BORDER | wx.CAPTION |
wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX | wx.SYSTEM_MENU)
Expand All @@ -114,7 +124,6 @@ def __init__(self, parent):
Figure = app.GetFigureClass()
fig = Figure(self)
fig.bgcolor = (1, 1, 1)
self.__setup_plot()

sizer = wx.BoxSizer()
sizer.Add(fig._widget, 1, wx.EXPAND | wx.ALL, border=5)
Expand All @@ -123,11 +132,17 @@ def __init__(self, parent):
self.SetAutoLayout(True)
self.Layout()

self.__setup_plot()

def __restore_style(self, style):
self.SetWindowStyle(style)

def __setup_plot(self):
axes = vv.gca()
axes.axis.showGrid = True
axes.axis.xLabel = 'Frequency (MHz)'
axes.axis.yLabel = 'Level (dB)'
axes.camera = 2

def clear_plots(self):
for wobject in vv.gca().wobjects:
Expand All @@ -139,10 +154,22 @@ def set_plot(self, spectrum):

total = len(spectrum)
count = 0.
alpha = 1
for _time, sweep in spectrum.items():
alpha = (total - count) / total
if self.settings.fadeScans:
alpha = (total - count) / total
vv.plot(sweep.keys(), sweep.values(), lw=1, alpha=alpha)
count += 1

def set_title(self, title):
vv.title(title.replace('\n', ' '))

def to_front(self):
style = self.GetWindowStyle()
self.SetWindowStyle(style | wx.STAY_ON_TOP)
wx.CallAfter(self.__restore_style, style)


if __name__ == '__main__':
print 'Please run rtlsdr_scan.py'
exit(1)
2 changes: 1 addition & 1 deletion src/rtlsdr_scan.py
Expand Up @@ -44,7 +44,7 @@
try:
import visvis as vv
vv.use('wx')
except ImportError as error:
except ImportError:
pass

import argparse
Expand Down
5 changes: 5 additions & 0 deletions src/toolbars.py
Expand Up @@ -564,6 +564,11 @@ def set_type(self, display):
elif display == Display.TIMELINE:
self.__add_auto_range(False, True, True)

elif display == Display.PREVIEW:
self.__add_check_tool('fade', 'Fade plots',
self.__on_check_fade,
self.settings.fadeScans)

self.__set_func()

self.Realize()
Expand Down
2 changes: 1 addition & 1 deletion src/version-timestamp
@@ -1 +1 @@
1411061386
1411076796

0 comments on commit e0af449

Please sign in to comment.