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

merge #5

Merged
merged 3 commits into from
Feb 21, 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
4 changes: 2 additions & 2 deletions commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def runTests():
for fileI in os.listdir('pasta_eln/Tests'):
if not fileI.endswith('.py'):
continue
result = subprocess.run(['python3','-m','pasta_eln.Tests.'+fileI], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
result = subprocess.run(['python3','-m','pasta_eln.Tests.'+fileI[:-3]], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
success = result.stdout.decode('utf-8').count('*** DONE WITH VERIFY ***')
if success==1:
success += result.stdout.decode('utf-8').count('**ERROR')
Expand All @@ -99,7 +99,7 @@ def runTests():
else:
successAll = False
print(" FAILED: Python unit test "+fileI)
print(" run: 'python3 Tests/"+fileI+"' and check logFile")
print(" run: 'python3 -m pasta_eln.Tests."+fileI[:-3]+"' and check logFile")
return


Expand Down
File renamed without changes.
26 changes: 24 additions & 2 deletions pasta_eln/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from .miscTools import upIn, upOut, createDirName, generic_hash, camelCase
from .handleDictionaries import ontology2Labels, fillDocBeforeCreate

#TODO_P5 App freezes on loadKey
#TODO_P5 unprocessed files should be have separate docType
#TODO_P5 rerun extractors as batch

class Backend(CLI_Mixin):
"""
PYTHON BACKEND
Expand Down Expand Up @@ -287,6 +291,21 @@ def scanTree(self, **kwargs):
startPath = Path(self.cwd)
#prepare lists and start iterating
inDB_all = self.db.getView('viewHierarchy/viewPaths')
#update content between DB and harddisk
for line in inDB_all:
if line['value'][1][0][0]=='x':
continue
doc = self.db.getDoc(line['id'])
if 'content' in doc:
path = self.basePath/line['key']
doc= {'-type':['procedure']}
self.useExtractors(path, '', doc)
self.db.updateDoc(doc, line['id'])
#TODO_P5: Basic functionality for V1
#V1: GUI content write-protected; assume one link and no conflicts
#V2: What happens if you change a file (procedure) on disk / database -> conflicts
# Copy of procedure exists on harddisk: one entry in db and links; then change one, but not other, -branch should separate; can they reunite?

pathsInDB_x = [i['key'] for i in inDB_all if i['value'][1][0][0]=='x'] #all structure elements: task, subtasts
pathsInDB_data = [i['key'] for i in inDB_all if i['value'][1][0][0]!='x']
for root, dirs, files in os.walk(self.cwd, topdown=True):
Expand All @@ -307,7 +326,7 @@ def scanTree(self, **kwargs):
if path in pathsInDB_x: #path already in database
pathsInDB_x.remove(path)
continue
_ = self.addData('x'+str(len(hierStack)), {'-name':dirName}, hierStack)
self.addData('x'+str(len(hierStack)), {'-name':dirName}, hierStack)
newDir = Path(self.basePath)/self.db.getDoc(self.currentID)['-branch'][0]['path']
(newDir/'.id_pastaELN.json').rename(Path(self.basePath)/root/dirName/'.id_pastaELN.json') #move index file into old folder
newDir.rmdir() #remove created path
Expand Down Expand Up @@ -339,7 +358,10 @@ def scanTree(self, **kwargs):
change = {'-branch': {'op':'d', 'oldpath':branch['path'], 'path':branch['path'], \
'stack':branch['stack'] }}
break
self.db.updateDoc(change, docID)
if change is None:
print('**ERROR Tried to remove orphan in database but could not', orphan)
else:
self.db.updateDoc(change, docID)
if rerunScanTree:
self.scanTree()
return
Expand Down
2 changes: 1 addition & 1 deletion pasta_eln/dialogConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Configuration(QDialog):
""" Main class of entire config dialog """
def __init__(self, backend, startTap):
def __init__(self, backend, startTap=''):
"""
Initialization

Expand Down
2 changes: 0 additions & 2 deletions pasta_eln/dialogConfigGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def __init__(self, backend, callbackFinished):
self.wD = self.addRowList('imageWidthDetails','Image width in details view', ['500','600','700','800'])
self.wS = self.addRowList('sidebarWidth','Sidebar width', ['200','300','400'])
self.log = self.addRowList('loggingLevel','Logging level (more->less)', ['DEBUG','INFO','WARNING','ERROR'])
self.nTC = self.addRowList('tableColumnsMax','Maximum number of table columns', ['8','16','32'])
self.tabAppearanceL.addRow(TextButton('Save changes', self.saveData, None),
TextButton('Restart PASTA-ELN', restart, None))

Expand Down Expand Up @@ -82,7 +81,6 @@ def saveData(self):
self.backend.configuration['GUI']['imageWidthDetails'] = int(self.wD.currentText())
self.backend.configuration['GUI']['sidebarWidth'] = int(self.wS.currentText())
self.backend.configuration['GUI']['loggingLevel'] = self.log.currentText()
self.backend.configuration['GUI']['tableColumnsMax'] = int(self.nTC.currentText())
with open(Path.home()/'.pastaELN.json', 'w', encoding='utf-8') as fConf:
fConf.write(json.dumps(self.backend.configuration,indent=2))
restart()
Expand Down
18 changes: 15 additions & 3 deletions pasta_eln/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .widgetSidebar import Sidebar
from .widgetBody import Body
from .dialogForm import Form
from .dialogConfig import Configuration
os.environ['QT_API'] = 'pyside6'

# Subclass QMainWindow to customize your application's main window
Expand All @@ -28,10 +29,13 @@ def __init__(self):

#Menubar
menu = self.menuBar()
_ = menu.addMenu("&File")
menu.addMenu("&File")
viewMenu = menu.addMenu("&View list")
_ = menu.addMenu("&System")
_ = menu.addMenu("&Help")
systemMenu = menu.addMenu("&System")
action = QAction('&Configuration',self)
action.triggered.connect(self.openConfigDialog)
systemMenu.addAction(action)
menu.addMenu("&Help")

shortCuts = {'measurement':'m', 'sample':'s'}
for docType, docLabel in self.comm.backend.db.dataLabels.items():
Expand Down Expand Up @@ -78,6 +82,14 @@ def viewMenu(self):
self.comm.changeTable.emit(docType, '')
return

def openConfigDialog(self):
"""
open configuration dialog
"""
configWindow = Configuration(self.comm.backend)
configWindow.exec()
return


##############
## Main function
Expand Down
32 changes: 29 additions & 3 deletions pasta_eln/widgetDetails.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
""" widget that shows the details of the items """
import json
from PySide6.QtWidgets import QScrollArea, QWidget, QVBoxLayout, QHBoxLayout, QLabel # pylint: disable=no-name-in-module
from PySide6.QtWidgets import QScrollArea, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QMenu # pylint: disable=no-name-in-module
from PySide6.QtCore import Qt, Slot, QByteArray # pylint: disable=no-name-in-module
from PySide6.QtSvgWidgets import QSvgWidget # pylint: disable=no-name-in-module
from PySide6.QtGui import QPixmap, QImage # pylint: disable=no-name-in-module
from PySide6.QtGui import QPixmap, QImage, QAction# pylint: disable=no-name-in-module
from .style import TextButton, Image, Label

class Details(QScrollArea):
Expand All @@ -26,8 +26,9 @@ def __init__(self, comm):
self.headerL = QHBoxLayout(headerW)
self.mainL.addWidget(headerW)
self.imageW = QWidget()
self.imageW.setContextMenuPolicy(Qt.CustomContextMenu)
self.imageW.customContextMenuRequested.connect(self.contextMenu)
self.imageL = QVBoxLayout(self.imageW)
#TODO_P2 include extractor change
self.mainL.addWidget(self.imageW)
self.btnDetails = TextButton('Details', self.showArea, self.mainL, 'Details', 'Show / hide details', \
checkable=True, hide=True)
Expand All @@ -51,6 +52,31 @@ def __init__(self, comm):
self.mainL.addWidget(self.metaDatabaseW)
self.mainL.addStretch(1)

def contextMenu(self, pos):
"""
Create a context menu

Args:
pos (position): Position to create context menu at
"""
context = QMenu(self)
mask = '/'.join(self.doc['-type'][:3])
choices= {key:value for key,value in self.comm.backend.configuration['extractors'].items() if key.startswith(mask)}
for key,value in choices.items():
thisAction = QAction(value, self)
thisAction.setData(key)
thisAction.triggered.connect(self.changeExtractor)
context.addAction(thisAction)
context.exec(self.mapToGlobal(pos))
return

def changeExtractor(self):
"""
What happens when user changes extractor
"""
extractor = self.sender().data()
print(extractor)
return

@Slot(str)
def changeDetails(self, docID):
Expand Down