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
@@ -347,12 +347,6 @@ def parse_command_line(): @@ -347,12 +347,6 @@ def parse_command_line():
347 347
348 348
349 def use_cmd_optargs(options, args): 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 # If import DICOM argument... 350 # If import DICOM argument...
357 if options.dicom_dir: 351 if options.dicom_dir:
358 import_dir = options.dicom_dir 352 import_dir = options.dicom_dir
@@ -495,6 +489,12 @@ def main(): @@ -495,6 +489,12 @@ def main():
495 """ 489 """
496 options, args = parse_command_line() 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 if options.remote_host is not None: 498 if options.remote_host is not None:
499 from invesalius.net.remote_control import RemoteControl 499 from invesalius.net.remote_control import RemoteControl
500 500
invesalius/constants.py
@@ -655,6 +655,18 @@ BOOLEAN_DIFF = 2 @@ -655,6 +655,18 @@ BOOLEAN_DIFF = 2
655 BOOLEAN_AND = 3 655 BOOLEAN_AND = 3
656 BOOLEAN_XOR = 4 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 #------------ Navigation defaults ------------------- 670 #------------ Navigation defaults -------------------
659 671
660 MARKER_COLOUR = (1.0, 1.0, 0.) 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,6 +53,7 @@ import invesalius.data.record_coords as rec
53 import invesalius.data.vtk_utils as vtk_utils 53 import invesalius.data.vtk_utils as vtk_utils
54 import invesalius.gui.dialogs as dlg 54 import invesalius.gui.dialogs as dlg
55 import invesalius.project as prj 55 import invesalius.project as prj
  56 +import invesalius.session as ses
56 from invesalius import utils 57 from invesalius import utils
57 from invesalius.gui import utils as gui_utils 58 from invesalius.gui import utils as gui_utils
58 from invesalius.navigation.icp import ICP 59 from invesalius.navigation.icp import ICP
@@ -1212,6 +1213,8 @@ class MarkersPanel(wx.Panel): @@ -1212,6 +1213,8 @@ class MarkersPanel(wx.Panel):
1212 1213
1213 self.__bind_events() 1214 self.__bind_events()
1214 1215
  1216 + self.session = ses.Session()
  1217 +
