<commit_before>"""
xlwings - Make Excel fly with Python!

Homepage and documentation: http://xlwings.org
See also: http://zoomeranalytics.com

Copyright (C) 2014-2016, Zoomer Analytics LLC.
All rights reserved.

License: BSD 3-clause (see LICENSE.txt for details)
"""
import os
import sys
import re
import numbers
import inspect
import tempfile

from . import xlplatform, string_types, ShapeAlreadyExists, PY3
from .utils import VersionNumber

# Optional imports
try:
    from matplotlib.backends.backend_agg import FigureCanvas
except ImportError:
    FigureCanvas = None

try:
    from PIL import Image
except ImportError:
    Image = None


class Collection(object):

    def __init__(self, impl):
        self.impl = impl

    @property
    def api(self):
        return self.impl.api

    def __call__(self, name_or_index):
        return self._wrap(impl=self.impl(name_or_index))

    def __len__(self):
        return len(self.impl)

    count = property(__len__)

    def __iter__(self):
        for impl in self.impl:
            yield self._wrap(impl=impl)

    def __getitem__(self, key):
        if isinstance(key, numbers.Number):
            l = len(self)
            if key >= l:
                raise IndexError("Index %s out of range (%s elements)" % (key, l))
            if key < 0:
                if key < -l:
                    raise IndexError("Index %s out of range (%s elements)" % (key, l))
                key += l
            return self(key + 1)
        elif isinstance(key, slice):
            raise ValueError(self.impl.__class__.__name__ + " object does not support slicing")
        else:
            return self(key)

    def __contains__(self, key):
        return key in self.impl

    # used by repr - by default the name of the collection class, but can be overridden
    @property
    def _name(self):
        return self.__class__.__name__

    def __repr__(self):
        r = []
        for i, x in enumerate(self):
            if i == 3:
                r.append("...")
                break
            else:
                r.append(repr(x))

        return '{}({})'.format(
            self._name,
            "[" + ", ".join(r) + "]"
        )


class Apps(object):

    def __init__(self, impl):
        self.impl = impl

    @property
    def active(self):
        for app in self.impl:
            return App(impl=app)
        return None

    def __call__(self, i):
        return self[i-1]

    def __repr__(self):
        return '{}({})'.format(
            self.__class__.__name__,
            repr(list(self))
        )

    def __getitem__(self, item):
        return App(impl=self.impl[item])

    def __len__(self):
        return len(self.impl)

    count = property(__len__)

    def __iter__(self):
        for app in self.impl:
            yield App(impl=app)


apps = Apps(impl=xlplatform.Apps())


class App(object):
    """
    Application is dependent on the Workbook since there might be different application instances on Windows.
    """

    def __init__(self, spec=None, impl=None, visible=None):
        if impl is None:
            self.impl = xlplatform.App(spec=spec)
            if visible or visible is None:
                self.visible = True
        else:
            self.impl = impl
            if visible:
                self.visible = True

    @property
    def api(self):
        return self.impl.api

    @property
    def version(self):
        return VersionNumber(self.impl.version)

    @property
    def selection(self):
        return Range(impl=self.impl.selection)

    def activate(self, steal_focus=False):
        return self.impl.activate(steal_focus)<commit_msg>App activation makes the app visible<commit_after>"""
xlwings - Make Excel fly with Python!

Homepage and documentation: http://xlwings.org
See also: http://zoomeranalytics.com

Copyright (C) 2014-2016, Zoomer Analytics LLC.
All rights reserved.

License: BSD 3-clause (see LICENSE.txt for details)
"""
import os
import sys
import re
import numbers
import inspect
import tempfile

from . import xlplatform, string_types, ShapeAlreadyExists, PY3
from .utils import VersionNumber

# Optional imports
try:
    from matplotlib.backends.backend_agg import FigureCanvas
except ImportError:
    FigureCanvas = None

try:
    from PIL import Image
except ImportError:
    Image = None


class Collection(object):

    def __init__(self, impl):
        self.impl = impl

    @property
    def api(self):
        return self.impl.api

    def __call__(self, name_or_index):
        return self._wrap(impl=self.impl(name_or_index))

    def __len__(self):
        return len(self.impl)

    count = property(__len__)

    def __iter__(self):
        for impl in self.impl:
            yield self._wrap(impl=impl)

    def __getitem__(self, key):
        if isinstance(key, numbers.Number):
            l = len(self)
            if key >= l:
                raise IndexError("Index %s out of range (%s elements)" % (key, l))
            if key < 0:
                if key < -l:
                    raise IndexError("Index %s out of range (%s elements)" % (key, l))
                key += l
            return self(key + 1)
        elif isinstance(key, slice):
            raise ValueError(self.impl.__class__.__name__ + " object does not support slicing")
        else:
            return self(key)

    def __contains__(self, key):
        return key in self.impl

    # used by repr - by default the name of the collection class, but can be overridden
    @property
    def _name(self):
        return self.__class__.__name__

    def __repr__(self):
        r = []
        for i, x in enumerate(self):
            if i == 3:
                r.append("...")
                break
            else:
                r.append(repr(x))

        return '{}({})'.format(
            self._name,
            "[" + ", ".join(r) + "]"
        )


class Apps(object):

    def __init__(self, impl):
        self.impl = impl

    @property
    def active(self):
        for app in self.impl:
            return App(impl=app)
        return None

    def __call__(self, i):
        return self[i-1]

    def __repr__(self):
        return '{}({})'.format(
            self.__class__.__name__,
            repr(list(self))
        )

    def __getitem__(self, item):
        return App(impl=self.impl[item])

    def __len__(self):
        return len(self.impl)

    count = property(__len__)

    def __iter__(self):
        for app in self.impl:
            yield App(impl=app)


apps = Apps(impl=xlplatform.Apps())


class App(object):
    """
    Application is dependent on the Workbook since there might be different application instances on Windows.
    """

    def __init__(self, spec=None, impl=None, visible=None):
        if impl is None:
            self.impl = xlplatform.App(spec=spec)
            if visible or visible is None:
                self.visible = True
        else:
            self.impl = impl
            if visible:
                self.visible = True

    @property
    def api(self):
        return self.impl.api

    @property
    def version(self):
        return VersionNumber(self.impl.version)

    @property
    def selection(self):
        return Range(impl=self.impl.selection)

    def activate(self, steal_focus=False):
        self.visible = True
        return self.impl.activate(steal_focus)
{'fraction_non_alphanumeric': 0.10031177985631015, 'fraction_numerical': 0.0037955808594279518, 'mean_word_length': 2.016353229762878, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6765815', 'n_tokens_mistral': 2193, 'n_tokens_neox': 2077, 'n_words': 640}