# Path: rtlsdr_scanner/constants.py
# class Display(object):
#     PLOT, SPECT, SURFACE, STATUS, TIMELINE, PREVIEW = range(6)
# 
# class Mode(object):
#     SINGLE, CONTIN, MAX = range(3)
# 
# class PlotFunc(object):
#     NONE, AVG, MIN, MAX, VAR, SMOOTH, DIFF, DELTA = range(8)
# 
# Path: rtlsdr_scanner/devices.py
# class DeviceRTL(object):
#     def __init__(self):
#         self.isDevice = True
#         self.indexRtl = None
#         self.name = None
#         self.serial = ''
#         self.server = 'localhost'
#         self.port = 1234
#         self.gains = []
#         self.gain = 0
#         self.calibration = 0
#         self.lo = 0
#         self.offset = 250e3
#         self.tuner = 0
#         self.levelOff = 0
# 
#     def set(self, device):
#         self.gain = device.gain
#         self.calibration = device.calibration
#         self.lo = device.lo
#         self.offset = device.offset
#         self.tuner = device.tuner
#         self.levelOff = device.levelOff
# 
#     def get_gains_str(self):
#         gainsStr = []
#         for gain in self.gains:
#             gainsStr.append(str(gain))
# 
#         return gainsStr
# 
#     def get_closest_gain_str(self, desired):
#         gain = min(self.gains, key=lambda n: abs(n - desired))
# 
#         return str(gain)
# 
# def format_device_rtl_name(name):
#     remove = ["/", "\\"]
#     for char in remove:
#         name = name.replace(char, " ")
# 
#     return name
# 
# class DeviceGPS(object):
#     NMEA_SERIAL, GPSD, GPSD_OLD, NMEA_TCP = range(4)
#     TYPE = ['NMEA (Serial)', 'GPSd', 'GPSd (Legacy)', 'NMEA (Server)']
#     BYTES = [serial.FIVEBITS, serial.SIXBITS, serial.SEVENBITS,
#              serial.EIGHTBITS]
#     PARITIES = [serial.PARITY_NONE, serial.PARITY_EVEN, serial.PARITY_ODD,
#                 serial.PARITY_MARK, serial.PARITY_SPACE]
#     STOPS = [serial.STOPBITS_ONE, serial.STOPBITS_ONE_POINT_FIVE,
#              serial.STOPBITS_TWO]
# 
#     def __init__(self):
#         self.name = 'GPS'
#         self.type = self.GPSD
#         self.resource = 'localhost:2947'
#         self.baud = 115200
#         self.bytes = serial.EIGHTBITS
#         self.parity = serial.PARITY_NONE
#         self.stops = serial.STOPBITS_ONE
#         self.soft = False
# 
#     def get_bauds(self):
#         if self.type == DeviceGPS.NMEA_SERIAL:
#             return serial.Serial.BAUDRATES
# 
#         return None
# 
#     def get_serial_desc(self):
#         port = self.resource.split('/')
#         return '{} {}-{}{}{:g}'.format(port[0], self.baud, self.bytes,
#                                        self.parity, self.stops)
# 
#     def get_desc(self):
#         if self.type == DeviceGPS.NMEA_SERIAL:
#             return self.get_serial_desc()
# 
#         return self.resource


import ConfigParser
import wx
from rtlsdr_scanner.constants import Display, Mode, PlotFunc
from rtlsdr_scanner.devices import DeviceRTL, format_device_rtl_name, DeviceGPS

    def __load(self):
        self.cfg = wx.Config('rtlsdr-scanner')

        self.cfg.RenameGroup('Devices', 'DevicesRTL')

        self.display = self.cfg.ReadInt('display', self.display)
        self.saveWarn = self.cfg.ReadBool('saveWarn', self.saveWarn)
        self.backup = self.cfg.ReadBool('backup', self.backup)
        self.fileHistory.Load(self.cfg)
        self.dirScans = self.cfg.Read('dirScans', self.dirScans)
        self.dirExport = self.cfg.Read('dirExport', self.dirExport)
        self.annotate = self.cfg.ReadBool('annotate', self.annotate)
        self.peaks = self.cfg.ReadBool('peaks', self.peaks)
        self.peaksThres = self.cfg.ReadInt('peaksThres', self.peaksThres)
        self.retainScans = self.cfg.ReadBool('retainScans', self.retainScans)
        self.fadeScans = self.cfg.ReadBool('fadeScans', self.fadeScans)
        self.lineWidth = self.cfg.ReadFloat('lineWidth', self.lineWidth)
        self.retainMax = self.cfg.ReadInt('retainMax', self.retainMax)
        self.colourMapUse = self.cfg.ReadBool('colourMapUse', self.colourMapUse)
        self.colourMap = self.cfg.Read('colourMap', self.colourMap)
        self.background = self.cfg.Read('background', self.background)
        self.wireframe = self.cfg.ReadBool('wireframe', self.wireframe)
        self.pointsLimit = self.cfg.ReadBool('pointsLimit', self.pointsLimit)
        self.pointsMax = self.cfg.ReadInt('pointsMax', self.pointsMax)
        self.grid = self.cfg.ReadBool('grid', self.grid)
        self.plotFunc = self.cfg.ReadInt('plotFunc', self.plotFunc)
        self.smoothFunc = self.cfg.Read('smoothFunc', self.smoothFunc)
        self.smoothRatio = self.cfg.ReadInt('smoothRatio', self.smoothRatio)
        self.clickTune = self.cfg.ReadBool('clickTune', self.clickTune)

