Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
b872fe3
replace monolithic setup.py with pyproject.toml + scripts
samizdatco Jul 9, 2026
19809d0
bump minimum python version to 3.9
samizdatco Jul 9, 2026
3256a87
publish wheels containing the native extension
samizdatco Jul 9, 2026
18f985c
reflect test results in exit code
samizdatco Jul 9, 2026
d486a29
test for presence of pyobjc+extension, not just paths
samizdatco Jul 9, 2026
cafc691
fix regex escape
samizdatco Jul 10, 2026
62e9ca2
fix objc.super use in ConsoleScript
samizdatco Jul 10, 2026
665bc57
fix `ordered()` crash on grobs and silent dotted-path failures
samizdatco Jul 10, 2026
3f69b4c
add python 3.14 support by bumping pyobjc to 11.1
samizdatco Jul 10, 2026
3639d49
ignore rsrc files resulting from in-place build
samizdatco Jul 10, 2026
dc2ac7f
generate MANIFEST.in only when needed for sdist
samizdatco Jul 10, 2026
cb696af
rename build.py to make.py (to prevent `-m build` shadowing)
samizdatco Jul 10, 2026
46052ee
opt into secure restorable state
samizdatco Jul 10, 2026
ddab30c
update embedded python to 3.14.6
samizdatco Jul 10, 2026
f8ca3c8
update python version compat
samizdatco Jul 10, 2026
7df6d3b
update 1.0.1 docs
samizdatco Jul 11, 2026
ef7093a
bump copyright year
samizdatco Jul 11, 2026
2f58879
fix typos
samizdatco Jul 11, 2026
e0e6d59
add missing 3.14 classifier
samizdatco Jul 11, 2026
00d7e22
use system fonts in typography tests
samizdatco Jul 11, 2026
6363a2a
fixed Text.flow() when invoked w/ callback
samizdatco Jul 11, 2026
30f574f
fix the test for blend-only effects
samizdatco Jul 11, 2026
e4b666a
fix MagicNumber's numeric-protocol implementation
samizdatco Jul 11, 2026
41556e2
fix rasterization of clipping masks based on vector images
samizdatco Jul 13, 2026
318b8d9
add clip() test cases that use canvas transforms
samizdatco Jul 13, 2026
e5b8d1b
replace deprecated WebView with WKWebView
samizdatco Jul 13, 2026
79b7051
update document contents after each edit
samizdatco Jul 13, 2026
bbff6e9
fix license format
samizdatco Jul 13, 2026
74fc923
rename `sync_edits` and `flash_menu` methods
samizdatco Jul 13, 2026
293f85a
add new default editor theme
samizdatco Jul 13, 2026
5280134
add `Assets.car` for macOS 26+ icon
samizdatco Jul 14, 2026
43e2599
Replace setup.py with direct call to tests
samizdatco Jul 14, 2026
cf15d6e
handle quadratic curves in `path_to_polygon`
samizdatco Jul 14, 2026
8315113
Add logo banner to readme
samizdatco Jul 14, 2026
0226c2b
Fix deprecation warning from pyobjc
samizdatco Jul 14, 2026
2e5635e
update module providing UTType*
samizdatco Jul 14, 2026
a119caf
set exit code on script errors when running `plotdevice` headless
samizdatco Jul 14, 2026
8338229
replace `xrange` with `range` in code samples
samizdatco Jul 14, 2026
1773ce0
update markdown docs
samizdatco Jul 14, 2026
ac940c6
fix crash when canvas is zoomed before script has rendered
samizdatco Jul 15, 2026
73471c5
upgrade vendored ace.js to 1.44.0
samizdatco Jul 13, 2026
40164de
local ace modification: filter autocompletions
samizdatco Jul 14, 2026
3846f3a
local ace modification: fix snippet formatting
samizdatco Jul 15, 2026
8ca98b3
rough draft: add command-click documentation lookups
samizdatco Jul 14, 2026
f68126d
Add links to the documentation for all known symbols
samizdatco Jul 14, 2026
81318c4
add usage samples
samizdatco Jul 14, 2026
41ca645
reformat
samizdatco Jul 14, 2026
4daf9a3
ensure only actual function tokens have clickable docs
samizdatco Jul 14, 2026
87f9178
Add tooltips with syntax reference for plotdevice symbols
samizdatco Jul 15, 2026
b22781b
remove command-click docs (but keep tooltip links)
samizdatco Jul 15, 2026
a94fec7
add context menu for opening docs
samizdatco Jul 15, 2026
97474d7
add () to token name in View Docs context menu
samizdatco Jul 15, 2026
e53ec91
clean up usage strings
samizdatco Jul 15, 2026
86cedbf
fix refreshdoc command mishandling an empty source string
samizdatco Jul 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add context menu for opening docs
  • Loading branch information
