Skip to content

Commit 83602bb

Browse files
committed
macOS: Put the application icons in a frame
Bloody waste of time. In a few years somebody at Apple will decide they like triangular icons or 3D icons or God knows what and I will have to waste a few more hours of my life on their idiocy.
1 parent df44a58 commit 83602bb

File tree

7 files changed

+138
-33
lines changed

7 files changed

+138
-33
lines changed

icons/icns/make_iconsets.py

100644100755
+42-26
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import shutil
99
import subprocess
1010
import sys
11+
import tempfile
1112

1213
d, j, a = (getattr(os.path, x) for x in ('dirname', 'join', 'abspath'))
1314
base = d(a(__file__))
@@ -18,30 +19,45 @@
1819
if sys.argv[-1] == 'only-logo':
1920
sources = {'calibre':sources['calibre']}
2021

21-
for name, src in sources.items():
22-
iconset = name + '.iconset'
23-
if os.path.exists(iconset):
24-
shutil.rmtree(iconset)
25-
os.mkdir(iconset)
26-
os.chdir(iconset)
27-
try:
28-
for sz in (16, 32, 128, 256, 512, 1024):
29-
iname = f'icon_{sz}x{sz}.png'
30-
iname2x = f'icon_{sz // 2}x{sz // 2}@2x.png'
31-
if src.endswith('.svg'):
32-
subprocess.check_call(['rsvg-convert', src, '-w', str(sz), '-h', str(sz), '-o', iname])
33-
else:
34-
# We have a 512x512 png image
35-
if sz == 512:
36-
shutil.copy2(src, iname)
22+
23+
def render_svg(src, sz, dest):
24+
subprocess.check_call(['rsvg-convert', src, '-w', str(sz), '-h', str(sz), '-o', dest])
25+
26+
27+
with tempfile.TemporaryDirectory() as tdir:
28+
29+
def render_frame(sz: int):
30+
f = os.path.join(tdir, f'frame-{sz}.png')
31+
if not os.path.exists(f):
32+
render_svg(j(imgsrc, 'frame.svg'), sz, f)
33+
return f
34+
35+
def render_framed(sz: int, iname: str, shrink_factor: float = 0.76):
36+
frame = render_frame(sz)
37+
icon = os.path.join(tdir, f'icon-{sz}.png')
38+
render_svg(src, int(shrink_factor * sz), icon)
39+
subprocess.check_call(f'convert {frame} {icon} -gravity center -compose over -composite {iname}'.split())
40+
41+
for name, src in sources.items():
42+
iconset = name + '.iconset'
43+
if os.path.exists(iconset):
44+
shutil.rmtree(iconset)
45+
os.mkdir(iconset)
46+
os.chdir(iconset)
47+
try:
48+
for sz in (16, 32, 128, 256, 512, 1024):
49+
iname = f'icon_{sz}x{sz}.png'
50+
iname2x = f'icon_{sz // 2}x{sz // 2}@2x.png'
51+
if sz < 128:
52+
render_svg(src, sz, iname)
3753
else:
38-
subprocess.check_call(['convert', src, '-resize', f'{sz}x{sz}', iname])
39-
if sz > 16:
40-
shutil.copy2(iname, iname2x)
41-
if sz > 512:
42-
os.remove(iname)
43-
for name in (iname, iname2x):
44-
if os.path.exists(name):
45-
subprocess.check_call(['optipng', '-o7', '-strip', 'all', name])
46-
finally:
47-
os.chdir('..')
54+
render_framed(sz, iname)
55+
if sz > 16:
56+
shutil.copy2(iname, iname2x)
57+
if sz > 512:
58+
os.remove(iname)
59+
for name in (iname, iname2x):
60+
if os.path.exists(name):
61+
subprocess.check_call(['optipng', '-o7', '-strip', 'all', name])
62+
finally:
63+
os.chdir('..')

imgsrc/frame.svg

+83
Loading

src/calibre/gui2/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ def init_qt(args):
127127
# Ancient broken VNC servers cannot handle icons of size greater than 256
128128
# https://www.mobileread.com/forums/showthread.php?t=278447
129129
ic = 'lt.png' if is_x11 else 'library.png'
130-
app.setWindowIcon(QIcon(I(ic, allow_user_override=False)))
130+
if not ismacos:
131+
app.setWindowIcon(QIcon(I(ic, allow_user_override=False)))
131132
return app, opts, args
132133

133134

src/calibre/gui2/tweak_book/main.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from qt.core import QIcon
1010

11-
from calibre.constants import EDITOR_APP_UID, islinux
11+
from calibre.constants import EDITOR_APP_UID, islinux, ismacos
1212
from calibre.ebooks.oeb.polish.check.css import shutdown as shutdown_css_check_pool
1313
from calibre.gui2 import Application, decouple, set_gui_prefs, setup_gui_option_parser
1414
from calibre.ptempfile import reset_base_dir
@@ -60,7 +60,8 @@ def _run(args, notify=None):
6060
from calibre.utils.webengine import setup_default_profile
6161
setup_default_profile()
6262
app.load_builtin_fonts()
63-
app.setWindowIcon(QIcon.ic('tweak.png'))
63+
if not ismacos:
64+
app.setWindowIcon(QIcon.ic('tweak.png'))
6465
main = Main(opts, notify=notify)
6566
main.set_exception_handler()
6667
main.show()

src/calibre/gui2/tweak_book/ui.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from qt.core import (
1212
QAction,
13+
QApplication,
1314
QDockWidget,
1415
QEvent,
1516
QHBoxLayout,
@@ -285,7 +286,8 @@ def __init__(self, opts, notify=None):
285286
traceback.print_exc()
286287
self.setWindowTitle(self.APP_NAME)
287288
self.boss = Boss(self, notify=notify)
288-
self.setWindowIcon(QIcon.ic('tweak.png'))
289+
if not ismacos:
290+
self.setWindowIcon(QApplication.instance().windowIcon())
289291
self.opts = opts
290292
self.path_to_ebook = None
291293
self.container = None

src/calibre/gui2/ui.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
125125
def __init__(self, opts, parent=None, gui_debug=None):
126126
MainWindow.__init__(self, opts, parent=parent, disable_automatic_gc=True)
127127
self.setVisible(False)
128-
self.setWindowIcon(QApplication.instance().windowIcon())
128+
if not ismacos:
129+
self.setWindowIcon(QApplication.instance().windowIcon())
129130
self.extra_files_watcher = ExtraFilesWatcher(self)
130131
self.jobs_pointer = Pointer(self)
131132
self.proceed_requested.connect(self.do_proceed,

src/calibre/gui2/viewer/main.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from qt.core import QIcon, QObject, Qt, QTimer, pyqtSignal
1111

12-
from calibre.constants import VIEWER_APP_UID, islinux
12+
from calibre.constants import VIEWER_APP_UID, islinux, ismacos
1313
from calibre.gui2 import Application, error_dialog, setup_gui_option_parser
1414
from calibre.gui2.listener import send_message_in_process
1515
from calibre.gui2.viewer.config import get_session_pref, vprefs
@@ -149,7 +149,8 @@ def run_gui(app, opts, args, internal_book_data, listener=None):
149149
acc = EventAccumulator(app)
150150
app.file_event_hook = acc
151151
app.load_builtin_fonts()
152-
app.setWindowIcon(QIcon.ic('viewer.png'))
152+
if not ismacos:
153+
app.setWindowIcon(QIcon.ic('viewer.png'))
153154
migrate_previous_viewer_prefs()
154155
main = EbookViewer(
155156
open_at=opts.open_at, continue_reading=opts.continue_reading, force_reload=opts.force_reload,

0 commit comments

Comments
 (0)