mojo.UI

This page documents a large collection of function and classes able to interact with the RoboFont user interface.

Retrieve windows

If you need to access a RoboFont window from a script, here you’ll find the right function

CurrentGlyphWindow(currentFontOnly=False)

Get the current Glyph Window.

currentFontOnly
Bool. Optionally only return the glyph window for the current font.

CurrentFontWindow()

Return the current Font Window.

CurrentSpaceCenter(currentFontOnly=False)

Return the current Space Center.

currentFontOnly
Bool. Optionally only return the Space Center for the current font.

CurrentSpaceCenterWindow(currentFontOnly=False)

Return the current Space Center window.

currentFontOnly
Bool. Optionally only return the Space Center window for the current font.

CurrentWindow(currentFontOnly=False)

Get the current font-related window. It can be either a Font Window, Glyph Window, Space Center or a Single Font Window.

currentFontOnly
Bool. Optionally only return the window for the current font.

AllGlyphWindows(currentFontOnly=False)

Get all open Glyph Windows.

currentFontOnly
Bool. Optionally only return the glyph windows for the current font.

AllFontWindows()

Return all open Font Windows.

AllSpaceCenters(currentFontOnly=False)

Return a list of all open Space Centers.

currentFontOnly
Bool. Optionally only return the Space Centers for the current font.

AllSpaceCenterWindows(currentFontOnly=False)

Return a list of all open Space Center windows.

currentFontOnly
Bool: Optionally only return the Space Center windows for the current font.

AllWindows(currentFontOnly=False)

Return all open font-related windows. The result is a list containing Font Windows, Glyph Windows, Space Centers, Single Font Windows.

currentFontOnly
Bool. Optionally only return the windows for the current font.

OutputWindow()

The Output Window. Use OutputWindow().clear() to empty it.

Open Windows

Handy helpers for opening RoboFont windows from a Python script

OpenGlyphWindow(glyph=None, newWindow=False)

Open a Glyph Window with a given glyph.

from mojo.UI import OpenGlyphWindow
myGlyph = CurrentFont()["Agrave"]
OpenGlyphWindow(glyph=myGlyph, newWindow=True)
glyph
RGlyph. The glyph to be displayed in the glyph view.
newWindow
Bool. Optionally force opening a new Glyph Window, even if there is already one open.

OpenSpaceCenter(font, newWindow=False)

Open a Space Center for a given font.

newWindow
Bool. Optionally force opening a new Space Center window, even if there is already one open.

OpenFontInfoSheet(font, parentWindow=None)

Open a Font Info Sheet for a given font.

parentWindow
Optionally attach the Font Info Sheet to a specific parent window. By default it is attached to the main window.

Display Settings

These function allow the user to interact with the display settings of the glyph window

getGlyphViewDisplaySettings()

Return a dictionary with the current display settings in the glyph view.

setGlyphViewDisplaySettings(settings)

Set display options for the current glyph view.

Input must be provided as a dict[str: bool]. The given settings will become the new defaults for the glyph view.

from mojo.UI import setGlyphViewDisplaySettings
setGlyphViewDisplaySettings({"Fill": True})

The available options are:

  • MeasurementInfo
  • Fill
  • SegmentIndexes
  • Image
  • FamilyBlues
  • OutlineErrors
  • Bitmap
  • Metrics
  • Stroke
  • ComponentInfo
  • Grid
  • ContourIndexes
  • CurveLength
  • OffCurvePoints
  • PointCoordinates
  • Blues
  • ImageInfo
  • PointIndexes
  • MetricsTitles
  • Labels
  • Guides
  • OnCurvePoints
  • Anchors
  • AnchorIndexes
  • ComponentIndexes

Set by name

It is possible to set a glyph or a layer by name in the current Glyph Window

SetCurrentGlyphByName(glyphName)

Set the current glyph by glyph name in the current Glyph View.

from mojo.UI import SetCurrentGlyphByName
SetCurrentGlyphByName(glyphName="Agrave")

SetCurrentLayerByName(layerName)

Set the current layer by layer name in the current Glyph View.

from mojo.UI import SetCurrentLayerByName
SetCurrentLayerByName(layerName="background")

Draw View to PDF

Export to PDF the Glyph Window or the Space Center

GlyphWindowToPDF(path, glyphWindow=None, currentFontOnly=False)

Save the contents of the glyph window as a pdf.

path
The path to save the pdf.
glyphWindow
Optionally provide a Glyph Window, as default it takes the current Glyph Window.
currentFontOnly
Bool. Optionally only return the Glyph Window for the current font.

SpaceCenterToPDF(path, spaceCenter=None, currentFontOnly=False)

Save the contents of the Space Center as a pdf.

path
The path to the pdf file.
spaceCenter
Optionally provide a Space Center, as default it takes the current Space Center.
currentFontOnly
Bool. Optionally only return the Space Center for the current font.

Test Installed Fonts

Functions to work with test installed fonts

getTestInstalledFonts()

Return all fonts which are test installed.

testDeinstallFont(font)

Deinstall a provided font.

Character Sets

Function to manipulate and use the character sets from the RoboFont application

setDefaultCharacterSet(characterSetName)

Set the default character set by name as defined in the Preferences.

from mojo.UI import setDefaultCharacterSet
setDefaultCharacterSet(characterSetName="MyCharSet")

getDefaultCharacterSet()

Return the name of the current default character set.

addCharacterSet(characterSetName, glyphNames, useAsDefault=False)

Add a character set with a characterSetName and a list of glyphNames.

useAsDefault
Bool. Optionally set a bool indicating if characterSetName is the new default character set name.

removeCharacterSet(characterSetName)

Remove a character set by name.

getCharacterSets()

Return all character sets as a dictionary.

setCharacterSets(characterSets)

Set character sets from a dictionary.

from mojo.UI import setCharacterSets
setCharacterSets({"Latin-2": ["A", "B"], "Latin-3": ["C", "D"]})

Tools

Miscellanea of powerful tools!

splitText(text, cmap, groups={})

Convert a given text string to a list of glyph names based on the given cmap.

Optionally a groups dictionary can be provided.

class MenuBuilder()

Build a menu from a structured list of items.

[
    NSMenuItem,
    ("title", callback),
    ("title", [
            ("sub menu title", callback),
        ])
]
title
Optionally provide a title.
menu
Optionally use "main" to add the items to the main menu or provide an NSMenu.
insert
Optionally provide an insert index to insert the items at a specific index.
shouldAddSeparatorItem
Optionally add seperator item when items are added to an existing menu`.
closeCallback
Optionally provide a close callback, this callback is called when the menu closes.
Inherits from subclass: mojo.UI.MenuBuilder

pyobjc_ISA

pyobjc_instanceMethods

addMenuFromPath(path)

Add a menu build from a directory of python files.

open(event, view)

Open the menu for an event in a view.

buildAdditionContextualMenuItems(menu, additionContextualMenuItems, insert=None, shouldAddSeparatorItem=True)

getMenu()

Return the menu.

Keyboard Tools

These functions allow you to interact with the keyboard and the application shortcuts

createModifier(command=False, shift=False, control=False, alternate=False)

Return a modifier mask (integer) indicating which modifiers keys have been pressed.

Keyword arguments (bool): command, shift, control, alternate.

shortKeyExists(shortKey)

Returns a bool indicating if a keyboard shortcut exists in the application menu.

getMenuShortCuts()

Get all menu shortcuts as a dictionary.

setMenuShortCuts(menuShortCuts)

Set menu shortcuts.

menuShortCuts must be a dict with a tuple of strings as keys, and a tuple of modifier integer and string as values:

from mojo.UI import setMenuShortCuts
shortCutsMap = { ("Scripts", "myToolMenuName"): (123456, "a") }
setMenuShortCuts(shortCutsMap)

removeMenuShortCut(*menuShortCut)

Remove a menu shortcut by its menu name.

Vanilla components

A collection of RoboFont specific vanilla components

dontShowAgainMessage(messageText='', informativeText='', alertStyle=1, parentWindow=None, resultCallback=None, dontShowAgainKey='')

Show a dialog with a Don’t Show Again option.

messageText
The message to be displayed in the dialog.
informativeText
The informative text to be displayed in the dialog.
alertStyle
Optionally provide an alert style – see NSAlertStyle.
parentWindow
Optionally provide a window object, must be a vanilla or NSWindow object.
resultCallback
The callback return the user input.
dontShowAgainKey
The key to store the result. If the key is available, the dialog will not pop up. Must be a reverse domain key: com.example.myTool.action

dontShowAgainYesOrNo(messageText='', informativeText='', alertStyle=1, parentWindow=None, resultCallback=None, buttons=[], dontShowAgainKey='')

Show a Yes or No dialog with a Don’t Show Again option.

messageText
The message to be displayed in the dialog.
informativeText
The informative text to be displayed in the dialog.
alertStyle
Optionally provide an alert style – see NSAlertStyle.
parentWindow
Optionally provide a window object, must be a vanilla or NSWindow object.
resultCallback
The callback return the user input.
buttons
Optionally provide a list of button titles. The defaults are:
  • Yes
  • No
  • Don’t show this message again
dontShowAgainKey
The key to store the result. If the key is available, the dialog will not pop up. Must be a reverse domain key: com.example.myTool.action

AskString(message, value='', title='FontParts')

AskString

A dialog to ask for a string. A message is required.

Optionally a default value and title can be provided.

from mojo.UI import AskString
print(AskString("who are you?", value="James Font"))

AskYesNoCancel(message, title='FontParts', default=0, informativeText='')

AskYesNoCancel

A dialog to ask for Yes, No or Cancel. A message is required.

Optionally a title, default (0 or 1) and informativeText can be provided. The default option indicates which button is the default one.

from mojo.UI import AskYesNoCancel
answer = AskYesNoCancel("is it raining?")
print(answer)
# Yes = 1
# No = 0
# Cancel = -1

FindGlyph(aFont, message='Search for a glyph:', title='FontParts')

FindGlyph

A dialog to search for a glyph in a given font.

Optionally a message and title can be provided.

from mojo.UI import FindGlyph
glyph = FindGlyph(CurrentFont())
print(glyph)

GetFile(message=None, title=None, directory=None, fileName=None, allowsMultipleSelection=False, fileTypes=None)

GetFile

A dialog to select one or more files.

message
message on top of the GetFile sheet. (optional)
directory
starting point of the GetFile dialog. (optional)
fileName
You can restrict the search to a specific filename. Default is None(optional)
allowsMultipleSelection
Boolean. If True allows the selection of multiple files. Default is False (optional)
from mojo.UI import GetFile
answer = GetFile(
    message="Select a binary font",
    directory="~/Desktop",
    fileName=None,
    allowsMultipleSelection=False,
    fileTypes=["ttf", "otf"])
print(answer)

GetFileOrFolder(message=None, title=None, directory=None, fileName=None, allowsMultipleSelection=False, fileTypes=None)

GetFileOrFolder

A dialog to select one or more files or folders.

message
message on top of the GetFile sheet. (optional)
directory
starting point of the GetFile dialog. (optional)
fileName
You can restrict the search to a specific filename. Default is None(optional)
allowsMultipleSelection
Boolean. If True allows the selection of multiple files. Default is False (optional)
from mojo.UI import GetFileOrFolder
answer = GetFileOrFolder(
    message="Select a binary font",
    directory="~/Desktop",
    fileName=None,
    allowsMultipleSelection=False,
    fileTypes=["ttf", "otf"])
print(answer)

GetFolder(message=None, title=None, directory=None, allowsMultipleSelection=False)

GetFolder

A dialog to select one or more folders.

message
message on top of the GetFolder sheet. (optional)
directory
starting point of the GetFolder dialog. (optional)
allowsMultipleSelection
Boolean. It only allows the selection of one folder. Default is False.
from mojo.UI import GetFolder
answer = GetFolder(
    message="Select a folder with fonts",
    directory="~/Desktop",
    allowsMultipleSelection=True
    )
print(answer)

Message(message, title='FontParts', informativeText='')

Message

A dialog to display a message.

Optionally a message and informativeText can be provided.

from mojo.UI import Message
Message("This is going to be bold",
        informativeText="This instead just regular")

PutFile(message=None, fileName=None)

A dialog to put a file in a selected folder.

message
Call to action on top of the sheet. (optional)
fileName
Suggested filename. (optional)
from mojo.UI import PutFile
path = PutFile(
    message="Choose a location for this font",
    fileName="Griddy Sans.ttf")
print(path)

SearchList(items, message='Select an item:', title='FontParts')

SearchList

A dialog to search in a given list.

Optionally a message and title can be provided.

from mojo.UI import SearchList
result = SearchList(["a", "b", "c"])
print(result)

SelectFont(message='Select a font:', title='FontParts', allFonts=None)

SelectFont

A dialog to select one font among all open fonts.

Optionally a message, title and allFonts can be provided. If allFonts is None, all open fonts will be listed.

from mojo.UI import SelectFont
font = SelectFont()
print(font)

SelectGlyph(aFont, message='Select a glyph:', title='FontParts')

SelectGlyph

A dialog to select a glyph from a given font.

Optionally a message and title can be provided.

from mojo.UI import SelectGlyph
font = CurrentFont()
glyph = SelectGlyph(font)
print(glyph)

PostBannerNotification(title, informativeText)

Pop up a banner notification with a provided title and informativeText.

from mojo.UI import PostBannerNotification
PostBannerNotification("foo", "bar")

RoboFont Windows

A collection of your favourite RoboFont windows to be subclassed or initiated

class HelpWindow()

A Help Window to view HTML help files.

htmlPath
Path to html file to set in the HTML view.
htmlString
A string containing html to set in the HTML view.
title
The title of the window.
developer
A string with the name of the developer. (optional)
developerURL
A URL link to the developer. (optional)
from mojo.UI import HelpWindow

HelpWindow("http://robofont.com")
Inherits from subclass: mojo.UI.HelpWindow

reload()

Reload the contents of the HTML view.

setHTML(html)

Set window contents from HTML string.

setHTMLPath(htmlPath)

Set window contents from path to HTML file.

class DoodleWindow()

A window capable of containing controls.

To add a control to a window, simply set it as an attribute of the window.

from vanilla import Window, Button, TextBox

class WindowDemo:

    def __init__(self):
        self.w = Window((200, 70), "Window Demo")
        self.w.myButton = Button((10, 10, -10, 20), "My Button")
        self.w.myTextBox = TextBox((10, 40, -10, 17), "My Text Box")
        self.w.open()

WindowDemo()

No special naming is required for the attributes. However, each attribute must have a unique name.

posSize Tuple of form (left, top, width, height) representing the position and size of the window. It may also be a tuple of form (width, height). In this case, the window will be positioned on screen automatically.

title The title to be set in the title bar of the window.

minSize Tuple of the form (width, height) representing the minimum size that the window can be resized to.

maxSize Tuple of the form (width, height) representing the maximum size that the window can be resized to.

textured Boolean value representing if the window should have a textured appearance or not.

autosaveName A string representing a unique name for the window. If given, this name will be used to store the window position and size in the application preferences.

closable Boolean value representing if the window should have a close button in the title bar.

miniaturizable Boolean value representing if the window should have a minimize button in the title bar.

initiallyVisible Boolean value representing if the window will be initially visible. Default is True. If False, you can show the window later by calling window.show().

fullScreenMode An indication of the full screen mode. These are the options:

   
None The window does not allow full screen.
“primary” Corresponds to NSWindowCollectionBehaviorFullScreenPrimary.
“auxiliary” Corresponds to NSWindowCollectionBehaviorFullScreenAuxiliary.

titleVisible Boolean value indicating if the window title should be displayed.

fullSizeContentView Boolean value indicating if the content view should be the full size of the window, including the area underneath the titlebar and toolbar.

screen A NSScreen object indicating the screen that the window should be drawn to. When None the window will be drawn to the main screen.

Inherits from subclass: objc._PyObjCIntermediate_NSObject

class StatusInteractivePopUpWindow()

A window capable of containing controls.

To add a control to a window, simply set it as an attribute of the window.

from vanilla import Window, Button, TextBox

class WindowDemo:

    def __init__(self):
        self.w = Window((200, 70), "Window Demo")
        self.w.myButton = Button((10, 10, -10, 20), "My Button")
        self.w.myTextBox = TextBox((10, 40, -10, 17), "My Text Box")
        self.w.open()

WindowDemo()

No special naming is required for the attributes. However, each attribute must have a unique name.

posSize Tuple of form (left, top, width, height) representing the position and size of the window. It may also be a tuple of form (width, height). In this case, the window will be positioned on screen automatically.

title The title to be set in the title bar of the window.

minSize Tuple of the form (width, height) representing the minimum size that the window can be resized to.

maxSize Tuple of the form (width, height) representing the maximum size that the window can be resized to.

textured Boolean value representing if the window should have a textured appearance or not.

autosaveName A string representing a unique name for the window. If given, this name will be used to store the window position and size in the application preferences.

closable Boolean value representing if the window should have a close button in the title bar.

miniaturizable Boolean value representing if the window should have a minimize button in the title bar.

initiallyVisible Boolean value representing if the window will be initially visible. Default is True. If False, you can show the window later by calling window.show().

fullScreenMode An indication of the full screen mode. These are the options:

   
None The window does not allow full screen.
“primary” Corresponds to NSWindowCollectionBehaviorFullScreenPrimary.
“auxiliary” Corresponds to NSWindowCollectionBehaviorFullScreenAuxiliary.

titleVisible Boolean value indicating if the window title should be displayed.

fullSizeContentView Boolean value indicating if the content view should be the full size of the window, including the area underneath the titlebar and toolbar.

screen A NSScreen object indicating the screen that the window should be drawn to. When None the window will be drawn to the main screen.

close()

windowDeselectCallback_()

Inherits from subclass: objc._PyObjCIntermediate_NSObject

class ScrollToFirstResponderWindow()

A window capable of containing controls.

To add a control to a window, simply set it as an attribute of the window.

from vanilla import Window, Button, TextBox

class WindowDemo:

    def __init__(self):
        self.w = Window((200, 70), "Window Demo")
        self.w.myButton = Button((10, 10, -10, 20), "My Button")
        self.w.myTextBox = TextBox((10, 40, -10, 17), "My Text Box")
        self.w.open()

WindowDemo()

No special naming is required for the attributes. However, each attribute must have a unique name.

posSize Tuple of form (left, top, width, height) representing the position and size of the window. It may also be a tuple of form (width, height). In this case, the window will be positioned on screen automatically.

title The title to be set in the title bar of the window.

minSize Tuple of the form (width, height) representing the minimum size that the window can be resized to.

maxSize Tuple of the form (width, height) representing the maximum size that the window can be resized to.

textured Boolean value representing if the window should have a textured appearance or not.

autosaveName A string representing a unique name for the window. If given, this name will be used to store the window position and size in the application preferences.

closable Boolean value representing if the window should have a close button in the title bar.

miniaturizable Boolean value representing if the window should have a minimize button in the title bar.

initiallyVisible Boolean value representing if the window will be initially visible. Default is True. If False, you can show the window later by calling window.show().

fullScreenMode An indication of the full screen mode. These are the options:

   
None The window does not allow full screen.
“primary” Corresponds to NSWindowCollectionBehaviorFullScreenPrimary.
“auxiliary” Corresponds to NSWindowCollectionBehaviorFullScreenAuxiliary.

titleVisible Boolean value indicating if the window title should be displayed.

fullSizeContentView Boolean value indicating if the content view should be the full size of the window, including the area underneath the titlebar and toolbar.

screen A NSScreen object indicating the screen that the window should be drawn to. When None the window will be drawn to the main screen.

Inherits from subclass: objc._PyObjCIntermediate_NSObject

class ModalWindow()

A window capable of containing controls.

To add a control to a window, simply set it as an attribute of the window.

from vanilla import Window, Button, TextBox

class WindowDemo:

    def __init__(self):
        self.w = Window((200, 70), "Window Demo")
        self.w.myButton = Button((10, 10, -10, 20), "My Button")
        self.w.myTextBox = TextBox((10, 40, -10, 17), "My Text Box")
        self.w.open()

WindowDemo()

No special naming is required for the attributes. However, each attribute must have a unique name.

posSize Tuple of form (left, top, width, height) representing the position and size of the window. It may also be a tuple of form (width, height). In this case, the window will be positioned on screen automatically.

title The title to be set in the title bar of the window.

minSize Tuple of the form (width, height) representing the minimum size that the window can be resized to.

maxSize Tuple of the form (width, height) representing the maximum size that the window can be resized to.

textured Boolean value representing if the window should have a textured appearance or not.

autosaveName A string representing a unique name for the window. If given, this name will be used to store the window position and size in the application preferences.

closable Boolean value representing if the window should have a close button in the title bar.

miniaturizable Boolean value representing if the window should have a minimize button in the title bar.

initiallyVisible Boolean value representing if the window will be initially visible. Default is True. If False, you can show the window later by calling window.show().

fullScreenMode An indication of the full screen mode. These are the options:

   
None The window does not allow full screen.
“primary” Corresponds to NSWindowCollectionBehaviorFullScreenPrimary.
“auxiliary” Corresponds to NSWindowCollectionBehaviorFullScreenAuxiliary.

titleVisible Boolean value indicating if the window title should be displayed.

fullSizeContentView Boolean value indicating if the content view should be the full size of the window, including the area underneath the titlebar and toolbar.

screen A NSScreen object indicating the screen that the window should be drawn to. When None the window will be drawn to the main screen.

Inherits from subclass: objc._PyObjCIntermediate_NSObject

class ShowHideWindow()

A window capable of containing controls.

To add a control to a window, simply set it as an attribute of the window.

from vanilla import Window, Button, TextBox

class WindowDemo:

    def __init__(self):
        self.w = Window((200, 70), "Window Demo")
        self.w.myButton = Button((10, 10, -10, 20), "My Button")
        self.w.myTextBox = TextBox((10, 40, -10, 17), "My Text Box")
        self.w.open()

WindowDemo()

No special naming is required for the attributes. However, each attribute must have a unique name.

posSize Tuple of form (left, top, width, height) representing the position and size of the window. It may also be a tuple of form (width, height). In this case, the window will be positioned on screen automatically.

title The title to be set in the title bar of the window.

minSize Tuple of the form (width, height) representing the minimum size that the window can be resized to.

maxSize Tuple of the form (width, height) representing the maximum size that the window can be resized to.

textured Boolean value representing if the window should have a textured appearance or not.

autosaveName A string representing a unique name for the window. If given, this name will be used to store the window position and size in the application preferences.

closable Boolean value representing if the window should have a close button in the title bar.

miniaturizable Boolean value representing if the window should have a minimize button in the title bar.

initiallyVisible Boolean value representing if the window will be initially visible. Default is True. If False, you can show the window later by calling window.show().

fullScreenMode An indication of the full screen mode. These are the options:

   
None The window does not allow full screen.
“primary” Corresponds to NSWindowCollectionBehaviorFullScreenPrimary.
“auxiliary” Corresponds to NSWindowCollectionBehaviorFullScreenAuxiliary.

titleVisible Boolean value indicating if the window title should be displayed.

fullSizeContentView Boolean value indicating if the content view should be the full size of the window, including the area underneath the titlebar and toolbar.

screen A NSScreen object indicating the screen that the window should be drawn to. When None the window will be drawn to the main screen.

Inherits from subclass: objc._PyObjCIntermediate_NSObject

class ShowHideFloatingWindow()

A window that floats above all other windows.

To add a control to a window, simply set it as an attribute of the window.

from vanilla import FloatingWindow, Button, TextBox

class FloatingWindowDemo:

    def __init__(self):
        self.w = FloatingWindow((200, 70), "FloatingWindow Demo")
        self.w.myButton = Button((10, 10, -10, 20), "My Button")
        self.w.myTextBox = TextBox((10, 40, -10, 17), "My Text Box")
        self.w.open()

FloatingWindowDemo()

No special naming is required for the attributes. However, each attribute must have a unique name.

posSize Tuple of form (left, top, width, height) representing the position and size of the window. It may also be a tuple of form (width, height). In this case, the window will be positioned on screen automatically.

title The title to be set in the title bar of the window.

minSize Tuple of the form (width, height) representing the minimum size that the window can be resized to.

maxSize Tuple of the form (width, height) representing the maximum size that the window can be resized to.

textured Boolean value representing if the window should have a textured appearance or not.

autosaveName A string representing a unique name for the window. If given, this name will be used to store the window position and size in the application preferences.

closable Boolean value representing if the window should have a close button in the title bar.

screen A NSScreen object indicating the screen that the window should be drawn to. When None the window will be drawn to the main screen.

Inherits from subclass: vanilla.vanillaWindows.FloatingWindow

show()

Show the window if it is hidden.

class ScrollToFirstResponderSheet()

A window that is attached to another window.

To add a control to a sheet, simply set it as an attribute of the sheet.

from vanilla import Window, Sheet, Button

class SheetDemo:

    def __init__(self):
        self.w = Window((240, 140), "Sheet Demo")
        self.w.openSheet = Button((10, -30, -10, 20),
                    "open sheet", callback=self.openSheetCallback)
        self.w.open()

    def openSheetCallback(self, sender):
        self.sheet = Sheet((160, 70), self.w)
        self.sheet.closeSheet = Button((10, -30, -10, 20),
                    "close sheet", callback=self.closeSheetCallback)
        self.sheet.open()

    def closeSheetCallback(self, sender):
        self.sheet.close()
        del self.sheet

SheetDemo()

No special naming is required for the attributes. However, each attribute must have a unique name.

posSize Tuple of form (width, height) representing the size of the sheet.

parentWindow The window that the sheet should be attached to.

minSize Tuple of the form (width, height) representing the minimum size that the sheet can be resized to.

maxSize Tuple of the form (width, height) representing the maximum size that the sheet can be resized to.

autosaveName A string representing a unique name for the sheet. If given, this name will be used to store the sheet size in the application preferences.

Inherits from subclass: vanilla.vanillaWindows.Sheet

RoboFont Views

A collection of RoboFont Views to be composed into a vanilla window

class SpaceCenter()

A vanilla object to preview text and edit the spacing values in a font.

from vanilla import Window
from mojo.UI import SpaceCenter

class MySpacingWindow:

    def __init__(self, font):
        self.font = font
        self.w = Window((800, 600), 'My Space Center', minSize=(600, 400))
        self.w.spaceCenter = SpaceCenter((0, 0, -0, -0), self.font, glyphNames='hello world')
        self.w.open()

MySpacingWindow(CurrentFont().naked())

beam()

Get the vertical position of the beam.

disableDrag(value)

get()

Get the text input as a list of glyph names.

getAfter()

Get the after control glyphs input as a list of glyph names.

getLayerName()

Get the selected font layer to be used in the preview.

getLeftToRight()

Get the writing direction of the text sample as a bool.

  • True: left-to-right
  • False: right-to-left

getLineHeight()

Get the line height of the text sample.

getOffset()

Get the view offset.

getPointSize()

Get the point size of the text sample.

getPre()

Get the before control glyphs input as a list of glyph names.

getRaw()

Get the text input as a string of characters.

getScrollbarSize()

getShowLayers()

Get the layers to be shown in addition to the current layer.

getShowNumberInputView()

Get the current display state of the Space Matrix as a bool.

getSuffix()

Get the current glyph name suffix.

getTracking()

Get the tracking of the text sample.

glyphLineViewInputCallback(sender)

keepSelectionAfterCurrentGlyphChanged()

layersCallback(sender)

layersChanged(sender)

populateLayers()

populateSettings()

populateSuffixes()

previewSizeCallback(sender)

refreshAllExept(sender=None)

refreshGlyphLineView(sender=None)

Refresh the glyph line view.

set(glyphNames)

Set the text input from a list of glyph names.

setAfter(glyphNames)

Set the after control glyphs input from a list of glyph names.

setBeam(value)

Set the position of the beam.

setFont(font)

Set the font for the text sample.

The given font can be an RFont or a defcon Font object.

setGlyphLineInputSampleText()

setInputWritingDirection(direction)

setLayerName(layer)

Set the font layer to be used in the preview.

setLeftToRight(value)

Set the writing direction of the text sample.

  • True: left-to-right
  • False: right-to-left

setLineHeight(value)

Set the line height of the text sample.

setLineHeightCallback(sender)

setOffset(xy)

Set an offset of the view.

setPointSize(size)

Set the point size of the text sample.

setPointSizeFromLineView(value)

setPre(glyphNames)

Set the before control glyphs input from a list of glyph names.

setRaw(value)

Set the text input from a string of characters.

setSettingMenuStates()

setShowLayers(layers)

Set additional layers to be shown in the text sample.

Layers which are not present in the font will be silently ignored.

Use None to clear the layers list.

setShowNumberInputView(value)

Set the current display state of the Space Matrix as a bool.

setSuffix(suffix)

Set a glyph name suffix.

Suffixes which are not present in the font will be silently ignored.

Use None to clear suffixes.

setTracking(value)

Set the tracking of the text sample.

setTrackingCallback(sender)

settingsCallback(sender)

suffixCallback(sender)

updateGlyphLineView()

Refresh the glyph line view.

updateInputFields(sender, changedItem, newGlyph)

usesCurrentGlyph()

windowDidFinish(sender)

Inherits from subclass: vanilla.vanillaGroup.Group

getDropItemValues(items, pasteboardType=None)

Get Python objects from the given NSPasteboardItem objects for the given pasteboard type. If this view is registered for only one pasteboard type, None may be given as the pasteboard type.

setDropSettings(settings)

class AccordionView()

A vanilla object hosting different kinds of other vanilla objects (like vanilla.List, vanilla.TextEditor, ….) in an accordion view.

posSize

a tuple of four, setting the size

descriptions

list of options for each item in the accordionView (see example)

backgroundColor

a NSColor object used as background color

from mojo.UI import AccordionView
from vanilla import *

class MyInspector:

    def __init__(self):

        self.w = FloatingWindow((200, 600))

        self.firstItem = TextEditor((10, 10, -10, -10))

        self.secondItem = List((0, 0, -0, -0), ["a", "b", "c"])

        self.thirdItem = Tabs((10, 10, -10, -10), ["1", "2", "3"])

        self.fourthItem = Group((0, 0, -0, -0))

        self.fourthItem.checkBox = CheckBox((10, 10, 100, 22), "CheckBox")
        self.fourthItem.editText = EditText((10, 40, -10, 22))


        descriptions = [
                       dict(label="first item", view=self.firstItem, size=200, collapsed=False, canResize=False),
                       dict(label="second item", view=self.secondItem, minSize=100, size=140, collapsed=True, canResize=True),
                       dict(label="third item", view=self.thirdItem, minSize=100, size=140, collapsed=True, canResize=False),
                       dict(label="fourth item", view=self.fourthItem, size=140, collapsed=False, canResize=False)
                       ]

        self.w.accordionView = AccordionView((0, 0, -0, -0), descriptions)

        self.w.open()

MyInspector()

isPaneVisible(label)

showPane(label, onOff, animate=False)

togglePane(label, animate=False)

Inherits from subclass: vanilla.vanillaScrollView.ScrollView

setBackgroundColor(color)

Set the background of the scrol view to color.

class MultiLineView()

A vanilla object to display a multi-glyph line view. This is the object used to build a Space Center.

Available arguments when initiating a multi line view object:

posSize
A tuple of four values (x, y, w, h) setting the position and size.
pointSize
The initial point size. (optional)
lineHeight
The initial line height. (optional)
doubleClickCallback
Callback for a double-click event. (optional)
applyKerning
Enable kerning in the view. (optional)
bordered
Set a border around the view. (optional)
hasHorizontalScroller
Set the horizontal scroller. (optional)
hasVerticalScroller
Set the vertical scroller. (optional)
displayOptions
A dict with multi-line view display options. (optional)
selectionCallback
Callback for when a glyph gets selected. (optional)
menuForEventCallback
Callback for when a contextual menu is used, required to return a NSMenu object. (optional)
from mojo.UI import MultiLineView
from vanilla import *

class MyOwnSpaceCenter:

    def __init__(self, font):

        self.w = Window((600, 400), minSize=(300, 300))

        self.w.lineView = MultiLineView((0, 0, -0, -0),
                pointSize=30,
                selectionCallback=self.lineViewSelectionCallback)
        self.w.lineView.setFont(font)

        glyphs = []
        for glyphName in font.glyphOrder:
            glyphs.append(font[glyphName])

        self.w.lineView.set(glyphs)

        self.w.open()

    def lineViewSelectionCallback(self, sender):
        print(sender.getSelectedGlyph())

MyOwnSpaceCenter(CurrentFont())
Inherits from subclass: mojo.UI.MultiLineView

createEmptyGlyph(name=None)

Return a special empty glyph.

createNewLineGlyph()

Return a special new line glyph.

getGlyphRecords()

Returns all glyph records in the line view.

getSelectedGlyph()

Return the selected glyph.

getSelection()

Return the selected index.

setCanSelect(value)

Set a bool indicating if the line view can select glyphs.

setGlyphRecords(glyphRecords)

Set a list of glyph records in the line view.

setSelection(index)

Set a selection index.

update()

Update the glyph line view.

canAutoScale()

Return a bool indicating if the view can scale automatically.

getApplyKerning()

Return bool is if kerning is applied.

getDisplayStates()

Return the current display states as a dictionary.

getFont()

Return the font from the glyph line view.

getLayer()

getSelected()

Return the selected glyph.

getSelectedGlyphRecord()

Return the selected glyph record.

isFirstResponder()

Return a bool indicating if the line view is the first responder.

refresh()

Refresh the glyph line view.

setApplyKerning(value)

Set apply kerning.

setCenter(center)

Get the parent Space Center.

setDisplayMode(mode)

Set a display mode.

setDisplayStates(displayOptions)

Set display states from a given dict displayOptions.

setKerningInGlyphRecords(glyphRecords)

Apply kerning in the given glyph records.

setLayer(layer)

setSelectedGlyphRecord(glyphRecord)

Set the selected glyph record.

setShouldDrawGlyph(value)

Disable default glyph drawing.

class HTMLView()

A vanilla browser object.

posSize

a tuple of four, setting the size

clearHistory()

Clear HTMLView history.

getWKWebView()

Return the WebKit WebView.

goBack()

Go backward in the history of the HTMLView.

goForward()

Go forward in the history of the HTMLView.

setFrameDelegate(delegate)

Set a frame delegate.

Inherits from subclass: vanilla.vanillaGroup.Group

class SpaceMatrix()

A vanilla object to input values for width and left/right margins when spacing glyphs.

from mojo.UI import MultiLineView, SpaceMatrix
from vanilla import Window, HorizontalLine

class Controller:

    def __init__(self):

        self.w = Window((400, 400))

        self.w.lineView = MultiLineView((0, 0, -0, -48), pointSize=72)
        self.w.hl = HorizontalLine((0, -(48+1), -0, 1))
        self.w.matrix = SpaceMatrix((0, -50, -0, -0), callback=self._matrixCallback)

        f = CurrentFont()
        glyphs = [f["A"], f["a"]]

        self.w.lineView.setFont(f)
        self.w.lineView.set(glyphs)
        self.w.matrix.set(glyphs)
        self.w.open()

    def _matrixCallback(self, sender):
        self.w.lineView.update()

Controller()
Inherits from subclass: mojo.UI.SpaceMatrix

getShowPreAfterGlyphs()

Get a bool indicating if pre and after glyphs should be shown in the matrix.

getShowTemplateGlyphs()

Get a bool indicating if template glyphs should be shown in the matrix.

isInputEditing()

Return a bool is the scroll view text editing is active.

setBeamPosition(value)

Set the vertical position of the beam from the given value.

setShowBeam(value)

Set a bool indicating if the beam should be shown.

setShowPreAfterGlyphs(value)

Set a bool indicating if pre and after glyphs should be shown in the matrix.

setShowTemplateGlyphs(value)

Set a bool indicating if template glyphs should be shown in the matrix.

setSpaceCenter(spaceCenter)

Set a parent Space Center.

class CodeEditor()

Code editor control.

from vanilla import Window
from mojo.UI import CodeEditor

class CodeEditorDemo(object):

    def __init__(self):
        self.w = Window((200, 200))
        self.w.codeEditor = CodeEditor((10, 10, -10, -10),
                            callback=self.codeEditorCallback,
                            showLineNumbers=True)
        self.w.open()

    def codeEditorCallback(self, sender):
        print("text entry!", sender.get())

CodeEditorDemo()

posSize Tuple of form (left, top, width, height) representing the position and size of the text entry control.

text The text to be displayed in the text entry control.

lexer A pygements lexer: `from pygments.lexers import PythonLexer

usesTabs Boolean representing if the ediotor should use tabs.

indentSize The amount of indent.

showLineNumbers Boolean representing to showing line numbers

callback The method to be called when the user presses the text entry control.

readOnly Boolean representing if the text can be edited or not.

checksSpelling Boolean representing if spelling should be automatically checked or not.

comment()

dedent()

hasLineNumbers()

indent()

indentSize()

insertText(text)

jumpToLine(lineNumber=None)

setHighlightStyle(style)

setIndentSize(value)

setLanguagesIDEBehavior(languagesIDEBehavior)

setLexer(lexer)

setRunCallback(callback)

Set a callback when ever cmd-R is pressed

setUsesTabs(value)

showLineNumbers(value)

toggleLineNumbers()

uncomment()

usesTabs()

wrapWord(value)

Inherits from subclass: vanilla.vanillaTextEditor.TextEditor

enable(onOff)

Enable or disable the object. onOff should be a boolean.

getNSTextView()

Return the NSTextView_ that this object wraps.

.. _NSTextView: https://developer.apple.com/documentation/appkit/nstextview?language=objc

selectAll()

Select all text in the text entry control.

class KernCenter()

A vanilla object to preview and edit kerning values in a given font.

parentWindow
Optionally provide a parentWindow to attach the sheet to.
Inherits from subclass: mojo.UI.KernCenter

