10 import mimetypes |
10 import mimetypes |
11 import base64 |
11 import base64 |
12 import getpass |
12 import getpass |
13 import datetime |
13 import datetime |
14 |
14 |
15 from PyQt4.QtCore import pyqtSlot |
15 from PyQt5.QtCore import pyqtSlot |
16 from PyQt4.QtGui import QDialog, QDialogButtonBox, QApplication, QInputDialog |
16 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QApplication, \ |
|
17 QInputDialog |
17 |
18 |
18 from E5Gui.E5Completers import E5FileCompleter |
19 from E5Gui.E5Completers import E5FileCompleter |
19 from E5Gui import E5FileDialog, E5MessageBox |
20 from E5Gui import E5FileDialog, E5MessageBox |
20 |
21 |
21 from .Ui_DataUriEncoderWizardDialog import Ui_DataUriEncoderWizardDialog |
22 from .Ui_DataUriEncoderWizardDialog import Ui_DataUriEncoderWizardDialog |
102 """ |
103 """ |
103 start = Utilities.fromNativeSeparators(self.fileEdit.text()) or \ |
104 start = Utilities.fromNativeSeparators(self.fileEdit.text()) or \ |
104 self.__getStartDir() |
105 self.__getStartDir() |
105 inputFile = E5FileDialog.getOpenFileName( |
106 inputFile = E5FileDialog.getOpenFileName( |
106 self, |
107 self, |
107 self.trUtf8("Data URI Encoder"), |
108 self.tr("Data URI Encoder"), |
108 start, |
109 start, |
109 self.trUtf8( |
110 self.tr( |
110 "Audio Files (*.flac *.mp3 *.ogg *.wav *.weba *.wma);;" |
111 "Audio Files (*.flac *.mp3 *.ogg *.wav *.weba *.wma);;" |
111 "Image Files (*.gif *.ico *.jpg *.png *.svg *.tif *.webp" |
112 "Image Files (*.gif *.ico *.jpg *.png *.svg *.tif *.webp" |
112 " *.xpm);;" |
113 " *.xpm);;" |
113 "Video Files (*.3gp *.avi *.flv *.mp4 *.ogv *.webm *.wmv);;" |
114 "Video Files (*.3gp *.avi *.flv *.mp4 *.ogv *.webm *.wmv);;" |
114 "All Files (*)" |
115 "All Files (*)" |
141 mimetype = mime if mime is not None else self.__askMime() |
142 mimetype = mime if mime is not None else self.__askMime() |
142 |
143 |
143 if os.path.getsize(filepath) // 1024 // 1024 >= 1: |
144 if os.path.getsize(filepath) // 1024 // 1024 >= 1: |
144 res = E5MessageBox.warning( |
145 res = E5MessageBox.warning( |
145 self, |
146 self, |
146 self.trUtf8("Data URI Encoder"), |
147 self.tr("Data URI Encoder"), |
147 self.trUtf8( |
148 self.tr( |
148 """The file size is > 1 Megabyte. Encoding this will""" |
149 """The file size is > 1 Megabyte. Encoding this will""" |
149 """ take some time depending on your CPU processing""" |
150 """ take some time depending on your CPU processing""" |
150 """ power!"""), |
151 """ power!"""), |
151 E5MessageBox.StandardButtons( |
152 E5MessageBox.StandardButtons( |
152 E5MessageBox.Cancel | |
153 E5MessageBox.Cancel | |
164 base64.b64encode(open(filepath, "rb").read()).decode() |
165 base64.b64encode(open(filepath, "rb").read()).decode() |
165 ) |
166 ) |
166 except (IOError, OSError) as err: |
167 except (IOError, OSError) as err: |
167 E5MessageBox.critical( |
168 E5MessageBox.critical( |
168 self, |
169 self, |
169 self.trUtf8("Data URI Encoder"), |
170 self.tr("Data URI Encoder"), |
170 self.trUtf8( |
171 self.tr( |
171 """<p>The file <b>{0}</b> could not be read.</p>""" |
172 """<p>The file <b>{0}</b> could not be read.</p>""" |
172 """<p>Reason: {1}</p>""").format(filepath, str(err))) |
173 """<p>Reason: {1}</p>""").format(filepath, str(err))) |
173 return |
174 return |
174 if self.embeddingComboBox.currentIndex() == 1: |
175 if self.embeddingComboBox.currentIndex() == 1: |
175 output = ('html, body {{ margin:0; padding:0; background: url({0})' |
176 output = ('html, body {{ margin:0; padding:0; background: url({0})' |
234 index = mimetypesList.index("application/octet-stream") |
235 index = mimetypesList.index("application/octet-stream") |
235 except ValueError: |
236 except ValueError: |
236 index = 0 |
237 index = 0 |
237 mimetype, ok = QInputDialog.getItem( |
238 mimetype, ok = QInputDialog.getItem( |
238 self, |
239 self, |
239 self.trUtf8("Data URI Encoder"), |
240 self.tr("Data URI Encoder"), |
240 self.trUtf8("Enter a mime type:"), |
241 self.tr("Enter a mime type:"), |
241 mimetypesList, |
242 mimetypesList, |
242 index, True) |
243 index, True) |
243 if ok: |
244 if ok: |
244 return mimetype.lower() |
245 return mimetype.lower() |
245 else: |
246 else: |