1215 self.current_coord = 0, 0, 0, 0, 0, 0 1218 self.current_coord = 0, 0, 0, 0, 0, 0
1216 self.current_angle = 0, 0, 0 1219 self.current_angle = 0, 0, 0
1217 self.current_seed = 0, 0, 0 1220 self.current_seed = 0, 0, 0
@@ -1269,21 +1272,27 @@ class MarkersPanel(wx.Panel): @@ -1269,21 +1272,27 @@ class MarkersPanel(wx.Panel):
1269 1272
1270 # List of markers 1273 # List of markers
1271 self.lc = wx.ListCtrl(self, -1, style=wx.LC_REPORT, size=wx.Size(0,120)) 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 self.lc.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.OnMouseRightDown) 1297 self.lc.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.OnMouseRightDown)
1289 self.lc.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemBlink) 1298 self.lc.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemBlink)
@@ -1301,7 +1310,6 @@ class MarkersPanel(wx.Panel): @@ -1301,7 +1310,6 @@ class MarkersPanel(wx.Panel):
1301 self.Update() 1310 self.Update()
1302 1311
1303 def __bind_events(self): 1312 def __bind_events(self):
1304 - # Publisher.subscribe(self.UpdateCurrentCoord, 'Co-registered points')  
1305 Publisher.subscribe(self.UpdateCurrentCoord, 'Set cross focal point') 1313 Publisher.subscribe(self.UpdateCurrentCoord, 'Set cross focal point')
1306 Publisher.subscribe(self.OnDeleteMultipleMarkers, 'Delete fiducial marker') 1314 Publisher.subscribe(self.OnDeleteMultipleMarkers, 'Delete fiducial marker')
1307 Publisher.subscribe(self.OnDeleteAllMarkers, 'Delete all markers') 1315 Publisher.subscribe(self.OnDeleteAllMarkers, 'Delete all markers')
@@ -1311,13 +1319,15 @@ class MarkersPanel(wx.Panel): @@ -1311,13 +1319,15 @@ class MarkersPanel(wx.Panel):
1311 Publisher.subscribe(self.OnChangeCurrentSession, 'Current session changed') 1319 Publisher.subscribe(self.OnChangeCurrentSession, 'Current session changed')
1312 1320
1313 def __find_target_marker(self): 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 for i in range(len(self.markers)): 1326 for i in range(len(self.markers)):
1317 if self.markers[i].is_target: 1327 if self.markers[i].is_target:
1318 return i 1328 return i
1319 1329
1320 - return -1 1330 + return None
1321 1331
1322 def __get_selected_items(self): 1332 def __get_selected_items(self):
1323 """ 1333 """
@@ -1327,25 +1337,28 @@ class MarkersPanel(wx.Panel): @@ -1327,25 +1337,28 @@ class MarkersPanel(wx.Panel):
1327 1337
1328 next = self.lc.GetFirstSelected() 1338 next = self.lc.GetFirstSelected()
1329 1339
1330 - while next != -1: 1340 + while next is not None:
1331 selection.append(next) 1341 selection.append(next)
1332 next = self.lc.GetNextSelected(next) 1342 next = self.lc.GetNextSelected(next)
1333 1343
1334 return selection 1344 return selection
1335 1345
1336 def __delete_multiple_markers(self, index): 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 the ascending order. 1349 the ascending order.
1339 """ 1350 """
1340 for i in reversed(index): 1351 for i in reversed(index):
1341 del self.markers[i] 1352 del self.markers[i]
1342 self.lc.DeleteItem(i) 1353 self.lc.DeleteItem(i)
1343 for n in range(0, self.lc.GetItemCount()): 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 Publisher.sendMessage('Remove multiple markers', index=index) 1356 Publisher.sendMessage('Remove multiple markers', index=index)
1346 1357
1347 def __set_marker_as_target(self, idx): 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 # Find the previous target 1362 # Find the previous target
1350 prev_idx = self.__find_target_marker() 1363 prev_idx = self.__find_target_marker()
1351 1364
@@ -1354,16 +1367,16 @@ class MarkersPanel(wx.Panel): @@ -1354,16 +1367,16 @@ class MarkersPanel(wx.Panel):
1354 return 1367 return
1355 1368
1356 # Unset the previous target 1369 # Unset the previous target
1357 - if prev_idx != -1: 1370 + if prev_idx is not None:
1358 self.markers[prev_idx].is_target = False 1371 self.markers[prev_idx].is_target = False
1359 self.lc.SetItemBackgroundColour(prev_idx, 'white') 1372 self.lc.SetItemBackgroundColour(prev_idx, 'white')
1360 Publisher.sendMessage('Set target transparency', status=False, index=prev_idx) 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 # Set the new target 1376 # Set the new target
1364 self.markers[idx].is_target = True 1377 self.markers[idx].is_target = True
1365 self.lc.SetItemBackgroundColour(idx, 'RED') 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 Publisher.sendMessage('Update target', coord=self.markers[idx].coord) 1381 Publisher.sendMessage('Update target', coord=self.markers[idx].coord)
1369 Publisher.sendMessage('Set target transparency', status=True, index=idx) 1382 Publisher.sendMessage('Set target transparency', status=True, index=idx)
@@ -1416,9 +1429,9 @@ class MarkersPanel(wx.Panel): @@ -1416,9 +1429,9 @@ class MarkersPanel(wx.Panel):
1416 def OnMenuEditMarkerLabel(self, evt): 1429 def OnMenuEditMarkerLabel(self, evt):
1417 list_index = self.lc.GetFocusedItem() 1430 list_index = self.lc.GetFocusedItem()
1418 if list_index != -1: 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 self.markers[list_index].label = str(new_label) 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 else: 1435 else:
1423 wx.MessageBox(_("No data selected."), _("InVesalius 3")) 1436 wx.MessageBox(_("No data selected."), _("InVesalius 3"))
1424 1437
@@ -1445,20 +1458,17 @@ class MarkersPanel(wx.Panel): @@ -1445,20 +1458,17 @@ class MarkersPanel(wx.Panel):
1445 # XXX: Seems like a slightly too early point for rounding; better to round only when the value 1458 # XXX: Seems like a slightly too early point for rounding; better to round only when the value
1446 # is printed to the screen or file. 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 Publisher.sendMessage('Set new color', index=index, color=color_new) 1463 Publisher.sendMessage('Set new color', index=index, color=color_new)
1451 1464
1452 def OnDeleteAllMarkers(self, evt=None): 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 result = dlg.ShowConfirmationDialog(msg=_("Remove all markers? Cannot be undone.")) 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 Publisher.sendMessage('Disable or enable coil tracker', status=False) 1472 Publisher.sendMessage('Disable or enable coil tracker', status=False)
1463 if evt is not None: 1473 if evt is not None:
1464 wx.MessageBox(_("Target deleted."), _("InVesalius 3")) 1474 wx.MessageBox(_("Target deleted."), _("InVesalius 3"))
@@ -1472,17 +1482,19 @@ class MarkersPanel(wx.Panel): @@ -1472,17 +1482,19 @@ class MarkersPanel(wx.Panel):
1472 # OnDeleteMultipleMarkers is used for both pubsub and button click events 1482 # OnDeleteMultipleMarkers is used for both pubsub and button click events
1473 # Pubsub is used for fiducial handle and button click for all others 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 index = [] 1487 index = []
1477 1488
1478 if label and (label in self.__list_fiducial_labels()): 1489 if label and (label in self.__list_fiducial_labels()):
1479 for id_n in range(self.lc.GetItemCount()): 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 if item.GetText() == label: 1492 if item.GetText() == label:
1482 self.lc.Focus(item.GetId()) 1493 self.lc.Focus(item.GetId())
1483 index = [self.lc.GetFocusedItem()] 1494 index = [self.lc.GetFocusedItem()]
1484 1495
1485 - else: # called from button click 1496 + # called from button click
  1497 + else:
