Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sb less user interaction #177

Merged
merged 6 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions pasta_eln/GUI/configGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
from pathlib import Path
from typing import Callable, Any
from PySide6.QtWidgets import QWidget, QFormLayout # pylint: disable=no-name-in-module
from PySide6.QtWidgets import QWidget, QFormLayout, QVBoxLayout, QGroupBox, QLabel # pylint: disable=no-name-in-module
from ..miscTools import restart
from ..guiStyle import TextButton, addRowList
from ..guiCommunicate import Communicate
Expand All @@ -20,16 +20,18 @@ def __init__(self, comm:Communicate, callbackFinished:Callable[[],None]):
"""
super().__init__()
self.comm = comm

#GUI elements
if hasattr(self.comm.backend, 'configuration'):
onDisk = self.comm.backend.configuration['GUI']
self.mainL = QFormLayout(self)
for items in configurationGUI.values():
mainL = QVBoxLayout(self)
for label, items in configurationGUI.items():
groupbox = QGroupBox(label)
mainL.addWidget(groupbox)
sectionL = QFormLayout(groupbox)
for k,v in items.items():
setattr(self, k,
addRowList(self.mainL, label=v[0], default=str(onDisk[k]), itemList=[str(i) for i in v[2]]))
self.mainL.addRow('Save changes', TextButton('Save changes', self, [], None))
addRowList(sectionL, label=v[0], default=str(onDisk[k]), itemList=[str(i) for i in v[2]]))
mainL.addWidget(TextButton('Save changes', self, [], None))


def execute(self, _:list[Any]) -> None:
Expand Down
26 changes: 13 additions & 13 deletions pasta_eln/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,20 @@ def __init__(self, user:str, password:str, databaseName:str, configuration:dict[
if '-version' in self.dataHierarchy and self.dataHierarchy['-version'] < 4:
logging.info('Convert data hierarchy to V4.0')
dataHierarchy_pre_to_V4(self.dataHierarchy)
self.db['-dataHierarchy-'].delete()
if '-dataHierarchy-' in self.db:
self.db['-dataHierarchy-'].delete()
self.db.create_document(self.dataHierarchy)
if '-ontology-' in self.db:
self.db['-ontology-'].delete()
# temporary changes for version 2.5: remove afterwards: code does not harm but would be legacy then
testDocIDs = [doc['_id'] for doc in self.db if doc['_id'].startswith('x-')]
if testDocIDs and '-gui' not in self.db[testDocIDs[0]]:
for doc in self.db:
if doc['_id'].startswith('_') or doc['_id'].endswith('-'):
continue
if '-gui' not in doc:
doc['-gui'] = [True, True]
doc.save()
if '-version' not in self.dataHierarchy or self.dataHierarchy['-version']!=4:
print(F"**ERROR wrong dataHierarchy version: {self.dataHierarchy['-version']}")
raise ValueError(f"Wrong dataHierarchy version {self.dataHierarchy['-version']}")
Expand Down Expand Up @@ -804,9 +816,6 @@ def checkDB(self, outputStyle:str='text', repair:bool=False, minimal:bool=False)
outstring+= outputString(outputStyle,'h2','List all database entries')
if repair:
print('REPAIR MODE IS ON: afterwards, full-reload and create views')
## loop all documents
if repair and '-ontology-' in self.db:
self.db['-ontology-'].delete()
for doc in self.db:
try:
if '_design' in doc['_id']:
Expand Down Expand Up @@ -837,15 +846,6 @@ def checkDB(self, outputStyle:str='text', repair:bool=False, minimal:bool=False)
# doc['-branch'][0]['path'] = newPath
# doc.save()

# change database to version 4
if '-gui' not in doc:
outstring+= outputString(outputStyle,'error',f"dch00: gui does not exist {doc['_id']}")
if repair:
doc['-gui'] = [True, True]
doc.save()



#branch test
if '-branch' not in doc:
outstring+= outputString(outputStyle,'error',f"dch01: branch does not exist {doc['_id']}")
Expand Down
14 changes: 2 additions & 12 deletions pasta_eln/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def __init__(self) -> None:
helpMenu = menu.addMenu("&Help")
Action('&Website', self, [Command.WEBSITE], helpMenu)
Action('&Verify database', self, [Command.VERIFY_DB], helpMenu, shortcut='Ctrl+?')
Action('&Repair database', self, [Command.REPAIR_DB], helpMenu)
Action('Shortcuts', self, [Command.SHORTCUTS], helpMenu)
# shortcuts for advanced usage (user should not need)
QShortcut('F9', self, lambda: self.execute([Command.RESTART]))
Expand Down Expand Up @@ -197,14 +196,6 @@ def execute(self, command: list[Any]) -> None:
elif command[0] is Command.VERIFY_DB:
report = self.comm.backend.checkDB(outputStyle='html', minimal=True)
showMessage(self, 'Report of database verification', report, style='QLabel {min-width: 800px}')
elif command[0] is Command.REPAIR_DB:
ret = QMessageBox.critical(self, 'Warning', 'Are you sure you want to repair the database as it can destroy information?', \
QMessageBox.StandardButton.No | QMessageBox.StandardButton.Yes, # type: ignore[operator]
QMessageBox.StandardButton.No)
if ret==QMessageBox.StandardButton.Yes:
self.comm.backend.checkDB(outputStyle='html', minimal=True, repair=True)
showMessage(self, 'Report of database verification', 'Rerun verification to test success',
style='QLabel {min-width: 800px}')
elif command[0] is Command.SHORTCUTS:
showMessage(self, 'Keyboard shortcuts', shortcuts)

Expand Down Expand Up @@ -266,9 +257,8 @@ class Command(Enum):
CONFIG = 12
WEBSITE = 13
VERIFY_DB = 14
REPAIR_DB = 15
SHORTCUTS = 16
RESTART = 17
SHORTCUTS = 15
RESTART = 16


def startMain() -> None:
Expand Down
5 changes: 4 additions & 1 deletion pasta_eln/guiStyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def getColor(backend:Backend, color:str) -> str:
str: #123456 color code
"""
if not hasattr(backend, 'configuration') or backend.configuration['GUI']['theme']=='none':
return '#000000'
if color=='primary':
return '#000000'
else:
return '#BBBBBB'
themeName = backend.configuration['GUI']['theme']
return get_theme(f'{themeName}.xml')[f'{color}Color']

Expand Down
Loading