简体   繁体   English

traitsui编辑器的当前大小

[英]current size of traitsui editor

I have a tvtk SceneEditor for a mayavi scene in my traitsui application. 我的traitsui应用程序中有一个mayavi场景的tvtk SceneEditor。 When defining this editor, I asked it to have size 500x500. 定义此编辑器时,我要求其尺寸为500x500。

Because of the mayavi toolbar, the scene editor itself understands that it has a smaller size than this under normal circumstances: 由于使用了mayavi工具栏,因此场景编辑器本身可以理解,在正常情况下,其大小小于此大小:

>>> self.scene.scene_editor.get_size()
wx.Size(500, 468)

And when the window is enlarged so that the editor takes up much more space, it understands this too 当窗口扩大以使编辑器占用更多空间时,它也可以理解

>>> self.scene.scene_editor.get_size()
wx.Size(500, 781)

However, if the editor is made much smaller, it refuses to take up less space (even if the contents could easily be rescaled) because the editor was specified to take up 500x500. 但是,如果使编辑器小得多,则它会拒绝占用较少的空间(即使可以轻松地缩放内容),因为已指定编辑器占用500x500。 It allows the editor to be resized, but just cuts off part of the display until it is enlarged again. 它允许调整编辑器的大小,但是只剪掉一部分显示,直到再次放大为止。

I want to know if there is a way to a) ask how much of the editor is currently displayed on the screen (instead of the minimum size the editor is willing to display) and b) make the editor default to 500x500 but be willing to ask its contents to rescale themselves if it is made smaller. 我想知道是否有办法a)询问当前在屏幕上显示多少编辑器(而不是编辑器愿意显示的最小尺寸),以及b)将编辑器默认设置为500x500,但愿意询问其内容是否缩小以重新调整规模。

I am using the wxpython backend. 我正在使用wxpython后端。

edit: It is also important that the scene is contained within a layout='split' Group -- after exploring this question and running into the enormous number of sizers that wx generates when adding traitsui widgets, I realized this might matter as well. 编辑:将场景包含在layout='split'组中也很重要-在研究了这个问题并遇到wx添加traitsui小部件时生成的大量sizer之后,我意识到这也很重要。

After hacking around for a few days, I have an answer to part a) (though it is hacky and not necessarily general purpose and it might be specific to the layout='split' layout). 潜入几天后,我对a)部分有一个答案(尽管它是易破解的,不一定是通用的,并且可能特定于layout='split'布局)。

self.scene.scene_editor.control.Parent.Parent.Size describes the size of the viewport in which the editor is being displayed, at least with layout='split' but I can easily imagine that it would be different for other layout types (which I didn't test). self.scene.scene_editor.control.Parent.Parent.Size描述了要在其中显示编辑器的视口的大小,至少使用layout='split'但我可以很容易地想象到,对于其他布局类型,它会有所不同(我没有测试过)。

Armed with this information, I managed to write a wrapper that resizes the editor to be at least this small before making snapshots. 掌握了这些信息之后,我设法编写了一个包装器,该包装器在制作快照之前将编辑器的大小调整为至少如此之小。

More gory details: 更多血腥细节:

The sizer associated with self.scene.scene_editor.control isn't the right one, probably because that sizer refers to the window containing the editor, whereas the sizer associated with the size of window within the containing splitter widget is allowed to "cover" that window and ignore its size. self.scene.scene_editor.control关联的sizer不是正确的,可能是因为该sizer指向包含编辑器的窗口,而与包含splitter窗口小部件内的窗口大小相关的sizer被“覆盖”了该窗口并忽略其大小。

I found out that the process of adding traitsui widgets defines so many boxes (assuming a nontrivial number of widgets) that there result is this enormous glut of wx Windows with their associated wx Sizers that all depend on their child widgets to determine the current size, so it is extremely difficult to control things like this. 我发现添加traitsui小部件的过程定义了太多的框(假设小部件的数量非常少),结果是大量的wx Windows及其关联的wx Sizer都依赖于其子小部件来确定当前大小,因此控制这样的事情非常困难。 This is probably why enaml exists; 这可能是enaml存在的原因。 so that these constraints can be explicitly specified by the user. 以便用户可以明确指定这些约束。 Maybe someday I will convert my program to use enaml, but that seems like a lot of effort for something that currently works pretty well. 也许有一天,我会将我的程序转换为使用enaml,但是对于目前运行良好的某些事情来说,这似乎需要付出很多努力。

I still don't have an answer to part b), so I am leaving this question open. 对于b)部分,我仍然没有答案,所以我将这个问题保留。 It would be nice if there were a way to specify at construction to the mess of wx sizers that resizing this window below its initial size is allowed, but there probably isn't one. 如果有一种方法可以指定构造成使wx sizer混乱的一种方法,那就是允许将此窗口的大小调整为小于其初始大小,但可能没有这种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM