fontlab.flBasicTool
flBasicTool
Base class for editor tools.
What is flBasicTool?
Every tool in FontLab's toolbar — the Pointer, the Pen, the Knife, the Eraser, the Text tool — is an flBasicTool under the hood. This class defines the minimum interface that all canvas tools share: the ability to activate and deactivate, and an identifier for the cursor shape to display while the tool is active.
If you want to write a custom editor tool that handles mouse and keyboard events on the canvas, you subclass flBasicTool and implement event handler methods (mousePressEvent, mouseMoveEvent, keyPressEvent, etc.). You then receive flEvent objects in those methods describing exactly what the user did.
For most designers writing utility scripts, you will never create a tool — you call methods on model objects directly. But if you want a persistent tool that always lives in the toolbar and responds to drawing gestures in real time, flBasicTool is your starting point.
Tutorial
The most common scripting use of flBasicTool is activating a built-in tool programmatically. The tool instances are accessible through the workspace.
import fontlab as fl
# ============================================================
# List all available tools in the current workspace.
# Each tool is an flBasicTool subclass registered with the
# workspace tool manager.
# ============================================================
ws = fl.flWorkspace.instance()
tools = ws.tools # list of registered flBasicTool objects
print(f"Available tools ({len(tools)}):")
for tool in tools:
active = " [ACTIVE]" if tool == ws.currentTool else ""
print(f" {type(tool).__name__:30s} cursor={tool.cursorId}{active}")
# ============================================================
# Activate a specific tool by name.
# Replace 'flPointerTool' with the tool class you want.
# ============================================================
pointer = next((t for t in tools if 'Pointer' in type(t).__name__), None)
if pointer:
pointer.activateTool()
print(f"\nActivated: {type(pointer).__name__}")
else:
print("\nPointer tool not found.")
# ============================================================
# Subclassing example (not runnable in the scripting panel,
# but shows the structure for a real plugin):
# ============================================================
#
# class MyMeasureTool(fl.flBasicTool):
# def __init__(self):
# super().__init__()
# self._start = None
#
# def mousePressEvent(self, event):
# # Convert canvas click to glyph coordinates:
# canvas = fl.flWorkspace.instance().currentCanvas
# self._start = canvas.canvasToGlyph(event.origin)
#
# def mouseMoveEvent(self, event):
# if self._start and event.buttons:
# canvas = fl.flWorkspace.instance().currentCanvas
# current = canvas.canvasToGlyph(event.global)
# dx = current.x() - self._start.x()
# dy = current.y() - self._start.y()
# import math
# dist = math.hypot(dx, dy)
# print(f"Distance: {dist:.1f} units")
#
# my_tool = MyMeasureTool()
# fl.flWorkspace.instance().registerTool(my_tool)
# my_tool.activateTool()
Common Scripting Patterns
Activate the Pointer tool to return to normal editing mode
import fontlab as fl
ws = fl.flWorkspace.instance()
for tool in ws.tools:
if 'Pointer' in type(tool).__name__:
tool.activateTool()
break
Check which tool is currently active
import fontlab as fl
ws = fl.flWorkspace.instance()
current = ws.currentTool
if current:
print(f"Active tool: {type(current).__name__}")
print(f" Cursor ID: {current.cursorId}")
Inherited binding members: flObject.
Constructors: flBasicTool() flBasicTool(flObject) flBasicTool(flBasicTool)
Native bases: object
Captured native MRO: flBasicTool, 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:
A basic tool. The captured declaration exposes activateTool, deactivateTool, and the attributes cursorId, needDeactivateParent. 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: flBasicTool 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 |
|---|---|---|---|
__init__ |
function | (self, /, *args: Any, **kwargs: Any) -> None |
Initialize self. (shared captured text) |
activateTool |
function | (self) -> Any |
Switches the editor into this tool's mode. |
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) |
createObject |
function | (*args: Any, **kwargs: Any) -> Any |
FlObject/Nothing createObject(int); (shared captured text) |
currentHistoryState |
function | (self, *args: Any, **kwargs: Any) -> Any |
(shared captured text) |
cursorId |
attribute | Any |
The cursor shape to display when this tool is active. |
deactivateTool |
function | (self) -> Any |
Switches away from this tool, returning to the previously active tool (or the application's default tool). |
flObjectFlags |
attribute | dict |
(shared captured text) |
flag |
function | (self, f: int) -> Any |
(shared captured text) |
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) |
hasChanges |
attribute | Any |
(shared captured text) |
hasHistoryState |
function | (self, history_ix: int) -> Any |
(shared captured text) |
hasHistoryStates |
attribute | Any |
(shared captured text) |
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) |
initialHistoryState |
function | (self, *args: Any, **kwargs: Any) -> Any |
(shared captured text) |
instanceType |
function | (*args: Any, **kwargs: Any) -> Any |
(shared captured text) |
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) |
isValid |
attribute | Any |
(shared captured text) |
name |
attribute | Any |
Object name (shared captured text) |
needDeactivateParent |
attribute | Any |
If True, the tool's parent tool should be deactivated when this tool activates. |
propertyNames |
function | (self, *args: Any, **kwargs: Any) -> Any |
PropertyNames(): sorted snapshot of dynamic property keys (shared captured text) |
refCnt |
attribute | Any |
Object references count (shared captured text) |
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) |
restoreHistoryState |
function | (self, history_ix: int) -> Any |
(shared captured text) |
setFlag |
function | (self, *args: Any, **kwargs: Any) -> Any |
(shared captured text) |
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) |
tag |
function | (self, *args: Any, **kwargs: Any) -> Any |
(shared captured text) |
type |
attribute | Any |
Object type (shared captured text) |
update |
function | (self) -> Any |
(shared captured text) |