[Mumps2Py:] [178] simplified the code somewhat.

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


Revision: 178
Author:   pgallot
Date:     2008-03-16 16:57:37 +0000 (Sun, 16 Mar 2008)

Log Message:
-----------
simplified the code somewhat.

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


Modified: trunk/mumps2py_ui.pyw
===================================================================
--- trunk/mumps2py_ui.pyw	2008-03-16 14:27:41 UTC (rev 177)
+++ trunk/mumps2py_ui.pyw	2008-03-16 16:57:37 UTC (rev 178)
@@ -63,12 +63,10 @@
         entry_ctl.pack(side = TOP, fill = X, expand = YES)
         btn = Button(popup, text = "Go", takefocus = YES)
         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>', \
-                 lambda event, c = callback, p = popup: (c(p))) 
-        entry_ctl.bind('<KeyPress-Return>', \
-                     lambda event, c = callback, p = popup: (c(p))) 
+        action = lambda event, c = callback, p = popup: (c(p))
+        btn.bind('<Button-1>', action)
+        btn.bind('<KeyPress-Return>', action) 
+        entry_ctl.bind('<KeyPress-Return>', action) 
         entry_ctl.focus_set()
 
     def create_scrolled_text(self, root, **kws):
@@ -95,14 +93,16 @@
         f_info.pack(side = TOP, fill = BOTH, expand = YES)
         btn = Button(popup, text = "Close", takefocus = YES)
         btn.pack(side = BOTTOM)
-        btn.bind('<Button-1>', lambda event, p = popup: (p.destroy()))
-        btn.bind('<KeyPress-Return>', lambda event, p = popup: (p.destroy())) 
+        action = lambda event, p = popup: (p.destroy())
+        btn.bind('<Button-1>', action)
+        btn.bind('<KeyPress-Return>', action) 
         return info_window
 
     def busy(self, busy_state = True):
         """ sets a wait cursor """
         if busy_state:
             self.root.config(cursor="watch")
+            self.root.update_idletasks()
         else:
             self.root.config(cursor="")
 
@@ -162,17 +162,15 @@
             the_module = a_module
         else:
             the_module = self.current_module
-        line_start, line_end = the_module.start, the_module.end
         self.busy()
         self.before_window.delete(0.0, END)
-        for line in fileinput.input(the_module.input_file):
-            line_no = fileinput.lineno()
-            if line_no < line_start:
-                continue
-            if line_end != -1 and line_no >= line_end:
-                break
+
+        if the_module.linebuffer_isempty():
+            the_module.load()
+
+        for line in the_module.loaded():
             self.before_window.insert(END, line)
-        fileinput.close()
+
         self.busy(False)
 
     def title(self):
@@ -242,7 +240,8 @@
         self.__display_before()
         try:
             self.busy()
-            mumps2py.parse_routine(the_module)
+            if the_module.tokenlist_isempty():
+                mumps2py.parse_routine(the_module)
             self.colorize_routine()
             translation = mumps2py.translate(the_module)
             self.__display_after(translation)
@@ -381,7 +380,7 @@
                             ref_routines.append(ref)
                             ref_dict[mod_name] = ref_routines
 
-                the_module.empty_tokenlist() # keep memory usage down
+                the_module.empty() # keep memory usage down
         except mumps2py.ParseError, err:
             self.message(err.error_msg(),
                          "Parse Error in " + the_module.mod_name)
@@ -419,7 +418,7 @@
                 if instances.get(toktype, None):
                     ref_dict[mod_name] = instances[toktype]
 
-                the_module.empty_tokenlist() # keep memory usage down
+                the_module.empty() # keep memory usage down
         except mumps2py.ParseError, err:
             self.message(err.error_msg(),
                          "Parse Error in " + the_module.mod_name)
@@ -491,31 +490,21 @@
         if not extract_fname:
             return
 
+        self.busy()
         extract_file = open(extract_fname,"w")
-        routine = the_mod_list.pop(0)
-        input_file = fileinput.input(routine.input_file)
+        input_file = fileinput.input(the_mod_list[0].input_file)
+        for routine in the_mod_list:
+            extract_file.write(routine.mod_name + '\n')
+            routine.load(input_file)
+            for line in routine.loaded():
+                extract_file.write(line)                
+            extract_file.write('\n')
 
-        for line in input_file:
-            lineno = fileinput.lineno()
-
-            if lineno < routine.start:
-                continue
-            elif lineno == routine.start:
-                extract_file.write(routine.mod_name + '\n')
-                
-            if routine.end != -1 and lineno > routine.end:
-                extract_file.write('\n')
-                if the_mod_list:
-                    routine = the_mod_list.pop(0)
-                    continue
-                else:
-                    break
-
-            extract_file.write(line)
-
         extract_file.write("\n\n%s" % ("#########\n" * 4))
         extract_file.close()
         fileinput.close()
+        self.busy(False)
+        self.message("%s created." % extract_fname)
 
 
     def parse_for_errors(self):
@@ -534,7 +523,7 @@
                 except mumps2py.ParseError, err:
                     error_list.append((the_module, err.error_msg()))
     
-                the_module.empty_tokenlist() # keep memory usage down
+                the_module.empty() # keep memory usage down
         finally:
             print time.time() - tstart, "seconds to parse %d routines" % \
                   (modcnt + 1)
@@ -566,12 +555,10 @@
                                      font = ("Consolas", 18))
             rpt_window.tag_configure(blacklist, foreground = 'purple',
                                      font = ("Consolas", 12))
-
             rpt_window.tag_bind(r_name, '<1>', lambda e, s = self, \
                                 n = r_name: s.select_mod(n))
             rpt_window.tag_bind(blacklist, '<1>', lambda e, s = self, \
-                    n = r_name: s.blacklist_mod(n))
-
+                                n = r_name: s.blacklist_mod(n))
             rpt_window.insert(END, r_name, r_name)
             rpt_window.insert(END, " (blacklist)\n", blacklist)
             rpt_window.insert(END, "%s\n" % error)
@@ -608,6 +595,7 @@
                 for modcnt, the_module in enumerate(modules_list):
                     if modcnt % 20 == 0: # cut down on console feedback
                         print the_module.mod_name
+                        self.root.update_idletasks()
                     mumps2py.parse_routine(the_module, input_file)
                     for token in the_module.tokenized():
                         token.count_subtokens(toks)
@@ -632,10 +620,10 @@
                 toktype_key = TOKEN_REVERSE_DICT.get(toktype, toktype)
                 tag = "toktype_%d" % toktype
                 if count < 1000: # arbitrary limit
+                    action = lambda e, s = self, t = toktype, l = modules_list:\
+                        s.extract_rpt(t, l)
                     rpt_window.tag_configure(tag, foreground = 'blue')
-                    rpt_window.tag_bind(tag, '<1>', lambda e, s = self,
-                                        t = toktype, l = modules_list:
-                                        s.extract_rpt(t, l))
+                    rpt_window.tag_bind(tag, '<1>', action)
                     rpt_window.insert(END, toktype_key, tag)
                     rpt_window.insert(END, ": %d\n" % count)
                 else:


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