mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
8ebb585539
commit
21c2b5f048
@ -79,10 +79,10 @@ def get_icons(zfp, name_or_list_of_names, plugin_name=''):
|
|||||||
if plugin_name:
|
if plugin_name:
|
||||||
for name in namelist:
|
for name in namelist:
|
||||||
q = QIcon.ic(f'{plugin_name}/{name}')
|
q = QIcon.ic(f'{plugin_name}/{name}')
|
||||||
if q.isNull() or not len(q.availableSizes()):
|
if q.is_ok():
|
||||||
failed.add(name)
|
|
||||||
else:
|
|
||||||
ans[name] = q
|
ans[name] = q
|
||||||
|
else:
|
||||||
|
failed.add(name)
|
||||||
else:
|
else:
|
||||||
failed = set(namelist)
|
failed = set(namelist)
|
||||||
if failed:
|
if failed:
|
||||||
|
@ -167,11 +167,11 @@ class IconResourceManager:
|
|||||||
return QIcon(q)
|
return QIcon(q)
|
||||||
icon_name = os.path.splitext(name.replace('\\', '__').replace('/', '__'))[0]
|
icon_name = os.path.splitext(name.replace('\\', '__').replace('/', '__'))[0]
|
||||||
ans = QIcon.fromTheme(icon_name)
|
ans = QIcon.fromTheme(icon_name)
|
||||||
if ans.isNull() or not len(ans.availableSizes()):
|
if not ans.is_ok():
|
||||||
if 'user-any' in QIcon.themeName():
|
if 'user-any' in QIcon.themeName():
|
||||||
tc = 'dark' if QApplication.instance().is_dark_theme else 'light'
|
tc = 'dark' if QApplication.instance().is_dark_theme else 'light'
|
||||||
q = QIcon(f':/icons/calibre-default-{tc}/images/{name}')
|
q = QIcon(f':/icons/calibre-default-{tc}/images/{name}')
|
||||||
if not q.isNull() and len(q.availableSizes()):
|
if q.is_ok():
|
||||||
ans = q
|
ans = q
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
@ -203,6 +203,7 @@ class IconResourceManager:
|
|||||||
icon_resource_manager = IconResourceManager()
|
icon_resource_manager = IconResourceManager()
|
||||||
QIcon.ic = icon_resource_manager
|
QIcon.ic = icon_resource_manager
|
||||||
QIcon.icon_as_png = icon_resource_manager.icon_as_png
|
QIcon.icon_as_png = icon_resource_manager.icon_as_png
|
||||||
|
QIcon.is_ok = lambda self: not self.isNull() and len(self.availableSizes()) > 0
|
||||||
|
|
||||||
|
|
||||||
# Setup gprefs {{{
|
# Setup gprefs {{{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user