Change python scripting panel to allow multiple editor windows

* We also remove the old completion/help functionality as it will be replaced.
This commit is contained in:
baldurk committed 2026-08-13 17:46:43 +01:00
1 parent f5033de8ff
commit 2aff86b678
5 files changed
+488 -402

No files matched your search

+18 -11
View File
@@ -1223,13 +1223,19 @@ QWidget.
)");
virtual QWidget *Widget() = 0;
DOCUMENT(R"(Sets the current script in the python shell to the given string.
DOCUMENT(R"(Checks if there are unsaved changes to python scripts, and prompts the user about whether to
discard them or not.
:param str script: The text of the script to set.
If it is OK to close the window (either because there are no unsaved changes, they were saved after a prompt,
or the user chose to discard them then this function returns ``True``.
:return: Whether or not it is OK to close without losing changes.
:rtype: bool
)");
virtual void SetScriptText(rdcstr script) = 0;
virtual bool CheckUnsavedChanges() = 0;
DOCUMENT(R"(Sets the current script in the python shell to the contents of the given file.
DOCUMENT(R"(Loads the given file and creates a new tab with the script contents. No tab is
created if the file fails to load
:param str filename: The filename of the script to load.
:return: Whether or not the script was successfully loaded.
@@ -1237,7 +1243,14 @@ QWidget.
)");
virtual bool LoadScriptFromFilename(rdcstr filename) = 0;
DOCUMENT(R"(Returns the current script text.
DOCUMENT(R"(Creates a new script editor with a given name and text contents.
:param str name: The name to give the editor, does not have to be a filename.
:param str text: The contents to prefill in the script, can be blank.
)");
virtual void CreateNewScriptEditor(rdcstr name, rdcstr text) = 0;
DOCUMENT(R"(Returns the text of the currently focussed script editor.
:return: The current script text.
:rtype: str
@@ -1276,12 +1289,6 @@ This will show output from the running script, as well as any extensions that ar
)");
virtual void RemoveOutputFilter() = 0;
DOCUMENT(R"(Raises the script editor.
This will ensure the panel containing the script editor is visible.
)");
virtual void ShowScriptEditor() = 0;
DOCUMENT(R"(Raises the output panel.
This will ensure the panel showing the output from running python code is visible.
+11
View File
@@ -3195,6 +3195,17 @@ void MainWindow::closeEvent(QCloseEvent *event)
delete live;
}
if(m_Ctx.HasPythonShell())
{
IPythonShell *shell = m_Ctx.GetPythonShell();
if(!shell->CheckUnsavedChanges())
{
event->ignore();
return;
}
}
SaveLayout(0);
}
File diff suppressed because it is too large. Load diff
+36 -9
View File
@@ -26,10 +26,12 @@
#include <QFrame>
#include "Code/Interface/QRDInterface.h"
#include "scintilla/include/qt/ScintillaEdit.h"
class PythonContext;
class ScintillaEdit;
class QTextEdit;
class RDToolTip;
class QTimer;
namespace Ui
{
@@ -38,6 +40,21 @@ class PythonShell;
struct CaptureContextInvoker;
class PythonShell;
class EditorWrapper : public ScintillaEdit
{
Q_OBJECT
PythonShell *m_PyShell;
public:
EditorWrapper(PythonShell *parent);
public slots:
bool checkAllowClose();
};
class PythonShell : public QFrame, public IPythonShell
{
Q_OBJECT
@@ -54,8 +71,9 @@ public:
// IPythonShell
QWidget *Widget() override { return this; }
void SetScriptText(rdcstr script) override;
bool CheckUnsavedChanges() override;
bool LoadScriptFromFilename(rdcstr filename) override;
void CreateNewScriptEditor(rdcstr name, rdcstr text) override;
rdcstr GetScriptText() override;
void RunScript() override { runScript(false); }
void DebugScript() override { runScript(true); }
@@ -63,7 +81,6 @@ public:
void SetExtensionOutputFilter(const rdcstr &extensionName) override;
void SetScriptOutputFilter() override;
void RemoveOutputFilter() override;
void ShowScriptEditor() override;
void ShowOutput() override;
void ShowREPL() override;
void ShowHelp() override;
@@ -71,6 +88,9 @@ public:
QVariant persistData();
void setPersistData(const QVariant &persistData);
bool saveEditorAs(ScintillaEdit *editor);
bool saveEditor(ScintillaEdit *editor, QString filename);
private slots:
// automatic slots
void on_execute_clicked();
@@ -78,11 +98,15 @@ private slots:
void on_newScript_clicked();
void on_openScript_clicked();
void on_saveScript_clicked();
void on_saveAsScript_clicked();
void on_runScript_clicked();
void on_debugScript_clicked();
void on_abortRun_clicked();
void on_outputContext_currentIndexChanged(int idx);
bool checkAllowClose();
// manual slots
void interactive_keypress(QKeyEvent *e);
void helpSearch_keypress(QKeyEvent *e);
@@ -92,17 +116,18 @@ private slots:
void textOutput(const QString &extension, bool isStdError, const QString &output);
void extensionLoaded(const QString &extension);
void editor_contextMenu(const QPoint &pos);
void editorTab_Changed(int index);
private:
Ui::PythonShell *ui;
ICaptureContext &m_Ctx;
CaptureContextInvoker *m_ThreadCtx = NULL;
ScintillaEdit *scriptEditor;
ScintillaEdit *runningScriptEditor = NULL;
static const int CURRENT_MARKER = 0;
PythonContext *interactiveContext, *scriptContext;
PythonContext *interactiveContext = NULL, *scriptContext = NULL;
QList<QString> history;
int historyidx = -1;
@@ -119,17 +144,19 @@ private:
rdcarray<ScriptOutputLine> scriptOutputLines;
size_t lastDisplayedLine = 0;
QList<ScintillaEdit *> m_Scintillas;
ScintillaEdit *curEditor();
ScintillaEdit *makeEditor();
void updateEditorCloseButton();
void updateScriptOutput(bool fullRefresh);
QString getDottedWordAtPoint(int scintillaPos);
PythonContext *newContext();
PythonContext *newImportedDummyContext();
void setGlobals(PythonContext *ret);
void runScript(bool debugging);
void startAutocomplete();
void selectedHelp(QString word);
void refreshCurrentHelp();
+21 -1
View File
@@ -213,7 +213,27 @@
<item>
<widget class="QToolButton" name="saveScript">
<property name="toolTip">
<string>Save the current script to disk</string>
<string>Save the current script (Ctrl+S)</string>
</property>
<property name="text">
<string>Save</string>
</property>
<property name="icon">
<iconset resource="../Resources/resources.qrc">
<normaloff>:/save.png</normaloff>:/save.png</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="saveAsScript">
<property name="toolTip">
<string>Save the current script to a new location</string>
</property>
<property name="text">
<string>Save As</string>