One way to enhance a package is to add to Maple's context-sensitive menus  some new menu entries which utilize that package's features.

In Maple's Standard GUI, context-sensitive menus (a.k.a. context-menus) appear when the mouse is right-clicked over (input or output) 2D Math expressions.

For a package implemented as a module, new and relevant context-menu entries can be created inside the module's ModuleLoad export. That will cause the new menu entries to be created (automatically) upon the first invocation or use of the package.

Moreover, such new context-menu entries can be configured so as to only appear under specific circumstances -- such as when the package is loaded (using with).

The following is an example. Note that running this code will create a file named myp.mla in one's home directory/folder.

restart:

mypackage := module()
option package;
export _pexports, f, ModuleLoad;
local pCM;

  ModuleLoad := proc()
    pCM := ContextMenu:-CurrentContext:-Copy():
    pCM:-Queries:-Add(
      "Is mypackage Loaded",
      proc()
        member( :-mypackage, packages() );
      end proc);
    pCM:-Entries:-Add("f",
            ":-mypackage:-f(%EXPR)",
            'Matrix(square)',
            'operator'=Typesetting:-mover(Typesetting:-mo("→"),
                                          Typesetting:-mi("f")),
            'active'="Is mypackage Loaded",
            'category'="Category 1",
            'helpstring'="apply f to Matrix",
            'submenu'=["mypackage"]
           );
    ContextMenu:-Install(pCM);
  end proc;

  f := proc(M)
    LinearAlgebra:-Determinant(M);
  end proc;

  _pexports := () -> [ op( { exports( mypackage ) } minus
                           { ':-_pexports', ':-ModuleLoad' } ) ];

end module:

FileTools:-Remove(cat(kernelopts(homedir),"/myp.mla")):
LibraryTools:-Create(cat(kernelopts(homedir),"/myp.mla")):

libname:=kernelopts(homedir),libname:
savelib('mypackage');

restart:
libname:=kernelopts(homedir),libname:

# Without the package loaded, its menus aren't present.
# Right-click on the Matrix output below.
A := Matrix([[1,2],[3,9]]);

# With the package loaded, its menus appear.
# Right-click on the Matrix output below.
with(mypackage);
A;

Here are a  few of the options to the Entries:-Add routine (an export of a context-menu module, see the ?ContextMenu[CurrentContext][Entries][Add] help-page):

  • 'helpstring' optionally designates what appears as tooltip help when the mouse cursor hovers over a context-menu item. (Those are only visible when Menu Tips are enabled in the Interface tab under Tools->Options.)
  • 'operator' optionally designates what appears between output when the context-menu action is performed in a Document (not Worksheet).
  • 'active' optionally denotes whether a "query" (added separately, in the above code) will determine whether the menu entry will appear.

acer


Please Wait...