Commit ed365dc5a0a038c1fbcf738a56b8a9625e7a328b

Authored by Renan
Committed by GitHub
2 parents f64959b9 0acb6ee2
Exists in master

Merge branch 'master' into multimodal_tracking

app.py
... ... @@ -87,11 +87,11 @@ session = ses.Session()
87 87 if session.ReadSession():
88 88 lang = session.GetLanguage()
89 89 if lang:
90   - LANG = lang
91 90 try:
92 91 _ = i18n.InstallLanguage(lang)
  92 + LANG = lang
93 93 except FileNotFoundError:
94   - LANG = None
  94 + pass
95 95  
96 96  
97 97 class InVesalius(wx.App):
... ... @@ -134,7 +134,7 @@ class Inv3SplashScreen(SplashScreen):
134 134 Splash screen to be shown in InVesalius initialization.
135 135 """
136 136 def __init__(self):
137   - # Splash screen image will depend on currently language
  137 + # Splash screen image will depend on the current language
138 138 lang = LANG
139 139 self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
140 140  
... ... @@ -143,22 +143,20 @@ class Inv3SplashScreen(SplashScreen):
143 143 # should be created
144 144 create_session = LANG is None
145 145  
146   - install_lang = 0
  146 + install_lang = False
147 147 if lang:
148 148 _ = i18n.InstallLanguage(lang)
149   - install_lang = 1
150   - else:
151   - install_lang = 0
  149 + install_lang = True
152 150  
153 151 # If no language is set into session file, show dialog so
154 152 # user can select language
155   - if install_lang == 0:
  153 + if not install_lang:
156 154 dialog = lang_dlg.LanguageDialog()
157 155  
158 156 # FIXME: This works ok in linux2, darwin and win32,
159 157 # except on win64, due to wxWidgets bug
160 158 try:
161   - ok = (dialog.ShowModal() == wx.ID_OK)
  159 + ok = dialog.ShowModal() == wx.ID_OK
162 160 except wx._core.PyAssertionError:
163 161 ok = True
164 162 finally:
... ... @@ -174,9 +172,8 @@ class Inv3SplashScreen(SplashScreen):
174 172  
175 173 dialog.Destroy()
176 174  
177   - # Session file should be created... So we set the recent
178   - # choosen language
179   - if (create_session):
  175 + # Session file should be created... So we set the recently chosen language.
  176 + if create_session:
180 177 session.CreateItens()
181 178 session.SetLanguage(lang)
182 179 session.WriteSessionFile()
... ... @@ -184,8 +181,7 @@ class Inv3SplashScreen(SplashScreen):
184 181 # session.SaveConfigFileBackup()
185 182  
186 183  
187   - # Only after language was defined, splash screen will be
188   - # shown
  184 + # Only after language was defined, splash screen will be shown.
189 185 if lang:
190 186  
191 187 #import locale
... ... @@ -206,9 +202,7 @@ class Inv3SplashScreen(SplashScreen):
206 202 abs_file_path = os.path.abspath(".." + os.sep)
207 203 path = abs_file_path
208 204 path = os.path.join(path, 'icons', icon_file)
209   -
210 205 else:
211   -
212 206 path = os.path.join(inv_paths.ICON_DIR, icon_file)
213 207 if not os.path.exists(path):
214 208 path = os.path.join(inv_paths.ICON_DIR, "splash_en.png")
... ... @@ -241,7 +235,7 @@ class Inv3SplashScreen(SplashScreen):
241 235 self.control = Controller(self.main)
242 236  
243 237 self.fc = wx.CallLater(200, self.ShowMain)
244   - options, args = parse_comand_line()
  238 + options, args = parse_command_line()
245 239 wx.CallLater(1, use_cmd_optargs, options, args)
246 240  
247 241 # Check for updates
... ... @@ -292,7 +286,7 @@ def non_gui_startup(options, args):
292 286 # ------------------------------------------------------------------
293 287  
294 288  
295   -def parse_comand_line():
  289 +def parse_command_line():
296 290 """
297 291 Handle command line arguments.
298 292 """
... ... @@ -302,7 +296,7 @@ def parse_comand_line():
302 296 # Parse command line arguments
303 297 parser = op.OptionParser()
304 298  
305   - # -d or --debug: print all pubsub messagessent
  299 + # -d or --debug: print all pubsub messages sent
306 300 parser.add_option("-d", "--debug",
307 301 action="store_true",
308 302 dest="debug")
... ... @@ -353,12 +347,6 @@ def parse_comand_line():
353 347  
354 348  
355 349 def use_cmd_optargs(options, args):
356   - # If debug argument...
357   - if options.debug:
358   - Publisher.subscribe(print_events, Publisher.ALL_TOPICS)
359   - session = ses.Session()
360   - session.debug = 1
361   -
362 350 # If import DICOM argument...
363 351 if options.dicom_dir:
364 352 import_dir = options.dicom_dir
... ... @@ -494,11 +482,18 @@ def print_events(topic=Publisher.AUTO_TOPIC, **msg_data):
494 482 """
495 483 utils.debug("%s\n\tParameters: %s" % (topic, msg_data))
496 484  
  485 +
