Skip to content

Commit

Permalink
[processing] helpfiles for scripts/models are now stored as json
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Jun 2, 2014
1 parent ff24353 commit 6c9f7d7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
2 changes: 0 additions & 2 deletions python/plugins/processing/core/ProcessingLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@

__revision__ = '$Format:%H$'

import os
import re
import codecs
import datetime
from PyQt4 import QtGui
from processing.tools.system import *
from processing.core.ProcessingConfig import ProcessingConfig

Expand Down
11 changes: 5 additions & 6 deletions python/plugins/processing/gui/Help2Html.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* *
***************************************************************************
"""
import re


__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand All @@ -26,10 +26,9 @@

__revision__ = '$Format:%H$'

import pickle
from processing.tools.system import *
import os
import codecs
import re
import json

ALG_DESC = 'ALG_DESC'
ALG_CREATOR = 'ALG_CREATOR'
Expand Down Expand Up @@ -58,8 +57,8 @@ def getHtmlFromHelpFile(alg, helpFile):
if not os.path.exists(helpFile):
return None
alg = alg
f = open(helpFile, 'rb')
descriptions = pickle.load(f)
with open(helpFile) as f:
descriptions = json.load(f)
s = '<html><body><h2>Algorithm description</h2>\n'
s += '<p>' + getDescription(ALG_DESC, descriptions) + '</p>\n'
s += '<h2>Input parameters</h2>\n'
Expand Down
29 changes: 17 additions & 12 deletions python/plugins/processing/gui/HelpEditionDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
***************************************************************************
"""


__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
Expand All @@ -26,11 +27,12 @@
__revision__ = '$Format:%H$'

import os
import pickle
import json
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from processing.ui.ui_DlgHelpEdition import Ui_DlgHelpEdition
from processing.core.ProcessingLog import ProcessingLog


class HelpEditionDialog(QDialog, Ui_DlgHelpEdition):
Expand All @@ -49,8 +51,13 @@ def __init__(self, alg):
if self.alg.descriptionFile is not None:
helpfile = alg.descriptionFile + '.help'
if os.path.exists(helpfile):
f = open(helpfile, 'rb')
self.descriptions = pickle.load(f)
try:
with open(helpfile) as f:
self.descriptions = json.load(f)
except Exception, e:
print e
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING, "Cannot open gelp file: " + helpfile)

self.currentName = self.ALG_DESC
if self.ALG_DESC in self.descriptions:
self.text.setText(self.descriptions[self.ALG_DESC])
Expand All @@ -67,17 +74,15 @@ def accept(self):
self.descriptions[self.currentName] = unicode(self.text.toPlainText())
if self.alg.descriptionFile is not None:
try:
f = open(self.alg.descriptionFile + '.help', 'wb')
pickle.dump(self.descriptions, f)
f.close()
with open(self.alg.descriptionFile + '.help', 'w') as f:
json.dump(self.descriptions, f)
except Exception, e:
QMessageBox.warning(self, 'Error saving help file',
'Help file could not be saved. Check that \
you have permission to modify the help \
file. You might not have permission if \
you are editing an example model or \
script, since they are stored on the \
installation folder')
'Help file could not be saved.\n'
'Check that you have permission to modify the help\n'
'file. You might not have permission if you are \n'
'editing an example model or script, since they \n'
'are stored on the installation folder')

QDialog.accept(self)

Expand Down
7 changes: 3 additions & 4 deletions python/plugins/processing/gui/ScriptEditorDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

__revision__ = '$Format:%H$'

import pickle
import codecs
import sys
import json

from PyQt4.QtCore import *
from PyQt4.QtGui import *
Expand Down Expand Up @@ -166,9 +166,8 @@ def saveScript(self, saveAs):
# If help strings were defined before saving the script for
# the first time, we do it here
if self.help:
f = open(self.filename + '.help', 'wb')
pickle.dump(self.help, f)
f.close()
with open(self.filename + '.help', 'w') as f:
json.dump(self.help, f)
self.help = None
self.setHasChanged(False)
else:
Expand Down
7 changes: 3 additions & 4 deletions python/plugins/processing/modeler/ModelerDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
import json

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand All @@ -26,7 +27,6 @@
__revision__ = '$Format:%H$'

import codecs
import pickle
from PyQt4.QtCore import *
from PyQt4.QtGui import *

Expand Down Expand Up @@ -308,9 +308,8 @@ def saveModel(self, saveAs):
# If help strings were defined before saving the model
# for the first time, we do it here.
if self.help:
f = open(self.alg.descriptionFile + '.help', 'wb')
pickle.dump(self.help, f)
f.close()
with open(self.descriptionFile + '.help', 'w') as f:
json.dump(self.help, f)
self.help = None
QMessageBox.information(self, self.tr('Model saved'),
self.tr('Model was correctly saved.'))
Expand Down

0 comments on commit 6c9f7d7

Please sign in to comment.