# Path: pyweed/signals.py
# class SignalingThread(QtCore.QThread):
#     """
#     Mixin that serves to standardize how we use signals to pass information around
#     """
#     # Signal to indicate success
#     done = QtCore.pyqtSignal(object)
# 
#     def __del__(self):
#         self.wait()
# 
# class SignalingObject(QtCore.QObject):
#     """
#     Mixin for other objects that manage threaded work, and need to signal completion
#     """
#     # Signal to indicate success
#     done = QtCore.pyqtSignal(object)
# 
# Path: pyweed/dist_from_events.py
# def get_combined_locations(points, distance):
#     """
#     Given a set of points and a distance, return a reasonable set of
#     bounding areas covering everything within that distance of any point.
#     """
#     # Very simple implementation, try to draw a box around all points
#     box = LatLonBox(distance)
# 
#     if not points:
#         return []
# 
#     for lat, lon in points:
#         box.add_point(lat, lon)
#     LOGGER.info("Combined points into: %s", box)
#     return [box]
# 
# class CrossBorderException(Exception):
#     pass


import logging
import concurrent.futures
    import doctest
from pyweed.signals import SignalingThread, SignalingObject
from obspy.core.inventory.inventory import Inventory
from pyweed.pyweed_utils import get_service_url, CancelledException, DataRequest, get_distance
from PyQt5 import QtCore
from pyweed.dist_from_events import get_combined_locations, CrossBorderException


class StationsDataRequest(DataRequest):
    event_locations = None
    distance_range = None

    def __init__(self, client, base_options, distance_range, event_locations):
        """
        :param client: an ObsPy FDSN client
        :param base_options: the basic query options (ie. from StationOptions)
        :param distance_range: a tuple of (min, max) if querying by distance from events
        :param event_locations: a list of selected event locations if querying by distance from events
        """
        super(StationsDataRequest, self).__init__(client)
        if distance_range and event_locations:
            # Get a list of just the (lat, lon) for each event
            self.event_locations = list((loc[1] for loc in event_locations))
            self.distance_range = distance_range
            try:
                combined_locations = get_combined_locations(self.event_locations, self.distance_range['maxdistance'])
                self.sub_requests = [
                    dict(
                        base_options,
                        minlatitude=box.lat1,
                        maxlatitude=box.lat2,
                        minlongitude=box.lon1,
                        maxlongitude=box.lon2
                    )
                    for box in combined_locations
                ]

# Path: pyweed/signals.py
# class SignalingThread(QtCore.QThread):
#     """
#     Mixin that serves to standardize how we use signals to pass information around
#     """
#     # Signal to indicate success
#     done = QtCore.pyqtSignal(object)
# 
#     def __del__(self):
#         self.wait()
# 
# class SignalingObject(QtCore.QObject):
#     """
#     Mixin for other objects that manage threaded work, and need to signal completion
#     """
#     # Signal to indicate success
#     done = QtCore.pyqtSignal(object)
# 
# Path: pyweed/dist_from_events.py
# def get_combined_locations(points, distance):
#     """
#     Given a set of points and a distance, return a reasonable set of
#     bounding areas covering everything within that distance of any point.
#     """
#     # Very simple implementation, try to draw a box around all points
#     box = LatLonBox(distance)
# 
#     if not points:
#         return []
# 
#     for lat, lon in points:
#         box.add_point(lat, lon)
#     LOGGER.info("Combined points into: %s", box)
#     return [box]
# 
# class CrossBorderException(Exception):
#     pass


# Path: pyweed/stations_handler.py
import logging
import concurrent.futures
    import doctest
from pyweed.signals import SignalingThread, SignalingObject
from obspy.core.inventory.inventory import Inventory
from pyweed.pyweed_utils import get_service_url, CancelledException, DataRequest, get_distance
from PyQt5 import QtCore
from pyweed.dist_from_events import get_combined_locations, CrossBorderException



class StationsDataRequest(DataRequest):
    event_locations = None
    distance_range = None

    def __init__(self, client, base_options, distance_range, event_locations):
        """
        :param client: an ObsPy FDSN client
        :param base_options: the basic query options (ie. from StationOptions)
        :param distance_range: a tuple of (min, max) if querying by distance from events
        :param event_locations: a list of selected event locations if querying by distance from events
        """
        super(StationsDataRequest, self).__init__(client)
        if distance_range and event_locations:
            # Get a list of just the (lat, lon) for each event
            self.event_locations = list((loc[1] for loc in event_locations))
            self.distance_range = distance_range
            try:
                combined_locations = get_combined_locations(self.event_locations, self.distance_range['maxdistance'])
                self.sub_requests = [
                    dict(
                        base_options,
                        minlatitude=box.lat1,
                        maxlatitude=box.lat2,
                        minlongitude=box.lon1,
                        maxlongitude=box.lon2
                    )
                    for box in combined_locations
                ]

            except CrossBorderException: