Manipulating the splitter programmatically

Once the splitter window is created, you can use window methods to manipulate the position of the sash. Specifically, you can use the method SetSashPosi-tion(position, redraw=True) to move the sash. The position is the new position in pixels, defined from the top for a horizontal sash, or from the left for a vertical one. Negative indexes are used as in the split methods to indicate position from the other side. If redraw is True, the window updates immediately, otherwise it waits for a regular window refresh. The behavior of the set method is not defined if your pixel value is out of range. To get the current sash position, use GetSashPosition().

Under the default splitter behavior, the user can move the sash anywhere between the two borders. Moving the sash all the way to one border reduces the size of one sub-window to zero, causing a de facto unsplit of the window. To prevent this, you can specify the minimum size of the sub-windows using the method SetMinimumPaneSize(paneSize). The paneSize parameter is the minimum pixel size of a sub-window. The user is prevented from dragging the sash far enough to create a smaller sub-window, and programmatic changes to the sash position are similarly constrained. As mentioned earlier in this chapter, you can allow programmatic unsplitting even in a minimum sub-window size, by declaring the window with the style wx.SP_PERMIT_UNSPLIT. To get the current minimum subwindow size, use the method GetMinimumPaneSize().

Change the split mode of the window with the method SetSplitMode(mode), where the mode parameter is one of the constants wx.split_vertical or wx.split_horizontal. If the mode changes, the top window becomes the left, while the bottom becomes the right (and vice-versa if the switch is the other way). This method does not cause a redraw of the window, instead, you must explicitly force a redraw. You can get the current split mode with GetSplitMode() which returns one of the two constant values. If the window is currently unsplit, GetSplitMode() returns the most recent split mode.

Typically, if the wx.SP_LlVE_UPDATE style is not set, the sub-windows only resizes at the end of a sash drag session. If you want to force a sub-window redraw at any other time, you can use the method UpdateSize().

Was this article helpful?

0 0

Post a comment