Commit dd3f5e8d authored by Franziska Koehn's avatar Franziska Koehn
Browse files

search extendet

parent 11b87b24
......@@ -82,6 +82,17 @@ def get_fields_of_type(type):
except ValueError:
pass
def get_fields_from_labels(labels, type):
result=[]
fields = get_fields_of_type(type)
if fields is not None:
for l in labels:
for f in fields:
if f['label'] == l:
result.append(f['field'])
break
return result
def get_search_fields():
import json
return json.loads("""[{"label":"type", "field":"xnat:mrScanData/TYPE"},
......
......@@ -32,15 +32,18 @@ class XnatSearchApp(gtk.Window):
hpaned.set_position(400)
vbox_root.pack_start(hpaned, True, True, 5)
def on_search_query(_, host, credentials, query):
def on_search_query(_, host, credentials, root_type, query, labels):
import xnat_search
user, _, passw = credentials.partition(":")
requested_fields=[]
query_results = xnat_search.search_for(host, 'xnat:mrScanData', query, requested_fields, user, passw)
fields = xnat_search.get_fields_from_labels(labels,root_type)
query_results = xnat_search.search_for(host, 'xnat:mrScanData', query, [], user, passw)
xnat_search.HOST = host
#TODO catch errors
#httplib.ResponseNotReady
#one message dialog for all
if query_results is "DatabaseError":
md = gtk.MessageDialog(type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_OK,
......
......@@ -21,7 +21,7 @@ class QueryView(gtk.VBox):
self.entry_host.set_text(new_host)
def __send_query(self):
self.emit("send-query", self.host, self.credentials, self.treeView_search.get_query())
self.emit("send-query", self.host, self.credentials, self.combobox.get_selected_item(), self.treeView_search.get_query(), self.treeView_fields.get_selected_fields())
def __init__(self, *args, **kwargs):
super(QueryView, self).__init__(*args, **kwargs)
......@@ -30,7 +30,7 @@ class QueryView(gtk.VBox):
import gobject
gobject.signal_new("send-query", QueryView, gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, (gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT))
gobject.TYPE_NONE, (gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT))
# root-type
......@@ -47,14 +47,14 @@ class QueryView(gtk.VBox):
self.treeView_search.set_root_type(selected)
self.treeView_fields.show_fields(fields)
combobox = ComboBoxRootType(gtk.ListStore(str))
combobox.connect('changed', changed_cb)
self.combobox = ComboBoxRootType(gtk.ListStore(str))
self.combobox.connect('changed', changed_cb)
cell = gtk.CellRendererText()
combobox.pack_start(cell)
combobox.add_attribute(cell, 'text', 0)
self.combobox.pack_start(cell)
self.combobox.add_attribute(cell, 'text', 0)
for t in xnat_search.get_data_types():
combobox.append_text(t)
hBox_root_type.pack_start(combobox, True, True,0)
self.combobox.append_text(t)
hBox_root_type.pack_start(self.combobox, True, True,0)
# Sash
......@@ -113,8 +113,8 @@ class QueryView(gtk.VBox):
hBox_send.pack_end(self.button_send, expand=False, fill=False)
# setting start state
combobox.set_active(0)
self.treeView_search.set_root_type(combobox.get_selected_item())
self.combobox.set_active(0)
self.treeView_search.set_root_type(self.combobox.get_selected_item())
class ComboBoxRootType(gtk.ComboBox):
......@@ -166,8 +166,12 @@ class TreeViewResultFields(gtk.TreeView):
f
])
def get_selected_fields():
raise NotImplemented
def get_selected_fields(self):
results = []
for r in self.store:
if r[0]: # if selected
results.append(r[1])
return results
class TreeViewQuery(gtk.TreeView):
......
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