summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2014-12-28 14:35:28 +0100
committerFlorian Bruhin <git@the-compiler.org>2014-12-28 14:35:28 +0100
commit2a4e884e1b89b731301cf3bc46c7abe4115c3b44 (patch)
treea2f8f0eaed7b1449815870426a0dd976c9b6bae4
parentaef693805a50eb09a3029484a782581b95ef8189 (diff)
downloadqutebrowser-2a4e884e1b89b731301cf3bc46c7abe4115c3b44.tar.gz
qutebrowser-2a4e884e1b89b731301cf3bc46c7abe4115c3b44.zip
Set window icon. Closes #325.
-rw-r--r--qutebrowser/app.py18
-rw-r--r--qutebrowser/utils/qtutils.py6
-rw-r--r--qutebrowser/utils/utils.py10
-rwxr-xr-xscripts/freeze.py1
-rwxr-xr-xsetup.py2
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'],
diff --git a/setup.py b/setup.py
index 5217488e1..fcbb19aae 100755
--- a/setup.py
+++ b/setup.py
@@ -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: