# Accessing the Module Window

**URL:** <https://discourse.slicer.org/t/accessing-the-module-window/2241>\
**Category:** Development\
**Created:** [March 5, 2018, 5:38pm UTC](https://discourse.slicer.org/t/accessing-the-module-window/2241 "2018-03-05T17:38:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![asheu](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@asheu](https://discourse.slicer.org/u/asheu)\
**Post date:** [March 5, 2018, 5:38pm UTC](https://discourse.slicer.org/t/accessing-the-module-window/2241/1 "2018-03-05T17:38:10Z")

</div>

Hi there,

I was wondering if there was any way to access the currently running module and its corresponding widgets through code. By this, I mean for example if I were running the Segmentation module, is it possible for me to access the module that is on the display menu, and then isolate the SliceFill widget that is present in the module?

Thank you very much for the help.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 5, 2018, 6:42pm UTC](https://discourse.slicer.org/t/accessing-the-module-window/2241/2 "2018-03-05T18:42:03Z")

</div>

Yes, you can access any module from any other module.

A module must not use another module’s GUI (the GUI is only for user interactions), but instead a module should create/modify MRML nodes and call module logic functions.

Specifically about Segment Editor - you can find here are examples for running Segment Editor effects from a Python script:  
[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How\_to\_run\_segment\_editor\_effects\_from\_a\_script](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How_to_run_segment_editor_effects_from_a_script)

---

<div class="post-metadata">

**Author:** ![asheu](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@asheu](https://discourse.slicer.org/u/asheu)\
**Post date:** [March 5, 2018, 6:47pm UTC](https://discourse.slicer.org/t/accessing-the-module-window/2241/3 "2018-03-05T18:47:17Z")

</div>

I used the segmentation editor as an example but am more specifically looking to pull the widgets out of the Reformat module. I’m having a bit of trouble locating the module (i.e, I am able to call the widgets present on the mainWindow() but could not find access to the module window) and as such, cannot find the widgets that the Reformat module has built in.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 5, 2018, 7:03pm UTC](https://discourse.slicer.org/t/accessing-the-module-window/2241/4 "2018-03-05T19:03:42Z")

</div>

You cannot reuse the module’s main GUI widgets, but usually a module widget consists of reusable widgets. How to find a widget:

- Go to Slicer’s github page: [https://github.com/Slicer/Slicer](https://github.com/Slicer/Slicer)
- Search for any text that appears in the widget, for example, for reformat widget you can search for `Normal to Camera` - [https://github.com/Slicer/Slicer/search?l=XML&q=normal+to+camera&type=&utf8=✓](https://github.com/Slicer/Slicer/search?l=XML&q=normal+to+camera&type=&utf8=%E2%9C%93)

In Reslice module’s case, search result shows that the button is in a module widget (qSlicerReformatModuleWidget.ui), so the widget is not reusable. If you are familiar with C++ then you can refactor the code to move the part you need to a separate reusable widget and use that widget in your module. However, it may be simpler to just have a look at the [module widget’s code](https://github.com/Slicer/Slicer/blob/master/Modules/Loadable/Reformat/qSlicerReformatModuleWidget.cxx) and reimplement in your code whatever you need.

Reslicing a volume using sliders is really simple to implement. See for example how it is done in ValveView module in SlicerHeart extension: [https://github.com/SlicerHeart/SlicerHeart/blob/master/ValveView/ValveView.py](https://github.com/SlicerHeart/SlicerHeart/blob/master/ValveView/ValveView.py)

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [March 5, 2018, 11:07pm UTC](https://discourse.slicer.org/t/accessing-the-module-window/2241/5 "2018-03-05T23:07:30Z")

</div>

> You cannot reuse the module’s main GUI widgets, but usually a module widget consists of reusable widgets.

To complete the answer of @lassoan, we introduced a method named [createNewWidgetRepresentation](http://apidocs.slicer.org/master/classqSlicerAbstractCoreModule.html#a4e33c1cc55d85bbf8739763f347bf906) to support creating new module representation.

In your case, the following would work:

```auto
reformatModuleWidget = slicer.modules.reformat.createNewWidgetRepresentation()
reformatModuleWidget.setMRMLScene(slicer.app.mrmlScene())
reformatModuleWidget.show()

```

That said, your module and workflow would be dependent on the layout of that specific module.

---

<div class="post-metadata">

**Author:** ![asheu](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@asheu](https://discourse.slicer.org/u/asheu)\
**Post date:** [March 6, 2018, 2:13am UTC](https://discourse.slicer.org/t/accessing-the-module-window/2241/6 "2018-03-06T02:13:07Z")

</div>

@jcfr in the scenario that you have stated above, does this not take the entire reformat module and simply create a widget elsewhere? in which case the individually packaged components would still not be retrievable, is that correct?

@lassoan thank you for the response! i will certainly take a look into the code and try to develop the widget after i figure out all the individual components of it

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [March 6, 2018, 2:43am UTC](https://discourse.slicer.org/t/accessing-the-module-window/2241/7 "2018-03-06T02:43:45Z")

</div>

> [@asheu](#):
>
> in the scenario that you have stated above, does this not take the entire reformat module and simply create a widget elsewhere? in which case the individually packaged components would still not be retrievable, is that correct?

This is correct, you would get the following:

![reformat-ui-standalone](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/7/57f62f05a381ce118df09e1f0f99b25c0df97053.png)

Then, if you only want to hide part of it, you could do something like this:

```auto
slicer.util.findChild(reformatModuleWidget, "OriginCoordinatesGroupBox").hide()

```

and you would get:

![reformat-ui-standalone-tweaked](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/1/d1e0e89fc47a095322929944cb372521d4c122de.png)

Name of the object to access is found in the associated UI file: [qSlicerReformatModuleWidget.ui](https://github.com/Slicer/Slicer/blob/0ab294089b4827fea3272417a23c321d57e391b4/Modules/Loadable/Reformat/Resources/UI/qSlicerReformatModuleWidget.ui)

This approach is suitable for fast prototyping and experimenting with UI. After, an approach is validated, I suggest to refactor the module so that you could reuse its components.

---

<div class="post-metadata">

**Author:** ![asheu](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@asheu](https://discourse.slicer.org/u/asheu)\
**Post date:** [March 6, 2018, 3:12am UTC](https://discourse.slicer.org/t/accessing-the-module-window/2241/8 "2018-03-06T03:12:47Z")

</div>

thank you so much, this has been extremely helpful