lineViewAdjustSelectedPair(value)

lineViewSelectionCallback(selection)

class GroupCenter()

A vanilla object to preview and edit groups in a given font.

parentWindow
Optionally provide a parentWindow to attach the sheet to.
Inherits from subclass: mojo.UI.GroupCenter

RoboFont Controls

A collection of RoboFont Controls to be composed into a vanilla window

class GlyphSequenceEditText()

A vanilla view to input a sequence of glyphs.

from mojo.UI import GlyphSequenceEditText
from vanilla import Window

class Controller:

    def __init__(self):
        self.w = Window((400, 200))
        self.w.sequence = GlyphSequenceEditText((10, 10, -10, 22),
            font=CurrentFont(),
            callback=self.sequenceCallback)
        self.w.open()

    def sequenceCallback(self, sender):
        print(sender.get())

Controller()
Inherits from subclass: mojo.UI.GlyphSequenceEditText

layer()

validateSequenceEditCallback(sender)

getNSTextField()

Return the NSTextField_ that this object wraps.

.. _NSTextField: https://developer.apple.com/documentation/appkit/nstextfield?language=objc

getPlaceholder()

Get the placeholder string displayed in the control.

setPlaceholder(value)

Set value as the placeholder string to be displayed in the control. value must be a string.

bind(key, callback)

getTitle()

Get the control title.

isEnabled()

Return a bool indicating if the object is enable or not.

setTitle(title)

Set the control title.

title A string representing the title.

class EditStepper()

A vanilla object to edit a value with stepper.

Inherits from subclass: vanilla.vanillaGroup.Group

class EditIntStepper()

A vanilla object to edit a value with stepper.

Inherits from subclass: vanilla.vanillaGroup.Group

class SliderEditStepper()

A vanilla object to edit a value with stepper and a slider.

Inherits from subclass: vanilla.vanillaGroup.Group

class NumberEditText()

A vanilla object to edit a numbers.

Inherits from subclass: vanilla.vanillaEditText.EditText

class StatusBar()

A vanilla object status bar.status

posSize

a tuple of four, setting the size

notificationName

A optional notification name to subscribe to extract status messages when the notification is been send.

horizontalLine

An optional bool indication to draw a horizontal line at the top.

textAlign

An optional text align value, possible options are left, right, center, justified, natural.

textPosLeft and textPosRight

An optional value indication the left and right margins inside the view

from mojo.UI import StatusBar
from vanilla import *

class StatusBarExample(object):

    def __init__(self):
        self.w = Window((250, 300))

        self.w.hello = Button((10, 10, -10, 22), "Hello", callback=self.helloCallback)
        self.w.helloFade = Button((10, 40, -10, 22), "Hello Fade", callback=self.helloFadeCallback)
        self.w.helloWarning = Button((10, 70, -10, 22), "Hello Warning", callback=self.helloWarningCallback)

        self.w.statusBar = StatusBar((0, -18, -0, -0))
        self.w.open()

    def helloCallback(self, sender):
        self.w.statusBar.set(["hello"])

    def helloFadeCallback(self, sender):
        self.w.statusBar.set(["hello Fade"], fadeOut=True)

    def helloWarningCallback(self, sender):
        self.w.statusBar.set(["hello Warning"], warning=True)

