view release on metacpan or search on metacpan
lib/AAC/Pvoice.pm view on Meta::CPAN
BEGIN {
use Exporter ();
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";
lib/AAC/Pvoice/Bitmap.pm view on Meta::CPAN
use base qw(Wx::Bitmap);
our $cache;
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;
lib/AAC/Pvoice/Bitmap.pm view on Meta::CPAN
close($fh);
$cache->set("$file-$x-$y-$caption-$ibg-$blowup-$pbg-$mtime", $image);
}
my $fh = IO::Scalar->new(\$image);
my $contenttype = 'image/png';
return Wx::Bitmap->new(Wx::Image->newStreamMIME($fh, $contenttype))
}
sub wxColor2hex
{
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;
lib/AAC/Pvoice/Bitmap.pm view on Meta::CPAN
my $contenttype = 'image/png';
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);
lib/AAC/Pvoice/Dialog.pm view on Meta::CPAN
use strict;
use warnings;
our $VERSION = sprintf("%d.%02d", q$Revision: 1.1 $=~/(\d+)\.(\d+)/);
use Wx qw(:everything);
use Wx::Event qw(EVT_CLOSE);
use base 'Wx::Dialog';
sub new
{
my $class = shift;
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);
lib/AAC/Pvoice/Dialog.pm view on Meta::CPAN
$self->{selectionborder}, # selectionborderwidth
1); # disabletitle
$self->{panel}->BackgroundColour($self->{backgroundcolour});
$self->WarpPointer($self->{margin}+1,$self->{margin}+1);
$self->SetFocus();
EVT_CLOSE($self, \&OnClose);
return $self;
}
sub Append
{
my $self = shift;
$self->{panel}->Append(@_);
}
sub OnClose
{
my $self = shift;
$self->Destroy();
}
sub Show
{
my $self = shift;
my $bool = shift;
$self->{panel}->Finalize();
$self->SUPER::Show($bool);
}
sub ShowModal
{
my $self = shift;
$self->{panel}->Finalize();
$self->SUPER::ShowModal();
}
1;
__END__
lib/AAC/Pvoice/EditableRow.pm view on Meta::CPAN
use Wx qw(:everything);
use Wx::Perl::Carp;
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;
lib/AAC/Pvoice/Input.pm view on Meta::CPAN
else
{
require Device::ParallelPort::drv::parport;
}
}
use Wx::Event qw( EVT_TIMER
EVT_CHAR
EVT_MOUSE_EVENTS);
our $VERSION = sprintf("%d.%02d", q$Revision: 1.12 $=~/(\d+)\.(\d+)/);
sub new
{
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
bless $self, $class;
$self->{window} = shift;
# We get the configuration from the Windows registry
# If it's not initialized, we provide some defaults
$self->{window}->{config} = Wx::ConfigBase::Get || croak "Can't get Config";
lib/AAC/Pvoice/Input.pm view on Meta::CPAN
$self->_initautoscan if $self->{window}->{config}->ReadInt('Buttons') == 1;
$self->_initkeys;
$self->_initicon;
$self->StartMonitor if $self->{window}->{Device} eq 'adremo';
$self->StartAutoscan if $self->{window}->{config}->ReadInt('Buttons') == 1;
return $self;
}
sub newchild
{
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
bless $self, $class;
$self->{window} = shift;
# We get the configuration from the Windows registry
# If it's not initialized, we provide some defaults
$self->{window}->{config} = Wx::ConfigBase::Get || croak "Can't get Config";
lib/AAC/Pvoice/Input.pm view on Meta::CPAN
# adremo = electric wheelchair adremo
# keys = keystrokes
$self->{window}->{Device} = $self->{window}->{config}->Read('Device', 'icon');
$self->_initkeys;
$self->_initicon;
return $self;
}
sub _initkeys
{
my $self = shift;
EVT_CHAR($self->{window}, \&_keycontrol)
if $self->{window}->{config}->Read('Device') eq 'keys';
}
sub _initicon
{
my $self = shift;
EVT_MOUSE_EVENTS($self->{window}, \&_iconcontrol)
if $self->{window}->{config}->Read('Device') eq 'icon';
}
sub _initmonitor
{
my $self = shift;
# The event for the adremo device
$self->{window}->{adremotimer} = Wx::Timer->new($self->{window},my $tid = Wx::NewId());
EVT_TIMER($self->{window}, $tid, \&_monitorport);
}
sub _initautoscan
{
my $self = shift;
$self->{window}->{onebuttontimer} = Wx::Timer->new($self->{window},my $obtid = Wx::NewId());
EVT_TIMER($self->{window}, $obtid, sub{my $self = shift; $self->{input}->{next}->() if $self->{input}->{next}});
}
sub StartMonitor
{
my $self = shift;
$self->{window}->{adremotimer}->Start($self->{window}->{Interval}, 0) # 0 is continuous
if $self->{window}->{adremotimer};
}
sub QuitMonitor
{
my $self = shift;
# stop the timer for the port monitor
$self->{window}->{adremotimer}->Stop() if $self->{window}->{adremotimer} && $self->{window}->{adremotimer}->IsRunning;
}
sub StartAutoscan
{
my $self = shift;
$self->{window}->{onebuttontimer}->Start($self->{window}->{OneButtonInterval}, 0) # 0 is continuous
if $self->{window}->{onebuttontimer};
}
sub QuitAutoscan
{
my $self = shift;
$self->{window}->{onebuttontimer}->Stop() if $self->{window}->{onebuttontimer} && $self->{window}->{onebuttontimer}->IsRunning;
}
sub PauseMonitor
{
my $self = shift;
my $bool = shift;
return unless $self->{window}->{config}->Read('Device') eq 'adremo';
$self->QuitMonitor if $bool;
$self->StartMonitor unless $bool;
}
sub PauseAutoscan
{
my $self = shift;
my $bool = shift;
return unless $self->{window}->{config}->ReadInt('Buttons') == 1;
$self->QuitAutoscan if $bool;
$self->StartAutoscan unless $bool;
}
sub Pause
{
my $self = shift;
$self->{pause} = shift;
}
sub GetDevice
{
my $self = shift;
return $self->{window}->{config}->Read('Device');
}
sub SetupMouse
{
my $self = shift;
my ($window, $subgetfocus, $subup, $sublosefocus) = @_;
if ($self->{window}->{config}->Read('Device') eq 'mouse')
{
EVT_MOUSE_EVENTS($window, sub { my ($self, $event) = @_;
&$subup if $event->LeftUp;
&$sublosefocus if $event->Leaving;
&$subgetfocus if $event->Entering;
});
}
}
sub Next
{
my $self = shift;
my $sub = shift;
$self->{next} = $sub;
}
sub Select
{
my $self = shift;
my $sub = shift;
$self->{select} = $sub;
}
sub _keycontrol
{
# BEWARE: $self is the window object this event belongs to
my ($self, $event) = @_;
return if $self->{pause};
$self->{input}->{select}->() if ($event->GetKeyCode == $self->{config}->ReadInt('SelectKey', WXK_RETURN)) || (uc(chr($event->GetKeyCode)) eq uc(chr($self->{config}->ReadInt('SelectKey'))));
$self->{input}->{next}->() if (( ($event->GetKeyCode == $self->{config}->ReadInt('NextKey', WXK_SPACE)) ||
(uc(chr($event->GetKeyCode)) eq uc(chr($self->{config}->ReadInt('NextKey'))))) and
(not $self->{config}->ReadInt('Buttons') == 1));
}
sub _iconcontrol
{
# BEWARE: $self is the window object this event belongs to
my ($self, $event) = @_;
return if $self->{pause};
$self->{input}->{select}->() if $event->LeftUp;
$self->{input}->{next}->() if $event->RightUp &&
not $self->{config}->ReadInt('Buttons') == 1;
}
#----------------------------------------------------------------------
# This sub is used to monitor the parallel port for the adremo device
sub _monitorport
{
# BEWARE: $self is the wxWindow subclass the timer
# belongs to!
my ($self, $event) = @_;
# do nothing if the device is not adremo or
# if we're already running
return if ($self->{monitorrun} ||
(not $self->{input}->{next}) ||
(not $self->{input}->{select}) ||
$self->{pause});
lib/AAC/Pvoice/Panel.pm view on Meta::CPAN
use warnings;
our $VERSION = sprintf("%d.%02d", q$Revision: 1.15 $=~/(\d+)\.(\d+)/);
use Wx qw(:everything);
use Wx::Perl::Carp;
use Wx::Event qw(EVT_PAINT EVT_UPDATE_UI);
use base qw(Wx::Panel);
#----------------------------------------------------------------------
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];
lib/AAC/Pvoice/Panel.pm view on Meta::CPAN
$self->{input} = AAC::Pvoice::Input->new($self);
$self->{input}->Next( sub{$self->Next});
$self->{input}->Select(sub{$self->Select});
$self->{rowcolumnscanning} = ($self->{input}->GetDevice ne 'mouse');
EVT_PAINT($self, \&OnPaint);
EVT_UPDATE_UI($self, $self, \&OnPaint);
return $self;
}
sub SetEditmode
{
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
{
my $self = shift;
my $dc = shift;
my $window = $self->{selectedwindow};
my ($x, $y) = $window->GetPositionXY;
my $size = $window->GetSize;
my ($xsize, $ysize) = ($size->GetWidth, $size->GetHeight);
$dc->BeginDrawing;
$dc->SetBrush(wxTRANSPARENT_BRUSH);
$dc->SetPen(Wx::Pen->new($self->{setselection} ? $self->SelectColour :
$self->BackgroundColour, $self->{selectionborder}, wxSOLID));
$dc->DrawRoundedRectangle($x-($self->{itemspacing}/2-1), $y-($self->{itemspacing}/2-1), $xsize+($self->{itemspacing}/2+1), $ysize+($self->{itemspacing}/2+1), $self->RoundCornerRadius);
$dc->EndDrawing;
}
sub SetSelectionBorder
{
my $self = shift;
$self->{selectedwindow} = shift;
$self->{setselection} = 1;
my $dc = Wx::WindowDC->new($self->{selectedwindow}->GetParent);
$self->DrawBorder($dc);
}
sub SetNormalBorder
{
my $self = shift;
$self->{selectedwindow} = shift;
$self->{setselection} = 0;
my $dc = Wx::WindowDC->new($self->{selectedwindow}->GetParent);
$self->DrawBorder($dc);
}
sub RoundCornerRadius
{
my $self = shift;
$self->{radius} = shift || $self->{radius};
return $self->{radius};
}
sub xsize
{
my $self = shift;
$self->{xsize} = shift || $self->{xsize};
return $self->{xsize}-2*$self->RoundCornerRadius;
}
sub ysize
{
my $self = shift;
$self->{ysize} = shift || $self->{ysize};
return $self->{ysize}-2*$self->RoundCornerRadius;
}
sub lastrow
{
my $self = shift;
return $self->{lastrow};
}
sub SelectColour
{
my $self = shift;
$self->{selectcolour} = shift || $self->{selectcolour};
return $self->{selectcolour};
}
sub BackgroundColour
{
my $self = shift;
$self->{backgroundcolour} = shift || $self->{backgroundcolour};
return $self->{backgroundcolour};
}
sub DrawBackground
{
my $self = shift;
my $dc = shift;
$dc->SetBrush(Wx::Brush->new($self->BackgroundColour, wxSOLID));
$dc->SetPen(Wx::Pen->new($self->BackgroundColour, 1, wxSOLID));
$dc->DrawRoundedRectangle(0,0,$self->{realx}, $self->{realy}, $self->RoundCornerRadius);
}
sub AddTitle
{
my ($self, $title) = @_;
return if $self->{disabletitle};
my $titleupdate = exists $self->{title};
if ($titleupdate)
{
$self->{tls}->Remove($self->{title});
}
# Create the TextControl
$self->{title} = Wx::StaticText->new( $self,
-1,
$title,
wxDefaultPosition,
wxDefaultSize,
wxALIGN_CENTRE);
$self->TitleFont();
# Don't use 'Add' here...the title should be on top!!
$self->{tls}->Prepend($self->{title},0, wxALIGN_CENTRE, 0);
}
sub TitleFont
{
my $self = shift;
$self->{titlefont} = shift || $self->{titlefont};
return if not $self->{titlefont};
$self->{title}->SetFont($self->{titlefont}) if $self->{title};
return $self->{titlefont};
}
sub Append
{
my $self = shift;
my $row = shift;
my $unselectable = shift;
$self->{tls}->Add($row, # what to add
0, # unused
wxALIGN_CENTRE, # style
0); # padding
# setup the input event handling unless we're in editmode
lib/AAC/Pvoice/Panel.pm view on Meta::CPAN
}
}
}
$self->{totalrows}++ if not $unselectable;
$self->{lastrow}++;
push @{$self->{rows}}, $row if not $unselectable;
push @{$self->{unselectablerows}}, $row if $unselectable;
}
sub PauseInput
{
my $self = shift;
my $bool = shift;
$self->{input}->PauseMonitor($bool);
$self->{input}->PauseAutoscan($bool);
$self->{input}->Pause($bool);
}
sub Clear
{
my $self = shift;
$self->{tls}->Remove($_) for (0..$self->{lastrow});
foreach my $row (@{$self->{rows}})
{
$_->Destroy for $row->GetChildren();
$row->Destroy
}
$_->Destroy for @{$self->{unselectablerows}};
$self->{text}->Destroy if exists $self->{text};
$self->{title}->Destroy if exists $self->{title};
$self->{rows} = [];
$self->{unselectablerows} = [];
$self->SUPER::Clear();
$self->{totalrows} = 0;
$self->{lastrow} = 0;
$self->Refresh;
}
sub Finalize
{
my $self = shift;
my $dc = Wx::WindowDC->new($self);
$self->DrawBackground($dc);
unless ($self->{disabletextrow})
{
# Create the TextControl
my $font = Wx::Font->new( 24, # font size
wxSWISS, # font family
lib/AAC/Pvoice/Panel.pm view on Meta::CPAN
# Select the first row
$self->{selectedrow} = 0;
$self->{selecteditem} = 0;
$self->SetSelectionBorder($self->{rows}->[$self->{selectedrow}]) if $self->{rowcolumnscanning} && not $self->{editmode};
$self->{rowselection} = 1;
$self->Refresh;
$self->Update();
$self->{unfinished} = 0;
}
sub Next
{
my $self = shift;
return if ($self->{editmode} || $self->{unfinished});
$self->{input}->QuitAutoscan;
if ($self->{rowselection})
{
$self->SetNormalBorder($self->{rows}->[$self->{selectedrow}]) if $self->{rowcolumnscanning};
if ($self->{selectedrow} < ($self->{totalrows}-1))
{
$self->{selectedrow}++;
lib/AAC/Pvoice/Panel.pm view on Meta::CPAN
}
else
{
$self->{selecteditem} = 0;
}
$self->SetSelectionBorder($self->{rows}->[$self->{selectedrow}]->{items}->[$self->{selecteditem}]) if $self->{rowcolumnscanning};
}
$self->{input}->StartAutoscan;
}
sub Select
{
my $self = shift;
return if $self->{editmode};
$self->{input}->QuitAutoscan;
if (($self->{rowselection}) && (@{$self->{rows}->[$self->{selectedrow}]->{items}} == 1))
{
$self->{rowselection} = 0;
$self->{selecteditem} = 0;
}
if ($self->{rowselection})
lib/AAC/Pvoice/Panel.pm view on Meta::CPAN
{
$self->SetNormalBorder($self->{rows}->[$self->{selectedrow}]->{items}->[$self->{selecteditem}]) if $self->{rowcolumnscanning};
$self->SetSelectionBorder($self->{rows}->[$self->{selectedrow}]) if $self->{rowcolumnscanning};
&{$self->{rows}->[$self->{selectedrow}]->{actions}->[$self->{selecteditem}]};
$self->{rowselection} = 1;
}
$self->{input}->StartAutoscan;
}
sub ToRowSelection
{
my $self = shift;
return if $self->{editmode};
$self->SetNormalBorder($self->{rows}->[$self->{selectedrow}]->{items}->[$self->{selecteditem}]) if $self->{rowcolumnscanning};
$self->SetSelectionBorder($self->{rows}->[$self->{selectedrow}]) if $self->{rowcolumnscanning};
$self->{rowselection} = 1;
}
sub DisplayAddText
{
my $self = shift;
push @{$self->{displaytextsave}}, $_[0];
$self->{text}->AppendText($_[0]);
$self->{text}->Refresh(); # Added to test it on the Mercury...added text
# isn't visible there...
}
sub SpeechAddText
{
my $self = shift;
push @{$self->{speechtextsave}}, $_[0];
}
sub RetrieveText
{
my $self = shift;
return wantarray ? @{$self->{displaytextsave}} : join('', @{$self->{displaytextsave}});
}
sub ClearText
{
my $self = shift;
$self->{displaytextsave}=[];
$self->{speechtextsave}=[];
$self->{text}->SetValue('');
$self->{text}->Refresh(); # Added to test it on the Mercury...added text
# isn't visible there...
}
sub BackspaceText
{
my $self = shift;
pop @{$self->{displaytextsave}};
pop @{$self->{speechtextsave}};
$self->{text}->SetValue(my $x = $self->RetrieveText);
$self->{text}->SetStyle(0, length($self->{text}->GetValue), $self->{ta});
$self->{text}->Refresh(); # Added to test it on the Mercury...added text
# isn't visible there...
}
sub SpeechRetrieveText
{
my $self = shift;
return wantarray ? @{$self->{speechtextsave}} : join('', @{$self->{speechtextsave}});
}
1;
__END__
=pod
lib/AAC/Pvoice/Row.pm view on Meta::CPAN
use strict;
use warnings;
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,
t/001_load.t view on Meta::CPAN
# more testing will be added later
use Test::More tests => 2;
use Wx qw(:everything);
BEGIN { use_ok( 'AAC::Pvoice' ); }
package MyApp;
use base 'Wx::App';
sub OnInit
{
my $frame = MyFrame->new();
return 1;
}
package MyFrame;
use base 'Wx::Frame';
sub new
{
my $class = shift;
my $self = $class->SUPER::new(undef, -1, 'Test');
my $panel = AAC::Pvoice::Panel->new ($self, -1);
main::isa_ok ($panel, 'AAC::Pvoice::Panel');
return $self;
}
package main;