| 1 | package Wx::App::AnnualCal::MyFrame; | ||
| 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 feature qw(switch); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 0 | ▶ | use Wx 0.990 qw(wxICON_ERROR wxTheApp wxID_OK |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | 0 | :font :sizer :dialog :textctrl :button); | |
| 9 | use Wx::Event qw(EVT_BUTTON); | ||
| 10 | use base qw(Wx::Frame); | ||
| 11 | |||
| 12 | use Date::Calc 6.3 qw(Today Month_to_Text); | ||
| 13 | use Readonly 1.03; | ||
| 14 | |||
| 15 | use lib qw(../../../../lib); | ||
| 16 | use Wx::App::AnnualCal::MonthSizer; | ||
| 17 | |||
| 18 | ################################################## | ||
| 19 | |||
| 20 | sub new | ||
| 21 | { | ||
| 22 | my $class = shift; | ||
| 23 | my $self = $class->SUPER::new(@_); | ||
| 24 | |||
| 25 | my $panel = Wx::Panel->new($self); | ||
| 26 | $panel->SetBackgroundColour(Wx::Colour->new('black')); | ||
| 27 | |||
| 28 | my ($yr, $mon, $day) = Today(0); | ||
| 29 | my $current = {'day' => $day, 'month' => Month_to_Text($mon), 'year' => $yr}; | ||
| 30 | |||
| 31 | my $day_names = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']; | ||
| 32 | |||
| 33 | my $fonts = {'norm' => Wx::Font->new(9, wxFONTFAMILY_MODERN, | ||
| 34 | wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL), | ||
| 35 | 'ital' => Wx::Font->new(9, wxFONTFAMILY_MODERN, | ||
| 36 | wxFONTSTYLE_ITALIC, wxFONTWEIGHT_BOLD), | ||
| 37 | 'emph' => Wx::Font->new(10, wxFONTFAMILY_MODERN, | ||
| 38 | wxFONTSTYLE_ITALIC, wxFONTWEIGHT_BOLD), | ||
| 39 | 'bold' => Wx::Font->new(12, wxFONTFAMILY_MODERN, | ||
| 40 | wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD), | ||
| 41 | }; | ||
| 42 | |||
| 43 | my $colors = {'gold' => Wx::Colour->new(255,215,0), | ||
| 44 | 'gray' => Wx::Colour->new(100,100,100)}; | ||
| 45 | |||
| 46 | my $year = $ARGV[0] || $current->{year}; | ||
| 47 | if ($year =~ /\A[0-9]+\Z/x and 1 <= $year and $year <= 32767) | ||
| 48 | { | ||
| 49 | chomp($year); | ||
| 50 | } | ||
| 51 | else | ||
| 52 | { | ||
| 53 | Wx::MessageBox('Enter a year between 1 and 32767.', 'ERROR', | ||
| 54 | wxICON_ERROR|wxOK); | ||
| 55 | exit(0); | ||
| 56 | } | ||
| 57 | |||
| 58 | $self->{param} = {'current' => $current, 'day_names' => $day_names, | ||
| 59 | 'fonts' => $fonts, 'panel' => $panel, 'year' => $year, | ||
| 60 | 'colors' => $colors}; | ||
| 61 | |||
| 62 | Readonly my %IDS => (PRIOR_BUTTON => 1001, | ||
| 63 | NEXT_BUTTON => 1002, | ||
| 64 | ANY_BUTTON => 1003, | ||
| 65 | EXIT_BUTTON => 1004, | ||
| 66 | ); | ||
| 67 | |||
| 68 | my $priorbtn = Wx::Button->new($panel, # parent window | ||
| 69 | $IDS{PRIOR_BUTTON}, # id | ||
| 70 | ' < ', # label | ||
| 71 | [-1,-1], # default location | ||
| 72 | [-1,-1], # default size | ||
| 73 | wxBU_EXACTFIT, # minimum size | ||
| 74 | ); | ||
| 75 | $self->{priorbtn} = $priorbtn; | ||
| 76 | $priorbtn->SetFont($fonts->{bold}); | ||
| 77 | $priorbtn->SetForegroundColour(Wx::Colour->new('green')); | ||
| 78 | $priorbtn->SetBackgroundColour($colors->{'gray'}); | ||
| 79 | ($year == 1) ? $priorbtn->Enable(0) : $priorbtn->Enable(1); | ||
| 80 | EVT_BUTTON($self, $IDS{PRIOR_BUTTON}, \&ClickPRIOR); | ||
| 81 | |||
| 82 | my $yeartxt = Wx::TextCtrl->new($panel, | ||
| 83 | -1, | ||
| 84 | $year, | ||
| 85 | [-1,-1], | ||
| 86 | [-1,-1], | ||
| 87 | wxTE_CENTRE|wxTE_READONLY, | ||
| 88 | ); | ||
| 89 | $yeartxt->SetFont($fonts->{bold}); | ||
| 90 | $yeartxt->SetForegroundColour(Wx::Colour->new('black')); | ||
| 91 | $yeartxt->SetBackgroundColour($colors->{'gold'}); | ||
| 92 | $self->{yeartxt} = $yeartxt; | ||
| 93 | |||
| 94 | my $nextbtn = Wx::Button->new($panel, # parent window | ||
| 95 | $IDS{NEXT_BUTTON}, # id | ||
| 96 | ' > ', # label | ||
| 97 | [-1,-1], # default location | ||
| 98 | [-1,-1], # default size | ||
| 99 | wxBU_EXACTFIT, # minimum size | ||
| 100 | ); | ||
| 101 | $self->{nextbtn} = $nextbtn; | ||
| 102 | $nextbtn->SetFont($fonts->{bold}); | ||
| 103 | $nextbtn->SetForegroundColour(Wx::Colour->new('green')); | ||
| 104 | $nextbtn->SetBackgroundColour($colors->{'gray'}); | ||
| 105 | ($year == 32767) ? $nextbtn->Enable(0) : $nextbtn->Enable(1); | ||
| 106 | EVT_BUTTON($self, $IDS{NEXT_BUTTON}, \&ClickNEXT); | ||
| 107 | |||
| 108 | my $anybtn = Wx::Button->new($panel, # parent window | ||
| 109 | $IDS{ANY_BUTTON}, # id | ||
| 110 | 'ANY YEAR', # label | ||
| 111 | ); | ||
| 112 | $anybtn->SetFont($fonts->{bold}); | ||
| 113 | $anybtn->SetForegroundColour(Wx::Colour->new('green')); | ||
| 114 | $anybtn->SetBackgroundColour($colors->{'gray'}); | ||
| 115 | EVT_BUTTON($self, $IDS{ANY_BUTTON}, \&ClickANY); | ||
| 116 | |||
| 117 | my $exitbtn = Wx::Button->new($panel, # parent window | ||
| 118 | $IDS{EXIT_BUTTON}, # id | ||
| 119 | 'EXIT' # label | ||
| 120 | ); | ||
| 121 | $exitbtn->SetFont($fonts->{bold}); | ||
| 122 | $exitbtn->SetForegroundColour(Wx::Colour->new('white')); | ||
| 123 | $exitbtn->SetBackgroundColour(Wx::Colour->new('red')); | ||
| 124 | EVT_BUTTON($self, $IDS{EXIT_BUTTON}, sub {wxTheApp->ExitMainLoop()}); | ||
| 125 | |||
| 126 | my $lowersizer = Wx::BoxSizer->new(wxHORIZONTAL); | ||
| 127 | $lowersizer->AddSpacer(20); | ||
| 128 | $lowersizer->Add($anybtn, # button control | ||
| 129 | 1, # unit length | ||
| 130 | wxBOTTOM| # bottom border | ||
| 131 | wxALIGN_CENTER, # central alignment | ||
| 132 | 20, # border width | ||
| 133 | ); | ||
| 134 | $lowersizer->AddSpacer(30); | ||
| 135 | $lowersizer->Add($priorbtn, # button control | ||
| 136 | 0, # exact fit | ||
| 137 | wxBOTTOM| # bottom border | ||
| 138 | wxALIGN_CENTER, # central alignment | ||
| 139 | 20, # border width | ||
| 140 | ); | ||
| 141 | $lowersizer->Add($yeartxt, # text control | ||
| 142 | 1.5, # proportional length | ||
| 143 | wxBOTTOM| # bottom border | ||
| 144 | wxALIGN_CENTER, # central alignment | ||
| 145 | 20, # border width | ||
| 146 | ); | ||
| 147 | $lowersizer->Add($nextbtn, # button control | ||
| 148 | 0, # exact fit | ||
| 149 | wxBOTTOM| # bottom border | ||
| 150 | wxALIGN_CENTER, # central alignment | ||
| 151 | 20, # border width | ||
| 152 | ); | ||
| 153 | $lowersizer->AddSpacer(30); | ||
| 154 | $lowersizer->Add($exitbtn, # button control | ||
| 155 | 1, # unit length | ||
| 156 | wxBOTTOM| # bottom border | ||
| 157 | wxALIGN_CENTER, # central alignment | ||
| 158 | 20, # border width | ||
| 159 | ); | ||
| 160 | $lowersizer->AddSpacer(20); | ||
| 161 | |||
| 162 | $self->{lowersizer} = $lowersizer; | ||
| 163 | |||
| 164 | return($self); | ||
| 165 | } | ||
| 166 | |||
| 167 | ################################################## | ||
| 168 | |||
| 169 | sub build | ||
| 170 | { | ||
| 171 | my $self = shift; | ||
| 172 | my $panel = $self->{param}->{panel}; | ||
| 173 | my $year = $self->{param}->{year}; | ||
| 174 | |||
| 175 | my $ms = Wx::App::AnnualCal::MonthSizer->new($self->{param}); | ||
| 176 | |||
| 177 | my $gridsizer = Wx::GridSizer->new(3,4,0,0); | ||
| 178 | map { $gridsizer->Add($ms->getmonthsizer($_)) } (0..11); | ||
| 179 | $self->{gridsizer} = $gridsizer; | ||
| 180 | |||
| 181 | my $margin = Wx::Panel->new($self, -1, [-1,-1], [13,-1]); | ||
| 182 | $margin->SetBackgroundColour(Wx::Colour->new('black')); | ||
| 183 | $self->{margin} = $margin; | ||
| 184 | |||
| 185 | my $uppersizer = Wx::BoxSizer->new(wxHORIZONTAL); | ||
| 186 | $uppersizer->Add($margin); | ||
| 187 | $uppersizer->Add($gridsizer); | ||
| 188 | $self->{uppersizer} = $uppersizer; | ||
| 189 | |||
| 190 | my $panelsizer = Wx::BoxSizer->new(wxVERTICAL); | ||
| 191 | $panelsizer->Add($uppersizer); | ||
| 192 | $panelsizer->Add($self->{lowersizer},1,wxGROW); | ||
| 193 | |||
| 194 | $panel->SetSizer($panelsizer); | ||
| 195 | |||
| 196 | my $framesizer = Wx::BoxSizer->new(wxVERTICAL); | ||
| 197 | $framesizer->Add($panel); | ||
| 198 | $self->SetSizerAndFit($framesizer); | ||
| 199 | |||
| 200 | return(1); | ||
| 201 | } | ||
| 202 | |||
| 203 | ################################################## | ||
| 204 | |||
| 205 | sub update | ||
| 206 | { | ||
| 207 | my $self = shift; | ||
| 208 | |||
| 209 | my $ms = Wx::App::AnnualCal::MonthSizer->new($self->{param}); | ||
| 210 | |||
| 211 | my $gridsizer = Wx::GridSizer->new(3,4,0,0); | ||
| 212 | map { $gridsizer->Add($ms->getmonthsizer($_)) } (0..11); | ||
| 213 | |||
| 214 | my $uppersizer = $self->{uppersizer}; | ||
| 215 | $uppersizer->Detach(1); | ||
| 216 | $uppersizer->Add($gridsizer); | ||
| 217 | $uppersizer->Layout(); | ||
| 218 | |||
| 219 | my $yeartxt = $self->{yeartxt}; | ||
| 220 | $yeartxt->Clear(); | ||
| 221 | $yeartxt->ChangeValue($self->{param}->{year}); | ||
| 222 | |||
| 223 | return(1); | ||
| 224 | } | ||
| 225 | |||
| 226 | ################################################## | ||
| 227 | |||
| 228 | sub ClickPRIOR | ||
| 229 | { | ||
| 230 | my $self = shift; | ||
| 231 | my $year = $self->{param}->{year} - 1; | ||
| 232 | $self->{param}->{year} = $year; | ||
| 233 | |||
| 234 | $self->{nextbtn}->Enable(1); | ||
| 235 | ($year == 1) ? $self->{priorbtn}->Enable(0) : $self->{priorbtn}->Enable(1); | ||
| 236 | |||
| 237 | $self->update(); | ||
| 238 | return; | ||
| 239 | } | ||
| 240 | |||
| 241 | ################################################## | ||
| 242 | |||
| 243 | sub ClickNEXT | ||
| 244 | { | ||
| 245 | my $self = shift; | ||
| 246 | my $year = $self->{param}->{year} + 1; | ||
| 247 | $self->{param}->{year} = $year; | ||
| 248 | |||
| 249 | $self->{priorbtn}->Enable(1); | ||
| 250 | ($year == 32767) ? $self->{nextbtn}->Enable(0) : $self->{nextbtn}->Enable(1); | ||
| 251 | |||
| 252 | $self->update(); | ||
| 253 | return; | ||
| 254 | } | ||
| 255 | |||
| 256 | ################################################## | ||
| 257 | |||
| 258 | sub ClickANY | ||
| 259 | { | ||
| 260 | my $self = shift; | ||
| 261 | my $dlg = Wx::TextEntryDialog->new($self, 'Enter a year between 1 and 32767.', | ||
| 262 | 'USER INPUT', '', wxOK|wxCANCEL); | ||
| 263 | my $ans = $dlg->ShowModal(); | ||
| 264 | if ($ans == wxID_OK) | ||
| 265 | { | ||
| 266 | my $year = $dlg->GetValue(); | ||
| 267 | if ($year =~ /\A[0-9]+\Z/x and 1 <= $year and $year <= 32767) | ||
| 268 | { | ||
| 269 | $self->{param}->{year} = $year; | ||
| 270 | } | ||
| 271 | else | ||
| 272 | { | ||
| 273 | $dlg->Destroy(); | ||
| 274 | Wx::MessageBox("$year is invalid.", 'ERROR', wxICON_ERROR|wxOK); | ||
| 275 | } | ||
| 276 | } | ||
| 277 | else | ||
| 278 | { | ||
| 279 | $dlg->Destroy(); | ||
| 280 | } | ||
| 281 | |||
| 282 | my $year = $self->{param}->{year}; | ||
| 283 | given ($year) | ||
| 284 | { | ||
| 285 | when (1) | ||
| 286 | { | ||
| 287 | $self->{priorbtn}->Enable(0); | ||
| 288 | $self->{nextbtn}->Enable(1); | ||
| 289 | } | ||
| 290 | when (32767) | ||
| 291 | { | ||
| 292 | $self->{priorbtn}->Enable(1); | ||
| 293 | $self->{nextbtn}->Enable(0); | ||
| 294 | } | ||
| 295 | default | ||
| 296 | { | ||
| 297 | $self->{nextbtn}->Enable(1); | ||
| 298 | $self->{priorbtn}->Enable(1); | ||
| 299 | } | ||
| 300 | } | ||
| 301 | $self->update(); | ||
| 302 | return; | ||
| 303 | } | ||
| 304 | |||
| 305 | # * * * | ||
| 306 | # | ||
| 307 | # Input for Dist::Zilla::Pod::Weaver plugin to create POD documentation. | ||
| 308 | # | ||
| 309 | # * * * | ||
| 310 | |||
| 311 | #ABSTRACT: a module in the AnnualCal distribution | ||
| 312 | |||
| 313 | 1; | ||
| 314 | |||
| 315 | __END__ | ||