Commit 92e615f0 authored by Franziska Koehn's avatar Franziska Koehn
Browse files

messageboxes for catched exceptions

parent 60f52b94
......@@ -80,14 +80,20 @@ def search_for_mrScanData(host, constraints, user, passw):
def search_for(host, root_element, constraints):
from pyxnat import Interface
from pyxnat.core import errors
from tempfile import mkdtemp
from httplib2 import ServerNotFoundError
user, passw = get_credentials()
tmp_dir=mkdtemp()
central = Interface(server="%s" % host,
user=user,
password=passw,
cachedir=tmp_dir)
try:
central = Interface(server="%s" % host,
user=user,
password=passw,
cachedir=tmp_dir)
except IndexError:
return "ServerNotFoundError" #TODO Eigene Fehlerklasse
search_fields = [
'xnat:mrSessionData/PROJECT', #project id
......@@ -97,7 +103,14 @@ def search_for(host, root_element, constraints):
'xnat:mrScanData/TYPE', #scan type
]
result = central.select(root_element,search_fields).where(constraints)
result = []
try:
result = central.select(root_element,search_fields).where(constraints)
except errors.DatabaseError:
return "DatabaseError" #TODO Eigene Fehlerklasse
except ServerNotFoundError:
return "ServerNotFoundError" #TODO Eigene Fehlerklasse
try:
central.disonnect()
......
......@@ -27,11 +27,30 @@ class XnatSearchApp(gtk.Window):
def on_search_query(_, host, credentials, query):
import xnat_search
user, _, passw = credentials.partition(":")
self.results = xnat_search.search_for_mrScanData(host, query, user, passw)
query_results = xnat_search.search_for_mrScanData(host, query, user, passw)
xnat_search.HOST = host
#TODO catch errors
print ("start",query_results,"end")
if query_results is "DatabaseError":
md = gtk.MessageDialog(type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_OK,
message_format="Error! Check your query."
)
md.run()
md.destroy()
self.results = []
elif query_results is "ServerNotFoundError":
md = gtk.MessageDialog(type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_OK,
message_format="Error! Server not found."
)
md.run()
md.destroy()
self.results = []
else:
self.results = query_results
self.vbox_results.show_data(self.results)
self.treeViewChartValues.emit("columns-changed")#TODO eigenes event waer besser...
......
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