Project/ProjectFormsBrowser.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2791
a9577f248f04
parent 2995
63d874899b8b
child 3058
0a02c433f52d
--- a/Project/ProjectFormsBrowser.py	Tue Oct 15 22:03:54 2013 +0200
+++ b/Project/ProjectFormsBrowser.py	Fri Oct 18 23:00:41 2013 +0200
@@ -18,7 +18,8 @@
 import shutil
 
 from PyQt4.QtCore import QThread, QFileInfo, pyqtSignal, QProcess
-from PyQt4.QtGui import QDialog, QInputDialog, QApplication, QMenu, QProgressDialog
+from PyQt4.QtGui import QDialog, QInputDialog, QApplication, QMenu, \
+    QProgressDialog
 
 from E5Gui.E5Application import e5App
 from E5Gui import E5MessageBox, E5FileDialog
@@ -41,17 +42,17 @@
     A class used to display the forms part of the project.
     
     @signal appendStderr(str) emitted after something was received from
-            a QProcess on stderr
+        a QProcess on stderr
     @signal sourceFile(str) emitted to open a forms file in an editor
     @signal uipreview(str) emitted to preview a forms file
     @signal trpreview(list of str) emitted to preview form files in the
-            translations previewer
-    @signal closeSourceWindow(str) emitted after a file has been removed/deleted
-            from the project
-    @signal showMenu(str, QMenu) emitted when a menu is about to be shown. The name
-            of the menu and a reference to the menu are given.
+        translations previewer
+    @signal closeSourceWindow(str) emitted after a file has been
+        removed/deleted from the project
+    @signal showMenu(str, QMenu) emitted when a menu is about to be shown. The
+        name of the menu and a reference to the menu are given.
     @signal menusAboutToBeCreated() emitted when the context menus are about to
-            be created. This is the right moment to add or remove hook methods.
+        be created. This is the right moment to add or remove hook methods.
     """
     appendStderr = pyqtSignal(str)
     uipreview = pyqtSignal(str)
@@ -65,7 +66,8 @@
         @param project reference to the project object
         @param parent parent widget of this browser (QWidget)
         """
-        ProjectBaseBrowser.__init__(self, project, ProjectBrowserFormType, parent)
+        ProjectBaseBrowser.__init__(self, project, ProjectBrowserFormType,
+                                    parent)
         
         self.selectedItemsFilter = \
             [ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem]
@@ -74,8 +76,9 @@
 
         self.setWhatsThis(self.trUtf8(
             """<b>Project Forms Browser</b>"""
-            """<p>This allows to easily see all forms contained in the current"""
-            """ project. Several actions can be executed via the context menu.</p>"""
+            """<p>This allows to easily see all forms contained in the"""
+            """ current project. Several actions can be executed via the"""
+            """ context menu.</p>"""
         ))
         
         # templates for Qt4
@@ -123,18 +126,23 @@
         self.menusAboutToBeCreated.emit()
         
         self.menu = QMenu(self)
-        if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
-            self.menu.addAction(self.trUtf8('Compile form'), self.__compileForm)
+        if self.project.getProjectType() in \
+                ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
+            self.menu.addAction(
+                self.trUtf8('Compile form'), self.__compileForm)
             self.menu.addAction(self.trUtf8('Compile all forms'),
                 self.__compileAllForms)
             self.menu.addAction(self.trUtf8('Generate Dialog Code...'),
                 self.__generateDialogCode)
             self.menu.addSeparator()
-            self.menu.addAction(self.trUtf8('Open in Qt-Designer'), self.__openFile)
-            self.menu.addAction(self.trUtf8('Open in Editor'), self.__openFileInEditor)
+            self.menu.addAction(
+                self.trUtf8('Open in Qt-Designer'), self.__openFile)
+            self.menu.addAction(
+                self.trUtf8('Open in Editor'), self.__openFileInEditor)
             self.menu.addSeparator()
             self.menu.addAction(self.trUtf8('Preview form'), self.__UIPreview)
-            self.menu.addAction(self.trUtf8('Preview translations'), self.__TRPreview)
+            self.menu.addAction(
+                self.trUtf8('Preview translations'), self.__TRPreview)
         else:
             if self.hooks["compileForm"] is not None:
                 self.menu.addAction(
@@ -162,12 +170,14 @@
         self.menu.addSeparator()
         act = self.menu.addAction(self.trUtf8('Rename file'), self._renameFile)
         self.menuActions.append(act)
-        act = self.menu.addAction(self.trUtf8('Remove from project'), self._removeFile)
+        act = self.menu.addAction(
+            self.trUtf8('Remove from project'), self._removeFile)
         self.menuActions.append(act)
         act = self.menu.addAction(self.trUtf8('Delete'), self.__deleteFile)
         self.menuActions.append(act)
         self.menu.addSeparator()
-        if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
+        if self.project.getProjectType() in \
+                ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
             self.menu.addAction(self.trUtf8('New form...'), self.__newForm)
         else:
             if self.hooks["newForm"] is not None:
@@ -189,8 +199,9 @@
         self.menu.addAction(self.trUtf8('Configure...'), self._configure)
 
         self.backMenu = QMenu(self)
-        if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"] or \
-           self.hooks["compileAllForms"] is not None:
+        if self.project.getProjectType() in \
+                ["Qt4", "PyQt5", "E4Plugin", "PySide"] or \
+                self.hooks["compileAllForms"] is not None:
             self.backMenu.addAction(self.trUtf8('Compile all forms'),
                 self.__compileAllForms)
             self.backMenu.addSeparator()
@@ -200,7 +211,8 @@
                 self.backMenu.addAction(
                     self.hooksMenuEntries.get("newForm",
                         self.trUtf8('New form...')), self.__newForm)
-        self.backMenu.addAction(self.trUtf8('Add forms...'), self.project.addUiFiles)
+        self.backMenu.addAction(
+            self.trUtf8('Add forms...'), self.project.addUiFiles)
         self.backMenu.addAction(self.trUtf8('Add forms directory...'),
             self.project.addUiDir)
         self.backMenu.addSeparator()
@@ -214,7 +226,8 @@
 
         # create the menu for multiple selected files
         self.multiMenu = QMenu(self)
-        if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
+        if self.project.getProjectType() in \
+                ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
             act = self.multiMenu.addAction(self.trUtf8('Compile forms'),
                 self.__compileSelectedForms)
             self.multiMenu.addSeparator()
@@ -236,12 +249,14 @@
                 self.multiMenu.addAction(
                     self.hooksMenuEntries.get("open", self.trUtf8('Open')),
                     self.__openFile)
-            self.multiMenu.addAction(self.trUtf8('Open'), self.__openFileInEditor)
+            self.multiMenu.addAction(
+                self.trUtf8('Open'), self.__openFileInEditor)
         self.multiMenu.addSeparator()
         act = self.multiMenu.addAction(self.trUtf8('Remove from project'),
             self._removeFile)
         self.multiMenuActions.append(act)
-        act = self.multiMenu.addAction(self.trUtf8('Delete'), self.__deleteFile)
+        act = self.multiMenu.addAction(
+            self.trUtf8('Delete'), self.__deleteFile)
         self.multiMenuActions.append(act)
         self.multiMenu.addSeparator()
         self.multiMenu.addAction(self.trUtf8('Expand all directories'),
@@ -252,7 +267,8 @@
         self.multiMenu.addAction(self.trUtf8('Configure...'), self._configure)
 
         self.dirMenu = QMenu(self)
-        if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
+        if self.project.getProjectType() in \
+                ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
             self.dirMenu.addAction(self.trUtf8('Compile all forms'),
                 self.__compileAllForms)
             self.dirMenu.addSeparator()
@@ -263,19 +279,23 @@
                         self.trUtf8('Compile all forms')),
                     self.__compileAllForms)
                 self.dirMenu.addSeparator()
-        act = self.dirMenu.addAction(self.trUtf8('Remove from project'), self._removeDir)
+        act = self.dirMenu.addAction(
+            self.trUtf8('Remove from project'), self._removeDir)
         self.dirMenuActions.append(act)
-        act = self.dirMenu.addAction(self.trUtf8('Delete'), self._deleteDirectory)
+        act = self.dirMenu.addAction(
+            self.trUtf8('Delete'), self._deleteDirectory)
         self.dirMenuActions.append(act)
         self.dirMenu.addSeparator()
-        if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
+        if self.project.getProjectType() in \
+                ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
             self.dirMenu.addAction(self.trUtf8('New form...'), self.__newForm)
         else:
             if self.hooks["newForm"] is not None:
                 self.dirMenu.addAction(
                     self.hooksMenuEntries.get("newForm",
                         self.trUtf8('New form...')), self.__newForm)
-        self.dirMenu.addAction(self.trUtf8('Add forms...'), self.__addFormFiles)
+        self.dirMenu.addAction(
+            self.trUtf8('Add forms...'), self.__addFormFiles)
         self.dirMenu.addAction(self.trUtf8('Add forms directory...'),
             self.__addFormsDirectory)
         self.dirMenu.addSeparator()
@@ -290,7 +310,8 @@
         self.dirMenu.addAction(self.trUtf8('Configure...'), self._configure)
         
         self.dirMultiMenu = QMenu(self)
-        if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
+        if self.project.getProjectType() in \
+                ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
             self.dirMultiMenu.addAction(self.trUtf8('Compile all forms'),
                 self.__compileAllForms)
             self.dirMultiMenu.addSeparator()
@@ -311,7 +332,8 @@
         self.dirMultiMenu.addAction(self.trUtf8('Collapse all directories'),
             self._collapseAllDirs)
         self.dirMultiMenu.addSeparator()
-        self.dirMultiMenu.addAction(self.trUtf8('Configure...'), self._configure)
+        self.dirMultiMenu.addAction(
+            self.trUtf8('Configure...'), self._configure)
         
         self.menu.aboutToShow.connect(self.__showContextMenu)
         self.multiMenu.aboutToShow.connect(self.__showContextMenuMulti)
@@ -338,7 +360,8 @@
                 if index.isValid():
                     self._selectSingleItem(index)
                     categories = self.getSelectedItemsCountCategorized(
-                        [ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem])
+                        [ProjectBrowserFileItem,
+                         ProjectBrowserSimpleDirectoryItem])
                     cnt = categories["sum"]
             
             bfcnt = categories[str(ProjectBrowserFileItem)]
@@ -504,12 +527,14 @@
         if self.hooks["newForm"] is not None:
             self.hooks["newForm"](path)
         else:
-            if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
+            if self.project.getProjectType() in \
+                    ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
                 self.__newUiForm(path)
         
     def __newUiForm(self, path):
         """
-        Private slot to handle the New Form menu action for Qt-related projects.
+        Private slot to handle the New Form menu action for Qt-related
+        projects.
         
         @param path full directory path for the new form file (string)
         """