497 486 def main():
498 487 """
499 488 Initialize InVesalius GUI
500 489 """
501   - options, args = parse_comand_line()
  490 + options, args = parse_command_line()
  491 +
  492 + session = ses.Session()
  493 + session.debug = options.debug
  494 +
  495 + if options.debug:
  496 + Publisher.subscribe(print_events, Publisher.ALL_TOPICS)
502 497  
503 498 if options.remote_host is not None:
504 499 from invesalius.net.remote_control import RemoteControl
... ... @@ -517,6 +512,7 @@ def main():
517 512 application = InVesalius(0)
518 513 application.MainLoop()
519 514  
  515 +
520 516 if __name__ == '__main__':
521 517 #Is needed because of pyinstaller
522 518 multiprocessing.freeze_support()
... ...
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
... ... @@ -61,9 +61,11 @@ import invesalius.data.slice_ as sl
61 61 import invesalius.data.tractography as dti
62 62 import invesalius.data.record_coords as rec
63 63 import invesalius.data.vtk_utils as vtk_utils
  64 +import invesalius.data.bases as db
64 65 import invesalius.gui.dialogs as dlg
65 66 import invesalius.project as prj
66   -import invesalius.data.bases as db
  67 +import invesalius.session as ses
  68 +
67 69 from invesalius import utils
68 70 from invesalius.gui import utils as gui_utils
69 71 from invesalius.navigation.icp import ICP
... ... @@ -1249,6 +1251,8 @@ class MarkersPanel(wx.Panel):
1249 1251  
1250 1252 self.__bind_events()
1251 1253  
  1254 + self.session = ses.Session()
  1255 +
1252 1256 self.current_coord = 0, 0, 0, 0, 0, 0
1253 1257 self.current_angle = 0, 0, 0
1254 1258 self.current_seed = 0, 0, 0
... ... @@ -1309,21 +1313,27 @@ class MarkersPanel(wx.Panel):
1309 1313  
1310 1314 # List of markers
1311 1315 self.lc = wx.ListCtrl(self, -1, style=wx.LC_REPORT, size=wx.Size(0,120))
1312   - self.lc.InsertColumn(0, '#')
1313   - self.lc.InsertColumn(1, 'X')
1314   - self.lc.InsertColumn(2, 'Y')
1315   - self.lc.InsertColumn(3, 'Z')
1316   - self.lc.InsertColumn(4, 'Label')
1317   - self.lc.InsertColumn(5, 'Target')
1318   - self.lc.InsertColumn(6, 'Session')
1319   -
1320   - self.lc.SetColumnWidth(0, 28)
1321   - self.lc.SetColumnWidth(1, 50)
1322   - self.lc.SetColumnWidth(2, 50)
1323   - self.lc.SetColumnWidth(3, 50)
1324   - self.lc.SetColumnWidth(4, 60)
1325   - self.lc.SetColumnWidth(5, 60)
1326   - self.lc.SetColumnWidth(5, 50)
  1316 + self.lc.InsertColumn(const.ID_COLUMN, '#')
  1317 + self.lc.SetColumnWidth(const.ID_COLUMN, 28)
  1318 +
  1319 + self.lc.InsertColumn(const.SESSION_COLUMN, 'Session')
  1320 + self.lc.SetColumnWidth(const.SESSION_COLUMN, 52)
  1321 +
  1322 + self.lc.InsertColumn(const.LABEL_COLUMN, 'Label')
  1323 + self.lc.SetColumnWidth(const.LABEL_COLUMN, 118)
  1324 +
  1325 + self.lc.InsertColumn(const.TARGET_COLUMN, 'Target')
  1326 + self.lc.SetColumnWidth(const.TARGET_COLUMN, 45)
  1327 +
  1328 + if self.session.debug:
  1329 + self.lc.InsertColumn(const.X_COLUMN, 'X')
  1330 + self.lc.SetColumnWidth(const.X_COLUMN, 45)
  1331 +
  1332 + self.lc.InsertColumn(const.Y_COLUMN, 'Y')
  1333 + self.lc.SetColumnWidth(const.Y_COLUMN, 45)
  1334 +
  1335 + self.lc.InsertColumn(const.Z_COLUMN, 'Z')
  1336 + self.lc.SetColumnWidth(const.Z_COLUMN, 45)