1486 index = self.__get_selected_items() 1498 index = self.__get_selected_items()
1487 1499
1488 if index: 1500 if index:
@@ -1532,13 +1544,12 @@ class MarkersPanel(wx.Panel): @@ -1532,13 +1544,12 @@ class MarkersPanel(wx.Panel):
1532 # If the new marker has is_target=True, we first create 1544 # If the new marker has is_target=True, we first create
1533 # a marker with is_target=False, and then call __set_marker_as_target 1545 # a marker with is_target=False, and then call __set_marker_as_target
1534 if marker.is_target: 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 except: 1549 except:
1538 wx.MessageBox(_("Invalid markers file."), _("InVesalius 3")) 1550 wx.MessageBox(_("Invalid markers file."), _("InVesalius 3"))
1539 1551
1540 def OnMarkersVisibility(self, evt, ctrl): 1552 def OnMarkersVisibility(self, evt, ctrl):
1541 -  
1542 if ctrl.GetValue(): 1553 if ctrl.GetValue():
1543 Publisher.sendMessage('Hide all markers', indexes=self.lc.GetItemCount()) 1554 Publisher.sendMessage('Hide all markers', indexes=self.lc.GetItemCount())
1544 ctrl.SetLabel('Show') 1555 ctrl.SetLabel('Show')
@@ -1573,8 +1584,8 @@ class MarkersPanel(wx.Panel): @@ -1573,8 +1584,8 @@ class MarkersPanel(wx.Panel):
1573 wx.MessageBox(_("Error writing markers file."), _("InVesalius 3")) 1584 wx.MessageBox(_("Error writing markers file."), _("InVesalius 3"))
1574 1585
1575 def OnSelectColour(self, evt, ctrl): 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 def OnSelectSize(self, evt, ctrl): 1590 def OnSelectSize(self, evt, ctrl):
1580 self.marker_size = ctrl.GetValue() 1591 self.marker_size = ctrl.GetValue()
@@ -1602,11 +1613,14 @@ class MarkersPanel(wx.Panel): @@ -1602,11 +1613,14 @@ class MarkersPanel(wx.Panel):
1602 # Add item to list control in panel 1613 # Add item to list control in panel
1603 num_items = self.lc.GetItemCount() 1614 num_items = self.lc.GetItemCount()
1604 self.lc.InsertItem(num_items, str(num_items + 1)) 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 self.lc.EnsureVisible(num_items) 1624 self.lc.EnsureVisible(num_items)
1611 1625
1612 class DbsPanel(wx.Panel): 1626 class DbsPanel(wx.Panel):