Adept Scientific - English
The world's best software for research, science and engineering.
flag arrow
clearclear

 Adept Store | register Join My Adept | Flags  
Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055  
UKusdedksvnofi
Home
Products
Training
Events
 Buy Online
Downloads
Education
Support
My Adept
International |  About Us |  Contact Us |  Press Room |  Jobs
The Maple Reporter Online

Build Your Own Context-Sensitive Menu

Every new application comes with a learning curve. Maplesoft is going to great lengths to assist novice users in making this learning curve as short as possible. You’ve seen how easy it is to build a graphical user interface to access the Maple kernel using the Maplets package. Do you know that you can build your own context-sensitive menu just as easily using the context package? A context-sensitive menu associates Maple output expressions with specific Maple actions. Once an action is selected, not only is the action performed on the expression, but the Maple routine is also displayed to show users the corresponding Maple command. When the full expression is selected the context package is used for the creation and maintenance of procedures that generate a context-sensitive menu.

In this article, we will build a simple context-sensitive menu to some of the routines in the Student[Calculus1] package. Specifically, this menu will allow users to ask Maple for a hint, undo a rule or apply the product rule to differentiation problems..

> with(context);        

[buildcontext, clearlabels, defaultcontext, display, installconext, restoredefault, testactions, troubleshoot]

Context-sensitive menus are built using classes. A class requires a unique name for the menu, a Boolean statement that will test expressions for membership in this class, and an explanation of what this class contains. In the following example, the unique name is “Differentiate”. The Boolean statement tests if an expression is in the inert differentiation form. This is required to access the routines from within the Student[Calculus1] package. A second test is performed to verify if a hint can be applied to the problem. This is needed to invoke the context-sensitive menu on expressions that are incomplete while in the single-stepping process. The description for this menu is, “Interface to Student[Calculus1]”.

Once the class has been defined, you need to design the menu items with respective actions, called CF_ACTION. CF_ACTION definitions require the following entries:

MenuString
The string that appears in the context-sensitive menu.
HelpString
The text that appears in the bubble help
CodeType
The type of action.
Code
The action that will be invoked once selected.
> CMCalc:=
	CF_CLASS(
	 "Key" = "Differentiate",
	 "Test" = "type(f, specfunc(anything, Diff))
	or evalb(Student:-Calculus1:-Hint(f)<>[NULL])",
	 "Description" = "Interface to Student[Calculus1]",

		CF_ACTION(
			"MenuString" = "Hint",
			"HelpString" = "Ask for a hint",
			"CodeType" = "complete",
			"Code" = "Student:-Calculus1:-Hint(f)"),

		CF_ACTION(
			"MenuString" = "Undo",
			"HelpString" = "Undo the previous rule",
			"CodeType" = "complete",
			"Code" = "Student:-Calculus1:-Undo(f)"),

		CF_ACTION(
			"MenuString" = "Product Rule",
			"HelpString" = "Apply the Product Rule",
			"CodeType" = "complete",
			"Code" = "if nops([Student:-Calculus1:-Rule
		[product](f), Student:-Calculus1:-GetMessage()])=1 then
					Student:-Calculus1:-Rule[product](f)
				else
					`Product Rule is not applicable` end if:")
		):

The last action requires a procedure as the Code. This procedure verifies if the product Rule is applicable to this expression. If not, an error message will display.

Now that the context-sensitive menu definition is complete, we need to build the menu.

> CM := buildcontext(CMCalc):        

Install the context-sensitive menu.

> installcontext(CM):        

Now let's try it out. Right click on the output to display the menu.

> Diff(sin(x)*cos(x), x);

> if nops([Student:-Calculus1:-Rule[product](Diff(sin(x)*x,x)),
	  Student:-Calculus1:-GetMessage()]) = 1 then Student:-Calculus1:-
	  Rule[product](Diff(sin(x)*x,x)) else `Product Rule is not
	  applicable` end if;

> R2 := Student:-Calculus1:-Hint(Diff(sin(x)*cos(x),x));       
				R2 := [product]

Installing your context-sensitive menu, temporarily disables the default menus. Restoring the default menus is done with the restoredefault command.

> restoredefault();  

For more information, to edit the default context-sensitive menu, or to see the advanced options available in the context package, visit Maple’s Help page by entering ?context at the Maple prompt.

Article: Build Your Own Context-Sensitive Menu

 
The Next Steps

Contact the Maple Team

Buy Maple Now

View Maple Pricing

Download a Brochure

Request a Brochure

Download a Demo

Request a Demo



In This Issue:

Introducing Maplesoft
Maple T.A. Makes Online
testing and Assignments
Easy

Calc I Maplets
Student Linear Algebra
High School PowerTools
Dynamical Systems are
No Match for This High
School Senior

Maple in Japan
Four New Books Reviewed
Build Your Own Context-
Sensitive Menu

MSW 2003 - Maple
Summer Workshop

Application Center Highlights
Maple Resources Guide

Learn more about Maple

Maple 8 Overview
Maple 8 functionality
MapleNet

Reinvent how you explore, teach and share mathematics.
Explore...
Teach...
Share...
System Requirements

Maple Service & Support

Maple Primes
  • Login to MaplePrimes
  • What is MaplePrimes
  • What is EMP
  • What is Maplets
  • How to get access to
Maple Primes

Application Centre
Powertools
Maple User Group (MUG)
Join the Maple User Group
(MUG)

Search the Knowledge Base
Technical Support request

adept

Top of the Page

Our Privacy and Terms and Conditions Statement
All Trademarks Recognised. Copyright © 2008, Adept Scientific plc.
Site designed and maintained by Adeptise

Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055