Commit e2c39d009468f5f6f5a2b036ebd8fa7a6959ca10

Authored by Thiago Franco de Moraes
1 parent 34cd93f5
Exists in command-line

Create option to open InVesalius without gui

@@ -198,7 +198,8 @@ class SplashScreen(wx.SplashScreen): @@ -198,7 +198,8 @@ class SplashScreen(wx.SplashScreen):
198 self.control = Controller(self.main) 198 self.control = Controller(self.main)
199 199
200 self.fc = wx.FutureCall(1, self.ShowMain) 200 self.fc = wx.FutureCall(1, self.ShowMain)
201 - wx.FutureCall(1, parse_comand_line) 201 + options, args = parse_comand_line()
  202 + wx.FutureCall(1, use_cmd_optargs, options, args)
202 203
203 # Check for updates 204 # Check for updates
204 from threading import Thread 205 from threading import Thread
@@ -224,6 +225,24 @@ class SplashScreen(wx.SplashScreen): @@ -224,6 +225,24 @@ class SplashScreen(wx.SplashScreen):
224 if self.fc.IsRunning(): 225 if self.fc.IsRunning():
225 self.Raise() 226 self.Raise()
226 227
  228 +
  229 +def non_gui_startup(options, args):
  230 + lang = 'en'
  231 + _ = i18n.InstallLanguage(lang)
  232 +
  233 + from invesalius.control import Controller
  234 + from invesalius.project import Project
  235 +
  236 + session = ses.Session()
  237 + if not session.ReadSession():
  238 + session.CreateItens()
  239 + session.SetLanguage(lang)
  240 + session.WriteSessionFile()
  241 +
  242 + control = Controller(None)
  243 +
  244 + use_cmd_optargs(options, args)
  245 +
227 # ------------------------------------------------------------------ 246 # ------------------------------------------------------------------
228 247
229 248
@@ -241,6 +260,10 @@ def parse_comand_line(): @@ -241,6 +260,10 @@ def parse_comand_line():
241 action="store_true", 260 action="store_true",
242 dest="debug") 261 dest="debug")
243 262
  263 + parser.add_option('--no-gui',
  264 + action='store_true',
  265 + dest='no_gui')
  266 +
244 # -i or --import: import DICOM directory 267 # -i or --import: import DICOM directory
245 # chooses largest series 268 # chooses largest series
246 parser.add_option("-i", "--import", 269 parser.add_option("-i", "--import",
@@ -254,7 +277,10 @@ def parse_comand_line(): @@ -254,7 +277,10 @@ def parse_comand_line():
254 help="To open a project and export it to STL for all mask presets.") 277 help="To open a project and export it to STL for all mask presets.")
255 278
256 options, args = parser.parse_args() 279 options, args = parser.parse_args()
  280 + return options, args
  281 +
257 282
  283 +def use_cmd_optargs(options, args):
258 # If debug argument... 284 # If debug argument...
259 if options.debug: 285 if options.debug:
260 Publisher.subscribe(print_events, Publisher.ALL_TOPICS) 286 Publisher.subscribe(print_events, Publisher.ALL_TOPICS)
@@ -333,8 +359,13 @@ def main(): @@ -333,8 +359,13 @@ def main():
333 """ 359 """
334 Initialize InVesalius GUI 360 Initialize InVesalius GUI
335 """ 361 """
336 - application = InVesalius(0)  
337 - application.MainLoop() 362 + options, args = parse_comand_line()
  363 +
  364 + if options.no_gui:
  365 + non_gui_startup(options, args)
  366 + else:
  367 + application = InVesalius(0)
  368 + application.MainLoop()
338 369
339 if __name__ == '__main__': 370 if __name__ == '__main__':
340 #Is needed because of pyinstaller 371 #Is needed because of pyinstaller
invesalius/constants.py
@@ -686,19 +686,19 @@ BTNS_IMG_MKS = {IR1: {0: 'LEI'}, @@ -686,19 +686,19 @@ BTNS_IMG_MKS = {IR1: {0: 'LEI'},
686 IR2: {1: 'REI'}, 686 IR2: {1: 'REI'},
687 IR3: {2: 'NAI'}} 687 IR3: {2: 'NAI'}}
688 688
689 -TIPS_IMG = [wx.ToolTip(_("Select left ear in image")),  
690 - wx.ToolTip(_("Select right ear in image")),  
691 - wx.ToolTip(_("Select nasion in image"))] 689 +TIPS_IMG = [_("Select left ear in image"),
  690 + _("Select right ear in image"),
  691 + _("Select nasion in image")]
