- Notifications
You must be signed in to change notification settings - Fork2
Cross-Platform and multi-monitor toolkit to handle rectangular areas and windows box
License
Kalmat/PyWinBox
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Cross-Platform and multi-monitor module which allows to manage window areas (position andsize) and all their properties, as well as any rectangular area.
You just need to instantiate the PyWinBox class, passing custom callbacks to be called when any property isqueried (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.
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 handlesusing 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, theinformation contained in the PyWinBox class, and returned by all properties, will likely become obsolete. So, you canuse both in your custom callback:
def customOnQuery(): currBox = myBox.onQuery() # This will retrieve the current window's box # ... do your stuff ... return currBoxdef 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)left, top, right, bottomsize, width, heighttopleft, bottomleft, topright, bottomrightmidtop, midleft, midbottom, midrightcenter, centerx, centerybox (left, top, width, height)rect (left, top, right, bottom)These are useful data structs (named tuples, actually) you can use to better manage the values:
Box: left, top, width, heightRect: left, top, right, bottomSize: width, heightPoint: x, yTo install this module on your system, you can use pip:
pip3 install pywinboxor
python3 -m pip install pywinboxAlternatively, you can download the wheel file (.whl) available in theDownload page and thedist folder, and run this (don't forget to replace 'x.x.xx' with proper version number):
pip install PyWinBox-x.x.xx-py3-none-any.whlYou may want to add--force-reinstall option to be sure you are installing the right dependencies version.
Then, you can use it on your own projects just importing it:
import pywinboxIn case you have a problem, comments or suggestions, do not hesitate toopen issues on theproject homepage
If you want to use this code or contribute, you can either:
- Create a fork of therepository, or
- Download the repository, uncompress, and open it on your IDE of choice (e.g. PyCharm)
Be sure you install all dependencies described on "requirements.txt" by using pip
To test this module on your own system, cd to "tests" folder and run:
python3 test_pywinbox.pyFor macOS NSWindow, you can also test using:
python3 test_MacNSBox.pyAbout
Cross-Platform and multi-monitor toolkit to handle rectangular areas and windows box
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.