~ubuntu-branches/ubuntu/precise/code-saturne/precise

« back to all changes in this revision

Viewing changes to gui/Base/MainView.py

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-24 00:00:08 UTC
  • mfrom: (6.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20111124000008-2vo99e38267942q5
Tags: 2.1.0-3
Install a missing file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
 
#-------------------------------------------------------------------------------
3
 
#
4
 
#     This file is part of the Code_Saturne User Interface, element of the
5
 
#     Code_Saturne CFD tool.
6
 
#
7
 
#     Copyright (C) 1998-2009 EDF S.A., France
8
 
#
9
 
#     contact: saturne-support@edf.fr
10
 
#
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.
15
 
#
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.
20
 
#
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
26
 
#
27
 
#-------------------------------------------------------------------------------
28
 
 
 
2
 
 
3
#-------------------------------------------------------------------------------
 
4
 
 
5
# This file is part of Code_Saturne, a general-purpose CFD tool.
 
6
#
 
7
# Copyright (C) 1998-2011 EDF S.A.
 
8
#
 
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
 
12
# version.
 
13
#
 
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
 
17
# details.
 
18
#
 
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.
 
22
 
 
23
#-------------------------------------------------------------------------------
29
24
 
30
25
"""
31
26
This module defines the main application classes for the Qt GUI.
57
52
# Application modules
58
53
#-------------------------------------------------------------------------------
59
54
 
60
 
from MainForm import Ui_MainForm
61
 
from IdView import IdView
62
 
from BrowserView import BrowserView
63
 
import XMLengine
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
68
63
 
69
64
try:
70
65
    import Pages
73
68
 
74
69
from Pages.WelcomeView import WelcomeView
75
70
from Pages.IdentityAndPathesModel import IdentityAndPathesModel
76
 
from Pages.BatchRunningModel import BatchRunningModel
77
71
 
78
72
#-------------------------------------------------------------------------------
79
73
# log config
93
87
    Instances = set()
94
88
 
95
89
    def __init__(self,
 
90
                 package          = None,
96
91
                 cmd_case         = "",
97
 
                 cmd_matisse      = False,
98
92
                 cmd_batch_window = False,
99
93
                 cmd_batch_file   = 'runcase',
100
94
                 cmd_tree_window  = True,
176
170
 
177
171
        # create some instance variables
178
172
 
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
185
 
        self.notree     = 0
 
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
 
181
        self.notree      = 0
 
182
        self.package     = package
186
183
 
187
184
        self.resize(800, 700)
188
185
        #self.setMaximumSize(QSize(2000, 900))
223
220
#        self.setMaximumSize(QSize(700, 600))
224
221
#        self.setMinimumSize(QSize(700, 600))
225
222
 
 
223
 
226
224
    @staticmethod
227
225
    def updateInstances(qobj):
228
226
        """
373
371
 
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
380
376
 
381
377
        self.updateStudyId()
460
456
        create new Code_Saturne case
461
457
        """
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)
468
464
 
469
465
            self.Browser.configureTree(self.case)
482
478
            self.case['saved'] = "yes"
483
479
 
484
480
        else:
485
 
            MainView(cmd_case="new case").show()
 
481
            MainView(package=self.package, cmd_case="new case").show()
486
482
 
487
483
 
488
484
    def fileAlreadyLoaded(self, f):
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()
530
526
        else:
531
527
            self.loadFile(file_name)
532
528
 
548
544
        # Instantiate a new case
549
545
 
550
546
        try:
551
 
            self.case = XMLengine.Case(file_name)
 
547
            self.case = XMLengine.Case(package=self.package, file_name=file_name)
552
548
        except:
553
549
            err = QErrorMessage(self)
554
550
            msg = self.tr("XML file reading error. "\
583
579
 
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)
588
584
 
589
585
        msg = self.tr("Loaded: %s" % fn)
624
620
            path = os.getcwd()
625
621
            if os.path.isdir(path + "/../DATA"): path = path + "/../DATA"
626
622
 
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 (*)")
628
624
 
629
625
        file_name = QFileDialog.getOpenFileName(self, title, path, filetypes)
630
626
 
640
636
 
641
637
        if hasattr(self, 'case'):
642
638
            if not self.fileAlreadyLoaded(file_name):
643
 
                MainView(cmd_case = file_name).show()
 
639
                MainView(package=self.package, cmd_case = file_name).show()
644
640
        else:
645
641
            self.loadFile(file_name)
646
642
 
668
664
        print the case (xml file) on the current terminal
669
665
        """
670
666
        if hasattr(self, 'case'):
671
 
            print self.case
 
667
            print(self.case)
672
668
 
673
669
 
674
670
    def updateStudyId(self):
715
711
 
716
712
        self.updateStudyId()
717
713
        self.case.xmlSaveDocument()
 
714
        self.batchFileSave()
718
715
 
719
716
        log.debug("fileSave(): ok")
720
717
 
 
718
        if self.case['batch'] and self.batch_lines:
 
719
            batch = self.case['scripts_path'] + "/" + self.case['batch']
 
720
            f = open(batch, 'w')
 
721
            f.writelines(self.batch_lines)
 
722
            f.close()
 
723
 
721
724
        msg = self.tr("%s saved" % file_name)
722
725
        self.statusbar.showMessage(msg, 2000)
723
726
 
732
735
        log.debug("fileSaveAs()")
733
736
 
734
737
        if hasattr(self,'case'):
 
738
            filetypes = self.tr(self.package.code_name) + self.tr(" GUI files (*.xml);;""All Files (*)")
735
739
            fname = QFileDialog.getSaveFileName(self,
736
740
                                  self.tr("Save File As"),
737
741
                                  self.case['data_path'],
738
 
                                  self.tr("Code_Saturne GUI file (*.xml);;All files (*)"))
 
742
                                  filetypes)
739
743
 
740
744
            if not fname.isEmpty():
741
745
                f = str(fname)
744
748
                self.fileSave()
745
749
                self.updateStudyId()
746
750
                self.case.xmlSaveDocument()
747
 
                title = os.path.basename(self.case['xmlfile']) + " - " + self.tr("Code_Saturne GUI")
 
751
                self.batchFileSave()
 
752
                title = os.path.basename(self.case['xmlfile']) + " - " + self.tr(self.package.code_name) + self.tr(" GUI")
748
753
                self.setWindowTitle(title)
749
754
 
750
 
                for k,v in self.case['batchScript'].items():
751
 
                    if v:
752
 
                        self.case['computer'] = k
753
 
                        mdl = BatchRunningModel(self.case)
754
 
                        mdl.updateBatchScriptFile('PARAM')
755
755
            else:
756
756
                msg = self.tr("Saving aborted")
757
757
                self.statusbar.showMessage(msg, 2000)
758
758
 
759
759
 
 
760
    def batchFileUpdate(self):
 
761
        """
 
762
        Update the run command
 
763
        """
 
764
        cmd_name = self.case['package'].name
 
765
        parameters = os.path.basename(self.case['xmlfile'])
 
766
        batch_lines = self.batch_lines
 
767
 
 
768
        # If filename has whitespace, protect it
 
769
        if parameters.find(' ') > -1:
 
770
            parameters = '"' + parameters + '"'
 
771
 
 
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)
 
776
                if index < 0:
 
777
                    continue
 
778
                if line[index + len(cmd_name):].strip()[0:3] != 'run':
 
779
                    continue
 
780
                index = string.find(line, '--param')
 
781
                if index >= 0:
 
782
                    # Find file name, possibly protected by quotes
 
783
                    # (protection by escape character not handled)
 
784
                    index += len('--param')
 
785
                    end = len(line)
 
786
                    while index < end and line[index] in (' ', '\t'):
 
787
                        index += 1
 
788
                    if index < end:
 
789
                        sep = line[index]
 
790
                        if sep == '"' or sep == "'":
 
791
                            index += 1
 
792
                        else:
 
793
                            sep = ' '
 
794
                        start = index
 
795
                        while index < end and line[index] != sep:
 
796
                            index += 1
 
797
                        end = index
 
798
                        batch_lines[i] = line[0:start].strip() \
 
799
                            + ' ' + parameters + ' ' + line[end:].strip() + '\n'
 
800
                    else:
 
801
                        batch_lines[i] = line + ' --param ' + parameters + '\n'
 
802
                else:
 
803
                    batch_lines[i] = line + ' --param ' + parameters + '\n'
 
804
 
 
805
        self.batch_lines = batch_lines
 
806
 
 
807
 
 
808
    @pyqtSignature("")
 
809
    def batchFileSave(self):
 
810
        """
 
811
        public slot
 
812
 
 
813
        save the current case
 
814
        """
 
815
        log.debug("batchFileSave()")
 
816
 
 
817
        if not hasattr(self, 'case'):
 
818
            return
 
819
 
 
820
        if self.case['batch'] and self.batch_lines:
 
821
 
 
822
            self.batchFileUpdate()
 
823
 
 
824
            batch = self.case['scripts_path'] + "/" + self.case['batch']
 
825
            f = open(batch, 'w')
 
826
            f.writelines(self.batch_lines)
 
827
            f.close()
 
828
 
 
829
 
760
830
    @pyqtSignature("")
761
831
    def reload_modules(self):
762
832
        """
827
897
         - version
828
898
         - contact
829
899
        """
830
 
        import cs_config
831
 
 
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"                 +\
 
906
              self.package.url
 
907
        QMessageBox.about(self, self.package.name + ' Interface', msg)
840
908
 
841
909
 
842
910
    @pyqtSignature("")
846
914
 
847
915
        GNU GPL license dialog window
848
916
        """
849
 
        QMessageBox.about(self, 'Code_Saturne Interface', "see COPYING file") # TODO
 
917
        QMessageBox.about(self, self.package.code_name + ' Interface', "see COPYING file") # TODO
850
918
 
851
919
 
852
920
    @pyqtSignature("")
856
924
 
857
925
        configuration information window
858
926
        """
859
 
        QMessageBox.about(self, 'Code_Saturne Interface', "see config.py") # TODO
 
927
        QMessageBox.about(self, self.package.code_name + ' Interface', "see config.py") # TODO
860
928
 
861
929
 
862
930
    def displayManual(self, manual, reader = None):
868
936
        try:
869
937
            import cs_info
870
938
        except:
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.")
873
941
            return
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)
877
945
 
878
946
 
879
947
    @pyqtSignature("")