Skip to content

Commit

Permalink
Always prefer 'Tango' icon theme (#250)
Browse files Browse the repository at this point in the history
The legacy behavior was to attempt to detect if an existing theme was
already set which supplied some of the needed icons, and if not, use the
Tango theme specifically. If that didn't work either, revert the change
to the original theme (or lack thereof).

The current behavior changes the theme only if no theme is set, and only
if tango_icons_vendor is installed.

This change makes qt_gui always prefer the 'Tango' theme, and always
prefer the version supplied by tango_icons_vendor (if available). If
'Tango' is not available, fall back to the system theme.

Signed-off-by: Scott K Logan <logans@cottsay.net>
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
  • Loading branch information
cottsay and clalancette authored Apr 29, 2021
1 parent 9eb8e8e commit 71f7432
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions qt_gui/src/qt_gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

from argparse import ArgumentParser, SUPPRESS
import os
import platform
import signal
import sys

Expand Down Expand Up @@ -193,20 +192,19 @@ def _add_reload_paths(self, reload_importer):

def _set_theme_if_necessary(self):
from python_qt_binding.QtGui import QIcon
# if themeName is defined we are on Linux
# otherwise try to use the them provided by tango_icons_vendor
if not QIcon.themeName():
package_path = has_resource('packages', 'tango_icons_vendor')
if package_path:
icon_paths = QIcon.themeSearchPaths()
icon_paths.append(os.path.join(
package_path, 'share', 'tango_icons_vendor',
'resource', 'icons', 'Tango'))
QIcon.setThemeSearchPaths(icon_paths)
QIcon.setThemeName('scalable')
elif platform.system() != 'Linux':
print("The 'tango_icons_vendor' package was not found - icons "
'will not work', file=sys.stderr)
# Always prefer tango_icons_vendor
package_path = has_resource('packages', 'tango_icons_vendor')
if package_path:
icon_paths = QIcon.themeSearchPaths()
icon_paths = [
os.path.join(package_path, 'share', 'tango_icons_vendor', 'resource', 'icons')
] + icon_paths
QIcon.setThemeSearchPaths(icon_paths)
# Use Tango if possible, fall back to system default
original_theme = QIcon.themeName()
QIcon.setThemeName('Tango')
if QIcon.fromTheme('document-save').isNull():
QIcon.setThemeName(original_theme)

def create_application(self, argv):
from python_qt_binding.QtCore import Qt
Expand Down

0 comments on commit 71f7432

Please sign in to comment.