Skip to content

Commit

Permalink
Merge pull request #377 from qipe-nlab/tag-complete
Browse files Browse the repository at this point in the history
Feature for monitr: show whether a measurement is complete or was interrupted
  • Loading branch information
marcosfrenkel committed Feb 20, 2023
2 parents 0835387 + 4069ecf commit a877d5c
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 3 deletions.
70 changes: 67 additions & 3 deletions plottr/apps/monitr.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from ..apps.watchdog_classes import WatcherClient
from ..gui.widgets import Collapsible
from .json_viewer import JsonModel, JsonTreeView
from ..icons import get_starIcon as get_star_icon, get_trashIcon as get_trash_icon, get_imageIcon as get_img_icon, get_jsonIcon as get_json_icon, get_mdIcon as get_md_icon
from ..icons import get_starIcon as get_star_icon, get_trashIcon as get_trash_icon, get_completeIcon as get_complete_icon, get_interruptedIcon as get_interrupted_icon, get_imageIcon as get_img_icon, get_jsonIcon as get_json_icon, get_mdIcon as get_md_icon
from .appmanager import AppManager

TIMESTRFORMAT = "%Y-%m-%dT%H%M%S"
Expand Down Expand Up @@ -172,11 +172,14 @@ def __init__(self, path: Path, files: Dict[Path, ContentType] = {}):
self.tags_widget = ItemTagLabel(self.tags)
self.star = False
self.trash = False
self.complete = False
self.interrupted = False
self.scroll_height = 0
self.show = True
if files is not None:
self.files.update(files)
self.tags = [file.stem for file, file_type in self.files.items() if file_type == ContentType.tag]

if '__star__' in self.tags and '__trash__' in self.tags:
star_path = self.path.joinpath('__star__.tag')
trash_path = self.path.joinpath('__trash__.tag')
Expand All @@ -193,6 +196,24 @@ def __init__(self, path: Path, files: Dict[Path, ContentType] = {}):
elif '__trash__' in self.tags:
self.trash = True
self.tags.remove('__trash__')

if '__complete__' in self.tags and '__interrupted__' in self.tags:
complete_path = self.path.joinpath('__complete__.tag')
interrupted_path = self.path.joinpath('__interrupted__.tag')
if complete_path.is_file() and interrupted_path.is_file():
LOGGER.error(
f'The folder: {self.path} contains both the complete and interrupted tag. Both tags will be deleted.')
complete_path.unlink()
interrupted_path.unlink()
self.tags.remove('__complete__')
self.tags.remove('__interrupted__')
elif '__complete__' in self.tags:
self.complete = True
self.tags.remove('__complete__')
elif '__interrupted__' in self.tags:
self.interrupted = True
self.tags.remove('__interrupted__')

self.tags_widget = ItemTagLabel(self.tags)

self.setText(str(self.path.name))
Expand All @@ -219,7 +240,7 @@ def add_file(self, path: Path) -> None:
error_msg = QtWidgets.QMessageBox()
error_msg.setText(f'Folder is already trash. Please do not add both __trash__ and __star__ tags in the same folder. '
f' \n {path} was deleted ')
error_msg.setWindowTitle(f'Deleting __trash__.tag')
error_msg.setWindowTitle(f'Deleting __star__.tag')
error_msg.exec_()
return
else:
Expand All @@ -234,11 +255,42 @@ def add_file(self, path: Path) -> None:
error_msg.setText(
f'Folder is already star. Please do not add both __trash__ and __star__ tags in the same folder. '
f' \n {path} was deleted ')
error_msg.setWindowTitle(f'Deleting __star__.tag')
error_msg.setWindowTitle(f'Deleting __trash__.tag')
error_msg.exec_()
return
else:
self.trash = True

elif path.name == '__complete__.tag':
# Check if the item is already tagged as interrupted.
interrupted_path = path.parent.joinpath('__interrupted__.tag')
if interrupted_path.is_file():
path.unlink()
error_msg = QtWidgets.QMessageBox()
error_msg.setText(
f'Folder is already tagged as interrupted. Please do not add both __complete__ and __interrupted__ tags in the same folder.\n'
f'{path} was deleted.')
error_msg.setWindowTitle(f'Deleting __complete__.tag')
error_msg.exec_()
return
else:
self.complete = True

elif path.name == '__interrupted__.tag':
# Check if the item is already tagged as complete.
complete_path = path.parent.joinpath('__complete__.tag')
if complete_path.is_file():
path.unlink()
error_msg = QtWidgets.QMessageBox()
error_msg.setText(
f'Folder is already tagged as complete. Please do not add both __complete__ and __interrupted__ tags in the same folder.\n'
f'{path} was deleted.')
error_msg.setWindowTitle(f'Deleting __interrupted__.tag')
error_msg.exec_()
return
else:
self.interrupted = True

else:
self.tags.append(path.stem)
self.tags_widget.add_tag(path.stem)
Expand Down Expand Up @@ -268,6 +320,10 @@ def delete_file(self, path: Path) -> None:
self.star = False
elif path.name == '__trash__.tag':
self.trash = False
elif path.name == '__complete__.tag':
self.complete = False
elif path.name == '__interrupted__.tag':
self.interrupted = False

model.item_files_changed(self)

Expand Down Expand Up @@ -500,6 +556,10 @@ def sort_and_add_item(self, folder_path: Path, files_dict: Optional[Dict] = None
item.setIcon(get_star_icon())
elif item.trash:
item.setIcon(get_trash_icon())
elif item.complete:
item.setIcon(get_complete_icon())
elif item.interrupted:
item.setIcon(get_interrupted_icon())
else:
item.setIcon(QtGui.QIcon())

Expand Down Expand Up @@ -895,6 +955,10 @@ def item_files_changed(self, item: Item) -> None:
item.setIcon(get_star_icon())
elif item.trash:
item.setIcon(get_trash_icon())
elif item.complete:
item.setIcon(get_complete_icon())
elif item.interrupted:
item.setIcon(get_interrupted_icon())
else:
item.setIcon(QtGui.QIcon())

Expand Down
6 changes: 6 additions & 0 deletions plottr/data/datadict_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,12 @@ def __exit__(self,
assert self.filepath is not None
with FileOpener(self.filepath, 'a', timeout=self.file_timeout) as f:
add_cur_time_attr(f[self.groupname], name='close')
if exc_type is None:
# exiting because the measurement is complete
self.add_tag('__complete__')
else:
# exiting because of an exception
self.add_tag('__interrupted__')

def data_folder(self) -> Path:
"""Return the folder, relative to the data root path, in which data will
Expand Down
17 changes: 17 additions & 0 deletions plottr/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ def get_starIcon() -> QtGui.QIcon:
return starIcon


def get_completeIcon() -> QtGui.QIcon:
"""
Icon taken from: https://glyphs.fyi/
"""
completeIcon = QtGui.QIcon(
os.path.join(gfxPath, "complete.svg")
)
return completeIcon


def get_interruptedIcon() -> QtGui.QIcon:
interruptedIcon = QtGui.QIcon(
os.path.join(gfxPath, "interrupted.svg")
)
return interruptedIcon


def get_imageIcon() -> QtGui.QIcon:
"""
Icon taken from: https://www.svgrepo.com/collection/file-type-collection/
Expand Down
3 changes: 3 additions & 0 deletions plottr/resource/gfx/complete.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions plottr/resource/gfx/interrupted.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a877d5c

Please sign in to comment.