Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为 macOS 添加了专用窗口属性 #65

Merged
merged 9 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions maliang/core/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def fullscreen(self, value: bool | None = True) -> bool | None:

@_fixed_theme
def toolwindow(self, value: bool | None = True) -> bool | None:
"""Set or get whether the window is tool-window
"""Set or get whether the window is tool-window.

* `value`: indicate whether the window is tool-window

Expand All @@ -299,7 +299,7 @@ def toolwindow(self, value: bool | None = True) -> bool | None:
return None if result == "" else bool(result)

def transparentcolor(self, value: str | None = None) -> str | None:
"""Set or get the penetration color of the window
"""Set or get the penetration color of the window.

* `value`: the penetration color of the window

Expand All @@ -308,6 +308,28 @@ def transparentcolor(self, value: str | None = None) -> str | None:
result = self.wm_attributes("-transparentcolor", value)
return None if result == "" else result

elif platform.system() == "Darwin":

def modified(self, value: bool | None = None) -> bool | None:
"""Set or get whether the window is modified.

* `value`: indicate whether the window is modified

This method only works on macOS!
"""
result = self.wm_attributes("-modified", value)
return None if result == "" else bool(result)

def transparent(self, value: bool | None = None) -> bool | None:
"""Set or get whether the window is transparent.

* `value`: indicate whether the window is transparent

This method only works on macOS!
"""
result = self.wm_attributes("-transparent", value)
return None if result == "" else bool(result)

@typing_extensions.override
def destroy(self) -> None:
"""Destroy this and all descendants widgets."""
Expand Down
14 changes: 14 additions & 0 deletions tests/test_core/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ def test_transparentcolor(self) -> None:
self.assertIsNone(tk.transparentcolor(""))
self.assertEqual(tk.transparentcolor(), None)

@unittest.skipUnless(platform.system() == "Darwin", "Only works on Darwin")
def test_modified(self) -> None:
with containers.Tk() as tk:
self.assertFalse(tk.modified())
self.assertIsNone(tk.modified(True))
self.assertTrue(tk.modified())

@unittest.skipUnless(platform.system() == "Darwin", "Only works on Darwin")
def test_transparent(self) -> None:
with containers.Tk() as tk:
self.assertFalse(tk.transparent())
self.assertIsNone(tk.transparent(True))
self.assertTrue(tk.transparent())

def test_center(self) -> None:
with containers.Tk() as tk:
tk.center()
Expand Down
Loading