[system] / trunk / pg / macros / parserPopUp.pl Repository:
ViewVC logotype

Annotation of /trunk/pg/macros/parserPopUp.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5373 - (view) (download) (as text)

1 : dpvc 5371 loadMacros('MathObjects.pl','contextString.pl');
2 : dpvc 3723
3 :     Context("Numeric");
4 :    
5 :     sub _parserPopUp_init {}; # don't reload this file
6 :    
7 : gage 4997 =head1 DESCRIPTION
8 :    
9 : dpvc 5373 ####################################################################
10 :     #
11 :     # This file implements a pop-up menu object that is compatible
12 :     # with Value objects, and in particular, with the MultiPart object.
13 :     #
14 :     # To create a PopUp object, use
15 :     #
16 :     # $popup = PopUp([choices,...],correct);
17 :     #
18 :     # where "choices" are the strings for the items in the popup menu,
19 :     # and "correct" is the choice that is the correct answer for the
20 :     # popup.
21 :     #
22 :     # To insert the popup menu into the problem text, use
23 :     #
24 :     # BEGIN_TEXT
25 :     # \{$popup->menu\}
26 :     # END_TEXT
27 :     #
28 :     # and then
29 :     #
30 :     # ANS($popup->cmp);
31 :     #
32 :     # to get the answer checker for the popup.
33 :     #
34 :     # You can use the PopUp menu object in MultiPart objects. This is
35 :     # the reason for the pop-up menu's ans_rule method (since that is what
36 :     # MultiPart calls to get answer rules).
37 :     #
38 : dpvc 3723
39 : gage 4997 =cut
40 :    
41 : dpvc 3723 sub PopUp {parserPopUp->new(@_)}
42 :    
43 :     #
44 :     # The package that implements pop-up menus
45 :     #
46 :     package parserPopUp;
47 :     our @ISA = qw(Value::String);
48 :    
49 :     sub new {
50 :     my $self = shift; my $class = ref($self) || $self;
51 :     my $choices = shift; my $value = shift;
52 :     Value::Error("A PopUp's first argument should be a list of menu items")
53 :     unless ref($choices) eq 'ARRAY';
54 :     Value::Error("A PopUp's second argument should be the correct menu choice")
55 :     unless defined($value) && $value ne "";
56 :     my $oldContext = main::Context();
57 :     my $context = $main::context{String}->copy;
58 :     main::Context($context);
59 :     $context->strings->add(map {$_=>{}} @{$choices});
60 :     my $self = bless Value::String->new($value), $class;
61 :     $self->{isValue} = 1; $self->{choices} = $choices;
62 :     $self->{context} = $context;
63 :     main::Context($oldContext);
64 :     return $self;
65 :     }
66 :    
67 :     sub menu {
68 :     my $self = shift;
69 :     main::pop_up_list($self->{choices});
70 :     }
71 :    
72 :     sub ans_rule {shift->menu(@_)}
73 :    
74 :     1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9