Mini Editor

Mon, 05 Oct 2020 19:51:55 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 05 Oct 2020 19:51:55 +0200
changeset 7758
dd54d33d21d2
parent 7757
1f9f35f9be6d
child 7759
51aa6c6b66f7

Mini Editor
-- added a status bar languages menu
-- added a status bar zoom slider

docs/changelog file | annotate | diff | comparison | revisions
eric6/QScintilla/MiniEditor.py file | annotate | diff | comparison | revisions
--- a/docs/changelog	Mon Oct 05 19:11:15 2020 +0200
+++ b/docs/changelog	Mon Oct 05 19:51:55 2020 +0200
@@ -4,6 +4,9 @@
 - bug fixes
 - Editor
   -- added support for TOML files
+- Mini Editor
+  -- added a status bar languages menu
+  -- added a status bar zoom slider
 - Syntax Checker
   -- added a syntax checker for TOML files
 
--- a/eric6/QScintilla/MiniEditor.py	Mon Oct 05 19:11:15 2020 +0200
+++ b/eric6/QScintilla/MiniEditor.py	Mon Oct 05 19:51:55 2020 +0200
@@ -15,7 +15,7 @@
     QSignalMapper, QPoint, QTimer, QFileInfo, pyqtSignal, QSize, QRegExp, Qt,
     QCoreApplication
 )
-from PyQt5.QtGui import QCursor, QKeySequence, QPalette, QFont
+from PyQt5.QtGui import QCursor, QKeySequence, QPalette, QFont, QPixmap
 from PyQt5.QtWidgets import (
     QWidget, QWhatsThis, QActionGroup, QDialog, QInputDialog, QApplication,
     QMenu, QVBoxLayout, QHBoxLayout, QLabel
@@ -26,6 +26,8 @@
 from E5Gui.E5Action import E5Action, createActionGroup
 from E5Gui import E5MessageBox, E5FileDialog
 from E5Gui.E5MainWindow import E5MainWindow
+from E5Gui.E5ClickableLabel import E5ClickableLabel
+from E5Gui.E5ZoomWidget import E5ZoomWidget
 
 from .QsciScintillaCompat import QsciScintillaCompat
 
@@ -109,9 +111,7 @@
         self.endUndoAction()
 
 
-# TODO: add language icon and menu to statusbar
-# TODO: add cursor position to statusbar
-# TODO: add zoom functionality (?)
+# TODO: add zoom actions and view menu
 class MiniEditor(E5MainWindow):
     """
     Class implementing a minimalistic editor for simple editing tasks.
@@ -156,6 +156,8 @@
         
         self.getCursorPosition = self.__textEdit.getCursorPosition
         self.text = self.__textEdit.text
+        self.getZoom = self.__textEdit.getZoom
+        self.zoomTo = self.__textEdit.zoomTo
         
         self.__curFile = filename
         self.__lastLine = 0
@@ -372,15 +374,22 @@
         self.redoAct.setEnabled(self.__textEdit.isRedoAvailable())
         
         if setSb:
-            line, pos = self.__textEdit.getCursorPosition()
-            self.__setSbFile(line + 1, pos)
+            line, pos = self.getCursorPosition()
+            lang = self.getLanguage()
+            self.__setSbFile(line + 1, pos, lang)
     
-    def __setSbFile(self, line=None, pos=None):
+    def __setSbFile(self, line=None, pos=None, language=None, zoom=None):
         """
         Private method to set the file info in the status bar.
         
-        @param line line number to display (int)
-        @param pos character position to display (int)
+        @param line line number to display
+        @type int
+        @param pos character position to display
+        @type int
+        @param language language to display
+        @type str
+        @param zoom zoom value
+        @type int
         """
         if not self.__curFile:
             writ = '   '
@@ -399,6 +408,27 @@
         if pos is None:
             pos = ''
         self.sbPos.setText(self.tr('Pos: {0:5}').format(pos))
+        
+        if language is None:
+            pixmap = QPixmap()
+        elif language == "":
+            pixmap = UI.PixmapCache.getPixmap("fileText")
+        else:
+            import QScintilla.Lexers
+            pixmap = QScintilla.Lexers.getLanguageIcon(language, True)
+        self.sbLanguage.setPixmap(pixmap)
+        if pixmap.isNull():
+            self.sbLanguage.setText(language)
+            self.sbLanguage.setToolTip("")
+        else:
+            self.sbLanguage.setText("")
+            self.sbLanguage.setToolTip(
+                self.tr('Language: {0}').format(language))
+        
+        if zoom is None:
+            self.sbZoom.setValue(self.getZoom())
+        else:
+            self.sbZoom.setValue(zoom)
     
     def __readShortcut(self, act, category):
         """
@@ -2308,6 +2338,14 @@
         self.__statusBar = self.statusBar()
         self.__statusBar.setSizeGripEnabled(True)
 
+        self.sbLanguage = E5ClickableLabel(self.__statusBar)
+        self.__statusBar.addPermanentWidget(self.sbLanguage)
+        self.sbLanguage.setWhatsThis(self.tr(
+            """<p>This part of the status bar displays the"""
+            """ editor language.</p>"""
+        ))
+        self.sbLanguage.clicked.connect(self.__showLanguagesMenu)
+
         self.sbWritable = QLabel(self.__statusBar)
         self.__statusBar.addPermanentWidget(self.sbWritable)
         self.sbWritable.setWhatsThis(self.tr(
@@ -2329,6 +2367,18 @@
             """ of the editor.</p>"""
         ))
         
+        self.sbZoom = E5ZoomWidget(
+            UI.PixmapCache.getPixmap("zoomOut"),
+            UI.PixmapCache.getPixmap("zoomIn"),
+            UI.PixmapCache.getPixmap("zoomReset"),
+            self.__statusBar)
+        self.__statusBar.addPermanentWidget(self.sbZoom)
+        self.sbZoom.setWhatsThis(self.tr(
+            """<p>This part of the status bar allows zooming the current"""
+            """ editor or shell.</p>"""
+        ))
+        self.sbZoom.valueChanged.connect(self.__zoomTo)
+        
         self.__statusBar.showMessage(self.tr("Ready"))
     
     def __readSettings(self):
@@ -2575,7 +2625,8 @@
         @param line line number of the cursor
         @param pos position in line of the cursor
         """
-        self.__setSbFile(line + 1, pos)
+        lang = self.getLanguage()
+        self.__setSbFile(line + 1, pos, lang)
         
         if Preferences.getEditor("MarkOccurrencesEnabled"):
             self.__markOccurrencesTimer.stop()
@@ -2956,6 +3007,14 @@
         else:
             self.pygmentsSelAct.setText(self.tr("Alternatives"))
     
+    def __showLanguagesMenu(self, pos):
+        """
+        Private slot to show the Languages menu of the status bar.
+        
+        @param pos position the menu should be shown at (QPoint)
+        """
+        self.languagesMenu.exec_(pos)
+    
     def __selectPygmentsLexer(self):
         """
         Private method to select a specific pygments lexer.
@@ -3323,7 +3382,7 @@
         
         @return the word at that current position
         """
-        line, index = self.__textEdit.getCursorPosition()
+        line, index = self.getCursorPosition()
         return self.__getWord(line, index)
         
     def showSearchWidget(self):
@@ -3608,3 +3667,20 @@
             self.getLanguage())
         
         self.__sourceOutline.setVisible(supported)
+        
+        line, pos = self.getCursorPosition()
+        lang = self.getLanguage()
+        self.__setSbFile(line + 1, pos, language=lang)
+    
+    #######################################################################
+    ## Methods supporting zooming
+    #######################################################################
+        
+    def __zoomTo(self, value):
+        """
+        Private slot to zoom to a given value.
+        
+        @param value zoom value to be set (integer)
+        """
+        self.zoomTo(value)
+        self.sbZoom.setValue(self.getZoom())

eric ide

mercurial