1327 1337  
1328 1338 self.lc.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.OnMouseRightDown)
1329 1339 self.lc.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemBlink)
... ... @@ -1341,7 +1351,6 @@ class MarkersPanel(wx.Panel):
1341 1351 self.Update()
1342 1352  
1343 1353 def __bind_events(self):
1344   - # Publisher.subscribe(self.UpdateCurrentCoord, 'Co-registered points')
1345 1354 Publisher.subscribe(self.UpdateCurrentCoord, 'Set cross focal point')
1346 1355 Publisher.subscribe(self.OnDeleteMultipleMarkers, 'Delete fiducial marker')
1347 1356 Publisher.subscribe(self.OnDeleteAllMarkers, 'Delete all markers')
... ... @@ -1352,13 +1361,15 @@ class MarkersPanel(wx.Panel):
1352 1361 Publisher.subscribe(self.UpdateRobotCoordinates, 'Update raw coordinates')
1353 1362  
1354 1363 def __find_target_marker(self):
1355   - """Return the index of the marker currently selected as target (there
1356   - should be at most one). If there is no such marker, return -1."""
  1364 + """
  1365 + Return the index of the marker currently selected as target (there
  1366 + should be at most one). If there is no such marker, return None.
  1367 + """
1357 1368 for i in range(len(self.markers)):
1358 1369 if self.markers[i].is_target:
1359 1370 return i
1360 1371  
1361   - return -1
  1372 + return None
1362 1373  
1363 1374 def __get_selected_items(self):
1364 1375 """
... ... @@ -1368,14 +1379,15 @@ class MarkersPanel(wx.Panel):
1368 1379  
1369 1380 next = self.lc.GetFirstSelected()
1370 1381  
1371   - while next != -1:
  1382 + while next is not None:
1372 1383 selection.append(next)
1373 1384 next = self.lc.GetNextSelected(next)
1374 1385  
1375 1386 return selection
1376 1387  
1377 1388 def __delete_multiple_markers(self, index):
1378   - """ Delete multiple markers indexed by index. index must be sorted in
  1389 + """
  1390 + Delete multiple markers indexed by index. index must be sorted in
1379 1391 the ascending order.
1380 1392 """
1381 1393 for i in reversed(index):
... ... @@ -1383,11 +1395,13 @@ class MarkersPanel(wx.Panel):
1383 1395 del self.robot_markers[i]
1384 1396 self.lc.DeleteItem(i)
1385 1397 for n in range(0, self.lc.GetItemCount()):
1386   - self.lc.SetItem(n, 0, str(n+1))
  1398 + self.lc.SetItem(n, 0, str(n + 1))
1387 1399 Publisher.sendMessage('Remove multiple markers', index=index)
1388 1400  
1389 1401 def __set_marker_as_target(self, idx):
1390   - """Set marker indexed by idx as the new target. idx must be a valid index."""
  1402 + """
  1403 + Set marker indexed by idx as the new target. idx must be a valid index.
  1404 + """
1391 1405 # Find the previous target
1392 1406 prev_idx = self.__find_target_marker()
1393 1407  
... ... @@ -1396,16 +1410,16 @@ class MarkersPanel(wx.Panel):
1396 1410 return
1397 1411  
1398 1412 # Unset the previous target
1399   - if prev_idx != -1:
  1413 + if prev_idx is not None:
1400 1414 self.markers[prev_idx].is_target = False
1401 1415 self.lc.SetItemBackgroundColour(prev_idx, 'white')
1402 1416 Publisher.sendMessage('Set target transparency', status=False, index=prev_idx)
1403   - self.lc.SetItem(prev_idx, 5, "")
  1417 + self.lc.SetItem(prev_idx, const.TARGET_COLUMN, "")
1404 1418  
1405 1419 # Set the new target
1406 1420 self.markers[idx].is_target = True
1407 1421 self.lc.SetItemBackgroundColour(idx, 'RED')
1408   - self.lc.SetItem(idx, 5, _("Yes"))
  1422 + self.lc.SetItem(idx, const.TARGET_COLUMN, _("Yes"))
1409 1423  
1410 1424 Publisher.sendMessage('Update target', coord=self.markers[idx].coord)
1411 1425 Publisher.sendMessage('Set target transparency', status=True, index=idx)
... ... @@ -1471,9 +1485,9 @@ class MarkersPanel(wx.Panel):
1471 1485 def OnMenuEditMarkerLabel(self, evt):
1472 1486 list_index = self.lc.GetFocusedItem()
1473 1487 if list_index != -1:
1474   - new_label = dlg.ShowEnterMarkerID(self.lc.GetItemText(list_index, 4))
  1488 + new_label = dlg.ShowEnterMarkerID(self.lc.GetItemText(list_index, const.LABEL_COLUMN))
1475 1489 self.markers[list_index].label = str(new_label)
1476   - self.lc.SetItem(list_index, 4, new_label)
  1490 + self.lc.SetItem(list_index, const.LABEL_COLUMN, new_label)
1477 1491 else:
1478 1492 wx.MessageBox(_("No data selected."), _("InVesalius 3"))
1479 1493  
... ... @@ -1500,7 +1514,7 @@ class MarkersPanel(wx.Panel):
1500 1514 # XXX: Seems like a slightly too early point for rounding; better to round only when the value
1501 1515 # is printed to the screen or file.
1502 1516 #
1503   - self.markers[index].colour = [round(s/255.0, 3) for s in color_new]
  1517 + self.markers[index].colour = [round(s / 255.0, 3) for s in color_new]
1504 1518  
1505 1519 Publisher.sendMessage('Set new color', index=index, color=color_new)
1506 1520  
... ... @@ -1514,15 +1528,12 @@ class MarkersPanel(wx.Panel):
1514 1528 Publisher.sendMessage('Robot target matrix', robot_tracker_flag=True, m_change_robot_to_head=m_target_robot)
1515 1529  
1516 1530 def OnDeleteAllMarkers(self, evt=None):
1517   - if evt is None:
1518   - result = wx.ID_OK
1519   - else:
  1531 + if evt is not None:
1520 1532 result = dlg.ShowConfirmationDialog(msg=_("Remove all markers? Cannot be undone."))
  1533 + if result != wx.ID_OK:
  1534 + return
1521 1535  
1522   - if result != wx.ID_OK:
1523   - return
1524   -
1525   - if self.__find_target_marker() != -1:
  1536 + if self.__find_target_marker() is not None:
1526 1537 Publisher.sendMessage('Disable or enable coil tracker', status=False)
1527 1538 if evt is not None:
1528 1539 wx.MessageBox(_("Target deleted."), _("InVesalius 3"))
... ... @@ -1537,17 +1548,19 @@ class MarkersPanel(wx.Panel):
1537 1548 # OnDeleteMultipleMarkers is used for both pubsub and button click events
1538 1549 # Pubsub is used for fiducial handle and button click for all others
1539 1550  
1540   - if not evt: # called through pubsub
  1551 + # called through pubsub
  1552 + if not evt:
1541 1553 index = []
1542 1554  
1543 1555 if label and (label in self.__list_fiducial_labels()):
1544 1556 for id_n in range(self.lc.GetItemCount()):
1545   - item = self.lc.GetItem(id_n, 4)
  1557 + item = self.lc.GetItem(id_n, const.LABEL_COLUMN)
1546 1558 if item.GetText() == label:
1547 1559 self.lc.Focus(item.GetId())
1548 1560 index = [self.lc.GetFocusedItem()]
1549 1561  
1550   - else: # called from button click
  1562 + # called from button click
  1563 + else:
1551 1564 index = self.__get_selected_items()
1552 1565  
1553 1566 if index:
... ... @@ -1599,13 +1612,12 @@ class MarkersPanel(wx.Panel):
1599 1612 # If the new marker has is_target=True, we first create
1600 1613 # a marker with is_target=False, and then call __set_marker_as_target
1601 1614 if marker.is_target:
1602   - self.__set_marker_as_target(len(self.markers)-1)
  1615 + self.__set_marker_as_target(len(self.markers) - 1)
