-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_model.py
More file actions
27 lines (27 loc) · 928 Bytes
/
Copy pathtest_model.py
File metadata and controls
27 lines (27 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import sys
from PyQt6.QtGui import QStandardItemModel, QStandardItem
from PyQt6.QtCore import Qt
model = QStandardItemModel()
sec = QStandardItem('Proteins')
model.appendRow(sec)
prot = QStandardItem('1abc')
prot.setData('protein', Qt.ItemDataRole.UserRole + 1)
sec.appendRow(prot)
header = QStandardItem('Chains')
prot.appendRow(header)
chain = QStandardItem('A')
chain.setData('chain', Qt.ItemDataRole.UserRole + 1)
header.appendRow(chain)
res = QStandardItem('42 - GLY')
res.setData('residue', Qt.ItemDataRole.UserRole + 1)
chain.appendRow(res)
atom = QStandardItem('CA')
atom.setData('atom', Qt.ItemDataRole.UserRole + 1)
res.appendRow(atom)
def test(idx):
if idx.data(Qt.ItemDataRole.UserRole + 1) == 'atom':
r = idx.parent()
c = r.parent()
p = c.parent().parent()
return f'({p.data(Qt.ItemDataRole.DisplayRole)} and chain {c.data(Qt.ItemDataRole.DisplayRole)})'
print('Atom Result:', test(atom.index()))