LumaPictures / pymel

Python in Maya Done Right
Other
479 stars 130 forks source link

add window('mywin', replace=True) #331

Open pmolodo opened 8 years ago

pmolodo commented 8 years ago

From chad...@gmail.com on April 10, 2013 13:44:09

this is a common python idiom:

    if pm.window(self.NAME, exists=True):
        pm.deleteUI(self.NAME)
    self.win = pm.window(self.NAME, title='Script Layers')

we could simplify this with a replace flag that performs the same behavior:

    self.win = pm.window(self.NAME, title='Script Layers', replace=True)

Original issue: http://code.google.com/p/pymel/issues/detail?id=297

pmolodo commented 8 years ago

From tdor...@zindagigames.com on April 10, 2013 14:32:16

I agree that you can simplify it by adding the replace keyword, but I think a better question is should this be common use? The argument could be made that you should only create the window once, populate it, and then re-use it on future runs of the code. Your common pattern becomes:

self.win = getWindow(self.NAME)

where getWindow will either return the existing window or build one. This could have the side effect of encouraging MVC patterns (which I find to be a good thing) by having the getWindow function act as the view creator.

An argument against this is that during development you often need to rebuild the window but that can be solved by a small alternation to getWindow that wouldn't go into production.

kartikg3 commented 8 years ago

Has a decision been made regarding these design choices? I really love the idea of having a replace=True kwarg. Truely a common idiom, those 3 lines you pointed out, Chad.