# Path: rtlsdr_scanner/constants.py
# F_MIN = 0
# 
# F_MAX = 9999
# 
# SAMPLE_RATE = 2e6
# 
# BANDWIDTH = 500e3
# 
# WINFUNC = ["Bartlett", numpy.bartlett,
#            "Blackman", numpy.blackman,
#            "Hamming", numpy.hamming,
#            "Hanning", numpy.hanning]
# 
# Path: rtlsdr_scanner/panels.py
# class PanelColourBar(wx.Panel):
# 
#     def __init__(self, parent, colourMap):
#         wx.Panel.__init__(self, parent)
#         dpi = wx.ScreenDC().GetPPI()[0]
#         figure = matplotlib.figure.Figure(facecolor='white', dpi=dpi)
#         figure.set_size_inches(200.0 / dpi, 25.0 / dpi)
#         self.canvas = FigureCanvas(self, -1, figure)
#         axes = figure.add_subplot(111)
#         figure.subplots_adjust(0, 0, 1, 1)
#         norm = Normalize(vmin=0, vmax=1)
#         self.bar = ColorbarBase(axes, norm=norm, orientation='horizontal',
#                                 cmap=cm.get_cmap(colourMap))
#         axes.xaxis.set_visible(False)
# 
#     def set_map(self, colourMap):
#         self.bar.set_cmap(colourMap)
#         self.bar.changed()
#         self.bar.draw_all()
#         self.canvas.draw()
# 
# Path: rtlsdr_scanner/rtltcp.py
# class RtlTcp(object):
#     def __init__(self, host, port, notify):
#         self.host = host
#         self.port = port
# 
#         self.threadBuffer = None
#         self.tuner = 0
#         self.rate = 0
# 
#         self.__setup(notify)
# 
#     def __setup(self, notify):
#         self.threadBuffer = ThreadBuffer(self.host, self.port, notify)
#         self.__get_header()
# 
#     def __get_header(self):
#         header = self.threadBuffer.get_header()
#         if len(header) == 12:
#             if header.startswith('RTL0'):
#                 self.tuner = ((ord(header[4]) << 24) |
#                               (ord(header[5]) << 16) |
#                               (ord(header[6]) << 8) |
#                               ord(header[7]))
# 
#     def __send_command(self, command, data):
#         send = array.array('c', '\0' * 5)
# 
#         struct.pack_into('>l', send, 1, data)
#         send[0] = struct.pack('<b', command)
# 
#         self.threadBuffer.sendall(send)
# 
#     def __read_raw(self, samples):
#         return self.threadBuffer.recv(samples * 2)
# 
#     def __raw_to_iq(self, raw):
#         iq = numpy.empty(len(raw) / 2, 'complex')
#         iq.real, iq.imag = raw[::2], raw[1::2]
#         iq /= (255 / 2)
#         iq -= 1
# 
#         return iq
# 
#     def set_sample_rate(self, rate):
#         self.__send_command(RtlTcpCmd.SET_SAMPLE_RATE, rate)
#         self.rate = rate
# 
#     def set_manual_gain_enabled(self, mode):
#         self.__send_command(RtlTcpCmd.SET_GAIN_MODE, mode)
# 
#     def set_gain(self, gain):
#         self.__send_command(RtlTcpCmd.SET_GAIN, gain * 10)
# 
#     def set_center_freq(self, freq):
#         self.__send_command(RtlTcpCmd.SET_FREQ, freq)
#         self.__read_raw(int(self.rate * 2 * 0.1))
# 
#     def get_tuner_type(self):
#         return self.tuner
# 
#     def read_samples(self, samples):
# 
#         raw = self.__read_raw(samples)
#         return self.__raw_to_iq(raw)
# 
#     def close(self):
#         self.threadBuffer.abort()
#         self.threadBuffer.join()


import itertools
import matplotlib
import numpy
import rtlsdr
import wx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from wx.lib.agw.cubecolourdialog import CubeColourDialog
from wx.lib.masked.numctrl import NumCtrl
from rtlsdr_scanner.constants import F_MIN, F_MAX, SAMPLE_RATE, BANDWIDTH, WINFUNC
from rtlsdr_scanner.panels import PanelColourBar
from rtlsdr_scanner.rtltcp import RtlTcp
from rtlsdr_scanner.utils_mpl import get_colours
        gridSizer.Add(refresh, pos=(3, 0), span=(1, 2),
                      flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
        gridSizer.Add(boxSizer2, pos=(4, 0), span=(1, 2),
                      flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
        gridSizer.Add(sizerButtons, pos=(5, 1),
                      flag=wx.ALIGN_RIGHT | wx.ALL, border=5)

        self.SetSizerAndFit(gridSizer)
        self.__draw_limits()

        self.__setup_plot()

    def __setup_plot(self):
        self.axes.clear()
        self.band1 = None
        self.band2 = None
        self.axes.set_xlabel("Frequency (MHz)")
        self.axes.set_ylabel('Level (dB/Hz)')
        self.axes.set_yscale('log')
        self.axes.set_xlim(-1, 1)
        self.axes.set_ylim(auto=True)
        self.axes.grid(True)
        self.__draw_limits()

    def __plot(self, capture):
        self.__setup_plot()
        pos = WINFUNC[::2].index(self.winFunc)
        function = WINFUNC[1::2][pos]
        powers, freqs = matplotlib.mlab.psd(capture,
                                            NFFT=1024,

# Path: rtlsdr_scanner/constants.py
# F_MIN = 0
# 
# F_MAX = 9999
# 
# SAMPLE_RATE = 2e6
# 
# BANDWIDTH = 500e3
# 
# WINFUNC = ["Bartlett", numpy.bartlett,
#            "Blackman", numpy.blackman,
#            "Hamming", numpy.hamming,
#            "Hanning", numpy.hanning]
# 
# Path: rtlsdr_scanner/panels.py
# class PanelColourBar(wx.Panel):
# 
#     def __init__(self, parent, colourMap):
#         wx.Panel.__init__(self, parent)
#         dpi = wx.ScreenDC().GetPPI()[0]
#         figure = matplotlib.figure.Figure(facecolor='white', dpi=dpi)
#         figure.set_size_inches(200.0 / dpi, 25.0 / dpi)
#         self.canvas = FigureCanvas(self, -1, figure)
#         axes = figure.add_subplot(111)
#         figure.subplots_adjust(0, 0, 1, 1)
#         norm = Normalize(vmin=0, vmax=1)
#         self.bar = ColorbarBase(axes, norm=norm, orientation='horizontal',
#                                 cmap=cm.get_cmap(colourMap))
#         axes.xaxis.set_visible(False)
# 
#     def set_map(self, colourMap):
#         self.bar.set_cmap(colourMap)
#         self.bar.changed()
#         self.bar.draw_all()
#         self.canvas.draw()
# 
# Path: rtlsdr_scanner/rtltcp.py
# class RtlTcp(object):
#     def __init__(self, host, port, notify):
#         self.host = host
#         self.port = port
# 
#         self.threadBuffer = None
#         self.tuner = 0
#         self.rate = 0
# 
#         self.__setup(notify)
# 
#     def __setup(self, notify):
#         self.threadBuffer = ThreadBuffer(self.host, self.port, notify)
#         self.__get_header()
# 
#     def __get_header(self):
#         header = self.threadBuffer.get_header()
#         if len(header) == 12:
#             if header.startswith('RTL0'):
#                 self.tuner = ((ord(header[4]) << 24) |
#                               (ord(header[5]) << 16) |
#                               (ord(header[6]) << 8) |
#                               ord(header[7]))
# 
#     def __send_command(self, command, data):
#         send = array.array('c', '\0' * 5)
# 
#         struct.pack_into('>l', send, 1, data)
#         send[0] = struct.pack('<b', command)
# 
#         self.threadBuffer.sendall(send)
# 
#     def __read_raw(self, samples):
#         return self.threadBuffer.recv(samples * 2)
# 
#     def __raw_to_iq(self, raw):
#         iq = numpy.empty(len(raw) / 2, 'complex')
#         iq.real, iq.imag = raw[::2], raw[1::2]
#         iq /= (255 / 2)
#         iq -= 1
# 
#         return iq
# 
#     def set_sample_rate(self, rate):
#         self.__send_command(RtlTcpCmd.SET_SAMPLE_RATE, rate)
#         self.rate = rate
# 
#     def set_manual_gain_enabled(self, mode):
#         self.__send_command(RtlTcpCmd.SET_GAIN_MODE, mode)
# 
#     def set_gain(self, gain):
#         self.__send_command(RtlTcpCmd.SET_GAIN, gain * 10)
# 
#     def set_center_freq(self, freq):
#         self.__send_command(RtlTcpCmd.SET_FREQ, freq)
#         self.__read_raw(int(self.rate * 2 * 0.1))
# 
#     def get_tuner_type(self):
#         return self.tuner
# 
#     def read_samples(self, samples):
# 
#         raw = self.__read_raw(samples)
#         return self.__raw_to_iq(raw)
# 
#     def close(self):
#         self.threadBuffer.abort()
#         self.threadBuffer.join()


# Path: rtlsdr_scanner/dialogs_prefs.py
import itertools
import matplotlib
import numpy
import rtlsdr
import wx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from wx.lib.agw.cubecolourdialog import CubeColourDialog
from wx.lib.masked.numctrl import NumCtrl
from rtlsdr_scanner.constants import F_MIN, F_MAX, SAMPLE_RATE, BANDWIDTH, WINFUNC
from rtlsdr_scanner.panels import PanelColourBar
from rtlsdr_scanner.rtltcp import RtlTcp
from rtlsdr_scanner.utils_mpl import get_colours

        gridSizer.Add(refresh, pos=(3, 0), span=(1, 2),
                      flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
        gridSizer.Add(boxSizer2, pos=(4, 0), span=(1, 2),
                      flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
        gridSizer.Add(sizerButtons, pos=(5, 1),
                      flag=wx.ALIGN_RIGHT | wx.ALL, border=5)

        self.SetSizerAndFit(gridSizer)
        self.__draw_limits()

        self.__setup_plot()

    def __setup_plot(self):
        self.axes.clear()
        self.band1 = None
        self.band2 = None
        self.axes.set_xlabel("Frequency (MHz)")
        self.axes.set_ylabel('Level (dB/Hz)')
        self.axes.set_yscale('log')
        self.axes.set_xlim(-1, 1)
        self.axes.set_ylim(auto=True)
        self.axes.grid(True)
        self.__draw_limits()

    def __plot(self, capture):
        self.__setup_plot()
        pos = WINFUNC[::2].index(self.winFunc)
        function = WINFUNC[1::2][pos]
        powers, freqs = matplotlib.mlab.psd(capture,
                                            NFFT=1024,

                                            Fs=SAMPLE_RATE / 1e6,