def _selectFontCallback(self, sender):
     oldFont = getFontDefault("PyDEFont", fallbackFont)
     newFont = sender.convertFont_(oldFont)
     if oldFont != newFont:
         self._setFont(newFont)
         setFontDefault("PyDEFont", newFont)
         self.preferencesChanged()
 def _selectFontCallback(self, sender):
     oldFont = getFontDefault("PyDEFont", fallbackFont)
     newFont = sender.convertFont_(oldFont)
     if oldFont != newFont:
         self._setFont(newFont)
         setFontDefault("PyDEFont", newFont)
         self.preferencesChanged()
Exemple #3
0
def _textAttributesForStyle(style, font=None, token=None):
    if font is None:
        font = getFontDefault("PyDEFont", fallbackFont)
    if token and token in _textAttributesForStyleCache:
        return _textAttributesForStyleCache[token]
    attr = {AppKit.NSLigatureAttributeName: 0, AppKit.NSParagraphStyleAttributeName: basicParagraph}
    if style.get("italic", False) and style.get("bold", False):
        fontManager = AppKit.NSFontManager.sharedFontManager()
        boldItalic = fontManager.convertFont_toHaveTrait_(font, AppKit.NSBoldFontMask | AppKit.NSItalicFontMask)
        if boldItalic is not None:
            font = boldItalic
    elif style.get("italic", False):
        fontManager = AppKit.NSFontManager.sharedFontManager()
        italic = fontManager.convertFont_toHaveTrait_(font, AppKit.NSItalicFontMask)
        if italic is not None:
            font = italic
    elif style.get("bold", False):
        fontManager = AppKit.NSFontManager.sharedFontManager()
        bold = fontManager.convertFont_toHaveTrait_(font, AppKit.NSBoldFontMask)
        if bold is not None:
            font = bold
    attr[AppKit.NSFontAttributeName] = font

    if style.get("color", False):
        attr[AppKit.NSForegroundColorAttributeName] = style["color"]
    if style.get("bgcolor", False):
        attr[AppKit.NSBackgroundColorAttributeName] = style["bgcolor"]
    if style.get("underline", False):
        attr[AppKit.NSUnderlineStyleAttributeName] = AppKit.NSUnderlineStyleSingle
        if style["color"]:
            attr[AppKit.NSUnderlineColorAttributeName] = style["color"]
    if token:
        _textAttributesForStyleCache[token] = attr
    return attr
 def selectFontCallback(self, sender):
     fm = NSFontManager.sharedFontManager()
     fm.setSelectedFont_isMultiple_(getFontDefault("PyDEFont", fallbackFont), False)
     fm.orderFrontFontPanel_(sender)
     fp = fm.fontPanel_(False)
     
     self._fontCallbackWrapper = VanillaCallbackWrapper(self._selectFontCallback)
     fm.setTarget_(self._fontCallbackWrapper)
     fm.setAction_("action:")
    def selectFontCallback(self, sender):
        fm = NSFontManager.sharedFontManager()
        fm.setSelectedFont_isMultiple_(getFontDefault("PyDEFont", fallbackFont), False)
        fm.orderFrontFontPanel_(sender)
        fp = fm.fontPanel_(False)

        self._fontCallbackWrapper = VanillaCallbackWrapper(self._selectFontCallback)
        fm.setTarget_(self._fontCallbackWrapper)
        fm.setAction_("action:")
    def getFromDefaults(self):
        self._initializing = True
        self._setFont(getFontDefault("PyDEFont", fallbackFont))

        styles = styleFromDefault()
        items = []

        for token, value in fallbackStyles:
            data = dict(token=str(token))
            style = styles.style_for_token(token)
            data.update(style)
            item = ColorItem(data)
            items.append(item)
        self.tokenList.set(items)

        self.backgroundColor.set(getColorDefault("PyDEBackgroundColor", fallbackBackgroundColor))
        self.hightLightColor.set(getColorDefault("PyDEHightLightColor", fallbackHightLightColor))
        self._initializing = False
    def getFromDefaults(self):
        self._initializing = True
        self._setFont(getFontDefault("PyDEFont", fallbackFont))

        styles = styleFromDefault()
        items = []

        for token, value in fallbackStyles:
            data = dict(token=str(token))
            style = styles.style_for_token(token)
            data.update(style)
            item = ColorItem(data)
            items.append(item)
        self.tokenList.set(items)

        self.backgroundColor.set(getColorDefault("PyDEBackgroundColor", fallbackBackgroundColor))
        self.hightLightColor.set(getColorDefault("PyDEHightLightColor", fallbackHightLightColor))
        self._initializing = False
Exemple #8
0
    def setTextAttributes(self):
        self.setString_("")

        styles = styleFromDefault()
        self.setHighlightStyle_(styles)
        self.textAttributes = outputTextAttributesForStyles(styles)
        self.tracebackAttributes = outputTextAttributesForStyles(styles, isError=True)

        backgroundColor = _hexStringToNSColor(styles.background_color, self._fallbackBackgroundColor)
        self.setBackgroundColor_(backgroundColor)
        selectionColor = _hexStringToNSColor(styles.highlight_color, self._fallbackHightLightColor)
        self.setSelectedTextAttributes_({NSBackgroundColorAttributeName:selectionColor})

        self.setFont_(getFontDefault("PyDEFont", self._fallbackFont))

        items = self._items
        self._items = []
        for text, isError in items:
            self.appendText_isError_(text, isError)
Exemple #9
0
 def _highlightSyntax(self, location, text):
     if self.lexer() is None:
         return
     font = getFontDefault("PyDEFont", self._fallbackFont)
     length = len(self.string())
     setAttrs = self.textStorage().setAttributes_range_
     if text.endswith("\n"):
         text = text[:-1]
     #setAttrs = self.layoutManager().addTemporaryAttributes_forCharacterRange_
     self.textStorage().beginEditing()
     totLenValue = 0
     for pos, token, value in self.lexer().get_tokens_unprocessed(text):
         style = self.highlightStyleMap.get(token)
         lenValue = len(value)
         if location + pos + lenValue > length:
             lenValue = length - (location + pos)
         if lenValue > 0:
             setAttrs(_textAttributesForStyle(style, font), (location + pos, lenValue))
             totLenValue += lenValue
     self.textStorage().fixFontAttributeInRange_((location, totLenValue))
     self.textStorage().endEditing()
 def _highlightSyntax(self, location, text):
     if self.lexer() is None:
         return
     font = getFontDefault("PyDEFont", self._fallbackFont)
     length = len(self.string())
     setAttrs = self.textStorage().setAttributes_range_
     if text.endswith("\n"):
         text = text[:-1]
     # setAttrs = self.layoutManager().addTemporaryAttributes_forCharacterRange_
     self.textStorage().beginEditing()
     totLenValue = 0
     for pos, token, value in self.lexer().get_tokens_unprocessed(text):
         style = self.highlightStyleMap.get(token)
         lenValue = len(value)
         if location + pos + lenValue > length:
             lenValue = length - (location + pos)
         if lenValue > 0:
             setAttrs(_textAttributesForStyle(style, font),
                      (location + pos, lenValue))
             totLenValue += lenValue
     self.textStorage().fixFontAttributeInRange_((location, totLenValue))
     self.textStorage().endEditing()
def _textAttributesForStyle(style, font=None, token=None):
    if font is None:
        font = getFontDefault("PyDEFont", fallbackFont)
    if token and token in _textAttributesForStyleCache:
        return _textAttributesForStyleCache[token]
    attr = {
        NSLigatureAttributeName: 0,
        NSParagraphStyleAttributeName: basicParagraph,
    }

    if style.get("italic", False) and style.get("bold", False):
        fontManager = NSFontManager.sharedFontManager()
        boldItalic = fontManager.convertFont_toHaveTrait_(
            font, NSBoldFontMask | NSItalicFontMask)
        if boldItalic is not None:
            font = boldItalic
    elif style.get("italic", False):
        fontManager = NSFontManager.sharedFontManager()
        italic = fontManager.convertFont_toHaveTrait_(font, NSItalicFontMask)
        if italic is not None:
            font = italic
    elif style.get("bold", False):
        fontManager = NSFontManager.sharedFontManager()
        bold = fontManager.convertFont_toHaveTrait_(font, NSBoldFontMask)
        if bold is not None:
            font = bold
    attr[NSFontAttributeName] = font

    if style.get("color", False):
        attr[NSForegroundColorAttributeName] = style["color"]
    if style.get("bgcolor", False):
        attr[NSBackgroundColorAttributeName] = style["bgcolor"]
    if style.get("underline", False):
        attr[NSUnderlineStyleAttributeName] = NSUnderlineStyleSingle
        if style["color"]:
            attr[NSUnderlineColorAttributeName] = style["color"]
    if token:
        _textAttributesForStyleCache[token] = attr
    return attr
    def setTextAttributes(self):
        self.setString_("")

        styles = styleFromDefault()
        self.setHighlightStyle_(styles)
        self.textAttributes = outputTextAttributesForStyles(styles)
        self.tracebackAttributes = outputTextAttributesForStyles(styles,
                                                                 isError=True)

        backgroundColor = _hexStringToNSColor(styles.background_color,
                                              self._fallbackBackgroundColor)
        self.setBackgroundColor_(backgroundColor)
        selectionColor = _hexStringToNSColor(styles.highlight_color,
                                             self._fallbackHightLightColor)
        self.setSelectedTextAttributes_(
            {NSBackgroundColorAttributeName: selectionColor})

        self.setFont_(getFontDefault("PyDEFont", self._fallbackFont))

        items = self._items
        self._items = []
        for text, isError in items:
            self.appendText_isError_(text, isError)