App-PLab
view release on metacpan or search on metacpan
lib/App/PLab/ImageApp.pm view on Meta::CPAN
{
my ( $self, $code, $key, $mod) = @_;
my $iv = $self->IV;
if ( $key == kb::Esc) {
if ( $iv-> {transaction}) {
$self-> iv_cancelmode( $iv);
$self-> clear_event;
return;
}
}
$self-> clear_event if $iv-> {transaction};
}
sub on_deactivate
{
my ( $self) = @_;
$self-> iv_cancelmode( $self-> IV);
}
sub on_mousewheel
{
my ( $self, $mod, $x, $y, $z) = @_;
$self = $self-> IV;
return if $self->{transaction};
$z = int( $z / 120);
my $xv = ( $mod & km::Shift) ? $self-> VScroll : $self-> HScroll;
$z *= ( $mod & km::Ctrl) ? $xv-> step : $xv-> pageStep;
if ( $mod & km::Shift) {
$self-> deltaX( $self-> deltaX - $z);
} else {
$self-> deltaY( $self-> deltaY - $z);
}
}
sub on_create
{
my $w = $_[0];
my $uname = lc(Prima::Utils::username() || '');
$uname .= '.' if $uname;
my @iniDefaults = $w-> win_inidefaults();
my $keys = $w-> opt_keys;
my $colors = $w-> opt_colors;
push ( @iniDefaults,
map {
( "Key_$_", "'" . $keys->{$_}->[0] . "'")
} keys %$keys);
push( @iniDefaults,
map {
( "Color_$_", $w-> ini_makecolor( $colors->{$_}->[0]))
} keys %$colors);
$w->{iniFile} = Prima::IniFile-> create(
file => Prima::Utils::path('PLabApps'),
default => [
$uname.$::application->name => \@iniDefaults,
]
);
my $i;
$w-> {uname} = $uname;
$i = $w-> {ini} = $w-> {iniFile}-> section( $uname.$::application->name);
$w-> {keyMappings} = { map { $_ => Prima::AbstractMenu-> translate_shortcut( eval($i-> {$_})); }
grep { m/^Key_/ } keys %$i };
$i->{"Color_$_"} = eval( $i->{"Color_$_"}) for keys %$colors;
my @rc = split ' ', $i->{WindowRect};
my @ac = $::application-> rect;
$ac[3] -= $::application-> get_system_value( sv::YMenu) * 3 + $::application-> get_system_value( sv::YTitleBar);
$rc[0] = 0 if $rc[0] >= $ac[2];
$rc[1] = 0 if $rc[1] >= $ac[3];
$rc[3] = $ac[3] if $rc[3] >= $ac[3];
$w-> rect(@rc);
$w-> {cypherMask} = ( lc $w->{ini}->{SerType} eq 'long') ? 3 : 2;
-d $w-> {ini}-> {path} or $w-> {ini}-> {path} = '.';
$w-> {ini}-> {path} = eval {&Cwd::abs_path($w-> {ini}-> {path})};
$w-> {ini}-> {path} = '.' if $@;
$w-> {ini}-> {path} = '' unless -d $w-> {ini}-> {path};
$w-> maximize if $i->{MaxState};
$w-> insert( Popup =>
auto => 0,
selected => 0,
name => 'LoadSeriesPopup',
items => [['' => '']],
);
$::application-> showHint( $w-> {ini}-> {showHint});
$w-> winmenu_updatemappings;
}
sub on_destroy
{
my ($w,$i) = ($_[0],$_[0]->{ini});
$i->{MaxState} = $w-> windowState == ws::Maximized;
$w-> windowState(ws::Normal) if $i->{MaxState};
my @rc = $w-> rect;
$i->{WindowRect} = "@rc";
$i->{SerType} = ( $w->{cypherMask} == 2) ? 'Short' : 'Long';
$i-> {$_} = Prima::KeySelector::shortcut( $w-> {keyMappings}->{$_})
for keys %{$w->{keyMappings}};
my $optColors = $w-> opt_colors;
$i-> {"Color_$_"} = $w-> ini_makecolor( $i-> {"Color_$_"}) for keys %$optColors;
$::application-> close;
}
sub on_close
{
my ($w,$i) = ($_[0],$_[0]->{ini});
$w-> clear_event unless $w-> win_closefile;
}
sub win_inidefaults
{
my $w = $_[0];
my @rc = $w-> rect;
return (
path => '.',
WindowRect => "@rc",
MaxState => 0,
SerType => 'Short',
extSaveDir => '',
silentExtDir => 0,
dirTimeout => 120,
statusDelay => 5,
showHint => 1,
);
}
lib/App/PLab/ImageApp.pm view on Meta::CPAN
origin => [ 220, 110],
size => [ 150, 170],
name => 'KeySelector',
visible => 0,
onChange => sub {
return if $w-> {keyMappings_change};
my $kl = $nbpages-> KeyList;
my ( $item, $lev) = $kl-> get_item( $kl-> focusedItem);
return unless $item;
my $okey = $kl-> get_item_text( $item);
my $key = "Key_$okey";
my $value = $_[0]-> key;
if ( $value != kb::NoKey) {
for ( keys %{$w-> {keyMappings}}) {
next if $_ eq $key;
next unless $value == $w-> {keyMappings}->{$_};
s/^Key_//;
$w-> {keyMappings_change} = 1;
$_[0]-> key( $w-> {keyMappings}->{$key});
delete $w-> {keyMappings_change};
my $l = $nbpages-> KeyDescription;
$l-> backColor( cl::LightRed);
$l-> color( cl::Yellow);
$l-> text( "This key combination is already occupied by $_ and cannot be used");
$l-> insert( Timer => timeout => 100 => onTick => sub {
$l-> backColor( cl::Back);
$l-> color( cl::Fore);
$_[0]-> destroy;
})-> start;
return;
}
}
$w-> {keyMappings}->{$key} = $value;
$nbpages-> KeyDescription-> text( $optKeys-> {$okey}-> [1] );
},
], [ Label =>
origin => [ 220, 10],
size => [ 150, 100],
autoWidth => 0,
autoHeight => 0,
text => '',
name => 'KeyDescription',
wordWrap => 1,
], [ Button =>
origin => [ 10, 10],
size => [96, 36],
text => '~Clear',
hint => 'Clears the key',
onClick => sub {
$nbpages-> KeySelector-> key( kb::NoKey);
},
] , [ Button =>
origin => [ 114, 10],
size => [96, 36],
text => '~Default',
hint => 'Set default value for a key',
onClick => sub {
my $kl = $nbpages-> KeyList;
my ( $item, $lev) = $kl-> get_item( $kl-> focusedItem);
return unless $item;
$nbpages-> KeySelector-> key( Prima::AbstractMenu-> translate_shortcut(
$w-> opt_keys()-> {$kl-> get_item_text( $item)}-> [0]));
},
] );
$nbpages-> KeyList-> focusedItem(0);
}
sub opt_proppush
{
my ( $w, $dlg, $nb, $nbpages) = @_;
# General
$nbpages->RG_SeriesType-> RG_Short-> checked( $w-> {cypherMask} == 2);
$nbpages->RG_SeriesType-> RG_Long -> checked( $w-> {cypherMask} == 3);
$dlg->{page0}->{extSaveDir} = $w->{ini}->{extSaveDir};
$nbpages-> UseDef-> checked( length($w->{ini}->{extSaveDir}) ? 0 : 1);
$nbpages-> Path-> enabled(( length( $w->{ini}->{extSaveDir}) > 0) ? 1 : 0);
$nbpages-> Path-> text( length($w->{ini}->{extSaveDir}) ? $w->{ini}->{extSaveDir} : '.');
$nbpages-> StatusDelay-> value( $w->{ini}->{statusDelay});
# Colors
$nbpages-> ShowHint-> checked( $w-> {ini}-> {showHint});
my $optColors = $w-> opt_colors;
my @colors = map { $w-> {ini}->{"Color_$_"}} sort keys %$optColors;
$dlg-> {page2}-> {csave} = { map { ( "Color_$_", $w-> {ini}->{"Color_$_"}) } keys %$optColors};
$dlg-> {page2}-> {colors} = [ @colors ];
if ( scalar @colors) {
$nbpages-> NameSel-> focusedItem( defined $w->{nameSelFoc} ? $w->{nameSelFoc} : 0);
$nbpages-> ColorSel-> value( $colors[ $nbpages-> NameSel-> focusedItem]);
}
# Keys
$w-> {keyMappings_save} = { %{ $w-> {keyMappings}} };
}
sub opt_propvalid
{
my ( $w, $dlg, $nb, $nbpages) = @_;
# General
unless ( $nbpages-> UseDef-> checked) {
unless ( -d $nbpages-> Path-> text) {
$nb-> pageIndex(0);
return 0 if Prima::MsgBox::message_box( "External save path",
"Unexistent directory: ".$nbpages-> Path-> text.
"\nDo you want to use it anyway?",
mb::YesNo|mb::Warning) != mb::Yes;
}
}
return 1;
}
sub opt_proppop
{
my ( $w, $dlg, $nb, $nbpages, $mr) = @_;
if ( $mr) {
# General
my $x = $nbpages-> Path-> text;
$x =~ s/^\s+//;
$x =~ s/\s+$//;
if ( $x eq '.' || $x eq '..' || length( $x) == 0) {
$nbpages-> UseDef-> check;
}
( run in 1.288 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )