Skip to content

Commit

Permalink
added scintilla based editor to R scripts editor
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Sep 2, 2013
1 parent 6607ced commit e44c57c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
51 changes: 40 additions & 11 deletions python/plugins/processing/r/EditRScriptDialog.py
Expand Up @@ -16,22 +16,20 @@
* *
***************************************************************************
"""
from processing.gui.ParametersDialog import ParametersDialog
from processing.core.QGisLayers import QGisLayers
from processing.modeler.Providers import Providers

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import sys

from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from processing.gui.HelpEditionDialog import HelpEditionDialog
from processing.gui.ParametersDialog import ParametersDialog
from processing.core.QGisLayers import QGisLayers
from processing.modeler.Providers import Providers
import pickle
from processing.r.RAlgorithm import RAlgorithm
from processing.r.RUtils import RUtils
Expand All @@ -51,11 +49,11 @@ def __init__(self, alg):

def setupUi(self):
self.resize(600,400)
self.setWindowFlags(self.windowFlags() | Qt.WindowSystemMenuHint |
Qt.WindowMinMaxButtonsHint)
self.setWindowTitle("Edit script")
layout = QVBoxLayout()
self.text = QtGui.QTextEdit()
self.text.setObjectName("text")
self.text.setEnabled(True)
self.text = ScriptEditorWidget(self.alg.script if self.alg is not None else "")
self.buttonBox = QtGui.QDialogButtonBox()
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
if self.alg != None:
Expand Down Expand Up @@ -83,7 +81,7 @@ def setupUi(self):

def editHelp(self):
if self.alg is None:
alg = RAlgorithm(None, unicode(self.text.toPlainText()))
alg = RAlgorithm(None, unicode(self.text.text()))
else:
alg = self.alg
dlg = HelpEditionDialog(alg)
Expand All @@ -94,7 +92,7 @@ def editHelp(self):
self.help = dlg.descriptions

def runAlgorithm(self):
alg = RAlgorithm(None, unicode(self.text.toPlainText()))
alg = RAlgorithm(None, unicode(self.text.text()))
alg.provider = Providers.providers['r']
dlg = alg.getCustomParametersDialog()
if not dlg:
Expand All @@ -117,7 +115,7 @@ def saveAlgorithm(self):
if self.filename:
if not self.filename.endswith(".rsx"):
self.filename += ".rsx"
text = str(self.text.toPlainText())
text = str(self.text.text())
if self.alg is not None:
self.alg.script = text
try:
Expand All @@ -144,3 +142,34 @@ def saveAlgorithm(self):
def cancelPressed(self):
#self.update = False
self.close()

from PyQt4.Qsci import QsciScintilla

class ScriptEditorWidget(QsciScintilla):
ARROW_MARKER_NUM = 8

def __init__(self, text, parent=None):
super(ScriptEditorWidget, self).__init__(parent)

font = QFont()
font.setFamily('Courier')
font.setFixedPitch(True)
font.setPointSize(10)
self.setFont(font)
self.setMarginsFont(font)

fontmetrics = QFontMetrics(font)
self.setMarginsFont(font)
self.setMarginWidth(0, fontmetrics.width("00000") + 6)
self.setMarginLineNumbers(0, True)
self.setMarginsBackgroundColor(QColor("#cccccc"))

self.setBraceMatching(QsciScintilla.SloppyBraceMatch)

self.setCaretLineVisible(True)
self.setCaretLineBackgroundColor(QColor("#ffe4e4"))

self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Courier')

self.setText(text)

5 changes: 3 additions & 2 deletions python/plugins/processing/script/EditScriptDialog.py
Expand Up @@ -48,10 +48,11 @@ def __init__(self, alg):

def setupUi(self):
self.resize(600,400)
self.setWindowFlags(self.windowFlags() | Qt.WindowSystemMenuHint |
Qt.WindowMinMaxButtonsHint)
self.setWindowTitle("Edit script")
layout = QVBoxLayout()
self.text = ScriptEditorWidget(self.alg.script if self.alg is not None else "")
#self.text.setEnabled(True)
self.buttonBox = QtGui.QDialogButtonBox()
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.editHelpButton = QtGui.QPushButton()
Expand All @@ -74,7 +75,7 @@ def setupUi(self):

def editHelp(self):
if self.alg is None:
alg = ScriptAlgorithm(None, unicode(self.text.toPlainText()))
alg = ScriptAlgorithm(None, unicode(self.text.text()))
else:
alg = self.alg
dlg = HelpEditionDialog(alg)
Expand Down

0 comments on commit e44c57c

Please sign in to comment.