openlp/openlp/core/ui/icons.py

211 lines
10 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2018-04-10 19:26:56 +00:00
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
2022-02-01 10:10:57 +00:00
# Copyright (c) 2008-2022 OpenLP Developers #
2019-04-13 13:00:22 +00:00
# ---------------------------------------------------------------------- #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
2018-04-10 19:26:56 +00:00
"""
The :mod:`languages` module provides a list of icons.
"""
2018-07-15 19:54:41 +00:00
import logging
2018-04-10 19:26:56 +00:00
2018-10-02 04:39:42 +00:00
import qtawesome as qta
2018-04-10 19:26:56 +00:00
from PyQt5 import QtGui, QtWidgets
2019-07-20 12:27:28 +00:00
from openlp.core.common import Singleton
2018-05-08 18:44:47 +00:00
from openlp.core.common.applocation import AppLocation
2018-04-21 19:57:51 +00:00
from openlp.core.lib import build_icon
2021-09-01 18:34:06 +00:00
from openlp.core.ui.style import is_ui_theme_dark
2018-04-21 19:57:51 +00:00
2018-10-02 04:39:42 +00:00
2018-07-15 19:54:41 +00:00
log = logging.getLogger(__name__)
2018-04-10 19:26:56 +00:00
2019-07-20 12:27:28 +00:00
class UiIcons(metaclass=Singleton):
2018-04-10 19:26:56 +00:00
"""
Provide standard icons for objects to use.
"""
2019-07-20 12:27:28 +00:00
def __init__(self):
2018-04-10 19:26:56 +00:00
"""
These are the font icons used in the code.
"""
2018-05-08 18:44:47 +00:00
font_path = AppLocation.get_directory(AppLocation.AppDir) / 'core' / 'ui' / 'fonts' / 'OpenLP.ttf'
charmap_path = AppLocation.get_directory(AppLocation.AppDir) / 'core' / 'ui' / 'fonts' / 'openlp-charmap.json'
qta.load_font('op', font_path, charmap_path)
2018-04-10 19:26:56 +00:00
palette = QtWidgets.QApplication.palette()
qta.set_defaults(color=palette.color(QtGui.QPalette.Active,
2020-07-03 18:45:17 +00:00
QtGui.QPalette.WindowText),
2018-04-10 19:26:56 +00:00
color_disabled=palette.color(QtGui.QPalette.Disabled,
2020-07-03 18:45:17 +00:00
QtGui.QPalette.WindowText))
icon_list = {
2018-05-06 20:11:06 +00:00
'active': {'icon': 'fa.child'},
2018-05-06 08:03:42 +00:00
'add': {'icon': 'fa.plus-circle'},
'alert': {'icon': 'fa.exclamation-triangle'},
'arrow_down': {'icon': 'fa.arrow-down'},
'arrow_left': {'icon': 'fa.arrow-left'},
'arrow_right': {'icon': 'fa.arrow-right'},
'arrow_up': {'icon': 'fa.arrow-up'},
'audio': {'icon': 'fa.file-sound-o'},
2018-06-16 06:09:15 +00:00
'authentication': {'icon': 'fa.exclamation-triangle', 'attr': 'red'},
2018-05-06 08:03:42 +00:00
'address': {'icon': 'fa.book'},
'back': {'icon': 'fa.step-backward'},
'backspace': {'icon': 'fa.times'},
# 'backspace': {'icon': 'fa.caret-square-o-left'},
2018-05-06 08:03:42 +00:00
'bible': {'icon': 'fa.book'},
'blank': {'icon': 'fa.times-circle'},
2018-06-02 06:37:31 +00:00
'blank_theme': {'icon': 'fa.file-image-o'},
'bold': {'icon': 'fa.bold'},
2018-05-06 20:11:06 +00:00
'book': {'icon': 'fa.book'},
2018-05-06 08:03:42 +00:00
'bottom': {'icon': 'fa.angle-double-down'},
2018-06-24 06:56:50 +00:00
'box': {'icon': 'fa.briefcase'},
'clapperboard': {'icon': 'fa.film'},
2018-05-06 08:03:42 +00:00
'clock': {'icon': 'fa.clock-o'},
'clone': {'icon': 'fa.clone'},
2018-05-08 19:45:34 +00:00
'close': {'icon': 'fa.times-circle-o'},
2018-05-06 08:03:42 +00:00
'copy': {'icon': 'fa.copy'},
'copyright': {'icon': 'fa.copyright'},
'database': {'icon': 'fa.database'},
'default': {'icon': 'fa.info-circle'},
'desktop': {'icon': 'fa.desktop'},
'delete': {'icon': 'fa.trash'},
'device_stream': {'icon': 'fa.video-camera'},
2018-08-04 21:01:15 +00:00
'download': {'icon': 'fa.download'},
'edit': {'icon': 'op.edit'},
2018-05-06 08:03:42 +00:00
'email': {'icon': 'fa.envelope'},
2018-06-16 06:09:15 +00:00
'error': {'icon': 'fa.exclamation', 'attr': 'red'},
2018-05-08 19:45:34 +00:00
'exception': {'icon': 'fa.times-circle'},
2018-05-06 08:03:42 +00:00
'exit': {'icon': 'fa.sign-out'},
'folder': {'icon': 'fa.folder'},
2018-05-06 08:03:42 +00:00
'group': {'icon': 'fa.object-group'},
2018-05-07 06:44:57 +00:00
'inactive': {'icon': 'fa.child', 'attr': 'lightGray'},
2018-05-06 08:03:42 +00:00
'info': {'icon': 'fa.info'},
'italic': {'icon': 'fa.italic'},
2018-06-03 16:07:20 +00:00
'light_bulb': {'icon': 'fa.lightbulb-o'},
'live': {'icon': 'op.live'},
'live_presentation': {'icon': 'op.live-presentation'},
'live_theme': {'icon': 'op.live-theme'},
'live_black': {'icon': 'op.live-black'},
'live_desktop': {'icon': 'op.live-desktop'},
'loop': {'icon': 'op.loop'},
2018-05-06 08:03:42 +00:00
'manual': {'icon': 'fa.graduation-cap'},
2018-05-08 19:45:34 +00:00
'media': {'icon': 'fa.fax'},
2018-05-06 08:03:42 +00:00
'minus': {'icon': 'fa.minus'},
'move_start': {'icon': 'op.move-start'},
'move_up': {'icon': 'op.move-up'},
'move_down': {'icon': 'op.move-down'},
'move_end': {'icon': 'op.move-end'},
2018-05-06 08:03:42 +00:00
'music': {'icon': 'fa.music'},
2020-03-08 22:05:09 +00:00
'network_stream': {'icon': 'fa.link'},
'new': {'icon': 'op.new'},
2018-05-06 08:03:42 +00:00
'new_group': {'icon': 'fa.folder'},
'notes': {'icon': 'fa.sticky-note'},
'open': {'icon': 'fa.folder-open'},
'optical': {'icon': 'fa.circle-thin'},
2018-05-06 08:03:42 +00:00
'pause': {'icon': 'fa.pause'},
2019-11-09 16:17:41 +00:00
'planning_center': {'icon': 'fa.cloud-download'},
2018-05-06 08:03:42 +00:00
'play': {'icon': 'fa.play'},
2018-06-03 16:07:20 +00:00
'player': {'icon': 'fa.tablet'},
'play_slides': {'icon': 'op.play-slides'},
2018-06-02 06:37:31 +00:00
'plugin_list': {'icon': 'fa.puzzle-piece'},
2018-05-06 08:03:42 +00:00
'plus': {'icon': 'fa.plus'},
'presentation': {'icon': 'fa.bar-chart'},
'preview': {'icon': 'fa.laptop'},
2018-06-24 06:56:50 +00:00
'projector': {'icon': 'op.video'},
2019-03-08 15:19:57 +00:00
'projector_connect': {'icon': 'fa.plug'}, # Projector connect
2018-06-10 19:29:00 +00:00
'projector_cooldown': {'icon': 'fa.video-camera', 'attr': 'blue'},
2019-03-08 15:19:57 +00:00
'projector_disconnect': {'icon': 'fa.plug', 'attr': 'lightGray'}, # Projector disconnect
2018-06-10 19:29:00 +00:00
'projector_error': {'icon': 'fa.video-camera', 'attr': 'red'},
2018-06-16 06:09:15 +00:00
'projector_hdmi': {'icon': 'op.hdmi'},
2019-03-08 15:19:57 +00:00
'projector_power_off': {'icon': 'fa.video-camera', 'attr': 'red'}, # Toolbar power off
'projector_power_on': {'icon': 'fa.video-camera', 'attr': 'green'}, # Toolbar power on
'projector_off': {'icon': 'fa.video-camera', 'attr': 'black'}, # Projector off
'projector_on': {'icon': 'fa.video-camera', 'attr': 'green'}, # Projector on
'projector_select_connect': {'icon': 'fa.plug', 'attr': 'green'}, # Toolbar connect
'projector_select_disconnect': {'icon': 'fa.plug', 'attr': 'red'}, # Toolbar disconnect
2018-06-10 19:29:00 +00:00
'projector_warmup': {'icon': 'fa.video-camera', 'attr': 'yellow'},
2018-05-06 08:03:42 +00:00
'picture': {'icon': 'fa.picture-o'},
'print': {'icon': 'fa.print'},
'remote': {'icon': 'fa.rss'},
'repeat': {'icon': 'fa.repeat'},
'save': {'icon': 'fa.save'},
'search': {'icon': 'fa.search'},
2018-06-03 16:07:20 +00:00
'search_ccli': {'icon': 'op.search-CCLI'},
2018-05-06 19:50:41 +00:00
'search_comb': {'icon': 'fa.columns'},
'search_lyrics': {'icon': 'op.search-lyrics'},
2018-05-06 08:03:42 +00:00
'search_minus': {'icon': 'fa.search-minus'},
'search_plus': {'icon': 'fa.search-plus'},
2018-05-06 19:50:41 +00:00
'search_ref': {'icon': 'fa.institution'},
2018-06-03 16:07:20 +00:00
'search_text': {'icon': 'op.search-text'},
2019-02-15 22:34:53 +00:00
'select_all': {'icon': 'fa.check-square-o'},
'select_none': {'icon': 'fa.square-o'},
2018-05-06 08:03:42 +00:00
'settings': {'icon': 'fa.cogs'},
'shortcuts': {'icon': 'fa.wrench'},
2018-05-08 19:45:34 +00:00
'song_usage': {'icon': 'fa.line-chart'},
'song_usage_active': {'icon': 'op.plus-sign'},
'song_usage_inactive': {'icon': 'op.minus-sign'},
2018-05-06 19:50:41 +00:00
'sort': {'icon': 'fa.sort'},
'stop': {'icon': 'op.stop'},
2018-05-06 19:50:41 +00:00
'square': {'icon': 'fa.square'},
2018-05-08 18:44:47 +00:00
'text': {'icon': 'op.file-text'},
2018-05-08 19:45:34 +00:00
'time': {'icon': 'fa.history'},
2018-06-02 06:37:31 +00:00
'theme': {'icon': 'fa.paint-brush'},
2018-05-06 08:03:42 +00:00
'top': {'icon': 'fa.angle-double-up'},
'undo': {'icon': 'fa.undo'},
2018-08-04 21:01:15 +00:00
'upload': {'icon': 'fa.upload'},
2018-05-06 08:03:42 +00:00
'user': {'icon': 'fa.user'},
2018-05-08 18:44:47 +00:00
'usermo': {'icon': 'op.users'},
2018-05-06 08:03:42 +00:00
'users': {'icon': 'fa.users'},
2018-06-24 06:56:50 +00:00
'video': {'icon': 'fa.file-video-o'},
'volunteer': {'icon': 'fa.group'}
}
2019-07-03 13:23:23 +00:00
self.load_icons(icon_list)
2019-07-20 12:27:28 +00:00
self.main_icon = build_icon(':/icon/openlp-logo.svg')
2018-06-10 19:29:00 +00:00
def load_icons(self, icon_list):
"""
Load the list of icons to be processed
"""
2021-09-01 18:34:06 +00:00
is_dark = is_ui_theme_dark()
for key in icon_list:
try:
2018-05-06 08:03:42 +00:00
icon = icon_list[key]['icon']
try:
attr = icon_list[key]['attr']
2018-05-07 06:44:57 +00:00
setattr(self, key, qta.icon(icon, color=attr))
except KeyError:
2020-01-06 21:15:11 +00:00
if is_dark:
setattr(self, key, qta.icon(icon, color='white'))
else:
setattr(self, key, qta.icon(icon))
2018-05-07 06:44:57 +00:00
except Exception:
log.exception(f'Unexpected error for icon: {icon}')
setattr(self, key, qta.icon('fa.exclamation-circle', color='red'))
2018-10-27 01:53:43 +00:00
except Exception:
log.exception(f'Unexpected error for icon with key: {key}')
setattr(self, key, qta.icon('fa.exclamation-circle', color='red'))
2018-04-21 19:57:51 +00:00
@staticmethod
def _print_icons():
"""
2018-06-10 19:29:00 +00:00
Have ability to dump icons to see what is actually available. Can only run within an application
:return:
"""
ico = qta._resource['iconic']
fa = ico.charmap['fa']
for ky in fa.keys():
print(ky, fa[ky])