-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #704 from int-brain-lab/task_qc_viewer
Task qc viewer
- Loading branch information
Showing
24 changed files
with
954 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""PyQt5 helper functions.""" | ||
import logging | ||
import sys | ||
from functools import wraps | ||
|
||
from PyQt5 import QtWidgets | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_main_window(): | ||
"""Get the Main window of a QT application.""" | ||
app = QtWidgets.QApplication.instance() | ||
return [w for w in app.topLevelWidgets() if isinstance(w, QtWidgets.QMainWindow)][0] | ||
|
||
|
||
def create_app(): | ||
"""Create a Qt application.""" | ||
global QT_APP | ||
QT_APP = QtWidgets.QApplication.instance() | ||
if QT_APP is None: # pragma: no cover | ||
QT_APP = QtWidgets.QApplication(sys.argv) | ||
return QT_APP | ||
|
||
|
||
def require_qt(func): | ||
"""Function decorator to specify that a function requires a Qt application. | ||
Use this decorator to specify that a function needs a running Qt application before it can run. | ||
An error is raised if that is not the case. | ||
""" | ||
@wraps(func) | ||
def wrapped(*args, **kwargs): | ||
if not QtWidgets.QApplication.instance(): | ||
_logger.warning('Creating a Qt application.') | ||
create_app() | ||
return func(*args, **kwargs) | ||
return wrapped | ||
|
||
|
||
@require_qt | ||
def run_app(): # pragma: no cover | ||
"""Run the Qt application.""" | ||
global QT_APP | ||
return QT_APP.exit(QT_APP.exec_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.