view release on metacpan or search on metacpan
lib/AAC/Pvoice.pm view on Meta::CPAN
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
$VERSION = 0.91;
@ISA = qw (Exporter);
@EXPORT = qw (MessageBox);
@EXPORT_OK = qw ();
%EXPORT_TAGS = ();
}
sub MessageBox
{
my ($message, $caption, $style, $parent, $x, $y) = @_;
$caption ||= 'Message';
$style ||= wxOK;
$x ||= -1;
$y ||= -1;
$Text::Wrap::columns = 25;
$message = wrap('','',$message)."\n";
my $width = 0;
$width = 25 if $style & wxOK;
lib/AAC/Pvoice.pm view on Meta::CPAN
$d->Append($messagectrl,1);
my $ok = [Wx::NewId,AAC::Pvoice::Bitmap->new('',50,25,'OK', Wx::Colour->new(255, 230, 230)),sub{$d->SetReturnCode(wxOK); $d->Close()}];
my $yes = [Wx::NewId,AAC::Pvoice::Bitmap->new('',50,30,'Yes', Wx::Colour->new(255, 230, 230)),sub{$d->SetReturnCode(wxYES); $d->Close()}];
my $no = [Wx::NewId,AAC::Pvoice::Bitmap->new('',50,25,'No', Wx::Colour->new(255, 230, 230)),sub{$d->SetReturnCode(wxNO); $d->Close()}];
my $cancel = [Wx::NewId,AAC::Pvoice::Bitmap->new('',50,60,'Cancel',Wx::Colour->new(255, 230, 230)),sub{$d->SetReturnCode(wxCANCEL);$d->Close()}];
my $items = [];
push @$items, $ok if $style & wxOK;
push @$items, $yes if $style & wxYES_NO;
push @$items, $no if $style & wxYES_NO;
push @$items, $cancel if $style & wxCANCEL;
$d->Append(AAC::Pvoice::Row->new($d->{panel}, # parent
scalar(@$items), # max
$items, # items
wxDefaultPosition, # pos
wxDefaultSize,
$width,
25,
$d->{ITEMSPACING},
$d->{backgroundcolour}),
0); #selectable
return $d->ShowModal();
lib/AAC/Pvoice.pm view on Meta::CPAN
use a normal mouse and/or keyboard. To see an application that uses this
set of modules, take a look at pVoice (http://www.pvoice.org, or the
sources on http://opensource.pvoice.org).
AAC::Pvoice is in fact a wrapper around many wxPerl classes, to make it
easier to create applications like pVoice.
=head1 USAGE
=head2 AAC::Pvoice::MessageBox(message, caption, style, parent, x, y)
This function is similar to Wx::MessageBox. It uses the same parameters as
Wx::MessageBox does. Currently the style parameter doesn't support the
icons that can be set on Wx::MessageBox.
See the individual module's documentation
=head1 BUGS
probably a lot, patches welcome!
lib/AAC/Pvoice/Bitmap.pm view on Meta::CPAN
BEGIN
{
Wx::InitAllImageHandlers;
$cache = File::Cache->new({namespace => 'images'});
}
#----------------------------------------------------------------------
sub new
{
my $class = shift;
my ($file, $MAX_X, $MAX_Y, $caption, $background, $blowup, $parent_background) = @_;
$caption||='';
$parent_background=Wx::Colour->new(220,220,220) if not defined $parent_background;
my $config = Wx::ConfigBase::Get;
$caption = $config->ReadInt('Caption')?$caption:'';
# return ReadImage($file, $MAX_X, $MAX_Y, $caption, $background, $blowup, $parent_background) if $file;
return ReadImageMagick($file, $MAX_X, $MAX_Y, $caption, $background, $blowup, $parent_background) if $file;
return DrawCaption($MAX_X, $MAX_Y, $caption, $background, $parent_background);
}
sub ReadImage
{
my $file = shift;
my ($x, $y, $caption, $background, $blowup, $parent_background) = @_;
return DrawCaption($x, $y, '?', $background, $parent_background) unless -r $file;
confess "MaxX and MaxY should be positive" if $x < 1 || $y < 1;
my $newbmp;
$caption ||='';
$blowup ||=0;
$background = $parent_background unless defined $background;
my $ibg = wxColor2hex($background) if (ref($background) eq 'Wx::Colour');
my $pbg = wxColor2hex($parent_background) if (ref($parent_background) eq 'Wx::Colour');
my $stat = stat($file);
my $mtime = $stat->mtime();
my $image = $cache->get("$file-$x-$y-$caption-$ibg-$blowup-$pbg-$mtime");
if (!$image)
{
my $capdc = Wx::MemoryDC->new();
my $cpt = 10;
my ($cfont, $cw, $ch) = (wxNullFont, 0, 0);
if ($caption)
lib/AAC/Pvoice/Bitmap.pm view on Meta::CPAN
return wxNullBitmap if not $factor;
($w, $h) = (int($w/$factor),$y-$ch);
}
$img = $img->Scale($w, $h);
}
my $bmp = Wx::Bitmap->new($img);
my $newbmp = Wx::Bitmap->new($x, $y);
my $tmpdc = Wx::MemoryDC->new();
$tmpdc->SelectObject($newbmp);
my $bgbr = Wx::Brush->new($parent_background, wxSOLID);
$tmpdc->SetBrush($bgbr);
$tmpdc->SetBackground($bgbr);
$tmpdc->Clear();
my $bg = $parent_background;
if (defined $background)
{
if (ref($background)=~/ARRAY/)
{
$bg = Wx::Colour->new(@$background);
}
else
{
$bg = $background;
}
lib/AAC/Pvoice/Bitmap.pm view on Meta::CPAN
my $color = shift;
my $red = $color->Red();
my $green = $color->Green();
my $blue = $color->Blue();
return sprintf("#%0x%0x%0x", $red,$green,$blue);
}
sub ReadImageMagick
{
my $file = shift;
my ($x, $y, $caption, $bgcolor, $blowup, $parent_background) = @_;
confess "MaxX and MaxY should be positive" if $x < 1 || $y < 1;
return DrawCaption($x, $y, '?', $bgcolor, $parent_background) unless -r $file;
$caption ||='';
$blowup ||=0;
$bgcolor = $parent_background unless defined $bgcolor;
my $ibg = wxColor2hex($bgcolor) if (ref($bgcolor) eq 'Wx::Colour');
my $pbg = wxColor2hex($parent_background) if (ref($parent_background) eq 'Wx::Colour');
my $stat = stat($file);
my $mtime = $stat->mtime();
my $image = $cache->get("$file-$x-$y-$caption-$ibg-$blowup-$pbg-$mtime");
if (!$image)
{
my $radius = 10;
my $svg = <<SVG;
<svg width="$x" height="$y" viewBox="0 0 $x $y">
<rect x="0" y="0" width="$x" height="$y" ry="$radius"
lib/AAC/Pvoice/Bitmap.pm view on Meta::CPAN
$background->Annotate(text => $caption, font => 'Comic-Sans-MS', pointsize => $pt, gravity => 'South');
}
# Read the actual image
my $img = Image::Magick->new;
my $rc = $img->Read($file);
carp "Can't read $file: $rc" if $rc;
# wmf files have a white background color by default
# if we can't get the matte color for the image, we assume
# that white can be used as the transparent color...
$img->Transparent(color => 'white') if (!$img->Get('matte') || $file =~ /wmf$/i);
my $w = $img->Get('width');
my $h = $img->Get('height');
my $ch = $textheight;
if (($w > $x) || ($h > ($y-$ch)))
{
my ($newx, $newy) = ($w, $h);
if ($w > $x)
{
my $factor = $w/$x;
return wxNullBitmap if not $factor;
lib/AAC/Pvoice/Bitmap.pm view on Meta::CPAN
return Wx::Bitmap->new(Wx::Image->newStreamMIME($fh, $contenttype))
}
END
{
undef $cache;
}
sub DrawCaption
{
my ($x, $y, $caption, $background, $parent_background) = @_;
confess "MaxX and MaxY should be positive" if $x < 1 || $y < 1;
my $newbmp = Wx::Bitmap->new($x, $y);
my $tmpdc = Wx::MemoryDC->new();
$tmpdc->SelectObject($newbmp);
my $bgbr = Wx::Brush->new($parent_background, wxSOLID);
$tmpdc->SetBrush($bgbr);
$tmpdc->SetBackground($bgbr);
$tmpdc->Clear();
my $bg = $parent_background;
if (defined $background)
{
if (ref($background)=~/ARRAY/)
{
$bg = Wx::Colour->new(@$background);
}
else
{
$bg = $background;
}
lib/AAC/Pvoice/Bitmap.pm view on Meta::CPAN
=head1 DESCRIPTION
This module is a simpler interface to the Wx::Bitmap to do things with
images that I tend to do with almost every image I use in pVoice applications.
It's a subclass of Wx::Bitmap, so you can call any method that a Wx::Bitmap
can handle on the resulting AAC::Pvoice::Bitmap.
=head1 USAGE
=head2 new(image, maxX, maxY, caption, background, blowup, parentbackground)
This constructor returns a bitmap (useable as a normal Wx::Bitmap), that
has a size of maxX x maxY, the image drawn into it as large as possible.
If blowup has a true value, it will enlarge the image to try and match
the maxX and maxY. Any space not filled by the image will be the
specified background colour. A caption can be specified to draw under the
image.
If the image doesn't exist, it will draw a large questionmark and warn
the user.
lib/AAC/Pvoice/Bitmap.pm view on Meta::CPAN
This is the background of the image, specified as either a constant
(i.e. wxWHITE) or as an arrayref of RGB colours (like [128,150,201] ).
=item blowup
This boolean parameter determines whether or not images that are smaller
than maxX and maxY should be blown up to be as large as possible within
the given maxX and maxY.
=item parentbackground
This is the background of the parent of this bitmap, which is the colour to
be used outside of the round cornered background.
=back
=head1 BUGS
probably a lot, patches welcome!
=head1 AUTHOR
lib/AAC/Pvoice/Dialog.pm view on Meta::CPAN
my $self = $class->SUPER::new(@_);
my ($x, $y) = ($self->GetClientSize->GetWidth,
$self->GetClientSize->GetHeight);
$self->{margin} = 10;
$self->{ITEMSPACING} = 4;
$self->{selectionborder} = 3;
$self->{backgroundcolour} = Wx::Colour->new(220,220,220);
$self->SetBackgroundColour(wxWHITE);
$self->{panel} = AAC::Pvoice::Panel->new( $self, # parent
-1, # id
[$self->{margin},
$self->{margin}], # position
[$x-2*$self->{margin},
$y-2*$self->{margin}],# size
wxNO_3D|wxWANTS_CHARS, # style
1, # disabletextrow
$self->{ITEMSPACING}, # rowspacing
$self->{selectionborder}, # selectionborderwidth
1); # disabletitle
lib/AAC/Pvoice/Dialog.pm view on Meta::CPAN
use AAC::Pvoice::Dialog;
=head1 DESCRIPTION
This subclass of Wx::Dialog knows all of Wx::Dialog's methods. Therefore
only two methods are described below. The constructor (which is also similar
to the Wx::Dialog constructor) and the (added) Append method.
=head1 USAGE
=head2 new(parent, id, caption, [x,y], [w,h])
This is the constructor for a new AAC::Pvoice::Dialog. It is similar to calling
the constructor of a Wx::Dialog.
=head2 Append
This method is similar to AAC::Pvoice::Panel's Append method and allows you
to append a 'row' (or any Wx::Window subclass) to the Dialog.
=head1 BUGS
lib/AAC/Pvoice/EditableRow.pm view on Meta::CPAN
use Wx::Event qw( EVT_BUTTON );
use AAC::Pvoice::Bitmap;
use base qw(Wx::Panel);
our $VERSION = sprintf("%d.%02d", q$Revision: 1.4 $=~/(\d+)\.(\d+)/);
#----------------------------------------------------------------------
sub new
{
my $class = shift;
my ($parent,$maxitems,$items,$wxPos,$wxSize, $itemmaxX, $itemmaxY, $itemspacing, $background, $style,$name) = @_;
$wxPos ||= wxDefaultPosition;
$wxSize ||= wxDefaultSize;
$style ||= 0;
$name ||= '';
my $self = $class->SUPER::new($parent, -1, $wxPos, $wxSize, $style, $name);
$self->{maxitems} = $maxitems;
$self->{itemspacing}=$itemspacing;
# Create a new panel
my $sizer = Wx::GridSizer->new(1,0);
$self->{items} = [];
$self->{actions} = [];
my ($maxX, $maxY) = ($itemmaxX, $itemmaxY);
# Add the defined keys for this row
for (@$items)
{
my ($id, $img, $sub) = @$_;
my $button = Wx::BitmapButton->new
($self, # parent
$id, # id
$img, # image
wxDefaultPosition, # position
[$maxX+3, $maxY+3], # size
wxBU_AUTODRAW); # style
$button->SetBackgroundColour($background);
$sizer->Add($button, 0, wxALIGN_CENTRE|wxALL, $self->{itemspacing});
push @{$self->{items}}, $button;
EVT_BUTTON($self, $id, $sub);
}
lib/AAC/Pvoice/Panel.pm view on Meta::CPAN
sub new
{
my $class = shift;
$_[2] ||= wxDefaultPosition;
$_[3] ||= wxDefaultSize;
$_[4] ||= wxTAB_TRAVERSAL;
my $self = $class->SUPER::new(@_[0..4]);
$self->SetBackgroundColour(wxWHITE);
$self->{parent} = $_[0];
$self->{position} = $_[2];
$self->{size} = $_[3];
$self->{disabletextrow} = $_[5] || 0;
$self->{itemspacing} = $_[6] || 0;
$self->{selectionborder}= $_[7] || int($self->{itemspacing}/2)||1;
$self->{disabletitle} = $_[8] || 0;
$self->{tls} = Wx::FlexGridSizer->new(0,1);
$self->{totalrows} = 0;
$self->{lastrow} = 0;
$self->{currentpage} = 0;
$self->{unfinished} = 1;
$self->RoundCornerRadius(10);
my ($x, $y);
# to get the right dimensions for the items, we maximize the
# frame, show it, get the dimensions, and hide it again
if (ref($self->{parent}) =~ /Frame/)
{
if ($self->{parent}->IsMaximized)
{
($x, $y) = @{$self->{size}};
}
else
{
$self->{parent}->Maximize(1);
$self->{parent}->Show(1);
($x, $y) = ( $self->GetSize()->GetWidth(),
$self->GetSize()->GetHeight() );
$self->{parent}->Show(0);
}
}
else
{
# if our parent isn't a frame, we're not able to maximize
# it, so we just get the dimensions of the parent
($x, $y) = @{$self->{size}};
}
$self->{realx} = $x;
$self->{realy} = $y;
$self->xsize($x);
$self->ysize($y);
unless ($self->{disabletitle})
{
# to be able to calculate the useable y-size, we need to add the
# title and get its height. Since we don't know what the title
lib/AAC/Pvoice/Panel.pm view on Meta::CPAN
{
my $self = shift;
$self->{editmode} = shift;
}
sub OnPaint
{
my ($self, $event) = @_;
$self->{setselection} = 1;
my $dc = Wx::PaintDC->new($self);
$self->SetBackgroundColour($self->{parent}->GetBackgroundColour);
$self->DrawBackground($dc);
if ($self->{rowcolumnscanning} && not $self->{editmode})
{
$dc = Wx::WindowDC->new($self->{selectedwindow}->GetParent);
$self->DrawBorder($dc);
}
$event->Skip;
}
sub DrawBorder
lib/AAC/Pvoice/Panel.pm view on Meta::CPAN
wxNORMAL, # style
wxNORMAL, # weight
0,
'Comic Sans MS',# face name
wxFONTENCODING_SYSTEM);
$font->SetUnderlined(1);
$self->{ta} = Wx::TextAttr->new( Wx::Colour->new(0,0,0), # textcol
Wx::Colour->new(255,255,255),# backgr.
$font); # font
my $rowsizer = Wx::GridSizer->new(1,0);
$self->{text} = Wx::TextCtrl->new( $self, # parent
-1, # id
'', # text
wxDefaultPosition,# position
[4*($self->{realx}/5),60], # size
wxTE_RICH|
wxTE_MULTILINE); # style
# set the text-attributes
$self->{text}->SetDefaultStyle($self->{ta});
$rowsizer->Add($self->{text}, # what to add
0, # unused
lib/AAC/Pvoice/Panel.pm view on Meta::CPAN
use AAC::Pvoice::Panel;
=head1 DESCRIPTION
=head1 USAGE
=head2 new(parent, id, size, position, style, disabletextrow, itemspacing, selectionborderwidth, disabletitle)
This is the constructor for a new AAC::Pvoice::Panel. The first 5 parameters are
equal to the parameters for a normal Wx::Panel, see the wxPerl documentation
for those parameters.
=over 4
=item disabletextrow
This is s a boolean (1 or 0), which determines
lib/AAC/Pvoice/Row.pm view on Meta::CPAN
use Wx qw(:everything);
use Wx::Perl::Carp;
use AAC::Pvoice::Bitmap;
use base qw(Wx::Panel);
our $VERSION = sprintf("%d.%02d", q$Revision: 1.5 $=~/(\d+)\.(\d+)/);
#----------------------------------------------------------------------
sub new
{
my $class = shift;
my ($parent,$maxitems,$items,
$wxPos,$wxSize, $itemmaxX, $itemmaxY,
$itemspacing, $background, $style,$name) = @_;
my $self = $class->SUPER::new( $parent,
Wx::NewId,
$wxPos || wxDefaultPosition,
$wxSize || wxDefaultSize,
$style || 0,
$name || '');
$self->{maxitems} = $maxitems;
my $sizer = Wx::GridSizer->new(1,0);
$self->{items} = [];
lib/AAC/Pvoice/Row.pm view on Meta::CPAN
Wx::NewId,
wxNullBitmap,
wxDefaultPosition,
[$maxX, $maxY],
wxSUNKEN_BORDER);
$empty->SetBackgroundColour($background);
$sizer->Add($empty,0, wxALIGN_CENTRE|wxALL, $itemspacing);
next;
}
my ($id, $img, $sub) = @$_;
my $button = Wx::BitmapButton->new ($self, # parent
$id, # id
$img, # image
wxDefaultPosition, # position
[$maxX, $maxY],# size
wxSUNKEN_BORDER); # style
$button->SetBackgroundColour($background);
$sizer->Add($button, 0, wxALIGN_CENTRE|wxALL, $itemspacing);
push @{$self->{items}}, $button;
push @{$self->{actions}}, $sub;
push @{$self->{ids}}, $id;
lib/AAC/Pvoice/Row.pm view on Meta::CPAN
=head1 SYNOPSIS
use AAC::Pvoice::Row;
use Wx;
my $panel = Wx::Panel->new($self, -1);
my $items = [ [Wx::NewId, $SomeWxBitmap, sub{ print "do something useful here"} ],
[Wx::NewId, $SomeOtherWxBitmap, sub{ print "do something else here"} ]];
my $row = AAC::Pvoice::Row->new($panel, # parent
scalar(@$items), # max
$items, # items
wxDefaultPosition,# pos
wxDefaultSize, # size
50, # maxX
75, # maxY
5, # spacing
wxWHITE) # background colour
=head1 DESCRIPTION
AAC::Pvoice::Row is a subclass of Wx::Panel. It will typically be placed
on an AAC::Pvoice::Panel, and contains selectable Wx::Bitmap-s, which,
when selected, will invoke a callback.
=head1 USAGE
=head 2 new(parent, maxitems, items, position, size, maxX, maxY, spacing, backgroundcolour)
This constructor is the only overridden function in AAC::Pvoice::Row. It
takes quite a number of parameters
=over 4
=item parent
The parent on which this row will be placed. Typically you'll be using an
instance of AAC::Pvoice::Panel for this, but it can be any Wx::Window
subclass
=item maxitems
The maximum number of items (images) in this row. If the supplied number
of items (next parameter) is lower than maxitems, the row will be filled up
with (unselectable) WxNullBitmap-s.
=item items