<commit_before>"""
Helper module for loading an ActiveX library.

The module also defines all the `Window Styles`_ and `Extended Window Styles`_ constants.

.. _Window Styles: https://docs.microsoft.com/en-us/windows/win32/winmsg/window-styles
.. _Extended Window Styles: https://docs.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles
"""
import ctypes

try:
    import clr
    import System
    clr.AddReference('System.Windows.Forms')
    import System.Windows.Forms as Forms
    from System.Threading import ApartmentState, Thread, ThreadStart
except:
    clr = None

    class Forms(object):
        Form = object
        """Represents a window or dialog box that makes up an application's user interface."""

try:
    from comtypes import (
        IUnknown,
        GUID,
    )
    from comtypes.client import (
        GetEvents,
        GetBestInterface,
    )
except:
    GUID = None


CW_USEDEFAULT = 0x80000000

# Window Styles
WS_OVERLAPPED = 0x00000000
WS_POPUP = 0x80000000
WS_CHILD = 0x40000000
WS_MINIMIZE = 0x20000000
WS_VISIBLE = 0x10000000
WS_DISABLED = 0x08000000
WS_CLIPSIBLINGS = 0x04000000
WS_CLIPCHILDREN = 0x02000000
WS_MAXIMIZE = 0x01000000
WS_CAPTION = 0x00C00000
WS_BORDER = 0x00800000
WS_DLGFRAME = 0x00400000
WS_VSCROLL = 0x00200000
WS_HSCROLL = 0x00100000
WS_SYSMENU = 0x00080000
WS_THICKFRAME = 0x00040000
WS_GROUP = 0x00020000
WS_TABSTOP = 0x00010000
WS_MINIMIZEBOX = 0x00020000
WS_MAXIMIZEBOX = 0x00010000
WS_TILED = WS_OVERLAPPED
WS_ICONIC = WS_MINIMIZE
WS_SIZEBOX = WS_THICKFRAME
WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU
WS_CHILDWINDOW = WS_CHILD
WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW

# Extended Window Styles
WS_EX_DLGMODALFRAME = 0x00000001
WS_EX_NOPARENTNOTIFY = 0x00000004
WS_EX_TOPMOST = 0x00000008
WS_EX_ACCEPTFILES = 0x00000010
WS_EX_TRANSPARENT = 0x00000020
WS_EX_MDICHILD = 0x00000040
WS_EX_TOOLWINDOW = 0x00000080
WS_EX_WINDOWEDGE = 0x00000100
WS_EX_CLIENTEDGE = 0x00000200
WS_EX_CONTEXTHELP = 0x00000400
WS_EX_RIGHT = 0x00001000
WS_EX_LEFT = 0x00000000
WS_EX_RTLREADING = 0x00002000
WS_EX_LTRREADING = 0x00000000
WS_EX_LEFTSCROLLBAR = 0x00004000
WS_EX_RIGHTSCROLLBAR = 0x00000000
WS_EX_CONTROLPARENT = 0x00010000
WS_EX_STATICEDGE = 0x00020000
WS_EX_APPWINDOW = 0x00040000
WS_EX_LAYERED = 0x00080000
WS_EX_NOINHERITLAYOUT = 0x00100000
WS_EX_NOREDIRECTIONBITMAP = 0x00200000
WS_EX_LAYOUTRTL = 0x00400000
WS_EX_COMPOSITED = 0x02000000
WS_EX_NOACTIVATE = 0x08000000
WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE
WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST


class Application(Forms.Form):

    def __init__(self):
        """Create the main application window to display ActiveX controls.

        Creating an application requires pythonnet_ to be installed.

        See Form_ for more details.

        .. _Form: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.form
        .. _pythonnet: https://pypi.org/project/pythonnet/

        Examples
        --------
        >>> from msl.loadlib.activex import Application
        >>> app = Application()
        >>> app.create_panel()
        <System.Windows.Forms.Panel object at ...>
        """
        super(Application, self).__init__()

        if clr is None:
            raise RuntimeError(
                'Creating an ActiveX application requires pythonnet to be installed.\n'
                'Run: pip install pythonnet'
            )

        self._event_connections = []

    def handle_events(self, sink, source=None, interface=None):
        """Handle events from an ActiveX object.

        Parameters
        ----------
        sink
            The object that handles the events. The `sink` must
            define methods with the same names as the ActiveX event names.
        source
            An ActiveX object that sends events. If not specified then
            uses the calling application instance as the `source`.
        interface
            The interface to use.
        """
        cxn = GetEvents(source or self, sink, interface=interface)
        self._event_connections.append(cxn)

    @staticmethod<commit_msg>change signature of Application.handle_events<commit_after>"""
Helper module for loading an ActiveX library.

The module also defines all the `Window Styles`_ and `Extended Window Styles`_ constants.

.. _Window Styles: https://docs.microsoft.com/en-us/windows/win32/winmsg/window-styles
.. _Extended Window Styles: https://docs.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles
"""
import ctypes

try:
    import clr
    import System
    clr.AddReference('System.Windows.Forms')
    import System.Windows.Forms as Forms
    from System.Threading import ApartmentState, Thread, ThreadStart
except:
    clr = None

    class Forms(object):
        Form = object
        """Represents a window or dialog box that makes up an application's user interface."""

try:
    from comtypes import (
        IUnknown,
        GUID,
    )
    from comtypes.client import (
        GetEvents,
        GetBestInterface,
    )
except:
    GUID = None


CW_USEDEFAULT = 0x80000000

# Window Styles
WS_OVERLAPPED = 0x00000000
WS_POPUP = 0x80000000
WS_CHILD = 0x40000000
WS_MINIMIZE = 0x20000000
WS_VISIBLE = 0x10000000
WS_DISABLED = 0x08000000
WS_CLIPSIBLINGS = 0x04000000
WS_CLIPCHILDREN = 0x02000000
WS_MAXIMIZE = 0x01000000
WS_CAPTION = 0x00C00000
WS_BORDER = 0x00800000
WS_DLGFRAME = 0x00400000
WS_VSCROLL = 0x00200000
WS_HSCROLL = 0x00100000
WS_SYSMENU = 0x00080000
WS_THICKFRAME = 0x00040000
WS_GROUP = 0x00020000
WS_TABSTOP = 0x00010000
WS_MINIMIZEBOX = 0x00020000
WS_MAXIMIZEBOX = 0x00010000
WS_TILED = WS_OVERLAPPED
WS_ICONIC = WS_MINIMIZE
WS_SIZEBOX = WS_THICKFRAME
WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU
WS_CHILDWINDOW = WS_CHILD
WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW

# Extended Window Styles
WS_EX_DLGMODALFRAME = 0x00000001
WS_EX_NOPARENTNOTIFY = 0x00000004
WS_EX_TOPMOST = 0x00000008
WS_EX_ACCEPTFILES = 0x00000010
WS_EX_TRANSPARENT = 0x00000020
WS_EX_MDICHILD = 0x00000040
WS_EX_TOOLWINDOW = 0x00000080
WS_EX_WINDOWEDGE = 0x00000100
WS_EX_CLIENTEDGE = 0x00000200
WS_EX_CONTEXTHELP = 0x00000400
WS_EX_RIGHT = 0x00001000
WS_EX_LEFT = 0x00000000
WS_EX_RTLREADING = 0x00002000
WS_EX_LTRREADING = 0x00000000
WS_EX_LEFTSCROLLBAR = 0x00004000
WS_EX_RIGHTSCROLLBAR = 0x00000000
WS_EX_CONTROLPARENT = 0x00010000
WS_EX_STATICEDGE = 0x00020000
WS_EX_APPWINDOW = 0x00040000
WS_EX_LAYERED = 0x00080000
WS_EX_NOINHERITLAYOUT = 0x00100000
WS_EX_NOREDIRECTIONBITMAP = 0x00200000
WS_EX_LAYOUTRTL = 0x00400000
WS_EX_COMPOSITED = 0x02000000
WS_EX_NOACTIVATE = 0x08000000
WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE
WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST


class Application(Forms.Form):

    def __init__(self):
        """Create the main application window to display ActiveX controls.

        Creating an application requires pythonnet_ to be installed.

        See Form_ for more details.

        .. _Form: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.form
        .. _pythonnet: https://pypi.org/project/pythonnet/

        Examples
        --------
        >>> from msl.loadlib.activex import Application
        >>> app = Application()
        >>> app.create_panel()
        <System.Windows.Forms.Panel object at ...>
        """
        super(Application, self).__init__()

        if clr is None:
            raise RuntimeError(
                'Creating an ActiveX application requires pythonnet to be installed.\n'
                'Run: pip install pythonnet'
            )

        self._event_connections = []

    def handle_events(self, source, sink=None, interface=None):
        """Handle events from an ActiveX object.

        Parameters
        ----------
        source
            The ActiveX object that emits events.
        sink
            The object that handles the events. The `sink` must
            define methods with the same names as the ActiveX event names.
            If not specified then uses the calling application instance
            as the `sink`.
        interface
            The interface to use.
        """
        cxn = GetEvents(source, sink or self, interface=interface)
        self._event_connections.append(cxn)

    @staticmethod
{'fraction_non_alphanumeric': 0.06873457878040183, 'fraction_numerical': 0.09799083538949595, 'mean_word_length': 3.3808543489449305, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 24, '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': '6502158', 'n_tokens_mistral': 3658, 'n_tokens_neox': 2855, 'n_words': 668}