StatusBarExample()

performFadeOut(sender)

Inherits from subclass: vanilla.vanillaGroup.Group

class LightStatusBar()

A vanilla object status bar.status

posSize

a tuple of four, setting the size

notificationName

A optional notification name to subscribe to extract status messages when the notification is been send.

horizontalLine

An optional bool indication to draw a horizontal line at the top.

textAlign

An optional text align value, possible options are left, right, center, justified, natural.

textPosLeft and textPosRight

An optional value indication the left and right margins inside the view

from mojo.UI import StatusBar
from vanilla import *

class StatusBarExample(object):

    def __init__(self):
        self.w = Window((250, 300))

        self.w.hello = Button((10, 10, -10, 22), "Hello", callback=self.helloCallback)
        self.w.helloFade = Button((10, 40, -10, 22), "Hello Fade", callback=self.helloFadeCallback)
        self.w.helloWarning = Button((10, 70, -10, 22), "Hello Warning", callback=self.helloWarningCallback)

        self.w.statusBar = StatusBar((0, -18, -0, -0))
        self.w.open()

    def helloCallback(self, sender):
        self.w.statusBar.set(["hello"])

    def helloFadeCallback(self, sender):
        self.w.statusBar.set(["hello Fade"], fadeOut=True)

    def helloWarningCallback(self, sender):
        self.w.statusBar.set(["hello Warning"], warning=True)

