# Path: yubioath/yubicommon/qt/utils.py
# def connect_once(signal, slot):
#     _SignalConnector(signal, slot)
# 
# def get_active_window():
#     active_win = QtGui.QApplication.activeWindow()
#     if active_win is not None:
#         return active_win
# 
#     wins = [w for w in QtGui.QApplication.topLevelWidgets()
#             if isinstance(w, QtGui.QDialog) and w.isVisible()]
# 
#     if not wins:
#         return QtCore.QCoreApplication.instance().window
# 
#     return wins[0]  # TODO: If more than one candidates remain, find best one.
# 
# def default_messages(_m, name='m'):
#     def inner(fn):
#         @wraps(fn)
#         def wrapper(*args, **kwargs):
#             index = getargspec(fn).args.index(name)
#             if len(args) > index:
#                 args = list(args)
#                 args[index] = _DefaultMessages(_m, args[index])
#             else:
#                 kwargs[name] = _DefaultMessages(_m, kwargs.get(name))
#             return fn(*args, **kwargs)
#         return wrapper
#     return inner


from PySide import QtGui, QtCore
from functools import partial
from os import getenv
from .utils import connect_once, get_active_window, default_messages
import traceback
# modified version of that library), containing parts covered by the
# terms of the OpenSSL or SSLeay licenses, We grant you additional
# permission to convey the resulting work. Corresponding Source for a
# non-source form of such a combination shall include the source code
# for the parts of OpenSSL used as well as that of the covered work.

from __future__ import absolute_import



class _Messages(object):
    wait = 'Please wait...'


class _Event(QtCore.QEvent):
    EVENT_TYPE = QtCore.QEvent.Type(QtCore.QEvent.registerEventType())

    def __init__(self, callback):
        super(_Event, self).__init__(_Event.EVENT_TYPE)
        self._callback = callback

    def callback(self):
        self._callback()
        del self._callback


class Worker(QtCore.QObject):
    _work_signal = QtCore.Signal(tuple)
    _work_done_0 = QtCore.Signal()


# Path: yubioath/yubicommon/qt/utils.py
# def connect_once(signal, slot):
#     _SignalConnector(signal, slot)
# 
# def get_active_window():
#     active_win = QtGui.QApplication.activeWindow()
#     if active_win is not None:
#         return active_win
# 
#     wins = [w for w in QtGui.QApplication.topLevelWidgets()
#             if isinstance(w, QtGui.QDialog) and w.isVisible()]
# 
#     if not wins:
#         return QtCore.QCoreApplication.instance().window
# 
#     return wins[0]  # TODO: If more than one candidates remain, find best one.
# 
# def default_messages(_m, name='m'):
#     def inner(fn):
#         @wraps(fn)
#         def wrapper(*args, **kwargs):
#             index = getargspec(fn).args.index(name)
#             if len(args) > index:
#                 args = list(args)
#                 args[index] = _DefaultMessages(_m, args[index])
#             else:
#                 kwargs[name] = _DefaultMessages(_m, kwargs.get(name))
#             return fn(*args, **kwargs)
#         return wrapper
#     return inner


# Path: yubioath/yubicommon/qt/worker.py
from PySide import QtGui, QtCore
from functools import partial
from os import getenv
from .utils import connect_once, get_active_window, default_messages
import traceback

# modified version of that library), containing parts covered by the
# terms of the OpenSSL or SSLeay licenses, We grant you additional
# permission to convey the resulting work. Corresponding Source for a
# non-source form of such a combination shall include the source code
# for the parts of OpenSSL used as well as that of the covered work.

from __future__ import absolute_import



class _Messages(object):
    wait = 'Please wait...'


class _Event(QtCore.QEvent):
    EVENT_TYPE = QtCore.QEvent.Type(QtCore.QEvent.registerEventType())

    def __init__(self, callback):
        super(_Event, self).__init__(_Event.EVENT_TYPE)
        self._callback = callback

    def callback(self):
        self._callback()
        del self._callback


class Worker(QtCore.QObject):
    _work_signal = QtCore.Signal(tuple)
    _work_done_0 = QtCore.Signal()


    @default_messages(_Messages)