| 1 |
#!/usr/bin/env perl |
| 2 |
# |
| 3 |
# ColorEditor demonstration. |
| 4 |
|
| 5 |
|
| 6 |
use Tk; |
| 7 |
require Tk::ColorEditor; |
| 8 |
require Tk::ErrorDialog; |
| 9 |
use English; |
| 10 |
use strict; |
| 11 |
|
| 12 |
my $MW = MainWindow->new; |
| 13 |
my $f = $MW->Frame(-bg => 'blue'); |
| 14 |
$f->pack; |
| 15 |
my $ce = $f->Button(-text => 'Color Editor'); |
| 16 |
$ce->pack; |
| 17 |
my $qu = $f->Button(-text => 'Quit', -command => \&exit); |
| 18 |
$qu->pack; |
| 19 |
|
| 20 |
my $f2=$f->Frame; |
| 21 |
$f2->pack; |
| 22 |
my $f2b1=$f2->Button(-text => 'f2b1'); |
| 23 |
$f2b1->pack(-side=>'left'); |
| 24 |
my $f2b2=$f2->Button(-text => 'f2b1'); |
| 25 |
$f2b2->pack(-side=>'left'); |
| 26 |
|
| 27 |
my $cref = $MW->ColorEditor( |
| 28 |
-title => 'Test CE', |
| 29 |
-cursor => ['@' . Tk->findINC('demos/images/cursor.xbm'), |
| 30 |
Tk->findINC('demos/images/cursor.mask'), 'red', 'green'], |
| 31 |
); |
| 32 |
$ce->configure(-command => [$cref => 'Show']); |
| 33 |
|
| 34 |
# Configure the color menu slightly. The default color_list explicity |
| 35 |
# references only three of the four buttons so applying colors only effects |
| 36 |
# them. If you uncomment the `get_widget_tree' call the color_list then |
| 37 |
# becomes those widgets of the hierarchy starting at $f2, i.e. only the last |
| 38 |
# two buttons. The "color_configurator" option allows you to supply your |
| 39 |
# own color configurator. |
| 40 |
|
| 41 |
sub my_special_configurator { |
| 42 |
|
| 43 |
# If you choose to supply a non-standard color configurator use the |
| 44 |
# default code `configure_application_colors' in ColorEditor.pm as a |
| 45 |
# guide to the internals of the ColorEditor object. |
| 46 |
|
| 47 |
my($objref, $type, $color) = @_; |
| 48 |
|
| 49 |
print "\nColorEditor object reference : $objref\n"; |
| 50 |
print "Color attribute : $type\n"; |
| 51 |
print "New color : $color\n"; |
| 52 |
print "display_status : ", $objref->cget('-display_status'), "\n"; |
| 53 |
print "color_list widget references :\n"; |
| 54 |
print join("\n", @{$objref->cget('-widgets')}), "\n"; |
| 55 |
|
| 56 |
} # end my_special_configurator |
| 57 |
|
| 58 |
$cref->delete_menu_item(3); |
| 59 |
$cref->delete_menu_item('disabledForeground','troughColor'); |
| 60 |
$cref->add_menu_item('SEP','frog colors'); |
| 61 |
|
| 62 |
$cref->configure( |
| 63 |
-display_status => 1, |
| 64 |
-widgets => [$ce, $qu, $f2b2], |
| 65 |
# -widgets => [$f2->Descendants], |
| 66 |
# -command => [\&my_special_configurator,$cref] |
| 67 |
); |
| 68 |
|
| 69 |
my $e = $MW->ErrorDialog; |
| 70 |
$e->Subwidget('error_dialog')->Subwidget('message')->configure(-bg => 'red'); |
| 71 |
|
| 72 |
MainLoop; |