src/eric7/QScintilla/MiniEditor.py

branch
eric7
changeset 9482
a2bc06a54d9d
parent 9473
3f23dbf37dbe
child 9573
9960d19d66b5
equal deleted inserted replaced
9481:0b936ff1bbb9 9482:a2bc06a54d9d
24 QTimer, 24 QTimer,
25 pyqtSignal, 25 pyqtSignal,
26 pyqtSlot, 26 pyqtSlot,
27 ) 27 )
28 from PyQt6.QtGui import QAction, QActionGroup, QFont, QKeySequence, QPalette, QPixmap 28 from PyQt6.QtGui import QAction, QActionGroup, QFont, QKeySequence, QPalette, QPixmap
29 from PyQt6.QtPrintSupport import QAbstractPrintDialog, QPrintDialog, QPrinter 29 from PyQt6.QtPrintSupport import (
30 QAbstractPrintDialog,
31 QPrintDialog,
32 QPrinter,
33 QPrintPreviewDialog,
34 )
30 from PyQt6.QtWidgets import ( 35 from PyQt6.QtWidgets import (
31 QApplication, 36 QApplication,
32 QDialog, 37 QDialog,
33 QHBoxLayout, 38 QHBoxLayout,
34 QInputDialog, 39 QInputDialog,
48 from eric7.EricWidgets.EricMainWindow import EricMainWindow 53 from eric7.EricWidgets.EricMainWindow import EricMainWindow
49 from eric7.EricWidgets.EricZoomWidget import EricZoomWidget 54 from eric7.EricWidgets.EricZoomWidget import EricZoomWidget
50 from eric7.Globals import isMacPlatform 55 from eric7.Globals import isMacPlatform
51 from eric7.UI import Config 56 from eric7.UI import Config
52 57
58 from . import Lexers
59 from .EditorOutline import EditorOutlineView
53 from .QsciScintillaCompat import QsciScintillaCompat 60 from .QsciScintillaCompat import QsciScintillaCompat
61 from .SearchReplaceWidget import SearchReplaceWidget
54 62
55 63
56 class MiniScintilla(QsciScintillaCompat): 64 class MiniScintilla(QsciScintillaCompat):
57 """ 65 """
58 Class implementing a QsciScintillaCompat subclass for handling focus 66 Class implementing a QsciScintillaCompat subclass for handling focus
287 295
288 self.__curFile = filename 296 self.__curFile = filename
289 self.__lastLine = 0 297 self.__lastLine = 0
290 298
291 self.srHistory = {"search": [], "replace": []} 299 self.srHistory = {"search": [], "replace": []}
292 from .SearchReplaceWidget import SearchReplaceWidget
293
294 self.__searchWidget = SearchReplaceWidget(False, self, self) 300 self.__searchWidget = SearchReplaceWidget(False, self, self)
295 self.__replaceWidget = SearchReplaceWidget(True, self, self) 301 self.__replaceWidget = SearchReplaceWidget(True, self, self)
296
297 from .EditorOutline import EditorOutlineView
298 302
299 self.__sourceOutline = EditorOutlineView(self, populate=False) 303 self.__sourceOutline = EditorOutlineView(self, populate=False)
300 self.__sourceOutline.setMaximumWidth( 304 self.__sourceOutline.setMaximumWidth(
301 Preferences.getEditor("SourceOutlineWidth") 305 Preferences.getEditor("SourceOutlineWidth")
302 ) 306 )
536 if language is None: 540 if language is None:
537 pixmap = QPixmap() 541 pixmap = QPixmap()
538 elif language == "": 542 elif language == "":
539 pixmap = EricPixmapCache.getPixmap("fileText") 543 pixmap = EricPixmapCache.getPixmap("fileText")
540 else: 544 else:
541 from eric7.QScintilla import Lexers
542
543 pixmap = Lexers.getLanguageIcon(language, True) 545 pixmap = Lexers.getLanguageIcon(language, True)
544 self.sbLanguage.setPixmap(pixmap) 546 self.sbLanguage.setPixmap(pixmap)
545 if pixmap.isNull(): 547 if pixmap.isNull():
546 self.sbLanguage.setText(language) 548 self.sbLanguage.setText(language)
547 self.sbLanguage.setToolTip("") 549 self.sbLanguage.setToolTip("")
3676 3678
3677 def __printPreviewFile(self): 3679 def __printPreviewFile(self):
3678 """ 3680 """
3679 Private slot to show a print preview of the text. 3681 Private slot to show a print preview of the text.
3680 """ 3682 """
3681 from PyQt6.QtPrintSupport import QPrintPreviewDialog
3682
3683 from .Printer import Printer 3683 from .Printer import Printer
3684 3684
3685 printer = Printer(mode=QPrinter.PrinterMode.HighResolution) 3685 printer = Printer(mode=QPrinter.PrinterMode.HighResolution)
3686 if self.__curFile: 3686 if self.__curFile:
3687 printer.setDocName(pathlib.Path(self.__curFile).name) 3687 printer.setDocName(pathlib.Path(self.__curFile).name)
3748 self.noLanguageAct.setCheckable(True) 3748 self.noLanguageAct.setCheckable(True)
3749 self.noLanguageAct.setData("None") 3749 self.noLanguageAct.setData("None")
3750 self.languagesActGrp.addAction(self.noLanguageAct) 3750 self.languagesActGrp.addAction(self.noLanguageAct)
3751 menu.addSeparator() 3751 menu.addSeparator()
3752 3752
3753 from . import Lexers
3754
3755 self.supportedLanguages = {} 3753 self.supportedLanguages = {}
3756 supportedLanguages = Lexers.getSupportedLanguages() 3754 supportedLanguages = Lexers.getSupportedLanguages()
3757 languages = sorted(supportedLanguages.keys()) 3755 languages = sorted(supportedLanguages.keys())
3758 for language in languages: 3756 for language in languages:
3759 if language != "Guessed": 3757 if language != "Guessed":
3805 Private method to select a specific pygments lexer. 3803 Private method to select a specific pygments lexer.
3806 3804
3807 @return name of the selected pygments lexer 3805 @return name of the selected pygments lexer
3808 @rtype str 3806 @rtype str
3809 """ 3807 """
3810 from pygments.lexers import get_all_lexers 3808 from pygments.lexers import get_all_lexers # __IGNORE_WARNING_I102__
3811 3809
3812 lexerList = sorted(lex[0] for lex in get_all_lexers()) 3810 lexerList = sorted(lex[0] for lex in get_all_lexers())
3813 try: 3811 try:
3814 lexerSel = lexerList.index( 3812 lexerSel = lexerList.index(
3815 self.getLanguage(normalized=False, forPygments=True) 3813 self.getLanguage(normalized=False, forPygments=True)
3960 if not self.filetype: 3958 if not self.filetype:
3961 if not language and pyname: 3959 if not language and pyname:
3962 self.filetype = pyname 3960 self.filetype = pyname
3963 else: 3961 else:
3964 self.filetype = language 3962 self.filetype = language
3965
3966 from . import Lexers
3967 3963
3968 self.lexer_ = Lexers.getLexer(language, self.__textEdit, pyname=pyname) 3964 self.lexer_ = Lexers.getLexer(language, self.__textEdit, pyname=pyname)
3969 if self.lexer_ is None: 3965 if self.lexer_ is None:
3970 self.__textEdit.setLexer() 3966 self.__textEdit.setLexer()
3971 self.apiLanguage = "" 3967 self.apiLanguage = ""
4040 elif line0.startswith("\\documentclass"): 4036 elif line0.startswith("\\documentclass"):
4041 bindName = "dummy.tex" 4037 bindName = "dummy.tex"
4042 4038
4043 if not bindName and self.filetype: 4039 if not bindName and self.filetype:
4044 # check filetype 4040 # check filetype
4045 from . import Lexers
4046
4047 supportedLanguages = Lexers.getSupportedLanguages() 4041 supportedLanguages = Lexers.getSupportedLanguages()
4048 if self.filetype in supportedLanguages: 4042 if self.filetype in supportedLanguages:
4049 bindName = supportedLanguages[self.filetype][1] 4043 bindName = supportedLanguages[self.filetype][1]
4050 elif self.filetype in ["Python", "Python3", "MicroPython"]: 4044 elif self.filetype in ["Python", "Python3", "MicroPython"]:
4051 bindName = "dummy.py" 4045 bindName = "dummy.py"

eric ide

mercurial