[Mumps2Py:] [66] The regression tests results window now displays 'Pass' in green, and 'Fail' in red.

[ Thread Index | Date Index | More lists.mumps2py.org/discuss Archives ]


Revision: 66
Author:   pgallot
Date:     2008-01-29 22:58:06 +0000 (Tue, 29 Jan 2008)

Log Message:
-----------
The regression tests results window now displays 'Pass' in green, and 'Fail' in red.  Otherwise, mostly clean up, with a small bit of new cruft added in parseuntilmodule.

Modified Paths:
--------------
    trunk/mumps2py_ui.pyw


Modified: trunk/mumps2py_ui.pyw
===================================================================
--- trunk/mumps2py_ui.pyw	2008-01-28 21:24:46 UTC (rev 65)
+++ trunk/mumps2py_ui.pyw	2008-01-29 22:58:06 UTC (rev 66)
@@ -18,10 +18,11 @@
 """ Implements a user interface for translating Mumps code to Python """
 
 import os, re, fileinput
-import mumps2py.mumps_module, mumps2py.mumps2tok, mumps2py.tok2python
+from mumps2py.mumps_module import parseForModules, ModuleInfo
+from mumps2py.mumps2tok import parseMumps
+from mumps2py.tok2python import translate
 import mumps2py_test
 
-
 from Tkinter import *
 import tkFileDialog
 
@@ -34,14 +35,15 @@
     def __init__(self, my_root):
         """initialize a Generic_UI object"""
         self.root = my_root
-
+        self.entry_val = None
+        
     def message(self, msg):
         """pop up a dialog showing a message"""
         popup = Toplevel(self.root)
         popup.transient(self.root)
-        Label(popup, text = msg).grid(row = 1, column = 1)
+        Label(popup, text = msg).pack(side = TOP, fill = BOTH, expand = YES)
         btn = Button(popup, text = "OK", takefocus = YES)
-        btn.grid(row = 2, column = 1)
+        btn.pack(side = BOTTOM, padx = "0.5c", padx = "0.5c")
         btn.bind('<Button-1>', lambda event, p = popup: (p.destroy()))
         btn.bind('<KeyPress-Return>', lambda event, p = popup: (p.destroy())) 
         btn.focus_set()
@@ -50,15 +52,15 @@
         """ generic pop-up query for a single value."""
         popup = Toplevel(self.root)
         popup.transient(self.root)
-        Label(popup, text = msg).grid(row = 1, column = 1)
+        Label(popup, text = msg).pack(side = TOP, fill = BOTH, expand = YES)
         self.entry_val = StringVar()
         entry_ctl = Entry(popup, \
                         width = entry_width, \
                         textvariable = self.entry_val, \
                         takefocus = YES)
-        entry_ctl.grid(row = 2, column = 1)
+        entry_ctl.pack(side = TOP, fill = X, expand = YES)
         btn = Button(popup, text = "Go", takefocus = YES)
-        btn.grid(row = 3, column = 1)
+        btn.pack(side = TOP, padx = "0.5c", padx = "0.5c")
         btn.bind('<Button-1>', \
                  lambda event, c = callback, p = popup: (c(p)))
         btn.bind('<KeyPress-Return>', \
@@ -71,29 +73,23 @@
         """ generic popup for displaying a bunch of Text."""
         popup = Toplevel(self.root)
         popup.transient(self.root)
-        
         f_info = Frame(popup, borderwidth = 2)
-        info_window = Text(f_info, \
-                          width = 60, \
-                          font = ("Consolas", 10), \
-                          wrap = NONE)
+        info_window = Text(f_info, width = 60, font = ("Consolas", 10),
+                           wrap = NONE)
         dvscroll = Scrollbar(f_info, command = info_window.yview)
         dhscroll = Scrollbar(f_info, command = info_window.xview, \
                              orient = HORIZONTAL)
         info_window.configure(yscrollcommand = dvscroll.set, \
-                                    xscrollcommand = dhscroll.set)
-        dvscroll.pack(side = RIGHT, fill = Y)
-        dhscroll.pack(side = BOTTOM, fill = X)
-        info_window.pack(side = LEFT, expand = YES)
-        f_info.grid(row = 1, column = 1)
-
+                              xscrollcommand = dhscroll.set)
+        dvscroll.pack(side = RIGHT, fill = Y, expand = YES)
+        dhscroll.pack(side = BOTTOM, fill = X, expand = YES)
+        info_window.pack(side = LEFT, fill = BOTH, expand = YES)
+        f_info.pack(side = TOP, fill = BOTH, expand = YES)
         btn = Button(popup, text = "Close", takefocus = YES)
-        btn.grid(row = 2, column = 1)
+        btn.pack(side = BOTTOM)
         btn.bind('<Button-1>', lambda event, p = popup: (p.destroy()))
         btn.bind('<KeyPress-Return>', lambda event, p = popup: (p.destroy())) 
