Beispiel #1
0
 def get_current_font(self):
     font_name = gprefs.get('gpm_template_editor_font', None)
     size = gprefs['gpm_template_editor_font_size']
     if font_name is None:
         font = QFont()
         font.setFixedPitch(True)
         font.setPointSize(size)
     else:
         font = QFont(font_name, pointSize=size)
     return font
Beispiel #2
0
 def set_up_font_boxes(self):
     font_name = gprefs.get('gpm_template_editor_font', None)
     size = gprefs['gpm_template_editor_font_size']
     if font_name is None:
         font = QFont()
         font.setFixedPitch(True)
         font.setPointSize(size)
     else:
         font = QFont(font_name, pointSize=size)
     self.font_box.setWritingSystem(QFontDatabase.Latin)
     self.font_box.setCurrentFont(font)
     self.font_box.setEditable(False)
     gprefs['gpm_template_editor_font'] = unicode_type(font.family())
     self.font_size_box.setValue(size)
     self.font_box.currentFontChanged.connect(self.font_changed)
     self.font_size_box.valueChanged.connect(self.font_size_changed)
     self.highlighter.initializeFormats()
     self.highlighter.rehighlight()
    def initialize_formats(self):
        font_name = gprefs.get('gpm_template_editor_font', None)
        size = gprefs['gpm_template_editor_font_size']
        if font_name is None:
            font = QFont()
            font.setFixedPitch(True)
            font.setPointSize(size)
            font_name = font.family()
        config = self.Config = {}
        config["fontfamily"] = font_name
        app_palette = QApplication.instance().palette()
        for name, color, bold, italic in (
            ("normal", None, False, False),
            ("keyword", app_palette.color(QPalette.ColorRole.Link).name(),
             True, False), ("builtin",
                            app_palette.color(QPalette.ColorRole.Link).name(),
                            False, False), ("identifier", None, False, True),
            ("comment", "#007F00", False, True), ("string", "#808000", False,
                                                  False), ("number", "#924900",
                                                           False, False),
            ("lparen", None, True, True), ("rparen", None, True, True)):
            config["%sfontcolor" % name] = color
            config["%sfontbold" % name] = bold
            config["%sfontitalic" % name] = italic
        base_format = QTextCharFormat()
        base_format.setFontFamily(config["fontfamily"])
        config["fontsize"] = size
        base_format.setFontPointSize(config["fontsize"])

        self.Formats = {}
        for name in ("normal", "keyword", "builtin", "comment", "identifier",
                     "string", "number", "lparen", "rparen"):
            format_ = QTextCharFormat(base_format)
            color = config["%sfontcolor" % name]
            if color:
                format_.setForeground(QColor(color))
            if config["%sfontbold" % name]:
                format_.setFontWeight(QFont.Weight.Bold)
            format_.setFontItalic(config["%sfontitalic" % name])
            self.Formats[name] = format_