7 Module containing a web site icon storage object. |
7 Module containing a web site icon storage object. |
8 """ |
8 """ |
9 |
9 |
10 import json |
10 import json |
11 import os |
11 import os |
|
12 import contextlib |
12 |
13 |
13 from PyQt5.QtCore import ( |
14 from PyQt5.QtCore import ( |
14 pyqtSignal, QObject, QByteArray, QBuffer, QIODevice, QUrl |
15 pyqtSignal, QObject, QByteArray, QBuffer, QIODevice, QUrl |
15 ) |
16 ) |
16 from PyQt5.QtGui import QIcon, QPixmap, QImage |
17 from PyQt5.QtGui import QIcon, QPixmap, QImage |
118 icon.pixmap(32).toImage().save(buffer, "PNG") |
119 icon.pixmap(32).toImage().save(buffer, "PNG") |
119 db[url] = bytes(buffer.data()).decode(self.__encoding) |
120 db[url] = bytes(buffer.data()).decode(self.__encoding) |
120 |
121 |
121 filename = os.path.join(self.__iconDatabasePath, |
122 filename = os.path.join(self.__iconDatabasePath, |
122 self.__iconsFileName) |
123 self.__iconsFileName) |
123 try: |
124 with contextlib.suppress(OSError), open(filename, "w") as f: |
124 with open(filename, "w") as f: |
125 json.dump(db, f) |
125 json.dump(db, f) |
|
126 except OSError: |
|
127 # ignore silentyl |
|
128 pass |
|
129 |
126 |
130 def saveIcon(self, view): |
127 def saveIcon(self, view): |
131 """ |
128 """ |
132 Public method to save a web site icon. |
129 Public method to save a web site icon. |
133 |
130 |