Skip to content
Snippets Groups Projects
Commit 1ed212aa authored by Martyn Gigg's avatar Martyn Gigg
Browse files

Add export for ScriptEditor widget and basic test.

Refs #21251
parent a8df2dc4
No related branches found
No related tags found
No related merge requests found
# This file is part of the mantidqt package
#
# Copyright (C) 2017 mantidproject
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import)
from mantidqt.utils.qt import import_qtlib
CodeEditor = import_qtlib('_widgetscore', 'mantidqt.widgets', 'ScriptEditor')
......@@ -8,6 +8,24 @@ using namespace MantidQt::MantidWidgets;
qRegisterMetaType<MantidQt::MantidWidgets::Message>();
%End
// ----------------------------------------------------------------------------
// Exceptions
// ----------------------------------------------------------------------------
%Exception std::invalid_argument(SIP_Exception) /PyName=ValueError/
{
%TypeHeaderCode
#include <stdexcept>
%End
%RaiseCode
const char *detail = sipExceptionRef.what();
SIP_BLOCK_THREADS
PyErr_SetString(PyExc_ValueError, detail);
SIP_UNBLOCK_THREADS
%End
};
// ----------------------------------------------------------------------------
// Classes
// ----------------------------------------------------------------------------
......@@ -36,3 +54,15 @@ public:
MessageDisplay(QWidget *parent = 0);
void attachLoggingChannel();
};
class ScriptEditor {
%TypeHeaderCode
#include "MantidQtWidgets/Common/ScriptEditor.h"
%End
public:
ScriptEditor(const QString & language,
QWidget *parent /TransferThis/ = 0) throw(std::invalid_argument);
private:
ScriptEditor(const ScriptEditor&);
};
# This file is part of the mantid workbench.
#
# Copyright (C) 2017 mantidproject
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, unicode_literals)
# system imports
import unittest
# third-party library imports
# local imports
from mantidqt.widgets.codeeditor import CodeEditor
from mantidqt.utils.qt.testing import requires_qapp
@requires_qapp
class CodeEditorTest(unittest.TestCase):
# Success tests
def test_construction_accepts_Python_as_language(self):
widget = CodeEditor("Python")
# Failure tests
def test_construction_raises_error_for_unknown_language(self):
# self.assertRaises causes a segfault here for some reason...
try:
CodeEditor("MyCoolLanguage")
except ValueError:
pass
except Exception as exc:
self.fail("Expected a Value error to be raised but found a " + exc.__name__)
if __name__ == '__main__':
unittest.main()
......@@ -37,15 +37,13 @@ namespace {
* Return a new instance of a lexer based on the given language
* @param language A string defining the language. Currently hardcoded to
* Python.
* @param editor The editor that the lexer will be installed on.
* @return A new QsciLexer instance
*/
QsciLexer *createLexerFromLanguage(const QString &language,
QsciScintilla *editor) {
QsciLexer *createLexerFromLanguage(const QString &language) {
if (language != "Python")
throw std::invalid_argument("createLexerFromLanguage: Unsupported "
"language. Supported languages=Python");
return new QsciLexerPython(editor);
return new QsciLexerPython;
}
}
......@@ -64,7 +62,7 @@ QColor ScriptEditor::g_error_colour = QColor("red");
* @param parent Parent widget
*/
ScriptEditor::ScriptEditor(const QString &language, QWidget *parent)
: ScriptEditor(parent, createLexerFromLanguage(language, this)) {}
: ScriptEditor(parent, createLexerFromLanguage(language)) {}
/**
* Constructor
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment