-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an interactive Python command console #145
Conversation
Add a dock widget at the bottom of the main window that a horizontally split text edit areas. The upper and larger one is for displaying the history of the input Python commands. The lower and narrow one is to input a Python command for execution. The command line supports history navigation through up and down arrow keys on the keyboard, and uses enter for sending the command for execution. It does not yet support multi-line Python code. Improvements that are needed in the future: * The output from Python goes to the process stdout and stderr that are not redirected to the Qt widget. It should be in the future. * The Python code dock widget on the right-hand side of the main window will be kept for a while before all the apps are migrated to use the new Python command console.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tigercosmos It happens that I am working on a feature similar to your #144. But in #144 there is not history navigation. I think we can take both PRs after reviewing both.
@@ -40,6 +40,10 @@ void RMainWindow::setUp() | |||
m_pytext->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); | |||
addDockWidget(Qt::RightDockWidgetArea, m_pytext); | |||
|
|||
m_pycon = new RPythonConsoleDockWidget(QString("Console"), this); | |||
m_pycon->setAllowedAreas(Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow the console to be at the bottom or the top. Having it in the left or right could make it too narrow.
interp.exec_code(code); | ||
} | ||
|
||
void RPythonConsoleDockWidget::navigateCommand(int offset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Navigate through the history. Slight complexity.
m_command_string = m_command_edit->toPlainText().toStdString(); | ||
} | ||
|
||
int new_index = m_current_command_index + offset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Limit the range of new_index
.
new_index = 0; | ||
} | ||
|
||
if ((0 == m_past_command_strings.size()) || (new_index == m_current_command_index)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's nothing in the history or the new index does not change, do nothing.
} | ||
// Move cursor to the end of line. | ||
{ | ||
QTextCursor cursor = m_command_edit->textCursor(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
textCursor()
returns a copy.
:ivar locals: | ||
The local namespace of the application. | ||
""" | ||
def __init__(self, name): | ||
self.globals = {} | ||
self.locals = { | ||
self.globals = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to have the symbols to appear in the "module global".
@tigercosmos I am checking it in for discussions in the sprint later this afternoon. We can still discuss in this PR. |
def exec_code(code): | ||
try: | ||
apputil.run_code(code) | ||
except Exception as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't work well I think.
for example, I enter print(a)
(with undefined a
) in the console, it will just crash.
You tagged another one but not me. Hope he/she does not mind :)
Yes. But in general, the buffered output of the Python interpreter should be redirected. We do not need to limit it to the
And we should find an apparent way to distinguish the command from the output. |
For #104
Add a dock widget at the bottom of the main window that a horizontally split text edit areas. The upper and larger one is for displaying the history of the input Python commands. The lower and narrow one is to input a Python command for execution.
The command line supports history navigation through up and down arrow keys on the keyboard, and uses enter for sending the command for execution. It does not yet support multi-line Python code.
Improvements that are needed in the future: