src
rqt_py_console
py_console_text_edit.py
Go to the documentation of this file.
1
# Software License Agreement (BSD License)
2
#
3
# Copyright (c) 2012, Dorian Scholz
4
# All rights reserved.
5
#
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions
8
# are met:
9
#
10
# * Redistributions of source code must retain the above copyright
11
# notice, this list of conditions and the following disclaimer.
12
# * Redistributions in binary form must reproduce the above
13
# copyright notice, this list of conditions and the following
14
# disclaimer in the documentation and/or other materials provided
15
# with the distribution.
16
# * Neither the name of Willow Garage, Inc. nor the names of its
17
# contributors may be used to endorse or promote products derived
18
# from this software without specific prior written permission.
19
#
20
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
# POSSIBILITY OF SUCH DAMAGE.
32
33
import
sys
34
from
code
import
InteractiveInterpreter
35
36
from
python_qt_binding
import
QT_BINDING, QT_BINDING_VERSION
37
from
python_qt_binding.QtCore
import
Qt, Signal
38
39
from
qt_gui_py_common.console_text_edit
import
ConsoleTextEdit
40
41
42
class
PyConsoleTextEdit
(
ConsoleTextEdit
):
43
_color_stdin = Qt.darkGreen
44
_multi_line_char =
':'
45
_multi_line_indent =
' '
46
_prompt = (
'>>> '
,
'... '
)
# prompt for single and multi line
47
exit = Signal()
48
49
def
__init__
(self, parent=None):
50
super(PyConsoleTextEdit, self).
__init__
(parent)
51
52
self.
_interpreter_locals
= {}
53
self.
_interpreter
= InteractiveInterpreter(self.
_interpreter_locals
)
54
55
self.
_comment_writer
.write(
'Python %s on %s\n'
%
56
(sys.version.replace(
'\n'
,
''
), sys.platform))
57
self.
_comment_writer
.write(
58
'Qt bindings: %s version %s\n'
% (QT_BINDING, QT_BINDING_VERSION))
59
60
self.
_add_prompt
()
61
62
def
update_interpreter_locals
(self, newLocals):
63
self.
_interpreter_locals
.update(newLocals)
64
65
def
_exec_code
(self, code):
66
try
:
67
self.
_interpreter
.runsource(code)
68
except
SystemExit:
# catch sys.exit() calls, so they don't close the whole gui
69
self.
exit
.emit()
qt_gui_py_common::console_text_edit::ConsoleTextEdit::_add_prompt
def _add_prompt(self)
qt_gui_py_common::console_text_edit
qt_gui_py_common::console_text_edit::ConsoleTextEdit::_comment_writer
_comment_writer
qt_gui_py_common::console_text_edit::ConsoleTextEdit
rqt_py_console.py_console_text_edit.PyConsoleTextEdit._interpreter
_interpreter
Definition:
py_console_text_edit.py:53
rqt_py_console.py_console_text_edit.PyConsoleTextEdit.__init__
def __init__(self, parent=None)
Definition:
py_console_text_edit.py:49
rqt_py_console.py_console_text_edit.PyConsoleTextEdit.exit
exit
Definition:
py_console_text_edit.py:47
rqt_py_console.py_console_text_edit.PyConsoleTextEdit.update_interpreter_locals
def update_interpreter_locals(self, newLocals)
Definition:
py_console_text_edit.py:62
rqt_py_console.py_console_text_edit.PyConsoleTextEdit
Definition:
py_console_text_edit.py:42
rqt_py_console.py_console_text_edit.PyConsoleTextEdit._exec_code
def _exec_code(self, code)
Definition:
py_console_text_edit.py:65
rqt_py_console.py_console_text_edit.PyConsoleTextEdit._interpreter_locals
_interpreter_locals
Definition:
py_console_text_edit.py:52
rqt_py_console
Author(s): Dorian Scholz
autogenerated on Sun Mar 5 2023 03:05:53