Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Evan Edmond
fslpy
Commits
66e1b06c
Commit
66e1b06c
authored
8 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Some new functions in status module for reporting errors
parent
af32b7cd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/utils/status.py
+61
-1
61 additions, 1 deletion
fsl/utils/status.py
with
61 additions
and
1 deletion
fsl/utils/status.py
+
61
−
1
View file @
66e1b06c
...
@@ -15,6 +15,16 @@ following functions:
...
@@ -15,6 +15,16 @@ following functions:
update
update
clearStatus
clearStatus
A couple of other functions are also provided, for reporting error messages
to the user:
.. autosummary::
:nosignatures:
reportError
reportIfError
reportErrorDecorator
The :func:`update` function may be used to display a message. By default, the
The :func:`update` function may be used to display a message. By default, the
message is simply logged (via the ``logging`` module). However, if a status
message is simply logged (via the ``logging`` module). However, if a status
...
@@ -29,6 +39,7 @@ passed to this target.
...
@@ -29,6 +39,7 @@ passed to this target.
import
threading
import
threading
import
contextlib
import
logging
import
logging
import
inspect
import
inspect
import
os.path
as
op
import
os.path
as
op
...
@@ -108,7 +119,56 @@ def clearStatus():
...
@@ -108,7 +119,56 @@ def clearStatus():
if
_statusUpdateTarget
is
None
:
if
_statusUpdateTarget
is
None
:
return
return
_statusUpdateTarget
(
''
)
_statusUpdateTarget
(
''
)
def
reportError
(
title
,
msg
,
err
):
"""
Reports an error to the user in a generic manner. If a GUI is available,
(see the :meth.`.Platform.haveGui` attribute), a ``wx.MessageBox`` is
shown. Otherwise a log message is generated.
"""
from
.platform
import
platform
as
fslplatform
from
.
import
async
log
.
error
(
'
{}: {}
'
.
format
(
title
,
msg
,
exc_info
=
True
))
if
fslplatform
.
haveGui
:
msg
=
'
{}
\n\n
Details: {}
'
.
format
(
msg
,
str
(
err
))
import
wx
async
.
idle
(
wx
.
MessageBox
,
msg
,
title
,
wx
.
ICON_ERROR
|
wx
.
OK
)
@contextlib.contextmanager
def
reportIfError
(
title
,
msg
,
raiseError
=
True
):
"""
A context manager which calls :func:`reportError` if the enclosed code
raises an ``Exception``.
"""
try
:
yield
except
Exception
as
e
:
reportError
(
title
,
msg
,
e
)
if
raiseError
:
raise
def
reportErrorDecorator
(
title
,
msg
):
"""
A decorator which calls :func:`reportError` if the decorated function
raises an ``Exception``.
"""
def
decorator
(
func
):
def
wrapper
(
*
args
,
**
kwargs
):
with
reportIfError
(
title
,
msg
):
func
(
*
args
,
**
kwargs
)
return
wrapper
return
decorator
class
ClearThread
(
threading
.
Thread
):
class
ClearThread
(
threading
.
Thread
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment