A lightweight windowing toolkit designed for DirectPython. This is somewhat similar to the old d3dgui-module, but there are some big differences. Notably the event system has changed, the rendering code has been rewritten and many widgets have been completely rewritten.
A Manager is class that manages windows. All windows must be owned by a manager. You can have many managers running simultaneously, altough they don’t know about each other and the windows can’t interact between other windows owned by another manager.
Because the Manager must keep track of all it’s windows and windows must know their manager they form circular references (and even weak references don’t solve all issues). This is why it is recommended that you call Manager.close() when your application is closing. It is not critical but it makes sure that you don’t get any resource leak warnings when debugging.
Creates a new Manager.
Closes the manager and every window it owns. Don’t use the manager after calling this.
The found window or None.
Searches for a window. You can pass a query fuction to customize what window you want to be returned. The callback function should accept two parameters window and arg. The first is the window being tested and the second is the same as passed to findWindow(). The callback should return True if it found a satisfactory window.
#Find a window with a "Tools"-title. window = manager.findWindow("Tools")
Returns all windows that are owned by this manager.
Returns the focus window or None.
Returns the window which is currently under the mouse cursor or None.
Returns all root windows (ie. windows that don’t have a parent).
Returns the window at given coordinates or None.
An event callback which returns True if the manager handled the message.
Renders all windows.
A simple wrapper for d3d11.Window.getMessages() messages. Currently the only new attribute is sender. In certain situations many attributes can be None (for example non-user generated messages), in this case the only useful attribute is sender.
This is the base class for all other widgets. Don’t confuse this with d3d11.Window.
Creates a new Window.
Adds a child window to this window.
Centers the window inside it’s parent. If it has no parent it is centered on the srceen.
Closes the window and all it’s child windows. Don’t use the window after calling this.
Collapses or uncollapses the window.
Disabled or enables the Window and all it’s child windows. Disabled windows don’t receive any window messages.
Returns every child and descendant of the window. You can use the .children attribute to access immediate children.
Returns the client area of the window. This is the area which excludes borders, caption etc. Always in global coordinates.
Returns window’s parents as a list.
Returns the window’s rectangle as a new Rect. Always in global coordinates.
Returns the root window of a window. This will return itself if called on a root window.
This is similar to getClientRect() except that .textPad is also used when computing the area. Always in global coordinates.
Gives focus to the window.
Hides or shows the Window and all it’s child windows.
Returns True if the given coordinates hit the given window area. You can override this method if you want to make custom widgets. If the window is hidden this should always return False.
Makes the windows modal. All other windows will be disabled. When the window is closed or makeModal(False) is called other windows will be restored to the state they were when this window was made modal.
Maximizes or restores the window.
Called when a user types a character into a window. Note that control characters (newline, backspace etc.) are included too. This is a convenience callback, onKey() receives these messages as WM_KEYDOWN / WM_KEYUP. Only the focus window will receive this event.
Called when the window is about to be closed.
Called when the user is dragging the window.
Called when the user starts to drag the window.
Called when the user stops dragging the window.
Called when the window has been drag-and-dropped into another window. The “target” window will receive this event.
Called when a mouse is moving over the window. If this returns something that evaluates to True it will be passed to d3d11.Window.setCursor().
Called when the window has gained focus. By default this gives focus to the root window. If you want to keep focus on your window, override this method (just an empty stub will do).
Called when a tooltip string should be displayed. By default this returns self.toolTip.
Called when a user presses, holds down or releases a key. Only the focus window will receive this event.
Called when the window has lost focus.
Called when a mouse button has been pressed or released.
Called when the mouse enters into the window area.
Called when the mouse has left the window.
Called when the mouse is moving inside the window.
Called when the user rotates the mouse wheel. Only the focus window will receive this event.
Called when the window should draw itself.
Called when the window has been resized (by user, setRect() etc.). This is also called when the window has been moved.
Called when the user starts to resize the window.
Called when the user has stopped resizing the window.
Removes the child from window’s children. After this the child is a root window.
Resizes the window without moving it.
Sets anchor information. An anchor is a tuple of four elements which specify how the window should behave when it’s parent area is moved or resized. Element order is left, top, right, bottom. For example anchor (None, None, 10, 10) tells that right and bottom sides of the window are “anchored” and should always be 10 pixels from the parent border. Because left and top borders are not specified the size of the window will not change when the parent is resized. Another example (10, 10, 10, 10) tells that the window should always have space of 10 pixels in each direction relative to the parent. This can also cause the window to be resized when this constraint must be satisfied.
Sets the window rectangle in global coordinates. All constraints like minSize and anchor are applied to the new rectangle so the final size might not be what you specified.
Updates the window and all it’s child windows. Call this if you have changed the .minSize etc.
Alpha value of the window (from 0.0 to 1.0). Class attribute used for initialization. (R/W)
Window anchor or None. (R)
Border color in RGBA format. (R/W)
Width of the window border. (R/W)
Size of the caption buttons (close etc.) as a tuple (width, height). (R/W)
Caption color in RGBA format. (R/W)
Height of the caption. If 0 no caption is used. (R/W)
All immediate children. (R)
True if the window is currently collapsed. (R)
Background color in RGBA format. (R/W)
True if the window is currently disabled. (R)
True if the window is currently dragged by the user. (R)
True if the window is currently hidden. (R)
Maximum size of the window as a tuple (width, height). (R/W)
True if the window is currently maximized. (R)
Minimum size of the window as a tuple (width, height). (R/W)
True if the window is currently in modal state. (R)
If True the window can be moved by the user. (R/W)
Window’s parent window. (R)
If True the window can be resized by the user. (R/W)
True if the window is currently resized by the user. (R)
Content text. (R/W)
Text color in RGBA format. (R/W)
Text padding in each direction (left, top, right, bottom). (R/W)
Caption title text. (R/W)
Title text color in RGBA format. (R/W)
Tooltip text. (R/W)
When True a scissor rectangle is used when rendering children. Only used on root windows. (R/W)
True if the window has not been closed. (R)
A simple widget for displaying text. If the title attribute is set the widget will display a title with a border.
Creates a new Label.
A drop-down list of choices.
Creates a new Choice.
Adds a new choice into the control.
Called when the user has selected a value.
Removes a choice from the control.
All choice names in the control.
Index of the currently selected item.
A group of checkboxes.
Creates a new CheckBoxGroup.
Adds a new checkbox into the control.
Checks or unchecks a checkbox.
Called when a checkbox has been checked or unchecked.
Removes a checkbox from the control.
All checkbox names in the control. All objects in the list have name and checked attributes.
A radio group control.
A control for displaying images. Transparency (alpha) is supported.
Creates a new Image.
Resizes the control so that it’s pixels will map 1:1 to screen pixels. Border size is taken into account. You can call this when you have changed certain visual parameters (border size etc.).
#Width and height are changed later, they don't really matter. image = Image(window, Rect(10, 10, 1, 1), "Textures/SomeImage.png") #We want a perfect pixel mapping with a border. image.borderSize = 1 #Resize the control. image.adjustSize()
A slider class.
Creates a new Slider. By default a slider increses the size of it’s rectangle so that selectors are easier to drag with a mouse. If you don’t want this you can set the class attribute: Slider.pad = (0, 0). That disables this behaviour.
#Create a "normal" slider with one selector. slider1 = Slider(parent, Rect(10, 10, 200, 10)) slider1.range = 50 slider1.addSelector() #Create a slider with two selector so that the user can specify a range of values. slider2 = Slider(parent, Rect(10, 10, 200, 10)) slider2.range = 100 #0-99, 100 possible positions. slider2.addSelector(Selector(0, 50)) #Range 0-49, 50 possible positions. slider2.addSelector(Selector(49, 100, 99)) #Range 49-99, 50 possible positions.
Adds a new Selector into the slider. If no argument is given a default selector is created.
Called during the rendering. This should return a string that will be drawn above or under the selector. By default this returns selector.position + 1 as a string.
Called when a selector has moved.
Removes a selector.
If True a line is draw between selectors if there are more than one. They are assumed to form pairs (first-second, third-fourth etc.).
Maximum value for all selectors, non-inclusive.
All selectors. Don’t change the list itself, but you can modify it’s items.
Selector is a helper class used by the Slider.
Creates a new Selector.
True if the selector is currently dragged by the user.
Current position of the selector.
Minimum value for the selector, zero based.
Maximum value for the selector, zero based, non-inclusive.
A scroll bar class.
Creates a new ScrollBar.
Attaches the ScrollBar to it’s current parent window. Note that once a scrollbar has been attached to a window the scrollbar should not be removed (altough it can be hidden).
Returns the ScrollData from the given axis or None. The returned object is a copy and can be modified.
Called when a scrollbar has been moved. By default parent’s child windows are moved when scrolling. You can override this behaviour. Also when child windows are outside the parent’s client rectangle they are hidden (for performace reasons).
Scrolls a relative amount from current position.
Scrolls to a specific position.
ScrollData is a helper class used by the ScrollBar.
Creates a new ScrollData.
Creates a new copy from self.
Either SCROLL_X or SCROLL_Y.
True if the selector is currently dragged by the user.
Current position of the scroll bar.
Maximum value for the selector, zero based, non-inclusive.
A progress bar class.
Creates a new ProgressBar.
Called during the rendering. This should return a string that will be drawn inside the progress bar. You probably want to return different values if self.throbber is True.
Current position. This can be from 0.0 to 1.0 (inclusive).
If True the progress bar will be animated to show to the user that something is happening but that it is unknown how long it will take.
How fast the throbber should be moving.
A TextBox allows the user to type and edit text. As an implementation detail the text attribute of this class is handled by a property and getting and setting the value involves some computation overhead so using it should be avoided in speed-critical places (loops etc.). Windows clipboard operations ctrl+x/c/v are supported.
Creates a new TextBox.
Clears the box from all content.
Erases all selected text (if any).
Returns the line index at given screen coordinates. The returned index will be clamped if outside the valid range.
Returns selected text or None if no text is selected.
Returns the text selection data (start, end). If no text is selected both values will be None. Otherwise they are tuples: (lineindex, charindex, xcoordinate).
Inserts text at the current caret position.
Called when the contents of the text box have changed. This might be called several times and in certain cases no actual changes have occurred. This can happen if the user selects text and then pastes the same text. First the selected text is erased and then the new one is inserted. The contents did change but the end result is same.
Moves the caret to the given position. Both arguments will be clamped if outside the valid range.
Sets the caret at the given screen coordinates.
Stops text selection.
A list of all lines in the control.
If True no line breaks are allowed.