From 24c9bf10db4622fe63d7096158f5bf08059303d3 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 16 Jul 2010 07:33:45 -0500 Subject: [PATCH] Maemo 4.1 has an older Qt without fromTheme, so let's abstract that away and switch to trying to use fd.o icon naming --- src/ejpi_qt.py | 8 ++------ src/maeqt.py | 22 ++++++++++++++++++++++ src/qhistory.py | 6 +++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/ejpi_qt.py b/src/ejpi_qt.py index 3c063cc..8992f72 100755 --- a/src/ejpi_qt.py +++ b/src/ejpi_qt.py @@ -129,9 +129,7 @@ class QErrorDisplay(object): def __init__(self): self._messages = [] - errorIcon = QtGui.QIcon.fromTheme("app_install_error") - if errorIcon.isNull(): - errorIcon = QtGui.QIcon.fromTheme("gtk-dialog-error") + errorIcon = maeqt.get_theme_icon(("dialog-error", "app_install_error", "gtk-dialog-error")) self._severityIcon = errorIcon.pixmap(32, 32) self._severityLabel = QtGui.QLabel() self._severityLabel.setPixmap(self._severityIcon) @@ -139,9 +137,7 @@ class QErrorDisplay(object): self._message = QtGui.QLabel() self._message.setText("Boo") - closeIcon = QtGui.QIcon.fromTheme("general_close") - if closeIcon.isNull(): - closeIcon = QtGui.QIcon.fromTheme("gtk-close") + closeIcon = maeqt.get_theme_icon(("window-close", "general_close", "gtk-close")) self._closeLabel = QtGui.QPushButton(closeIcon, "") self._closeLabel.clicked.connect(self._on_close) diff --git a/src/maeqt.py b/src/maeqt.py index b240fe5..d5eb18b 100644 --- a/src/maeqt.py +++ b/src/maeqt.py @@ -98,3 +98,25 @@ def screen_orientation(): return QtCore.Qt.Vertical else: return QtCore.Qt.Horizontal + + +def _null_get_theme_icon(iconNames, fallback = None): + icon = fallback if fallback is not None else QtGui.QIcon() + return icon + + +def _newqt_get_theme_icon(iconNames, fallback = None): + for iconName in iconNames: + if QtGui.QIcon.hasThemeIcon(iconName): + icon = QtGui.QIcon.fromTheme(iconName) + break + else: + icon = fallback if fallback is not None else QtGui.QIcon() + return icon + + +try: + QtGui.QIcon.fromTheme + get_theme_icon = _newqt_get_theme_icon +except AttributeError: + get_theme_icon = _null_get_theme_icon diff --git a/src/qhistory.py b/src/qhistory.py index c67e719..a853173 100644 --- a/src/qhistory.py +++ b/src/qhistory.py @@ -10,6 +10,7 @@ import logging from PyQt4 import QtGui from PyQt4 import QtCore +import maeqt import util.misc as misc_utils import history import operation @@ -53,6 +54,7 @@ class QCalcHistory(history.AbstractHistory): self._rowCount = 0 self._programmaticUpdate = False + self._closeIcon = maeqt.get_theme_icon(("window-close", "general_close", "gtk-close")) @property def toplevel(self): @@ -65,9 +67,7 @@ class QCalcHistory(history.AbstractHistory): def push(self, node): simpleNode = node.simplify() - closeIcon = QtGui.QIcon.fromTheme("general_close") - if closeIcon.isNull(): - closeIcon = QtGui.QIcon.fromTheme("gtk-close") + closeIcon = self._closeIcon icon = QtGui.QStandardItem(closeIcon, "") icon.setEditable(False) icon.setCheckable(False) -- 1.7.9.5