-
         return info_window
-
     
 class Mumps2pyUI(GenericUI):
     """The class which provides the User Interface to Mumps2Py"""
@@ -103,7 +99,23 @@
         self.modules = None
         self.before_window = None
         self.after_window = None
-   
+
+        self.query = { "from": \
+                       ("Enter the approximate line # to parse from:", 7, \
+                        self.parse_fromlinemodule),\
+                       "module": \
+                       ("Enter the exact name of the module to parse:", 32, \
+                        self.parsegivenmodule),\
+                       "until": \
+                       ("Enter the name of the module at which to stop:", 32, \
+                        self.parseuntilmodule) \
+                       }
+
+    def popup_query(self, key):
+        """pops up a pre-defined query for a value to launch a function with"""
+        msg, entry_width, callback = self.query[key]
+        self.popup_entry(msg, entry_width, callback)
+
     def help_about(self):
         """pop up a dialog showing licensing/waranty information"""
         msg = """
@@ -156,7 +168,7 @@
             for a_module in self.modules:
                 if a_module.end < start_line:
                     continue
-                mumps2py.mumps2tok.parseMumps(a_module)
+                parseMumps(a_module)
 
     def parsegivenmodule(self, popup):
         """parse the module specified by popup"""
@@ -168,9 +180,9 @@
                     self.display_before(the_module.input_file, \
                                        the_module.start, \
                                        the_module.end)
-                    mumps2py.mumps2tok.parseMumps(the_module)
+                    parseMumps(the_module)
                     self.display_decomposed(the_module)
-                    translation = mumps2py.tok2python.translate(the_module)
+                    translation = translate(the_module)
                     self.display_after(the_module, translation)
                     return
 
@@ -179,14 +191,16 @@
         mod_name = self.entry_val.get()
         popup.destroy()
         toks = {}
+        entryrefs = {}
         if self.modules:
             for the_module in self.modules:
                 if the_module.mod_name == mod_name:
                     break
                 
-                mumps2py.mumps2tok.parseMumps(the_module)
+                parseMumps(the_module)
                 for token in the_module.TokenList:
                     token.count_subtokens(toks)
+                    token.extract_subtokens(entryrefs, (37, )) # 37 == ENTRYREF
 
             analysis = [(v, k) for k, v in toks.items()]
             analysis.sort(reverse = True)
@@ -196,33 +210,22 @@
                 analysis_str = "%s: %d\n" % (toktype_key, count)
                 analysis_window.insert(END, analysis_str)
 
+            entryref_window = self.info_window()
+            print len(entryrefs[37]),"entryrefs."
+            for entryref in entryrefs[37]:
+                entryref_window.insert(END, str(entryref)+"***\n")
 
-    def parse_from(self):
-        """ ask for a value to call parse_fromlinemodule with"""
-        self.popup_entry("Enter the approximate line # to parse from:", 7, \
-                         self.parse_fromlinemodule)
 
-    def parse_module(self):
-        """ ask for a value to call parsegivenmodule with"""
-        self.popup_entry("Enter the exact name of the module to parse:", 32, \
-                         self.parsegivenmodule)
-
-    def parse_until_module(self):
-        """ ask for a value to call parseuntilmodule with"""
-        self.popup_entry("Enter the exact name of the module at which to stop:", \
-                         32, \
-                         self.parseuntilmodule)
-
     def parse_all(self):
         """parse all the modules in a Mumps file"""
         if self.modules:
             for the_module in self.modules:
-                mumps2py.mumps2tok.parseMumps(the_module)
+                parseMumps(the_module)
             if len(self.modules) == 1:
                 the_module = self.modules[0]
-                mumps2py.mumps2tok.parseMumps(the_module)
+                parseMumps(the_module)
                 self.display_decomposed(the_module)
-                translation = mumps2py.tok2python.translate(the_module)
+                translation = translate(the_module)
                 self.display_after(the_module, translation)
 
     def parse_analyze_tokens(self):
@@ -231,7 +234,7 @@
         if self.modules:
             for the_module in self.modules:
                 if the_module.tokenlist_isempty():
-                    mumps2py.mumps2tok.parseMumps(the_module)
+                    parseMumps(the_module)
                 for token in the_module.TokenList:
                     token.count_subtokens(toks)
 
@@ -242,7 +245,6 @@
             for count, toktype_key in analysis:
                 analysis_str = "%s: %d\n" % (toktype_key, count)
                 analysis_window.insert(END, analysis_str)
-        del toks
 
     def file_close(self):
         """ clear out all the information for what was just open"""
@@ -264,19 +266,16 @@
 
         self.file_close()
             
-        f = open(mumps_file)
-        headerline = f.readline()
-        f.close()
+        mfile = open(mumps_file)
+        headerline = mfile.readline()
+        mfile.close()
 
         if re.search(r"CACHE FORMAT\^~Format=Cache.S~", headerline):
-            self.modules = mumps2py.mumps_module.parseForModules(mumps_file,
-                                                                 m2py_dir)
+            self.modules = parseForModules(mumps_file, m2py_dir)
         else:
             outputname = re.split(r"\..*$", mumps_file)[0]
             print "outputname: [%s]"  % outputname
-            self.modules = [mumps2py.mumps_module.ModuleInfo(mumps_file, \
-                                                    m2py_dir, \
-                                                    outputname), ]
+            self.modules = [ModuleInfo(mumps_file, m2py_dir, outputname), ]
             self.display_before(mumps_file)
                 
 
@@ -307,8 +306,19 @@
         
         result_file = open("test_results.txt", "r")
         results_window = self.info_window()
+        results_window.tag_configure('Pass', foreground = 'green',
+                                     font = ("Consolas", 14))
+        results_window.tag_configure('Fail', foreground = 'red',
+                                     font = ("Consolas", 18))
         for line in result_file:
-            results_window.insert(END, line)
+            result = re.search("Pass|Fail", line)
+            if result:
+                results_window.insert(END, line[:result.start()])
+                results_window.insert(END, line[result.start():result.end()], \
+                                      result.group())
+                results_window.insert(END, line[result.end():])
+            else:
+                results_window.insert(END, line)
 
     def add_regr_test(self):
         """ adds a file to the regression test suite."""
@@ -334,7 +344,6 @@
                                   underline = 0, \
                                   command = (lambda s = self: s.file_close()))
         file_btn['menu'] = file_btn.menu
-        menu_bar.tk_menuBar(file_btn)
 
         parse_btn = Menubutton(menu_bar, text = 'Parse', underline = 0,
                               takefocus = TRUE)
@@ -342,23 +351,22 @@
         parse_btn.menu = Menu(parse_btn)
 
         parse_btn.menu.add_command( label = "Parse All", \
-                                  underline = 6, \
-                                  command = (lambda s = self: s.parse_all()))
+                                    underline = 6, command = \
+                                    (lambda s = self: s.parse_all()))
+        parse_btn.menu.add('separator')
         parse_btn.menu.add_command( label = "Analyze tokens", \
-                                  underline = 1, \
-                                  command = (lambda s = self: \
-                                             s.parse_analyze_tokens()))
+                                    underline = 1, command = \
+                                    (lambda s = self: s.parse_analyze_tokens()))
         parse_btn.menu.add_command( label = "Parse From...", \
-                                   underline = 6, \
-                                   command = (lambda s = self: s.parse_from()))
+                                    underline = 6, command = \
+                                    (lambda s = self: s.popup_query("from")))
         parse_btn.menu.add_command( label = "Parse until Module...", \
-                                  underline = 6, \
-                                  command = (lambda s = self: s.parse_until_module()))
+                                    underline = 6, command = \
+                                    (lambda s = self: s.popup_query("until")))
         parse_btn.menu.add_command( label = "Parse Module...", \
-                                  underline = 6, \
-                                  command = (lambda s = self: s.parse_module()))
+                                    underline = 6, command = \
+                                    (lambda s = self: s.popup_query("module")))
         parse_btn['menu'] = parse_btn.menu
-        menu_bar.tk_menuBar(parse_btn)
 
         run_btn = Menubutton(menu_bar, text = 'Run', underline = 0,
                              takefocus = TRUE)
@@ -367,14 +375,15 @@
         run_btn.menu.add_command( label="Save and run", \
                                   underline = 1, \
                                   command = (lambda s = self: s.save_and_run()))
+        run_btn.menu.add('separator')
         run_btn.menu.add_command( label="Regression test run", \
-                                  underline = 1, \
-                                  command = (lambda s = self: s.regr_test_run()))
+                                  underline = 1, command = \
+                                  (lambda s = self: s.regr_test_run()))
+        run_btn.menu.add('separator')
         run_btn.menu.add_command( label="Add regression test", \
-                                  underline = 1, \
-                                  command = (lambda s = self: s.add_regr_test()))
+                                  underline = 1, command = \
+                                  (lambda s = self: s.add_regr_test()))
         run_btn['menu'] = run_btn.menu
-        menu_bar.tk_menuBar(run_btn)
 
         help_btn = Menubutton(menu_bar, text = 'Help', underline = 0,
                              takefocus = TRUE)
@@ -384,11 +393,11 @@
                                   underline = 0, \
                                   command = (lambda s = self: s.help_about()))
         help_btn['menu'] = help_btn.menu
-        menu_bar.tk_menuBar(help_btn)
         
     def make_dialog(self):
         """Set up the User Interface"""
         self.root.title('Mumps2Py')
+        self.root.geometry("+0+0")
         menu_bar = Frame( self.root, relief = RAISED, borderwidth = 2)
         menu_bar.pack(fill = X)
         self.make_dialog_menus(menu_bar)


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/