Skip to content
Open
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
69 changes: 36 additions & 33 deletions cviewer/action/load_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@ class OpenFile(Action):
path = Str("MenuBar/File/LoadDataMenu")
image = ImageResource("cff-open.png", search_path=[IMAGE_PATH])

# Is the action enabled?
# Is the action enabled?
enabled = Bool(True)

# Is the action visible?
# Is the action visible?
visible = Bool(True)

###########################################################################
# 'Action' interface.
###########################################################################
###########################################################################
# 'Action' interface.
###########################################################################

def perform(self, event, cfile=None):
""" Performs the action. """

logger.info('Performing open connectome file action')
logger.info('Performing add data file action')

# helper variable to use this function not only in the menubar
exec_as_funct = True
Expand All @@ -55,20 +56,22 @@ def perform(self, event, cfile=None):
cfile = self.window.application.get_service('cviewer.plugins.cff2.cfile.CFile')
exec_as_funct = False

wildcard = "All files (*.*)|*.*" \
wildcard = "All files (*.*)|*.*|" \
'All files (*)|*|' \
"Nifti-1 (*.nii.gz)|*.nii.gz|" \
"Gifti (*.gii)|*.gii|" \
"TrackVis tracks (*.trk)|*.trk|" \
"Network Pickle (*.gpickle)|*.gpickle|" \
"Network GraphML (*.graphml)|*.graphml|" \
"NetworkX Pickle (*.gpickle)|*.gpickle|" \
"NetworkX Pickle (*.pck)|*.pck|" \
"NetworkX GraphML (*.graphml)|*.graphml|" \
"Numpy Data (*.npy)|*.npy|" \
"Pickle Data (*.pkl)|*.pkl|" \
"Text Data (*.txt)|*.txt|" \
"CSV Data (*.csv)|*.csv|"
"CSV Data (*.csv)|*.csv"

dlg = FileDialog(wildcard=wildcard,title="Choose a file",\
dlg = FileDialog(wildcard=wildcard,title="Add Neuroimaging or network data",\
resizeable=False, \
default_directory=preference_manager.cviewerui.cffpath,)
default_directory=preference_manager.cviewerui.cffpath)

if dlg.open() == OK:

Expand All @@ -90,20 +93,20 @@ def perform(self, event, cfile=None):
name = fname, gii_filename = dlg.paths[0])
cfile.obj.add_connectome_surface(csurf)

elif os.path.exists(dlg.paths[0]) and fname.endswith('.trk'):
elif os.path.exists(dlg.paths[0]) and (dlg.paths[0]).endswith('.trk'):
ctrk = cfflib.CTrack(
name = fname, src = dlg.paths[0])
cfile.obj.add_connectome_track(ctrk)

elif os.path.exists(dlg.paths[0]) and fname.endswith('.gpickle'):
ctrk = cfflib.CNetwork(name = fname, src = dlg.paths[0],
elif os.path.exists(dlg.paths[0]) and (fname.endswith('.gpickle') or fname.endswith('.pck')):
cntwk = cfflib.CNetwork(name = fname, src = dlg.paths[0],
fileformat="NXGPickle")
cfile.obj.add_connectome_network(ctrk)
cfile.obj.add_connectome_network(cntwk)

elif os.path.exists(dlg.paths[0]) and fname.endswith('.graphml'):
ctrk = cfflib.CNetwork.create_from_graphml(name = fname,
cntwk = cfflib.CNetwork.create_from_graphml(name = fname,
ml_filename = dlg.paths[0])
cfile.obj.add_connectome_network(ctrk)
cfile.obj.add_connectome_network(cntwk)

elif os.path.exists(dlg.paths[0]) and fname.endswith('.npy'):
cdat = cfflib.CData(name = fname, src = dlg.paths[0],
Expand Down Expand Up @@ -155,49 +158,49 @@ class OpenCFile(Action):

def perform(self, event, cfile=None):
""" Performs the action. """

logger.info('Performing open connectome file action')

# helper variable to use this function not only in the menubar
exec_as_funct = True

if cfile is None:
# get the instance of the current CFile
# with the help of the Service Registry
cfile = self.window.application.get_service('cviewer.plugins.cff2.cfile.CFile')
exec_as_funct = False

wildcard = "Connectome Markup File v2.0 (meta.cml)|meta.cml|" \
"Connectome File Format v2.0 (*.cff)|*.cff|" \
"All files (*.*)|*.*"
wildcard = "Connectome File Format v2.0 (*.cff)|*.cff|" \
"Connectome Markup File v2.0 (meta.cml)|meta.cml|" \
"All files (*.*)|*.*"

dlg = FileDialog(wildcard=wildcard,title="Choose a Connectome File",\
resizeable=False, \
default_directory=preference_manager.cviewerui.cffpath,)
default_directory=preference_manager.cviewerui.cffpath)

if dlg.open() == OK:

if not os.path.isfile(dlg.path):
logger.error("File '%s' does not exist!"%dlg.path)
return

# if file exists and has .cff ending
if os.path.exists(dlg.paths[0]) and (dlg.paths[0]).endswith('.cff'):

# close the cfile if one is currently loaded
cfile.close_cfile()

# load cfile data
cfile.load_cfile(dlg.paths[0])

self.window.status_bar_manager.message=''
elif os.path.exists(dlg.paths[0]) and (dlg.paths[0]).endswith('meta.cml'):
cfile.close_cfile()
cfile.load_cfile(dlg.paths[0], ismetacml = True)

else:
logger.info('Could not load file: '+ dlg.paths)


class SaveCFile(Action):
""" An action that save aconnectome file """

Expand Down
Loading