ECToo / pymel

Automatically exported from code.google.com/p/pymel
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 reported on code.google.com by chad...@gmail.com on 10 Apr 2013 at 8:44

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
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.

Original comment by tdor...@zindagigames.com on 10 Apr 2013 at 9:32