692 692
693 BTNS_TRK = {TR1: {3: _('LET')}, 693 BTNS_TRK = {TR1: {3: _('LET')},
694 TR2: {4: _('RET')}, 694 TR2: {4: _('RET')},
695 TR3: {5: _('NAT')}, 695 TR3: {5: _('NAT')},
696 SET: {6: _('SET')}} 696 SET: {6: _('SET')}}
697 697
698 -TIPS_TRK = [wx.ToolTip(_("Select left ear with spatial tracker")),  
699 - wx.ToolTip(_("Select right ear with spatial tracker")),  
700 - wx.ToolTip(_("Select nasion with spatial tracker")),  
701 - wx.ToolTip(_("Show set coordinates in image"))] 698 +TIPS_TRK = [_("Select left ear with spatial tracker"),
  699 + _("Select right ear with spatial tracker"),
  700 + _("Select nasion with spatial tracker"),
  701 + _("Show set coordinates in image")]
702 702
703 CAL_DIR = os.path.abspath(os.path.join(FILE_PATH, '..', 'navigation', 'mtc_files', 'CalibrationFiles')) 703 CAL_DIR = os.path.abspath(os.path.join(FILE_PATH, '..', 'navigation', 'mtc_files', 'CalibrationFiles'))
704 MAR_DIR = os.path.abspath(os.path.join(FILE_PATH, '..', 'navigation', 'mtc_files', 'Markers')) 704 MAR_DIR = os.path.abspath(os.path.join(FILE_PATH, '..', 'navigation', 'mtc_files', 'Markers'))
invesalius/data/slice_.py
@@ -353,19 +353,22 @@ class Slice(object): @@ -353,19 +353,22 @@ class Slice(object):
353 353
354 # TODO: merge this code with apply_slice_buffer_to_mask 354 # TODO: merge this code with apply_slice_buffer_to_mask
355 b_mask = self.buffer_slices["AXIAL"].mask 355 b_mask = self.buffer_slices["AXIAL"].mask
356 - n = self.buffer_slices["AXIAL"].index + 1  
357 - self.current_mask.matrix[n, 1:, 1:] = b_mask  
358 - self.current_mask.matrix[n, 0, 0] = 1 356 + if b_mask:
  357 + n = self.buffer_slices["AXIAL"].index + 1
  358 + self.current_mask.matrix[n, 1:, 1:] = b_mask
  359 + self.current_mask.matrix[n, 0, 0] = 1
359 360
360 b_mask = self.buffer_slices["CORONAL"].mask 361 b_mask = self.buffer_slices["CORONAL"].mask
361 - n = self.buffer_slices["CORONAL"].index + 1  
362 - self.current_mask.matrix[1:, n, 1:] = b_mask  
363 - self.current_mask.matrix[0, n, 0] = 1 362 + if b_mask:
  363 + n = self.buffer_slices["CORONAL"].index + 1
  364 + self.current_mask.matrix[1:, n, 1:] = b_mask
  365 + self.current_mask.matrix[0, n, 0] = 1
364 366
365 b_mask = self.buffer_slices["SAGITAL"].mask 367 b_mask = self.buffer_slices["SAGITAL"].mask
366 - n = self.buffer_slices["SAGITAL"].index + 1  
367 - self.current_mask.matrix[1:, 1:, n] = b_mask  
368 - self.current_mask.matrix[0, 0, n] = 1 368 + if b_mask:
  369 + n = self.buffer_slices["SAGITAL"].index + 1
  370 + self.current_mask.matrix[1:, 1:, n] = b_mask
  371 + self.current_mask.matrix[0, 0, n] = 1
369 372
370 if to_reload: 373 if to_reload:
371 Publisher.sendMessage('Reload actual slice') 374 Publisher.sendMessage('Reload actual slice')
@@ -882,8 +885,8 @@ class Slice(object): @@ -882,8 +885,8 @@ class Slice(object):
882 self.current_mask.matrix[n+1, 1:, 1:] = m 885 self.current_mask.matrix[n+1, 1:, 1:] = m
883 else: 886 else:
884 slice_ = self.buffer_slices[orientation].image 887 slice_ = self.buffer_slices[orientation].image
885 - print ">>>", slice_, index  
886 - self.buffer_slices[orientation].mask = (255 * ((slice_ >= thresh_min) & (slice_ <= thresh_max))).astype('uint8') 888 + if slice_:
  889 + self.buffer_slices[orientation].mask = (255 * ((slice_ >= thresh_min) & (slice_ <= thresh_max))).astype('uint8')
887 890
888 # Update viewer 891 # Update viewer
889 #Publisher.sendMessage('Update slice viewer') 892 #Publisher.sendMessage('Update slice viewer')
invesalius/data/vtk_utils.py
@@ -44,7 +44,10 @@ def ShowProgress(number_of_filters = 1, @@ -44,7 +44,10 @@ def ShowProgress(number_of_filters = 1,
44 progress = [0] 44 progress = [0]
45 last_obj_progress = [0] 45 last_obj_progress = [0]
46 if (dialog_type == "ProgressDialog"): 46 if (dialog_type == "ProgressDialog"):
47 - dlg = ProgressDialog(100) 47 + try:
  48 + dlg = ProgressDialog(100)
  49 + except wx._core.PyNoAppError:
  50 + return lambda obj, label: 0
48 51
49 52
50 # when the pipeline is larger than 1, we have to consider this object 53 # when the pipeline is larger than 1, we have to consider this object
invesalius/gui/task_navigator.py
@@ -247,7 +247,7 @@ class NeuronavigationPanel(wx.Panel): @@ -247,7 +247,7 @@ class NeuronavigationPanel(wx.Panel):
247 n = btns_img[k].keys()[0] 247 n = btns_img[k].keys()[0]
248 lab = btns_img[k].values()[0] 248 lab = btns_img[k].values()[0]
249 self.btns_coord[n] = wx.ToggleButton(self, k, label=lab, size=wx.Size(45, 23)) 249 self.btns_coord[n] = wx.ToggleButton(self, k, label=lab, size=wx.Size(45, 23))
250 - self.btns_coord[n].SetToolTip(tips_img[n]) 250 + self.btns_coord[n].SetToolTip(wx.ToolTip(tips_img[n]))
251 self.btns_coord[n].Bind(wx.EVT_TOGGLEBUTTON, self.OnImageFiducials) 251 self.btns_coord[n].Bind(wx.EVT_TOGGLEBUTTON, self.OnImageFiducials)
252 252
253 # Push buttons for tracker fiducials 253 # Push buttons for tracker fiducials
@@ -258,7 +258,7 @@ class NeuronavigationPanel(wx.Panel): @@ -258,7 +258,7 @@ class NeuronavigationPanel(wx.Panel):
258 n = btns_trk[k].keys()[0] 258 n = btns_trk[k].keys()[0]
259 lab = btns_trk[k].values()[0] 259 lab = btns_trk[k].values()[0]
260 self.btns_coord[n] = wx.Button(self, k, label=lab, size=wx.Size(45, 23)) 260 self.btns_coord[n] = wx.Button(self, k, label=lab, size=wx.Size(45, 23))
261 - self.btns_coord[n].SetToolTip(tips_trk[n-3]) 261 + self.btns_coord[n].SetToolTip(wx.ToolTip(tips_trk[n-3]))
262 # Excepetion for event of button that set image coordinates 262 # Excepetion for event of button that set image coordinates
263 if n == 6: 263 if n == 6:
264 self.btns_coord[n].Bind(wx.EVT_BUTTON, self.OnSetImageCoordinates) 264 self.btns_coord[n].Bind(wx.EVT_BUTTON, self.OnSetImageCoordinates)
@@ -796,4 +796,4 @@ class MarkersPanel(wx.Panel): @@ -796,4 +796,4 @@ class MarkersPanel(wx.Panel):
796 while len(selection) != self.lc.GetSelectedItemCount(): 796 while len(selection) != self.lc.GetSelectedItemCount():
797 index = self.lc.GetNextSelected(index) 797 index = self.lc.GetNextSelected(index)
798 selection.append(index) 798 selection.append(index)
799 - return selection  
800 \ No newline at end of file 799 \ No newline at end of file
  800 + return selection