Skip to content

Commit

Permalink
ALL: Renamed findMonitors() and findMonitorsInfo to findMonitorsAtPoi…
Browse files Browse the repository at this point in the history
…nt() and findMonitorsAtPointInfo().

Added findMonitorWithName() and findMonitorWithNameInfo()
  • Loading branch information
Kalmat committed Sep 15, 2023
1 parent dbbb793 commit 36fa2a3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
Binary file modified dist/PyMonCtl-0.6-py3-none-any.whl
Binary file not shown.
6 changes: 4 additions & 2 deletions src/pymonctl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# -*- coding: utf-8 -*-

__all__ = [
"getAllMonitors", "getAllMonitorsDict", "getMonitorsCount", "getPrimary", "findMonitor", "findMonitorInfo",
"getAllMonitors", "getAllMonitorsDict", "getMonitorsCount", "getPrimary", "findMonitorsAtPoint",
"findMonitorsAtPointInfo",
"arrangeMonitors", "getMousePos", "version", "Monitor",
"enableUpdateInfo", "disableUpdateInfo", "isUpdateInfoEnabled", "isWatchdogEnabled", "updateWatchdogInterval",
"plugListenerRegister", "plugListenerUnregister", "isPlugListenerRegistered",
Expand All @@ -18,7 +19,8 @@ def version(numberOnly: bool = True) -> str:
return ("" if numberOnly else "PyMonCtl-")+__version__


from ._main import (getAllMonitors, getAllMonitorsDict, getMonitorsCount, getPrimary, findMonitor, findMonitorInfo,
from ._main import (getAllMonitors, getAllMonitorsDict, getMonitorsCount, getPrimary,
findMonitorsAtPoint, findMonitorsAtPointInfo, findMonitorWithName, findMonitorWithNameInfo,
arrangeMonitors, getMousePos, Monitor,
enableUpdateInfo, disableUpdateInfo, isUpdateInfoEnabled, isWatchdogEnabled, updateWatchdogInterval,
plugListenerRegister, plugListenerUnregister, isPlugListenerRegistered,
Expand Down
50 changes: 42 additions & 8 deletions src/pymonctl/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def getAllMonitorsDict() -> dict[str, ScreenValue]:
Values:
"system_name":
display name as returned by the system (in macOS, the name can be duplicated!)
"handle":
"id":
display handle according to each platform/OS
"is_primary":
''True'' if monitor is primary (shows clock and notification area, sign in, lock, CTRL+ALT+DELETE screens...)
Expand Down Expand Up @@ -95,28 +95,62 @@ def getPrimary() -> Monitor:
return _getPrimary()


def findMonitor(x: int, y: int) -> List[Monitor]:
def findMonitorsAtPoint(x: int, y: int) -> List[Monitor]:
"""
Get monitor instance in which given coordinates (x, y) are found.
Get all Monitor class instances in which given coordinates (x, y) are found.
:return: Monitor instance or None
:param x: target X coordinate
:param y: target Y coordinate
:return: List of Monitor instances or empty
"""
return _findMonitor(x, y)


def findMonitorInfo(x: int, y: int) -> dict[str, ScreenValue]:
def findMonitorsAtPointInfo(x: int, y: int) -> List[dict[str, ScreenValue]]:
"""
Get monitor info in which given coordinates (x, y) are found.
Get all monitors info in which given coordinates (x, y) are found.
:return: monitor info (see getAllMonitorsDict() doc) as dictionary, or empty
:param x: target X coordinate
:param y: target Y coordinate
:return: list of monitor info (see getAllMonitorsDict() doc) as a list of dicts, or empty
"""
info: dict[str, ScreenValue] = {}
info: List[dict[str, ScreenValue]] = [{}]
monitors = getAllMonitorsDict()
for monitor in monitors.keys():
pos = monitors[monitor]["position"]
size = monitors[monitor]["size"]
if _pointInBox(x, y, pos.x, pos.y, size.width, size.height):
info.append({monitor: monitors[monitor]})
return info


def findMonitorWithName(name: str) -> Optional[Monitor]:
"""
Get the Monitor class instance which name matches given name.
:param name: target monitor name
:return: Monitor or None if not found
"""
monitors = getAllMonitorsDict()
for monitor in monitors.keys():
if monitor == name:
return Monitor(monitors[monitor]["id"])
return None


def findMonitorWithNameInfo(name: str) -> dict[str, ScreenValue]:
"""
Get monitor instance which name matches given name.
:param name: target monitor name
:return: monitor info (see getAllMonitorsDict() doc) as dict, or empty
"""
info: dict[str, ScreenValue] = {}
monitors = getAllMonitorsDict()
for monitor in monitors.keys():
if monitor == name:
info[monitor] = monitors[monitor]
break
return info


Expand Down

0 comments on commit 36fa2a3

Please sign in to comment.