Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Michiel Cottaar
fslpy
Commits
379006de
Commit
379006de
authored
11 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
added ability to specify file suffixes for FilePath properties
parent
2f8314f6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
betDemo.py
+6
-8
6 additions, 8 deletions
betDemo.py
runshell.py
+1
-1
1 addition, 1 deletion
runshell.py
tkprop/properties_types.py
+34
-14
34 additions, 14 deletions
tkprop/properties_types.py
with
41 additions
and
23 deletions
betDemo.py
+
6
−
8
View file @
379006de
...
...
@@ -32,12 +32,13 @@ runChoices = OrderedDict((
(
'
-A
'
,
'
Run bet2 and then betsurf to get additional skull and scalp surfaces
'
),
(
'
-A2
'
,
'
As above, when also feeding in non-brain extracted T2
'
)))
filetypes
=
[
'
.nii.gz
'
,
'
.nii
'
,
'
.hdr
'
,
'
.img
'
]
class
BetOptions
(
tkp
.
HasProperties
):
inputImage
=
tkp
.
FilePath
(
exists
=
True
,
required
=
True
)
outputImage
=
tkp
.
FilePath
(
required
=
True
)
t2Image
=
tkp
.
FilePath
(
exists
=
True
,
required
=
lambda
i
:
i
.
runChoice
==
'
-A2
'
)
inputImage
=
tkp
.
FilePath
(
exists
=
True
,
suffixes
=
filetypes
,
required
=
True
)
outputImage
=
tkp
.
FilePath
(
required
=
True
)
t2Image
=
tkp
.
FilePath
(
exists
=
True
,
suffixes
=
filetypes
,
required
=
lambda
i
:
i
.
runChoice
==
'
-A2
'
)
runChoice
=
tkp
.
Choice
(
runChoices
)
...
...
@@ -264,15 +265,12 @@ class BetFrame(tk.Frame):
if
__name__
==
'
__main__
'
:
import
logging
logging
.
basicConfig
(
format
=
'
%(levelname)s - %(funcName)s: %(message)s
'
,
level
=
logging
.
DEBUG
)
#
import logging
#
logging.basicConfig(format='%(levelname)s - %(funcName)s: %(message)s', level=logging.DEBUG)
app
=
tk
.
Tk
()
betopts
=
BetOptions
()
betopts
.
inputImage
=
'
/Users/paulmc/MNI152_T1_2mm.nii.gz
'
betopts
.
outputImage
=
'
/Users/paulmc/brain
'
frame
=
BetFrame
(
app
,
betopts
)
# stupid hack for testing under OS X - forces the TK
...
...
This diff is collapsed.
Click to expand it.
runshell.py
+
1
−
1
View file @
379006de
#!/usr/bin/env python
#
# runshell.py -
# runshell.py -
Run a process, display its output in a Tkinter window.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
...
...
This diff is collapsed.
Click to expand it.
tkprop/properties_types.py
+
34
−
14
View file @
379006de
...
...
@@ -277,17 +277,21 @@ class FilePath(String):
may be either a file or a directory.
"""
def
__init__
(
self
,
exists
=
False
,
isFile
=
True
,
**
kwargs
):
def
__init__
(
self
,
exists
=
False
,
isFile
=
True
,
suffixes
=
[],
**
kwargs
):
"""
FilePath constructor. Optional arguments:
- exists: If True, the path must exist.
- isFile: If True, the path must be a file. If False, the
path must be a directory. This check is only
performed if exists=True.
- exists: If True, the path must exist.
- isFile: If True, the path must be a file. If False, the
path must be a directory. This check is only
performed if exists=True.
- suffixes: List of acceptable file suffixes (only relevant
if isFile is True).
"""
self
.
exists
=
exists
self
.
isFile
=
isFile
self
.
exists
=
exists
self
.
isFile
=
isFile
self
.
suffixes
=
suffixes
String
.
__init__
(
self
,
**
kwargs
)
...
...
@@ -295,16 +299,32 @@ class FilePath(String):
String
.
validate
(
self
,
instance
,
value
)
if
value
is
None
:
return
if
value
==
''
:
return
if
value
is
None
:
return
if
value
==
''
:
return
if
not
self
.
exists
:
return
if
self
.
isFile
:
values
=
[
value
]
# if suffixes have been specified, check to
# see if any file exists with each of the
# suffixes (in addition to the specified path)
if
len
(
self
.
suffixes
)
>
0
:
values
.
extend
([
'
{}{}
'
.
format
(
value
,
s
)
for
s
in
self
.
suffixes
])
if
self
.
exists
:
files
=
map
(
op
.
isfile
,
values
)
if
self
.
isFile
and
(
not
op
.
isfile
(
value
)):
raise
ValueError
(
'
Must be a file ({})
'
.
format
(
value
))
if
not
any
(
map
(
op
.
isfile
,
values
)):
if
len
(
self
.
suffixes
)
==
0
:
raise
ValueError
(
'
Must be a file ({})
'
.
format
(
value
))
else
:
raise
ValueError
(
'
Must be a file ending in [{}] ({})
'
.
format
(
'
,
'
.
join
(
self
.
suffixes
),
value
))
if
(
not
self
.
isFile
)
and
(
not
op
.
isdir
(
value
)
)
:
raise
ValueError
(
'
Must be a directory ({})
'
.
format
(
value
))
elif
not
op
.
isdir
(
value
):
raise
ValueError
(
'
Must be a directory ({})
'
.
format
(
value
))
class
ListWrapper
(
object
):
...
...
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