From 1c64fdb78cf7be5767db54c7d1bc46e3433d33ab Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Tue, 18 Jul 2023 17:49:55 -0400 Subject: [PATCH] Fix Python rocket icon showing in dock on macOS after Set As Wallpaper --- README.md | 2 -- cspell.json | 3 +++ requirements.txt | 3 ++- src/textual_paint/paint.py | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b086d84..3b79ab4 100644 --- a/README.md +++ b/README.md @@ -224,8 +224,6 @@ GNOME Terminal works best, with crisp triangles used for icons in dialogs, emoji ### macOS -For **Set As Wallpaper**, it works better if you install tkinter, with `brew install python-tk`, so it can use your monitor's resolution. (This dependency could be removed in the future.) - Tested on OSX 10.14 (Mojave), with iTerm2, and VS Code's integrated terminal. iTerm2 mostly works, but two tool icons are missing (Free-Form Select and Fill With Color). diff --git a/cspell.json b/cspell.json index 91177c8..7ed204b 100644 --- a/cspell.json +++ b/cspell.json @@ -51,6 +51,7 @@ "getpid", "getpixel", "goland", + "gsettings", "gvim", "hackily", "Haha", @@ -75,6 +76,7 @@ "Nemo", "Noto", "Odhner", + "osascript", "pagedown", "pageup", "palettized", @@ -88,6 +90,7 @@ "pycache", "pyfiglet", "Pylance", + "pyobjc", "pyperclip", "pypixelart", "pyright", diff --git a/requirements.txt b/requirements.txt index 116248c..9e8e7b1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ -appscript==1.2.2; sys_platform == 'darwin' +appscript==1.2.2; sys_platform == 'darwin' # for setting the wallpaper on macOS; optional, falls back to osascript CLI +pyobjc-framework-Quartz==9.2; sys_platform == 'darwin' # for getting the screen resolution on macOS; optional, falls back to 1920x1080 Pillow==9.5.0 # psutil==5.9.0 # for cleaning up open files when auto-restarting on changes in development; optional pyfiglet==0.8.post1 diff --git a/src/textual_paint/paint.py b/src/textual_paint/paint.py index bae2d5c..e9cee8c 100755 --- a/src/textual_paint/paint.py +++ b/src/textual_paint/paint.py @@ -11,6 +11,7 @@ import argparse import asyncio from enum import Enum from random import randint, random +import sys from typing import Any, Coroutine, NamedTuple, Optional, Callable, Iterator from uuid import uuid4 @@ -3604,6 +3605,19 @@ Columns: {len(palette) // 2} """Get the screen size.""" # TODO: test DPI scaling try: + # special macOS handling to avoid a Python rocket icon bouncing in the dock + # (with screeninfo module it bounced; with tkinter it didn't, but still it stayed there indefinitely) + if sys.platform == "darwin": + # from AppKit import NSScreen + # screen = NSScreen.mainScreen() # Shows rocket icon in dock... + # size = screen.frame().size.width, screen.frame().size.height + # return size + + from Quartz import CGDisplayBounds + from Quartz import CGMainDisplayID + main_monitor = CGDisplayBounds(CGMainDisplayID()) + return (int(main_monitor.size.width), int(main_monitor.size.height)) + # from screeninfo import get_monitors # largest_area = 0 # largest_monitor = None