Commit 9eb75dcaf2bd5d20c269d59908b1122c84a39ec8

Authored by Thiago Franco de Moraes
Committed by GitHub
1 parent 58ded45e
Exists in master

using wx.calllater to fix problem with opengl (#179)

* using wx.calllater to fix problem with opengl

* handling exception at pool.terminate

* using callafter instead of calllater
Showing 1 changed file with 19 additions and 26 deletions   Show diff stats
invesalius/data/surface.py
... ... @@ -506,6 +506,9 @@ class SurfaceManager():
506 506  
507 507 def _on_complete_surface_creation(self, args, overwrite, surface_name, colour, dialog):
508 508 surface_filename, surface_measures = args
  509 + wx.CallAfter(self._show_surface, surface_filename, surface_measures, overwrite, surface_name, colour, dialog)
  510 +
  511 + def _show_surface(self, surface_filename, surface_measures, overwrite, surface_name, colour, dialog):
509 512 print(surface_filename, surface_measures)
510 513 reader = vtk.vtkXMLPolyDataReader()
511 514 reader.SetFileName(surface_filename)
... ... @@ -739,31 +742,18 @@ class SurfaceManager():
739 742 wx.Yield()
740 743  
741 744 if not sp.WasCancelled() or sp.running:
742   - try:
743   - f = pool.apply_async(surface_process.join_process_surface,
744   - args=(filenames, algorithm, smooth_iterations,
745   - smooth_relaxation_factor,
746   - decimate_reduction, keep_largest,
747   - fill_holes, options, msg_queue),
748   - callback=functools.partial(self._on_complete_surface_creation,
749   - overwrite=overwrite,
750   - surface_name=surface_name,
751   - colour=colour,
752   - dialog=sp),
753   - error_callback=functools.partial(self._on_callback_error,
754   - dialog=sp))
755   - # python2
756   - except TypeError:
757   - f = pool.apply_async(surface_process.join_process_surface,
758   - args=(filenames, algorithm, smooth_iterations,
759   - smooth_relaxation_factor,
760   - decimate_reduction, keep_largest,
761   - fill_holes, options, msg_queue),
762   - callback=functools.partial(self._on_complete_surface_creation,
763   - overwrite=overwrite,
764   - surface_name=surface_name,
765   - colour=colour,
766   - dialog=sp))
  745 + f = pool.apply_async(surface_process.join_process_surface,
  746 + args=(filenames, algorithm, smooth_iterations,
  747 + smooth_relaxation_factor,
  748 + decimate_reduction, keep_largest,
  749 + fill_holes, options, msg_queue),
  750 + callback=functools.partial(self._on_complete_surface_creation,
  751 + overwrite=overwrite,
  752 + surface_name=surface_name,
  753 + colour=colour,
  754 + dialog=sp),
  755 + error_callback=functools.partial(self._on_callback_error,
  756 + dialog=sp))
767 757  
768 758 while sp.running:
769 759 if sp.WasCancelled():
... ... @@ -787,7 +777,10 @@ class SurfaceManager():
787 777 del sp
788 778  
789 779 pool.close()
790   - pool.terminate()
  780 + try:
  781 + pool.terminate()
  782 + except AssertionError:
  783 + pass
791 784 del pool
792 785 del manager
793 786 del msg_queue
... ...