StatusBarExample()
Inherits from subclass: vanilla.vanillaGroup.Group

class SimpleStatus()

A vanilla object status bar.status

posSize

a tuple of four, setting the size

notificationName

A optional notification name to subscribe to extract status messages when the notification is been send.

horizontalLine

An optional bool indication to draw a horizontal line at the top.

textAlign

An optional text align value, possible options are left, right, center, justified, natural.

textPosLeft and textPosRight

An optional value indication the left and right margins inside the view

from mojo.UI import StatusBar
from vanilla import *

class StatusBarExample(object):

    def __init__(self):
        self.w = Window((250, 300))

        self.w.hello = Button((10, 10, -10, 22), "Hello", callback=self.helloCallback)
        self.w.helloFade = Button((10, 40, -10, 22), "Hello Fade", callback=self.helloFadeCallback)
        self.w.helloWarning = Button((10, 70, -10, 22), "Hello Warning", callback=self.helloWarningCallback)

        self.w.statusBar = StatusBar((0, -18, -0, -0))
        self.w.open()

    def helloCallback(self, sender):
        self.w.statusBar.set(["hello"])

    def helloFadeCallback(self, sender):
        self.w.statusBar.set(["hello Fade"], fadeOut=True)

    def helloWarningCallback(self, sender):
        self.w.statusBar.set(["hello Warning"], warning=True)

