diff --git a/fossils.py b/fossils.py index 196ba50c68b0ad11f560ed96f9a1470853bd9c63..83cf8bed250710f07d8af7128a7aa5f667bb17a4 100644 --- a/fossils.py +++ b/fossils.py @@ -44,6 +44,24 @@ class Window(QWidget, Ui_Form): if pyfile: self.inpFileLineEdit.setText(QDir.toNativeSeparators(pyfile)) + def on_inpFileEditPushButton_pressed(self): + """Open input file with a text editor + """ + editors = [ + "C:/Program Files/Just Great Software/EditPad Pro 8/EditPadPro8.exe", + "C:/Windows/notepad.exe" + ] + for editor in editors: + if os.path.isfile(editor): + import subprocess + subprocess.Popen([ editor, self.inpFileLineEdit.text() ]) + break + + def on_wrkspExplorePushButton_pressed(self): + """Browse workspace folder with system explorer + """ + os.startfile(self.wrkspLineEdit.text()) + def on_wrkspPushButton_pressed(self): dir = QFileDialog.getExistingDirectory( self, "Select output folder", self.wrkspLineEdit.text()) @@ -98,11 +116,21 @@ def view_results(): gmsh.fltk.run() -def add_folder2path(folder): +def add_folder2pypath(folder): if os.path.isdir(folder): print(f'{folder} added to pythonpath') sys.path.append(folder) +def add_folder2path(folder): + if not os.path.isdir(folder): + return + import platform + if 'Windows' in platform.uname(): + path = os.environ['PATH'].split(';') + path.insert(0, folder) + os.environ['PATH'] = ';'.join(path) + print(f'{folder} added to PATH') + def setup_pythonpath(): """setup PYTHONPATH @@ -110,16 +138,49 @@ def setup_pythonpath(): # adds script folder to the pythonpath thisdir = os.path.split(os.path.abspath(__file__))[0] thisdir = os.path.normcase(thisdir) - add_folder2path(thisdir) + add_folder2pypath(thisdir) # add binary dir to PYTHONPATH pyexe = os.path.basename(sys.executable) print(f'pyexe = {pyexe}') - add_folder2path(os.path.join(thisdir, 'cxxfem', + add_folder2pypath(os.path.join(thisdir, 'cxxfem', 'build', 'bin')) # gcc/mingw - add_folder2path(os.path.join(thisdir, 'cxxfem', - 'build', 'bin', 'Release')) # msvc + add_folder2pypath(os.path.join(thisdir, 'cxxfem', + 'build', 'bin', 'Release')) # msvc + # allows this script to be run without setting env + add_folder2pypath(os.path.join(thisdir, 'lib', + 'gmsh-sdk', 'lib')) # msvc + add_folder2path(os.path.join(thisdir, 'lib', + 'gmsh-sdk', 'bin')) # gmsh + +def create_workspace(workspace, testname): + """create workspace and chdir into it + """ + + if workspace: + # workspace is given: + # => workspace + testname + common = os.path.basename(testname) + resdir = common.replace(os.sep, "_") + resdir, ext = os.path.splitext(resdir) + wdir = os.path.join(workspace, resdir) + else: + # workspace is not given: + # => current_folder + 'workspace' + testname + thisdir = os.path.normcase(os.getcwd()) + # print(f'testname={testname}') + # print(f'thisdir={thisdir}') + common = os.path.commonprefix((testname, thisdir)) + # print(f'common={common}') + resdir = testname[len(common)+1:].replace(os.sep, "_") + resdir, ext = os.path.splitext(resdir) + wdir = os.path.join('workspace', resdir) + print('workspace =', wdir) + # sys.exit() + if not os.path.isdir(wdir): + os.makedirs(wdir) + os.chdir(wdir) if __name__ == "__main__": @@ -159,8 +220,11 @@ if __name__ == "__main__": testname = win.inpFileLineEdit.text() gui = True else: - workspace = None - action = 'run' + workspace = None # use default + if args.post: + action = 'post' + else: + action = 'run' testname = os.path.abspath(args.file) gui = False @@ -171,24 +235,9 @@ if __name__ == "__main__": testname = os.path.normcase(testname) # F:/ => f:/ on Windows print(f'testname = {testname}') - # create workspace - if workspace: - common = os.path.basename(testname) - resdir = common.replace(os.sep, "_") - resdir, ext = os.path.splitext(resdir) - wdir = os.path.join(workspace, resdir) - else: - common = os.path.commonprefix((testname, thisdir + os.sep)) - resdir = testname[len(common):].replace(os.sep, "_") - resdir, ext = os.path.splitext(resdir) - wdir = os.path.join('workspace', resdir) - print('workspace =', wdir) - - if not os.path.isdir(wdir): - os.makedirs(wdir) - os.chdir(wdir) + create_workspace(workspace, testname) - tee = cxxfem.Tee('stdout.txt') # split streams + tee = cxxfem.Tee('stdout.txt') # split streams (stdout + logfile) try: if action == 'run': diff --git a/fossils.ui b/fossils.ui index 34123a86a37f16f8723ba00dca570f21e5705f8e..084eb7bd98fb51efb1df149252c10f80cc72e155 100644 --- a/fossils.ui +++ b/fossils.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>827</width> - <height>124</height> + <width>708</width> + <height>154</height> </rect> </property> <property name="windowTitle"> @@ -33,6 +33,13 @@ </property> </widget> </item> + <item row="0" column="3"> + <widget class="QPushButton" name="inpFileEditPushButton"> + <property name="text"> + <string>Edit</string> + </property> + </widget> + </item> <item row="1" column="0"> <widget class="QLabel" name="wrksplabel"> <property name="text"> @@ -50,6 +57,13 @@ </property> </widget> </item> + <item row="1" column="3"> + <widget class="QPushButton" name="wrkspExplorePushButton"> + <property name="text"> + <string>Explore</string> + </property> + </widget> + </item> </layout> </item> <item> diff --git a/ui_fossils.py b/ui_fossils.py index 9debdc697a394bc674e9818c58f0030adfac451c..d103407e12dff23df5397733022fca6c65c5e926 100644 --- a/ui_fossils.py +++ b/ui_fossils.py @@ -14,7 +14,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") - Form.resize(827, 124) + Form.resize(708, 154) self.verticalLayout = QtWidgets.QVBoxLayout(Form) self.verticalLayout.setObjectName("verticalLayout") self.gridLayout = QtWidgets.QGridLayout() @@ -28,6 +28,9 @@ class Ui_Form(object): self.inpFilePushButton = QtWidgets.QPushButton(Form) self.inpFilePushButton.setObjectName("inpFilePushButton") self.gridLayout.addWidget(self.inpFilePushButton, 0, 2, 1, 1) + self.inpFileEditPushButton = QtWidgets.QPushButton(Form) + self.inpFileEditPushButton.setObjectName("inpFileEditPushButton") + self.gridLayout.addWidget(self.inpFileEditPushButton, 0, 3, 1, 1) self.wrksplabel = QtWidgets.QLabel(Form) self.wrksplabel.setObjectName("wrksplabel") self.gridLayout.addWidget(self.wrksplabel, 1, 0, 1, 1) @@ -37,6 +40,9 @@ class Ui_Form(object): self.wrkspPushButton = QtWidgets.QPushButton(Form) self.wrkspPushButton.setObjectName("wrkspPushButton") self.gridLayout.addWidget(self.wrkspPushButton, 1, 2, 1, 1) + self.wrkspExplorePushButton = QtWidgets.QPushButton(Form) + self.wrkspExplorePushButton.setObjectName("wrkspExplorePushButton") + self.gridLayout.addWidget(self.wrkspExplorePushButton, 1, 3, 1, 1) self.verticalLayout.addLayout(self.gridLayout) self.horizontalLayout_2 = QtWidgets.QHBoxLayout() self.horizontalLayout_2.setObjectName("horizontalLayout_2") @@ -60,7 +66,9 @@ class Ui_Form(object): Form.setWindowTitle(_translate("Form", "Form")) self.inpFilelabel.setText(_translate("Form", "input file")) self.inpFilePushButton.setText(_translate("Form", "...")) + self.inpFileEditPushButton.setText(_translate("Form", "Edit")) self.wrksplabel.setText(_translate("Form", "workspace")) self.wrkspPushButton.setText(_translate("Form", "...")) + self.wrkspExplorePushButton.setText(_translate("Form", "Explore")) self.runPushButton.setText(_translate("Form", "Run")) self.viewPushButton.setText(_translate("Form", "View"))