1603 1616  
1604 1617 except:
1605 1618 wx.MessageBox(_("Invalid markers file."), _("InVesalius 3"))
1606 1619  
1607 1620 def OnMarkersVisibility(self, evt, ctrl):
1608   -
1609 1621 if ctrl.GetValue():
1610 1622 Publisher.sendMessage('Hide all markers', indexes=self.lc.GetItemCount())
1611 1623 ctrl.SetLabel('Show')
... ... @@ -1640,8 +1652,8 @@ class MarkersPanel(wx.Panel):
1640 1652 wx.MessageBox(_("Error writing markers file."), _("InVesalius 3"))
1641 1653  
1642 1654 def OnSelectColour(self, evt, ctrl):
1643   - #TODO: Make sure GetValue returns 3 numbers (without alpha)
1644   - self.marker_colour = [colour/255.0 for colour in ctrl.GetValue()][:3]
  1655 + # TODO: Make sure GetValue returns 3 numbers (without alpha)
  1656 + self.marker_colour = [colour / 255.0 for colour in ctrl.GetValue()][:3]
1645 1657  
1646 1658 def OnSelectSize(self, evt, ctrl):
1647 1659 self.marker_size = ctrl.GetValue()
... ... @@ -1678,11 +1690,14 @@ class MarkersPanel(wx.Panel):
1678 1690 # Add item to list control in panel
1679 1691 num_items = self.lc.GetItemCount()
1680 1692 self.lc.InsertItem(num_items, str(num_items + 1))
1681   - self.lc.SetItem(num_items, 1, str(round(new_marker.x, 2)))
1682   - self.lc.SetItem(num_items, 2, str(round(new_marker.y, 2)))
1683   - self.lc.SetItem(num_items, 3, str(round(new_marker.z, 2)))
1684   - self.lc.SetItem(num_items, 4, new_marker.label)
1685   - self.lc.SetItem(num_items, 6, str(new_marker.session_id))
  1693 + self.lc.SetItem(num_items, const.SESSION_COLUMN, str(new_marker.session_id))
  1694 + self.lc.SetItem(num_items, const.LABEL_COLUMN, new_marker.label)
  1695 +
  1696 + if self.session.debug:
  1697 + self.lc.SetItem(num_items, const.X_COLUMN, str(round(new_marker.x, 1)))
  1698 + self.lc.SetItem(num_items, const.Y_COLUMN, str(round(new_marker.y, 1)))
  1699 + self.lc.SetItem(num_items, const.Z_COLUMN, str(round(new_marker.z, 1)))
  1700 +
1686 1701 self.lc.EnsureVisible(num_items)
1687 1702  
1688 1703 class DbsPanel(wx.Panel):
... ...
invesalius/i18n.py
... ... @@ -21,7 +21,7 @@
21 21  
22 22 try:
23 23 import configparser as ConfigParser
24   -except(ImportError):
  24 +except ImportError:
25 25 import ConfigParser
26 26  
27 27 import locale
... ... @@ -66,22 +66,21 @@ def GetLocaleOS():
66 66 def InstallLanguage(language):
67 67 file_path = os.path.split(__file__)[0]
68 68  
69   - if hasattr(sys,"frozen") and (sys.frozen == "windows_exe"\
70   - or sys.frozen == "console_exe"):
  69 + abs_file_path = os.path.abspath(file_path + os.sep + "..")
71 70  
72   - abs_file_path = os.path.abspath(file_path + os.sep + ".." + os.sep + ".." + os.sep + "..")
73   - language_dir = os.path.join(abs_file_path, 'locale')
74   - else:
75   - abs_file_path = os.path.abspath(file_path + os.sep + "..")
76   - language_dir = os.path.join(abs_file_path, 'locale')
  71 + if hasattr(sys, "frozen") and (sys.frozen == "windows_exe" or sys.frozen == "console_exe"):
  72 + abs_file_path = os.path.abspath(abs_file_path + os.sep + ".." + os.sep + "..")
77 73  
78   - # MAC App
  74 + language_dir = os.path.join(abs_file_path, 'locale')
  75 +
  76 + # MAC app
79 77 if not os.path.exists(language_dir):
80 78 abs_file_path = os.path.abspath(os.path.join(file_path, '..', '..', '..', '..'))
81 79 language_dir = os.path.join(abs_file_path, 'locale')
82 80  
83   - lang = gettext.translation('invesalius', language_dir,\
84   - languages=[language], codeset='utf8')
  81 + lang = gettext.translation('invesalius', language_dir,
  82 + languages=[language], codeset='utf8')
  83 +
85 84 # Using unicode
86 85 try:
87 86 lang.install(unicode=1)
... ...