diff options
-rw-r--r-- | qutebrowser/app.py | 18 | ||||
-rw-r--r-- | qutebrowser/utils/qtutils.py | 6 | ||||
-rw-r--r-- | qutebrowser/utils/utils.py | 10 | ||||
-rwxr-xr-x | scripts/freeze.py | 1 | ||||
-rwxr-xr-x | setup.py | 2 |
5 files changed, 34 insertions, 3 deletions
diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 7dd703660..5989cc6a8 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -32,7 +32,7 @@ import traceback import faulthandler from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox -from PyQt5.QtGui import QDesktopServices +from PyQt5.QtGui import QDesktopServices, QPixmap, QIcon from PyQt5.QtCore import (pyqtSlot, qInstallMessageHandler, QTimer, QUrl, QStandardPaths, QObject, Qt) @@ -126,6 +126,7 @@ class Application(QApplication): self.setOrganizationName("qutebrowser") self.setApplicationName("qutebrowser") self.setApplicationVersion(qutebrowser.__version__) + self._init_icon() utils.actute_warning() try: self._init_modules() @@ -197,6 +198,21 @@ class Application(QApplication): main_window = objreg.get('main-window', scope='window', window=win_id) self.setActiveWindow(main_window) + def _init_icon(self): + """Initialize the icon of qutebrowser.""" + icon = QIcon() + for size in (16, 24, 32, 48, 64, 96, 128, 256, 512): + filename = 'icons/qutebrowser-{}x{}.png'.format(size, size) + data = utils.read_file(filename, binary=True, use_requirement=True) + pixmap = QPixmap() + ok = pixmap.loadFromData(data, 'PNG') + if not ok: + raise ValueError("Could not load icon!") + qtutils.ensure_not_null(pixmap) + icon.addPixmap(pixmap) + qtutils.ensure_not_null(icon) + self.setWindowIcon(icon) + def _handle_segfault(self): """Handle a segfault from a previous run.""" path = standarddir.get(QStandardPaths.DataLocation) diff --git a/qutebrowser/utils/qtutils.py b/qutebrowser/utils/qtutils.py index ffe3cdfb6..3052b3503 100644 --- a/qutebrowser/utils/qtutils.py +++ b/qutebrowser/utils/qtutils.py @@ -127,6 +127,12 @@ def ensure_valid(obj): raise QtValueError(obj) +def ensure_not_null(obj): + """Ensure a Qt object with an .isNull() method is not null.""" + if obj.isNull(): + raise QtValueError(obj) + + def _check_qdatastream(stream): """Check the status of a QDataStream and raise OSError if it's not ok.""" status_to_str = { diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py index 4b40f997d..b2aea8112 100644 --- a/qutebrowser/utils/utils.py +++ b/qutebrowser/utils/utils.py @@ -64,13 +64,15 @@ def compact_text(text, elidelength=None): return out -def read_file(filename, binary=False): +def read_file(filename, binary=False, use_requirement=False): """Get the contents of a file contained with qutebrowser. Args: filename: The filename to open as string. binary: Whether to return a binary string. If False, the data is UTF-8-decoded. + use_requirement: Use a pkg_resources.Requirement object to get + non-package data. Return: The file contents as string. @@ -85,7 +87,11 @@ def read_file(filename, binary=False): with open(fn, 'r', encoding='utf-8') as f: return f.read() else: - data = pkg_resources.resource_string(qutebrowser.__name__, filename) + if use_requirement: + target = pkg_resources.Requirement('qutebrowser', '', '') + else: + target = qutebrowser.__name__ + data = pkg_resources.resource_string(target, filename) if not binary: data = data.decode('UTF-8') return data diff --git a/scripts/freeze.py b/scripts/freeze.py index e82f835c1..8166993cc 100755 --- a/scripts/freeze.py +++ b/scripts/freeze.py @@ -52,6 +52,7 @@ build_exe_options = { ('qutebrowser/html', 'html'), ('qutebrowser/html/doc', 'html/doc'), ('qutebrowser/git-commit-id', 'git-commit-id'), + ('icons', 'icons'), ], 'include_msvcr': True, 'excludes': ['tkinter'], @@ -23,6 +23,7 @@ import os import os.path +import glob from scripts import setupcommon as common @@ -45,6 +46,7 @@ try: test_suite='qutebrowser.test', zip_safe=True, install_requires=['pypeg2', 'jinja2', 'pygments'], + data_files=[('icons', glob.glob('icons/*'))], **common.setupdata ) finally: |