Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoupled winforms event loop from AppContext. #2112

Merged
merged 13 commits into from
Sep 15, 2023
Prev Previous commit
Next Next commit
Restructured CLR reference creation.
  • Loading branch information
freakboy3742 committed Sep 15, 2023
commit b0257201ba9d4c6cda058e04b9b4975961abaedd
12 changes: 12 additions & 0 deletions winforms/src/toga_winforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

import toga

# Add a reference to the Winforms assembly
clr.AddReference("System.Windows.Forms")

# Add a reference to the WindowsBase assembly. This is needed to access
# System.Windows.Threading.Dispatcher.
#
# This assembly isn't exposed as a simple dot-path name; we have to extract it from the
# Global Assembly Cache (GAC). The version number and public key doesn't appear to
# change with Windows version or the underlying .NET, and has been available since
# Windows 7.
clr.AddReference(
"WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
)

__version__ = toga._package_version(__file__, __name__)
9 changes: 1 addition & 8 deletions winforms/src/toga_winforms/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import threading
from ctypes import windll

import clr
import System.Windows.Forms as WinForms
from System import Environment, Threading
from System.Media import SystemSounds
from System.Net import SecurityProtocolType, ServicePointManager
from System.Windows.Threading import Dispatcher

import toga
from toga import Key
Expand All @@ -17,13 +17,6 @@
from .libs.proactor import WinformsProactorEventLoop
from .window import Window

# A Reference to WindowsBase Assembly is needed for Dispatcher
clr.AddReference(
# This Assembly String is very specific and helps clr to resolve Assemblies present in the GAC.
"WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
)
from System.Windows.Threading import Dispatcher # noqa


class MainWindow(Window):
def winforms_FormClosing(self, sender, event):
Expand Down