Skip to content

Commit

Permalink
135 rename (#194)
Browse files Browse the repository at this point in the history
* Setup of rename/move

* Small bugfix

* importlib.resources.files

* Lift synchronise button up

* Ruff

* Ruff format

* Pylint

---------

Co-authored-by: Staiger, Christine <christine.staiger@wur.nl>
  • Loading branch information
chStaiger and Staiger, Christine authored Jun 6, 2024
1 parent 5740e8d commit 5653084
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 32 deletions.
19 changes: 16 additions & 3 deletions ibridgesgui/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
populate_table,
populate_textfield,
)
from ibridgesgui.popup_widgets import CreateCollection
from ibridgesgui.popup_widgets import CreateCollection, Rename
from ibridgesgui.ui_files.tabBrowser import Ui_tabBrowser


Expand All @@ -44,7 +44,6 @@ def __init__(self, session, app_name):
if self.session.home is not None:
root_path = IrodsPath(self.session).absolute()
else:

root_path = IrodsPath(
self.session, f"/{self.session.zone}/home/{self.session.username}"
)
Expand Down Expand Up @@ -76,6 +75,7 @@ def browse(self):
self.upload_dir_button.clicked.connect(self.folder_upload)
self.download_button.clicked.connect(self.download)
self.create_coll_button.clicked.connect(self.create_collection)
self.rename_button.clicked.connect(self.rename_item)

# Browser table behaviour
self.browser_table.doubleClicked.connect(self.update_path)
Expand Down Expand Up @@ -105,7 +105,6 @@ def set_parent(self):
self.path_input.setText(str(current_path.parent))
self.load_browser_table()

# @PyQt6.QtCore.pyqtSlot(PyQt6.QtCore.QModelIndex)
def update_path(self, index):
"""Take path from path_input and loads browser table."""
self.error_label.clear()
Expand All @@ -123,6 +122,20 @@ def create_collection(self):
coll_widget.exec()
self.load_browser_table()

def rename_item(self):
"""Rename/move a collection or data object."""
self.error_label.clear()
if self.browser_table.currentRow() == -1:
self.error_label.setText("Please select a row from the table first!")
return
item_name = self.browser_table.item(self.browser_table.currentRow(), 1).text()
irods_path = IrodsPath(self.session, "/" + self.path_input.text().strip("/")).joinpath(
item_name
)
rename_widget = Rename(irods_path, self.logger)
rename_widget.exec()
self.load_browser_table()

def folder_upload(self):
"""Select a folder and upload."""
self.error_label.clear()
Expand Down
1 change: 1 addition & 0 deletions ibridgesgui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def _get_config() -> Union[None, dict]:

# irods config functions


def is_session_from_config(session: Session) -> Union[Session, None]:
"""Create a new session from the given session.
Expand Down
7 changes: 6 additions & 1 deletion ibridgesgui/gui_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Handy and reusable functions for the GUI."""

import pathlib
from importlib.resources import files
from typing import Union

import irods
Expand All @@ -10,6 +9,12 @@

from ibridgesgui.config import get_last_ienv_path, is_session_from_config

try:
from importlib.resources import files
except ImportError:
from importlib_resources import files


UI_FILE_DIR = files(__package__) / "ui_files"


Expand Down
38 changes: 38 additions & 0 deletions ibridgesgui/popup_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ibridgesgui.gui_utils import UI_FILE_DIR, populate_textfield
from ibridgesgui.ui_files.configCheck import Ui_configCheck
from ibridgesgui.ui_files.createCollection import Ui_createCollection
from ibridgesgui.ui_files.renameItem import Ui_renameItem


class CreateCollection(QDialog, Ui_createCollection):
Expand Down Expand Up @@ -85,6 +86,43 @@ def accept(self):
self.error_label.setText("ERROR: insufficient rights.")


class Rename(QDialog, Ui_renameItem):
"""Popup window to rename and move a collection or data object."""

def __init__(self, irods_path: IrodsPath, logger):
"""Initialise window."""
super().__init__()
if getattr(sys, "frozen", False):
super().setupUi(self)
else:
loadUi(UI_FILE_DIR / "renameItem.ui", self)

self.logger = logger
self.setWindowTitle("Create iRODS collection")
self.setWindowFlags(QtCore.Qt.WindowType.WindowStaysOnTopHint)
self.irods_path = irods_path
self.item_path_label.setText(str(irods_path))
self.item_path_input.setText(str(irods_path))
self.buttonBox.accepted.connect(self.accept)

def accept(self):
"""Create new collection."""
if self.item_path_input.text() != "":
new_path = IrodsPath(self.irods_path.session, self.item_path_input.text())
if new_path.exists():
self.error_label.setText(f"{new_path} already exists.")
else:
try:
new_irods_path = self.irods_path.rename(new_path)
self.logger.info(f"Rename/Move {self.irods_path} --> {new_irods_path}")
self.done(0)
except irods.exception.CAT_NO_ACCESS_PERMISSION:
self.error_label.setText(f"No access rights to {new_path}.")
except Exception as err:
self.logger.exception(f"Could not create {new_path}: {err}")
self.error_label.setText(f"Could not create {new_path}, consult the logs.")


class CheckConfig(QDialog, Ui_configCheck):
"""Popup window to edit, create and check an environment.json."""

Expand Down
48 changes: 28 additions & 20 deletions ibridgesgui/ui_files/MainMenu.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Form implementation generated from reading ui file 'ibridgesgui/ui_files/MainMenu.ui'
#
# Created by: PyQt6 UI code generator 6.6.1
# Created by: PyQt6 UI code generator 6.4.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.
Expand All @@ -14,57 +14,65 @@ def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1300, 850)
MainWindow.setMinimumSize(QtCore.QSize(1300, 850))
MainWindow.setStyleSheet(
"QWidget\n"
"{\n"
" color: rgb(86, 184, 139);\n"
" background-color: rgb(54, 54, 54);\n"
" selection-background-color: rgb(58, 152, 112);\n"
" font: 16pt;\n"
"}\n"
"\n"
"QTabBar::tab:top:selected {\n"
" background-color: rgb(58, 152, 112);\n"
" color: rgb(54, 54, 54);\n"
"}\n"
""
)
MainWindow.setStyleSheet("QWidget\n"
"{\n"
" color: rgb(86, 184, 139);\n"
" background-color: rgb(54, 54, 54);\n"
" selection-background-color: rgb(58, 152, 112);\n"
" font: 16pt;\n"
"}\n"
"\n"
"QTabBar::tab:top:selected {\n"
" background-color: rgb(58, 152, 112);\n"
" color: rgb(54, 54, 54);\n"
"}\n"
"\n"
"QLabel#error_label\n"
"{\n"
" color: rgb(217, 174, 23);\n"
" font: 18pt;\n"
"}\n"
"")
self.centralwidget = QtWidgets.QWidget(parent=MainWindow)
self.centralwidget.setStyleSheet("")
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.tab_widget = QtWidgets.QTabWidget(parent=self.centralwidget)
self.tab_widget.setMinimumSize(QtCore.QSize(600, 300))
self.tab_widget.setMinimumSize(QtCore.QSize(600, 500))
font = QtGui.QFont()
font.setPointSize(16)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
self.tab_widget.setFont(font)
self.tab_widget.setObjectName("tab_widget")
self.verticalLayout.addWidget(self.tab_widget)
self.error_label = QtWidgets.QLabel(parent=self.centralwidget)
self.error_label.setText("")
self.error_label.setObjectName("error_label")
self.verticalLayout.addWidget(self.error_label)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(parent=MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1300, 24))
font = QtGui.QFont()
font.setPointSize(16)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
self.menubar.setFont(font)
self.menubar.setObjectName("menubar")
self.main_menu = QtWidgets.QMenu(parent=self.menubar)
font = QtGui.QFont()
font.setPointSize(16)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
self.main_menu.setFont(font)
self.main_menu.setObjectName("main_menu")
self.config_menu = QtWidgets.QMenu(parent=self.menubar)
self.config_menu.setObjectName("config_menu")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(parent=MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.action_close_session = QtGui.QAction(parent=MainWindow)
font = QtGui.QFont()
self.action_close_session.setFont(font)
Expand Down
5 changes: 4 additions & 1 deletion ibridgesgui/ui_files/MainMenu.ui
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ QLabel#error_label
<property name="minimumSize">
<size>
<width>600</width>
<height>300</height>
<height>500</height>
</size>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
Expand Down Expand Up @@ -86,6 +87,7 @@ QLabel#error_label
<property name="font">
<font>
<pointsize>16</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
Expand All @@ -94,6 +96,7 @@ QLabel#error_label
<property name="font">
<font>
<pointsize>16</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
Expand Down
77 changes: 77 additions & 0 deletions ibridgesgui/ui_files/renameItem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Form implementation generated from reading ui file 'ibridgesgui/ui_files/renameItem.ui'
#
# Created by: PyQt6 UI code generator 6.4.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.


from PyQt6 import QtCore, QtGui, QtWidgets


class Ui_renameItem(object):
def setupUi(self, renameItem):
createCollection.setObjectName("createCollection")
createCollection.resize(500, 200)
createCollection.setMinimumSize(QtCore.QSize(500, 200))
createCollection.setMaximumSize(QtCore.QSize(500, 200))
createCollection.setStyleSheet("QWidget\n"
"{\n"
" color: rgb(86, 184, 139);\n"
" background-color: rgb(54, 54, 54);\n"
" font: 16pt\n"
"}\n"
"\n"
"QLineEdit\n"
"{\n"
" background-color: rgb(85, 87, 83);\n"
" border-color: rgb(217, 174, 23)\n"
"}\n"
"\n"
"QLabel#error_label\n"
"{\n"
" color: rgb(217, 174, 23);\n"
"}\n"
"\n"
"")
self.verticalLayout = QtWidgets.QVBoxLayout(createCollection)
self.verticalLayout.setObjectName("verticalLayout")
self.label = QtWidgets.QLabel(parent=createCollection)
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.item_path_label = QtWidgets.QLabel(parent=createCollection)
self.item_path_label.setText("")
self.item_path_label.setObjectName("item_path_label")
self.horizontalLayout.addWidget(self.item_path_label)
self.verticalLayout.addLayout(self.horizontalLayout)
self.label_2 = QtWidgets.QLabel(parent=createCollection)
self.label_2.setObjectName("label_2")
self.verticalLayout.addWidget(self.label_2)
self.item_path_input = QtWidgets.QLineEdit(parent=createCollection)
self.item_path_input.setObjectName("item_path_input")
self.verticalLayout.addWidget(self.item_path_input)
self.error_label = QtWidgets.QLabel(parent=createCollection)
self.error_label.setStyleSheet("")
self.error_label.setText("")
self.error_label.setObjectName("error_label")
self.verticalLayout.addWidget(self.error_label)
spacerItem = QtWidgets.QSpacerItem(20, 10, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Minimum)
self.verticalLayout.addItem(spacerItem)
self.buttonBox = QtWidgets.QDialogButtonBox(parent=createCollection)
self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok)
self.buttonBox.setObjectName("buttonBox")
self.verticalLayout.addWidget(self.buttonBox)

self.retranslateUi(createCollection)
self.buttonBox.accepted.connect(createCollection.accept) # type: ignore
self.buttonBox.rejected.connect(createCollection.reject) # type: ignore
QtCore.QMetaObject.connectSlotsByName(createCollection)

def retranslateUi(self, createCollection):
_translate = QtCore.QCoreApplication.translate
createCollection.setWindowTitle(_translate("createCollection", "Rename/Move"))
self.label.setText(_translate("createCollection", "Rename or move:"))
self.label_2.setText(_translate("createCollection", "to new location:"))
Loading

0 comments on commit 5653084

Please sign in to comment.