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 222 remove twice #238

Merged
merged 5 commits into from
Mar 25, 2024
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
46 changes: 31 additions & 15 deletions pasta_eln/GUI/configAuthors.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,24 @@ def __init__(self, comm:Communicate, callbackFinished:Callable[[bool],None]):
self.userFirst = self.addRowText('first','First name')
self.userLast = self.addRowText('last', 'Surname')
self.userEmail = self.addRowText('email','Email address')
#headline of organizations
orgaW, orgaL = widgetAndLayout('H', None, spacing='s', top='l')
self.orgaCB = QComboBox()
self.orgaCB.addItems([i['organization'] for i in self.author['organizations']])
orgaL.addStretch(1)
orgaL.addWidget(self.orgaCB)
orgaL.addWidget(self.orgaCB, stretch=2) # type: ignore[call-arg]
IconButton('fa5s.plus-circle', self, [Command.ADD], orgaL, 'Add organization')
IconButton('fa5s.minus-circle', self, [Command.DELETE], orgaL, 'Delete organization')
self.tabAuthorL.addRow(orgaW)

self.userRorid = self.addRowText('rorid','RORID')
self.userOrg = self.addRowText('organization','Organization')
buttonBarW, buttonBarL = widgetAndLayout('H', None, top='l')
buttonBarL.addStretch(1)
TextButton('Save changes', self, [Command.SAVE], buttonBarL)
self.tabAuthorL.addRow(buttonBarW)
self.orgaCB_lastIndex = 0
self.orgaCB.previousIndex = 0
self.lockSelfAuthor = False
self.orgaCB.currentIndexChanged.connect(lambda: self.execute([Command.CHANGE])) #connect to slot only after all painting is done


Expand All @@ -71,7 +74,7 @@ def addRowText(self, item:str, label:str) -> QLineEdit:
else:
rightW.setText(self.author[item])
rightW.setAccessibleName(item)
if item in {'rorid','orcid'}:
if item in {'organization', 'rorid','orcid'}:
rightW.editingFinished.connect(self.changedID)
self.tabAuthorL.addRow(QLabel(label), rightW)
return rightW
Expand All @@ -87,6 +90,7 @@ def changedID(self) -> None:
reply = requests.get(
f'https://api.ror.org/organizations/{self.userRorid.text().strip()}')
self.userOrg.setText(reply.json()['name'])
self.orgaCB.setItemText(self.orgaCB.currentIndex(), reply.json()['name'])
elif sender == 'orcid':
if re.match(r'^\w{4}-\w{4}-\w{4}-\w{4}$', self.userOrcid.text().strip() ) is not None:
reply = requests.get(
Expand All @@ -96,8 +100,10 @@ def changedID(self) -> None:
last = text.split('<personal-details:family-name>')[1].split('</personal-details:family-name>')[0]
self.userFirst.setText(first)
self.userLast.setText(last)
elif sender == 'organization':
self.orgaCB.setItemText(self.orgaCB.currentIndex(), self.userOrg.text())
else:
print('**ERROR: did not understand sender')
print('**ERROR: did not understand sender:',sender)
return


Expand All @@ -111,7 +117,7 @@ def execute(self, command:list[Any]) -> None:
self.author['title'] = self.userTitle.text().strip()
self.author['email'] = self.userEmail.text().strip()
self.author['orcid'] = self.userOrcid.text().strip()
j = self.orgaCB_lastIndex
j = self.orgaCB.currentIndex()
if j>-1:
self.author['organizations'][j]['organization'] = self.userOrg.text().strip()
self.author['organizations'][j]['rorid'] = self.userRorid.text().strip()
Expand All @@ -120,23 +126,33 @@ def execute(self, command:list[Any]) -> None:
fConf.write(json.dumps(self.comm.backend.configuration,indent=2))
self.callbackFinished(False)
elif command[0] is Command.ADD:
self.author['organizations'].append({'rorid':'', 'organization':''})
self.orgaCB.addItem('- new -')
if len(self.author['organizations'])<self.orgaCB.count():
self.author['organizations'].append({'rorid':'', 'organization':''})
self.orgaCB.setCurrentText('- new -')
self.userRorid.setEnabled(True)
self.userRorid.setText('')
self.userOrg.setEnabled(True)
self.userOrg.setText('')
elif command[0] is Command.DELETE:
k = self.orgaCB.currentIndex()
j = 0 if k>0 else -1
self.orgaCB.setCurrentIndex(j)
self.author['organizations'].pop(k)
self.orgaCB.removeItem(k)
elif command[0] is Command.CHANGE:
j = self.orgaCB_lastIndex
self.author['organizations'][j]['organization'] = self.userOrg.text().strip()
self.author['organizations'][j]['rorid'] = self.userRorid.text().strip()
if k>-1:
self.author['organizations'].pop(k)
self.lockSelfAuthor = True
self.orgaCB.removeItem(k)
if self.orgaCB.currentIndex()==-1:
self.userRorid.setEnabled(False)
self.userOrg.setEnabled(False)
self.lockSelfAuthor = False
elif command[0] is Command.CHANGE and self.author['organizations']:
j = self.orgaCB.previousIndex
if j<len(self.author['organizations']) and not self.lockSelfAuthor:
self.author['organizations'][j]['organization'] = self.userOrg.text().strip()
self.author['organizations'][j]['rorid'] = self.userRorid.text().strip()
k = self.orgaCB.currentIndex()
self.userRorid.setText(self.author['organizations'][k]['rorid'])
self.userOrg.setText(self.author['organizations'][k]['organization'])
self.orgaCB_lastIndex = k
self.orgaCB.previousIndex = self.orgaCB.currentIndex()
return


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
requires = ["setuptools >= 43.0.0", "wheel"]

[tool.codespell]
skip = '.git,*.pdf,*.svg,*lookup*.json'
skip = '.git,*.pdf,*.svg,*lookup*.json,*dataset-create-new-all-default-fields.json,*test_dataverse_edit_metadata_dialog.py'
# for shortcuts like [l]ist
ignore-regex = '\[[a-z]\][a-z]+'
#
Expand Down
Loading