"""
Custom `Qt <https://www.qt.io/>`_ components for the graphical user interface.
"""
import re
import sys
from collections import namedtuple

__author__ = 'Measurement Standards Laboratory of New Zealand'
__copyright__ = '\xa9 2017 - 2019, ' + __author__
__version__ = '0.1.0.dev0'

_v = re.search(r'(\d+)\.(\d+)\.(\d+)[.-]?(.*)', __version__).groups()

version_info = namedtuple('version_info', 'major minor micro releaselevel')(int(_v[0]), int(_v[1]), int(_v[2]), _v[3])
""":obj:`~collections.namedtuple`: Contains the version information as a (major, minor, micro, releaselevel) tuple."""


def application(args=None):
    """Returns the :class:`QtWidgets.QApplication` instance (creating one if necessary).

    Parameters
    ----------
    args : :class:`list` of :class:`str`, optional
        A list of arguments to initialize the application. If :obj:`None` then
        uses :obj:`sys.argv`.

    Returns
    -------
    :class:`QtWidgets.QApplication`
        The application instance.
    """
    app = QtWidgets.QApplication.instance()
    if app is None:
        app = QtWidgets.QApplication(sys.argv if args is None else args)

        # use a default *MSL logo* as the app icon
        logo = 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAGXRFWHR' \
               'Db21tZW50AENyZWF0ZWQgd2l0aCBHSU1QV4EOFwAAAx9JREFUWIXNlk9oXFUYxX/fnZmmmQ6aVt+rBCsEgo' \
               '<KEY>' \
               '<KEY>' \
               '<KEY>vTd1TAFngCwMGn7RJSC1jrvufX/NryoCnJWLWapLWTWkDfqWgV+D4tv4HUSbhd2O4cuCUWx4p' \
               'PeXgbyIRx/+N<KEY>gQYR9fVLBp04IFL5cMFsl1DHnL7p749Y6CWTdLTwATGN8' \
               '<KEY>' \
               '<KEY>' \
               '<KEY>' \
               '<KEY>' \
               '<KEY>' \
               'W5jZsuEgSQPjZqubte5dw+aWb8wVvwNuOJgIpiqf7lTApohEDprxkqS+D936vC7As0QlIYefddgRXLvnfvq' \
               'wg+l4cFJPH1ynI9qM6dLwwPPIPecsKvBXytvXi4U9vpc8oaMfFSbeQ1QaeixEyCP2Yfnahe+KA0PPm9SCeP' \
               'ns7XZd0pDR49A8qrM3Eht5lgF/H9lKAuFC5KM1me5V48ZAVgBwJTNgwLD3/f3Q2sm57LA/SbCSuMiUggKpK' \
               'QbQN4KwgXy9AA4r13gAhPhxfL6T8y/FrQlyIjl7wYAAAAASUVORK5CYII='
        app.setWindowIcon(io.get_icon(QtCore.QByteArray(logo.encode())))

    return app


from ._qt import *
from .button import Button
from .exceptions import excepthook
from . import io
from .logger import Logger
from .loop_until_abort import LoopUntilAbort
from . import prompt
from .toggle_switch import ToggleSwitch
from .sleep import Sleep
from .threading import Thread, Worker

"""
Custom `Qt <https://www.qt.io/>`_ components for the graphical user interface.
"""
import re
import sys
from collections import namedtuple

__author__ = 'Measurement Standards Laboratory of New Zealand'
__copyright__ = '\xa9 2017 - 2019, ' + __author__
__version__ = '0.1.0.dev0'

_v = re.search(r'(\d+)\.(\d+)\.(\d+)[.-]?(.*)', __version__).groups()

version_info = namedtuple('version_info', 'major minor micro releaselevel')(int(_v[0]), int(_v[1]), int(_v[2]), _v[3])
""":obj:`~collections.namedtuple`: Contains the version information as a (major, minor, micro, releaselevel) tuple."""


def application(args=None):
    """Returns the :class:`QtWidgets.QApplication` instance (creating one if necessary).

    Parameters
    ----------
    args : :class:`list` of :class:`str`, optional
        A list of arguments to initialize the application. If :obj:`None` then
        uses :obj:`sys.argv`.

    Returns
    -------
    :class:`QtWidgets.QApplication`
        The application instance.
    """
    app = QtWidgets.QApplication.instance()
    if app is None:
        app = QtWidgets.QApplication(sys.argv if args is None else args)

        # use a default *MSL logo* as the app icon
        logo = 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAGXRFWHR' \
               'Db21tZW50AENyZWF0ZWQgd2l0aCBHSU1QV4EOFwAAAx9JREFUWIXNlk9oXFUYxX/fnZmmmQ6aVt+rBCsEgo' \
               '<KEY>' \
               '<KEY>' \
               '<KEY>vTd1TAFngCwMGn7RJSC1jrvufX/NryoCnJWLWapLWTWkDfqWgV+D4tv4HUSbhd2O4cuCUWx4p' \
               'PeXgbyIRx/+N<KEY>gQYR9fVLBp04IFL5cMFsl1DHnL7p749Y6CWTdLTwATGN8' \
               '<KEY>' \
               '<KEY>' \
               '<KEY>' \
               '<KEY>' \
               '<KEY>' \
               'W5jZsuEgSQPjZqubte5dw+aWb8wVvwNuOJgIpiqf7lTApohEDprxkqS+D936vC7As0QlIYefddgRXLvnfvq' \
               'wg+l4cFJPH1ynI9qM6dLwwPPIPecsKvBXytvXi4U9vpc8oaMfFSbeQ1QaeixEyCP2Yfnahe+KA0PPm9SCeP' \
               'ns7XZd0pDR49A8qrM3Eht5lgF/H9lKAuFC5KM1me5V48ZAVgBwJTNgwLD3/f3Q2sm57LA/SbCSuMiUggKpK' \
               'QbQN4KwgXy9AA4r13gAhPhxfL6T8y/FrQlyIjl7wYAAAAASUVORK5CYII='
        app.setWindowIcon(io.get_icon(QtCore.QByteArray(logo.encode())))

    return app


from ._qt import *
from .button import Button
from .exceptions import excepthook
from . import io
from .logger import Logger
from .loop_until_abort import LoopUntilAbort
from . import prompt
from .toggle_switch import ToggleSwitch
from .sleep import Sleep
from .threading import Thread, Worker

Custom `Qt <https://www.qt.io/>`_ components for the graphical user interface. :obj:`~collections.namedtuple`: Contains the version information as a (major, minor, micro, releaselevel) tuple. Returns the :class:`QtWidgets.QApplication` instance (creating one if necessary).      Parameters     ----------     args : :class:`list` of :class:`str`, optional         A list of arguments to initialize the application. If :obj:`None` then         uses :obj:`sys.argv`.      Returns     -------     :class:`QtWidgets.QApplication`         The application instance. # use a default *MSL logo* as the app icon