Attention

You are viewing PyUnity docs under the develop branch. As such, they are only applicable if you installed from source. Go to https://docs.pyunity.x10.bz/en/latest/ for the most recent release.

pyunity.window.abc module


Abstract base class for window providers. Imported into pyunity.Window.

class pyunity.window.abc.ABCWindow[source]

Bases: object

Abstract base class that window providers should subclass and define methods of.

Parameters:

name (str) – Name to display on window title.

setResize(resize)[source]

Sets the resize function, which has a signature of def Resize(width, height):. This should be bound to the appropriate callback handler of the window.

Parameters:

resize (function) – Resize function

getMouse(mousecode, keystate)[source]

Get mouse state for specific mouse button and state.

Parameters:
Returns:

If the query button matches the query state. Note that both KeyState.PRESS and KeyState.DOWN will match a query of KeyState.PRESS because when a button is first hit it is still pressed down.

Return type:

bool

Notes

A good starting point is this example function:

def getMouse(self, mousecode, keystate):
    mouse = mouseMap[mousecode]
    if keystate == KeyState.PRESS:
        if self.mouse[mouse] in [KeyState.PRESS, KeyState.DOWN]:
            return True
    if self.mouse[mouse] == keystate:
        return True
    return False

where mouseMap is a mapping of MouseCode to the window provider’s own representation of mouse buttons, self.mouse is a mapping of the window provider’s own representation of mouse buttons to KeyState. This makes it easy to both query and set the keystates of the mouse.

getKey(keycode, keystate)[source]

Get key state for specific key and state.

Parameters:
Returns:

If the query key matches the query state. Note that both KeyState.PRESS and KeyState.DOWN will match a query of KeyState.PRESS because when a key is first hit it is still pressed down.

Return type:

bool

Notes

A good starting point is this example function:

def getKey(self, keycode, keystate):
    key = keyMap[keycode]
    if keystate == KeyState.PRESS:
        if self.keys[key] in [KeyState.PRESS, KeyState.DOWN]:
            return True
    if self.keys[key] == keystate:
        return True
    return False

where keyMap is a mapping of KeyCode to the window provider’s own representation of keys, self.keys is a mapping of the window provider’s own representation of keys to KeyState. This makes it easy to both query and set the keystates of the keyboard.

getMousePos()[source]

Get a tuple of (x, y) representing the position of the mouse inside the window.

Returns:

Mouse coordinates

Return type:

tuple

refresh()[source]

Refreshes and redraws the screen.

updateFunc()[source]

Update the input of keys and mouse. Also checks to quit. Don’t close the window in this method. Close it in quit() instead.

Raises:

PyUnityExit – When the window should

quit()[source]

Closes the window.