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

add application_name variable #55

Merged
merged 1 commit into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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