Skip to content

Commit

Permalink
New approach based on Monitor() class to access all properties and fu…
Browse files Browse the repository at this point in the history
…nctionalities. macOS is still experimental and not tested on multi-monitor setups.
  • Loading branch information
Kalmat committed Jun 16, 2023
1 parent 363f14d commit 590250d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
Binary file modified dist/PyMonCtl-0.0.9-py3-none-any.whl
Binary file not shown.
8 changes: 4 additions & 4 deletions src/pymonctl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def orientation(self) -> Optional[Union[int, Orientation]]:
raise NotImplementedError

@abstractmethod
def setOrientation(self, orientation: Orientation):
def setOrientation(self, orientation: Optional[Union[int, Orientation]]):
"""
Change orientation for the monitor identified by name (or primary if empty)
Expand Down Expand Up @@ -350,7 +350,7 @@ def brightness(self) -> Optional[int]:
raise NotImplementedError

@abstractmethod
def setBrightness(self, brightness):
def setBrightness(self, brightness: Optional[int]):
"""
Change the brightness of monitor. The input parameter must be defined as a percentage (0-100)
"""
Expand All @@ -369,7 +369,7 @@ def contrast(self) -> Optional[int]:
raise NotImplementedError

@abstractmethod
def setContrast(self, contrast: int):
def setContrast(self, contrast: Optional[int]):
"""
Change the contrast of monitor. The input parameter must be defined as a percentage (0-100)
Expand All @@ -390,7 +390,7 @@ def mode(self) -> Optional[DisplayMode]:
raise NotImplementedError

@abstractmethod
def setMode(self, mode: DisplayMode):
def setMode(self, mode: Optional[DisplayMode]):
"""
Change current monitor mode (resolution and/or refresh-rate) for the monitor
Expand Down
8 changes: 4 additions & 4 deletions src/pymonctl/_pymonctl_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def orientation(self) -> Optional[Union[int, Orientation]]:
return rot
return None

def setOrientation(self, orientation: Orientation):
def setOrientation(self, orientation: Optional[Union[int, Orientation]]):
if orientation in (NORMAL, INVERTED, LEFT, RIGHT):
outputs = _XgetAllOutputs(self.name)
for outputData in outputs:
Expand Down Expand Up @@ -359,7 +359,7 @@ def brightness(self) -> Optional[int]:
# '--method org.freedesktop.DBus.Properties.Get org.gnome.SettingsDaemon.Power.Screen '
# 'Brightness')

def setBrightness(self, brightness: int):
def setBrightness(self, brightness: Optional[int]):
# https://unix.stackexchange.com/questions/150816/how-can-i-lazily-read-output-from-xrandr
if brightness is not None:
value = brightness / 100
Expand All @@ -380,7 +380,7 @@ def contrast(self) -> Optional[int]:
value = int(((1 / (float(r) or 1)) + (1 / (float(g) or 1)) + (1 / (float(b) or 1))) / 3) * 100
return value

def setContrast(self, contrast: int):
def setContrast(self, contrast: Optional[int]):
if contrast is not None:
value = contrast / 100
if 0 <= value <= 1:
Expand Down Expand Up @@ -408,7 +408,7 @@ def mode(self) -> Optional[DisplayMode]:
pass
return value

def setMode(self, mode: DisplayMode):
def setMode(self, mode: Optional[DisplayMode]):
# https://stackoverflow.com/questions/12706631/x11-change-resolution-and-make-window-fullscreen
# Xlib.ext.randr.set_screen_size(defaultRootWindow.root, mode.width, mode.height, 0, 0)
# Xlib.ext.randr.set_screen_config(defaultRootWindow.root, size_id, 0, 0, round(mode.frequency), 0)
Expand Down
8 changes: 4 additions & 4 deletions src/pymonctl/_pymonctl_macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def orientation(self) -> Optional[Union[int, Orientation]]:
return orientation
return None

def setOrientation(self, orientation: Union[int, Orientation]):
def setOrientation(self, orientation: Optional[Union[int, Orientation]]):
# display = self._dm.Display(self.handle)
# if orientation in (NORMAL, INVERTED, LEFT, RIGHT):
# display.setRotate(orientation * 90)
Expand Down Expand Up @@ -334,7 +334,7 @@ def brightness(self) -> Optional[int]:
# value = int(float(ret)) * 100
# return value

def setBrightness(self, brightness: int):
def setBrightness(self, brightness: Optional[int]):
# display = self._dm.Display(self.handle)
# try:
# display.setBrightness(brightness)
Expand All @@ -354,7 +354,7 @@ def contrast(self) -> Optional[int]:
# raise NotImplementedError
return None

def setContrast(self, contrast: int):
def setContrast(self, contrast: Optional[int]):
# Decrease display contrast: Command+Option+Control-
# Increase display contrast: Command+Option+Control+
# raise NotImplementedError
Expand All @@ -369,7 +369,7 @@ def mode(self) -> Optional[DisplayMode]:
res = DisplayMode(w, h, r)
return res

def setMode(self, mode: DisplayMode):
def setMode(self, mode: Optional[DisplayMode]):
# https://stackoverflow.com/questions/10596489/programmatically-change-resolution-os-x
if mode is not None:
allModes = Quartz.CGDisplayCopyAllDisplayModes(self.handle, None)
Expand Down
8 changes: 4 additions & 4 deletions src/pymonctl/_pymonctl_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def orientation(self) -> Optional[Union[int, Orientation]]:
return settings.DisplayOrientation
return None

def setOrientation(self, orientation: Orientation):
def setOrientation(self, orientation: Optional[Union[int, Orientation]]):
if orientation in (NORMAL, INVERTED, LEFT, RIGHT):
devmode = pywintypes.DEVMODEType() # type: ignore[attr-defined]
devmode.DisplayOrientation = orientation
Expand Down Expand Up @@ -257,7 +257,7 @@ def brightness(self) -> Optional[int]:
return normBrightness
return None

def setBrightness(self, brightness: int):
def setBrightness(self, brightness: Optional[int]):
if brightness is not None:
minBright = ctypes.c_uint()
currBright = ctypes.c_uint()
Expand Down Expand Up @@ -288,7 +288,7 @@ def contrast(self) -> Optional[int]:
return normContrast
return None

def setContrast(self, contrast: int):
def setContrast(self, contrast: Optional[int]):
if contrast is not None:
minCont = ctypes.c_uint()
currCont = ctypes.c_uint()
Expand All @@ -307,7 +307,7 @@ def mode(self) -> Optional[DisplayMode]:
winSettings = win32api.EnumDisplaySettings(self.name, win32con.ENUM_CURRENT_SETTINGS)
return DisplayMode(winSettings.PelsWidth, winSettings.PelsHeight, winSettings.DisplayFrequency)

def setMode(self, mode: DisplayMode):
def setMode(self, mode: Optional[DisplayMode]):
if DisplayMode:
devmode = pywintypes.DEVMODEType() # type: ignore[attr-defined]
devmode.PelsWidth = mode.width
Expand Down

0 comments on commit 590250d

Please sign in to comment.