view release on metacpan or search on metacpan
- added french and portuguese translation
- various small changes and fixes
- Some work by Raul Dias to fix some focus bugs
Version 0.74
============
2003-04-27 - Fixed critical bug that broke Menubar selection
Version 0.73
============
2003-03-28 - Added Russian, Polish, Italian and German language
pack
- Applied focusdelete and userdata patch by Raul Dias
2002-01-15: - Changed the displaying of the calendar widget
a little. The topbar showing a date is only
highlighted if the cursor is on the selected date.
- Renamed some widgets (now we still can). I think
there are too many capitals in them...
- Curses::UI::ListBox renamed to
Curses::UI::Listbox
- Curses::UI::CheckBox renamed to
Curses::UI::Checkbox
- Curses::UI::MenuBar renamed to
Curses::UI::Menubar
- Curses::UI::MenuListBox renamed to
Curses::UI::MenuListbox
- Curses::UI::PopupBox renamed to
Curses::UI::Popupmenu
- Curses::UI::ProgressBar renamed to
Curses::UI::Progressbar
- Curses::UI::ButtonBox renamed to
Curses::UI::Buttonbox
- Curses::UI::RadioButtonBox renamed to
Curses::UI::Radiobuttonbox
- Curses::UI::Dialog::FileBrowser renamed to
Curses::UI::Dialog::Filebrowser
- Added the -clear_on_exit option
to Curses::UI. If this option is
set, a Curses::UI application will
call "clear" on exit.
Version 0.60
============
2002-01-11: - Wrote documentation for:
- Curses::UI::MenuListbox
- Curses::UI::Menubar
- Added new example application:
- demo-Curses::UI::Menubar
2002-01-10: - Wrote documentation for:
- Curses::UI::TextEditor
- Curses::UI::TextEntry
- Curses::UI::TextViewer
- Curses::UI::Common
- Curses::UI::Container
- Added new example applications:
- demo-Curses::UI::Dialog::Basic
lib/Curses/UI/Language/italian.pm
lib/Curses/UI/Language/japanese.pm
lib/Curses/UI/Language/norwegian.pm
lib/Curses/UI/Language/polish.pm
lib/Curses/UI/Language/portuguese.pm
lib/Curses/UI/Language/russian.pm
lib/Curses/UI/Language/slovak.pm
lib/Curses/UI/Language/spanish.pm
lib/Curses/UI/Language/turkish.pm
lib/Curses/UI/Listbox.pm
lib/Curses/UI/Menubar.pm
lib/Curses/UI/Notebook.pm
lib/Curses/UI/PasswordEntry.pm
lib/Curses/UI/Popupmenu.pm
lib/Curses/UI/Progressbar.pm
lib/Curses/UI/Radiobuttonbox.pm
lib/Curses/UI/Searchable.pm
lib/Curses/UI/TextEditor.pm
lib/Curses/UI/TextEntry.pm
lib/Curses/UI/TextViewer.pm
lib/Curses/UI/Tutorial.pod
-------------------
A UI framework based on the curses library. Curses::UI contains
several widgets which can be used to build a user interface:
- Buttonbox
- Calendar
- Checkbox
- Container (container base element)
- Label
- Listbox
- Menubar
- PasswordEntry
- Popupmenu (a.k.a. pulldown- or dropdown menu)
- Progressbar
- Radiobuttonbox
- Texteditor (has features like word wrapping and undo)
- Textentry
- Textviewer
- Widget (widget base element)
- Window
examples/color_editor view on Meta::CPAN
}
# We don't want STDERR output to clutter the screen.
#
# Hint: If you need STDERR, write it out to a file and put
# a tail on that file to see the STDERR output. Example:
#open STDERR, ">>/tmp/editor_errors.$$";
open STDERR, ">/dev/null";
# ----------------------------------------------------------------------
# Menu definition
# ----------------------------------------------------------------------
my @menu = (
{ -label => 'File',
-submenu => [
{ -label => 'Open file ^O', -value => \&open_dialog },
{ -label => 'Save file ^S', -value => \&save_dialog },
{ -label => 'Exit ^Q', -value => \&exit_dialog }
]
},
examples/color_editor view on Meta::CPAN
# Create the root. Everything else will be built up from here.
use Curses::UI;
my $cui = new Curses::UI (
-clear_on_exit => 1,
-color_support => 1
);
# Add the menu to the root.
my $menu = $cui->add(
'menu','Menubar',
-fg => "white",
-bg => "blue",
-menu => \@menu,
);
# Create the screen for the editor.
my $screen = $cui->add(
'screen', 'Window',
-padtop => 1, # leave space for the menu
-border => 0,
examples/demo-widgets view on Meta::CPAN
{ -label => '------------', -value => sub{} },
{ -label => 'Next demo', -value => \&goto_next_demo },
{ -label => 'Previous demo', -value => \&goto_prev_demo },
];
my $menu = [
{ -label => 'File', -submenu => $file_menu },
{ -label => 'Select demo', -submenu => $demo_menu },
];
$cui->add('menu', 'Menubar', -menu => $menu);
# ----------------------------------------------------------------------
# Create the explanation window
# ----------------------------------------------------------------------
my $w0 = $cui->add(
'w0', 'Window',
-border => 1,
-y => -1,
-height => 3,
examples/editor view on Meta::CPAN
}
# We don't want STDERR output to clutter the screen.
#
# Hint: If you need STDERR, write it out to a file and put
# a tail on that file to see the STDERR output. Example:
#open STDERR, ">>/tmp/editor_errors.$$";
open STDERR, ">/dev/null";
# ----------------------------------------------------------------------
# Menu definition
# ----------------------------------------------------------------------
my @menu = (
{ -label => 'File',
-submenu => [
{ -label => 'Open file ^O', -value => \&open_dialog },
{ -label => 'Save file ^S', -value => \&save_dialog },
{ -label => 'Exit ^Q', -value => \&exit_dialog }
]
},
examples/editor view on Meta::CPAN
# ----------------------------------------------------------------------
# Create the root. Everything else will be built up from here.
use Curses::UI;
my $cui = new Curses::UI (
-clear_on_exit => 1
);
# Add the menu to the root.
my $menu = $cui->add(
'menu','Menubar',
-menu => \@menu,
);
# Create the screen for the editor.
my $screen = $cui->add(
'screen', 'Window',
-padtop => 1, # leave space for the menu
-border => 0,
-ipad => 0,
);
examples/tutorial view on Meta::CPAN
my @menu = (
{ -label => 'File',
-submenu => [
{ -label => 'Exit ^Q', -value => \&exit_dialog }
]
},
);
my $menu = $cui->add(
'menu','Menubar',
-menu => \@menu,
-fg => "blue",
);
my $win1 = $cui->add(
'win1', 'Window',
-border => 1,
-y => 1,
-bfg => 'red',
);
lib/Curses/UI.pm view on Meta::CPAN
=item L<Curses::UI::Buttonbox>
=item L<Curses::UI::Calendar>
=item L<Curses::UI::Checkbox>
=item L<Curses::UI::Label>
=item L<Curses::UI::Listbox>
=item L<Curses::UI::Menubar>
=item L<Curses::UI::MenuListbox> (used by Curses::UI::Menubar)
=item L<Curses::UI::Notebook>
=item L<Curses::UI::PasswordEntry>
=item L<Curses::UI::Popupmenu>
=item L<Curses::UI::Progressbar>
=item L<Curses::UI::Radiobuttonbox>
lib/Curses/UI/Menubar.pm view on Meta::CPAN
# ----------------------------------------------------------------------
# Curses::UI::Menubar
# Curses::UI::MenuListbox
#
# (c) 2001-2002 by Maurice Makaay. All rights reserved.
# This file is part of Curses::UI. Curses::UI is free software.
# You can redistribute it and/or modify it under the same terms
# as perl itself.
#
# Currently maintained by Marcus Thiesen
# e-mail: marcus@cpan.thiesenweb.de
# ----------------------------------------------------------------------
# TODO: fix dox
# ----------------------------------------------------------------------
# MenuListbox package
# ----------------------------------------------------------------------
package Curses::UI::MenuListbox;
use strict;
use Curses;
use Curses::UI::Common;
use Curses::UI::Container;
use Curses::UI::Window;
use Curses::UI::Listbox;
use Curses::UI::Widget;
use vars qw(
lib/Curses/UI/Menubar.pm view on Meta::CPAN
-bg => -1,
-fg => -1,
-bbg => -1,
-bfg => -1,
%userargs,
-vscrollbar => 1, # Always use a vscrollbar
-border => 1, # Always show a border
-wraparound => 1, # Use listbox wraparound
-returnaction => undef, # Is set by other MenuListboxes
);
# First determine the longest label.
my $longest = 0;
foreach my $item (@{$args{-menu}})
{
my $l = $item->{-label};
$args{-parent}->root->fatalerror(
"Missing argument: -label for the MenuListbox"
) unless defined $l;
$longest = length($l) if length($l) > $longest;
}
# Increase $longest for some whitespace on the
# right side of the labels.
$longest++;
# Now create the values and labels for the listbox.
my @values = ();
lib/Curses/UI/Menubar.pm view on Meta::CPAN
if ($args{-x} + $w > $ENV{COLS}) {
$args{-x} = $ENV{COLS} - $w;
$args{-x} = 0 if $args{-x} < 0;
}
my $this = $class->SUPER::new(%args);
$this->root->fatalerror(
"Missing or illegal argument: -menubar"
) unless defined $args{-menubar} and
$args{-menubar}->isa('Curses::UI::Menubar');
# Clear 'loose-focus' binding, so loosing focus through
# the <TAB> key does not work.
$this->clear_binding('loose-focus');
# Create binding routines.
$this->set_routine('cursor-left', \&cursor_left);
$this->set_routine('cursor-right', \&cursor_right);
$this->set_routine('option-select',\&option_select);
$this->set_routine('escape', \&escape_key);
lib/Curses/UI/Menubar.pm view on Meta::CPAN
{
# Compute the (x,y)-position of the new menu.
my $x = $this->{-x} + $this->borderwidth;
my $y = $this->{-y} + $this->{-ypos};
# Create the submenu.
my $id = "__submenu_$this";
my $submenu = $this->root->add(
$id, 'MenuListbox',
-prevobject => $this,
-menubar => $this->{-menubar},
-x => $x,
-y => $y,
-menu => $this->{-menu}->[$this->{-ypos}]->{-submenu},
-bg => $this->{-bg},
-fg => $this->{-fg},
-bbg => $this->{-bbg},
-bfg => $this->{-bfg},
);
lib/Curses/UI/Menubar.pm view on Meta::CPAN
$this->{-ypos} = $this->{-active} = $this->{-yscrpos} + $y;
$this->layout_content();
$this->schedule_draw(1);
$this->option_select();
}
# Let Curses::UI->usemodule() believe that this module
# was already loaded (usemodule() would else try to
# require the non-existing file).
#
$INC{'Curses/UI/MenuListbox.pm'} = $INC{'Curses/UI/Menubar.pm'};
# ----------------------------------------------------------------------
# Menubar package
# ----------------------------------------------------------------------
package Curses::UI::Menubar;
use strict;
use Curses;
use Curses::UI::Common;
use Curses::UI::Container;
use Curses::UI::Window;
use vars qw(
$VERSION
@ISA
lib/Curses/UI/Menubar.pm view on Meta::CPAN
-bindings => {%bindings},
-width => undef, # Always use the full width
-height => 1, # Always use height = 1
-focus => 0,
-nocursor => 1, # This widget does not use a cursor
-x => 0,
-y => 0,
-border => 0,
-selected => 0,
-returnaction => undef, # is set by MenuListboxes.
-menuoption => undef, # the value for the chosen option
# (is also set by MenuListboxes).
-is_expanded => 0, # let show focused on expand
);
my $this = $class->SUPER::new( %args );
$this->layout;
if ($Curses::UI::ncurses_mouse) {
$this->set_mouse_binding('mouse-button1', BUTTON1_CLICKED());
}
lib/Curses/UI/Menubar.pm view on Meta::CPAN
}
# does it have a border
if ($this->{-parent}->{-border}) {
$y += 1;
}
# Add the submenu.
my $id = "__submenu_$this";
my $submenu = $this->root->add(
$id, 'MenuListbox',
-x => $x,
-y => $y,
-is_topmenu => 1,
-menu => $this->{-menu}->[$this->{-selected}]->{-submenu},
-menubar => $this,
-prevobject => $this,
-fg => $this->{-fg},
-bg => $this->{-bg},
-bfg => $this->{-fg},
-bbg => $this->{-bg},
lib/Curses/UI/Menubar.pm view on Meta::CPAN
return $this;
}
1;
=pod
=head1 NAME
Curses::UI::Menubar - Create and manipulate menubar widgets
=head1 CLASS HIERARCHY
Curses::UI::Widget
|
+----Curses::UI::Container
|
+----Curses::UI::Window
|
+----Curses::UI::Menubar
=head1 SYNOPSIS
use Curses::UI;
my $cui = new Curses::UI;
# define the menu datastructure.
my $menu_data = [....];
my $menu = $cui->add(
'menu', 'Menubar',
-menu => $menu_data
);
$menu->focus();
=head1 DESCRIPTION
This class can be used to add a menubar to Curses::UI. This
menubar can contain a complete submenu hierarchy. It looks
lib/Curses/UI/Menubar.pm view on Meta::CPAN
|menuitem 1 |
|menuitem 2 |+--------------+
|menuitem 3 >>||submenuitem 1 |
|menuitem 4 ||submenuitem 2 |
+-------------+|submenuitem 3 |
|submenuitem 4 |
|submenuitem 5 |
+--------------+
See exampes/demo-Curses::UI::Menubar in the distribution
for a short demo.
=head1 STANDARD OPTIONS
This class does not use any of the standard options that
are provided by L<Curses::UI::Widget>.
=head1 WIDGET-SPECIFIC OPTIONS
There is only one option: B<-menu>. The value for this
option is an ARRAYREF. This ARRAYREF behaves exactly
like the one that is described in
L<Curses::UI::MenuListbox|Curses::UI::MenuListbox>.
The difference is that for the top-level menu, you
will only use -submenu's. Example data structure:
my $menu1 = [
{ -label => 'option 1', -value => '1-1' },
{ -label => 'option 2', -value => '1-2' },
{ -label => 'option 3', -value => '1-3' },
];
my $menu2 = [
lib/Curses/UI/Menubar.pm view on Meta::CPAN
=back
=head1 SEE ALSO
L<Curses::UI>,
L<Curses::UI::MenuListbox>,
L<Curses::UI::Listbox>
=head1 AUTHOR
Copyright (c) 2001-2002 Maurice Makaay. All rights reserved.
Maintained by Marcus Thiesen (marcus@cpan.thiesenweb.de)
lib/Curses/UI/Tutorial.pod view on Meta::CPAN
my @menu = (
{ -label => 'File',
-submenu => [
{ -label => 'Exit ^Q', -value => \&exit_dialog }
]
},
);
In order to describe the structure of a menu Curses::UI uses
a rather ugly construct out of hash and arrayrefs. See
Curses::UI::Menubar for details. What you do at this point is to
create a Menubar with just one entry and one submenu. The entry
is 'File' and the submenu is 'Exit'.
The value of this menu item is a reference to a sub called
exit_dialog.
=head1 Dialogs
sub exit_dialog()
{
my $return = $cui->dialog(
-message => "Do you really want to quit?",
lib/Curses/UI/Tutorial.pod view on Meta::CPAN
}
The dialog method of Curses::UI gives us an easy and convenient way to
create dialogs on the main screen. A dialog is a way to interact with
the user in order to ask him a question or give him important
information. This dialog is a more complex one, which asks the
question whether or not you really want to exit. As the button for
"yes" would return us a true value, you can easily exit on this return
value.
=head1 Add the Menubar
my $menu = $cui->add(
'menu','Menubar',
-menu => \@menu,
-fg => "blue",
);
To finally add the Menubar to our root object, you have to call the add
method on the Curses UI object. You specify the internal name of the
widget as the first argument, the widget type as the second argument
(like Label, TextViewer, etc.) and the menu structure you created at
the beginning as an array reference as third object. Because you want
the Menubar to have a blue theme, you give him the -fg option
"blue". There are a couple of colors you can use, see
Curses::UI::Color for details.
=head1 Add a window
my $win1 = $cui->add(
'win1', 'Window',
-border => 1,
-y => 1,
-bfg => 'red',
);
There are only two types of object you can add to the Curses::UI root
object: Menubars and Windows. All other widgets have to be inserted
into a window. Of course you can add a Menubar to a window, but not
vice versa ;-).
The add method always has the same two first arguments: the internal
name and the widget type. The internal name can be used to find an
object. The method getobj takes this name and returns us the
corresponding object out of the hierarchy. See Curses::UI for details.
Again you want some fancy colors, so you tell the window to have a
border, leave some space for the Menubar (-y => 1) and set the border
foreground color to red.
=head1 Add a widget
my $texteditor = $win1->add("text", "TextEditor",
-text => "Here is some text\n"
. "And some more");
The next step is to add a useful widget to our new small Curses::UI
app. Here you take a TextEditor widget which performs basic tasks as a
text editor. You add some initial text to the widget to make it not
seem that empty.
=head1 Making keybindings
$cui->set_binding(sub {$menu->focus()}, "\cX");
$cui->set_binding( \&exit_dialog , "\cQ");
You want to be able to focus the Menubar if you finished editing in the
TextEditor widget. Therefore you set a binding to the focus function of
the menu and the key sequence Control (specified by \c) combined with
X. Now you can easily return to the menu after editing.
Because it is easier to have a shortcut for closing the application you
add a binding for the sequence Control-Q to our nice exit_dialog
method.
=head1 The final steps
$texteditor->focus();
t/02widget_classes.t view on Meta::CPAN
# -*- perl -*-
use strict;
use Test;
BEGIN { plan tests => 15 }
foreach my $class (qw(
Curses::UI::Checkbox
Curses::UI::Calendar
Curses::UI::Label
Curses::UI::Menubar
Curses::UI::Progressbar
Curses::UI::PasswordEntry
Curses::UI::Buttonbox
Curses::UI::Listbox
Curses::UI::Popupmenu
Curses::UI::TextEditor
Curses::UI::TextEntry
Curses::UI::TextViewer
Curses::UI::Window
Curses::UI::Radiobuttonbox