Skip to content

Commit

Permalink
Merge 0fdc513 into 5ee09ae
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Dec 15, 2020
2 parents 5ee09ae + 0fdc513 commit 8c8e6e3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions magicgui/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from magicgui.widgets._protocols import BaseApplicationBackend

DEFAULT_BACKEND = "qt"
APPLICATION_NAME = "magicgui"


@contextmanager
Expand Down
13 changes: 8 additions & 5 deletions magicgui/backends/_qtpy/application.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from qtpy.QtCore import QTimer
import sys

from qtpy.QtCore import Qt, QTimer
from qtpy.QtWidgets import QApplication

from magicgui.application import APPLICATION_NAME
from magicgui.widgets._protocols import BaseApplicationBackend


# qt implementation
class ApplicationBackend(BaseApplicationBackend):
_app: QApplication

Expand All @@ -19,7 +21,7 @@ def _mgui_process_events(self):
def _mgui_run(self):
app = self._mgui_get_native_app()
# only start the event loop if magicgui created it
if app.objectName() == "magicgui":
if app.applicationName() == APPLICATION_NAME:
return app.exec_()

def _mgui_quit(self):
Expand All @@ -29,8 +31,9 @@ def _mgui_get_native_app(self):
# Get native app
self._app = QApplication.instance()
if not self._app:
self._app = QApplication([])
self._app.setObjectName("magicgui")
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
self._app = QApplication(sys.argv)
self._app.setApplicationName(APPLICATION_NAME)
return self._app

def _mgui_start_timer(self, interval=0, on_timeout=None, single=False):
Expand Down
2 changes: 1 addition & 1 deletion magicgui/widgets/_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ def _mgui_run(self):
def _mgui_quit(self):
"""Quit the native GUI event loop."""

@abstractmethod
def _mgui_get_native_app(self):
"""Return the native GUI application instance."""
return self

@abstractmethod
def _mgui_start_timer(
Expand Down
7 changes: 7 additions & 0 deletions tests/test_application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from magicgui import use_app
from magicgui.application import APPLICATION_NAME


def test_app_name():
app = use_app("qt")
assert app.native.applicationName() == APPLICATION_NAME

0 comments on commit 8c8e6e3

Please sign in to comment.