br /> 您可以任意缩进这些。另外,你不必太担心匹配setParent和其他命令。 这对我有意义。在那个 例子中使用的库并没有让我觉得非常像Pythonic(使用一个 命令对象来处理所有事情并调用setParent('') ..'')指向 层次结构中的下一个对象)。但是,我没有理由(据我所知),他无法创造帮助函数来包裹它,因为 更加理智。 12月18日下午5:18,Sam< L33tmin ... @ gmail.comwrote: On 12月18日,晚上7:09,Jonathan Gardner < jgardner.jonathangardner .... @ gmail.comwrote: 12月18日下午2:16,Sam< L33tmin ... @ gmail.comwrote: layouts = [''column'',''form'',''frame''] cmds.window(t =''gwfUI Builder'') cmds.paneLayout(configuration =''vertical3'',ps =((1,25,100),(3,20, 100))) cmds .paneLayout(configuration =''horizo​​ntal2'') cmds.frameLayout(l =''Layouts'') cmds.scrollLayout (cr = True) cmds.columnLayout(adj = True,cat =('''',2)) for i in layouts: cmds.button(l = i) cmds.setParent(''..'') cmds.setParent(''..''') cmds.setParent(''..'') cmds.setParent(''..'') cmds.setParent( ''..'') cmds.showWindow() 格兰特拉他的头发在 月亮中大吼大叫,让我试着解释为什么你永远不想缩进代码那样的方式,更不用说以这种方式编写代码了。 如果你必须以嵌套方式运行一系列代码, 就像这样,它'''最好创建函数然后嵌套函数。 当然,我正在考虑更多的lisp解决方案而不是C语言解决方案。 在这种情况下,你将不得不拥有知道什么的对象(或数据 结构)要执行必要的命令。 当你把它们全部组装好后,你只需以递归的方式运行它们。 例如: cmd.build((''' pane'',dict(configuration =''horizo​​ntal''),(''frame'', dict(l =''Layouts''),(....)))) 您可以任意缩进这些。另外,你不必太担心匹配setParent和其他命令。 这对我有意义。在那个 例子中使用的库并没有让我觉得非常像Pythonic(使用一个 命令对象来处理所有事情并调用setParent('') ..'')指向 层次结构中的下一个对象)。但是没有理由(据我所知),他无法创造帮助函数来包装它,而是更加理智。 让我补充一点,对于大量的GUI布局,大多数编程语言 都是错误的工具。 GUI布局涉及大量嵌套的,几乎是锅炉板类型的数据。使用工具生成代码可以加载的布局,并执行您可能需要的一些调整。 这使得事情变得更加清晰,特别是对于任何人必须 以后维护布局。 缺少这样的布局工具是GUI库的弱点,而不是 必然是程序语言的问题。 --Jason A friend of mine is picking up some Python and is frustrated byPython''s indentation rules (http://greatbiggary.livejournal.com/260460.html?thread=1835884#t1835884). Personally, I''ve never had anyissues with Python''s ways of indentation, but that conversation got methinking about the issue. Consider the following indentation rules:1. Blocks begin with a line ending in ":"2. A line on the same indentation level or lower ends a block. Under those rules, this would work:layouts = [''column'', ''form'', ''frame'']cmds.window(t=''gwfUI Builder'')cmds.paneLayout(configuration=''vertical3'', ps=((1, 25, 100), (3, 20,100)))cmds.paneLayout(configuration=''horizontal2'')cmds.frameLayout(l=''Layouts'')cmds.scrollLayout(cr=True)cmds.columnLayout(adj=True, cat=(''both'', 2))for i in layouts:cmds.button(l=i)cmds.setParent(''..'')cmds.setParent(''..'')cmds.setParent(''..'')cmds.setParent(''..'')cmds.setParent(''..'')cmds.showWindow() Do such rules make sense? Is there any way to make code work that wayin Python? Should there be? Does that make this sort of code more orless readable? P.S. I''m definitely not looking for a tabs vs. spaces flamewar here.That''s a different issue. 解决方案 On Dec 18, 2:16 pm, Sam <[email protected]:layouts = [''column'', ''form'', ''frame'']cmds.window(t=''gwfUI Builder'')cmds.paneLayout(configuration=''vertical3'', ps=((1, 25, 100), (3, 20,100))) cmds.paneLayout(configuration=''horizontal2'') cmds.frameLayout(l=''Layouts'') cmds.scrollLayout(cr=True) cmds.columnLayout(adj=True, cat=(''both'', 2)) for i in layouts: cmds.button(l=i) cmds.setParent(''..'') cmds.setParent(''..'') cmds.setParent(''..'') cmds.setParent(''..'')cmds.setParent(''..'')cmds.showWindow() While Grant is pulling his hair out and yelling obscenities at themoon, let me try to explain why you''d never want to indent code thatway, let alone write code that way. In cases where you have to run a sequence of code in a nested way,like this, it''s best to create functions and then nest the functions.Of course, I''m thinking more of a lisp solution and less of a C one. In this case, you''re going to have to have objects (or datastructures) that know what to do to execute the commands necessary.When you get them all assembled, you simply run them in a recursiveway. For instance: cmd.build((''pane'', dict(configuration=''horizontal''), (''frame'',dict(l=''Layouts''), (....)))) You can indent these arbitrarily. Plus, you don''t have to worry toomuch about matching setParent and the other commands.On Dec 18, 7:09 pm, Jonathan Gardner<[email protected]:On Dec 18, 2:16 pm, Sam <[email protected]: layouts = [''column'', ''form'', ''frame''] cmds.window(t=''gwfUI Builder'') cmds.paneLayout(configuration=''vertical3'', ps=((1, 25, 100), (3, 20, 100))) cmds.paneLayout(configuration=''horizontal2'') cmds.frameLayout(l=''Layouts'') cmds.scrollLayout(cr=True) cmds.columnLayout(adj=True, cat=(''both'', 2)) for i in layouts: cmds.button(l=i) cmds.setParent(''..'') cmds.setParent(''..'') cmds.setParent(''..'') cmds.setParent(''..'') cmds.setParent(''..'') cmds.showWindow() While Grant is pulling his hair out and yelling obscenities at themoon, let me try to explain why you''d never want to indent code thatway, let alone write code that way.In cases where you have to run a sequence of code in a nested way,like this, it''s best to create functions and then nest the functions.Of course, I''m thinking more of a lisp solution and less of a C one.In this case, you''re going to have to have objects (or datastructures) that know what to do to execute the commands necessary.When you get them all assembled, you simply run them in a recursiveway.For instance: cmd.build((''pane'', dict(configuration=''horizontal''), (''frame'',dict(l=''Layouts''), (....))))You can indent these arbitrarily. Plus, you don''t have to worry toomuch about matching setParent and the other commands.That makes sense to me. The library that was being used in thatexample didn''t strike me as very Pythonic (what with the using onecommand object for everything and calling setParent(''..'') to point tothe next object up in the hierarchy). But there''s no reason (as faras I know) that he couldn''t create helper functions to wrap that withsomething more sane.On Dec 18, 5:18 pm, Sam <[email protected]:On Dec 18, 7:09 pm, Jonathan Gardner <[email protected]: On Dec 18, 2:16 pm, Sam <[email protected]: layouts = [''column'', ''form'', ''frame''] cmds.window(t=''gwfUI Builder'') cmds.paneLayout(configuration=''vertical3'', ps=((1, 25, 100), (3, 20, 100))) cmds.paneLayout(configuration=''horizontal2'') cmds.frameLayout(l=''Layouts'') cmds.scrollLayout(cr=True) cmds.columnLayout(adj=True, cat=(''both'', 2)) for i in layouts: cmds.button(l=i) cmds.setParent(''..'') cmds.setParent(''..'') cmds.setParent(''..'') cmds.setParent(''..'') cmds.setParent(''..'') cmds.showWindow() While Grant is pulling his hair out and yelling obscenities at the moon, let me try to explain why you''d never want to indent code that way, let alone write code that way. In cases where you have to run a sequence of code in a nested way, like this, it''s best to create functions and then nest the functions. Of course, I''m thinking more of a lisp solution and less of a C one. In this case, you''re going to have to have objects (or data structures) that know what to do to execute the commands necessary. When you get them all assembled, you simply run them in a recursive way. For instance: cmd.build((''pane'', dict(configuration=''horizontal''), (''frame'', dict(l=''Layouts''), (....)))) You can indent these arbitrarily. Plus, you don''t have to worry too much about matching setParent and the other commands. That makes sense to me. The library that was being used in thatexample didn''t strike me as very Pythonic (what with the using onecommand object for everything and calling setParent(''..'') to point tothe next object up in the hierarchy). But there''s no reason (as faras I know) that he couldn''t create helper functions to wrap that withsomething more sane.Let me add that, for lots of GUI layout, most programming languagesare the wrong tool for the job. GUI layout involves tons of nested,almost boiler-plate type data. Use a tool to generate the layout thatthe code can load, and perform the few tweaks that you might need.This makes things far more sane, especially for anyone who has tomaintain the layout later. The lack of such a layout tool is a weakness of your GUI library, notnecessarily a problem with the program language. --Jason 这篇关于允许Python中的任意缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-25 05:29