1
1
from PyQt4 import QtCore , QtGui
2
2
from PyQt4 .QtCore import *
3
3
from PyQt4 .QtGui import *
4
- from sextante .r .RUtils import RUtils
5
- import pickle
6
4
from sextante .gui .HelpEditionDialog import HelpEditionDialog
5
+ import pickle
6
+ from sextante .r .RAlgorithm import RAlgorithm
7
+ from sextante .r .RUtils import RUtils
7
8
8
9
class EditRScriptDialog (QtGui .QDialog ):
9
10
def __init__ (self , alg ):
10
11
self .alg = alg
12
+ if self .alg is not None :
13
+ self .filename = self .alg .descriptionFile
14
+ else :
15
+ self .filename = None
11
16
QtGui .QDialog .__init__ (self )
12
17
self .setModal (True )
13
18
self .setupUi ()
14
19
self .update = False
15
20
self .help = None
16
21
17
22
def setupUi (self ):
23
+ self .resize (600 ,400 )
18
24
self .setWindowTitle ("Edit script" )
19
- self .resize (600 , 350 )
20
25
layout = QVBoxLayout ()
21
26
self .text = QtGui .QTextEdit ()
22
27
self .text .setObjectName ("text" )
23
28
self .text .setEnabled (True )
29
+ self .buttonBox = QtGui .QDialogButtonBox ()
30
+ self .buttonBox .setOrientation (QtCore .Qt .Horizontal )
24
31
if self .alg != None :
25
32
self .text .setText (self .alg .script )
26
- self .buttonBox = QDialogButtonBox (QDialogButtonBox .Ok | QDialogButtonBox .Close )
27
33
self .editHelpButton = QtGui .QPushButton ()
28
- self .editHelpButton .setText ("Edit model help" )
34
+ self .editHelpButton .setText ("Edit script help" )
29
35
self .buttonBox .addButton (self .editHelpButton , QtGui .QDialogButtonBox .ActionRole )
36
+ QObject .connect (self .editHelpButton , QtCore .SIGNAL ("clicked()" ), self .editHelp )
37
+ self .saveButton = QtGui .QPushButton ()
38
+ self .saveButton .setText ("Save" )
39
+ self .buttonBox .addButton (self .saveButton , QtGui .QDialogButtonBox .ActionRole )
40
+ self .closeButton = QtGui .QPushButton ()
41
+ self .closeButton .setText ("Close" )
42
+ self .buttonBox .addButton (self .closeButton , QtGui .QDialogButtonBox .ActionRole )
43
+ QObject .connect (self .saveButton , QtCore .SIGNAL ("clicked()" ), self .saveAlgorithm )
44
+ QObject .connect (self .closeButton , QtCore .SIGNAL ("clicked()" ), self .cancelPressed )
30
45
layout .addWidget (self .text )
31
46
layout .addWidget (self .buttonBox )
32
47
self .setLayout (layout )
33
- self .connect (self .buttonBox , SIGNAL ("accepted()" ), self .saveAlgorithm )
34
- self .connect (self .buttonBox , SIGNAL ("rejected()" ), self .cancelPressed )
35
- self .connect (self .editHelpButton , SIGNAL ("clicked()" ), self .editHelp )
36
48
QtCore .QMetaObject .connectSlotsByName (self )
37
49
50
+
38
51
def editHelp (self ):
39
- dlg = HelpEditionDialog (self .alg )
52
+ if self .alg is None :
53
+ alg = RAlgorithm (None , unicode (self .text .toPlainText ()))
54
+ else :
55
+ alg = self .alg
56
+ dlg = HelpEditionDialog (alg )
40
57
dlg .exec_ ()
41
58
#We store the description string in case there were not saved because there was no
42
59
#filename defined yet
43
- if self .alg . descriptionFile is None and dlg .descriptions :
60
+ if self .alg is None and dlg .descriptions :
44
61
self .help = dlg .descriptions
45
62
63
+
46
64
def saveAlgorithm (self ):
47
- if self .alg != None :
48
- filename = self .alg .descriptionFile
49
- else :
50
- filename = QtGui .QFileDialog .getSaveFileName (self , "Save Script" , RUtils .RScriptsFolder (), "R-SEXTANTE scripts (*.rsx)" )
65
+ if self .filename is None :
66
+ self .filename = QtGui .QFileDialog .getSaveFileName (self , "Save Script" , RUtils .RScriptsFolder (), "SEXTANTE R script (*.rsx)" )
51
67
52
- if filename :
53
- #self.alg.descriptionFile = filename
54
- text = self .text .toPlainText ()
55
- fout = open (filename , "w" )
68
+ if self .filename :
69
+ text = str (self .text .toPlainText ())
70
+ if self .alg is not None :
71
+ self .alg .script = text
72
+ fout = open (self .filename , "w" )
56
73
fout .write (text )
57
74
fout .close ()
58
75
self .update = True
59
76
#if help strings were defined before saving the model for the first time, we do it here
60
77
if self .help :
61
- f = open (filename + ".help" , "wb" )
78
+ f = open (self . filename + ".help" , "wb" )
62
79
pickle .dump (self .help , f )
63
80
f .close ()
64
81
self .help = None
65
82
QtGui .QMessageBox .information (self , "Script saving" , "Script was correctly saved." )
66
- self .close ()
83
+ else :
84
+ self .filename = None
67
85
68
86
def cancelPressed (self ):
69
- self .update = False
87
+ # self.update = False
70
88
self .close ()
0 commit comments