[Mumps2Py:] [24] added a menu command to run the translated Python code.

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


Revision: 24
Author:   pgallot
Date:     2008-01-18 19:31:40 +0000 (Fri, 18 Jan 2008)

Log Message:
-----------
added a menu command to run the translated Python code.
Misc lint removal and similar tweaking.

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


Modified: trunk/mumps2py_ui.pyw
===================================================================
--- trunk/mumps2py_ui.pyw	2008-01-18 16:40:27 UTC (rev 23)
+++ trunk/mumps2py_ui.pyw	2008-01-18 19:31:40 UTC (rev 24)
@@ -33,6 +33,8 @@
     def __init__(self, my_root):
         self.modules = None
         self.root = my_root
+        self.before_window = None
+        self.after_window = None
    
     def help_about(self):
         """pop up a dialog showing licensing/waranty information"""
@@ -230,7 +232,12 @@
                 analysis_window.insert(END, analysis_str)
         del toks
 
-        
+    def file_close(self):
+        """ clear out all the information for what was just open"""
+        self.before_window.delete(0.0, END)
+        self.after_window.delete(0.0, END)
+        self.modules = None
+
     def file_open(self):
         """ open a file of Mumps code"""
         mumps_file = tkFileDialog.askopenfilename(\
@@ -238,7 +245,13 @@
             filetypes = [ ("MUMPS files", "*.mps"), ("RSA files","*.rsa"), ], 
             initialdir = ".\\testfiles",
             initialfile = "fm22.rsa")
-        m2py_dir = ".\\out" 
+        m2py_dir = ".\\out"
+
+        if not mumps_file:
+            return
+
+        self.file_close()
+            
         f = open(mumps_file)
         headerline = f.readline()
         f.close()
@@ -267,15 +280,16 @@
                 outfile = open(name,"w")
                 outfile.write( self.after_window.get(0.0, END))
                 outfile.close()
+        return name
                 
+    def save_and_run(self):
+        """save the result of the translation to a file and execute it"""
+        exec_file = self.file_save()
+        if exec_file:
+            print "*** Output from %s ***" % exec_file
+            execfile(exec_file,{},{})
 
-    def file_close(self):
-        """ clear out all the information for what was just open"""
-        self.before_window.delete(0.0, END)
-        self.after_window.delete(0.0, END)
-        self.modules = None
 
-
     def make_dialog(self):
         """Set up the User Interface"""
         self.root.title('Mumps2Py')
@@ -321,6 +335,16 @@
         parse_btn['menu'] = parse_btn.menu
         menu_bar.tk_menuBar(parse_btn)
 
+        run_btn = Menubutton(menu_bar, text = 'Run', underline = 0,
+                             takefocus = TRUE)
+        run_btn.pack(side = LEFT, padx = "2m")
+        run_btn.menu = Menu(run_btn)
+        run_btn.menu.add_command( label="Save and run", \
+                                  underline = 1, \
+                                  command = (lambda s = self: s.save_and_run()))
+        run_btn['menu'] = run_btn.menu
+        menu_bar.tk_menuBar(run_btn)
+
         help_btn = Menubutton(menu_bar, text = 'Help', underline = 0,
                              takefocus = TRUE)
         help_btn.pack(side = LEFT, padx = "2m")


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