Example #1
0
def selectFont(typeface, pointSize):
	manager = NSFontManager.sharedFontManager()
	fontList = list(manager.availableFonts()) 
	if typeface not in fontList:
		typeface = 'Helvetica-Bold'

	return CTFontCreateWithName(typeface, pointSize, None)
Example #2
0
def selectFont(typeface, pointSize):
    manager = NSFontManager.sharedFontManager()
    fontList = list(manager.availableFonts())
    if typeface not in fontList:
        typeface = 'Helvetica-Bold'

    return CTFontCreateWithName(typeface, pointSize, None)
    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 textview_format_setup(doc, textview):
    textview.setString_("")
    _family = doc.getOption('FONT_FAMILY')
    _weight = doc.getOption('FONT_WEIGHT')
    _style = doc.getOption('FONT_STYLE')
    _size = doc.getOption('FONT_SIZE')
    _color = doc.getOption('FONT_COLOR')
    _fm = NSFontManager.sharedFontManager()
    _traits = 0
    if PythonCAD.Generic.text.TextStyle.FONT_ITALIC == _style:
        _traits = _traits | NSItalicFontMask
    if PythonCAD.Generic.text.TextStyle.WEIGHT_LIGHT == _weight:
        _weight = 3
    if PythonCAD.Generic.text.TextStyle.WEIGHT_NORMAL == _weight:
        _weight = 5
    elif PythonCAD.Generic.text.TextStyle.WEIGHT_BOLD == _weight:
        _weight = 9
    elif PythonCAD.Generic.text.TextStyle.WEIGHT_HEAVY == _weight:
        _weight = 11
    _font = _fm.fontWithFamily_traits_weight_size_(_family, _traits, _weight, _size)
    if _font is None:
        return
    textview.setFont_(_font)
def textview_format_setup(doc, textview):
    textview.setString_("")
    _family = doc.getOption('FONT_FAMILY')
    _weight = doc.getOption('FONT_WEIGHT')
    _style = doc.getOption('FONT_STYLE')
    _size = doc.getOption('FONT_SIZE')
    _color = doc.getOption('FONT_COLOR')
    _fm = NSFontManager.sharedFontManager()
    _traits = 0
    if PythonCAD.Generic.text.TextStyle.FONT_ITALIC == _style:
        _traits = _traits | NSItalicFontMask
    if PythonCAD.Generic.text.TextStyle.WEIGHT_LIGHT == _weight:
        _weight = 3
    if PythonCAD.Generic.text.TextStyle.WEIGHT_NORMAL == _weight:
        _weight = 5
    elif PythonCAD.Generic.text.TextStyle.WEIGHT_BOLD == _weight:
        _weight = 9
    elif PythonCAD.Generic.text.TextStyle.WEIGHT_HEAVY == _weight:
        _weight = 11
    _font = _fm.fontWithFamily_traits_weight_size_(_family, _traits, _weight,
                                                   _size)
    if _font is None:
        return
    textview.setFont_(_font)
Example #6
0
    def openWindow(self):
        w = FloatingWindow((200, 242), title="Backdrop", closable=False)
        w.glyphList = List((10, 10, -10, 160), [{
            "Visibility": False,
            "Status": None,
            "Name": "None",
            "Position": 0,
            "layer": None
        }],
                           columnDescriptions=[{
                               "title": "Visibility",
                               "cell": CheckBoxListCell(),
                               "width": 30
                           }, {
                               "title": "Status",
                               "width": 20,
                               "editable": False
                           }, {
                               "title": "Name",
                               "width": 80,
                               "editable": False
                           }, {
                               "title": "Position",
                               "width": 30
                           }, {
                               "title": "layer",
                               "width": -3,
                               "editable": False
                           }],
                           showColumnTitles=False,
                           rowHeight=20,
                           drawFocusRing=False,
                           enableDelete=True,
                           editCallback=self.listEdited)
        w.addGlyphButton = Button((10, 180, 90, 20),
                                  "Add Glyph",
                                  callback=self.glyphPopover)
        w.transLeftButton = Button((128, 180, 30, 20),
                                   u"←",
                                   callback=self.moveLeft)
        w.transRightButton = Button((160, 180, 30, 20),
                                    u"→",
                                    callback=self.moveRight)
        w.alignButton = SegmentedButton(
            (10, 209, -7, 21),
            [dict(title=u"􀌀"),
             dict(title=u"􀌁"),
             dict(title=u"􀌂")],
            callback=self.changeAlignment,
            selectionStyle="one")
        w.alignButton.set(self.alignment)
        w.open()

        fm = NSFontManager.sharedFontManager()
        systemFont = NSFont.systemFontOfSize_(NSFont.systemFontSize())
        self.italicFont = fm.fontWithFamily_traits_weight_size_(
            systemFont.fontName(), NSItalicFontMask, 5, systemFont.pointSize())
        self.boldFont = fm.fontWithFamily_traits_weight_size_(
            systemFont.fontName(), NSUnitalicFontMask, 8,
            systemFont.pointSize())

        self.currentWindow = w
        self.toolStatus = True
        try:
            self.currentGlyph = Glyphs.font.selectedLayers[0]
        except:
            pass

        self.refreshGL()
        self.updateWindowUI()
Example #7
0
#
#   Python GUI - Fonts - PyObjC
#

import sys
from AppKit import NSFont, NSFontManager, NSBoldFontMask, NSItalicFontMask, \
 NSLayoutManager
from GUI import export
from GUI.GFonts import Font as GFont

_ns_font_manager = NSFontManager.sharedFontManager()
_ns_layout_manager = NSLayoutManager.alloc().init()


class Font(GFont):
    #  _ns_font   NSFont

    def _from_ns_font(cls, ns_font):
        font = cls.__new__(cls)
        font._ns_font = ns_font
        return font

    _from_ns_font = classmethod(_from_ns_font)

    def __init__(self, family, size=12, style=[]):
        traits = 0
        if 'bold' in style:
            traits |= NSBoldFontMask
        if 'italic' in style:
            traits |= NSItalicFontMask
        self._ns_font = _ns_font_manager.fontWithFamily_traits_weight_size_(
Example #8
0
#
#   Python GUI - Fonts - PyObjC
#

import sys
from AppKit import NSFont, NSFontManager, NSBoldFontMask, NSItalicFontMask, \
    NSLayoutManager
from GUI import export
from GUI.GFonts import Font as GFont

_ns_font_manager = NSFontManager.sharedFontManager()
_ns_layout_manager = NSLayoutManager.alloc().init()

class Font(GFont):
    #  _ns_font   NSFont
    
    def _from_ns_font(cls, ns_font):
        font = cls.__new__(cls)
        font._ns_font = ns_font
        return font
    
    _from_ns_font = classmethod(_from_ns_font)
    
    def __init__(self, family, size = 12, style = []):
        traits = 0
        if 'bold' in style:
            traits |= NSBoldFontMask
        if 'italic' in style:
            traits |= NSItalicFontMask
        self._ns_font = _ns_font_manager.fontWithFamily_traits_weight_size_(
            family, traits, 5, size)