arrangeit
– Application package¶
arrangeit.__main__
– Main module of the arrangeit application¶
-
arrangeit.__main__.
main
()¶ Retrieves, instantiates and runs platform specific app.
Configures simple logger too.
arrangeit.base
– Base classes holding common code for all the platforms¶
-
class
arrangeit.base.
BaseApp
¶ Bases:
object
Base App class holding common code for all the platforms.
Variables: - BaseApp.controller – object that connects data and presentation
- BaseApp.collector – object responsible for collecting windows data
-
activate_root
(*args)¶ Method must be overridden.
-
change_setting
(name='', value=None)¶ Changes provided setting name to provided value
and saves it to user settings file.
If name startswith _ it means we want to change theme part, so it calls and returns
change_settings_color_group()
.Parameters: - name (str) – setting name to save
- value (int/float/str) – setting value to save
-
change_settings_color_group
(group='', value=None)¶ Changes values for all settings ending with provided
group
and saves them to user settings file.
Parameters: - group (str) – settings group to save
- value (int/float/str) – setting value to save
-
collector
= None¶
-
controller
= None¶
-
create_snapping_sources
(for_model)¶ Returns collection of snapping rectangless grouped by workspace.
Snapping rectangle is created around window connected edge points pair with height (or width) of 2*SNAP_PIXELS and width (or height) of related window side. Snapping rects for all available monitors are created for each workspace.
Parameters: for_model ( WindowModel
) – current modelReturns: dict (int: list of four-tuples)
-
grab_window_screen
(model, root_wid=None)¶ Method must be overridden.
-
move
(*args)¶ Method must be overridden.
-
move_and_resize
(*args)¶ Method must be overridden.
-
move_to_workspace
(*args)¶ Method must be overridden.
-
rerun_from_window
(wid, remove_before)¶ Restart positioning routine from the window with provided wid
without already positioned/skipped windows.
Parameters: wid (int) – windows identifier
-
run
()¶ Collects data, prepare them for view and finally shows view application.
-
run_task
(task, *args)¶ Runs provided task with provided args
Parameters: task (str) – task name
-
save_default
()¶ Saves collection to default filename in user’s directory.
Creates application’s user data directory if it not exists.
-
screenshot_cleanup
()¶ Override if platform needs cleanup after screenshot is taken.
-
setup_collector
()¶ Returns platform specific Collector class.
-
setup_controller
()¶ Returns platform specific Controller class.
-
class
arrangeit.base.
BaseCollector
¶ Bases:
object
Base Collector class holding common code for all the platforms.
Variables: collection – collection of WindowModel
instances-
add_window
(win)¶ Method must be overridden.
-
check_window
(win)¶ Method must be overridden.
-
collection
= None¶
-
get_available_workspaces
()¶ Method must be overridden.
-
get_monitors_rects
()¶ Method must be overridden.
-
get_smallest_monitor_size
()¶ Returns size of the smallest monitor.
Returns: tuple (w,h)
-
get_windows
()¶ Method must be overridden.
-
get_workspace_number
(workspace)¶ Method must be overridden.
-
get_workspace_number_for_window
(win)¶ Method must be overridden.
-
is_applicable
(window_type)¶ Method must be overridden.
-
is_resizable
(window_type)¶ Method must be overridden.
-
is_restored
(window_type)¶ Method must be overridden.
-
is_valid_state
(window_type, window_state)¶ Method must be overridden.
-
run
()¶ Populates
collection
with WindowModel instancescreated from the windows list provided by
get_windows()
after they are checked for compliance withcheck_window()
by callingadd_window()
.Variables: win – current window instance/handle in the loop
-
-
class
arrangeit.base.
BaseController
(app)¶ Bases:
object
Base Controller class holding common code for all the platforms.
Variables: - BaseController.app – platform specific parent app
- model – model holding window data
- BaseController.generator – generator for retrieving model instances from collection
- BaseController.view – Tkinter application showing main window
- BaseController.mouse – class responsible for mouse events and queuw
- state – controller’s state (LOCATE+0..3, RESIZE+0..3 or OTHER)
- default_size – default root window size (width, height)
- screenshot_widget – widget holding background image
- screenshot – screenshot image of the window model
- BaseController.screenshot_when_exposed – should wait for window exposure
- snapping_targets – dictionary of snapping rectangles grouped by workspace number
- BaseController.timer – id of active timer
-
app
= None¶
-
apply_snapping
(new_x, new_y, sources, intersections)¶ Moves cursor and sets new state and corner if snapping occured on new side.
State and corner can change only for positioning phase, so for resizing phase this method just calls and returns
BaseMouse.move_cursor()
.Parameters: - new_x (int) – new cursor position on x-axis
- new_y (int) – new cursor position on y-axis
- sources (tuple of
Rectangle
) – four-tuple of root window snapping rectangles - intersections (tuple) – one or two pairs of snapping rectangles that intersect
Variables: new_state – positioning state
-
change_position
(x, y)¶ Changes root window position to provided x and y
if snapping criteria is not satisfied.
Parameters: - x (int) – absolute horizontal axis mouse position in pixels
- y (int) – absolute vertical axis mouse position in pixels
-
change_setting
(name, value)¶ Calls task for changing provided settings name to provided value.
Parameters: - name (str/int/float) – setting name
- value – value to change the setting to
-
change_size
(x, y)¶ Changes root window size in regard to provided current x and y
related to model’s changed x and y if calculated size won’t be smaller than minimum and if snapping criteria isn’t satisfied.
Parameters: - x (int) – absolute horizontal axis mouse position in pixels
- y (int) – absolute vertical axis mouse position in pixels
Variables: - position – eventual position of minimum sized root
- width – root window calculated width
- height – root window calculated height
- left – root window calculated position on x-axis
- top – root window calculated position on y-axis
-
check_current_size
(x, y)¶ Returns True if current size in resizing phase is greater than minimum size
defined in settings.
Parameters: - x (int) – absolute horizontal axis mouse position in pixels
- y (int) – absolute vertical axis mouse position in pixels
Returns: tuple position (int, int) or False
-
check_mouse
()¶ Runs method that corresponds to retrieved item from mouse queue.
There are only two possibilities for item type: Boolean (scroll direction) or tuple (mouse position).
Method calls itself in regular interval defined in settings.
-
check_snapping
(x, y)¶ Snaps root window and returns True if root window intersects
with any collection window according to snapping rects in current workspace or returns False if no snapping has occurred.
Calls
apply_snapping()
to change state and corner if snapping occurs on different corner that current state/corner.Parameters: - x (int) – absolute horizontal axis mouse position in pixels
- y (int) – absolute vertical axis mouse position in pixels
Variables: - sources – four-tuple of root window snapping rectangles
- intersections – one or two pairs of snapping rectangles that intersect
- offset – offset for axes
Returns: Boolean
-
check_snapping_state
(sources, intersections)¶ Returns new state changed by snapping or None if state should not be changed.
Parameters: - sources (tuple of
Rectangle
) – four-tuple of root window snapping rectangles - intersections (tuple) – one or two pairs of snapping rectangles that intersect
Variables: - new_state – positioning state
- index0 – position of root’s first intersected snapping rectangle in sources
- index1 – position of root’s second intersected snapping rectangle in sources
- sources (tuple of
-
cycle_corners
(counter=False)¶ Cycle through corners in positioning phase by changing state.
-
default_size
= None¶
-
display_message
(message, permanent=False)¶ Displays informational message in view’s status bar.
Variables: message – message to display
-
generator
= None¶
-
get_root_rect
(x, y)¶ Returns current root position and size calculated from provided x, y.
Parameters: - x (int) – current horizontal axis mouse position in pixels
- y (int) – current vertical axis mouse position in pixels
Returns: (int, int, int, int)
-
listed_window_activated
(wid)¶ Calls task that restarts positioning routine from provided window id
not including windows prior to current model.
Parameters: wid (int) – windows identifier
-
listed_window_activated_by_digit
(number)¶ Activates listed window by its ordinal in list presented by provided number.
Parameters: number (int) – number of 1 to 16 representing ordinal in list Variables: windows – available workspaces in view
-
mainloop
()¶ Tkinter main loop.
-
model
= None¶
-
mouse
= None¶
-
mouse_move
(x, y)¶ Moves root Tkinter window to provided mouse coordinates.
Parameters: - x (int) – absolute horizontal axis mouse position in pixels
- y (int) – absolute vertical axis mouse position in pixels
-
mouse_scroll
(counter=False)¶ Cycles through window corners in both directions.
Parameters: counter (Boolean) – is scroll in counter direction
-
move_to_corner
()¶ Configures mouse pointer and moves cursor to calculated corner position.
Variables:
-
next
(first_time=False, from_workspace=None)¶ Sets controller
model
attribute from the value yielded fromgenerator
and populates view widgets with new model data.
Sets program to be in positioning phase by setting LOCATE state. Also changes and moves cursor and root window to model’s window position. Grabs and sets screenshot image of the model’s window. If there are no values left in collection then saves and exits app. Switches workspace if it’s changed.
Parameters: - first_time (Boolean) – is method called for the very first time
- from_workspace (int) – workspace passed if listed window activated
Variables: old_workspace – old model’s workspace number
Returns: Boolean
-
on_continue
(event)¶ Restarts positioning routine.
-
on_focus
(event)¶ Calls task top activate root if Tkinter has lost focus.
-
on_key_pressed
(event)¶ Calls method related to pressed key.
Parameters: event (Tkinter event) – catched event
-
on_mouse_left_down
(event)¶ Calls
update
with current cursor positionParameters: event (Tkinter event) – catched event
-
on_mouse_middle_down
(event)¶ Switches to third state.
Parameters: event (Tkinter event) – catched event
-
on_mouse_right_down
(event)¶ Skips the current model.
Parameters: event (Tkinter event) – catched event
-
on_resizable_change
(event)¶ Switches model resizable attribute.
-
on_restored_change
(event)¶ Switches model restored attribute.
-
place_on_opposite_corner
()¶ Changes and moves cursor to model windows corner opposite to positioning phase
and so triggers master resizing.
Variables: - left – x-axis part of the cursor position
- top – y-axis part of the cursor position
-
place_on_top_left
()¶ Moves cursor to model’s top left position and setups that corner
widget and cursor.
-
prepare_view
()¶ Populates view’s workspaces and windows list widgets.
Very first window is our main window so we skip it in listing.
-
recapture_mouse
()¶ Starts mouse listener and positioning/resizing routine.
-
release_mouse
()¶ Stops positioning/resizing routine and releases mouse.
-
remove_listed_window
(wid)¶ Destroys window widget from windows list and refreshes the list afterward.
Parameters: wid (int) – id of window that will be destroyed
-
resizing_state_counterpart
()¶ Returns resizing counterpart to current positioning state.
-
run
(generator)¶ Prepares view, syncs data, starts mouse listener and enters main loop.
Calls
prepare_view()
to create workspaces and windows list widgets. Sets generator attribute to provided generator and sets window data by callingnext()
for the first time. Calls view application startup routine to show root and calculate visible parameters. Also brings global focus to root window.
-
save
()¶ Runs task for saving windows collection data to default file.
-
screenshot
= None¶
-
screenshot_when_exposed
= False¶
-
screenshot_widget
= None¶
-
set_default_geometry
(root)¶ Sets provided root window width and height
calculated from available width and height for screen as quarter of the smaller element. Returned width and height have 16:9 aspect ratio.
Parameters: root (
tkinter.Tk
instance) – root tkinter windowVariables: - width – root width in pixels
- height – root height in pixels
-
set_minimum_size
(x, y)¶ Sets root window size to minimum size defined in settings
and places root’s top left position to (x, y).
Parameters: - x (int) – absolute horizontal axis mouse position in pixels
- y (int) – absolute vertical axis mouse position in pixels
-
set_screenshot
()¶ Creates and places screenshot of model window as background image.
If we can’t include window decoration in image then offset is returned and we place image shifted by offset amount of pixels to related axis.
Variables: offset – offset (x, y)
-
set_timer
()¶ Cancels previous timer if it exists and creates a new one.
-
setup
()¶ Initializes Tkinter ViewApplication with root window and self as arguments.
Creates and place screenshot widget below view frame, used to hold window image. Sets view attribute to newly created Tkinter application. Temporary hides root window. Tkinter root window from now may be accessed by
self.view.master
attribute.
-
setup_corner
()¶ Configures mouse pointer and background to current corner.
-
setup_root_window
(root)¶ Sets provided root window appearance common for all platforms.
Parameters: root ( tkinter.Tk
instance) – root tkinter window
-
shutdown
()¶ Stops mouse listener, destroys Tkinter root window and exits.
-
snapping_targets
= None¶
-
state
= None¶
-
switch_resizable
()¶ Changes current model resizable Boolean value and updates view.
-
switch_restored
()¶ Changes current model restored Boolean value and updates view.
-
switch_workspace
()¶ Activates workspace and moves root window onto it.
-
timer
= None¶
-
update
(x, y)¶ Calls corresponding state related update method.
Parameters: - x (int) – current horizontal axis mouse position in pixels
- y (int) – current vertical axis mouse position in pixels
-
update_positioning
(x, y)¶ Updates model with provided cursor position in LOCATE state
and takes action in regard to model type.
Parameters: - x (int) – current horizontal axis mouse position in pixels
- y (int) – current vertical axis mouse position in pixels
-
update_resizing
(x, y)¶ Updates model related to provided cursor position and current root size
and calls move and resize task if window has changed.
Switches to next model anyway.
Parameters: - x (int) – current horizontal axis mouse position in pixels
- y (int) – current vertical axis mouse position in pixels
Variables: params – rect attributes we’re going to change
-
view
= None¶
-
workspace_activated
(number)¶ Activates workspace with number equal to provided number.
Parameters: number (int) – our custom workspace number (screen*1000 + workspace)
-
workspace_activated_by_digit
(number)¶ Activates workspace with humanized number equal to provided number.
Parameters: number (int) – number of 1 to 9 representing workspace Variables: workspaces – available workspaces in view
-
class
arrangeit.base.
BaseMouse
¶ Bases:
object
Class responsible for listening and controlling system-wide mouse events.
Variables: -
control
= None¶
-
cursor_position
()¶ Returns current cursor position.
Returns: (int, int)
-
get_item
()¶ Gets next item in queue and returns it.
Returns: (x,y) or bool or None
-
listener
= None¶
-
move_cursor
(x, y)¶ Moves cursor position to a point defined by provided x and y.
-
on_move
(x, y)¶ Puts provided x and y in queue as position tuple.
NOTE: int(x) and int(y) are needed for Darwin - making a specific platform mouse module just for that is avoided.
Parameters: - x (int) – absolute horizontal axis mouse position in pixels
- y (int) – absolute vertical axis mouse position in pixels
-
on_scroll
(x, y, dx, dy)¶ Puts scroll direction as Boolean value in queue.
We are interested only in in dy that holds either +1 or -1 value, so we converted that to Boolean value.
Parameters: - x (int) – absolute horizontal axis mouse position in pixels
- y (int) – absolute vertical axis mouse position in pixels
- dx (int) – scroll vector on x axis
- dy (int) – scroll vector on y axis
-
queue
= None¶
-
start
()¶ Initializes and starts listener for move and scroll events.
-
stop
()¶ Stops listener by raising an exception.
-
arrangeit.data
– Module with classes holding visible windows data¶
-
class
arrangeit.data.
WindowModel
(**kwargs)¶ Bases:
object
Class holding window data.
Variables: - WindowModel.wid – window id (xid, hwnd, …)
- rect – window rectangle (x, y, width, height)
- WindowModel.resizable – is window resizable or not
- WindowModel.restored – is window restored or minimized
- WindowModel.title – window title/caption
- WindowModel.name – window’s application name
- WindowModel.icon – window’s application icon
- workspace – virtual workspace the window is on in format 1000 * screen + number
- changed – changed window rectangle (x, y, width, height)
- changed_ws – changed window workspace
-
changed
= ()¶
-
changed_h
¶
-
changed_w
¶
-
changed_ws
= None¶
-
changed_x
¶
-
changed_y
¶
-
clear_changed
()¶ Resets changing related attributes to initial empty values.
-
h
¶
-
icon
= None¶
-
is_changed
¶ Checks if model rect has been changed.
Returns: Boolean
-
is_ws_changed
¶ Checks if workspace has been changed.
Returns: Boolean
-
name
= None¶
-
rect
= ()¶
-
resizable
= None¶
-
restored
= None¶
-
set_changed
(**kwargs)¶ Creates
changed
attribute from provided arguments.Accepts “rect” argument, individual rect element(s) as defined by Settings.WINDOW_MODEL_RECT_ELEMENTS or “ws” argument. If some rect part isn’t provided then
changed
, respectivelyrect
is used for valid changes or rect elements.Resets to () if any of provided rect arguments is invalid in regard to Settings.WINDOW_MODEL_TYPES for “rect”. changed_ws is reset to None in such a case.
NOTE this method needs refactoring
Variables: - index – argument’s index in rect tuple
- changed – temporary collection holding calculated values
- new_value – new value for rect element
-
setup
(**kwargs)¶ Sets model data from provided kwargs
or sets the value to None/() if attribute isn’t provided.
-
title
= None¶
-
w
¶
-
wid
= None¶
-
workspace
= None¶
-
ws
¶ Shorter alias for workspace attribute.
-
x
¶
-
y
¶
-
class
arrangeit.data.
WindowsCollection
¶ Bases:
object
Class holding visible windows collection.
-
add
(instance)¶ Adds given instance to _members list.
Raises ValueError if given
instance
isn’t a WindowModel instance.Parameters: instance (WindowModel instance) – window data
-
clear
()¶ Empties the _members list.
-
export
()¶ Prepares for saving useful data from collection.
-
generator
()¶ Yields the next member from
_members
.Raises ValueError if given
instance
isn’t a WindowModel instance. :returns: WindowModel instance
-
get_model_by_wid
(wid)¶ Returns window model having provided wid from collection.
Parameters: wid (int) – window id (xid, hwnd, …) Returns: WindowModel instance
-
get_windows_list
()¶ Prepares and returns list of windows ids, titles and icons.
Returns: [(int, str, PIL.Image.Image
)]
-
repopulate_for_wid
(wid, remove_before)¶ Repopulates collection starting from the window with identifier
wid
without including models placed before provided
remove_before
.Parameters: - wid (int) – window id (xid, hwnd, …)
- remove_before – window id (xid, hwnd, …)
Variables: - start_index – index of model that is going to become the first
- remove_index – index of first model that is not going to be removed
-
size
¶ Returns the size of _members list.
-
sort
()¶ Sorts collection for presentation queue.
First model stays first and the others are sorted by their workspace first and then on current position. <starts from workspace number 0 when all the windows from greater workspaces numbers are exhausted.
Variables: - others – sorted list without first element
- index – index of first element having greater or equal workspace like first
-
arrangeit.view
– Module with classes and functions holding visual presentation data¶
-
class
arrangeit.view.
CornerWidget
(master=None, shift=0, background='red')¶ Bases:
object
Widget holding three frames for emphasizing current corner.
Variables: - CornerWidget.master – parent widget
- shift – cursor shift from corner in pixels
- CornerWidget.background – widget background color
- length – axes frame length (long side) in pixels
- width – axes frame width (small side) in pixels
- box_size – box frame width/height in pixels
-
anchor
(corner=0)¶ Returns anchor for provided corner.
Returns: str
-
background
= 'red'¶
-
box_size
= 8¶
-
get_place_parameters
(corner, size_property)¶ Returns parameters for place method for given corner and size method.
Returns: dict
-
hide_corner
()¶ Places widget frames in provided corner.
-
length
= 20¶
-
master
= None¶
-
max_box
¶ Returns box placement on axis related to shift.
Returns: int
-
max_xy
¶ Returns placement on axis related to shift.
Returns: int
-
set_corner
(corner=0)¶ Places widget frames in provided corner.
-
setup_widgets
()¶ Creates all three frames and places them in default corner.
-
shift
= 0¶
-
width
= 4¶
-
class
arrangeit.view.
ListedWindow
(master=None, wid=0, title='', icon=<PIL.Image.Image image mode=RGB size=32x32>)¶ Bases:
tkinter.Frame
Tkinter frame holding window title and smaller icon.
Variables: - ListedWindow.master – master widget
- ListedWindow.wid – window id
- ListedWindow.title – window title
- ListedWindow.icon – window’s application icon
-
get_icon_image
(icon)¶ Returns provided icon resized and converted to format suitable for Tkinter.
Parameters: icon ( PIL.Image.Image
) – window’s application iconReturns: PIL.ImageTk.PhotoImage
-
icon
= <PIL.Image.Image image mode=RGB size=32x32>¶
-
master
= None¶
-
on_widget_enter
(event)¶ Highlights widget by changing foreground color.
-
on_widget_leave
(event)¶ Resets widget foreground color.
-
setup_bindings
()¶ Binds relevant events to related callback.
-
setup_widgets
()¶ Creates and places all the frame’s variables and widgets.
-
title
= ''¶
-
wid
= 0¶
-
class
arrangeit.view.
PropertyIcon
(master=None, background='white', callback=None)¶ Bases:
tkinter.Label
Tkinter label holding on/off image for a property.
Variables: - PropertyIcon.master – master widget
- PropertyIcon.images – collection of two possible images
- PropertyIcon.colorized – collection of two highlighted images
- PropertyIcon.background – main background color
- PropertyIcon.value – current widget value (0 or 1)
- PropertyIcon.on_name – image name when the property is on
- PropertyIcon.off_name – image name when the property is off
- PropertyIcon.callback – method to call on triggered event
-
background
= 'white'¶
-
callback
= None¶
-
colorized
= {0: None, 1: None}¶
-
images
= {0: None, 1: None}¶
-
master
= None¶
-
off_name
= None¶
-
on_name
= None¶
-
on_widget_enter
(event)¶ Highlights widget by changing image and its foreground.
-
on_widget_leave
(event)¶ Resets widget image and its foreground color.
-
set_value
(value)¶ Sets label image in relation to provided value.
Parameters: value (Boolean) – is property on or not
-
setup_bindings
()¶ Binds relevant events to related callback.
-
setup_widgets
()¶ Configures widgets images and sets current image.
-
value
= 1¶
-
class
arrangeit.view.
Resizable
(master=None, background='white')¶ Bases:
arrangeit.view.PropertyIcon
Widget holding resizable/non-resizable image.
Variables: - Resizable.images – collection of two possible images
- Resizable.colorized – collection of two highlighted images
- Resizable.on_name – image name when the property is on
- Resizable.off_name – image name when the property is off
-
colorized
= {0: None, 1: None}¶
-
images
= {0: None, 1: None}¶
-
off_name
= 'move.png'¶
-
on_name
= 'resize.png'¶
-
class
arrangeit.view.
Restored
(master=None, background='white')¶ Bases:
arrangeit.view.PropertyIcon
Widget holding restored/minimized image.
Variables: - Restored.images – collection of two possible images
- Restored.colorized – collection of two highlighted images
- Restored.on_name – image name when the property is on
- Restored.off_name – image name when the property is off
-
colorized
= {0: None, 1: None}¶
-
images
= {0: None, 1: None}¶
-
off_name
= 'minimize.png'¶
-
on_name
= 'restore.png'¶
-
class
arrangeit.view.
Statusbar
(master=None)¶ Bases:
tkinter.Frame
Tkinter frame showing app messages at the bottom of root window.
Variables: Statusbar.master – master widget -
master
= None¶
-
setup_widgets
()¶ Creates and places all the widget’s variables and widgets.
-
-
class
arrangeit.view.
Toolbar
(master=None)¶ Bases:
tkinter.Frame
Tkinter frame holding options and quit button.
Variables: Toolbar.master – master widget -
master
= None¶
-
on_options_click
()¶ Creates and shows options dialog and hides root window.
-
setup_widgets
()¶ Creates and places all the frame’s variables and widgets.
-
-
class
arrangeit.view.
ViewApplication
(master=None, controller=None)¶ Bases:
tkinter.Frame
Tkinter frame showing current window from the data provided through controller.
Variables: - ViewApplication.master – master Tkinter window
- ViewApplication.controller – controller object providing windows data
-
controller
= None¶
-
get_root_wid
()¶ Returns windows identifier of master/root window.
Returns: int
-
hide_root
()¶ Hides master/root window.
-
master
= None¶
-
reset_bindings
()¶ Unbinds all relevant events and binds those for positioning routine.
-
setup_bindings
()¶ Binds relevant events to related controller callbacks.
bind_all
method is used if possible so events can be catch in label widget. It first unbinds Button-1 events (in case they were bound inreset_bindings()
)NOTE master is None check exists solely because unit tests.
-
setup_corner
()¶ Creates and places corner widget in the default corner 0.
-
setup_icon
()¶ Sets and places icon label widget.
-
setup_name
()¶ Sets and places application name label widget.
-
setup_resizable
()¶ Sets and places resizable label widget.
-
setup_restored
()¶ Sets and places restored label widget.
-
setup_statusbar
()¶ Creates and places
statusbar
widget and sets corresponding variable.
-
setup_title
()¶ Sets and places title label widget.
-
setup_toolbar
()¶ Creates and places
toolbar
widget and sets corresponding variable.
-
setup_widgets
()¶ Calls all the frame’s widgets creation and placement methods.
-
setup_windows
()¶ Creates and places
windows
widget and sets corresponding variable.
-
setup_workspaces
()¶ Creates and places
workspaces
widget and sets corresponding variable.
-
show_root
()¶ Shows master/root window.
-
startup
()¶ Shows master and then calculates and sets now visible parameters.
Calls
focus_set()
so frame can trigger keyboard events.
-
update_widgets
(model)¶ Updates widgets with the data from provided WindowModel instance.
Tkinter needs a reference to image so we create
icon_image
reference.Parameters: model ( WindowModel
instance) – window data
-
class
arrangeit.view.
WindowsList
(master=None)¶ Bases:
tkinter.Frame
Tkinter frame holding titles and small icons of the windows in queue.
Variables: WindowsList.master – master widget -
add_windows
(windows)¶ Creates children widgets from provided windows list.
Parameters: windows ([(int, str, PIL.Image.Image
)]) – list of windows tuples (number, title, icon)
-
clear_list
()¶ Destroys all children widgets.
-
master
= None¶
Activates window by wid carried with provided event.
Parameters: event (Tkinter event) – catched event
-
place_children
()¶ Place children widgets in order.
Used after the top widget is destroyed.
-
place_widget_on_position
(widget, position)¶ Configures placement and place provided widget at provided vertical position.
Parameters: - widget (
ListedWindow
) – Tkinter Frame widget - position (int) – vertical position in master starting from top
- widget (
-
-
class
arrangeit.view.
Workspace
(master=None, number=0, name='')¶ Bases:
tkinter.Frame
Tkinter frame holding individual workspace widget.
Variables: - Workspace.master – master widget
- Workspace.number – workspace number
- Workspace.name – workspace name
-
get_humanized_number
(number)¶ Returns workspace number without screen part and increased by 1
as systems count workspaces from 0, but users expect to be from 1.
Parameters: number (int) – workspace number
-
master
= None¶
-
name
= ''¶
-
number
= 0¶
-
on_widget_enter
(event)¶ Highlights widget by changing foreground color.
-
on_widget_leave
(event)¶ Resets widget foreground color.
-
setup_bindings
()¶ Binds relevant events to related callback.
-
setup_widgets
()¶ Creates and places all the frame’s variables and widgets.
As systems counts workspace from 0, we increase number by 1.
-
class
arrangeit.view.
WorkspacesCollection
(master=None)¶ Bases:
tkinter.Frame
Tkinter frame holding all the available workspaces widgets.
Variables: - WorkspacesCollection.master – master widget
- active – currently active workspace number
- capacity – number of children workspaces
-
active
= 0¶
-
add_workspaces
(workspaces)¶ Creates children workspaces widgets from provided list of workspaces
Creates no widget for configuration without multiple workspaces. Widgets are stacked related to their numbers from top right two positions towards bottom and then too the left, Actual workspaces are placed from left to right, then down the same orientation. Still, as a design decision, we use the same size for every configuration having less than 5 workspaces.
Parameters: workspaces ([(int, str)]) – list of workspaces two-tuples (number, name) Variables: relwidth – workspace widget width
-
master
= None¶
Activates workspace by number carried with provided event.
Parameters: event (Tkinter event) – catched event
-
select_active
(number)¶ Emphasizes active workspace and deemphasizes all others.
Foreground text coloured by setting SELECTED_COLOR is used to emphasize selection, together with SELECT_CURSOR setting.
Parameters: number (int) – number of workspace to select
Variables: - workspace – child widget
- color – Tkinter color name
- cursor – Tkinter cursor name
-
arrangeit.view.
get_screenshot_widget
(root)¶ Returns Label widget that will hold screenshot image in background.
Parameters: root ( tk.Tk
) – application main windowReturns: tk.Label
-
arrangeit.view.
get_tkinter_root
()¶ Initializes and returns Tkinter root window.
Returns: tk.Tk
window instance
arrangeit.options
– Module with classes and functions for options dialog¶
-
class
arrangeit.options.
AboutDialog
(master=None)¶ Bases:
tkinter.Toplevel
Tkinter “About” dialog window.
Variables: - AboutDialog.master – master widget
- AboutDialog.logo – arrangeit logo
-
logo
= None¶
-
master
= None¶
-
on_help_click
()¶ Opens documentation page in user’s default web browser.
-
on_releases_click
()¶ Opens download releases page in user’s default web browser.
-
setup_widgets
()¶ Creates and packs all the dialog’s widgets.
-
class
arrangeit.options.
CheckOption
(master=None, name='', change_callback=None, initial=False, label='')¶ Bases:
tkinter.Checkbutton
Tkinter widget for showing and changing Boolean values.
Variables: - CheckOption.master – master widget
- CheckOption.name – setting name to change
- CheckOption.var – variable holding the check button value
-
master
= None¶
-
name
= ''¶
-
on_update_value
(*args)¶
-
var
= None¶
-
class
arrangeit.options.
ColorOption
(master=None, name='', change_callback=None, initial='', label='', choices=('white', 'black', 'gray', 'slategray', 'gray25', 'gray75', 'lightblue', 'blue', 'royalblue', 'cyan', 'orange', 'salmon', 'indianred', 'red', 'orchid', 'pink', 'green', 'olivedrab', 'wheat', 'khaki', 'tan', 'lightgoldenrodyellow', 'yellow'))¶ Bases:
tkinter.OptionMenu
Tkinter widget for showing and changing Boolean values.
Variables: - ColorOption.master – master widget
- ColorOption.name – setting name to change
- ColorOption.var – variable holding the choice value
-
label
= None¶
-
master
= None¶
-
name
= ''¶
-
on_update_value
(*args)¶
-
var
= None¶
-
class
arrangeit.options.
FloatScaleOption
(master, **kwargs)¶ Bases:
arrangeit.options.ScaleOption
Tkinter widget for showing and changing float range settings values.
-
on_update_value
(value)¶
-
-
class
arrangeit.options.
OptionsDialog
(master=None)¶ Bases:
tkinter.Toplevel
Tkinter dialog window for manipulating of user settings data.
Variables: - OptionsDialog.master – master widget
- message – variable holding message log
- OptionsDialog.timer – id of active timer
-
change_setting
(name='', value=None)¶ Calls sontroller’s change setting method and updates message log.
Also cancels previous timer if it exists and create a new one.
Parameters: - name (str/int/float) – setting name
- value – value for given name setting
-
create_frame
(master)¶ Creates and returns frame that will holds pair of widgets.
Parameters: master (Tkinter widget) – parent widget
-
create_separator
(master, vertical=False)¶ Creates and returns default horizontal separator of vertical if argument set.
Parameters: - master (Tkinter widget) – parent widget
- vertical (Booleand) – is separator oriented vertical instead default horizontal
-
create_widget
(master, name, **kwargs)¶ Creates and returns presentation widget for setting with provided name.
Parameters: - master (
ttk.LabelFrame
) – parent widget - name (str) – setting name
Returns: Tkinter widget instance
- master (
-
master
= None¶
-
message
= None¶
-
on_destroy_options
(event)¶ Brings back root window and destroys options dialog.
-
on_save_default
()¶ Saves windows collection data to default file.
-
on_show_about
()¶ Creates and shows about dialog on top of this dialog.
-
set_timer
()¶ Cancels previous timer if it exists and creates a new one.
-
setup_bindings
()¶ Binds relevant events to related callback.
-
setup_files_section
()¶ Creates and packs widgets for section dealing with files.
Returns: ttk.LabelFrame
-
setup_section
(name, denominator=6)¶ Creates and packs widgets for section with provided name.
Returns: ttk.LabelFrame
-
setup_widgets
()¶ Creates and packs all the options’ widgets.
-
timer
= None¶
-
widget_class_from_name
(name)¶ Returns related widget class from provided setting name.
Parameters: name (str) – setting name Returns: custom Tkinter widget instance
-
class
arrangeit.options.
ScaleOption
(master=None, name='', change_callback=None, initial=0, label='', configs={})¶ Bases:
tkinter.Scale
Tkinter widget for showing and changing range settings values.
Variables: - ScaleOption.master – master widget
- ScaleOption.name – setting name to change
-
master
= None¶
-
name
= ''¶
-
on_update_value
(value)¶
-
class
arrangeit.options.
ThemeOption
(*args, **kwargs)¶
arrangeit.utils
– Module holding various utility functions¶
-
class
arrangeit.utils.
Rectangle
(x0, y0, x1, y1)¶ Bases:
tuple
-
x0
¶ Alias for field number 0
-
x1
¶ Alias for field number 2
-
y0
¶ Alias for field number 1
-
y1
¶ Alias for field number 3
-
-
arrangeit.utils.
check_intersections
(sources, targets)¶ Returns first pairs that intersects from sources and targets list of Rectangles.
Sources is either four-tuple representing whole window or two-tuple representing specific corner of the window (from first top-left clockwise to forth bottom-left).
We are interested in intersection of odd or even pairs of sources and targets. It means that sources[0] or sources[2] should intersect with targets[n][0] or targets[n][2], respectively sources[1] or sources[3] should intersect with targets[n][1] or targets[n][3].
So we create iterator that first cycle through all even elements pairs and then through all odd elements pairs. Stops iteration when first intersected pair is found. Returns either single pair (even or odd) or tuple of both.
Parameters: - sources (tuple of
Rectangle
) – two-tuple or four-tuple of root window snapping rectangles - targets (list of
Rectangle
) – collection of other windows snapping rectangles - even ((
Rectangle
,Rectangle
)) – horizontal intersection pair or False - odd ((
Rectangle
,Rectangle
)) – vertical intersection pair or False
Returns: - sources (tuple of
-
arrangeit.utils.
get_class
(name, platform)¶ Helper method for retrieving platform specific class instance
for given
name
andplatform
.If provided
platform
is None then we useplatform_path()
.If class can’t be imported that means host system isn’t implemented (yet…) and so we sys.exit with a message.
Parameters: - name (string) – function name suffix
- platform (string or None) – platform name
Returns: class instance from the platform specific package
-
arrangeit.utils.
get_component_class
(name, platform=None)¶ Helper method for retrieving platform specific App class.
Parameters: platform (string) – platform name Returns: class with provided name
from the platform specific package
-
arrangeit.utils.
get_cursor_name
(corner, with_arrow=False)¶ Returns cursor name for provided corner.
Parameters: - corner (int) – corner number
- with_arrow (Boolean) – indicating should cursor contain an arrow
Returns: str
-
arrangeit.utils.
get_prepared_screenshot
(image, blur_size=2, grayscale=False)¶ Filters provided image and converts it to format suitable for Tkinter.
SCREENSHOT_BLUR_PIXELS defines blur depth in pixels.
Parameters: - image (
PIL.Image.Image
) – raw screenshot image - blur_size (int) – how many pixels in all directions will be blured
- grayscale (Boolean) – should image be converted to grayscale
Returns: PIL.ImageTk.PhotoImage
- image (
-
arrangeit.utils.
get_resized_image
(filename, size)¶ Opens and resizes image with provided filename to provided size.
Parameters: - filename (str) – resource file name
- size (tuple) – width and height to resize image to
Returns: PIL.Image
-
arrangeit.utils.
get_resource_path
(filename)¶ Returns full path to resource with provided filename.
Parameters: filename (str) – resource file name Returns: str
-
arrangeit.utils.
get_snapping_sources_for_rect
(rect, snap, corner=None)¶ Returns snapping rectangles formated as Rectangle(x0,y0,x0,y0) from provided rect.
Snapping rectangle is created around window connected edge points pair with height (or width) of 2*SNAP_PIXELS and width (or height) of related window side.
All four rectangles are returned for default corner of None. If corner is provided then it returns two adjacent rectangles for related provided corner (horizontal first, vertical second) where ordinal 0 is top-left corner, with clockwise ordering to bottom-left corner which is ordinal 3.
Parameters: - rect ((int, int, int, int)) – window defined by (x, y, width, height)
- snap (int) – snapping distance in pixels
Returns: two or four-tuple of
Rectangle
-
arrangeit.utils.
get_value_if_valid_type
(value, typ)¶ Returns provided value if it’s of provided type
or returns None if it’s not. If value is None then None is returned. If provided value and typ are collections then each element is checked.
Parameters: - value (Python type) – value to check for type
- typ (Python type) – type to check on
value
Returns: value or None
-
arrangeit.utils.
increased_by_fraction
(value, fraction)¶ Helper method for increasing provided value by provided fraction.
Parameters: - value (int) – value to increase
- fraction (float) – fraction of a whole to increase value by
Returns: int
-
arrangeit.utils.
offset_for_intersections
(rectangles, snap)¶ Checks if single or both axes intersect and returns related offset(s).
Parameters: Returns: tuple (x,y)
-
arrangeit.utils.
open_image
(filename, background='white', colorized=False, foreground='red')¶ Returns Pillow image instance from provided name and colorizes it if set.
Provided
black
andwhite
are used for colorize filter.Parameters: - filename (str) – image filename
- background (str) – image background color
- colorized (Boolean) – should return image be highlighted
- foreground (str) – image foreground color
Returns: PIL.Image
-
arrangeit.utils.
platform_path
()¶ Returns lowercased string holding platform name.
-
arrangeit.utils.
platform_user_data_path
()¶ Retrieves platform specific user data directory path.
-
arrangeit.utils.
quarter_by_smaller
(width, height, size=3)¶ Helper method for retrieving one-forth (default) for given
width
andheight
with aspect ratio of 16:9.
Starting point for calculation is the smaller value - the presumption is that monitors could be stacked in left-to-right or top-to-bottom manner.
Parameters: - width (int) – total desktop area width
- height (int) – total desktop area height
- size (int) – window size from 1 to 4
Variables: denominator – window size denominator from 6 to 3
Returns: (int, int)
-
arrangeit.utils.
set_icon
(widget)¶ Sets application icon to provided widget window.
Parameters: widget ( tk.Toplevel
ortk.Tk
) – Tkinter toplevel widget
arrangeit.settings
– Module holding program’s constants and settings¶
-
class
arrangeit.settings.
Settings
¶ Bases:
object
Class holding all the program’s constants and settings.
-
BLANK_ICON
= <PIL.Image.Image image mode=RGB size=32x32>¶
-
CORNER_RECT_INDEXES
= [(0, 3), (0, 1), (2, 1), (2, 3)]¶
-
HELP_PAGE_URL
= 'https://arrangeit.readthedocs.io/en/latest/userguide.html'¶
-
ICON_SIZE
= 32¶
-
LOCATE
= 0¶
-
OTHER
= 100¶
-
RELEASES_PAGE_URL
= 'https://github.com/ipaleka/arrangeit/releases'¶
-
RESIZE
= 10¶
-
WINDOW_MODEL_RECT_ELEMENTS
= ('x', 'y', 'w', 'h')¶
-
WINDOW_MODEL_TYPES
= {'icon': <class 'PIL.Image.Image'>, 'name': <class 'str'>, 'rect': (<class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>), 'resizable': <class 'bool'>, 'restored': <class 'bool'>, 'title': <class 'str'>, 'wid': <class 'int'>, 'workspace': <class 'int'>}¶
-
classmethod
color_group
(group)¶ Returns all the Settings members which names end with provided name.
Parameters: group (str) – setting name Returns: list
-
classmethod
is_setting
(name, value)¶ Returns True if provided name with value is valid setting.
Parameters: - name (str) – setting name
- value (str/int/float) – value to check type for
Returns: Boolean
-
classmethod
setting_type
(name)¶ Returns type of setting with provided name.
Parameters: name (str) – setting name Returns: type
-
user_settings
= {}¶
-
-
class
arrangeit.settings.
SettingsMetaclass
¶ Bases:
type
Meta class needed to access Settings class attributes by names.
-
arrangeit.settings.
read_user_settings
()¶ Reads and returns user settings data from user home directory.
Returns: dict
-
arrangeit.settings.
validate_user_settings
()¶ Reads, validates and returns dictionary of user settings.
Returns: dict {name: value}
arrangeit.darwin
– Subpackage holding code specific to Mac OS platform¶
arrangeit.darwin.app
– Module providing and running main app loop (Mac OS platform specific code)¶
-
class
arrangeit.darwin.app.
App
¶ Bases:
arrangeit.base.BaseApp
Main app class with Mac OS specific code.
-
activate_root
(wid)¶ TODO implement
Parameters: wid (int) – windows id
-
grab_window_screen
(model, root_wid=None)¶ Grabs and returns screenshot of the window from provided model.
TODO implement
Parameters: - model (
WindowModel
) – model of the window we want screenshot from - root_wid (int) – root window identifier
Returns: (
PIL.ImageTk.PhotoImage
, (int, int))- model (
-
move
(wid)¶ TODO implement
Parameters: wid (int) – windows id
-
move_and_resize
(wid)¶ Moves and resizes window identified by provided identifier wid.
TODO implement
Parameters: wid (int) – windows id Returns: Boolean
-
move_to_workspace
(wid, number)¶ TODO implement
Parameters: - wid (int) – root id got from Tkinter
- number (int) – our custom workspace number
-
arrangeit.darwin.collector
– Module responsible for collecting windows (Mac OS platform specific code)¶
-
class
arrangeit.darwin.collector.
Collector
¶ Bases:
arrangeit.base.BaseCollector
Collecting windows class with Mac OS specific code.
-
add_window
(win)¶ Creates WindowModel instance from provided win and adds it to collection.
Parameters: win (dict) – window object
-
check_window
(win)¶ Checks does window qualify to be collected
by checking window type applicability with
is_applicable()
and its current state validity withis_valid_state()
.Parameters: win (dict) – window object Returns: Boolean
-
get_application_name
(win)¶ Returns application/owner name for the provided win.
Parameters: win (dict) – window object Returns: str
-
get_available_workspaces
()¶ TODO implement
Returns: list
-
get_monitors_rects
()¶ Returns list of available monitors position and size rectangles.
Returns: list [(x,y,w,h)]
-
get_windows
()¶ Returns list of all windows as dictionary objects
Returns: list
-
get_workspace_number_for_window
(win)¶ TODO implement
Parameters: win (dict) – window object Returns: str
-
is_applicable
(win)¶ Checks if provided win represents window that should be collected.
TODO implement
Parameters: win (dict) – window object Returns: Boolean
-
is_resizable
(win)¶ TODO implement
Parameters: win (dict) – window object Returns: Boolean
-
is_restored
(win)¶ TODO implement
Parameters: win (dict) – window object Returns: Boolean
-
is_valid_state
(win)¶ Checks if provided win is window with valid state for collecting.
TODO implement
Parameters: win (dict) – window object Returns: Boolean
-
arrangeit.darwin.controller
– Module responsible for connecting data and view (Mac OS platform specific code)¶
-
class
arrangeit.darwin.controller.
Controller
(app)¶ Bases:
arrangeit.base.BaseController
Controller class with Mac OS specific code.
arrangeit.darwin.utils
– Mac OS specific utility functions¶
-
arrangeit.darwin.utils.
user_data_path
()¶ Returns Mac OS X specific path for saving user’s data.
arrangeit.linux
– Subpackage holding code specific to GNU/Linux platform¶
arrangeit.linux.app
– Module providing and running main app loop (GNU/Linux platform specific code)¶
-
class
arrangeit.linux.app.
App
¶ Bases:
arrangeit.base.BaseApp
Main app class with GNU/Linux specific code.
-
activate_root
(wid)¶ Activates/focuses root window identified by provided
wid
.Parameters: wid (int) – windows id
-
grab_window_screen
(model, root_wid=None)¶ Grabs and returns screenshot of the window from provided model.
We can’t include window decoration in image so offset in pixels for both axes is returned.
Parameters: - model (
WindowModel
) – model of the window we want screenshot from - root_wid (int) – root window identifier - not needed for GNU/Linux
Variables: - window – model window instance
- pixbuf – X11 pixbuf image
- width – window width in pixels without window manager decoration
- height – window height in pixels without window manager decoration
Returns: (
PIL.ImageTk.PhotoImage
, (int, int))- model (
-
move
(wid)¶ Just calls
move_and_resize()
as the same method moves and resizesin Wnck.Window class under GNU/Linux.
Parameters: wid (int) – windows id Returns: Boolean
-
move_and_resize
(wid)¶ Moves and resizes window identified by provided wid.
Gravity stays the same (Wnck.WindowGravity.CURRENT) and the other arguments are calculated/retrieved from model where
changed
attribute holds needed data.If returned
mask
is False then wee don’t need to do anything more.Parameters: wid (int) – windows id
Variables: - model – window data
- mask – combination of bits holding information what is changed
- win – window instance
Returns: Boolean
-
move_to_workspace
(wid, number)¶ Moves root window to provided custom workspace number.
Calls
_move_window_to_workspace()
with wid increased by 1.Parameters: - wid (int) – root id got from Tkinter
- number (int) – our custom workspace number
-
arrangeit.linux.collector
– Module responsible for collecting windows (GNU/Linux platform specific code)¶
-
class
arrangeit.linux.collector.
Collector
¶ Bases:
arrangeit.base.BaseCollector
Collecting windows class with GNU/Linux specific code.
-
add_window
(win)¶ Creates WindowModel instance from provided win and adds it to collection.
Parameters: win ( Wnck.Window
object) – window to create WindowModel from it
-
check_window
(win)¶ Checks does window qualify to be collected
by checking window type applicability with
is_applicable()
and its state validity for the type withis_valid_state()
.Parameters: win (
Wnck.Window
object) – window instance to checkVariables: - window_type – window type
- window_state – window state
Returns: Boolean
-
get_available_workspaces
()¶ Returns custom list of workspaces available on default screen.
Returned list contains two-tuples of calculated workspace number and corresponding name.
Variables: workspaces – workspaces collection Returns: [(int, str)]
-
get_image_from_pixbuf
(pixbuf)¶ Returns PIL image converted from provided pixbuf.
https://gist.github.com/mozbugbox/10cd35b2872628246140
Returns: PIL.Image
instance
-
get_monitors_rects
()¶ Returns list of available monitors position and size rectangles.
Variables: - display – default display
- area – monitor working area rect
Returns: list [(x,y,w,h)]
-
get_window_by_wid
(wid)¶ Returns window instance having provided wid.
Parameters: wid (int) – window id Returns: Wnck.Window object
-
get_window_move_resize_mask
(model)¶ Returns flag indicating what is changed when we move/resize window.
Calls recursive method traversing all rect parts. Returned flag is combination of the X, Y, WIDTH and HEIGHT bits.
Parameters: model ( WindowModel
instance) – model holding window dataReturns: flag
-
get_windows
()¶ Returns windows list from the Wnck.Screen object.
Variables: screen – provides all the windows instances Returns: list of Wnck.Window instances
-
get_wnck_workspace_for_custom_number
(number)¶ Returns
Wnck.Workspace
instance from provided custom number.Variables: number – our custom workspace number
-
get_workspace_number
(workspace)¶ Returns integer containing screen and workspace numbers of the workspace.
In returned integer screen number represents thousands part, and workspace number represents remainder of division by 1000.
Parameters: workspace ( Wnck.workspace
) – workspace instanceReturns: int
-
get_workspace_number_for_window
(win)¶ Returns workspace number for the provided window.
Parameters: win ( Wnck.Window
) – window instanceReturns: int
-
is_applicable
(window_type)¶ Checks if provided
window_type
qualifies window for collecting.Parameters: window_type (Wnck.WindowType int flag) – type of window Returns: Boolean
-
is_resizable
(window_type)¶ Checks if provided
window_type
implies that window is resizable.Parameters: window_type (Wnck.WindowType int flag) – type of window Returns: Boolean
-
is_restored
(win)¶ Checks if provided
win
is not minimized.Parameters: win ( Wnck.Window
object) – window instance to checkReturns: Boolean
-
is_valid_state
(window_type, window_state)¶ Checks if
window state
forwindow_type
qualifies window to collect.Parameters: - window_type (Wnck.WindowType int flag) – type of window
- window_state (Wnck.WindowState int flag) – current state of window
Returns: Boolean
-
arrangeit.linux.controller
– Module responsible for connecting data and view (GNU/Linux platform specific code)¶
-
class
arrangeit.linux.controller.
Controller
(app)¶ Bases:
arrangeit.base.BaseController
Controller class with GNU/Linux specific code.
-
setup_root_window
(root)¶ Sets provided root appearance attributes specific for GNU/Linux.
-
arrangeit.linux.utils
– GNU/Linux specific utility functions¶
-
arrangeit.linux.utils.
user_data_path
()¶ Returns GNU/Linux platform specific path for saving user’s data.
It first try with .local/share in user home directory, and if there’s no such directory returns .arrangeit directory in user home directory.
Returns: str path
arrangeit.windows
– Subpackage holding code specific to MS Windows platform¶
arrangeit.windows.app
– Module providing and running main app loop (MS Windows platform specific code)¶
-
class
arrangeit.windows.app.
App
¶ Bases:
arrangeit.base.BaseApp
Main app class with MS Windows specific code.
-
activate_root
(hwnd)¶ Activates/focuses root window identified by provided
hwnd
.
-
grab_window_screen
(model, root_wid=None)¶ Setups and returns screenshot of the window from provided model.
If DWM composition settings allows then surface of model window is taken from root window after thumbnails are created in it.
TODO check why this (-1, -1) fits
Parameters: - model (
WindowModel
) – model of the window we want screenshot from - root_wid (int) – root window identifier
Returns: (
PIL.ImageTk.PhotoImage
, (int, int))- model (
-
move
(hwnd)¶ Just calls
move_and_resize()
as the same method moves and resizesunder MS Windows.
Parameters: hwnd (int) – windows id
-
move_and_resize
(hwnd)¶ Moves and resizes window identified by provided hwnd.
Parameters: hwnd (int) – root id got from Tkinter Variables: model – collected window data Returns: Boolean
-
move_other_to_workspace
(hwnd, number)¶ Moves other process’ window to provided workspace number.
Parameters: - hwnd (int) – identifier of the window to move
- number (int) – workspace number
-
move_to_workspace
(hwnd, number)¶ Moves root window to provided workspace number.
Parameters: - hwnd (int) – root id got from Tkinter
- number (int) – workspace number
-
screenshot_cleanup
(*args)¶ Unregisters DWM thumbnails kept in instance’s
thumbnails
attribute.Variables: thumbnail – DWM thumbnail identifier
-
thumbnails
= ()¶
-
arrangeit.windows.api
– Module providing helper class and functions for API calls (MS Windows platform specific code)¶
-
class
arrangeit.windows.api.
Api
¶ Bases:
object
Helper class for calls to Windows API.
Variables: -
enum_windows
(hwnd=None, enum_children=False)¶ Helper function to enumerate either desktop windows or children windows
for window identified by provided hwnd.
Parameters: - hwnd (int) – window id
- enum_children (Boolean) – should children windows be enumerated
Returns: list
-
executable_name_for_hwnd
(hwnd)¶ Returns name of the executable associated with provided window identifier.
Parameters: hwnd (int) – window handle
Variables: - pid – process identifier
- hprocess – process handle
- path_buffer – buffer holding executable path
- ret_val – function returned value indicating success for value > 0
Returns: str
-
extended_frame_rect
(hwnd)¶ Helper function to return DWM frame rect for window with provided hwnd.
Parameters: hwnd (int) – window id
Variables: - winrect – area of window extended bounds
- ret_val – function returned value indicating success for value > 0
Returns: int
-
get_ancestor_by_type
(hwnd, ancestor_type)¶ Helper function to return hwnd of ancestor window of window with given hwnd.
Parameters: - hwnd (int) – window id
- ancestor_type (int) – window ancestor type
Returns: int
-
get_desktop_ordinal_for_window
(hwnd)¶ Returns corresponding desktop ordinal of the window with provided hwnd.
Parameters: hwnd (int) – window id Returns: int
-
get_desktops
()¶ Returns list of virtual desktops.
Returned list contains two-tuples of desktop numbers in order and their corresponding names. A name is formatted from “Desktop ” translation forllowed by ordinal increased by 1.
Returns: [(int, str)]
-
get_last_active_popup
(hwnd)¶ Helper function to return hwnd of last popup of window with provided hwnd.
Parameters: hwnd (int) – window id Returns: int
-
get_package
(hwnd)¶ Returns
Package
holding needed package data from provided window id.Parameters: hwnd (int) – window id
Variables: - full_name – buffer holding package full name
- package_info_reference – reference to package info structure pointer
- package_info_buffer – buffer holding reference to package info structure
- package_info – structure holding package data
Returns:
-
helpers
= None¶
-
is_cloaked
(hwnd)¶ Returns True if window with provided hwnd is cloaked/hidden.
False is returned for Windows 7 and earlier versions (helper method returns error value).
If DWM value confirms cloaked state, then the value from a call to
is_window_in_current_desktop
is returned as all the windows from the other desktops are presented as cloaked, so it is implied they are really cloaked. NOTE this behaviour needs additional testingParameters: hwnd (int) – window id
Variables: - cloaked – flag holding non-zero value if window is cloaked
- ret_val – function returned value indicating error/success status
Returns: Boolean
-
is_dwm_composition_enabled
()¶ Helper function returning True if DWM composition is enabled in system.
Variables: enabled – composition enabled or not value Returns: Boolean
-
move_other_window_to_desktop
(hwnd, number)¶ Moves other window with provided hwnd to desktop with provided ordinal.
Parameters: - hwnd (int) – window id
- number (int) – desktop ordinal
Returns: int
-
move_own_window_to_desktop
(hwnd, number)¶ Moves own/root window with provided hwnd to desktop with provided ordinal.
Parameters: - hwnd (int) – window id
- number (int) – desktop ordinal
Returns: int
-
packages
= {}¶
-
setup_thumbnail
(from_hwnd, root_hwnd, rectangle)¶ Create, updates and returns handle of thumbnail of provided source window
created in root window.
Parameters: - from_hwnd (int) – identifier of window to make thumbnail of
- root_hwnd (int) – identifier of root window to make thumbnail in
- rectangle (
arrangeit.utils.Rectangle
) – area occupied by thumbnail
Variables: - thumbnail_id – id of created thumbnail
- ret_val – function returned value indicating error/success status
Returns: ctypes.wintypes.HANDLE
-
title_info_state
(hwnd, state)¶ Helper function to return title bar info state for window with provided hwnd.
Parameters: - hwnd (int) – window id
- state (int) – title bar info state type
Variables: - title_info – title bar information structure
- success – value indicating is call successful
Returns: int
-
unregister_thumbnail
(thumbnail_id)¶ Unregisters thumbnail with provided identifier.
Parameters: thumbnail_id ( ctypes.wintypes.HANDLE
) – identifier of thumbnail to unregisterVariables: ret_val – function returned value indicating error/success status Returns: ctypes.wintypes.HANDLE
-
vdi
= None¶
-
window_info_extended_style
(hwnd, style)¶ Helper function to return extended window style for window with given hwnd.
Parameters: - hwnd (int) – window id
- style (int) – extended window style type
Variables: - window_info – window information structure
- success – value indicating is call successful
Returns: int
-
-
class
arrangeit.windows.api.
DummyVirtualDesktops
¶ Bases:
object
Helper class for systems that don’t support virtual desktops.
-
get_desktops
(refresh=False)¶ Returns list with single two-tuple of 0 and empty string.
-
get_window_desktop
(hwnd, refresh=False)¶ Returns two-tuple of 0 and empty string.
-
is_window_in_current_desktop
(hwnd)¶ Just returns True.
-
move_other_window_to_desktop
(hwnd, desktop_ordinal)¶ Just returns None.
-
move_own_window_to_desktop
(hwnd, desktop_ordinal)¶ Just returns None.
-
-
class
arrangeit.windows.api.
Helpers
¶ Bases:
object
Helper class for calls to WinDLL API.
-
class
arrangeit.windows.api.
Package
(path='')¶ Bases:
object
Helper class for calls to Windows API.
Variables: - path – filesystem path to package directory
- app_name – name of package’s first application
- Package.icon – application icon
-
app_name
= ''¶
-
icon
= <PIL.Image.Image image mode=RGB size=32x32>¶
-
path
= ''¶
-
setup_package
()¶ Retrieves and sets package data.
TODO add call to this method after window is exposed if it was minimized
Variables: root – root element of XML document
-
arrangeit.windows.api.
platform_supports_packages
()¶ Returns Boolean indicating if Windows version supports packages.
Variables: version – platform version data Returns: Boolean
-
arrangeit.windows.api.
platform_supports_virtual_desktops
()¶ Returns Boolean indicating if Windows version supports virtual desktops.
Variables: version – platform version data Returns: Boolean
arrangeit.windows.collector
– Module responsible for collecting windows (MS Windows platform specific code)¶
-
class
arrangeit.windows.collector.
Collector
¶ Bases:
arrangeit.base.BaseCollector
Collecting windows class with MS Windows specific code.
-
add_window
(hwnd)¶ Creates WindowModel instance from provided hwnd and adds it to collection.
Parameters: hwnd (int) – window id
-
check_window
(hwnd)¶ Checks does window qualify to be collected
by checking window type applicability with
is_applicable()
and its current state validity withis_valid_state()
.Parameters: hwnd (int) – window id Returns: Boolean
-
get_application_name
(hwnd)¶ Returns application name for the window represented by provided handle.
For Windows versions greater than 8.1 it uses package app_name if there’s cached package for provided hwnd.
Otherwise it tries to extract the name from executable path.
If previous methods haven’t succeed it returns window’s class name.
Parameters: - hwnd (int) – window id
- app_name (str) – executable name without extension
Returns: str
-
get_available_workspaces
()¶ Returns custom list of workspaces available on default screen.
Returned list contains two-tuples of workspace number in order and corresponding name.
Returns: [(int, str)]
-
get_monitors_rects
()¶ Returns list of available monitors position and size rectangles.
Returns: list [(x,y,w,h)]
-
get_windows
()¶ Creates and returns list of all the windows handles
Returns: list of integers
-
get_workspace_number_for_window
(hwnd)¶ Returns workspace number for the window with provided hwnd.
Parameters: hwnd (int) – window id Returns: int
-
is_applicable
(hwnd)¶ Checks if provided hwnd represents window type that should be collected.
Parameters: hwnd (int) – window id Returns: Boolean
-
is_resizable
(hwnd)¶ Checks if provided hwnd represents window that can be resized.
Parameters: hwnd (int) – window id Returns: Boolean
-
is_restored
(hwnd)¶ Checks if provided hwnd represents window that is not minimized.
Parameters: hwnd (int) – window id Returns: Boolean
-
is_valid_state
(hwnd)¶ Checks if provided hwnd represents window with valid state for collecting.
Checking just
_is_activable()
for now.Parameters: hwnd (int) – window id Returns: Boolean
-
arrangeit.windows.controller
– Module responsible for connecting data and view (MS Windows platform specific code)¶
-
class
arrangeit.windows.controller.
Controller
(app)¶ Bases:
arrangeit.base.BaseController
Controller class with MS Windows specific code.
-
screenshot_when_exposed
= True¶
-
setup_root_window
(root)¶ Sets provided root appearance attributes specific for MS Windows.
-
arrangeit.windows.vdi
– Virtual desktop interfaces for MS Windows¶
Code from this module is based on the blog <http://www.cyberforum.ru/blogs/105416/blog3671.html>. The Python implementation is based on the work by @kdschlosser <https://github.com/DanEdens/Virtual_Desktops_Plugin/blob/master/Virtualdesktops/__int__.py> (<http://www.eventghost.net>, <http://www.eventghost.net/forum/viewtopic.php?p=53308#p53308>)
-
class
arrangeit.windows.vdi.
IApplicationView
(*args, **kwargs)¶ Bases:
arrangeit.windows.vdi.IInspectable
Interface that provides view for the top-level application information.
-
class
arrangeit.windows.vdi.
IApplicationViewCollection
(*args, **kwargs)¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Interface to collection of application views for specified data group.
-
class
arrangeit.windows.vdi.
IApplicationViewConsolidatedEventArgs
(*args, **kwargs)¶ Bases:
arrangeit.windows.vdi.IInspectable
Interface providing the results of application view consolidation operations.
-
class
arrangeit.windows.vdi.
IInspectable
(*args, **kwargs)¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Interface that provides functionality required for all Windows Runtime classes.
-
class
arrangeit.windows.vdi.
IObjectArray
(*args, **kwargs)¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Interface for accessing collection of objects based on IUnknown interface.
-
class
arrangeit.windows.vdi.
IServiceProvider
(*args, **kwargs)¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Interface that provides custom support to other objects.
-
class
arrangeit.windows.vdi.
IVirtualDesktop
(*args, **kwargs)¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Class defining virtual desktop instance accessible through its pointer.
-
class
arrangeit.windows.vdi.
IVirtualDesktopManager
(*args, **kwargs)¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Interface to publicly documented methods dealing with virtual dektops.
-
class
arrangeit.windows.vdi.
IVirtualDesktopManagerInternal
(*args, **kwargs)¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Interface to methods dealing with virtual dektops documented by community.
-
class
arrangeit.windows.vdi.
VirtualDesktopsWin10
¶ Bases:
object
Helper class for calls to Windows 10 virtual desktop interfaces.
IVirtualDesktopManager is an interface publicly documented by Microsoft, whilst IVirtualDesktopManagerInternal is documented by community.
Variables: - manager – interface to publicly available API for virtual desktops
- internal_manager – interface to internal API for virtual desktops
- view_collection – interface to application views collection
- desktops – collection of virtual desktops ordinals and uids
-
desktops
= None¶
-
get_desktops
(refresh=False)¶ Returns virtual desktops collection available in the system.
Retrieves and sets instance attribute holding collection if it hasn’t been set yet or if True value is provided as
refresh
argument.Parameters: refresh (Boolean) – value indicating if desktop collection should be refreshed Returns: list of (int, GUID
)
-
get_window_desktop
(hwnd, refresh=False)¶ Returns virtual desktop where window with provided
hwnd
is placed.Parameters: - hwnd (int) – window handle
- refresh (Boolean) – value indicating if desktop collection should be refreshed
Variables: desktop_id – virtual desktop’s uid representation
Returns: (int,
GUID
)
-
internal_manager
= None¶
-
is_window_in_current_desktop
(hwnd)¶ Checks if window with provided
hwnd
is placed in current desktop.Parameters: hwnd (int) – window handle Returns: Boolean
-
manager
= None¶
-
move_other_window_to_desktop
(hwnd, desktop_ordinal)¶ Moves other process’ window with provided
hwnd
to the other desktopidentified by
desktop_ordinal
.Parameters: - hwnd (int) – window handle
- desktop_ordinal (int) – virtual desktop ordinal in desktops collection
Variables: - desktop_id – virtual desktop’s uid representation
- desktop – virtual desktop instance
- app_view – interface to application view
Returns: False on success, None on failure
-
move_own_window_to_desktop
(hwnd, desktop_ordinal)¶ Moves root window with provided
hwnd
to the desktop with provided ordinal.Parameters: - hwnd (int) – window handle
- desktop_ordinal (int) – virtual desktop ordinal in desktops collection
Variables: - desktop_id – virtual desktop’s uid representation
- desktop – virtual desktop instance
Returns: False on success, None on failure
-
view_collection
= None¶
arrangeit.windows.utils
– MS Windows specific utility functions¶
-
arrangeit.windows.utils.
extract_name_from_bytes_path
(path)¶ Returns name without directory structure and extension from given path.
Parameters: path (bytes) – full path to file Returns: str
-
arrangeit.windows.utils.
user_data_path
()¶ Returns MS Windows specific path for saving user’s data.