# Path: wwb_scanner/scan_objects/spectrum.py
# def compare_spectra(spec1, spec2):
#     diff_spec = Spectrum()
#     for sample in spec1.iter_samples():
#         other_sample = spec2.samples.get(sample.frequency)
#         if other_sample is None:
#             continue
#         magnitude = sample.magnitude - other_sample.magnitude
#         diff_spec.add_sample(frequency=sample.frequency, magnitude=magnitude)
#     return diff_spec
# 
# Path: wwb_scanner/file_handlers/importers.py
# class BaseImporter(object):
#     def __init__(self, **kwargs):
#         self.spectrum = Spectrum()
#         self.filename = kwargs.get('filename')
#     @classmethod
#     def import_file(cls, filename):
#         ext = os.path.splitext(filename)[1].strip('.').lower()
#         def find_importer(_cls):
#             if getattr(_cls, '_extension', None) == ext:
#                 return _cls
#             for _subcls in _cls.__subclasses__():
#                 r = find_importer(_subcls)
#                 if r is not None:
#                     return r
#             return None
#         cls = find_importer(BaseImporter)
#         fh = cls(filename=filename)
#         return fh()
#     def __call__(self):
#         self.file_data = self.load_file()
#         self.parse_file_data()
#         return self.spectrum
#     def load_file(self):
#         with open(self.filename, 'r') as f:
#             s = f.read()
#         return s
#     def parse_file_data(self):
#         raise NotImplementedError('Method must be implemented by subclasses')


import numpy as np
import matplotlib.pyplot as plt
from wwb_scanner.scan_objects.spectrum import compare_spectra
from wwb_scanner.file_handlers import BaseImporter
        #self.figure.canvas.mpl_connect('idle_event', self.on_idle)

    @property
    def x(self):
        return getattr(self, '_x', None)
    @x.setter
    def x(self, value):
        self._x = value
    @property
    def y(self):
        return getattr(self, '_y', None)
    @y.setter
    def y(self, value):
        self._y = value
    @property
    def figure(self):
        return getattr(self, '_figure', None)
    @figure.setter
    def figure(self, figure):
        self._figure = figure
        #self.timer = figure.canvas.new_timer(interval=100)
        #self.timer.add_callback(self.on_timer)
    def on_timer(self):
        print('timer')
        spectrum = self.spectrum
        with spectrum.data_update_lock:
            if spectrum.data_updated.is_set():
                print('update plot')
                self.update_plot()
                spectrum.data_updated.clear()

# Path: wwb_scanner/scan_objects/spectrum.py
# def compare_spectra(spec1, spec2):
#     diff_spec = Spectrum()
#     for sample in spec1.iter_samples():
#         other_sample = spec2.samples.get(sample.frequency)
#         if other_sample is None:
#             continue
#         magnitude = sample.magnitude - other_sample.magnitude
#         diff_spec.add_sample(frequency=sample.frequency, magnitude=magnitude)
#     return diff_spec
# 
# Path: wwb_scanner/file_handlers/importers.py
# class BaseImporter(object):
#     def __init__(self, **kwargs):
#         self.spectrum = Spectrum()
#         self.filename = kwargs.get('filename')
#     @classmethod
#     def import_file(cls, filename):
#         ext = os.path.splitext(filename)[1].strip('.').lower()
#         def find_importer(_cls):
#             if getattr(_cls, '_extension', None) == ext:
#                 return _cls
#             for _subcls in _cls.__subclasses__():
#                 r = find_importer(_subcls)
#                 if r is not None:
#                     return r
#             return None
#         cls = find_importer(BaseImporter)
#         fh = cls(filename=filename)
#         return fh()
#     def __call__(self):
#         self.file_data = self.load_file()
#         self.parse_file_data()
#         return self.spectrum
#     def load_file(self):
#         with open(self.filename, 'r') as f:
#             s = f.read()
#         return s
#     def parse_file_data(self):
#         raise NotImplementedError('Method must be implemented by subclasses')


# Path: wwb_scanner/ui/plots.py
import numpy as np
import matplotlib.pyplot as plt
from wwb_scanner.scan_objects.spectrum import compare_spectra
from wwb_scanner.file_handlers import BaseImporter

        #self.figure.canvas.mpl_connect('idle_event', self.on_idle)

    @property
    def x(self):
        return getattr(self, '_x', None)
    @x.setter
    def x(self, value):
        self._x = value
    @property
    def y(self):
        return getattr(self, '_y', None)
    @y.setter
    def y(self, value):
        self._y = value
    @property
    def figure(self):
        return getattr(self, '_figure', None)
    @figure.setter
    def figure(self, figure):
        self._figure = figure
        #self.timer = figure.canvas.new_timer(interval=100)
        #self.timer.add_callback(self.on_timer)
    def on_timer(self):
        print('timer')
        spectrum = self.spectrum
        with spectrum.data_update_lock:
            if spectrum.data_updated.is_set():
                print('update plot')
                self.update_plot()
                spectrum.data_updated.clear()

    def build_data(self):