Commit 6079d0f6 authored by j_stru18's avatar j_stru18

add comments, use exec_ for qdialog and use remote adding method

parent 85e0237a
......@@ -1170,6 +1170,9 @@ class InputManager(QtWidgets.QWidget):
already imported, the entry with the old hashed ID is deleted and it is added with the new ID. If changes were
made and the modified file is a duplicate, then the user has the choice of either discarding all changes or
replacing the old duplicate with the modified file.
@author: j_stru18
@ensure: the database of this DatabaseWidget is remote
"""
def _editLocal(self):
path = self.getPath()
......@@ -1215,6 +1218,22 @@ class InputManager(QtWidgets.QWidget):
self.manager.deletebyID(oldID)
self.manager.addDBbyPathLocal(path)
"""
Method for editing files on remote hosts.
The user can edit the file using a file dialog. If the file was changed and is no duplicate of a file, that is
already imported, the entry with the old hashed ID is deleted and it is added with the new ID. If changes were
made and the modified file is a duplicate, then the user has the choice of either discarding all changes or
replacing the old duplicate with the modified file.
WARNING: until #401 is implemented, we have to hash the port of the remote host as well, to ensure that
duplicate files on different hosts can be added. This has to be changed afterwards.
TODO: when #449 was fully implemented with a TableEditor for remote files, this method has to be updated.
@author: j_stru18
@ensure: the database of this DatabaseWidget is remote
"""
def _editRemote(self):
hostName = self.remoteHost[0]
port = self.remoteHost[1]
......@@ -1239,7 +1258,7 @@ class InputManager(QtWidgets.QWidget):
else:
oldID = str(oldHashValue ^ portHash)
self._openFileRemote() # acutal file editing
self._openFileRemote() # actual file editing
newHashRet = sendMsgToHost(hostName, port, hashMsg) # hash file again for new ID
newHashValue = newHashRet["hashValue"]
if newHashValue != 0: # modified file is not empty
......@@ -1250,7 +1269,6 @@ class InputManager(QtWidgets.QWidget):
else:
newID = self.id
isFileDuplicate = self.manager.dbcontains(newID) # does a db with the same id exist?
if newID != oldID:
if isFileDuplicate: # new file is identical to another imported file
duplicatePath = self.manager.getPathByID(newID)
......@@ -1261,7 +1279,7 @@ class InputManager(QtWidgets.QWidget):
if ret == QtWidgets.QMessageBox.Apply: # remove both old databases and add modified new one
self.manager.deletebyID(newID)
self.manager.deletebyID(oldID)
self.manager.addDBbyPathLocal(path)
self.manager.addDBbyPathRemote(path, hostName, port)
assert self.manager.dbcontains(newID)
Log.log("Old HDF5TXT was removed and current file was modified.",
self.manager.getLogID())
......@@ -1271,7 +1289,7 @@ class InputManager(QtWidgets.QWidget):
Log.log("No changes to HDF5TXT files were made.", self.manager.getLogID())
else: # file changed, but is unique
self.manager.deletebyID(oldID)
self.manager.addDBbyPathLocal(path)
self.manager.addDBbyPathRemote(path, hostName, port)
def onRename(self):
......@@ -1364,12 +1382,12 @@ class InputManager(QtWidgets.QWidget):
if ret["status"]:
self.editor = EditorWidget(False, self.manager)
self.editor.setText(ret["file"])
self.editor.show()
self.editor.setWindowTitle(self.getPath())
self.editor.sgSave.connect(self._editorSave)
self.editor.sgClose.connect(self._editorClose)
return
QtWidgets.QMessageBox.critical(self, "Open File", "Failed to open remote file:\n" + self.getPath())
self.editor.exec_()
else:
QtWidgets.QMessageBox.critical(self, "Open File", "Failed to open remote file:\n" + self.getPath())
def _editorClose(self):
self.editor.sgSave.disconnect(self._editorSave)
......
......@@ -3,7 +3,6 @@ from PyQt5.QtWidgets import QDialog, QPushButton, QMessageBox, QAction, QGridLay
from gui.prototxt_editor import text_edit
class EditorWidget(QDialog):
'''This Editor enables text-based changes of Prototxt files. Connect to the sinal sgSave to get the savedata'''
......@@ -46,6 +45,7 @@ class EditorWidget(QDialog):
self.addAction(self.quitaction)
self.quitaction.triggered.connect(self._onClose)
sgSave = pyqtSignal(['QString'])
sgClose = pyqtSignal()
......
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