Commit 584d38ab authored by Franziska Koehn's avatar Franziska Koehn
Browse files

extracted creating of message-dialogs, error messages improved

parent 7fb70e6b
......@@ -145,7 +145,7 @@ def get_xnat_server_connection(force=False, host="", user="", passw=""):
if get_xnat_server_connection.cache and not force:
return get_xnat_server_connection.cache
elif force and host=="":
raise xsa.errors.ServerNotFoundError("The host was not defined.")
raise xsa.errors.ServerNotFoundError("The host-address was not defined.")
elif force and (user=="" or passw==""):
raise xsa.errors.UnauthorizedError("The user-name and/or the user-password were not defined.")
......@@ -153,7 +153,7 @@ def get_xnat_server_connection(force=False, host="", user="", passw=""):
try:
get_xnat_server_connection.cache = Interface(server=host, user=user, password=passw, cachedir=mkdtemp())
except IndexError as e:
raise xsa.errors.ServerNotFoundError("Server not found, check your host-address.")
raise xsa.errors.ServerNotFoundError("Can't reach host! Check your host-address and your internet/network connection.")
return get_xnat_server_connection()
get_xnat_server_connection.cache = None
......@@ -241,13 +241,13 @@ def search_for(host, root_element, constraints, search_fields, user, passw):
result = central.select(root_element,search_fields).where(constraints)
except errors.DatabaseError as e:
if '401' in str(e):
raise xsa.errors.UnauthorizedError("Unauthorizied attempt. Check your User and Password")
raise xsa.errors.UnauthorizedError("Unauthorizied attempt. Check your user-name and -password")
else:
raise e
except ServerNotFoundError:
raise xsa.errors.ServerNotFoundError("Server not found, check your host-address.")
raise xsa.errors.ServerNotFoundError("Can't reach host! Check your host-address and your internet/network connection.")
except ResponseNotReady:
raise xsa.errors.ResponseNotReady("Please check your Host-Address")
raise xsa.errors.ResponseNotReady("Please check your host-address")
if result == []:
raise xsa.errors.QueryError("Please check your query.")
......
......@@ -11,6 +11,7 @@ import gtk
import gobject
import xsa.datatypereader
from xsagtk.message_dialogs import create_error_message
class QueryController(gobject.GObject):
"""Provides communication between different views."""
......@@ -91,49 +92,24 @@ class QueryController(gobject.GObject):
import xsa.errors
if passw =='' or user=='' or host=='':
md = gtk.MessageDialog( type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_OK,
message_format="Please set your Password, User-Name and Host-Address (Button 'Server Settings')."
)
md.run()
md.destroy()
create_error_message("Please set your password, user-name and host-address (use button 'Server Settings').")
return
if query==[]:
md = gtk.MessageDialog( type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_OK,
message_format="Please define a Query."
)
md.run()
md.destroy()
create_error_message("Please define a query.")
return
try:
query_results = xsa.queries.search_for( host,
self.results = xsa.queries.search_for( host,
root_type,
query,
fields,
user,
passw
)
except xsa.errors.Error as e:
md = gtk.MessageDialog( type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_OK,
message_format=str(e)
)
md.run()
md.destroy()
self.results = []
except Exception as e:
md = gtk.MessageDialog( type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_OK,
message_format="An unexpected Error occured:"
)
md.format_secondary_text(e)
md.run()
md.destroy()
create_error_message(e)
self.results = []
else:
self.results = query_results
self.resultsview.show_data(self.results, root_type)
self.statusbar.push(0, "%s Results"%len(self.results))
......@@ -284,12 +260,7 @@ class QueryController(gobject.GObject):
try:
xsa.queries.get_xnat_server_connection(force=True, host=self.host, user=self.credentials_tuple[0], passw=self.credentials_tuple[1])
except Exception as e:
md = gtk.MessageDialog( type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_OK,
message_format=str(e)
)
md.run()
md.destroy()
create_error_message(e)
dialog.destroy()
......
import gtk
def create_error_message(message):
md = gtk.MessageDialog( type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_OK,
message_format=str(message)
)
md.run()
md.destroy()
def create_confirmation_message(message):
md = gtk.MessageDialog(type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_YES_NO,
message_format=message
)
response = md.run()
md.destroy()
if response == gtk.RESPONSE_YES:
return True
return False
......@@ -8,6 +8,7 @@ This module contains all classes of widgets that are used for creating a query.
"""
import gtk
from xsagtk.message_dialogs import create_confirmation_message
class QueryView(gtk.VBox):
"""Contains all widgets for creating the query"""
......@@ -234,14 +235,7 @@ class TreeViewQuery(gtk.TreeView):
if path_info is not None:
path, col, cellx, celly = path_info
iter = self.store.get_iter(path)
if not path == (0,):
md = gtk.MessageDialog(type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_YES_NO,
message_format="Remove the element and its children?"
)
response = md.run()
md.destroy()
if response == gtk.RESPONSE_YES:
if not path == (0,) and create_confirmation_message("Remove this element and its children?"):
self.store.remove(iter)
self.connect('button_press_event', on_treeview_button_press_event)
......@@ -277,19 +271,13 @@ class TreeViewQuery(gtk.TreeView):
else: # existing value was changed
if new_value in self.fields and old_value in self.methods:
# subquery needs to be deleted, ask for confirmation
md = gtk.MessageDialog(type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_YES_NO,
message_format="The subquery will be deleted! Continue?"
)
response = md.run()
md.destroy()
if response == gtk.RESPONSE_NO:
return
else:
if create_confirmation_message("The subquery will be deleted! Continue?"):
self.store.set(it, 0, new_value)
while not self.store.iter_children(it) is None:
child = self.store.iter_children(it)
self.store.remove(child)
else:
return
else:
self.store.set(it, 0, new_value)
......
Markdown is supported
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