WizardDataUriEncoder/DataUriEncoderWizardDialog.py

changeset 35
20bea809ae09
parent 34
525dc29b6a22
child 39
3efaeaf599b6
--- a/WizardDataUriEncoder/DataUriEncoderWizardDialog.py	Wed Jan 01 11:59:05 2020 +0100
+++ b/WizardDataUriEncoder/DataUriEncoderWizardDialog.py	Tue Jun 23 19:56:12 2020 +0200
@@ -7,12 +7,6 @@
 Module implementing the base64 data URI encoder wizard dialog.
 """
 
-from __future__ import unicode_literals
-try:
-    str = unicode       # __IGNORE_EXCEPTION__
-except NameError:
-    pass
-
 import os
 import mimetypes
 import base64
@@ -20,8 +14,9 @@
 import datetime
 
 from PyQt5.QtCore import pyqtSlot
-from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QApplication, \
-    QInputDialog
+from PyQt5.QtWidgets import (
+    QDialog, QDialogButtonBox, QApplication, QInputDialog
+)
 
 from E5Gui.E5Completers import E5FileCompleter
 from E5Gui import E5FileDialog, E5MessageBox
@@ -33,22 +28,6 @@
 import UI.PixmapCache
 
 
-Python2Template = """#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-from base64 import b64decode
-from cStringIO import StringIO
-
-#metadata
-__author__ = '{0}'
-__date__ = '{1}'
-
-
-embedded_file = StringIO(b64decode({2}))
-print(embedded_file.read())
-"""
-
-
 Python3Template = """#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
@@ -85,13 +64,12 @@
         self.fileButton.setIcon(UI.PixmapCache.getIcon("open.png"))
         
         self.embeddingComboBox.addItems([
-            self.tr('Do not generate code'),
-            self.tr('Generate CSS embed code'),
-            self.tr('Generate Python3 embed code'),
-            self.tr('Generate Python2 embed code'),
-            self.tr('Generate HTML embed code'),
-            self.tr('Generate JS embed code'),
-            self.tr('Generate QML embed code'),
+            self.tr('Do not generate code'),            # 0
+            self.tr('Generate Python3 embed code'),     # 1
+            self.tr('Generate CSS embed code'),         # 2
+            self.tr('Generate HTML embed code'),        # 3
+            self.tr('Generate JS embed code'),          # 4
+            self.tr('Generate QML embed code'),         # 5
         ])
     
     def __getStartDir(self):
@@ -108,8 +86,10 @@
         """
         Private slot to select the file to be encoded via a selection dialog.
         """
-        start = Utilities.fromNativeSeparators(self.fileEdit.text()) or \
+        start = (
+            Utilities.fromNativeSeparators(self.fileEdit.text()) or
             self.__getStartDir()
+        )
         inputFile = E5FileDialog.getOpenFileName(
             self,
             self.tr("Data URI Encoder"),
@@ -132,10 +112,10 @@
         
         @param index index of the selected entry (integer)
         """
-        if index in [1, 4]:
+        if index in [2, 3]:
             self.encryptCheckBox.setChecked(False)
             self.dataCheckBox.setChecked(True)
-        elif index in [0, 2, 3, 5, 6]:
+        else:
             self.encryptCheckBox.setChecked(False)
             self.dataCheckBox.setChecked(False)
     
@@ -179,24 +159,20 @@
                     """<p>The file <b>{0}</b> could not be read.</p>"""
                     """<p>Reason: {1}</p>""").format(filepath, str(err)))
             return
-        if self.embeddingComboBox.currentIndex() == 1:
-            output = ('html, body {{ margin:0; padding:0; background: url({0})'
-                      ' no-repeat center center fixed; background-size:cover'
-                      ' }}'.format(output))
-        elif self.embeddingComboBox.currentIndex() == 2:
+        if self.embeddingComboBox.currentIndex() == 1:          # Python 3
             output = Python3Template.format(
                 getpass.getuser(),
                 datetime.datetime.now().isoformat().split('.')[0], output)
-        elif self.embeddingComboBox.currentIndex() == 3:
-            output = Python2Template.format(
-                getpass.getuser(),
-                datetime.datetime.now().isoformat().split('.')[0], output)
-        elif self.embeddingComboBox.currentIndex() == 4:
+        elif self.embeddingComboBox.currentIndex() == 2:        # CSS
+            output = ('html, body {{ margin:0; padding:0; background: url({0})'
+                      ' no-repeat center center fixed; background-size:cover'
+                      ' }}'.format(output))
+        elif self.embeddingComboBox.currentIndex() == 3:        # HTML
             output = '<img src={0} alt="{1}" title="{1}"/>'.format(
                 output, os.path.basename(filepath))
-        elif self.embeddingComboBox.currentIndex() == 5:
+        elif self.embeddingComboBox.currentIndex() == 4:        # JS
             output = 'var embedded_file = window.atob({0}); '.format(output)
-        elif self.embeddingComboBox.currentIndex() == 6:
+        elif self.embeddingComboBox.currentIndex() == 5:        # QML
             output = 'Image {{ source: {0} }} '.format(output)
         
         if self.encryptCheckBox.isChecked():

eric ide

mercurial