# Path: thrifty/settings.py
# DEFINITIONS = {
#     'sample_rate': Definition(
#         ['--sample-rate', '-s'],
#         setting_parsers.metric_float,
#         '2.4M',
#         "Sample rate (sps)"
#     ),
# 
#     'chip_rate': Definition(
#         ['--chip-rate', '-p'],
#         setting_parsers.metric_float,
#         '0.999707M',
#         "Rate at which the code is being transmitted (bps)"
#     ),
# 
#     'tuner_freq': Definition(
#         ['--freq', '-f'],
#         setting_parsers.metric_float,
#         '433.83M',
#         "Tuner center frequency (Hz)"
#     ),
# 
#     'tuner_gain': Definition(
#         ['--gain', '-g'],
#         float,
#         '0',
#         "Tuner gain (dB)"
#     ),
# 
#     'capture_skip': Definition(
#         ['--skip', '-k'],
#         int,
#         '1',
#         "Number of blocks to skip before starting capturing from the SDR"
#     ),
# 
#     'block_size': Definition(
#         ['--block-size', '-b'],
#         int,
#         '16384',
#         "Length of fixed-sized blocks, which should be a power of two "
#         "(samples)"
#     ),
# 
#     'block_history': Definition(
#         ['--history', '-y'],
#         int,
#         '4920',
#         "The number of samples at the end of a block that should be repeated "
#         "at the start of the next block (samples)"
#     ),
# 
#     'carrier_window': Definition(
#         ['--carrier-window', '-w'],
#         setting_parsers.freq_range,
#         '0--1',
#         "Range of frequencies or frequency bins to look for carrier"
#     ),
# 
#     'carrier_threshold': Definition(
#         ['--carrier-threshold', '-t'],
#         setting_parsers.threshold,
#         '15*snr',
#         "Threshold formula for carrier detector"
#     ),
# 
#     'corr_threshold': Definition(
#         ['--corr-threshold', '-u'],
#         setting_parsers.threshold,
#         '15*snr',
#         "Threshold formula for correlation peak detector"
#     ),
# 
#     'template': Definition(
#         ['--template', '-z'],
#         str,
#         'template.npy',
#         "Load template from a Numpy .npy file"
#     ),
# 
#     'rxid': Definition(
#         ['--rxid', '-r'],
#         int,
#         -1,
#         "Unique identifier of this receiver"
#     ),
# }
# DEFAULT_CONFIG_PATH = 'detector.cfg'
# CONFIG_COMMENT_CHAR = '#'
# CONFIG_DELIMITER = ':'
# CONFIG_DEST = 'config'
# class Error(Exception):
# class ConfigSyntaxError(Error):
# class SettingKeyError(Error):
# class Namespace(dict):
#     def __init__(self, line_no, msg):
#     def __str__(self):
#     def __init__(self, msg):
#     def __str__(self):
#     def __init__(self, dict_):
# def add_argparse_arguments(parser, keys, definitions=None):
# def load(args=None, config_file=None, definitions=None):
# def load_args(parser, keys, argv=None, definitions=None):
# def parse_kvconfig(config_file):


import argparse
import osmosdr
import sip
    import ctypes
    import sys
from PyQt4 import Qt
from gnuradio import blocks
from gnuradio import gr
from gnuradio import qtgui
from gnuradio.filter import firdes
from gnuradio.qtgui import Range, RangeWidget
from thrifty import settings
    from distutils.version import StrictVersion
def gnuradio_main(samp_rate, gain, freq, block_size):
    if sys.platform.startswith('linux'):
        try:
            x11 = ctypes.cdll.LoadLibrary('libX11.so')
            x11.XInitThreads()
        except:
            print "Warning: failed to XInitThreads()"

    if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
        style = gr.prefs().get_string('qtgui', 'style', 'raster')
        Qt.QApplication.setGraphicsSystem(style)

    qapp = Qt.QApplication([])

    tb = scope(samp_rate, gain, freq, block_size)
    tb.start()
    tb.show()

    def quitting():
        tb.stop()
        tb.wait()
    qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
    qapp.exec_()


def _main():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    setting_keys = ['tuner_freq', 'tuner_gain', 'sample_rate', 'block_size']

# Path: thrifty/settings.py
# DEFINITIONS = {
#     'sample_rate': Definition(
#         ['--sample-rate', '-s'],
#         setting_parsers.metric_float,
#         '2.4M',
#         "Sample rate (sps)"
#     ),
# 
#     'chip_rate': Definition(
#         ['--chip-rate', '-p'],
#         setting_parsers.metric_float,
#         '0.999707M',
#         "Rate at which the code is being transmitted (bps)"
#     ),
# 
#     'tuner_freq': Definition(
#         ['--freq', '-f'],
#         setting_parsers.metric_float,
#         '433.83M',
#         "Tuner center frequency (Hz)"
#     ),
# 
#     'tuner_gain': Definition(
#         ['--gain', '-g'],
#         float,
#         '0',
#         "Tuner gain (dB)"
#     ),
# 
#     'capture_skip': Definition(
#         ['--skip', '-k'],
#         int,
#         '1',
#         "Number of blocks to skip before starting capturing from the SDR"
#     ),
# 
#     'block_size': Definition(
#         ['--block-size', '-b'],
#         int,
#         '16384',
#         "Length of fixed-sized blocks, which should be a power of two "
#         "(samples)"
#     ),
# 
#     'block_history': Definition(
#         ['--history', '-y'],
#         int,
#         '4920',
#         "The number of samples at the end of a block that should be repeated "
#         "at the start of the next block (samples)"
#     ),
# 
#     'carrier_window': Definition(
#         ['--carrier-window', '-w'],
#         setting_parsers.freq_range,
#         '0--1',
#         "Range of frequencies or frequency bins to look for carrier"
#     ),
# 
#     'carrier_threshold': Definition(
#         ['--carrier-threshold', '-t'],
#         setting_parsers.threshold,
#         '15*snr',
#         "Threshold formula for carrier detector"
#     ),
# 
#     'corr_threshold': Definition(
#         ['--corr-threshold', '-u'],
#         setting_parsers.threshold,
#         '15*snr',
#         "Threshold formula for correlation peak detector"
#     ),
# 
#     'template': Definition(
#         ['--template', '-z'],
#         str,
#         'template.npy',
#         "Load template from a Numpy .npy file"
#     ),
# 
#     'rxid': Definition(
#         ['--rxid', '-r'],
#         int,
#         -1,
#         "Unique identifier of this receiver"
#     ),
# }
# DEFAULT_CONFIG_PATH = 'detector.cfg'
# CONFIG_COMMENT_CHAR = '#'
# CONFIG_DELIMITER = ':'
# CONFIG_DEST = 'config'
# class Error(Exception):
# class ConfigSyntaxError(Error):
# class SettingKeyError(Error):
# class Namespace(dict):
#     def __init__(self, line_no, msg):
#     def __str__(self):
#     def __init__(self, msg):
#     def __str__(self):
#     def __init__(self, dict_):
# def add_argparse_arguments(parser, keys, definitions=None):
# def load(args=None, config_file=None, definitions=None):
# def load_args(parser, keys, argv=None, definitions=None):
# def parse_kvconfig(config_file):


# Path: thrifty/scope.py
import argparse
import osmosdr
import sip
    import ctypes
    import sys
from PyQt4 import Qt
from gnuradio import blocks
from gnuradio import gr
from gnuradio import qtgui
from gnuradio.filter import firdes
from gnuradio.qtgui import Range, RangeWidget
from thrifty import settings
    from distutils.version import StrictVersion

def gnuradio_main(samp_rate, gain, freq, block_size):
    if sys.platform.startswith('linux'):
        try:
            x11 = ctypes.cdll.LoadLibrary('libX11.so')
            x11.XInitThreads()
        except:
            print "Warning: failed to XInitThreads()"

    if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
        style = gr.prefs().get_string('qtgui', 'style', 'raster')
        Qt.QApplication.setGraphicsSystem(style)

    qapp = Qt.QApplication([])

    tb = scope(samp_rate, gain, freq, block_size)
    tb.start()
    tb.show()

    def quitting():
        tb.stop()
        tb.wait()
    qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
    qapp.exec_()


def _main():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    setting_keys = ['tuner_freq', 'tuner_gain', 'sample_rate', 'block_size']

    config, _ = settings.load_args(parser, setting_keys)