Unverified Commit 8fbcb579 authored by Gagik Vardanyan's avatar Gagik Vardanyan Committed by GitHub
Browse files

Merge pull request #28786 from mantidproject/28253_add_python_extensions_setting

Add python extensions setting to workbench
parents 329a8ac7 520805fc
......@@ -22,6 +22,7 @@ Improvements
- Tile plots are now reloaded correctly by project recovery.
- When you stop a script running in workbench it will now automatically attempt to cancel the algorithm the script is running, rather than wait for the current algorthm to end.
This is similar to what Mantidplot does, and should result in the script stopping much sooner.
- The ``Python extensions directory`` setting from MantidPlot is now available in Workbench within the Manage User Directories window.
.. figure:: ../../images/wb_invalid_log_shading.png
:align: right
......
......@@ -29,7 +29,7 @@ private:
void loadProperties();
void saveProperties();
void appendSlashIfNone(QString &path) const;
QListWidget *listWidget();
QListWidget *listWidget(QObject *object);
private slots:
void helpClicked();
......
......@@ -48,7 +48,7 @@
<widget class="QLineEdit" name="leDirectoryPath"/>
</item>
<item>
<widget class="QPushButton" name="pbAddDirectory">
<widget class="QPushButton" name="pbDataAddDirectory">
<property name="text">
<string>Add Directory</string>
</property>
......@@ -64,28 +64,28 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="pbBrowseToDir">
<widget class="QPushButton" name="pbDataBrowseToDir">
<property name="text">
<string>Browse To Directory</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbRemDir">
<widget class="QPushButton" name="pbDataRemDir">
<property name="text">
<string>Remove Directory</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbMoveUp">
<widget class="QPushButton" name="pbDataMoveUp">
<property name="text">
<string>Move Up</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbMoveDown">
<widget class="QPushButton" name="pbDataMoveDown">
<property name="text">
<string>Move Down</string>
</property>
......@@ -175,7 +175,7 @@
<widget class="QLineEdit" name="leDirectoryPathPython"/>
</item>
<item>
<widget class="QPushButton" name="pbAddDirectoryPython">
<widget class="QPushButton" name="pbScriptAddDirectory">
<property name="text">
<string>Add Directory</string>
</property>
......@@ -186,33 +186,33 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QListWidget" name="lwUserSearchDirs"/>
<widget class="QListWidget" name="lwScriptSearchDirs"/>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QPushButton" name="pbBrowseToDirPython">
<widget class="QPushButton" name="pbScriptBrowseToDir">
<property name="text">
<string>Browse To Directory</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbRemDirPython">
<widget class="QPushButton" name="pbScriptRemDir">
<property name="text">
<string>Remove Directory</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbMoveUpPython">
<widget class="QPushButton" name="pbScriptMoveUp">
<property name="text">
<string>Move Up</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbMoveDownPython">
<widget class="QPushButton" name="pbScriptMoveDown">
<property name="text">
<string>Move Down</string>
</property>
......@@ -235,6 +235,63 @@
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="gbPythonExt">
<property name="title">
<string>Python Extensions (fit functions, algorithms)</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QListWidget" name="lwExtSearchDirs"/>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QPushButton" name="pbExtBrowseToDir">
<property name="text">
<string>Browse to Directory</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbExtRemoveDir">
<property name="text">
<string>Remove Directory</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbExtMoveUp">
<property name="text">
<string>Move Up</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbExtMoveDown">
<property name="text">
<string>Move Down</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
......
......@@ -16,7 +16,13 @@ using namespace MantidQt::API;
namespace {
std::unique_ptr<ManageUserDirectories> CURRENTLY_OPEN_MUD;
}
} // namespace
namespace ButtonPrefix {
const std::string DATA{"pbData"};
const std::string SCRIPT{"pbScript"};
const std::string EXTENSIONS{"pbExt"};
} // namespace ButtonPrefix
ManageUserDirectories::ManageUserDirectories(QWidget *parent)
: MantidDialog(parent) {
......@@ -35,20 +41,25 @@ void ManageUserDirectories::initLayout() {
connect(m_uiForm.pbCancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
connect(m_uiForm.pbConfirm, SIGNAL(clicked()), this, SLOT(confirmClicked()));
connect(m_uiForm.pbAddDirectory, SIGNAL(clicked()), this,
connect(m_uiForm.pbDataAddDirectory, SIGNAL(clicked()), this,
SLOT(addDirectory()));
connect(m_uiForm.pbAddDirectoryPython, SIGNAL(clicked()), this,
connect(m_uiForm.pbScriptAddDirectory, SIGNAL(clicked()), this,
SLOT(addDirectory()));
connect(m_uiForm.pbBrowseToDir, SIGNAL(clicked()), this,
connect(m_uiForm.pbDataBrowseToDir, SIGNAL(clicked()), this,
SLOT(browseToDirectory()));
connect(m_uiForm.pbBrowseToDirPython, SIGNAL(clicked()), this,
connect(m_uiForm.pbScriptBrowseToDir, SIGNAL(clicked()), this,
SLOT(browseToDirectory()));
connect(m_uiForm.pbRemDir, SIGNAL(clicked()), this, SLOT(remDir()));
connect(m_uiForm.pbRemDirPython, SIGNAL(clicked()), this, SLOT(remDir()));
connect(m_uiForm.pbMoveUp, SIGNAL(clicked()), this, SLOT(moveUp()));
connect(m_uiForm.pbMoveUpPython, SIGNAL(clicked()), this, SLOT(moveUp()));
connect(m_uiForm.pbMoveDown, SIGNAL(clicked()), this, SLOT(moveDown()));
connect(m_uiForm.pbMoveDownPython, SIGNAL(clicked()), this, SLOT(moveDown()));
connect(m_uiForm.pbExtBrowseToDir, SIGNAL(clicked()), this,
SLOT(browseToDirectory()));
connect(m_uiForm.pbDataRemDir, SIGNAL(clicked()), this, SLOT(remDir()));
connect(m_uiForm.pbScriptRemDir, SIGNAL(clicked()), this, SLOT(remDir()));
connect(m_uiForm.pbExtRemoveDir, SIGNAL(clicked()), this, SLOT(remDir()));
connect(m_uiForm.pbDataMoveUp, SIGNAL(clicked()), this, SLOT(moveUp()));
connect(m_uiForm.pbScriptMoveUp, SIGNAL(clicked()), this, SLOT(moveUp()));
connect(m_uiForm.pbExtMoveUp, SIGNAL(clicked()), this, SLOT(moveUp()));
connect(m_uiForm.pbDataMoveDown, SIGNAL(clicked()), this, SLOT(moveDown()));
connect(m_uiForm.pbScriptMoveDown, SIGNAL(clicked()), this, SLOT(moveDown()));
connect(m_uiForm.pbExtMoveDown, SIGNAL(clicked()), this, SLOT(moveDown()));
connect(m_uiForm.pbSaveBrowse, SIGNAL(clicked()), this,
SLOT(selectSaveDir()));
......@@ -75,8 +86,16 @@ void ManageUserDirectories::loadProperties() {
"pythonscripts.directories"))
.trimmed();
list = directories.split(";", QString::SkipEmptyParts);
m_uiForm.lwUserSearchDirs->clear();
m_uiForm.lwUserSearchDirs->addItems(list);
m_uiForm.lwScriptSearchDirs->clear();
m_uiForm.lwScriptSearchDirs->addItems(list);
directories = QString::fromStdString(
Mantid::Kernel::ConfigService::Instance().getString(
"user.python.plugins.directories"))
.trimmed();
list = directories.split(";", QString::SkipEmptyParts);
m_uiForm.lwExtSearchDirs->clear();
m_uiForm.lwExtSearchDirs->addItems(list);
// set flag of whether to search the data archive
QString archive = QString::fromStdString(
......@@ -130,6 +149,7 @@ void ManageUserDirectories::saveProperties() {
QStringList dataDirs;
QStringList userDirs;
QStringList extensionDirs;
for (int i = 0; i < m_uiForm.lwDataSearchDirs->count(); i++) {
QString dir = m_uiForm.lwDataSearchDirs->item(i)->text();
......@@ -137,21 +157,31 @@ void ManageUserDirectories::saveProperties() {
dataDirs.append(dir);
}
for (int i = 0; i < m_uiForm.lwUserSearchDirs->count(); i++) {
QString dir = m_uiForm.lwUserSearchDirs->item(i)->text();
for (int i = 0; i < m_uiForm.lwScriptSearchDirs->count(); i++) {
QString dir = m_uiForm.lwScriptSearchDirs->item(i)->text();
appendSlashIfNone(dir);
userDirs.append(dir);
}
for (int i = 0; i < m_uiForm.lwExtSearchDirs->count(); i++) {
QString dir = m_uiForm.lwExtSearchDirs->item(i)->text();
appendSlashIfNone(dir);
extensionDirs.append(dir);
}
QString newDataDirs;
QString newUserDirs;
QString newSaveDir;
QString newExtensionDirs;
newDataDirs = dataDirs.join(";");
newUserDirs = userDirs.join(";");
newDataDirs.replace('\\', '/');
newUserDirs.replace('\\', '/');
// Extensions dirs
newExtensionDirs = extensionDirs.join(";");
newExtensionDirs.replace('\\', '/');
newSaveDir = m_uiForm.leDefaultSave->text();
newSaveDir.replace('\\', '/');
appendSlashIfNone(newSaveDir);
......@@ -163,6 +193,8 @@ void ManageUserDirectories::saveProperties() {
config.setString("datasearch.directories", newDataDirs.toStdString());
config.setString("defaultsave.directory", newSaveDir.toStdString());
config.setString("pythonscripts.directories", newUserDirs.toStdString());
config.setString("user.python.plugins.directories",
newExtensionDirs.toStdString());
config.saveConfig(m_userPropFile.toStdString());
}
......@@ -181,12 +213,14 @@ void ManageUserDirectories::appendSlashIfNone(QString &path) const {
}
}
QListWidget *ManageUserDirectories::listWidget() {
if (m_uiForm.tabWidget->currentWidget() == m_uiForm.tabDataSearch) {
QListWidget *ManageUserDirectories::listWidget(QObject *sender) {
std::string objectName = sender->objectName().toStdString();
if (objectName.find(ButtonPrefix::DATA) != std::string::npos) {
return m_uiForm.lwDataSearchDirs;
} else if (m_uiForm.tabWidget->currentWidget() ==
m_uiForm.tabPythonDirectories) {
return m_uiForm.lwUserSearchDirs;
} else if (objectName.find(ButtonPrefix::SCRIPT) != std::string::npos) {
return m_uiForm.lwScriptSearchDirs;
} else if (objectName.find(ButtonPrefix::EXTENSIONS) != std::string::npos) {
return m_uiForm.lwExtSearchDirs;
} else {
return nullptr;
}
......@@ -213,7 +247,7 @@ void ManageUserDirectories::addDirectory() {
}
if (input && input->text() != "") {
listWidget()->addItem(input->text());
listWidget(sender())->addItem(input->text());
input->clear();
}
}
......@@ -229,17 +263,17 @@ void ManageUserDirectories::browseToDirectory() {
if (newDir != "") {
settings.setValue("ManageUserSettings/last_directory", newDir);
listWidget()->addItem(newDir);
listWidget(sender())->addItem(newDir);
}
}
void ManageUserDirectories::remDir() {
QList<QListWidgetItem *> selected = listWidget()->selectedItems();
QList<QListWidgetItem *> selected = listWidget(sender())->selectedItems();
for (auto &i : selected) {
delete i;
}
}
void ManageUserDirectories::moveUp() {
QListWidget *list = listWidget();
QListWidget *list = listWidget(sender());
QList<QListWidgetItem *> selected = list->selectedItems();
for (auto &i : selected) {
int index = list->row(i);
......@@ -251,7 +285,7 @@ void ManageUserDirectories::moveUp() {
}
}
void ManageUserDirectories::moveDown() {
QListWidget *list = listWidget();
QListWidget *list = listWidget(sender());
int count = list->count();
QList<QListWidgetItem *> selected = list->selectedItems();
for (auto &i : selected) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment