eric6/QScintilla/MiniEditor.py

changeset 7758
dd54d33d21d2
parent 7749
285855999b4e
child 7759
51aa6c6b66f7
equal deleted inserted replaced
7757:1f9f35f9be6d 7758:dd54d33d21d2
13 13
14 from PyQt5.QtCore import ( 14 from PyQt5.QtCore import (
15 QSignalMapper, QPoint, QTimer, QFileInfo, pyqtSignal, QSize, QRegExp, Qt, 15 QSignalMapper, QPoint, QTimer, QFileInfo, pyqtSignal, QSize, QRegExp, Qt,
16 QCoreApplication 16 QCoreApplication
17 ) 17 )
18 from PyQt5.QtGui import QCursor, QKeySequence, QPalette, QFont 18 from PyQt5.QtGui import QCursor, QKeySequence, QPalette, QFont, QPixmap
19 from PyQt5.QtWidgets import ( 19 from PyQt5.QtWidgets import (
20 QWidget, QWhatsThis, QActionGroup, QDialog, QInputDialog, QApplication, 20 QWidget, QWhatsThis, QActionGroup, QDialog, QInputDialog, QApplication,
21 QMenu, QVBoxLayout, QHBoxLayout, QLabel 21 QMenu, QVBoxLayout, QHBoxLayout, QLabel
22 ) 22 )
23 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog 23 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog
24 from PyQt5.Qsci import QsciScintilla 24 from PyQt5.Qsci import QsciScintilla
25 25
26 from E5Gui.E5Action import E5Action, createActionGroup 26 from E5Gui.E5Action import E5Action, createActionGroup
27 from E5Gui import E5MessageBox, E5FileDialog 27 from E5Gui import E5MessageBox, E5FileDialog
28 from E5Gui.E5MainWindow import E5MainWindow 28 from E5Gui.E5MainWindow import E5MainWindow
29 from E5Gui.E5ClickableLabel import E5ClickableLabel
30 from E5Gui.E5ZoomWidget import E5ZoomWidget
29 31
30 from .QsciScintillaCompat import QsciScintillaCompat 32 from .QsciScintillaCompat import QsciScintillaCompat
31 33
32 import UI.PixmapCache 34 import UI.PixmapCache
33 import UI.Config 35 import UI.Config
107 self.replaceTarget("") 109 self.replaceTarget("")
108 ok = self.findNextTarget() 110 ok = self.findNextTarget()
109 self.endUndoAction() 111 self.endUndoAction()
110 112
111 113
112 # TODO: add language icon and menu to statusbar 114 # TODO: add zoom actions and view menu
113 # TODO: add cursor position to statusbar
114 # TODO: add zoom functionality (?)
115 class MiniEditor(E5MainWindow): 115 class MiniEditor(E5MainWindow):
116 """ 116 """
117 Class implementing a minimalistic editor for simple editing tasks. 117 Class implementing a minimalistic editor for simple editing tasks.
118 118
119 @signal editorSaved() emitted after the file has been saved 119 @signal editorSaved() emitted after the file has been saved
154 self.__textEdit.setSearchIndicator = self.setSearchIndicator 154 self.__textEdit.setSearchIndicator = self.setSearchIndicator
155 self.__textEdit.setUtf8(True) 155 self.__textEdit.setUtf8(True)
156 156
157 self.getCursorPosition = self.__textEdit.getCursorPosition 157 self.getCursorPosition = self.__textEdit.getCursorPosition
158 self.text = self.__textEdit.text 158 self.text = self.__textEdit.text
159 self.getZoom = self.__textEdit.getZoom
160 self.zoomTo = self.__textEdit.zoomTo
159 161
160 self.__curFile = filename 162 self.__curFile = filename
161 self.__lastLine = 0 163 self.__lastLine = 0
162 164
163 self.srHistory = { 165 self.srHistory = {
370 372
371 self.undoAct.setEnabled(self.__textEdit.isUndoAvailable()) 373 self.undoAct.setEnabled(self.__textEdit.isUndoAvailable())
372 self.redoAct.setEnabled(self.__textEdit.isRedoAvailable()) 374 self.redoAct.setEnabled(self.__textEdit.isRedoAvailable())
373 375
374 if setSb: 376 if setSb:
375 line, pos = self.__textEdit.getCursorPosition() 377 line, pos = self.getCursorPosition()
376 self.__setSbFile(line + 1, pos) 378 lang = self.getLanguage()
377 379 self.__setSbFile(line + 1, pos, lang)
378 def __setSbFile(self, line=None, pos=None): 380
381 def __setSbFile(self, line=None, pos=None, language=None, zoom=None):
379 """ 382 """
380 Private method to set the file info in the status bar. 383 Private method to set the file info in the status bar.
381 384
382 @param line line number to display (int) 385 @param line line number to display
383 @param pos character position to display (int) 386 @type int
387 @param pos character position to display
388 @type int
389 @param language language to display
390 @type str
391 @param zoom zoom value
392 @type int
384 """ 393 """
385 if not self.__curFile: 394 if not self.__curFile:
386 writ = ' ' 395 writ = ' '
387 else: 396 else:
388 if QFileInfo(self.__curFile).isWritable(): 397 if QFileInfo(self.__curFile).isWritable():
397 self.sbLine.setText(self.tr('Line: {0:5}').format(line)) 406 self.sbLine.setText(self.tr('Line: {0:5}').format(line))
398 407
399 if pos is None: 408 if pos is None:
400 pos = '' 409 pos = ''
401 self.sbPos.setText(self.tr('Pos: {0:5}').format(pos)) 410 self.sbPos.setText(self.tr('Pos: {0:5}').format(pos))
411
412 if language is None:
413 pixmap = QPixmap()
414 elif language == "":
415 pixmap = UI.PixmapCache.getPixmap("fileText")
416 else:
417 import QScintilla.Lexers
418 pixmap = QScintilla.Lexers.getLanguageIcon(language, True)
419 self.sbLanguage.setPixmap(pixmap)
420 if pixmap.isNull():
421 self.sbLanguage.setText(language)
422 self.sbLanguage.setToolTip("")
423 else:
424 self.sbLanguage.setText("")
425 self.sbLanguage.setToolTip(
426 self.tr('Language: {0}').format(language))
427
428 if zoom is None:
429 self.sbZoom.setValue(self.getZoom())
430 else:
431 self.sbZoom.setValue(zoom)
402 432
403 def __readShortcut(self, act, category): 433 def __readShortcut(self, act, category):
404 """ 434 """
405 Private function to read a single keyboard shortcut from the settings. 435 Private function to read a single keyboard shortcut from the settings.
406 436
2305 """ 2335 """
2306 Private method to initialize the status bar. 2336 Private method to initialize the status bar.
2307 """ 2337 """
2308 self.__statusBar = self.statusBar() 2338 self.__statusBar = self.statusBar()
2309 self.__statusBar.setSizeGripEnabled(True) 2339 self.__statusBar.setSizeGripEnabled(True)
2340
2341 self.sbLanguage = E5ClickableLabel(self.__statusBar)
2342 self.__statusBar.addPermanentWidget(self.sbLanguage)
2343 self.sbLanguage.setWhatsThis(self.tr(
2344 """<p>This part of the status bar displays the"""
2345 """ editor language.</p>"""
2346 ))
2347 self.sbLanguage.clicked.connect(self.__showLanguagesMenu)
2310 2348
2311 self.sbWritable = QLabel(self.__statusBar) 2349 self.sbWritable = QLabel(self.__statusBar)
2312 self.__statusBar.addPermanentWidget(self.sbWritable) 2350 self.__statusBar.addPermanentWidget(self.sbWritable)
2313 self.sbWritable.setWhatsThis(self.tr( 2351 self.sbWritable.setWhatsThis(self.tr(
2314 """<p>This part of the status bar displays an indication of the""" 2352 """<p>This part of the status bar displays an indication of the"""
2327 self.sbPos.setWhatsThis(self.tr( 2365 self.sbPos.setWhatsThis(self.tr(
2328 """<p>This part of the status bar displays the cursor position""" 2366 """<p>This part of the status bar displays the cursor position"""
2329 """ of the editor.</p>""" 2367 """ of the editor.</p>"""
2330 )) 2368 ))
2331 2369
2370 self.sbZoom = E5ZoomWidget(
2371 UI.PixmapCache.getPixmap("zoomOut"),
2372 UI.PixmapCache.getPixmap("zoomIn"),
2373 UI.PixmapCache.getPixmap("zoomReset"),
2374 self.__statusBar)
2375 self.__statusBar.addPermanentWidget(self.sbZoom)
2376 self.sbZoom.setWhatsThis(self.tr(
2377 """<p>This part of the status bar allows zooming the current"""
2378 """ editor or shell.</p>"""
2379 ))
2380 self.sbZoom.valueChanged.connect(self.__zoomTo)
2381
2332 self.__statusBar.showMessage(self.tr("Ready")) 2382 self.__statusBar.showMessage(self.tr("Ready"))
2333 2383
2334 def __readSettings(self): 2384 def __readSettings(self):
2335 """ 2385 """
2336 Private method to read the settings remembered last time. 2386 Private method to read the settings remembered last time.
2573 Private slot to handle the cursorPositionChanged signal. 2623 Private slot to handle the cursorPositionChanged signal.
2574 2624
2575 @param line line number of the cursor 2625 @param line line number of the cursor
2576 @param pos position in line of the cursor 2626 @param pos position in line of the cursor
2577 """ 2627 """
2578 self.__setSbFile(line + 1, pos) 2628 lang = self.getLanguage()
2629 self.__setSbFile(line + 1, pos, lang)
2579 2630
2580 if Preferences.getEditor("MarkOccurrencesEnabled"): 2631 if Preferences.getEditor("MarkOccurrencesEnabled"):
2581 self.__markOccurrencesTimer.stop() 2632 self.__markOccurrencesTimer.stop()
2582 self.__markOccurrencesTimer.start() 2633 self.__markOccurrencesTimer.start()
2583 2634
2954 self.tr("Alternatives ({0})").format( 3005 self.tr("Alternatives ({0})").format(
2955 self.getLanguage(normalized=False))) 3006 self.getLanguage(normalized=False)))
2956 else: 3007 else:
2957 self.pygmentsSelAct.setText(self.tr("Alternatives")) 3008 self.pygmentsSelAct.setText(self.tr("Alternatives"))
2958 3009
3010 def __showLanguagesMenu(self, pos):
3011 """
3012 Private slot to show the Languages menu of the status bar.
3013
3014 @param pos position the menu should be shown at (QPoint)
3015 """
3016 self.languagesMenu.exec_(pos)
3017
2959 def __selectPygmentsLexer(self): 3018 def __selectPygmentsLexer(self):
2960 """ 3019 """
2961 Private method to select a specific pygments lexer. 3020 Private method to select a specific pygments lexer.
2962 3021
2963 @return name of the selected pygments lexer 3022 @return name of the selected pygments lexer
3321 """ 3380 """
3322 Private method to get the word at the current position. 3381 Private method to get the word at the current position.
3323 3382
3324 @return the word at that current position 3383 @return the word at that current position
3325 """ 3384 """
3326 line, index = self.__textEdit.getCursorPosition() 3385 line, index = self.getCursorPosition()
3327 return self.__getWord(line, index) 3386 return self.__getWord(line, index)
3328 3387
3329 def showSearchWidget(self): 3388 def showSearchWidget(self):
3330 """ 3389 """
3331 Public method to show the search widget. 3390 Public method to show the search widget.
3606 """ 3665 """
3607 supported = self.__sourceOutline.isSupportedLanguage( 3666 supported = self.__sourceOutline.isSupportedLanguage(
3608 self.getLanguage()) 3667 self.getLanguage())
3609 3668
3610 self.__sourceOutline.setVisible(supported) 3669 self.__sourceOutline.setVisible(supported)
3670
3671 line, pos = self.getCursorPosition()
3672 lang = self.getLanguage()
3673 self.__setSbFile(line + 1, pos, language=lang)
3674
3675 #######################################################################
3676 ## Methods supporting zooming
3677 #######################################################################
3678
3679 def __zoomTo(self, value):
3680 """
3681 Private slot to zoom to a given value.
3682
3683 @param value zoom value to be set (integer)
3684 """
3685 self.zoomTo(value)
3686 self.sbZoom.setValue(self.getZoom())

eric ide

mercurial