Commit 26d01fdf authored by Franziska Koehn's avatar Franziska Koehn
Browse files

new key "required" added (true if required for downloading)

parent dd3f5e8d
{"root-type":"xnat:mrScanData",
"fields":[
{"label":"type", "field":"xnat:mrScanData/TYPE"},
{"label":"fov_x", "field":"xnat:mrScanData/PARAMETERS_FOV_X"},
{"label":"fov_y", "field":"xnat:mrScanData/PARAMETERS_FOV_Y"},
{"label":"tr", "field": "xnat:mrScanData/PARAMETERS_TR"},
{"label":"te", "field": "xnat:mrScanData/PARAMETERS_TE"},
{"label":"ti", "field": "xnat:mrScanData/PARAMETERS_TI"},
{"label":"flip", "field": "xnat:mrScanData/PARAMETERS_FLIP"},
{"label":"voxel_res_x", "field":"xnat:mrScanData/PARAMETERS_VOXELRES_X"},
{"label":"voxel_res_y", "field":"xnat:mrScanData/PARAMETERS_VOXELRES_Y"},
{"label":"voxel_res_z", "field":"xnat:mrScanData/PARAMETERS_VOXELRES_Z"}
{"label":"type", "field":"xnat:mrScanData/TYPE", "required":true},
{"label":"fov_x", "field":"xnat:mrScanData/PARAMETERS_FOV_X", "required":false},
{"label":"fov_y", "field":"xnat:mrScanData/PARAMETERS_FOV_Y", "required":false},
{"label":"tr", "field": "xnat:mrScanData/PARAMETERS_TR", "required":false},
{"label":"te", "field": "xnat:mrScanData/PARAMETERS_TE", "required":false},
{"label":"ti", "field": "xnat:mrScanData/PARAMETERS_TI", "required":false},
{"label":"flip", "field": "xnat:mrScanData/PARAMETERS_FLIP", "required":false},
{"label":"voxel_res_x", "field":"xnat:mrScanData/PARAMETERS_VOXELRES_X", "required":false},
{"label":"voxel_res_y", "field":"xnat:mrScanData/PARAMETERS_VOXELRES_Y", "required":false},
{"label":"voxel_res_z", "field":"xnat:mrScanData/PARAMETERS_VOXELRES_Z", "required":false},
{"label":"Project-ID", "field":"xnat:mrSessionData/PROJECT", "required":true},
{"label":"Subject-ID", "field":"xnat:mrSessionData/SUBJECT_ID", "required":true},
{"label":"Session-ID", "field":"xnat:mrSessionData/SESSION_ID", "required":true},
{"label":"Scan-ID", "field":"xnat:mrScanData/ID", "required":true}
]
}
{"root-type":"xnat:subjectData",
"fields":[
{"label":"id", "field":"xnat:mrScanData/ID"}
{"label":"id", "field":"xnat:mrScanData/ID", "required":true}
]
}
......@@ -66,6 +66,14 @@ def get_field_labels_of_type(type):
result.append(f['label'])
return result
def get_field_labels_required_of_type(type):
result = []
fields = get_fields_of_type(type)
if fields is not None:
for f in fields:
result.append((f['label'],f['required']))
return result
def get_fields_of_type(type):
from os import listdir
from os.path import isfile, join
......@@ -137,7 +145,7 @@ def download(result, dest_folder='', host=None, cb=(lambda *_: None), cb_args=()
requests_lock.release()
cb(*cb_args)
def search_for(host, root_element, constraints, result_fields, user, passw):
def search_for(host, root_element, constraints, search_fields, user, passw):
from pyxnat import Interface
from pyxnat.core import errors
from tempfile import mkdtemp
......@@ -148,6 +156,8 @@ def search_for(host, root_element, constraints, result_fields, user, passw):
user, passw = get_credentials()
tmp_dir=mkdtemp()
print search_fields
try:
central = Interface(server="%s" % host,
user=user,
......@@ -156,16 +166,6 @@ def search_for(host, root_element, constraints, result_fields, user, passw):
except IndexError:
return "ServerNotFoundError" #TODO Eigene Fehlerklasse
main_fields = [
'xnat:mrSessionData/PROJECT', #project id
'xnat:mrSessionData/SUBJECT_ID', #subject id
'xnat:mrSessionData/SESSION_ID', #experiment id
'xnat:mrScanData/ID', #scan id
'xnat:mrScanData/TYPE', #scan type
]
search_fields = main_fields+result_fields
result = []
try:
......
......@@ -36,7 +36,7 @@ class XnatSearchApp(gtk.Window):
import xnat_search
user, _, passw = credentials.partition(":")
fields = xnat_search.get_fields_from_labels(labels,root_type)
query_results = xnat_search.search_for(host, 'xnat:mrScanData', query, [], user, passw)
query_results = xnat_search.search_for(host, 'xnat:mrScanData', query, fields, user, passw)
xnat_search.HOST = host
#TODO catch errors
......
......@@ -43,7 +43,7 @@ class QueryView(gtk.VBox):
def changed_cb(combobox):
selected = combobox.get_selected_item()
fields = xnat_search.get_field_labels_of_type(selected)
fields = xnat_search.get_field_labels_required_of_type(selected)
self.treeView_search.set_root_type(selected)
self.treeView_fields.show_fields(fields)
......@@ -135,7 +135,7 @@ class TreeViewResultFields(gtk.TreeView):
def __init__(self):
super(TreeViewResultFields, self).__init__()
self.create_columns()
self.store = gtk.ListStore(bool, str)
self.store = gtk.ListStore(bool, str, bool) # is_selected, label, is_required
self.set_model(self.store)
def create_columns(self):
......@@ -143,7 +143,8 @@ class TreeViewResultFields(gtk.TreeView):
def callback_toggled(cellrenderertoggle, path_string, col, *_):
it = self.store.get_iter_from_string(path_string)
is_active = cellrenderertoggle.get_active()
self.store.set(it, col, not is_active)
if not self.store.get_value(it, 2):
self.store.set(it, col, not is_active)
renderer = gtk.CellRendererToggle()
renderer.set_property('activatable', True)
......@@ -162,8 +163,9 @@ class TreeViewResultFields(gtk.TreeView):
def show_fields(self, fields):
self.store.clear()
for f in fields:
self.store.append( [ False,
f
self.store.append( [ f[1], # is_selected
f[0], # label
f[1] # is_required
])
def get_selected_fields(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment