1
1
# -*- coding: utf-8 -*-
2
#-------------------------------------------------------------------------------
4
# This file is part of the Code_Saturne User Interface, element of the
5
# Code_Saturne CFD tool.
7
# Copyright (C) 1998-2009 EDF S.A., France
9
# contact: saturne-support@edf.fr
11
# The Code_Saturne User Interface is free software; you can redistribute it
12
# and/or modify it under the terms of the GNU General Public License
13
# as published by the Free Software Foundation; either version 2 of
14
# the License, or (at your option) any later version.
16
# The Code_Saturne User Interface is distributed in the hope that it will be
17
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
18
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU General Public License for more details.
21
# You should have received a copy of the GNU General Public License
22
# along with the Code_Saturne Kernel; if not, write to the
23
# Free Software Foundation, Inc.,
24
# 51 Franklin St, Fifth Floor,
25
# Boston, MA 02110-1301 USA
27
#-------------------------------------------------------------------------------
3
#-------------------------------------------------------------------------------
5
# This file is part of Code_Saturne, a general-purpose CFD tool.
7
# Copyright (C) 1998-2011 EDF S.A.
9
# This program is free software; you can redistribute it and/or modify it under
10
# the terms of the GNU General Public License as published by the Free Software
11
# Foundation; either version 2 of the License, or (at your option) any later
14
# This program is distributed in the hope that it will be useful, but WITHOUT
15
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19
# You should have received a copy of the GNU General Public License along with
20
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
21
# Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
#-------------------------------------------------------------------------------
31
26
This module defines the main application classes for the Qt GUI.
57
52
# Application modules
58
53
#-------------------------------------------------------------------------------
60
from MainForm import Ui_MainForm
61
from IdView import IdView
62
from BrowserView import BrowserView
64
from XMLinitialize import *
65
from XMLmodel import *
66
from Toolbox import GuiParam, displaySelectedPage
67
from Common import XML_DOC_VERSION
55
from Base.MainForm import Ui_MainForm
56
from Base.IdView import IdView
57
from Base.BrowserView import BrowserView
58
from Base import XMLengine
59
from Base.XMLinitialize import *
60
from Base.XMLmodel import *
61
from Base.Toolbox import GuiParam, displaySelectedPage
62
from Base.Common import XML_DOC_VERSION, cs_batch_type
177
171
# create some instance variables
179
self.cmd_case = cmd_case
180
self.salome = cmd_salome
181
self.batch = cmd_batch_window
182
self.batch_file = cmd_batch_file
183
self.tree_w = cmd_tree_window
184
self.read_o = cmd_read_only
173
self.cmd_case = cmd_case
174
self.salome = cmd_salome
175
self.batch_type = cs_batch_type
176
self.batch = cmd_batch_window
177
self.batch_file = cmd_batch_file
178
self.batch_lines = []
179
self.tree_w = cmd_tree_window
180
self.read_o = cmd_read_only
182
self.package = package
187
184
self.resize(800, 700)
188
185
#self.setMaximumSize(QSize(2000, 900))
374
372
self.IdPthMdl.setPathI('mesh_path',
375
373
os.path.abspath(os.path.split(file_dir)[0] + '/' + 'MESH'))
376
self.case['computer'] = 'station'
377
self.case['batchScript'] = {'pbs': '', 'station': self.batch_file}
378
self.case['backupBatchScript'] = {'pbs': 'no', 'station': 'yes'}
374
self.case['batch'] = self.batch_file
379
375
del IdentityAndPathesModel
381
377
self.updateStudyId()
460
456
create new Code_Saturne case
462
458
if not hasattr(self, 'case'):
463
self.case = XMLengine.Case()
459
self.case = XMLengine.Case(package=self.package)
464
460
self.case.root()['version'] = XML_DOC_VERSION
465
461
XMLinit(self.case)
466
title = self.tr("New parameters set") + " - " + self.tr("Code_Saturne GUI")
462
title = self.tr("New parameters set") + " - " + self.tr(self.package.code_name) + self.tr(" GUI")
467
463
self.setWindowTitle(title)
469
465
self.Browser.configureTree(self.case)
526
522
# check if the file to load is not already loaded
527
523
if hasattr(self, 'case'):
528
524
if not self.fileAlreadyLoaded(file_name):
529
MainView(cmd_case = file_name).show()
525
MainView(package=self.package, cmd_case = file_name).show()
531
527
self.loadFile(file_name)
584
580
# Update the case and the StudyIdBar
585
581
self.case['xmlfile'] = file_name
586
title = fn + " - " + self.tr("Code_Saturne GUI")
582
title = fn + " - " + self.tr(self.package.code_name) + self.tr(" GUI")
587
583
self.setWindowTitle(title)
589
585
msg = self.tr("Loaded: %s" % fn)
624
620
path = os.getcwd()
625
621
if os.path.isdir(path + "/../DATA"): path = path + "/../DATA"
627
filetypes = self.tr("Code_Saturne GUI files (*.xml);;""All Files (*)")
623
filetypes = self.tr(self.package.code_name) + self.tr(" GUI files (*.xml);;""All Files (*)")
629
625
file_name = QFileDialog.getOpenFileName(self, title, path, filetypes)
716
712
self.updateStudyId()
717
713
self.case.xmlSaveDocument()
719
716
log.debug("fileSave(): ok")
718
if self.case['batch'] and self.batch_lines:
719
batch = self.case['scripts_path'] + "/" + self.case['batch']
721
f.writelines(self.batch_lines)
721
724
msg = self.tr("%s saved" % file_name)
722
725
self.statusbar.showMessage(msg, 2000)
745
749
self.updateStudyId()
746
750
self.case.xmlSaveDocument()
747
title = os.path.basename(self.case['xmlfile']) + " - " + self.tr("Code_Saturne GUI")
752
title = os.path.basename(self.case['xmlfile']) + " - " + self.tr(self.package.code_name) + self.tr(" GUI")
748
753
self.setWindowTitle(title)
750
for k,v in self.case['batchScript'].items():
752
self.case['computer'] = k
753
mdl = BatchRunningModel(self.case)
754
mdl.updateBatchScriptFile('PARAM')
756
756
msg = self.tr("Saving aborted")
757
757
self.statusbar.showMessage(msg, 2000)
760
def batchFileUpdate(self):
762
Update the run command
764
cmd_name = self.case['package'].name
765
parameters = os.path.basename(self.case['xmlfile'])
766
batch_lines = self.batch_lines
768
# If filename has whitespace, protect it
769
if parameters.find(' ') > -1:
770
parameters = '"' + parameters + '"'
772
for i in range(len(batch_lines)):
773
if batch_lines[i][0:1] != '#':
774
line = batch_lines[i].strip()
775
index = string.find(line, cmd_name)
778
if line[index + len(cmd_name):].strip()[0:3] != 'run':
780
index = string.find(line, '--param')
782
# Find file name, possibly protected by quotes
783
# (protection by escape character not handled)
784
index += len('--param')
786
while index < end and line[index] in (' ', '\t'):
790
if sep == '"' or sep == "'":
795
while index < end and line[index] != sep:
798
batch_lines[i] = line[0:start].strip() \
799
+ ' ' + parameters + ' ' + line[end:].strip() + '\n'
801
batch_lines[i] = line + ' --param ' + parameters + '\n'
803
batch_lines[i] = line + ' --param ' + parameters + '\n'
805
self.batch_lines = batch_lines
809
def batchFileSave(self):
813
save the current case
815
log.debug("batchFileSave()")
817
if not hasattr(self, 'case'):
820
if self.case['batch'] and self.batch_lines:
822
self.batchFileUpdate()
824
batch = self.case['scripts_path'] + "/" + self.case['batch']
826
f.writelines(self.batch_lines)
760
830
@pyqtSignature("")
761
831
def reload_modules(self):
832
msg = "Code_Saturne\n" +\
833
"version " + cs_config.package.version + "\n\n" +\
834
"For information about this application " +\
835
"please contact:\n\n" +\
836
"saturne-support@edf.fr\n\n" +\
837
"Please visit our site:\n" +\
838
"http://www.code-saturne.org"
839
QMessageBox.about(self, 'Code_Saturne Interface', msg)
900
msg = self.package.code_name + "\n" +\
901
"version " + self.package.version + "\n\n" +\
902
"For information about this application " +\
903
"please contact:\n\n" +\
904
self.package.bugreport + "\n\n" +\
905
"Please visit our site:\n" +\
907
QMessageBox.about(self, self.package.name + ' Interface', msg)
842
910
@pyqtSignature("")
857
925
configuration information window
859
QMessageBox.about(self, 'Code_Saturne Interface', "see config.py") # TODO
927
QMessageBox.about(self, self.package.code_name + ' Interface', "see config.py") # TODO
862
930
def displayManual(self, manual, reader = None):
871
QMessageBox.warning(self, 'Code_Saturne Interface',
939
QMessageBox.warning(self, self.package.code_name + ' Interface',
872
940
"The module 'cs_info' is not available.")
874
942
argv_info = ['--guide']
875
943
argv_info.append(manual)
876
cs_info.main(argv_info)
944
cs_info.main(argv_info, self.package)
879
947
@pyqtSignature("")