« lib/Games/Sudoku/Component/TkPlayer/Selector.pm
↑ Summary
lib/Games/Sudoku/Component/TkPlayer/View.pm »
| 1 | package Games::Sudoku::Component::TkPlayer::Splashscreen; | ||
| 2 | { | ||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 0 | ▶ | use Tk::widgets qw/Toplevel/; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | use base qw/Tk::Toplevel/; | ||
| 9 | |||
| 10 | Construct Tk::Widget 'Splashscreen'; | ||
| 11 | |||
| 12 | use Tk::ProgressBar; | ||
| 13 | |||
| 14 | sub Populate { | ||
| 15 | my $this = shift; | ||
| 16 | |||
| 17 | $this->withdraw; | ||
| 18 | $this->geometry('300x50+0+0'); | ||
| 19 | $this->overrideredirect(1); | ||
| 20 | |||
| 21 | $this->SUPER::Populate(@_); | ||
| 22 | |||
| 23 | $this->Label( | ||
| 24 | -text => 'Loading...', | ||
| 25 | )->pack( | ||
| 26 | -fill => 'x', | ||
| 27 | -expand => 1, | ||
| 28 | ); | ||
| 29 | $this->{pbar} = $this->ProgressBar( | ||
| 30 | -anchor => 'w', | ||
| 31 | -colors => [0, 'blue'], | ||
| 32 | )->pack( | ||
| 33 | -side => 'top', | ||
| 34 | -fill => 'x', | ||
| 35 | -padx => 10, | ||
| 36 | -pady => 10, | ||
| 37 | ); | ||
| 38 | } | ||
| 39 | |||
| 40 | sub progress { | ||
| 41 | my ($this, $value) = @_; | ||
| 42 | |||
| 43 | $this->{pbar}->value($value); | ||
| 44 | } | ||
| 45 | |||
| 46 | sub Show { | ||
| 47 | my ($this, %args) = @_; | ||
| 48 | |||
| 49 | $this->{pbar}->configure( | ||
| 50 | -blocks => int($args{-max} / 5), | ||
| 51 | -to => $args{-max}, | ||
| 52 | ); | ||
| 53 | |||
| 54 | $this->{old_focus} = $this->focusSave; | ||
| 55 | $this->{old_grab} = $this->grabSave; | ||
| 56 | |||
| 57 | $this->transient($this->Parent->toplevel); | ||
| 58 | |||
| 59 | $this->Popup( | ||
| 60 | -popover => $this->Parent, | ||
| 61 | -overanchor => 'c', | ||
| 62 | -popanchor => 'se', | ||
| 63 | ); | ||
| 64 | |||
| 65 | $this->grab; | ||
| 66 | |||
| 67 | if (my $focusw = $this->cget(-focus)) { | ||
| 68 | $focusw->focus; | ||
| 69 | } | ||
| 70 | else { | ||
| 71 | $this->focus; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | sub Hide { | ||
| 76 | my $this = shift; | ||
| 77 | |||
| 78 | $this->grabRelease; | ||
| 79 | |||
| 80 | $this->{old_focus}->(); | ||
| 81 | $this->{old_grab}->(); | ||
| 82 | |||
| 83 | $this->withdraw; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | 1; | ||
| 88 | |||
| 89 | __END__ | ||