Hi,

I recently saw that PySimulator is on the OpenModelica SVN.
Should I report issues on the OM mailing list or upstream?
Anyway, one of PySimulator authors is also in BCC.

I'm running OM on OSX, and I haven't tested it in other platforms.
In attach there is a patch that fix some small PySimulator (and the OM plugin) issues on OSX and maybe Linux. I think Windows is still ok.

Best regards,
Guilherme


From f59f3ac56da89edcf7fafef5d9afe12c46351399 Mon Sep 17 00:00:00 2001
From: Guilherme Brondani Torri <guito...@gmail.com>
Date: Wed, 13 Mar 2013 16:50:30 +0100
Subject: [PATCH] Fixes to run on OSX.

Added some logic to handle path and file name on Windows and Linux/OSX.
Created a simulation menu (action was not working on OSX).
Switched from call to Popen to run the binary model.
---
 Plugins/Simulator/OpenModelica/OpenModelica.py | 26 +++++++++++++++++++-------
 PySimulator.py                                 | 26 ++++++++++++++++++++------
 2 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/Plugins/Simulator/OpenModelica/OpenModelica.py 
b/Plugins/Simulator/OpenModelica/OpenModelica.py
index c0d124e..ba7d93b 100644
--- a/Plugins/Simulator/OpenModelica/OpenModelica.py
+++ b/Plugins/Simulator/OpenModelica/OpenModelica.py
@@ -52,7 +52,7 @@ modelExtension = ['mo', 'exe']  # e.g. ['mo']
 parameters_changed = False
 simulationProgressData = 0.0
 
-def closeSimulationPlugin():
+def closeSimulatorPlugin():
     try:
         OMPython.execute("quit()")
     except SystemExit:
@@ -139,7 +139,9 @@ class Model(Plugins.Simulator.SimulatorBase.Model):
         Read the current simulation time during a simulation
         from the Model.exe file generated during loadFile()
         '''
-        fName = os.path.abspath('.') + "/"+self.name+ ".exe"
+        fName = os.path.abspath('.') + os.sep + self.name
+        if os.name == 'nt':
+            fName += ".exe"
 
         if self.file_thread is None:
             self.file_thread = threading.Thread(runExeFile(fName, 
self.server_port))
@@ -209,7 +211,9 @@ class Model(Plugins.Simulator.SimulatorBase.Model):
 
         def precheck_for_model():
             work_dir = os.getcwd()
-            result_exe = work_dir + '\\' + self.name + ".exe"
+            result_exe = work_dir + os.sep + self.name
+            if os.name == 'nt':
+                result_exe += ".exe"
             sim_opts = precheck_for_set_sim_options()
             if os.path.isfile(result_exe):
                 exe_modify_time = os.path.getmtime(result_exe)
@@ -225,8 +229,12 @@ class Model(Plugins.Simulator.SimulatorBase.Model):
                         compile_model(sim_opts)
 
                     # prepare the flags and the parameters for simulating from 
the executable file
-                    flags = " -f " + self.name + "_init.xml " + "-r " + 
self.integrationSettings.resultFileName + 
self.integrationSettings.resultFileFormat
-                    subprocess.call(result_exe + flags)
+                    flags = ["-f " + self.name + "_init.xml",
+                             "-r " + self.integrationSettings.resultFileName + 
self.integrationSettings.resultFileFormat]
+
+                    command = [result_exe]+flags
+                    process=subprocess.Popen(command, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)
+                    process.communicate()
             else:
                 if sim_opts!='':
                     compile_model(sim_opts)
@@ -238,7 +246,10 @@ class Model(Plugins.Simulator.SimulatorBase.Model):
             Read statistics from the LOG_STATS.txt file
             '''
             work_dir = os.getcwd()
-            result_exe = work_dir + '\\' + self.name + ".exe -lv LOG_STATS"
+            result_exe = work_dir + os.sep + self.name
+            if os.name == 'nt':
+                result_exe += ".exe"
+            result_exe += " -lv LOG_STATS"
 
             with open('LOG_STATS.txt', 'w') as output_f:
                 p = subprocess.Popen(result_exe,
@@ -371,7 +382,8 @@ def loadResultFileInit(fileName):
        
     """
     # Correct file path if needed
-    fileName = fileName.replace("/","\\")
+    if os.name == 'nt':
+        fileName = fileName.replace("/","\\")
 
     # If no fileName given, inquire it interactively
     if fileName == None:
diff --git a/PySimulator.py b/PySimulator.py
index f0f62f6..7383ad4 100644
--- a/PySimulator.py
+++ b/PySimulator.py
@@ -89,9 +89,14 @@ class SimulatorGui(QtGui.QMainWindow):
         subMenu.addSeparator()
         subMenu.addAction("Open Result File", self._openResultFileMenu)
         subMenu.addAction("Convert to MTSF", self._convertResultFileMenu)
-        subMenu.addSeparator()
-        subMenu.addAction('Exit', self.close)
-        self.simulateAction = menu.addAction("Simulate", 
self._showIntegratorControl)
+
+        if not sys.platform.startswith('darwin'):
+            subMenu.addSeparator()
+            subMenu.addAction('Exit', self.close)
+
+        simMenu = menu.addMenu('Simulation')
+        simMenu.addAction("Simulate", self._showIntegratorControl)
+
         self.plotMenuCallbacks = []
         self.variableMenuCallbacks = []
         self.modelMenuCallbacks = []
@@ -165,7 +170,18 @@ class SimulatorGui(QtGui.QMainWindow):
             print("No Model selected, unable to execute Plugin\n")
 
     def showHelp(self):
-        os.startfile("file:///" + self.rootDir + "/Documentation/index.html")
+        filepath = "file:///" + self.rootDir + os.sep + "Documentation" + 
os.sep + "index.html"
+
+        if os.name == 'nt':
+            os.startfile(filepath)
+        elif os.name == 'posix':
+            import subprocess
+            subprocess.call(('xdg-open', filepath))
+        elif sys.platform.startswith('darwin'):
+            import subprocess
+            subprocess.call(('open', filepath))
+
+
 
     def showAbout(self):
         widget = QtGui.QDialog(self)
@@ -366,7 +382,6 @@ class SimulatorGui(QtGui.QMainWindow):
         else:
             currentModelName = str(self.nvb.currentModelItem.text(0))
             if self.models[currentModelName].modelType != 'None':
-                self.simulateAction.setDisabled(True)
                 self.ic = IntegratorControl.IntegratorControl(self, 
self.models)
                 self.ic.show()
                 #self.ic.printText.connect(print)
@@ -376,7 +391,6 @@ class SimulatorGui(QtGui.QMainWindow):
                 print("Only result file opened, no model existing that can be 
simulated!\n")
 
     def _finishIntegratorControl(self):
-        self.simulateAction.setEnabled(True)
         del(self.ic)
 
     def _newPlotContainer(self):
-- 
1.8.0.1

Reply via email to