eric6/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py

branch
jsonfiles
changeset 8026
d3eacdbcb18b
parent 8022
2da0139f4f91
child 8028
a4f1b68c0737
equal deleted inserted replaced
8025:aaad60a23960 8026:d3eacdbcb18b
8 """ 8 """
9 9
10 import os 10 import os
11 11
12 from PyQt5.QtCore import pyqtSlot, Qt, QFileInfo, QFile, QIODevice 12 from PyQt5.QtCore import pyqtSlot, Qt, QFileInfo, QFile, QIODevice
13 from PyQt5.QtGui import QPalette, QFont 13 from PyQt5.QtGui import QPalette, QFont, QColor
14 from PyQt5.QtWidgets import ( 14 from PyQt5.QtWidgets import (
15 QColorDialog, QFontDialog, QInputDialog, QMenu, QTreeWidgetItem, QDialog 15 QColorDialog, QFontDialog, QInputDialog, QMenu, QTreeWidgetItem, QDialog
16 ) 16 )
17 17
18 from .ConfigurationPageBase import ConfigurationPageBase 18 from .ConfigurationPageBase import ConfigurationPageBase
605 # new JSON based file 605 # new JSON based file
606 from Preferences.HighlightingStylesFile import ( 606 from Preferences.HighlightingStylesFile import (
607 HighlightingStylesFile 607 HighlightingStylesFile
608 ) 608 )
609 highlightingStylesFile = HighlightingStylesFile() 609 highlightingStylesFile = HighlightingStylesFile()
610 res = highlightingStylesFile.readFile(fn, lexers) 610 styles = highlightingStylesFile.readFile(fn, lexers)
611 if not res: 611 if not styles:
612 return 612 return
613 else: 613 else:
614 # old XML based file 614 # old XML based file
615 f = QFile(fn) 615 f = QFile(fn)
616 if f.open(QIODevice.ReadOnly): 616 if f.open(QIODevice.ReadOnly):
617 from E5XML.HighlightingStylesReader import ( 617 from E5XML.HighlightingStylesReader import (
618 HighlightingStylesReader 618 HighlightingStylesReader
619 ) 619 )
620 reader = HighlightingStylesReader(f, lexers) 620 reader = HighlightingStylesReader(f, lexers)
621 reader.readXML() 621 styles = reader.readXML()
622 f.close() 622 f.close()
623 if not styles:
624 return
623 else: 625 else:
624 E5MessageBox.critical( 626 E5MessageBox.critical(
625 self, 627 self,
626 self.tr("Import Highlighting Styles"), 628 self.tr("Import Highlighting Styles"),
627 self.tr( 629 self.tr(
629 " be read.</p><p>Reason: {1}</p>" 631 " be read.</p><p>Reason: {1}</p>"
630 ).format(fn, f.errorString()) 632 ).format(fn, f.errorString())
631 ) 633 )
632 return 634 return
633 635
636 self.__applyStyles(styles, lexers)
634 self.on_lexerLanguageComboBox_activated( 637 self.on_lexerLanguageComboBox_activated(
635 self.lexerLanguageComboBox.currentText()) 638 self.lexerLanguageComboBox.currentText())
639
640 def __applyStyles(self, stylesList, lexersList):
641 """
642 Private method to apply the imported styles to this dialog.
643
644 @param stylesList list of imported lexer styles
645 @type list of dict
646 @param lexersList list of lexers to apply the styles to
647 @type list of PreferencesLexer
648 """
649 for lexerDict in stylesList:
650 if lexerDict["name"] in lexersList:
651 lexer = lexersList[lexerDict["name"]]
652 for styleDict in lexerDict["styles"]:
653 style = styleDict["style"]
654 substyle = styleDict["substyle"]
655 lexer.setColor(QColor(styleDict["color"]), style, substyle)
656 lexer.setPaper(QColor(styleDict["paper"]), style, substyle)
657 font = QFont()
658 font.fromString(styleDict["font"])
659 lexer.setFont(font, style, substyle)
660 lexer.setEolFill(styleDict["eolfill"], style, substyle)
661 if substyle >= 0:
662 # description and words can only be set for sub-styles
663 lexer.setDescription(styleDict["description"],
664 style, substyle)
665 lexer.setWords(styleDict["words"], style, substyle)
636 666
637 ####################################################################### 667 #######################################################################
638 ## Methods to save and restore the state 668 ## Methods to save and restore the state
639 ####################################################################### 669 #######################################################################
640 670

eric ide

mercurial