From ad84f402d58f9f83de07edeeda0488d611438ab1 Mon Sep 17 00:00:00 2001 From: LtWorf Date: Thu, 8 Apr 2010 09:43:29 +0000 Subject: [PATCH] - More detail for errors in evaluation - Printing errors on stdout too, as well as query conversion to python git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@225 014f5005-505e-4b48-8d0a-63407b615a7c --- relational/relation.py | 8 +-- relational_curses/maingui.py | 95 ++++++++++++++++++++---------------- relational_gui/maingui.py | 1 + 3 files changed, 59 insertions(+), 45 deletions(-) diff --git a/relational/relation.py b/relational/relation.py index 8a6d3f0..f74b706 100644 --- a/relational/relation.py +++ b/relational/relation.py @@ -115,9 +115,11 @@ class relation (object): else: attributes[self.header.attributes[j]]=i[j] - - if eval(expr,attributes): - newt.content.append(i) + try: + if eval(expr,attributes): + newt.content.append(i) + except Exception,e: + raise Exception("Failed to evaluate %s\n%s" % (expr,e.__str__())) return newt def product (self,other): '''Cartesian product, attributes must be different to avoid collisions diff --git a/relational_curses/maingui.py b/relational_curses/maingui.py index c099d53..ab5ffeb 100644 --- a/relational_curses/maingui.py +++ b/relational_curses/maingui.py @@ -89,68 +89,79 @@ def main(): curses.flash() curses.textpad.rectangle(win,0,0,5,10)''' + squery='' + while True: c = win.window().getch() - s="" + if c==27: #Escape - query.window().addstr(add_symbol(symselect)) - query.window().refresh() - else: - #w.window().addstr(str(c)) - query.window().addstr(str(chr(c))) + squery+=add_symbol(symselect) - -def init_symbol_list(termsize): + + #elif c==curses.KEY_BACKSPACE: #Delete + elif c==13: + squery=squery[:-1] + else: + squery+=chr(c); + + + query.window().box() + query.top() + query.window().addstr(1,1,spaces(termsize[1]-2)) + query.window().addstr(1,1,squery) + + query.window().refresh() +def init_symbol_list(termsize,create=True): - p=curses.panel.new_panel(curses.newwin(15,16,1,0)) + if create: + p=curses.panel.new_panel(curses.newwin(15,16,2,termsize[1]/2-7)) + else: + p=termsize p.window().box() #p.window().addstr(1,1,"\n8 \na \nb \n") - p.window().addstr(01,2,"0 *") - p.window().addstr(02,2,"1 -") - p.window().addstr(03,2,"2 ᑌ") - p.window().addstr(04,2,"3 ᑎ") - p.window().addstr(05,2,"4 ᐅᐊ") + p.window().addstr(01,2,"0 *") + p.window().addstr(02,2,"1 -") + p.window().addstr(03,2,"2 ᑌ") + p.window().addstr(04,2,"3 ᑎ") + p.window().addstr(05,2,"4 ᐅᐊ") p.window().addstr(06,2,"5 ᐅLEFTᐊ") p.window().addstr(07,2,"6 ᐅRIGHTᐊ") p.window().addstr( 8,2,"7 ᐅFULLᐊ") - p.window().addstr( 9,2,"8 σ") - p.window().addstr(10,2,"9 ρ") - p.window().addstr(11,2,"a π") - p.window().addstr(12,2,"b ➡") + p.window().addstr( 9,2,"8 σ") + p.window().addstr(10,2,"9 ρ") + p.window().addstr(11,2,"a π") + p.window().addstr(12,2,"b ➡") p.window().addstr(13,2,"") - - - - p.hide() + #p.hide() return p - pass def add_symbol(p): - d_={'0':'*', - '1':'-', - '2':'ᑌ', - '3':'ᑎ', - '4':'ᐅᐊ', - '5':'ᐅLEFTᐊ', - '6':'ᐅRIGHTᐊ', - '7':'ᐅFULLᐊ', - '8':'σ', - '9':'ρ', - 'a':'π', - 'b':'➡'} + '''Shows the panel to add a symbol + and then returns the choosen symbol itself''' + init_symbol_list(p,False) + + d_={'0':'*','1':'-','2':'ᑌ','3':'ᑎ','4':'ᐅᐊ','5':'ᐅLEFTᐊ','6':'ᐅRIGHTᐊ','7':'ᐅFULLᐊ','8':'σ','9':'ρ','a':'π','b':'➡'} p.show() + p.top() p.window().refresh() - #curses.napms(1000) c = p.window().getch() p.hide() p.window().refresh() - return d_[chr(c)] -main() + try: + char=d_[chr(c)] + except: + char='' + return char - - - -terminate() \ No newline at end of file +def spaces(t): + '''Returns a number of spaces specified t''' + s='' + for i in range(t): + s+=' ' + return s +if __name__=='__main__': + main() + terminate() \ No newline at end of file diff --git a/relational_gui/maingui.py b/relational_gui/maingui.py index 013182d..7863186 100644 --- a/relational_gui/maingui.py +++ b/relational_gui/maingui.py @@ -85,6 +85,7 @@ class Ui_Form(object): self.selectedRelation=result self.showRelation(self.selectedRelation) #Show the result in the table except Exception, e: + print e QtGui.QMessageBox.information(None,QtGui.QApplication.translate("Form", "Error"),"%s\n%s" % (QtGui.QApplication.translate("Form", "Check your query!"),e.message) ) def showRelation(self,rel): '''Shows the selected relation into the table'''