Newer
Older
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source
// & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
Gigg, Martyn Anthony
committed
#ifndef SCRIPTINGWINDOW_H_
#define SCRIPTINGWINDOW_H_
//----------------------------------
// Includes
//----------------------------------
#include "MantidQtWidgets/Common/IProjectSerialisable.h"
#include "Script.h"
#include <QMainWindow>
Gigg, Martyn Anthony
committed
//----------------------------------------------------------
// Forward declarations
//---------------------------------------------------------
class ScriptFileInterpreter;
class MultiTabScriptInterpreter;
Gigg, Martyn Anthony
committed
class ScriptingEnv;
class QTextEdit;
class QPoint;
class QMenu;
class QAction;
class QActionGroup;
Gigg, Martyn Anthony
committed
class QCloseEvent;
Gigg, Martyn Anthony
committed
class QShowEvent;
class QHideEvent;
Gigg, Martyn Anthony
committed
This class displays a separate window for editing and executing scripts
Gigg, Martyn Anthony
committed
*/
class ScriptingWindow : public QMainWindow {
Gigg, Martyn Anthony
committed
Q_OBJECT
public:
/// Constructor
ScriptingWindow(ScriptingEnv *env, bool capturePrint = true,
QWidget *parent = nullptr, Qt::WindowFlags flags = nullptr);
~ScriptingWindow() override;
Gigg, Martyn Anthony
committed
/// Override the closeEvent
void closeEvent(QCloseEvent *event) override;
Gigg, Martyn Anthony
committed
/// Override the showEvent
void showEvent(QShowEvent *event) override;
Gigg, Martyn Anthony
committed
/// Is a script running?
bool isExecuting() const;
/// Save the current state of the script window for next time
Gigg, Martyn Anthony
committed
void saveSettings();
/// Read settings from store
void readSettings();
/// Open a script in a new tab. Primarily useful for automatically
/// opening a script
void open(const QString &filename, bool newtab = true);
/// Executes whatever is in the current tab. Primarily useful for
/// automatically
/// running a script loaded with open
void executeCurrentTab(const Script::ExecutionMode mode);
/// Set whether to accept/reject close events
Gigg, Martyn Anthony
committed
void acceptCloseEvent(const bool value);
/// Opens a script providing a copy is not already open
void openUnique(QString filename);
/// Saves the open script names to the current project
std::string saveToProject(ApplicationWindow *app);
/// Loads the open script names for the current project
void loadFromProject(const std::string &lines, ApplicationWindow *app,
const int fileVersion);
// Loads the scripts from a list of filenames
void loadFromFileList(const QStringList &files);
/// Sets a flag which is set to true if synchronous execution fails
// We set a flag on failure to avoid problems with Async not returning success
bool getSynchronousErrorFlag() { return m_failureFlag; }
ScriptFileInterpreter *getCurrentScriptInterpreter();
Gigg, Martyn Anthony
committed
signals:
/// Show the scripting language dialog
void chooseScriptingLanguage();
Gigg, Martyn Anthony
committed
/// Tell others we are closing
void closeMe();
/// Tell others we are hiding
void hideMe();
Gigg, Martyn Anthony
committed
/// Accept a custom defined event
void customEvent(QEvent *event) override;
void dragEnterEvent(QDragEnterEvent *de) override;
void dragMoveEvent(QDragMoveEvent *de) override;
void dropEvent(QDropEvent *de) override;
Gigg, Martyn Anthony
committed
private slots:
/// Populate file menu
void populateFileMenu();
/// Ensure the list is up to date
void populateRecentScriptsMenu();
/// Populate edit menu
void populateEditMenu();
/// Populate execute menu
void populateExecMenu();
/// Populate window menu
void populateWindowMenu();
/// Populate help menu
void populateHelpMenu();
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
/// Update window flags
void updateWindowFlags();
/// Update menus based on current tab counts
void setMenuStates(int nTabs);
/// Sets the execution actions based on the flag
void setEditActionsDisabled(bool off);
/// Sets the execution actions based on the flag
void setExecutionActionsDisabled(bool off);
/// Sets the abort actions based on the flag or the environment
void setAbortActionsDisabled(bool off);
Gigg, Martyn Anthony
committed
/// Finds the script corresponding to the action and
/// asks the manager to open it
void openRecentScript(QAction *);
/// Execute all using the current mode option
void executeAll();
/// Execute selection using the current mode option
void executeSelection();
/// Abort the current script
void abortCurrent();
/// Clear out any previous variable definitions in the current script
void clearScriptVariables();
/// Opens help page for scripting window
void showHelp();
/// Opens help page for Python API
void showPythonHelp();
private:
/// Create menu bar
void initMenus();
/// Create all actions
void initActions();
/// Create the file actions
void initFileMenuActions();
/// Create the edit menu actions
void initEditMenuActions();
/// Create the execute menu actions
void initExecMenuActions();
/// Create the window menu actions
void initWindowMenuActions();
/// Create the help menu actions
void initHelpMenuActions();
/// Should we enable abort functionality
bool shouldEnableAbort() const;
/// Opens tabs based on QStringList
void openPreviousTabs(const QStringList &tabsToOpen);
/// Returns the current execution mode
Script::ExecutionMode getExecutionMode() const;
Gigg, Martyn Anthony
committed
private:
Gigg, Martyn Anthony
committed
/// The script editors' manager
MultiTabScriptInterpreter *m_manager;
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
/// File menu
QMenu *m_fileMenu;
/// File menu actions
QAction *m_newTab, *m_openInCurTab, *m_openInNewTab, *m_save, *m_saveAs,
*m_print, *m_closeTab;
QMenu *m_recentScripts;
Gigg, Martyn Anthony
committed
/// Edit menu
QMenu *m_editMenu;
/// Edit menu actions
QAction *m_undo, *m_redo, *m_cut, *m_copy, *m_paste, *m_comment, *m_uncomment,
*m_tabsToSpaces, *m_spacesToTabs, *m_find;
Gigg, Martyn Anthony
committed
/// Run menu
QMenu *m_runMenu;
/// Execute menu actions
QAction *m_execSelect, *m_execAll, *m_abortCurrent, *m_clearScriptVars;
/// Execution mode menu
QMenu *m_execModeMenu;
/// Execute mode actions
QAction *m_execParallel, *m_execSerial;
/// Action group for execution mode
QActionGroup *m_execModeGroup;
Gigg, Martyn Anthony
committed
/// Window menu
QMenu *m_windowMenu;
Gigg, Martyn Anthony
committed
/// Window actions
QAction *m_alwaysOnTop, *m_hide, *m_zoomIn, *m_zoomOut, *m_resetZoom,
*m_toggleProgress, *m_toggleFolding, *m_toggleWrapping,
*m_toggleWhitespace, *m_openConfigTabs, *m_selectFont;
/// Help menu
QMenu *m_helpMenu;
/// Help actions
QAction *m_showHelp, *m_showPythonHelp;
Gigg, Martyn Anthony
committed
/// Change scripting language
QAction *m_scripting_lang;
Gigg, Martyn Anthony
committed
/// Flag to define whether we should accept a close event
bool m_acceptClose;
Gigg, Martyn Anthony
committed
};