Skip to content

Commit a96872c

Browse files
Fixes for DomainTableModel (#159)
* Fixing a couple of problems with the domain table selection * Avoid np.int in color options display --------- Co-authored-by: Paul Romano <[email protected]>
1 parent b5a1fd9 commit a96872c

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

openmc_plotter/plotmodel.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,12 @@ def __deepcopy__(self, memo):
11761176
obj.defaults = self.defaults
11771177
return obj
11781178

1179+
def get_defaults(self, key: int) -> DomainView:
1180+
return self.defaults[key]
1181+
1182+
def get_default_color(self, key: int):
1183+
return self.get_defaults(key).color
1184+
11791185
def set_name(self, key: int, name: Optional[str]):
11801186
domain = self[key]
11811187
self[key] = DomainView(domain.id, name, domain.color, domain.masked, domain.highlight)
@@ -1265,7 +1271,8 @@ def data(self, index, role=Qt.DisplayRole):
12651271
elif column == COLOR:
12661272
return '' if domain.color is not None else '+'
12671273
elif column == COLORLABEL:
1268-
return str(tuple(domain.color)) if domain.color is not None else '--'
1274+
return (str(tuple(int(x) for x in domain.color))
1275+
if domain.color is not None else '--')
12691276
elif column == MASK:
12701277
return None
12711278
elif column == HIGHLIGHT:
@@ -1343,10 +1350,11 @@ def setData(self, index, value, role=Qt.EditRole):
13431350

13441351
if column == NAME:
13451352
self.domains.set_name(key, value if value else None)
1346-
elif column == COLOR:
1347-
self.domains.set_color(key, value)
1348-
elif column == COLORLABEL:
1349-
self.domains.set_color(key, value)
1353+
elif column == COLOR or column == COLORLABEL:
1354+
# reset the color to the default value if the coloar value is None
1355+
if value is None:
1356+
value = self.domains.get_default_color(key)
1357+
self.domains.set_color(key, value)
13501358
elif column == MASK:
13511359
if role == Qt.CheckStateRole:
13521360
self.domains.set_masked(key, Qt.CheckState(value) == Qt.Checked)
@@ -1402,7 +1410,7 @@ def setEditorData(self, editor, index):
14021410
def editorEvent(self, event, model, option, index):
14031411

14041412
if index.column() in (COLOR, COLORLABEL):
1405-
if not int(index.flags() & Qt.ItemIsEditable) > 0:
1413+
if (index.flags() & Qt.ItemFlag.ItemIsEditable) == Qt.ItemFlag.NoItemFlags:
14061414
return False
14071415
if event.type() == QEvent.MouseButtonRelease \
14081416
and event.button() == Qt.RightButton:

0 commit comments

Comments
 (0)