StatusBarExample()
Inherits from subclass: vanilla.vanillaGroup.Group

class ProgressBar()

A progress bar dialog.

Optionally a title, ticks and label can be provided.

from mojo.UI import ProgressBar
from time import sleep
bar = ProgressBar()
sleep(3)  # seconds
bar.close()
Inherits from subclass: mojo.UI.ProgressBar

getCurrentTick()

Return the current tick state.

label(label)

Set the label for the progress bar.

tick(tickValue=None)

Increment the tick value. Optionally a tickValue can be provided to set the tick count.

setTickCount(value)

Set the tick count for the progress bar

Undo

These functions are the best way to keep track of undo/redo -ing processes

isUndoing()

Return a boolean when a undo action is happening on the current undo manager.

isRedoing()

Return a boolean when a redo action is happening on the current undo manager.

Preferences

Did you know that you can access and manipulate application preferences with Python code?

preferencesChanged()

Send out a notification that the Preferences have changed.

exportPreferences(path=None)

Export all user preferences to a given file path.

When path is None, a dictionary with all Preferences values is returned.

importPreferences(pathOrObject)

Import user Preferences from a path or dictionary object.

getDefault(key, defaultValue=None, defaultClass=None)

Get a default Preferences value for a key, with a fallback value if the key is not present in the defaults.

setDefault(key, value, validate=True)

Set a default Preferences value for a key.

validate
Bool. Optionally validate the key and the value, default is True.

removeDefault(key)

Remove a key from the Preferences defaults.

setMaxAmountOfVisibleTools(value)

Set the maximum amount of visible tools in the toolbar.

getMaxAmountOfVisibleTools()

Get the maximum amount of visible tools in the toolbar.

Passwords

A collection of function to deal with passwords

setPassword(service, username, password)

getPassword(service, username)

deletePassword(service, username)

Deprecated

A collection of still usable but deprecated functions/objects

UpdateCurrentGlyphView()

Update the current Glyph View.

getScriptingMenuNamingShortKey()

setScriptingMenuNamingShortKey(data)

setScriptingMenuNamingShortKeyForPath(path, preferredName, shortKey='', modifier=None)

removeScriptingMenuNamingShortKeyForPath(path)

class SliderEditIntStepper()

A vanilla object to edit a value with stepper and a slider.

Inherits from subclass: vanilla.vanillaGroup.Group

AllScriptingWindows()

Return all open Scripting Windows.

CurrentScriptingWindow()

Return the current scripting window.

OpenScriptingWindow(path=None)

Open a Scripting Window.

path
Optionally open a path to the .py file.

OpenInspectorWindow()

Open the Inspector Window.

from mojo.UI import OpenInspectorWindow
OpenInspectorWindow()

inDarkMode()

Return a True when the app is in dark mode.

appearanceColorKey(key)

Get the appearance color key if available in the preferences. Light is the default, dark is the Available after 10.14

class GlyphRecord()

advanceWidth

asString()

Last edited on 29/11/2024