SimpleITK / SlicerSimpleFilters

A Module for Slicer3D to provide a simple GUI to image filters from the Insight Toolkit.
Other
1 stars 12 forks source link

Fix python3 errors #19

Closed jcfr closed 5 years ago

jcfr commented 5 years ago

See https://github.com/SimpleITK/SlicerSimpleFilters/issues/17 and https://discourse.slicer.org/t/simple-filters-module-do-not-have-any-filters-in-latest-nightly-version/6787

blowekamp commented 5 years ago

Reviewing related exec code I found this:

 exec('self.filter = sitk.{0}()'.format(json["name"]), globals(), locals())

I am still trying to understand the change with Py3 exec and the context of execution, but I suppose this line will still work since it does not create a new variable in the local context.

blowekamp commented 5 years ago

Great fixes!

@jcfr You should have merge access when ready.

jcfr commented 5 years ago

Thanks for the review. I will follow up with changes later this evening.

The last one to fix is:

https://github.com/SimpleITK/SlicerSimpleFilters/blob/12efaabb0151c270e61bc7a3b3d08ad4c8db8095/SimpleFilters/SimpleFilters.py#L908-L909

Could it be simplified by simply using:

if v  == default:
  w.setCurrentIndex(w.count-1)
blowekamp commented 5 years ago

You can certainly try it as I'm not certain. Looking at the code: https://github.com/SimpleITK/SlicerSimpleFilters/blob/12efaabb0151c270e61bc7a3b3d08ad4c8db8095/SimpleFilters/SimpleFilters.py#L903

v will be something like self.filter.Ball ( e.g. for a morphological filter ) so the exec is used to get the value of that "enum".

Related I found this interesting stack overflow Q/A: https://stackoverflow.com/questions/2220699/whats-the-difference-between-eval-exec-and-compile

It sound like eval can be used if you just want the right hand side of an assignment. For example, this line in questions might be able to be changed into:

itemValue = eval(v)

This might do away with needing to muck with locals and globals.

jamesobutler commented 5 years ago

pinging status of this work @jcrf