# Path: rtlsdr_scanner/constants.py
# class Display(object):
#     PLOT, SPECT, SURFACE, STATUS, TIMELINE, PREVIEW = range(6)
# 
# class Mode(object):
#     SINGLE, CONTIN, MAX = range(3)
# 
# class PlotFunc(object):
#     NONE, AVG, MIN, MAX, VAR, SMOOTH, DIFF, DELTA = range(8)
# 
# Path: rtlsdr_scanner/devices.py
# class DeviceRTL(object):
#     def __init__(self):
#         self.isDevice = True
#         self.indexRtl = None
#         self.name = None
#         self.serial = ''
#         self.server = 'localhost'
#         self.port = 1234
#         self.gains = []
#         self.gain = 0
#         self.calibration = 0
#         self.lo = 0
#         self.offset = 250e3
#         self.tuner = 0
#         self.levelOff = 0
# 
#     def set(self, device):
#         self.gain = device.gain
#         self.calibration = device.calibration
#         self.lo = device.lo
#         self.offset = device.offset
#         self.tuner = device.tuner
#         self.levelOff = device.levelOff
# 
#     def get_gains_str(self):
#         gainsStr = []
#         for gain in self.gains:
#             gainsStr.append(str(gain))
# 
#         return gainsStr
# 
#     def get_closest_gain_str(self, desired):
#         gain = min(self.gains, key=lambda n: abs(n - desired))
# 
#         return str(gain)
# 
# def format_device_rtl_name(name):
#     remove = ["/", "\\"]
#     for char in remove:
#         name = name.replace(char, " ")
# 
#     return name
# 
# class DeviceGPS(object):
#     NMEA_SERIAL, GPSD, GPSD_OLD, NMEA_TCP = range(4)
#     TYPE = ['NMEA (Serial)', 'GPSd', 'GPSd (Legacy)', 'NMEA (Server)']
#     BYTES = [serial.FIVEBITS, serial.SIXBITS, serial.SEVENBITS,
#              serial.EIGHTBITS]
#     PARITIES = [serial.PARITY_NONE, serial.PARITY_EVEN, serial.PARITY_ODD,
#                 serial.PARITY_MARK, serial.PARITY_SPACE]
#     STOPS = [serial.STOPBITS_ONE, serial.STOPBITS_ONE_POINT_FIVE,
#              serial.STOPBITS_TWO]
# 
#     def __init__(self):
#         self.name = 'GPS'
#         self.type = self.GPSD
#         self.resource = 'localhost:2947'
#         self.baud = 115200
#         self.bytes = serial.EIGHTBITS
#         self.parity = serial.PARITY_NONE
#         self.stops = serial.STOPBITS_ONE
#         self.soft = False
# 
#     def get_bauds(self):
#         if self.type == DeviceGPS.NMEA_SERIAL:
#             return serial.Serial.BAUDRATES
# 
#         return None
# 
#     def get_serial_desc(self):
#         port = self.resource.split('/')
#         return '{} {}-{}{}{:g}'.format(port[0], self.baud, self.bytes,
#                                        self.parity, self.stops)
# 
#     def get_desc(self):
#         if self.type == DeviceGPS.NMEA_SERIAL:
#             return self.get_serial_desc()
# 
#         return self.resource


# Path: rtlsdr_scanner/settings.py
import ConfigParser
import wx
from rtlsdr_scanner.constants import Display, Mode, PlotFunc
from rtlsdr_scanner.devices import DeviceRTL, format_device_rtl_name, DeviceGPS


    def __load(self):
        self.cfg = wx.Config('rtlsdr-scanner')

        self.cfg.RenameGroup('Devices', 'DevicesRTL')

        self.display = self.cfg.ReadInt('display', self.display)
        self.saveWarn = self.cfg.ReadBool('saveWarn', self.saveWarn)
        self.backup = self.cfg.ReadBool('backup', self.backup)
        self.fileHistory.Load(self.cfg)
        self.dirScans = self.cfg.Read('dirScans', self.dirScans)
        self.dirExport = self.cfg.Read('dirExport', self.dirExport)
        self.annotate = self.cfg.ReadBool('annotate', self.annotate)
        self.peaks = self.cfg.ReadBool('peaks', self.peaks)
        self.peaksThres = self.cfg.ReadInt('peaksThres', self.peaksThres)
        self.retainScans = self.cfg.ReadBool('retainScans', self.retainScans)
        self.fadeScans = self.cfg.ReadBool('fadeScans', self.fadeScans)
        self.lineWidth = self.cfg.ReadFloat('lineWidth', self.lineWidth)
        self.retainMax = self.cfg.ReadInt('retainMax', self.retainMax)
        self.colourMapUse = self.cfg.ReadBool('colourMapUse', self.colourMapUse)
        self.colourMap = self.cfg.Read('colourMap', self.colourMap)
        self.background = self.cfg.Read('background', self.background)
        self.wireframe = self.cfg.ReadBool('wireframe', self.wireframe)
        self.pointsLimit = self.cfg.ReadBool('pointsLimit', self.pointsLimit)
        self.pointsMax = self.cfg.ReadInt('pointsMax', self.pointsMax)
        self.grid = self.cfg.ReadBool('grid', self.grid)
        self.plotFunc = self.cfg.ReadInt('plotFunc', self.plotFunc)
        self.smoothFunc = self.cfg.Read('smoothFunc', self.smoothFunc)
        self.smoothRatio = self.cfg.ReadInt('smoothRatio', self.smoothRatio)
        self.clickTune = self.cfg.ReadBool('clickTune', self.clickTune)

        self.precisionFreq = self.cfg.ReadInt('precisionFreq', self.precisionFreq)