Commit 60f52b94 authored by Franziska Koehn's avatar Franziska Koehn
Browse files

Refactoring Step 2

parent bd89589f
......@@ -58,6 +58,11 @@ def download_all(results, host=None):
for r in results:
download(r, host)
def download_f(*args, **kwargs):
download(*args, **kwargs)
# if this does not return False, the function will be repeatedly called by timeout_add
return False
def download(result, host=None):
if not host:
host = HOST
......@@ -68,11 +73,9 @@ def download(result, host=None):
scan = result['id']
file_name = "%s_%s_%s" % (subject, result['type'], scan)
download_file(host, project, subject, experiment, scan, file_name)
print("finished")
return False
def search_for_mrScanData(host, constraints, user, passw):
get_credentials(username=user, password=passw)
get_credentials(username=user, password=passw, force=True)
return search_for(host, 'xnat:mrScanData', constraints)
def search_for(host, root_element, constraints):
......
......@@ -28,10 +28,11 @@ class XnatSearchApp(gtk.Window):
import xnat_search
user, _, passw = credentials.partition(":")
self.results = xnat_search.search_for_mrScanData(host, query, user, passw)
xnat_search.HOST = host
#TODO catch errors
self.treeViewResults.show_data(self.results)
self.vbox_results.show_data(self.results)
self.treeViewChartValues.emit("columns-changed")#TODO eigenes event waer besser...
vbox_root = gtk.VBox(False, 1)
......@@ -52,34 +53,9 @@ class XnatSearchApp(gtk.Window):
vpaned.set_position(300)
hpaned.add2(vpaned)
vBox_results = gtk.VBox(False,1)
vpaned.add1(vBox_results)
sw_results = gtk.ScrolledWindow()
sw_results.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw_results.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
vBox_results.pack_start(sw_results,expand=True, fill=True)
self.treeViewResults = TreeViewResults()
sw_results.add(self.treeViewResults)
buttonBox_download = gtk.HButtonBox()
vBox_results.pack_end(buttonBox_download,expand=False, fill=False)
results_tree_view_store = self.treeViewResults.store
def event_clicked_download(*_):
import gobject
import xnat_search
enabled = (d for d in results_tree_view_store if d[0])
for d in enabled:
gobject.timeout_add(500, xnat_search.download, d[6], self.entry_host.get_text())
d[0] = False
button_download = gtk.Button(label="Download Selected Items")
button_download.connect("clicked", event_clicked_download)
buttonBox_download.add(button_download)
from xnatgtk.results_view import ResultsDownloadView
self.vbox_results = ResultsDownloadView(False,1)
vpaned.add1(self.vbox_results)
#chart
......@@ -196,68 +172,5 @@ class treeViewChartValues(gtk.TreeView):
self.set_model(self.store)
class TreeViewResults(gtk.TreeView):
def __init__(self):
import gobject
super(TreeViewResults, self).__init__()
self.create_columns()
self.store = gtk.ListStore(bool, str, str, str, str, str, gobject.TYPE_PYOBJECT)
self.set_model(self.store)
def create_columns(self):
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)
renderer = gtk.CellRendererToggle()
renderer.set_property('activatable', True)
renderer.connect("toggled", callback_toggled, 0)
column = gtk.TreeViewColumn("", renderer)
column.add_attribute(renderer, "active", 0)
column.set_sort_column_id(0)
column.set_resizable(False)
self.append_column(column)
column = gtk.TreeViewColumn("Project-ID", gtk.CellRendererText(), text=1)
column.set_sort_column_id(1)
column.set_resizable(True)
self.append_column(column)
column = gtk.TreeViewColumn("Subject-ID", gtk.CellRendererText(), text=2)
column.set_sort_column_id(2)
column.set_resizable(True)
self.append_column(column)
column = gtk.TreeViewColumn("Session-ID", gtk.CellRendererText(), text=3)
column.set_sort_column_id(3)
column.set_resizable(True)
self.append_column(column)
column = gtk.TreeViewColumn("Scan-ID", gtk.CellRendererText(), text=4)
column.set_sort_column_id(4)
column.set_resizable(True)
self.append_column(column)
column = gtk.TreeViewColumn("Scan-Type", gtk.CellRendererText(), text=5)
column.set_sort_column_id(5)
column.set_resizable(True)
self.append_column(column)
def show_data(self, data):
self.store.clear()
for d in data:
self.store.append( [ True,
d['xnat_mrsessiondata_project'],
d['xnat_mrsessiondata_subject_id'],
d['xnat_mrsessiondata_session_id'],
d['id'],
d['type'],
d
])
XnatSearchApp()
gtk.main()
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