Commit 0acb6ee26a18750c897bbc4d091260a4c2395b07

Authored by okahilak
Committed by GitHub
1 parent 43f8fe6e
Exists in master

Change column order in marker panel (#395)

* Change column order in marker panel

- Show most relevant information (id, session, label, target) in the
  first columns, and the coordinates only in the latter columns.

- Adjust the column sizes to give more horizontal space to the label.

- Round the coordinates to one decimal place instead of two.

- Minor clean-up.

* Fix debug option in Session object

- Before, debug option was updated when --debug flag was set
  but not when unset.

- Also, debug option was updated too late to be available when
  the __init__ functions in the UI were called.

* Show coordinate columns in marker list only when in --debug mode
app.py
... ... @@ -347,12 +347,6 @@ def parse_command_line():
347 347  
348 348  
349 349 def use_cmd_optargs(options, args):
350   - # If debug argument...
351   - if options.debug:
352   - Publisher.subscribe(print_events, Publisher.ALL_TOPICS)
353   - session = ses.Session()
354   - session.debug = 1
355   -
356 350 # If import DICOM argument...
357 351 if options.dicom_dir:
358 352 import_dir = options.dicom_dir
... ... @@ -495,6 +489,12 @@ def main():
495 489 """
496 490 options, args = parse_command_line()
497 491  
  492 + session = ses.Session()
  493 + session.debug = options.debug
  494 +
  495 + if options.debug:
  496 + Publisher.subscribe(print_events, Publisher.ALL_TOPICS)
  497 +
498 498 if options.remote_host is not None:
499 499 from invesalius.net.remote_control import RemoteControl
500 500  
... ...
invesalius/constants.py
... ... @@ -655,6 +655,18 @@ BOOLEAN_DIFF = 2
655 655 BOOLEAN_AND = 3
656 656 BOOLEAN_XOR = 4
657 657  
  658 +# -------------- User interface ---------------------
  659 +
  660 +# The column order in the marker panel
  661 +#
  662 +ID_COLUMN = 0
  663 +SESSION_COLUMN = 1
  664 +LABEL_COLUMN = 2
  665 +TARGET_COLUMN = 3
  666 +X_COLUMN = 4
  667 +Y_COLUMN = 5
  668 +Z_COLUMN = 6
  669 +
658 670 #------------ Navigation defaults -------------------
659 671  
660 672 MARKER_COLOUR = (1.0, 1.0, 0.)
... ...
invesalius/gui/task_navigator.py
... ... @@ -53,6 +53,7 @@ import invesalius.data.record_coords as rec
53 53 import invesalius.data.vtk_utils as vtk_utils
54 54 import invesalius.gui.dialogs as dlg
55 55 import invesalius.project as prj
  56 +import invesalius.session as ses
56 57 from invesalius import utils
57 58 from invesalius.gui import utils as gui_utils
58 59 from invesalius.navigation.icp import ICP
... ... @@ -1212,6 +1213,8 @@ class MarkersPanel(wx.Panel):
1212 1213  
1213 1214 self.__bind_events()
1214 1215  
  1216 + self.session = ses.Session()
  1217 +
1215 1218 self.current_coord = 0, 0, 0, 0, 0, 0
1216 1219 self.current_angle = 0, 0, 0
1217 1220 self.current_seed = 0, 0, 0
... ... @@ -1269,21 +1272,27 @@ class MarkersPanel(wx.Panel):
1269 1272  
1270 1273 # List of markers
1271 1274 self.lc = wx.ListCtrl(self, -1, style=wx.LC_REPORT, size=wx.Size(0,120))
1272   - self.lc.InsertColumn(0, '#')
1273   - self.lc.InsertColumn(1, 'X')
1274   - self.lc.InsertColumn(2, 'Y')
1275   - self.lc.InsertColumn(3, 'Z')
1276   - self.lc.InsertColumn(4, 'Label')
1277   - self.lc.InsertColumn(5, 'Target')
1278   - self.lc.InsertColumn(6, 'Session')
1279   -
1280   - self.lc.SetColumnWidth(0, 28)
1281   - self.lc.SetColumnWidth(1, 50)
1282   - self.lc.SetColumnWidth(2, 50)
1283   - self.lc.SetColumnWidth(3, 50)
1284   - self.lc.SetColumnWidth(4, 60)
1285   - self.lc.SetColumnWidth(5, 60)
1286   - self.lc.SetColumnWidth(5, 50)
  1275 + self.lc.InsertColumn(const.ID_COLUMN, '#')
  1276 + self.lc.SetColumnWidth(const.ID_COLUMN, 28)
  1277 +
  1278 + self.lc.InsertColumn(const.SESSION_COLUMN, 'Session')
  1279 + self.lc.SetColumnWidth(const.SESSION_COLUMN, 52)
  1280 +
  1281 + self.lc.InsertColumn(const.LABEL_COLUMN, 'Label')
  1282 + self.lc.SetColumnWidth(const.LABEL_COLUMN, 118)
  1283 +
  1284 + self.lc.InsertColumn(const.TARGET_COLUMN, 'Target')
  1285 + self.lc.SetColumnWidth(const.TARGET_COLUMN, 45)
  1286 +
  1287 + if self.session.debug:
  1288 + self.lc.InsertColumn(const.X_COLUMN, 'X')
  1289 + self.lc.SetColumnWidth(const.X_COLUMN, 45)
  1290 +
  1291 + self.lc.InsertColumn(const.Y_COLUMN, 'Y')
  1292 + self.lc.SetColumnWidth(const.Y_COLUMN, 45)
  1293 +
  1294 + self.lc.InsertColumn(const.Z_COLUMN, 'Z')
  1295 + self.lc.SetColumnWidth(const.Z_COLUMN, 45)
1287 1296  
1288 1297 self.lc.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.OnMouseRightDown)
1289 1298 self.lc.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemBlink)
... ... @@ -1301,7 +1310,6 @@ class MarkersPanel(wx.Panel):
1301 1310 self.Update()
1302 1311  
1303 1312 def __bind_events(self):
1304   - # Publisher.subscribe(self.UpdateCurrentCoord, 'Co-registered points')
1305 1313 Publisher.subscribe(self.UpdateCurrentCoord, 'Set cross focal point')
1306 1314 Publisher.subscribe(self.OnDeleteMultipleMarkers, 'Delete fiducial marker')
1307 1315 Publisher.subscribe(self.OnDeleteAllMarkers, 'Delete all markers')
... ... @@ -1311,13 +1319,15 @@ class MarkersPanel(wx.Panel):
1311 1319 Publisher.subscribe(self.OnChangeCurrentSession, 'Current session changed')
1312 1320  
1313 1321 def __find_target_marker(self):
1314   - """Return the index of the marker currently selected as target (there
1315   - should be at most one). If there is no such marker, return -1."""
  1322 + """
  1323 + Return the index of the marker currently selected as target (there
  1324 + should be at most one). If there is no such marker, return None.
  1325 + """
1316 1326 for i in range(len(self.markers)):
1317 1327 if self.markers[i].is_target:
1318 1328 return i
1319 1329  
1320   - return -1
  1330 + return None
1321 1331  
1322 1332 def __get_selected_items(self):
1323 1333 """
... ... @@ -1327,25 +1337,28 @@ class MarkersPanel(wx.Panel):
1327 1337  
1328 1338 next = self.lc.GetFirstSelected()
1329 1339  
1330   - while next != -1:
  1340 + while next is not None:
1331 1341 selection.append(next)
1332 1342 next = self.lc.GetNextSelected(next)
1333 1343  
1334 1344 return selection
1335 1345  
1336 1346 def __delete_multiple_markers(self, index):
1337   - """ Delete multiple markers indexed by index. index must be sorted in
  1347 + """
  1348 + Delete multiple markers indexed by index. index must be sorted in
1338 1349 the ascending order.
1339 1350 """
1340 1351 for i in reversed(index):
1341 1352 del self.markers[i]
1342 1353 self.lc.DeleteItem(i)
1343 1354 for n in range(0, self.lc.GetItemCount()):
1344   - self.lc.SetItem(n, 0, str(n+1))
  1355 + self.lc.SetItem(n, 0, str(n + 1))
1345 1356 Publisher.sendMessage('Remove multiple markers', index=index)
1346 1357  
1347 1358 def __set_marker_as_target(self, idx):
1348   - """Set marker indexed by idx as the new target. idx must be a valid index."""
  1359 + """
  1360 + Set marker indexed by idx as the new target. idx must be a valid index.
  1361 + """
1349 1362 # Find the previous target
1350 1363 prev_idx = self.__find_target_marker()
1351 1364  
... ... @@ -1354,16 +1367,16 @@ class MarkersPanel(wx.Panel):
1354 1367 return
1355 1368  
1356 1369 # Unset the previous target
1357   - if prev_idx != -1:
  1370 + if prev_idx is not None:
1358 1371 self.markers[prev_idx].is_target = False
1359 1372 self.lc.SetItemBackgroundColour(prev_idx, 'white')
1360 1373 Publisher.sendMessage('Set target transparency', status=False, index=prev_idx)
1361   - self.lc.SetItem(prev_idx, 5, "")
  1374 + self.lc.SetItem(prev_idx, const.TARGET_COLUMN, "")
1362 1375  
1363 1376 # Set the new target
1364 1377 self.markers[idx].is_target = True
1365 1378 self.lc.SetItemBackgroundColour(idx, 'RED')
1366   - self.lc.SetItem(idx, 5, _("Yes"))
  1379 + self.lc.SetItem(idx, const.TARGET_COLUMN, _("Yes"))
1367 1380  
1368 1381 Publisher.sendMessage('Update target', coord=self.markers[idx].coord)
1369 1382 Publisher.sendMessage('Set target transparency', status=True, index=idx)
... ... @@ -1416,9 +1429,9 @@ class MarkersPanel(wx.Panel):
1416 1429 def OnMenuEditMarkerLabel(self, evt):
1417 1430 list_index = self.lc.GetFocusedItem()
1418 1431 if list_index != -1:
1419   - new_label = dlg.ShowEnterMarkerID(self.lc.GetItemText(list_index, 4))
  1432 + new_label = dlg.ShowEnterMarkerID(self.lc.GetItemText(list_index, const.LABEL_COLUMN))
1420 1433 self.markers[list_index].label = str(new_label)
1421   - self.lc.SetItem(list_index, 4, new_label)
  1434 + self.lc.SetItem(list_index, const.LABEL_COLUMN, new_label)
1422 1435 else:
1423 1436 wx.MessageBox(_("No data selected."), _("InVesalius 3"))
1424 1437  
... ... @@ -1445,20 +1458,17 @@ class MarkersPanel(wx.Panel):
1445 1458 # XXX: Seems like a slightly too early point for rounding; better to round only when the value
1446 1459 # is printed to the screen or file.
1447 1460 #
1448   - self.markers[index].colour = [round(s/255.0, 3) for s in color_new]
  1461 + self.markers[index].colour = [round(s / 255.0, 3) for s in color_new]
1449 1462  
1450 1463 Publisher.sendMessage('Set new color', index=index, color=color_new)
1451 1464  
1452 1465 def OnDeleteAllMarkers(self, evt=None):
1453   - if evt is None:
1454   - result = wx.ID_OK
1455   - else:
  1466 + if evt is not None:
1456 1467 result = dlg.ShowConfirmationDialog(msg=_("Remove all markers? Cannot be undone."))
  1468 + if result != wx.ID_OK:
  1469 + return
1457 1470  
1458   - if result != wx.ID_OK:
1459   - return
1460   -
1461   - if self.__find_target_marker() != -1:
  1471 + if self.__find_target_marker() is not None:
1462 1472 Publisher.sendMessage('Disable or enable coil tracker', status=False)
1463 1473 if evt is not None:
1464 1474 wx.MessageBox(_("Target deleted."), _("InVesalius 3"))
... ... @@ -1472,17 +1482,19 @@ class MarkersPanel(wx.Panel):
1472 1482 # OnDeleteMultipleMarkers is used for both pubsub and button click events
1473 1483 # Pubsub is used for fiducial handle and button click for all others
1474 1484  
1475   - if not evt: # called through pubsub
  1485 + # called through pubsub
  1486 + if not evt:
1476 1487 index = []
1477 1488  
1478 1489 if label and (label in self.__list_fiducial_labels()):
1479 1490 for id_n in range(self.lc.GetItemCount()):
1480   - item = self.lc.GetItem(id_n, 4)
  1491 + item = self.lc.GetItem(id_n, const.LABEL_COLUMN)
1481 1492 if item.GetText() == label:
1482 1493 self.lc.Focus(item.GetId())
1483 1494 index = [self.lc.GetFocusedItem()]
1484 1495  
1485   - else: # called from button click
  1496 + # called from button click
  1497 + else:
1486 1498 index = self.__get_selected_items()
1487 1499  
1488 1500 if index:
... ... @@ -1532,13 +1544,12 @@ class MarkersPanel(wx.Panel):
1532 1544 # If the new marker has is_target=True, we first create
1533 1545 # a marker with is_target=False, and then call __set_marker_as_target
1534 1546 if marker.is_target:
1535   - self.__set_marker_as_target(len(self.markers)-1)
  1547 + self.__set_marker_as_target(len(self.markers) - 1)
1536 1548  
1537 1549 except:
1538 1550 wx.MessageBox(_("Invalid markers file."), _("InVesalius 3"))
1539 1551  
1540 1552 def OnMarkersVisibility(self, evt, ctrl):
1541   -
1542 1553 if ctrl.GetValue():
1543 1554 Publisher.sendMessage('Hide all markers', indexes=self.lc.GetItemCount())
1544 1555 ctrl.SetLabel('Show')
... ... @@ -1573,8 +1584,8 @@ class MarkersPanel(wx.Panel):
1573 1584 wx.MessageBox(_("Error writing markers file."), _("InVesalius 3"))
1574 1585  
1575 1586 def OnSelectColour(self, evt, ctrl):
1576   - #TODO: Make sure GetValue returns 3 numbers (without alpha)
1577   - self.marker_colour = [colour/255.0 for colour in ctrl.GetValue()][:3]
  1587 + # TODO: Make sure GetValue returns 3 numbers (without alpha)
  1588 + self.marker_colour = [colour / 255.0 for colour in ctrl.GetValue()][:3]
1578 1589  
1579 1590 def OnSelectSize(self, evt, ctrl):
1580 1591 self.marker_size = ctrl.GetValue()
... ... @@ -1602,11 +1613,14 @@ class MarkersPanel(wx.Panel):
1602 1613 # Add item to list control in panel
1603 1614 num_items = self.lc.GetItemCount()
1604 1615 self.lc.InsertItem(num_items, str(num_items + 1))
1605   - self.lc.SetItem(num_items, 1, str(round(new_marker.x, 2)))
1606   - self.lc.SetItem(num_items, 2, str(round(new_marker.y, 2)))
1607   - self.lc.SetItem(num_items, 3, str(round(new_marker.z, 2)))
1608   - self.lc.SetItem(num_items, 4, new_marker.label)
1609   - self.lc.SetItem(num_items, 6, str(new_marker.session_id))
  1616 + self.lc.SetItem(num_items, const.SESSION_COLUMN, str(new_marker.session_id))
  1617 + self.lc.SetItem(num_items, const.LABEL_COLUMN, new_marker.label)
  1618 +
  1619 + if self.session.debug:
  1620 + self.lc.SetItem(num_items, const.X_COLUMN, str(round(new_marker.x, 1)))
  1621 + self.lc.SetItem(num_items, const.Y_COLUMN, str(round(new_marker.y, 1)))
  1622 + self.lc.SetItem(num_items, const.Z_COLUMN, str(round(new_marker.z, 1)))
  1623 +
1610 1624 self.lc.EnsureVisible(num_items)
1611 1625  
1612 1626 class DbsPanel(wx.Panel):
... ...