fontlab.flWorkspace
flWorkspace
flWorkspace is the FontLab application itself — represented as a Python object. It knows which fonts you have open, which glyph window is in front, what tool is active, and what zoom level you're looking at. When you want to do anything at the application level — loop over all open fonts, switch to a different window, change the active tool, or trigger an export — flWorkspace is where you start.
You always get to it the same way:
ws = flWorkspace.instance()
That gives you the running FontLab application. There's only ever one.
As a type designer writing scripts, you'll use flWorkspace for:
- Finding open fonts —
ws.packages()gives you a list of every font currently open. - Knowing which font is in focus —
ws.currentPackageis the font whose window is active. - Accessing the active glyph window —
ws.getActiveCanvas()gives you the editor window you're looking at. - Switching tools —
ws.setToolEditor(),ws.setToolPen(), etc. - Exporting fonts —
ws.exportCurrentFont()orws.exportFont(pkg, options). - Batch scripts — loop over
ws.packages()to process every open font.
Getting the Instance
from fontlab import flWorkspace
ws = flWorkspace.instance()
Common Scripting Patterns
from fontlab import flWorkspace
ws = flWorkspace.instance()
# Get the active font
font = ws.currentPackage
# Get the active glyph editor window
canvas = ws.getActiveCanvas()
# Loop over all open fonts
for pkg in ws.packages():
print(pkg.info.familyName)
# Suppress screen flicker during a batch edit
ws.blockUpdate(5000) # suppress for up to 5 seconds
# ... make many edits ...
ws.unblockUpdate() # release immediately when done
# After batch edits, ensure screen is refreshed
ws.updateActiveViewport()
# Switch to the node editor tool when your script finishes
ws.setToolEditor()
Tutorial: Looping Over All Open Fonts
This pattern is the foundation of most batch-processing scripts.
from PythonQt.QtGui import QTransform
import fontlab as fl
from fontlab import flWorkspace, flModel
ws = flWorkspace.instance()
# ============================================================
# 1. Which font is active right now?
# ============================================================
active_font = ws.currentPackage
if active_font:
print(f"Active font: {active_font.info.familyName}")
else:
print("No font is currently active.")
# ============================================================
# 2. Loop over every open font
# ============================================================
all_fonts = ws.packages()
print(f"\n{len(all_fonts)} font(s) open:\n")
for pkg in all_fonts:
info = pkg.info
# info.familyName and info.styleName give you the font's
# family and style names as they appear in Font Info
print(f" {info.familyName} {info.styleName}")
# ============================================================
# 3. Do something to every glyph in every open font
# ============================================================
# Example: print the glyph count for each open font.
for pkg in ws.packages():
glyph_count = len(pkg.glyphs)
name = pkg.info.familyName or "(unnamed)"
print(f" {name}: {glyph_count} glyphs")
# ============================================================
# 4. Batch edit with update suppression
# ============================================================
# When making many edits across many glyphs, block screen
# updates first to avoid flickering and speed things up.
changed_ids = set()
ws.blockUpdate(10000) # suppress updates for up to 10 seconds
try:
for pkg in ws.packages():
for glyph in pkg.glyphs:
# Example: shift every glyph's first layer right by 10 units
if not glyph.layers:
continue
layer = glyph.layers[0]
for shape in layer.shapes:
shape.transform = QTransform().translate(10, 0)
changed_ids.add(glyph.id)
finally:
# Always unblock, even if the script errors partway through
ws.unblockUpdate()
# Notify FontLab about all the changes at once
flModel.notifyGlyphsChanged(changed_ids)
ws.updateActiveViewport()
# ============================================================
# 5. Export every open font to a folder
# ============================================================
# Note: exportCurrentFont() uses the settings from Font Info.
# For custom export options, use exportFont(pkg, ExportControl).
# for pkg in ws.packages():
# ws.currentPackage = pkg # make it active
# ws.exportCurrentFont()
# ============================================================
# 6. Access the active canvas and glyph
# ============================================================
canvas = ws.getActiveCanvas()
if canvas:
print(f"\nCanvas is active: {canvas.isActiveCanvas()}")
# The currentGlyph property tells you which glyph is in
# the editor right now
glyph_info = ws.currentGlyph
if glyph_info:
print(f"Currently editing: {glyph_info.name}")
else:
print("\nNo canvas is open — open a glyph window to get the canvas.")
# ============================================================
# 7. Switching tools at the end of a script
# ============================================================
# Good practice: leave the user in a sensible tool state
# after your script finishes. The node editor is usually
# the right choice.
ws.setToolEditor()
print("\nScript complete. Switched to Node Editor tool.")
Registering a Python tool
registerPythonTool(name, icon, object) -> int adds a tool to the palette/menu and returns a cleanup token. icon must be a PythonQt QIcon or None. unregisterPythonTool(token) -> bool removes the registered tool and deactivates it if necessary. Run both operations on the GUI thread.
The callback object can implement activate() and deactivate() with no arguments; mouse callbacks mousePressed(event, canvas), mouseMoved(event, canvas), mouseReleased(event, canvas) and mouseDoubleClicked(event, canvas); key callbacks keyPressed(event, canvas) and keyReleased(event, canvas); and paint(painter, canvas). Event callbacks receive borrowed Qt QMouseEvent/QKeyEvent wrappers, not flMouseEvent. Return a truthy value to consume an event, or false/None to allow normal processing. Painter coordinates are viewport coordinates.
import fontlab as fl
class ExampleTool:
def mousePressed(self, event, canvas):
print(event.pos())
return False
workspace = fl.flWorkspace.instance()
tool_token = workspace.registerPythonTool("Example Python tool", None, ExampleTool())
# Retain tool_token; later, during plugin/script cleanup:
workspace.unregisterPythonTool(tool_token)
The registry keeps the callback object alive while registered. Do not retain borrowed event/painter wrappers beyond their callbacks. Keep cleanup tokens and unregister before unloading a plugin. Callback errors are printed to Python output. The registration does not itself select the tool.
flWorkspace.RenderMode
Use the flWorkspace.RenderMode dictionary with subscription.
| Key | Native value | Description |
|---|---|---|
RenderIfActive |
flWorkspace::RenderMode::RenderIfActive |
Native enum value. |
RenderIfMaximized |
flWorkspace::RenderMode::RenderIfMaximized |
Native enum value. |
Constructors: flWorkspace() flWorkspace(flWorkspace) flWorkspace(flObject) flWorkspace(objId id) flWorkspace(QString title)
Native bases: object
Captured native MRO: flWorkspace, object
Native new allocation evidence (not an init overload): (args, *kwargs) Create and return a new object. See help(type) for accurate signature.
Supplemental documentation:
Workspace. The captured declaration exposes addPackage, closePackage, closeProject, createNewProject, readProject, saveProject, currentPackage, currentGlyph, packages, canvases, getActiveCanvas, setActiveCanvas, hasPackage, findPackageId, exportCurrentFont, exportFont, doZoomIn, doZoomOut, setRulers and isRulersEnabled. It is created with no captured constructor overloads. It also carries the shared object members changed, clone, cloneObject, getProperty, setProperty, release, remove and update and the shared attributes id, name, type, isValid and isNull.
Source: FontLab Proteus API documentation
Source: generated/fontlab.py: flWorkspace captured declaration
Complete member index
Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.
| Member | Kind | Signature | Summary |
|---|---|---|---|
RenderMode |
attribute | dict |
|
__init__ |
function | (self, /, *args: Any, **kwargs: Any) -> None |
Initialize self. (shared captured text) |
activateEditor |
function | (self, arg0: flVisualItem, canvas_pos: QPointF) -> Any |
Opens the full editor for a specific visual item at the given canvas position. |
activateNext |
function | (self) -> Any |
Switches focus to the next canvas in order — like pressing Ctrl+Tab to cycle through windows. |
activatePrev |
function | (self) -> Any |
Switches focus to the previous canvas. |
activeFontPanel |
attribute | Any |
The active (focused) font panel widget. |
activeTextMode |
attribute | Any |
The current text-editing mode (relevant in the Text/Metrics window). |
addFamilyMembers |
function | (self, match_subfamily: Any=...) -> bool |
Links multiple open fonts together as a family. |
addPackage |
function | (self, arg0: flPackage) -> Any |
Opens and registers a font package in the workspace, making it appear in the application. |
attachCanvas |
function | (self, arg0: flCanvas) -> Any |
Registers a new canvas with the workspace, making it part of the application's window management. |
blockUpdate |
function | (self, time: Any=...) -> Any |
Suppresses screen updates for time milliseconds. |
canvases |
function | (self) -> list[flObject] |
Returns all open canvas windows. |
changed |
function | (self) -> Any |
(shared captured text) |
checkInitHistoryState |
function | (self, history_ix: int) -> Any |
(shared captured text) |
clearAboveHistory |
function | (self, history_ix: int) -> Any |
(shared captured text) |
clearFlag |
function | (self, f: int) -> Any |
(shared captured text) |
clearFlags |
function | (self) -> Any |
(shared captured text) |
clone |
function | (self, *args: Any, **kwargs: Any) -> Any |
Clone the object (shared captured text) |
cloneObject |
function | (*args: Any, **kwargs: Any) -> Any |
(shared captured text) |
closePackage |
function | (self, arg0: flPackage) -> Any |
Closes a font package and removes it from the workspace. |
closeProject |
function | (self) -> Any |
Closes the current project. |
convertMouseEvent |
function | (self, QMouseEvent: Any, arg1: QPoint) -> flMouseEvent |
Converts a Qt mouse event into a FontLab mouse event. |
createNewProject |
function | (self) -> Any |
Creates a new empty project. |
createObject |
function | (*args: Any, **kwargs: Any) -> Any |
FlObject/Nothing createObject(int); (shared captured text) |
currentFontPanel |
attribute | Any |
The current font panel widget. |
currentGlyph |
attribute | Any |
Information about the glyph currently open in the glyph editor. |
currentHistoryState |
function | (self, *args: Any, **kwargs: Any) -> Any |
(shared captured text) |
currentPackage |
attribute | Any |
The currently active (foreground) font — the one whose window is in front. |
cursorId |
attribute | Any |
The current cursor shape displayed over the application. |
deactivateEditor |
function | (self) -> Any |
Closes the current editor mode, returning to the font window. |
defaultFontSize |
attribute | Any |
The default point size used when creating new text blocks in the Metrics or Text window. |
destroyCanvas |
function | (self, arg0: flCanvas) -> Any |
Closes and destroys a canvas window. |
doZoomIn |
function | (self, s: Any=...) -> Any |
Zooms into the active canvas by factor s. |
doZoomOut |
function | (self, s: Any=...) -> Any |
Zooms out of the active canvas by factor s. |
exportCurrentFont |
function | (self) -> Any |
Exports the currently active font using whatever export settings are configured in the Font Info → Export dialog. |
exportFont |
function | (self, arg0: flPackage, ExportControl: Any) -> Any |
Exports a specific font with explicit export options. |
exportTo |
function | (self, filename: str, format: str=...) -> bool |
Exports visible canvas content to a file. |
findPackageId |
function | (self, id: int) -> flPackage |
Finds an open font by its internal numeric ID. |
flObjectFlags |
attribute | dict |
(shared captured text) |
flag |
function | (self, f: int) -> Any |
(shared captured text) |
getActiveCanvas |
function | (self) -> Any |
FlCanvas/Nothing getActiveCanvas() |
getActiveTextBlock |
function | (self) -> Any |
FlTextBlockItem/Nothing getActiveTextBlock() |
getActiveTextBlockModel |
function | (self, *args: Any, **kwargs: Any) -> Any |
FlTextBlock/Nothing getActiveTextBlockModel(): model of the exact active text block |
getBoundingRect |
function | (self) -> QRectF |
Returns the bounding rectangle enclosing all content across open canvases. |
getCanvasForViewport |
function | (self, *args: Any, **kwargs: Any) -> Any |
FlCanvas/Nothing getCanvasForViewport(QWidget*) |
getCanvasUnderCursor |
function | (self) -> flCanvas |
Returns whichever canvas window the mouse cursor is currently hovering over. |
getProperties |
function | (self, *args: Any, **kwargs: Any) -> Any |
Get object's properties list (shared captured text) |
getProperty |
function | (self, *args: Any, **kwargs: Any) -> Any |
Get object property by 'key' or number (shared captured text) |
getPropertyFloat |
function | (self, *args: Any, **kwargs: Any) -> Any |
Get float object property by 'key' (shared captured text) |
getPropertyInt |
function | (self, *args: Any, **kwargs: Any) -> Any |
Get int object property by 'key' (shared captured text) |
guidelinesUpdater |
function | (self) -> flNotifier |
Returns the notifier that signals guideline changes. |
hasChanges |
attribute | Any |
(shared captured text) |
hasHistoryState |
function | (self, history_ix: int) -> Any |
(shared captured text) |
hasHistoryStates |
attribute | Any |
(shared captured text) |
hasPackage |
function | (self, flPackage: Any) -> bool |
Returns True if the given font is currently open. |
haveActiveEditor |
function | (self) -> bool |
Returns True if a glyph editor window is currently open and ready. |
haveObject |
function | (*args: Any, **kwargs: Any) -> Any |
(shared captured text) |
historyStates |
function | (self, accepted_state: bool) -> Any |
(shared captured text) |
id |
attribute | Any |
Object id (shared captured text) |
independedAll |
function | (self) -> Any |
(shared captured text) |
init |
function | (self) -> Any |
Initialises the workspace subsystem. |
initialHistoryState |
function | (self, *args: Any, **kwargs: Any) -> Any |
(shared captured text) |
instance |
function | () -> flWorkspace |
Returns the global workspace singleton — the FontLab application object. |
instanceType |
function | (*args: Any, **kwargs: Any) -> Any |
(shared captured text) |
isActiveCanvas |
function | (self, flCanvas: Any) -> bool |
Checks whether the given canvas is the currently active one. |
isChanged |
attribute | Any |
(shared captured text) |
isEqual |
function | (self, arg0: flObject) -> Any |
(shared captured text) |
isNull |
attribute | Any |
(shared captured text) |
isPresent |
attribute | Any |
(shared captured text) |
isReleased |
attribute | Any |
(shared captured text) |
isRulersEnabled |
function | (self) -> bool |
Returns True if rulers are currently visible. |
isValid |
attribute | Any |
(shared captured text) |
mainWindow |
attribute | Any |
The application's main window widget. |
name |
attribute | Any |
Object name (shared captured text) |
packages |
function | (self) -> list[flObject] |
Returns a list of all open font packages. |
paintBrush |
attribute | Any |
The active paint brush settings (used by ShapeBuilder brush tools). |
previewRender |
function | (self) -> bool |
Returns whether preview rendering is currently on. |
propertyNames |
function | (self, *args: Any, **kwargs: Any) -> Any |
PropertyNames(): sorted snapshot of dynamic property keys (shared captured text) |
readProject |
function | (self, QString: Any) -> bool |
Opens a project file from path. |
refCnt |
attribute | Any |
Object references count (shared captured text) |
registerPythonTool |
function | (self, *args: Any, **kwargs: Any) -> Any |
RegisterPythonTool(name, icon or None, object) -> token. |
release |
function | (self) -> Any |
(shared captured text) |
remove |
function | (self, *args: Any, **kwargs: Any) -> Any |
(shared captured text) |
removeChild |
function | (self, arg0: flObject) -> Any |
(shared captured text) |
resetToolCursor |
function | (self) -> Any |
Resets the cursor to the default arrow. |
restoreHistoryState |
function | (self, history_ix: int) -> Any |
(shared captured text) |
saveProject |
function | (self, *args: Any, **kwargs: Any) -> Any |
SaveProject([QString]) | bool saveProject(QString, QList<fgFont>, QString ui_state |
setActiveCanvas |
function | (self, arg0: flCanvas) -> Any |
Brings a specific canvas window to the front and makes it active. |
setActiveSketchboard |
function | (self) -> Any |
Switches to the Sketchboard canvas. |
setAutoMode |
function | (self) -> Any |
Lets FontLab automatically choose the most appropriate tool for the current context. |
setFlag |
function | (self, *args: Any, **kwargs: Any) -> Any |
(shared captured text) |
setFocusToCanvas |
function | (self, arg0: flCanvas) -> Any |
Sends keyboard focus to a canvas without necessarily bringing it to the front. |
setPreviewRender |
function | (self, bool: Any) -> Any |
Enables or disables preview rendering mode. |
setProperty |
function | (self, *args: Any, **kwargs: Any) -> Any |
Set object property by 'key' or number (shared captured text) |
setPropertyFloat |
function | (self, *args: Any, **kwargs: Any) -> Any |
Set float object property by 'key' (shared captured text) |
setPropertyInt |
function | (self, *args: Any, **kwargs: Any) -> Any |
Set int object property by 'key' (shared captured text) |
setRenderMode |
function | (self, RenderMode: Any) -> Any |
Sets the rendering mode for all canvases (e.g. outline, filled, preview). |
setRulers |
function | (self, enabled: bool) -> Any |
Shows or hides rulers. |
setToolBrush |
function | (self) -> Any |
Activates the Brush tool. |
setToolBucket |
function | (self) -> Any |
Activates the Paint Bucket tool. |
setToolCursor |
function | (self, CursorId: Any) -> Any |
Sets the cursor to a specific shape by CursorId constant. |
setToolEditor |
function | (self) -> Any |
Activates the Node/Contour editing tool — the standard editing mode for working with nodes. |
setToolEllipse |
function | (self) -> Any |
Activates the Ellipse drawing tool. |
setToolGuidelines |
function | (self) -> Any |
Activates the Guidelines tool. |
setToolKnife |
function | (self) -> Any |
Activates the Knife tool for cutting contours. |
setToolMagnet |
function | (self) -> Any |
Activates the Magnet (snap) tool. |
setToolMetrics |
function | (self) -> Any |
Activates the Metrics tool for adjusting spacing and kerning. |
setToolOptimizer |
function | (self) -> Any |
Activates the Optimizer tool. |
setToolPen |
function | (self) -> Any |
Activates the Pen tool for drawing new Bézier paths. |
setToolPencil |
function | (self) -> Any |
Activates the freehand Pencil tool. |
setToolRectangle |
function | (self) -> Any |
Activates the Rectangle drawing tool. |
setToolRotate |
function | (self) -> Any |
Activates the Rotate tool. |
setToolScale |
function | (self) -> Any |
Activates the Scale tool. |
setToolScissors |
function | (self) -> Any |
Activates the Scissors tool. |
setToolShape |
function | (self) -> Any |
Activates the Shape selection tool (selects whole shapes, not individual nodes). |
setToolSlant |
function | (self) -> Any |
Activates the Slant tool. |
setToolSmartPen |
function | (self) -> Any |
Activates the Smart Pen tool. |
setToolText |
function | (self) -> Any |
Activates the Text tool for inserting text strings. |
setToolTransform |
function | (self) -> Any |
Activates the Transform tool. |
showFocus |
function | (self) -> bool |
Returns whether the focus indicator is visible. |
showSmallItems |
function | (self) -> bool |
Returns whether small items (like tiny nodes) are shown. |
signedObjects |
attribute | Any |
A map of all "signed" (tracked/registered) objects in the workspace. |
sketchboard |
attribute | Any |
FlCanvas, bool new_paper |
tag |
function | (self, *args: Any, **kwargs: Any) -> Any |
(shared captured text) |
toolBarButtonStyle |
attribute | Any |
The visual style of toolbar buttons. |
turnTextModeOff |
function | (self) -> Any |
Exits text-entry mode in the metrics or text window, returning to normal editing. |
type |
attribute | Any |
Object type (shared captured text) |
uiState |
attribute | Any |
A serialized string representing the current window layout, panel positions, and UI configuration. |
unblockUpdate |
function | (self) -> Any |
Re-enables screen updates before the block time expires. |
unregisterPythonTool |
function | (self, token: Any) -> Any |
UnregisterPythonTool(token) -> bool. |
update |
function | (self) -> Any |
(shared captured text) |
updateActiveViewport |
function | (self) -> Any |
Forces an immediate redraw of the active viewport. |
weAreOnPaper |
function | (self) -> bool |
Returns True if the workspace is in Sketchboard (paper) mode. |