Yea, to me it just seems like a layer of complexity that is mostly sugar. I feel the only thing the with statement really gives you is that indented display and handles resetting the parent UI. But is now broken for Menu classes and its subclasses.
Personally, I never found a need to see UI descriptions in a tab-indented format in order to understand them. In PyQt you don't see that, and they don't use with statements to try and accomplish it. As long as I know who the parent is, thats pretty much enough information for me. And you can always separate them into blocks using empty lines, and comments. This is actually a perfect example of the point I was making in my video, when I was saying I didn't want to teach PyMel in a general 'learning python for maya' tutorial. Its a 3rd party wrapper around the api. The api and commands are subject to change at the will of Autodesk, and you rely on the maintainer of PyMel to stay on top of the changes and keep the wrappers in sync. Whats great about knowing the api and commands module directly is that when 3rd party wrappers break, you still know how to get your task done. It can put you into a pickle if you only learn the PyMel idioms (not saying you did specifically...just a general observation), and then suddenly can't use them. I'm all for being more pythonic and less C++ oriented, but it would have been even better if autodesk actually maintained an official python api that IS pythonic. I saw a doc in 2012 that actually had the NEW Python API (2.0) that does in fact try to be more pythonic in its function calls and return values. As for the with statement and Menus, maybe something changed from 2010 -> 2011, because its broken as of 2011 On Sun, Nov 13, 2011 at 2:22 AM, simonp91 <[email protected]> wrote: > Thats what i thought. But the optionMenu was the simple example. The same > problem seems to apply to a lot of things, but mostly, if you are writing > ui's using 'with' statements, and you stop using it, for perhaps an > optionMenu, it seems you may not then continue the 'with' statements > afterwards. This is definitly the case with frameLayouts and > tabLayouts..only works once, then you can't go back into a 'with'. What i > was trying to do was to use a tabLayout in a formLayout, in a frameLayout, > as you do, then on one of the tabs, it was to contain another frameLayout > with a form and another set of tabs. In fact, tabs just don't work using > 'with' at all, because you have to edit the formlayout with tab > descriptions from within the 'with' indent level which fsils saying it > can't find the forLayout, even though you've both named it and decalred it > 'with ... as .. ' and not even if you give the full path to the formLayout. > > I though 'with' statements were put there to auf ui design by allowing > you to use mel style indenting for clearer ui code sectioning. But it seems > it just does'nt work. > > Sent from my iPhone > > On 12 Nov 2011, at 23:46, Justin Israel <[email protected]> wrote: > > > Seems like a bug in PyMel... > > > > Class OptionMenu -> PopupMenu -> Menu > > Menu has a makeDefault() command that is called from the __enter__() > context switch and tries to setParent(menu=True) > > But an optionMenu does not allow a setParent() command to be called on > it... > > > > Example: > > > > win = cmds.window() > > cmds.columnLayout() > > m = cmds.optionMenu() > > cmds.setParent(m, menu=True) > > # RuntimeError: setParent: Object 'window3|columnLayout6|optionMenu4' > not found. # > > > > Solution is probably don't use a with statement on the OptionMenu, as > the context switching is not set up correctly. > > > > -- justin > > > > > > > > > > On Nov 7, 2011, at 8:33 AM, simon payne wrote: > > > >> So I am having a few issues using with statements to tab out my UI > >> code. below is a very simplistic example. The biggest problem is that > >> when laying out tabLayouts, you must first declare a formLayout, then > >> the tabLayout, then edit the form to attach the tabs. If you try this > >> entirely within 'with' statements it fails. If you remove the 'with' > >> statement from the line to edit the form and leave as pyMel, it works > >> fine...BUT, it seems you cannot then continue using 'with' statements > >> for the content of that tab. The following code uses the example from > >> the pyMel docs, which fails for the same reason : > >> > >> from __future__ import with_statement > >> from pymel.core import * > >> template = uiTemplate( 'ExampleTemplate', force=True ) > >> template.define( button, width=100, height=40, align='left' ) > >> template.define( frameLayout, borderVisible=True, labelVisible=False ) > >> > >> with window(menuBar=True,menuBarVisible=True) as win: > >> # start the template block > >> with template: > >> with columnLayout( rowSpacing=5 ): > >> with frameLayout(): > >> with columnLayout(): > >> button( label='One' ) > >> checkBox() > >> with frameLayout(): > >> button() > >> with optionMenu() as optM: > >> menuItem (l='test') > >> menuItem (l='test2') > >> > >> ##### However, if we use : > >> optionMenu() > >> menutItem(l='test') > >> > >> it works just fine. > >> > >> -- > >> view archives: http://groups.google.com/group/python_inside_maya > >> change your subscription settings: > http://groups.google.com/group/python_inside_maya/subscribe > > > > -- > > view archives: http://groups.google.com/group/python_inside_maya > > change your subscription settings: > http://groups.google.com/group/python_inside_maya/subscribe > > -- > view archives: http://groups.google.com/group/python_inside_maya > change your subscription settings: > http://groups.google.com/group/python_inside_maya/subscribe > -- view archives: http://groups.google.com/group/python_inside_maya change your subscription settings: http://groups.google.com/group/python_inside_maya/subscribe
