Home Website Youtube GitHub

Creating new modal dialogue

We have created new component to similar to chain_guide_initializer. I would like to see that modal dialogue when I hit Draw component. how do I do that? 2021-09-30_22h03_48

1 Like

Hi @meetketki this is a good question, and I haven’t totally figured it out yet. Did you make any progress?

(In this answer, I’ll refer to line numbers. I’m looking in the code base for mGear 3.6.0 so line numbers may have changed in later versions.)

  1. I know the Chain initializer window comes from

mgear_X.X.X/release/scripts/mgear/shifter/component/chain_guide_initializer.py

  1. And that gets imported by the more generic guide.py.

mgear_X.X.X/release/scripts/mgear/shifter/component/guide.py

  1. And then in guide.py, around line 400, you find
    def modalPositions(self):
        """Launch a modal dialog to set position of the guide."""
        self.sections_number = None
        self.dir_axis = None
        self.spacing = None

        for name in self.save_transform:

            if "#" in name:

                init_window = chain_guide_initializer.exec_window()

  1. And then if you look into a Shifter component, such as the spring chain you’ll find this, where the self.save_transform has the # in the name, which triggers that function to run:

mgear_X.X.X/release/scripts/mgear/shifter_classic_components/chain_spring_01/guide.py around line 36.

    def postInit(self):
        """Initialize the position for the guide"""
        self.save_transform = ["root", "#_loc"]
        self.save_blade = ["blade"]
        self.addMinMax("#_loc", 1, -1)

And that’s as far as I got. I hope that’s enough clues for you to untangle the logic.

1 Like

I must admit, this stumped me for a while before I figured it out. I don’t like this implementation. I’d much prefer a simple, readable way to envoke on the “intitalizer” window where you set a variable to enable it’s use and override the default if required.

Sudo code…
`
class MyCustomComponent:
use_inititalizer = True

def show_initializer(self):
if self.use_initialzer:
self.exec_initializer()

def exec_initializer(self):
“”" Override this default implementation if required “”""
init_window = chain_guide_initializer.exec_window()
`