samizdatco committed Jul 15, 2026
commit a94fec77e4fe10fa770a97366d21bebd2981690e
28 changes: 25 additions & 3 deletions app/Resources/ui/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ var Editor = function(elt){
ed.hoverTooltip.setDataProvider(that._sampleHover)
ed.hoverTooltip.addToEditor(ed)

// keep the native side informed of which documented symbol (if any) is
// under the pointer and/or text cursor, so the right-click context menu
// can offer a "View Documentation" item
that._docTarget = {mouse: null, caret: null}
ed.on("changeSelection", that._trackDocTarget)
ed.on("nativecontextmenu", that._trackDocTarget)

// configure the buffer
sess = ed.getSession()
sess.setMode("ace/mode/plotdevice");
Expand Down Expand Up @@ -115,10 +122,25 @@ var Editor = function(elt){

_isBindingTarget:function(token){
// spot locations where a term is being used as a kwarg (or other assignment), so we can
// exclude it from the usage-sample tooltip (since it would only coincidentally share
// the name of a documented function in that case)
// exclude it from the usage-sample tooltip and doc-target tracking (since it would only
// coincidentally share the name of a documented function in that case)
return !!token && (token.type === "variable.parameter" || token.type === "variable.assignment")
},
_trackDocTarget:function(e){
// find the symbol currently under the mouse (if e is defined) or the insertion point (if not)
let coords = e?.domEvent
let pos = coords ? ed.renderer.screenToTextCoordinates(coords.clientX, coords.clientY) : ed.getCursorPosition()
var token = sess.getTokenAt(pos.row, pos.column)
var word = token && token.value

// if there's documentation for it (and it's changed since the last event), relay it to the pyobjc side
var url = (!that._isBindingTarget(token) && word && PLOTDEVICE_SYMBOL_DOCS[word]) || null
let inputType = coords ? "mouse" : "caret"
if (url !== that._docTarget[inputType]?.url){
that._docTarget[inputType] = url ? {word, url} : null
app.setDocTarget(that._docTarget)
}
},
_sampleHover:function(e, editor){
var pos = e.getDocumentPosition()
var token = sess.getTokenAt(pos.row, pos.column)
Expand All @@ -141,7 +163,7 @@ var Editor = function(elt){
more.className = "ace_symbol-doc-more"
more.style.color = getComputedStyle(dom).color
var moreText = document.createElement("span")
moreText.textContent = "read more…"
moreText.textContent = "view documentation…"
more.appendChild(moreText)
more.addEventListener("click", function(){ app.openDoc(url) })
tooltip.appendChild(more)
Expand Down
54 changes: 40 additions & 14 deletions plotdevice/gui/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
def args(*jsargs):
return ', '.join([json.dumps(v, ensure_ascii=False) for v in jsargs])

def menu_index_of(menu, identifier):
# NSMenu has no indexOfItemWithIdentifier_ in this AppKit/PyObjC version; search manually
for i, item in enumerate(menu.itemArray()):
if item.identifier() == identifier:
return i
return -1

class DraggyWebView(WKWebView):
def draggingEntered_(self, sender):
pb = sender.draggingPasteboard()
Expand Down Expand Up @@ -51,21 +58,35 @@ def willOpenMenu_withEvent_(self, menu, event):
for item in list(menu.itemArray()):
if item.identifier() not in keep:
menu.removeItem_(item)
inspect = menu.indexOfItemWithIdentifier_('WKMenuItemIdentifierInspectElement')
if inspect > 0:

# read _doc_target to get the tokens currently targeted by the mouse and caret
# then choose which one to offer a View Docs menu item for based on the event type
targets = getattr(self.owner, '_doc_target', None) or {}
if event.type() == NSEventTypeKeyDown else 'mouse')
if target:
idx = menu_index_of(menu, 'WKMenuItemIdentifierInspectElement')
idx = idx if idx >= 0 else menu.numberOfItems()
if menu.numberOfItems() > 0:
menu.insertItem_atIndex_(NSMenuItem.separatorItem(), idx)
idx += 1
prefix = u"View Documentation: "
title = prefix + target['word']
base_font = NSFont.menuFontOfSize_(0)
mono_font = NSFont.monospacedSystemFontOfSize_weight_(base_font.pointSize(), -0.8)
attr_title = NSMutableAttributedString.alloc().initWithString_attributes_(title, {"NSFont":base_font})
attr_title.addAttribute_value_range_("NSFont", mono_font, (len(prefix), len(target['word'])))
doc = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(title, "viewDocumentation:", "")
doc.setAttributedTitle_(attr_title)
doc.setTarget_(self)
doc.setRepresentedObject_(target['url'])
menu.insertItem_atIndex_(doc, idx)

inspect = menu_index_of(menu, 'WKMenuItemIdentifierInspectElement')
if inspect >= 0:
menu.insertItem_atIndex_(NSMenuItem.separatorItem(), inspect)

# TODO: once a doc viewer exists, add a lookup-ref menu item pointing to it:
# word = self.js('editor.selected')
# _ns = ['curveto', 'TEXT', 'BezierPath', ...]
# def ref_url(proc):
# if proc in _ns:
# return proc
# if ref_url(word):
# doc = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(u"Documentation for ‘%s()’"%word, "copy:", "")
# sep = NSMenuItem.separatorItem()
# items.insert(0, sep)
# items.insert(0, doc)
def viewDocumentation_(self, sender):
self.owner.openDoc(sender.representedObject())


class EditorView(NSView):
Expand All @@ -89,6 +110,7 @@ def awakeFromNib(self):
ucc.addUserScript_(shim)

self.webview = DraggyWebView.alloc().initWithFrame_configuration_(self.bounds(), config)
self.webview.owner = self
if dev and self.webview.respondsToSelector_('setInspectable:'):
self.webview.setInspectable_(True)
self.webview.setValue_forKey_(False, 'drawsBackground')
Expand Down Expand Up @@ -159,7 +181,7 @@ def webViewWebContentProcessDidTerminate_(self, sender):
def userContentController_didReceiveScriptMessage_(self, ucc, msg):
body = msg.body()
fn, fnargs = body['fn'], list(body.get('args', []))
if fn in ('sync_edits', 'flash_menu', 'setSearchPasteboard', 'cancelRun', 'loadPrefs', 'openDoc'):
if fn in ('sync_edits', 'flash_menu', 'setSearchPasteboard', 'cancelRun', 'loadPrefs', 'openDoc', 'setDocTarget'):
getattr(self, fn)(*fnargs)

def resizeSubviewsWithOldSize_(self, oldSize):
Expand Down Expand Up @@ -333,6 +355,10 @@ def loadPrefs(self):
def openDoc(self, url):
NSWorkspace.sharedWorkspace().openURL_(NSURL.URLWithString_(url))

@objc.python_method
def setDocTarget(self, target):
self._doc_target = target

def cancelRun(self):
# catch command-period even when the editor is first responder
mm=NSApp().mainMenu()
Expand Down
2 changes: 1 addition & 1 deletion plotdevice/lib/cocoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
NSChangeRedone, NSChangeUndone, NSClipView, NSClosePathBezierPathElement, NSColor, NSColorSpace, \
NSCommandKeyMask, NSCompositeCopy, NSCompositeSourceOver, NSContentsCellMask, NSCriticalAlertStyle, NSCursor, \
NSCurveToBezierPathElement, NSDeviceCMYKColorSpace, NSDeviceIndependentModifierFlagsMask, NSDeviceRGBColorSpace, NSDocument, \
NSDocumentController, NSDragOperationCopy, NSFindPboard, NSFixedPitchFontMask, NSFocusRingTypeExterior, NSFont, \
NSDocumentController, NSDragOperationCopy, NSEventTypeKeyDown, NSFindPboard, NSFixedPitchFontMask, NSFocusRingTypeExterior, NSFont, \
NSFontDescriptor, NSFontManager, NSForegroundColorAttributeName, NSGIFFileType, NSGradient, \
NSGraphicsContext, NSGraphiteControlTint, NSImage, NSImageCacheNever, NSImageCompressionFactor, \
NSImageInterpolationHigh, NSItalicFontMask, NSJPEGFileType, NSJustifiedTextAlignment, \
Expand Down