canvas::edit::points(3tk)
π canvas::edit::points π
okay so bestie, welcome to canvas::edit::points from the canvas::edit family β the Tk manual page that lives under "Variations on a canvas", section 3tk. this is part 1 and it's a lot, so grab a snack π.
β¨ NAME β¨
canvas::edit::points β editing a cloud of points on a canvas π
πΈ SYNOPSIS πΈ
package require Tcl 8.5
package require Tk 8.5
package require canvas::edit::points ?0.3?
::canvas::edit points objectName canvas options...
objectName destroy
objectName enable
objectName disable
objectName active
objectName add x y
objectName clear
activeCmd editorObj id
createCmd canvas x y
dataCmd add editorObj id x y
dataCmd remove editorObj id
dataCmd move start editorObj id
dataCmd move delta editorObj id x y dx dy
dataCmd move done editorObj id
like. look at that command list. it's giving full service π
π¦ DESCRIPTION π¦
so this package hands you a class, and instances of that class handle editing a whole cloud of point markers on a canvas. you can configure the instances for how the markers look β the whole visual appearance situation β¨. but here's the key thing, no cap: instances do not store the edited points themselves. nope. they delegate that job to a configurable object. so the editor is the vibe, the storage is somebody else's problem π«Ά
π INTERACTION π
the default bindings let you create, remove and drag points (markers) with mouse buttons 1, 2 and 3. specifically:
- clicking anywhere with button 1 adds a new point.
- clicking on a point with button 2 removes that point.
- clicking on a point with button 3 starts a drag operation, and that drag ends when you release the button.
the option -drag-point is how you change which button kicks off drag operations. and heads up β the option value isn't just the button number. it can also carry a modifier prefix, separated from the button by a dash -. the modifiers that get recognized are Control, Shift, and Alt.
the option -add-remove-point is how you change the button used to add/remove points. why does one option do both? because removal is an item binding while adding is canvas global, that's why π. and yeah, this option recognizes the exact same button syntax as -drag-point.
in the standard configuration, the canvas item that represents a point is a circle, configured with the appearance options -color, -hilit-color, and -radius. their defaults are Skyblue2, red, and 3, respectively. cute, right? π
want to tweak it a lil? the option -kind lets you slightly customize the canvas item to any kind that accepts the item options -width, -outline, -fill, and -activefill.
for more extensive customization you gotta configure a creation callback with the option -create-cmd. that callback takes the canvas and the x. y coordinates as arguments, in this order, and it's expected to return a list of the canvas items that represent the point.
note the plural π. with that callback you can visualize a single point using a whole group of items. iconic.
further note: when the callback returns an empty list, no point gets created. which means the callback can also do checks β is a point at this given location even desirable, or not? and you can combine that with the default creation behaviour, because the option can be queried, and its default value is the callback for the default behaviour. yes bestie, the default is a callback. keep up π
staying on callbacks for a sec: the option -active-cmd sets a callback that gets invoked whenever the mouse is over one of the created points, i.e. when it's active. this is how you drive derived displays β for example, highlighting that point's entry in a table or some other widget. main character energy for your UI π
the last option of importance is -tag. its value is the name of the canvas tag used to mark all the items owned β created and managed β by an instance. the default is POINT.
when you attach multiple instances of this behaviour to the same canvas, each instance has to be configured with a unique tag, otherwise they'll interfere with each other. no sharing tags, bestie, that's a situationship π
π CLASS API π
::canvas::edit points objectName canvas options...β this, the class command, creates and configures a brand new instance of a point cloud editor named objectName. the instance gets connected to the canvas widget you specify.
the result of the command is the fully qualified name of the instance command.
the options it accepts, and their values, are explained in the Options section. (that's coming, hold on π)
π INSTANCE API π
instances of the point cloud editors give you this API:
objectName destroyβ this method destroys the point cloud editor and releases all its internal resources.
important: this operation does not destroy the items of the point markers the editor managed on the attached canvas, and it doesn't destroy the canvas itself either. it's a breakup, not a house fire π«Ά
the result of the method is an empty string.
objectName enableβ this method activates editing of the point cloud on the canvas. this is the default after instance creation. if the editor is already active, the call just gets ignored, no drama.
the result of the method is an empty string.
the complementary method is disable. the interrogatory method for the current state is active.
objectName disableβ this method disables editing of the point cloud on the canvas. if the editor is already disabled, the call gets ignored.
the result of the method is an empty string.
the complementary method is enable. the interrogatory method for the current state is active.
objectName activeβ this method queries the editor state.
the result of the method is a boolean value: true if the editor is active, and false otherwise, i.e. disabled.
the methods to change the state are enable and disable.
objectName add x yβ this method programmatically creates a point at the specified location.
the result of the method is an empty string.
note that this method goes through the whole set of callbacks invoked when the user interactively creates a point β that's -create-cmd, and, more importantly, -data-cmd.
this is the method through which you load pre-existing points into an editor instance. β
objectName clearβ this method programmatically removes all points from the editor.
the result of the method is an empty string.
note that this method goes through the same callback invoked when the user interactively removes a point, i.e. -data-cmd.
okay that's where this part runs out β the page keeps going, and so do we ππ
β¨ OPTIONS β¨
okay so the class command? it takes options. all of them. and bestie, we are going through every single one π«Ά
-active-cmdcommand-prefix β this is a command prefix your editor invokes when the mouse enters or leaves a point that this instance is managing.
if you don't set it, it defaults to an empty command that does literally nothing. no cap.
the signature of this command prefix is:
activeCmd editorObj id- the id identifies the point within the editor.
- an empty id means the last entered point was left. π
- the result of this method is ignored.
-add-remove-pointeventspec β the value is an event specification (without bracketing angles, iykyk) declaring which event triggers adding and removing a point.
β οΈ this option can only be set at construction time. set it later and it's not happening.
the default setup uses different events for adding vs removing, ButtonPress-1 and ButtonPress-2 respectively.
when you use this option, the same event is used for both operations. and that's genuinely fine, because adding is bound as a canvas-global event while removal is bound to the relevant canvas items. slay π
-colorcolorspec β the fill color for the default item created when adding a point, and no-create-cmdis specified.
the default value is SkyBlue2. π¦
-create-cmdcommand-prefix β a command prefix the editor invokes when it has to create a new point.
so technically you can set this after construction, but the recommendation is to only use this feature as a way to insert custom processing at creation time which remembers and calls the previous value of the option. don't be weird about it.
if not specified, it defaults to a command that creates a black-bordered blue circle of radius 3 centered on the location of the new point.
the signature of this command prefix is:
createCmd canvas x y- the result of the command prefix must be a list of the canvas items it created to represent the marker. π and note bestie: the visual representation of a "point" may consist of multiple canvas items in an arbitrary shape.
- the returned list of items is allowed to be empty, and that's taken as a signal that the callback vetoed the creation of the point. π«
-data-cmdcommand-prefix β a command prefix the editor invokes when a point was edited in some way. this is how the editor delegates the actual storage of point information to an outside object. main character energy honestly.
β οΈ this option can only be set at construction time.
if not specified it defaults to an empty string and is ignored by the editor, i.e. not invoked.
the signatures of this command prefix are:
dataCmd add editorObj id x y- invoked when a new point was added to the instance, either interactively or programmatically. (see instance method
addfor the programmatic route.) - the id identifies the point within the editor and will be used by the two other callbacks to specify which point to modify.
- the last two arguments x and y specify the location of the new point in canvas coordinates.
- the result of this method is ignored.
- invoked when a new point was added to the instance, either interactively or programmatically. (see instance method
dataCmd remove editorObj id- invoked when a point was removed from the editor instance.
- the id identifies the removed point within the editor.
- the result of this method is ignored.
dataCmd move start editorObj id- invoked when the movement of a point in the editor instance has started.
- the id identifies the point within the editor that's about to be moved.
- the result of this method is ignored.
dataCmd move delta editorObj id x y dx dy- invoked when the point moved in the editor instance.
- the id identifies the moved point within the editor, and the remaining arguments x, y, dx, and dy provide the new absolute location of the point, and the full delta to the original location.
- at the time of the calls the system is not committed to the move yet. only after method
move donewas invoked and has accepted or rejected the last position will the editor update its internal data structures, either committing to the new location or rolling the move back to the original one. - given that, the location data provided here should be saved only in temporary storage until then. π«£
- the result of this method is ignored.
dataCmd move done editorObj id- invoked when the movement of a point in the editor instance is complete.
- the id identifies the moved point within the editor.
- the result of this method must be a boolean value. if the method returns false the move is vetoed and rolled back. π
-drag-pointeventspec β an event specification (without bracketing angles) declaring which event triggers a drag action on points.
β οΈ this option can only be set at construction time.
the default specification is ButtonPress-3. π₯
-hilit-colorcolorspec β the highlight color for the default item created when adding a point, and no-highlight-cmdis specified.
the default value is red. π
-kindname β the canvas item type for the default item created when adding a point, and no-create-cmdis specified. only item types specified through a bounding box are suitable, so like, keep that in mind.
the default value is oval. β
-radiusint β the radius for the default item created when adding a point, and no-create-cmdis specified.
the default value is 3.
-tagstring β the name of the canvas tag with which to identify all items of all points managed by the editor.
β οΈ this option can only be set at construction time.
if not specified it defaults to POINT. π
π BUGS, IDEAS, FEEDBACK π
okay so, real talk: this document and the package it describes will undoubtedly contain bugs and other problems. it's giving humble, but it's also giving honest. π
please report such in the category canvas of the Tklib Trackers at http://core.tcl.tk/tklib/reportlist.
and please also report any ideas for enhancements you may have for either the package and/or the documentation. we want them fr fr. π
π KEYWORDS π
canvas, editing, point cloud, points
that's the whole page bestie!! you now know canvas::edit::points better than it knows itself π¦β¨ this beauty lives in tklib version 0.3, page canvas::edit::points(3tk) β go forth and edit those point clouds, you absolute icon ππ
π¦ where this page comes from
- debian trixie: tklib 0.9-1
- ubuntu questing: tklib 0.9-1
- ubuntu resolute: tklib 0.9-1build1
- ubuntu stonking: tklib 0.9-1build1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms