Ipelib
Lua bindings for Ipe

These are the Lua methods provided by the Ipe program itself. They are only available to Lua code running inside Ipe.

Application user interface

The application user interface object provides the GUI for the Ipe program.

-- model is a Lua table containing methods that will be called 
-- by the ui when events occur
ui = AppUi(model)

-- returns window id of window
-- (to be used as parent for dialogs)
id = ui:win()

ui:close()         -- close window

ui:setActionState(name, t) -- set whether action is checked 
t = ui:actionState(name)   -- is action checked?
-- return info about action: id, and whether it's always on 
id, alwaysOn = actionInfo(name)       

ui:explain(text)     -- show message in status bar for a few seconds
ui:setWindowTitle(caption)

-- make a tool visible or invisible
-- tool is one of "layers", "properties", "bookmarks", "notes"
-- t is true or false
ui:showTool(tool, t)

ui:setNotes(n)       -- set string for Notes tool


-- set contents of attribute selectors from style sheet
ui:setupSymbolicNames(styleSheet)

-- set attribute values displayed in user interface
-- 'attributes' table see below
ui:setAttributes(styleSheet, attributes)

-- set layer list from page
ui:setLayers(page, view)  

ui:setNumbers(?)
ui:setBookmarks(?)

-- page/view selector tool:
-- select one page and return page number (or nil if canceled)
pno = ui:selectPage(doc) 
-- select one view and return view number (or nil if canceled)
vno = ui:selectPage(doc, page_no)

ui:pageSorter(?)

ui:setClipboard(text)     -- store text on system clipboard
-- get text or bitmap property from system clipboard
-- if t is false, only text is retrieved
-- returns either a string or an image object.
obj = ipeui.clipboard(t)  

The following methods work on the canvas inside the UI:

ui:setPage(page, pgno, view, styleSheet) -- set page shown on canvas
ui:setSnap(snap)                    -- for 'snap' table see below
ui:setFontPool(p)       -- an opaque object obtained from an ipe.Document

-- 'pan' is a vector indicating the user coordinates at canvas center
v = ui:pan()       
ui:setPan(v)

zoom = ui:zoom()        -- a number
ui:setZoom(zoom)

v = ui:pos()            -- current mouse position, after snapping
v = ui:unsnappedPos()   -- current mouse position, before snapping
v = ui:simpleSnapPos()  -- same, but ignoring angular snap
v = ui:globalPos()      -- mouse position on screen

v, dpi = ui:canvasSize()  -- size of canvas in pixels, monitor resolution

ui:setNumbering(t)      -- true or false
ui:setFifiVisible(t)    -- true or false
ui:setSelectionVisible(t) -- true or false
ui:setPretty(t)         -- true or false

ui:setVisibleVariant(variant) -- which variant is shown in the canvas

-- setCursor only implemented on Qt.
-- Windows 8 switches to a dot cursor automatically when using the pen.
ui:setCursor(name)         -- name in "standard", "hand", "cross"
ui:setCursor(width, color) -- sets a colored dot cursor (on Qt)

ui:update()             -- update canvas and tool
ui:update(false)        -- update tool only
ui:finishTool()

ui:panTool()
ui:selectTool()
ui:transformTool()
ui:shapeTool()

Wait dialog

This dialog is for running an external program (that is, latex or a text editor). The dialog is modal, so that the program refreshes but otherwise waits for the running command.

ui:waitDialog(command, text)

Here, 'command' is a string that is passed to a shell to run the command. The argument 'text' appears in the dialog.

The behaviour is different on differen platforms:

  1. On Win32 and MacOS, the dialog has its own event loop. A thread is started for the command, and when the command terminates, the dialog is closed and the function returns with the value 'true'.
  2. On Qt, the dialog is modal, but lives on the main event loop. A thread is started for the command. If this thread terminates quickly (e.g. around 300ms), then the function immediately returns with value 'true'. Otherwise, the dialog appears, and the function immediately returns with value 'false'. In this case, the calling Lua code should yield to return to the main event loop. When the thread terminates, the method 'resumeLua' on the model of the ui object will be called to resume the incomplete action.
  3. On JS, the dialog is modal on the normal browser event loop. 'command' must be the name of a tex engine. The method now calls the 'runLatex' method on the JS 'window' object with the command as an argument. This method is supposed to be an async JS function that returns with a promise. The 'waitDialog' method immediately returns with value 'false'. The JS code that hosts the Ipe WASM libraries must ensure that when the promise is fulfilled, the 'resume' method in the JS bindings of the 'ui' is called. No additional threads are started by Ipelib.