Fix Python rocket icon showing in dock on macOS after Set As Wallpaper

This commit is contained in:
Isaiah Odhner 2023-07-18 17:49:55 -04:00
parent 5c7272db91
commit 1c64fdb78c
4 changed files with 19 additions and 3 deletions

View File

@ -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).

View File

@ -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",

View File

@ -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

View File

@ -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