[Mumps2Py:] [76] fixed up the UI to use the new stuff.

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


Revision: 76
Author:   pgallot
Date:     2008-01-31 21:43:21 +0000 (Thu, 31 Jan 2008)

Log Message:
-----------
fixed up the UI to use the new stuff.

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


Modified: trunk/mumps2py_ui.pyw
===================================================================
--- trunk/mumps2py_ui.pyw	2008-01-31 21:40:56 UTC (rev 75)
+++ trunk/mumps2py_ui.pyw	2008-01-31 21:43:21 UTC (rev 76)
@@ -18,9 +18,10 @@
 """ Implements a user interface for translating Mumps code to Python """
 
 import os, re, fileinput
-from mumps2py.mumps_module import parseForModules, ModuleInfo
+from mumps2py.mumps_module import parse_for_routines
 from mumps2py.mumps2tok import parseMumps
 from mumps2py.tok2python import translate
+from mumps2py.mumps2py_config import create_m2p_file
 import mumps2py_test
 
 from Tkinter import *
@@ -230,13 +231,17 @@
 
     def parse_analyze_tokens(self):
         """count the frequency of the different token types, sort and display"""
+        import gc 
         toks = {}
         if self.modules:
             for the_module in self.modules:
+                print the_module.mod_name
                 if the_module.tokenlist_isempty():
                     parseMumps(the_module)
                 for token in the_module.TokenList:
                     token.count_subtokens(toks)
+                the_module.empty_tokenlist() # keep memory usage down
+                gc.collect()
 
             analysis = [(v, k) for k, v in toks.items()]
             analysis.sort(reverse = True)
@@ -256,29 +261,21 @@
         """ open a file of Mumps code"""
         mumps_file = tkFileDialog.askopenfilename(\
             parent = self.root,
-            filetypes = [ ("MUMPS files", "*.mps"), ("RSA files","*.rsa"), ], 
-            initialdir = ".\\testfiles",
-            initialfile = "fm22.rsa")
-        m2py_dir = ".\\out"
+            filetypes = [ ("MUMPS files", "*.mps"), ("RSA files","*.rsa"),
+                          ("RTN files","*.rtn"), ("m2p files","*.m2p")], 
+            initialdir = "./testfiles",
+            initialfile = "VistA.m2p")
+        m2py_dir = "./out"
 
         if not mumps_file:
             return
 
         self.file_close()
             
-        mfile = open(mumps_file)
-        headerline = mfile.readline()
-        mfile.close()
-
-        if re.search(r"CACHE FORMAT\^~Format=Cache.S~", headerline):
-            self.modules = parseForModules(mumps_file, m2py_dir)
-        else:
-            outputname = re.split(r"\..*$", mumps_file)[0]
-            print "outputname: [%s]"  % outputname
-            self.modules = [ModuleInfo(mumps_file, m2py_dir, outputname), ]
+        self.modules = parse_for_routines(mumps_file, m2py_dir)
+        if len(self.modules) == 1:
             self.display_before(mumps_file)
                 
-
     def file_save(self):
         """ saves what is in the After window to a file."""
         if self.modules and len(self.modules) == 1:
@@ -292,6 +289,26 @@
                 outfile.write( self.after_window.get(0.0, END))
                 outfile.close()
         return name
+
+    def file_m2p(self):
+        """ saves what is in the After window to a file."""
+        if self.modules:
+            base_fname = self.modules[0].input_file
+            suggest_name = "%s.m2p" % ( \
+                os.path.splitext(base_fname)[0] )
+
+            m2p_fname = tkFileDialog.asksaveasfilename(parent = self.root,
+                                                  initialfile = suggest_name)
+            if m2p_fname:
+                input_fname = tkFileDialog.askopenfilename(\
+                    parent = self.root,
+                    filetypes = [ ("RSA files","*.rsa"), ("RTN files","*.rtn")],
+                    initialdir = os.path.abspath(base_fname),
+                    initialfile = os.path.basename(base_fname))
+                if input_fname:
+                    create_m2p_file(m2p_fname, input_fname)
+                    self.message(m2p_fname + " created.")
+
                 
     def save_and_run(self):
         """save the result of the translation to a file and execute it"""
@@ -337,6 +354,9 @@
         file_btn.menu.add_command( label = "Open", \
                                   underline = 0, \
                                   command = (lambda s = self: s.file_open()))
+        file_btn.menu.add_command( label = "Create m2p file", \
+                                  underline = 1, \
+                                  command = (lambda s = self: s.file_m2p()))
         file_btn.menu.add_command( label = "Save",
                                    underline = 0, \
                                    command = (lambda s = self: s.file_save()))


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