Cross-Platform and multi-monitor toolkit to handle rectangular areas and windows box
Low maintenance activity. Last release over 2 years ago, commits in 3 of the last 26 weeks. Weaker on commit activity and recent releases.
pip install pywinboxPyWinBox
Cross-Platform and multi-monitor module which allows to manage window areas (position and size) and all their properties, as well as any rectangular area.
Rectangular areas
You just need to instantiate the PyWinBox class, passing custom callbacks to be called when any property is queried (onQuery) or set (onSet).
myBox = pywinbox.PyWinBox(onQuery=customOnQuery, onSet=customOnSet)
For rectangular areas, it is necessary to pass custom (not default) callbacks which actually manage the box struct values, or the struct will be empty and useless.
Window areas
To manage window areas, you need to also pass the window handle when instantiating the class, in the following formats:
- MS-Windows: integer (window id) or str (as returned by, e.g., PyQt's winId() method)
- Linux: integer (window id) or X-Window object
- macOS / foreign window: in case you want to manage a window from another application, you must pass target app and window names, as a tuple of strings (appName, windowTitle)
- macOS / own window: if you want to manage your own application window, you must pass NSWindow() object
(Search for cross-platform modules if you need a cross-platform handle. For instance, you can get this kind of handles using PyWinCtl's getHandle(), getAppName() or title methods)
In this case, you can use the default methods to manage the window when its properties are queried or set:
- default OnQuery: Will update the window position and size values when any property is queried
- default OnSet: Will move and/or resize the window when any property is set
To use default methods, just pass them as None, like this:
myBox = pywinbox.PyWinBox(onQuery=None, onSet=None, handle=windowHandle)
Of course, you can also define (and pass) your own custom functions if you need to perform other actions on these events.
In this case, if your custom functions do not properly retrieve or set the actual window position and size, the information contained in the PyWinBox class, and returned by all properties, will likely become obsolete. So, you can use both in your custom callback:
def customOnQuery():
currBox = myBox.onQuery() # This will retrieve the current window's box
# ... do your stuff ...
return currBox
def customOnSet(newBox: Box):
myBox.onSet(newBox) # This will actually move/resize the window
# ... do your stuff ...
myBox = pywinbox.PyWinBox(onQuery=customOnQuery, onSet=customOnSet, handle=windowHandle)