@@ -559,7 +584,8 @@
         except IOError as e:
             E5MessageBox.critical(self,
                 self.trUtf8("New Form"),
-                self.trUtf8("<p>The new form file <b>{0}</b> could not be created.<br>"
+                self.trUtf8(
+                    "<p>The new form file <b>{0}</b> could not be created.<br>"
                     "Problem: {1}</p>").format(fname, str(e)))
             return
         
@@ -580,10 +606,12 @@
             fn = self.project.getRelativePath(fn2)
             files.append(fn)
         
-        from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
+        from UI.DeleteFilesConfirmationDialog import \
+            DeleteFilesConfirmationDialog
         dlg = DeleteFilesConfirmationDialog(self.parent(),
             self.trUtf8("Delete forms"),
-            self.trUtf8("Do you really want to delete these forms from the project?"),
+            self.trUtf8(
+                "Do you really want to delete these forms from the project?"),
             files)
         
         if dlg.exec_() == QDialog.Accepted:
@@ -591,9 +619,9 @@
                 self.closeSourceWindow.emit(fn2)
                 self.project.deleteFile(fn)
     
-    ############################################################################
+    ###########################################################################
     ##  Methods to handle the various compile commands
-    ############################################################################
+    ###########################################################################
     
     def __readStdout(self):
         """
@@ -655,7 +683,8 @@
                         self.trUtf8("The compilation of the form file"
                             " was successful."))
                 else:
-                    ui.showNotification(UI.PixmapCache.getPixmap("designer48.png"),
+                    ui.showNotification(
+                        UI.PixmapCache.getPixmap("designer48.png"),
                         self.trUtf8("Form Compilation"),
                         self.trUtf8("The compilation of the form file"
                             " was successful."))
@@ -664,12 +693,15 @@
                 if not self.noDialog:
                     E5MessageBox.information(self,
                         self.trUtf8("Form Compilation"),
-                        self.trUtf8("<p>The compilation of the form file failed.</p>"
+                        self.trUtf8(
+                            "<p>The compilation of the form file failed.</p>"
                             "<p>Reason: {0}</p>").format(str(msg)))
                 else:
-                    ui.showNotification(UI.PixmapCache.getPixmap("designer48.png"),
+                    ui.showNotification(
+                        UI.PixmapCache.getPixmap("designer48.png"),
                         self.trUtf8("Form Compilation"),
-                        self.trUtf8("<p>The compilation of the form file failed.</p>"
+                        self.trUtf8(
+                            "<p>The compilation of the form file failed.</p>"
                             "<p>Reason: {0}</p>").format(str(msg)))
         else:
             if not self.noDialog:
@@ -695,7 +727,8 @@
         args = []
         self.buf = ""
         
-        if self.project.pdata["PROGLANGUAGE"][0] in ["Python", "Python2", "Python3"]:
+        if self.project.pdata["PROGLANGUAGE"][0] in \
+                ["Python", "Python2", "Python3"]:
             if self.project.getProjectType() in ["Qt4", "E4Plugin"]:
                 self.uicompiler = 'pyuic4'
                 if Utilities.isWindowsPlatform():
@@ -728,7 +761,8 @@
         ofn, ext = os.path.splitext(fn)
         fn = os.path.join(self.project.ppath, fn)
         
-        if self.project.pdata["PROGLANGUAGE"][0] in ["Python", "Python2", "Python3"]:
+        if self.project.pdata["PROGLANGUAGE"][0] in \
+                ["Python", "Python2", "Python3"]:
             dirname, filename = os.path.split(ofn)
             self.compiledFile = os.path.join(dirname, "Ui_" + filename + ".py")
             args.append("-x")
@@ -762,7 +796,7 @@
         
     def __generateDialogCode(self):
         """
-        Private method to generate dialog code for the form (Qt4 only)
+        Private method to generate dialog code for the form (Qt4 only).
         """
         itm = self.model().item(self.currentIndex())
         fn = itm.fileName()
@@ -875,7 +909,8 @@
                 # ignore the request for non Qt GUI projects
                 return
             
-            progress = QProgressDialog(self.trUtf8("Determining changed forms..."),
+            progress = QProgressDialog(
+                self.trUtf8("Determining changed forms..."),
                 None, 0, 100)
             progress.setMinimumDuration(0)
             i = 0
@@ -902,7 +937,8 @@
             QApplication.processEvents()
             
             if changedForms:
-                progress.setLabelText(self.trUtf8("Compiling changed forms..."))
+                progress.setLabelText(
+                    self.trUtf8("Compiling changed forms..."))
                 progress.setMaximum(len(changedForms))
                 i = 0
                 progress.setValue(i)
@@ -927,9 +963,9 @@
         """
         ProjectBaseBrowser.handlePreferencesChanged(self)
     
-    ############################################################################
+    ###########################################################################
     ## Support for hooks below
-    ############################################################################
+    ###########################################################################
     
     def _initHookMethods(self):
         """

eric ide

mercurial