1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
|
#!/usr/bin/perl -w --
# Filename: galbum
# Author: David Ljung Madison <DaveSource.com>
# See License: http://MarginalHacks.com/License/
my $VERSION= '1.01';
#
# Description: GUI front-end to MarginalHacks album script
# Uses album output to create option pages
# (so new album options are automatically available to galbum)
# Uses configuration settings in album.conf files
#
# Bugs: Cannot remove array options (such as -lang, -exif, ..)
# This is due to the fact that album doesn't handle losing array
# options very well (due to the fact that they might have come
# from the global album.conf or a parent album, something we can't
# really change)
#
# Hotkey control-Q to quit usually only works with some delay
# between control and Q. wxPerl doesn't support FilterEvent?
#
##################################################
# generated by wxGlade 0.6.3 on Thu Jul 10 19:53:49 2008
# To get wxPerl visit http://wxPerl.sourceforge.net/
##################################################
use IO::File;
##################################################
# Issues
##################################################
# - Changes to array options are not handled well
# They are only additive. This is actually a
# difficulty in "album" itself
# - one_time options get cleared everytime we generate.
# Is this desirable?
##################################################
# Settings
##################################################
sub about {
<<ABOUT;
This is galbum v$VERSION on $^O
Running album v$MAIN::ALBUM_VERSION
Copyright: (c) 2008 David Ljung Madison
Docs: http://MarginalHacks.com/Hacks/album/
License: http://MarginalHacks.com/License/
Please see: http://MarginalHacks.com/Pay/
Description:
'galbum' is a graphical interface that makes it easy to run 'album'
'album' is an HTML photo album generator.
It can make and maintain beautiful photo albums for you to display
on your website on to burn to a CD/DVD. It does not host your
albums for you, you will need to upload them to a website for that.
It has many themes/skins and many options for building, as well
as international language support. See the docs for more info.
Bugs: Cannot remove array options (such as -lang, -exif, ..)
This is due to the fact that album can't easily clear array options.
ABOUT
}
# The executable
my @ALBUM = ('album');
$MAIN::ALBUM_VERSION= '(unknown)';
my $CONVERT = 'convert';
my $OSX = ($^O =~ /darwin/i) ? 1 : 0;
my $WINDOWS = (!$OSX && ($^O =~ /Win/i)) ? 1 : 0;
my $WIN2K = ($^O =~ /MSWin32/i) ? 1 : 0;
my $CYGWIN = ($^O =~ /cygwin/i) ? 1 : 0;
if ($WINDOWS) {
@ALBUM = ('perl','album');
eval "use Win32::API";
die "couldn't load module : $!n" if ($@);
eval "use Win32API::File";
die "couldn't load module : $!n" if ($@);
}
##################################################
# wxGlade generated code (intertwined with my code)
##################################################
use Wx 0.15 qw[:allclasses];
use strict;
##################################################
# The main frame
##################################################
package MyFrame;
use Wx qw[:everything];
use base qw(Wx::Frame);
use strict;
sub new {
my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
$parent = undef unless defined $parent;
$id = -1 unless defined $id;
$title = "" unless defined $title;
$pos = wxDefaultPosition unless defined $pos;
$size = wxDefaultSize unless defined $size;
$name = "" unless defined $name;
# begin wxGlade: MyFrame::new
$style = wxDEFAULT_FRAME_STYLE
unless defined $style;
$self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name );
$self->{notebook_1} = Wx::Notebook->new($self, -1, wxDefaultPosition, wxDefaultSize, 0);
$self->{aboutPanel} = Wx::Panel->new($self->{notebook_1}, -1, wxDefaultPosition, wxDefaultSize, );
$self->{moreMoreOptionsPanel} = Wx::ScrolledWindow->new($self->{notebook_1}, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
$self->{moreOptionsPanel} = Wx::ScrolledWindow->new($self->{notebook_1}, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
$self->{optionsPanel} = Wx::ScrolledWindow->new($self->{notebook_1}, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
$self->{themePanel} = Wx::ScrolledWindow->new($self->{notebook_1}, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
$self->{albumPanel} = Wx::Panel->new($self->{notebook_1}, -1, wxDefaultPosition, wxDefaultSize, );
$self->{chooseDirectory} = Wx::Button->new($self->{albumPanel}, -1, "Choose Directory..");
$self->{albumPath} = Wx::TextCtrl->new($self->{albumPanel}, -1, "<path to album directory>", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
$self->{generateAlbum} = Wx::Button->new($self->{albumPanel}, -1, "Generate Album");
$self->{albumProgress} = Wx::Gauge->new($self->{albumPanel}, -1, 100, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL|wxGA_SMOOTH);
$self->{checkboxDescend} = Wx::CheckBox->new($self->{albumPanel}, -1, "Do subalbums", wxDefaultPosition, wxDefaultSize, );
$self->{checkboxAddToParent} = Wx::CheckBox->new($self->{albumPanel}, -1, "Add this album to parent directory", wxDefaultPosition, wxDefaultSize, );
$self->{progressText} = Wx::StaticText->new($self->{albumPanel}, -1, "", wxDefaultPosition, wxDefaultSize, );
$self->{optionlangOption} = Wx::StaticText->new($self->{albumPanel}, -1, "Languages:", wxDefaultPosition, wxDefaultSize, );
$self->{optionlangValue} = Wx::ListBox->new($self->{albumPanel}, -1, wxDefaultPosition, wxDefaultSize, [], wxLB_MULTIPLE);
$self->{optionthemeOption} = Wx::StaticText->new($self->{themePanel}, -1, "Theme:", wxDefaultPosition, wxDefaultSize, );
$self->{optionthemeValue} = Wx::Choice->new($self->{themePanel}, -1, wxDefaultPosition, wxDefaultSize, ["No-Theme"], );
$self->{label_1} = Wx::StaticText->new($self->{optionsPanel}, -1, "Option", wxDefaultPosition, wxDefaultSize, );
$self->{label_2} = Wx::StaticText->new($self->{optionsPanel}, -1, "Setting", wxDefaultPosition, wxDefaultSize, );
$self->{label_3} = Wx::StaticText->new($self->{optionsPanel}, -1, "Usage", wxDefaultPosition, wxDefaultSize, );
$self->{static_line_1} = Wx::StaticLine->new($self->{optionsPanel}, -1, wxDefaultPosition, wxDefaultSize, );
$self->{static_line_2} = Wx::StaticLine->new($self->{optionsPanel}, -1, wxDefaultPosition, wxDefaultSize, );
$self->{static_line_3} = Wx::StaticLine->new($self->{optionsPanel}, -1, wxDefaultPosition, wxDefaultSize, );
$self->{label_1_copy} = Wx::StaticText->new($self->{moreOptionsPanel}, -1, "Option", wxDefaultPosition, wxDefaultSize, );
$self->{label_2_copy} = Wx::StaticText->new($self->{moreOptionsPanel}, -1, "Setting", wxDefaultPosition, wxDefaultSize, );
$self->{label_3_copy} = Wx::StaticText->new($self->{moreOptionsPanel}, -1, "Usage", wxDefaultPosition, wxDefaultSize, );
$self->{static_line_1_copy} = Wx::StaticLine->new($self->{moreOptionsPanel}, -1, wxDefaultPosition, wxDefaultSize, );
$self->{static_line_2_copy} = Wx::StaticLine->new($self->{moreOptionsPanel}, -1, wxDefaultPosition, wxDefaultSize, );
$self->{static_line_3_copy} = Wx::StaticLine->new($self->{moreOptionsPanel}, -1, wxDefaultPosition, wxDefaultSize, );
$self->{label_1_copy_1} = Wx::StaticText->new($self->{moreMoreOptionsPanel}, -1, "Option", wxDefaultPosition, wxDefaultSize, );
$self->{label_2_copy_1} = Wx::StaticText->new($self->{moreMoreOptionsPanel}, -1, "Setting", wxDefaultPosition, wxDefaultSize, );
$self->{label_3_copy_1} = Wx::StaticText->new($self->{moreMoreOptionsPanel}, -1, "Usage", wxDefaultPosition, wxDefaultSize, );
$self->{static_line_1_copy_1} = Wx::StaticLine->new($self->{moreMoreOptionsPanel}, -1, wxDefaultPosition, wxDefaultSize, );
$self->{static_line_2_copy_1} = Wx::StaticLine->new($self->{moreMoreOptionsPanel}, -1, wxDefaultPosition, wxDefaultSize, );
$self->{static_line_3_copy_1} = Wx::StaticLine->new($self->{moreMoreOptionsPanel}, -1, wxDefaultPosition, wxDefaultSize, );
$self->{quitPanel} = Wx::Panel->new($self->{notebook_1}, -1, wxDefaultPosition, wxDefaultSize, );
$self->__set_properties();
$self->__do_layout();
Wx::Event::EVT_BUTTON($self, $self->{chooseDirectory}->GetId, \&onChooseDirectory);
Wx::Event::EVT_TEXT_ENTER($self, $self->{albumPath}->GetId, \&albumPathChanged);
Wx::Event::EVT_BUTTON($self, $self->{generateAlbum}->GetId, \&doGenerateAlbum);
Wx::Event::EVT_LISTBOX($self, $self->{optionlangValue}->GetId, \&langSelectionChanged);
Wx::Event::EVT_CHOICE($self, $self->{optionthemeValue}->GetId, \&themeSelectionChanged);
Wx::Event::EVT_NOTEBOOK_PAGE_CHANGED($self, $self->{notebook_1}->GetId, \&onNotebookChange);
# end wxGlade
# Get keys
Wx::Event::EVT_KEY_UP($self, \&onKeyUp);
Wx::Event::EVT_KILL_FOCUS($self->{albumPath}, \&albumPathChanged);
Wx::Event::EVT_SET_FOCUS($self->{albumPath}, \&albumPathEnter);
return $self;
}
sub __set_properties {
my $self = shift;
# begin wxGlade: MyFrame::__set_properties
$self->SetTitle("galbum - GUI photo album generator");
$self->SetSize(Wx::Size->new(650, 600));
$self->{albumPath}->SetMinSize(Wx::Size->new(400, 27));
$self->{albumPath}->SetToolTipString("The directory of photos to convert into an album.");
$self->{albumProgress}->SetMinSize(Wx::Size->new(400, 28));
$self->{albumProgress}->SetToolTipString("Progress thermometer for album generation");
$self->{checkboxDescend}->SetValue(1);
$self->{optionlangOption}->SetFont(Wx::Font->new(13, wxDEFAULT, wxNORMAL, wxNORMAL, 0, "Sans"));
$self->{optionlangValue}->SetMinSize(Wx::Size->new(140, 200));
$self->{optionlangValue}->SetSelection(0);
$self->{optionthemeOption}->SetMinSize(Wx::Size->new(85, 22));
$self->{optionthemeOption}->SetFont(Wx::Font->new(13, wxDEFAULT, wxNORMAL, wxNORMAL, 0, "Sans"));
$self->{optionthemeValue}->SetMinSize(Wx::Size->new(300, 27));
$self->{optionthemeValue}->SetSelection(0);
$self->{themePanel}->SetScrollRate(10, 10);
$self->{optionsPanel}->SetScrollRate(10, 10);
$self->{moreOptionsPanel}->SetScrollRate(10, 10);
$self->{moreMoreOptionsPanel}->SetScrollRate(10, 10);
# end wxGlade
}
sub __do_layout {
my $self = shift;
# begin wxGlade: MyFrame::__do_layout
$self->{sizer_1} = Wx::BoxSizer->new(wxHORIZONTAL);
$self->{aboutGrid} = Wx::FlexGridSizer->new(2, 2, 0, 0);
$self->{moreMoreOptionsGrid} = Wx::FlexGridSizer->new(3, 3, 4, 7);
$self->{moreOptionsGrid} = Wx::FlexGridSizer->new(3, 3, 4, 7);
$self->{optionsGrid} = Wx::FlexGridSizer->new(3, 3, 4, 7);
$self->{grid_sizer_4} = Wx::FlexGridSizer->new(2, 1, 10, 0);
$self->{themesGrid} = Wx::FlexGridSizer->new(1, 3, 18, 10);
$self->{grid_sizer_5} = Wx::FlexGridSizer->new(1, 2, 0, 0);
$self->{grid_sizer_1} = Wx::FlexGridSizer->new(6, 2, 5, 10);
$self->{grid_sizer_1}->Add(20, 100, 0, 0, 0);
$self->{grid_sizer_1}->Add(100, 20, 0, 0, 0);
$self->{grid_sizer_1}->Add($self->{chooseDirectory}, 0, 0, 0);
$self->{grid_sizer_1}->Add($self->{albumPath}, 0, 0, 0);
$self->{grid_sizer_1}->Add($self->{generateAlbum}, 0, 0, 0);
$self->{grid_sizer_1}->Add($self->{albumProgress}, 0, 0, 0);
$self->{grid_sizer_1}->Add($self->{checkboxDescend}, 0, 0, 0);
$self->{grid_sizer_1}->Add($self->{checkboxAddToParent}, 0, 0, 0);
$self->{grid_sizer_1}->Add(40, 50, 0, 0, 0);
$self->{grid_sizer_1}->Add($self->{progressText}, 0, wxEXPAND, 2);
$self->{grid_sizer_1}->Add($self->{optionlangOption}, 0, 0, 0);
$self->{grid_sizer_1}->Add($self->{optionlangValue}, 0, 0, 0);
$self->{albumPanel}->SetSizer($self->{grid_sizer_1});
$self->{grid_sizer_5}->Add($self->{optionthemeOption}, 0, wxALIGN_CENTER_VERTICAL, 0);
$self->{grid_sizer_5}->Add($self->{optionthemeValue}, 0, 0, 0);
$self->{grid_sizer_4}->Add($self->{grid_sizer_5}, 1, wxEXPAND, 0);
$self->{grid_sizer_4}->Add($self->{themesGrid}, 1, wxEXPAND, 0);
$self->{themePanel}->SetSizer($self->{grid_sizer_4});
$self->{optionsGrid}->Add($self->{label_1}, 0, 0, 0);
$self->{optionsGrid}->Add($self->{label_2}, 0, 0, 0);
$self->{optionsGrid}->Add($self->{label_3}, 0, 0, 0);
$self->{optionsGrid}->Add($self->{static_line_1}, 0, wxEXPAND, 0);
$self->{optionsGrid}->Add($self->{static_line_2}, 0, wxEXPAND, 0);
$self->{optionsGrid}->Add($self->{static_line_3}, 0, wxEXPAND, 0);
$self->{optionsPanel}->SetSizer($self->{optionsGrid});
$self->{moreOptionsGrid}->Add($self->{label_1_copy}, 0, 0, 0);
$self->{moreOptionsGrid}->Add($self->{label_2_copy}, 0, 0, 0);
$self->{moreOptionsGrid}->Add($self->{label_3_copy}, 0, 0, 0);
$self->{moreOptionsGrid}->Add($self->{static_line_1_copy}, 0, wxEXPAND, 0);
$self->{moreOptionsGrid}->Add($self->{static_line_2_copy}, 0, wxEXPAND, 0);
$self->{moreOptionsGrid}->Add($self->{static_line_3_copy}, 0, wxEXPAND, 0);
$self->{moreOptionsPanel}->SetSizer($self->{moreOptionsGrid});
$self->{moreMoreOptionsGrid}->Add($self->{label_1_copy_1}, 0, 0, 0);
$self->{moreMoreOptionsGrid}->Add($self->{label_2_copy_1}, 0, 0, 0);
$self->{moreMoreOptionsGrid}->Add($self->{label_3_copy_1}, 0, 0, 0);
$self->{moreMoreOptionsGrid}->Add($self->{static_line_1_copy_1}, 0, wxEXPAND, 0);
$self->{moreMoreOptionsGrid}->Add($self->{static_line_2_copy_1}, 0, wxEXPAND, 0);
$self->{moreMoreOptionsGrid}->Add($self->{static_line_3_copy_1}, 0, wxEXPAND, 0);
$self->{moreMoreOptionsPanel}->SetSizer($self->{moreMoreOptionsGrid});
$self->{aboutGrid}->Add(100, 80, 0, 0, 0);
$self->{aboutGrid}->Add(5, 5, 0, 0, 0);
$self->{aboutPanel}->SetSizer($self->{aboutGrid});
$self->{notebook_1}->AddPage($self->{albumPanel}, "Album");
$self->{notebook_1}->AddPage($self->{themePanel}, "Theme");
$self->{notebook_1}->AddPage($self->{optionsPanel}, "Options");
$self->{notebook_1}->AddPage($self->{moreOptionsPanel}, "More options");
$self->{notebook_1}->AddPage($self->{moreMoreOptionsPanel}, "More more options");
$self->{notebook_1}->AddPage($self->{aboutPanel}, "About");
$self->{notebook_1}->AddPage($self->{quitPanel}, "Quit (^Q)");
$self->{sizer_1}->Add($self->{notebook_1}, 1, wxEXPAND, 0);
$self->SetSizer($self->{sizer_1});
$self->Layout();
$self->SetSize(Wx::Size->new(650, 600));
# end wxGlade
}
# Get the outer frame given any enclosed object
sub getFrame {
my ($self) = @_;
$self = $self->GetParent() while $self->GetParent();
$self;
}
sub tabAdd {
my ($self,$add) = @_;
my $tab = $self->{notebook_1}->GetSelection();
my $end = $self->{notebook_1}->GetPageCount();
$tab += $add;
# Skip the quit tab at the end ($end-1)
# (So actually this would break if $add > $end*2..)
$tab += $end-1 while $tab<0;
$tab -= $end-1 while $tab>=$end-1;
$self->{notebook_1}->SetSelection($tab);
#$self->{notebook_1}->AdvanceSelection();
}
# Frame: handle keypress
sub onKeyUp {
my ($self, $event) = @_;
my $key = $event->GetKeyCode;
# It seems like it should be easier than this...
QUIT($self) # Control-Q
if ($key==ord('Q')
&& Wx::GetKeyState(WXK_CONTROL)
&& !Wx::GetKeyState(WXK_SHIFT)
## Note that OSX doesn't have this (if we port)
&& !Wx::GetKeyState(WXK_ALT));
# 1,2 cycle through tabs (only if not in a TextCtrl)
if (($key==ord('1') || $key==ord('2')) && Wx::Window::FindFocus() !~ /TextCtrl/) {
my $add = ($key==ord('1')) ? -1 : +1;
tabAdd($self,$add);
}
}
##################################################
##################################################
# OPTIONS
##################################################
##################################################
# These need to match album
sub OPTION_SEP() { 1; } # Separator
sub OPTION_BOOL() { 2; }
sub OPTION_NUM() { 3; }
sub OPTION_STR() { 4; }
sub OPTION_ARR() { 5; } # Array of strings
my @IGNORE_OPTIONS = qw(q d D virgin_check configure theme lang windows cygwin hashes list_themes);
sub optionControls {
my ($option) = @_;
("option${option}Option","option${option}Value","option${option}Usage");
}
# Do we have the option in our frame?
sub hasOption {
my ($self,$option) = @_;
$self->{"option${option}Value"} ? 1 : 0;
}
# Get option value (returns array)
sub getOptionVal {
my ($self, $option) = @_;
my $opt = $self->{"option${option}Value"};
if (ref $opt eq 'Wx::ListBox') {
my @n = $opt->GetSelections();
return map { $opt->GetString($_) } @n;
}
my $val = (ref $opt eq 'Wx::Choice') ? $opt->GetString($opt->GetSelection()) : $opt->GetValue();
wantarray ? split(/\n/, $val) : $val;
}
sub setOptionVal {
my ($self, $option, @val) = @_;
return unless $self->{app}{d}{opt}{$option};
my $type = $self->{app}{d}{opt}{$option}{type};
return unless $type;
my $val = $type==OPTION_ARR ? join("\n",@val) : $val[0];
my $opt = $self->{"option${option}Value"};
return unless $opt;
if (ref $opt eq 'Wx::ListBox') {
for (my $num=$opt->GetCount()-1; $num>=0; $num--) {
my $item = $opt->GetString($num);
$self->{app}{d}{listbox}{lang}[$num] = grep($item eq $_, @val) ? 1 : 0;
$self->{app}{d}{listbox}{lang}[$num] ?
$self->{optionlangValue}->Select($num) :
$self->{optionlangValue}->Deselect($num);
}
return;
}
return $opt->SetValue($val) unless ref $opt eq 'Wx::Choice';
my $n = $opt->FindString($val);
return if $n==wxNOT_FOUND;
$opt->SetSelection($n);
}
# Frame: Find any differences between option values
sub diffOption {
my ($self,$option) = @_;
my $type = $self->{app}{d}{opt}{$option}{type};
return () unless $self->hasOption($option);
my @was = @{$self->{app}{d}{opt}{$option}{val}};
my @now = getOptionVal($self,$option);
# Checkboxes use 'undef' instead of 0 for some reason.
$now[0] = 0 if $type && $type==OPTION_BOOL && !$now[0];
# Special case. Consider () the same as (undef)
return () if $#$a==-1 && $#$b==0 && !$b->[0];
return () if $#$b==-1 && $#$a==0 && !$a->[0];
# Special case. Did we clear an option? Kludge: Return 0
return (0) if @was && $was[0] && !@now;
# Return any elements in @now not in @was
# (Ignores the problem of ARR options that lose some elements,
# but album doesn't really have a good solution for this
# without doing a clear_option - should we check for this??)
my @changed;
foreach my $now ( @now ) {
push(@changed, $now) unless grep($now eq $_, @was);
}
@changed;
}
# Frame: All the options that have been changed
sub changedOptions {
my ($self,@ignore) = @_;
my $d = $self->{app}{d};
return unless $d && $d->{opt};
my @changed;
foreach my $option ( keys %{$d->{opt}} ) {
next if grep($option eq $_, @ignore);
my @diff = diffOption($self,$option);
next unless @diff;
# Hack for 'No-Theme' theme
$diff[0]=0 if $option eq 'theme' && $diff[0] eq 'No-Theme';
# Value changed. Format it for output
if ($d->{opt}{$option}{type}==OPTION_BOOL) {
push(@changed, $diff[0] ? "-$option" : "-no_$option");
} elsif ($#diff==0 && $diff[0] eq '0') {
push(@changed,"-no_$option");
} else {
push(@changed,"-$option",0) unless @diff;
map { push(@changed,"-$option",$_ || 0) } @diff;
}
}
@changed;
}
sub setupProgressText {
my ($self) = @_;
# Resize progressText size and make it purple
my $ptFont = $self->{progressText}->GetFont();
$ptFont->SetPointSize($ptFont->GetPointSize()+1);
$self->{progressText}->SetFont($ptFont);
$self->{progressText}->SetForegroundColour(Wx::Colour->new(255,0,200));
}
my $UNBOUND_RANGE;
sub startUnboundProgress {
my ($self,$what) = @_;
print "$what\n";
$self->{progressText}->SetLabel($what);
$UNBOUND_RANGE = 3;
$self->updateUnboundProgress;
}
sub updateUnboundProgress() {
my ($self) = @_;
$self->{albumProgress}->SetRange($UNBOUND_RANGE+5);
$self->{albumProgress}->SetValue($UNBOUND_RANGE++);
Wx::Yield();
}
sub endUnboundProgress {
my ($self) = @_;
$self->{progressText}->SetLabel("");
$self->{albumProgress}->SetValue(0);
}
# Frame: The user entered something in an option
# Check if it changed and update the color
sub checkOption {
my ($self,$option) = @_;
my ($optTxt,undef,undef) = optionControls($option);
my @diff = diffOption($self,$option);
#my $lbl = @diff ? "!$option!" : $option;
$self->{$optTxt}->SetForegroundColour(@diff ? wxRED : wxNullColour);
# Also update the generateAlbum button if need be
if (@diff) {
$self->{generateAlbum}->SetForegroundColour(wxRED);
} else {
$self->{generateAlbum}->SetForegroundColour(wxNullColour)
unless ($self->changedOptions());
}
$self->Refresh();
}
# Frame: Add/setup the theme panel
sub setupThemes {
my ($self) = @_;
# For now..
return if $self->{app}{d}{themes};
my $dir = $self->getAlbumPath;
#########################
# Get all of the themes based on -theme_path and -data_path
#########################
$self->startUnboundProgress("Reading current themes");
my @cmd = (@ALBUM,'-crf','-list_themes');
push(@cmd, $dir) if $dir;
my ($fh) = openPipe(@cmd);
return unless $fh;
my ($imgSize,$txtSize) = (Wx::Size->new(180,200), Wx::Size->new(180,-1));
my $txtFont;
my %saw;
while (<$fh>) {
$self->updateUnboundProgress;
chomp;
$MAIN::ALBUM_VERSION = $1 if /crf:version:([^:]+):/i;
next unless /^crf:theme:\s*(.*?)([^\/]+)$/;
my ($path,$theme,$ptheme) = ($1.$2,$2,$2);
next if $saw{$theme}++;
push(@{$self->{app}{d}{themes}{paths}}, $path);
push(@{$self->{app}{d}{themes}{themes}}, $theme);
$ptheme =~ s/[_]/ /g;
$self->{optionthemeValue}->Append($theme);
# Make the thumbnail if we have the snapshot
if (-f "$path/snapshot.jpg" && !-f "$path/thumb.jpg") {
print STDERR "Generating theme thumbnail: $theme\n";
$self->{progressText}->SetLabel("Generating theme thumbnail: $theme");
Wx::Yield();
system($CONVERT,'-geometry','180x200',"$path/snapshot.jpg","$path/thumb.jpg");
$self->{progressText}->SetLabel("");
}
# Make the button/label
$self->{theme}{$theme}{grid} = Wx::FlexGridSizer->new(2, 1, 10, 0);
$self->{theme}{$theme}{label} = Wx::StaticText->new($self->{themePanel}, -1, "$ptheme", wxDefaultPosition, $txtSize, wxALIGN_CENTRE);
unless ($txtFont) {
$txtFont = $self->{theme}{$theme}{label}->GetFont();
$txtFont->SetPointSize($txtFont->GetPointSize()+1);
$txtFont->SetWeight(wxBOLD);
}
$self->{theme}{$theme}{label}->SetFont($txtFont);
if (-f "$path/thumb.jpg") {
$self->{theme}{$theme}{thumb} = Wx::BitmapButton->new($self->{themePanel}, -1, Wx::Bitmap->new("$path/thumb.jpg", wxBITMAP_TYPE_ANY), wxDefaultPosition, $imgSize);
$self->{theme}{$theme}{thumb}->SetLabel($theme);
} else {
$self->{theme}{$theme}{thumb} = Wx::Button->new($self->{themePanel}, -1, "$theme\n(no thumbnail)");
$self->{theme}{$theme}{thumb}->SetMinSize(Wx::Size->new(180, 200));
$self->{theme}{$theme}{thumb}->SetFont(Wx::Font->new(13, wxDEFAULT, wxNORMAL, wxNORMAL, 0, "Sans"));
}
$self->{theme}{$theme}{grid}->Add($self->{theme}{$theme}{thumb}, 0, wxADJUST_MINSIZE, 0);
Wx::Event::EVT_BUTTON($self, $self->{theme}{$theme}{thumb}->GetId, \&themeButton);
$self->{theme}{$theme}{grid}->Add($self->{theme}{$theme}{label}, 0, wxADJUST_MINSIZE, 0);
$self->{themesGrid}->Add($self->{theme}{$theme}{grid}, 1, wxEXPAND, 0);
$self->{theme}{$theme}{grid}->Layout(); # Update the layout
}
my $currTheme = $self->{app}{d}{opt}{theme}{val}[0];
setTheme($self, $currTheme) if $currTheme;
$self->endUnboundProgress;
# # Update the theme grid to update scrollbars
$self->{grid_sizer_4}->FitInside($self->{themePanel});
#$self->{themesGrid}->FitInside($self->{themePanel});
#$self->{themesGrid}->Layout(); # Update the layout
#$self->{grid_sizer_4}->Layout();
#$self->{themePanel}->Layout(); # Update the layout
$self->Layout(); # Update the layout
$self->Refresh();
close $fh;
}
# Frame: Add/setup the option pages
sub setupOptions {
my ($self,$path) = @_;
$self->{app}{d}{opt} = {}; # Clean opts
my $d = $self->{app}{d};
#########################
# Get all of the album options for a given album
#########################
$self->startUnboundProgress("Reading current options for [$path]");
my ($fh) = openPipe(@ALBUM,'-list_options',$path);
undef $self->{app}{opts}; # Start clean
my %saw;
while (<$fh>) {
$self->updateUnboundProgress;
if (/Can't find directory/) {
$self->{progressText}->SetLabel($_);
Wx::LogMessage($_);
print;
}
next unless /^crf:option:(\d+):(\d+):([^:]+):"([^"]+)":(.*)/;
my ($lvl,$type,$option,$usage,$val) = ($1,$2,$3,$4,$5);
next if $lvl>3;
my $deep = $lvl==1 ? "options" : $lvl==2 ? "moreOptions" : "moreMoreOptions";
push(@{$self->{app}{deep}{$deep}}, $option)
unless $saw{$option}++;
$d->{opt}{$option}{lvl} = $lvl;
$d->{opt}{$option}{type} = $type;
$d->{opt}{$option}{usage} = $usage;
push(@{$d->{opt}{$option}{val}}, $val);
}
close $fh;
$self->endUnboundProgress;
#########################
# Themes/Langs
#########################
setupThemes($self);
setOptionVal($self,'lang',@{$d->{opt}{lang}{val}}) if $path;
#########################
# If we've already created the forms, just update the values
#########################
if ($self->{app}{setupOptions}++) {
foreach my $option ( keys %{$d->{opt}} ) {
my ($optTxt,$valCtrl,undef) = optionControls($option);
next unless $self->hasOption($option);
my $val = $d->{opt}{$option}{val};
setOptionVal($self,$option,@$val);
$self->{$optTxt}->SetForegroundColour(wxNullColour);
}
$self->Refresh();
return;
}
#########################
# First time, create the forms
#########################
my $usageFont = undef;
my $strSize = Wx::Size->new(150,-1);
my $arrSize = Wx::Size->new(150,40);
foreach my $deep (qw(options moreOptions moreMoreOptions)) {
my $grid = $deep."Grid";
my $panel = $deep."Panel";
foreach my $option ( @{$self->{app}{deep}{$deep}} ) {
next if grep($_ eq $option, @IGNORE_OPTIONS);
my ($optTxt,$valCtrl,$usageTxt) = optionControls($option);
my $type = $d->{opt}{$option}{type};
# The option text
$self->{$optTxt} = Wx::StaticText->new($self->{$panel}, -1, $option, wxDefaultPosition, wxDefaultSize, );
# The value
my $val = $d->{opt}{$option}{val};
$val = $type==OPTION_ARR ? join("\n",@$val) : $val->[0];
# The input/checkbox
$self->{$valCtrl} = $type==OPTION_BOOL ?
Wx::CheckBox->new($self->{$panel}, -1, "", wxDefaultPosition, wxDefaultSize, ) :
$type==OPTION_ARR ?
Wx::TextCtrl->new($self->{$panel}, -1, $val, wxDefaultPosition, $arrSize, wxTE_MULTILINE|wxVSCROLL) :
Wx::TextCtrl->new($self->{$panel}, -1, $val, wxDefaultPosition, $strSize, );
$self->{$valCtrl}->SetValue(1) if $type==OPTION_BOOL && $val;
# Callbacks for enter/leave to check if it's changed
if ($type==OPTION_BOOL) {
Wx::Event::EVT_CHECKBOX($self, $self->{$valCtrl}->GetId, sub { checkOption($self,$option) });
} else {
Wx::Event::EVT_TEXT_ENTER($self, $self->{$valCtrl}->GetId, sub { checkOption($self,$option) });
Wx::Event::EVT_KILL_FOCUS($self->{$valCtrl}, sub { checkOption($self,$option) });
}
# Usage and lay it all out
$self->{$usageTxt} = Wx::StaticText->new($self->{$panel}, -1, $d->{opt}{$option}{usage}, wxDefaultPosition, wxDefaultSize, );
$self->{$usageTxt}->Wrap(700);
unless ($usageFont) {
$usageFont = $self->{$usageTxt}->GetFont();
$usageFont->SetPointSize(8);
# Note that OSX may not have italics (if we port)
$usageFont->SetStyle(wxFONTSTYLE_ITALIC);
}
$self->{$usageTxt}->SetFont($usageFont);
$self->{$grid}->Add($self->{$optTxt}, 0, wxADJUST_MINSIZE, 0);
$self->{$grid}->Add($self->{$valCtrl}, 0, wxADJUST_MINSIZE, 0);
$self->{$grid}->Add($self->{$usageTxt}, 0, wxADJUST_MINSIZE, 0);
}
# To resize the layout (for scrollbars)
$self->{$grid}->FitInside($self->{$panel});
$self->{$panel}->Layout(); # Update the layout
$self->{$grid}->Layout(); # Update the layout
}
$self->Layout();
$self->Refresh(); # Doesn't seem to make the scrollbars show up!
}
# Frame: Language options
# For now, just do it once when we build the app - we may have
# extra languages defined by an albums album.conf, but 'album -list_langs'
# doesn't currently show those anyways...
sub buildLangs {
my ($self) = @_;
#########################
# Get all of the langs based on -theme_path and -data_path
#########################
$self->startUnboundProgress("Reading current languages");
my @cmd = (@ALBUM,'-crf','-list_langs');
#push(@cmd, $dir) if $dir;
my ($fh) = openPipe(@cmd);
return unless $fh;
while (<$fh>) {
$self->updateUnboundProgress;
chomp;
$MAIN::ALBUM_VERSION = $1 if /crf:version:([^:]+):/i;
next unless /^crf:lang:\s*(\S+)$/;
my $lang = $1;
push(@{$self->{app}{d}{langs}}, $lang);
}
$self->{optionlangValue}->InsertItems(\@{$self->{app}{d}{langs}},0);
$self->endUnboundProgress;
$self->Refresh();
close $fh;
}
##################################################
##################################################
# ALBUM GENERATION
##################################################
##################################################
# Frame: Get the current album path
sub getAlbumPath {
my ($self) = @_;
my $dir = $self->{albumPath}->GetValue();
return '' if $dir eq "<path to album directory>";
$dir;
}
# Frame: Set the album path (and update the options)
sub newAlbumPath {
my ($self, $path) = @_;
($path) ?
$self->{albumPath}->SetValue($path) :
($path = $self->{albumPath}->GetValue());
return if $self->{app}{album} && $path eq $self->{app}{album};
$self->{progressText}->SetLabel("");
$self->{albumProgress}->SetValue(0);
$self->{app}{album} = $path;
$self->setupOptions($path) if $path;
}
# Frame: Choose an album dialog box
sub onChooseDirectory {
my ($self, $event) = @_;
# wxGlade: MyFrame::onChooseDirectory <event_handler>
my $dir = $self->getAlbumPath;
#$dir .= '/..' if $dir;
my $fd = Wx::DirDialog->new($self, "Choose a directory", $dir);
if ($fd->ShowModal == wxID_CANCEL) {
#Wx::LogMessage("User cancelled dialog");
} else {
my $path = $fd->GetPath;
$fd->Destroy;
$self->newAlbumPath($path);
}
# end wxGlade
}
# Frame: We enter the album path textCtrl
sub albumPathEnter {
my ($text, $event) = @_;
# First time we enter, make sure we clear the "<type here..>" message
my $self = getFrame($text);
my $path = $self->getAlbumPath();
$self->{albumPath}->SetValue("") unless $path;
}
# Frame: We saw the albumPath text string change
sub albumPathChanged {
my ($text, $event) = @_;
# wxGlade: MyFrame::albumPathChanged <event_handler>
getFrame($text)->newAlbumPath();
# end wxGlade
}
##################################################
# Running album: progress bar / job control
##################################################
# Frame: Kills a currently running album
my $GENERATING = 0;
sub stopAlbumProcess {
my ($self) = @_;
return unless $GENERATING;
print STDERR "Killing album process [$GENERATING]\n";
# this probably needs to be updated to use Win32::Process on Win machines
if (kill 9, $GENERATING) {
$GENERATING = 0;
$self->{generateAlbum}->SetLabel("Generate Album");
$self->{albumProgress}->SetValue(0);
$self->{progressText}->SetLabel("Aborted - album may be corrupt - regenerate to fix");
Wx::LogMessage("Aborted album generation\n\nAlbum may be corrupt.\nRegenerate to fix.\n");
$self->{generateAlbum}->SetForegroundColour(wxRED);
}
# Nothing if we failed
}
#########################
# Stolen from album
#########################
sub file_quote {
my ($file) = @_;
return $file if $CYGWIN;
$WINDOWS ? "\"$file\"" : "\Q$file\E";
}
sub openPipe {
my ($cmd,@args) = @_;
#print STDERR "run: $cmd @args\n" if $opt->{d};
my $fh = new IO::File;
my $qcmd = file_quote($cmd);
@args = map { file_quote($_) } @args;
# Happy Unix
return ($fh,open($fh, "$qcmd @args 2>&1 |"));# unless $WINDOWS;
# Windows2000,XP: -| pipe method, doesn't seem to work on Win98
# (Only works under Cygwin??)
my $pid = (open($fh,"-|"));
return undef unless defined $pid; # Failed
return ($fh,$pid) if $pid; # Parent
# Child
(open(STDERR,">&STDOUT")) || return undef;
exec($cmd,@args);
}
# An non-blocking filehandle read that returns an array of lines read
# Returns: ($eof,@lines)
my %nonblockGetLines_last;
sub nonblockGetLines_UNIX {
my ($fh,$timeout) = @_;
$timeout = 0 unless defined $timeout;
my $rfd = '';
$nonblockGetLines_last{$fh} = ''
unless defined $nonblockGetLines_last{$fh};
vec($rfd,fileno($fh),1) = 1;
return unless select($rfd, undef, undef, $timeout)>=0;
return unless vec($rfd,fileno($fh),1); # I'm not sure this is needed??
my $buf = '';
my $n = sysread($fh,$buf,1024*1024);
# If we're done, make sure to send the last unfinished line
return (1,$nonblockGetLines_last{$fh}) unless $n;
# Prepend the last unfinished line
$buf = $nonblockGetLines_last{$fh}.$buf;
# And save any newly unfinished lines
$nonblockGetLines_last{$fh} =
(substr($buf,-1) !~ /[\r\n]/ && $buf =~ s/([^\r\n]*)$//) ? $1 : '';
$buf ? (0,split(/\n/,$buf)) : (0);
}
my $peekNamedPipe = $WINDOWS ? Win32::API->Import('kernel32','PeekNamedPipe','LPLPPP','L') : undef;
sub nonblockGetLines_WINDOWS {
my ($fh,$timeout) = @_;
# We don't use the timeout..
# Thanks to perlmonks for the code
my $osfh = Win32API::File::GetOsFHandle( $fh ) or die $^E;
my( $bufsize, $buffer, $cAvail, $read ) = ( 1024, chr(0)x1024, 0, 0 );
PeekNamedPipe( $osfh, $buffer, $bufsize, $read, $cAvail, 0 )
or $^E == 109 or die $^E;
return (1) if $^E == 109;
my $eolPos = 1+index $buffer, $/;
return (0) unless $eolPos;
sysread( $fh, $buffer, $eolPos ) or die $!;
return (0) unless $buffer;
return (0,$buffer);
}
sub nonblockGetLines {
$WINDOWS ? nonblockGetLines_WINDOWS(@_) : nonblockGetLines_UNIX(@_);
}
sub absPath {
my ($dir) = @_;
my $save=`pwd`; chomp($save);
if (!chdir($dir)) {
Wx::LogMessage("Couldn't find directory ~[[_1]~]", $dir);
return undef;
}
my $name=`pwd`; chomp($name);
chdir($save);
$name;
}
#########################
# Frame: Runs album and watches the album output
#########################
sub doGenerateAlbum {
my ($self, $event) = @_;
# wxGlade: MyFrame::doGenerateAlbum <event_handler>
return $self->stopAlbumProcess if $GENERATING;
# We don't need the button to be red anymore
$self->{generateAlbum}->SetForegroundColour(wxNullColour);
onChooseDirectory($self) unless $self->getAlbumPath;
my $dir = $self->getAlbumPath;
return Wx::LogMessage("No album directory specified") unless $dir;
return Wx::LogMessage("Album directory not found:\n $dir") unless -d $dir;
print "Generate: $dir\n";
# Figure out the album command
my @cmd = (@ALBUM,'-crf');
my @ignore = ();
my $depth = $self->{checkboxDescend}->GetValue();
push(@ignore,'depth') unless $depth;
push(@cmd,'-depth','1') unless $depth;
my $addToParent = $self->{checkboxAddToParent}->GetValue();
if ($addToParent && (my $abs = absPath($dir))) {
if ($abs =~ m|(.+)/([^/]+)$|) {
($dir, my $add) = ($1,$2);
push(@ignore,'add');
push(@cmd, '-add', $add);
}
}
push(@cmd,$dir);
push(@cmd, $self->changedOptions(@ignore));
# Start up the album process
$self->{generateAlbum}->SetLabel("Stop generating");
#print "CMD @cmd\n";
(my $fh, $GENERATING) = openPipe(@cmd);
while ($GENERATING) {
Wx::Yield();
return if $self->{app}{QUIT}; # In case we died.
return unless $GENERATING; # Or stopped generating
# See if album has any output to parse
my ($eof,@lines) = nonblockGetLines($fh,.25);
foreach my $line ( @lines ) {
($self->{albumProgress}->SetRange($2),$self->{albumProgress}->SetValue($1))
if $line =~ m|^crf:hashes:\s*(\d+)/(\d+)|;
($self->{progressText}->SetLabel($1), print "Album: $1\n")
if $line =~ m|^crf:start_hashes:\s*(\S.*?)\s*$|;
}
$GENERATING=0 if $eof;
close $fh if $eof;
}
# Todo - set a timer to clear this?
$self->{progressText}->SetLabel("Album generation complete");
$self->{generateAlbum}->SetLabel("Generate Album");
# Make sure we have the new options as the "was" for changedOptions
$self->setupOptions($dir);
# Clear the progressText in 2000ms
my $timer = Wx::Timer->new($self,1); # Slight memory leak?
$timer->Start(2400,1);
Wx::Event::EVT_TIMER($self, 1, sub {
return if $self->{progressText}->GetLabel() ne "Album generation complete";
# Slight race condition here..
$self->{progressText}->SetLabel("");
$self->{albumProgress}->SetValue(0);
});
# end wxGlade
}
##################################################
# Quitting
##################################################
sub QUIT() {
my ($self) = @_;
# Check for changes and get confirmation?
if ($self->changedOptions()) {
my $answer = Wx::MessageBox("Album options have changed. Do you want to quit without generating the new album?", "Quit?", Wx::wxYES, undef);
unless ($answer == Wx::wxYES) {
$self->{notebook_1}->SetSelection(0)
if ($self->{notebook_1}->GetSelection()==$self->{notebook_1}->GetPageCount()-1);
return;
}
}
$self->stopAlbumProcess;
$self->{app}{QUIT}=1;
$self->Close(1);
}
sub onNotebookChange {
my ($self, $event) = @_;
# wxGlade: MyFrame::onNotebookChange <event_handler>
my $s = $event->GetSelection();
my $n = $self->{notebook_1}->GetPageCount();
# We need to select an album before dealing with themes/options
if ($s>=1 && $s<=4 && !$self->getAlbumPath) {
$self->{progressText}->SetLabel("SELECT AN ALBUM (before dealing with themes/options)");
return $self->{notebook_1}->SetSelection(0);
}
# Last 'button'/frame is Quit.
return unless $s==$n-1;
$self->QUIT;
# end wxGlade
}
sub aboutText {
my ($self,$msg) = @_;
## The old way, just one aboutText object
#return $self->{aboutText}->SetLabel($msg) if $self->{aboutText};
return if $self->{aboutText};
# Split links out of message so we can make them hyperlinks
my @msg = split(/(https?:\/\/\S+)/, $msg);
foreach my $piece ( @msg ) {
my $text;
$piece =~ s/^[\s\n\r]+//g;
$piece =~ s/[\s\n\r]+$//g;
if ($piece =~ /^https?:\/\/\S/) {
$text = Wx::HyperlinkCtrl->new($self->{aboutPanel}, -1, " $piece ", $piece, wxDefaultPosition, wxDefaultSize, );
} else {
$text = Wx::StaticText->new($self->{aboutPanel}, -1, $piece, wxDefaultPosition, wxDefaultSize, );
}
$self->{aboutGrid}->Add(5, 5, 0, 0, 0); # Spacer (left column)
$self->{aboutGrid}->Add($text, 0, 0, 0);
}
}
# Frame: Set the theme if we haven't already
my $lastTheme = "";
sub setTheme {
my ($self, $theme) = @_;
$theme = $self->getOptionVal('theme') unless $theme;
return 0 if $theme eq $lastTheme;
$self->setOptionVal('theme',$theme);
checkOption($self,'theme');
$lastTheme = $theme;
1;
}
# Frame: One of the theme buttons was pressed
sub themeButton {
my ($self, $event) = @_;
my $theme = $event->GetEventObject()->GetLabel();
$theme =~ s/\n.*//m;
setTheme($self,$theme);
}
# Frame: The theme selector changed
sub themeSelectionChanged {
my ($self, $event) = @_;
# wxGlade: MyFrame::themeSelectionChanged <event_handler>
return unless setTheme($self);
# Make sure it's a legal theme
my $theme = $self->getOptionVal('theme');
return unless $theme;
return if grep($theme eq $_, @{$self->{app}{d}{themes}{themes}});
return if $theme eq 'No-Theme';
print "Internal oops: [$theme] and No-Theme\n";
Wx::LogMessage("Not a theme [$theme]");
# end wxGlade
}
# Frame: The language selector changed
sub langSelectionChanged {
my ($self, $event) = @_;
# wxGlade: MyFrame::langSelectionChanged <event_handler>
# Handle selection
# The wxLB_MULTIPLE doesn't seem to be working right on GTK,
# so I'll just do the select/deselect myself... bah.
my $num = $event->GetInt();
my $lang = $self->{optionlangValue}->GetString($num);
$self->{app}{d}{listbox}{lang}[$num] = $self->{app}{d}{listbox}{lang}[$num] ? 0 : 1;
# reselect everything else
for (my $i=0; $i<=$#{$self->{app}{d}{listbox}{lang}}; $i++) {
$self->{optionlangValue}->Select($i)
if $self->{app}{d}{listbox}{lang}[$i];
}
# Do the current selection last so we leave on that focus.
# (unfortunately this is jumpy. Damn wxLB_MULTIPLE!)
$self->{app}{d}{listbox}{lang}[$num] ?
$self->{optionlangValue}->Select($num) :
$self->{optionlangValue}->Deselect($num);
my @s = $self->{optionlangValue}->GetSelections;
checkOption($self,'lang');
# end wxGlade
}
# end of class MyFrame
1;
##################################################
##################################################
# Glade: Application startup
##################################################
##################################################
package MyApp;
use base qw(Wx::App);
use strict;
sub OnInit {
my( $self ) = shift;
Wx::InitAllImageHandlers();
my $frame_1 = MyFrame->new();
$self->SetTopWindow($frame_1);
$frame_1->Show(1);
#$frame_1->SetFocus; # So we get keys
$frame_1->{notebook_1}->SetFocus; # For some reason it needs to be this
$frame_1->{app} = $self;
$frame_1->setupProgressText;
$frame_1->buildLangs();
# Kludge for now - need to parseArgs eventually
$frame_1->newAlbumPath($ARGV[0]) if @ARGV && -d $ARGV[0];
$self->{frame_1} = $frame_1; # So we can find the frame
return 1;
}
# end of class MyApp
package main;
sub main {
my $app = MyApp->new();
my $frame = $app->{frame_1};
# About text
$frame->aboutText(about());
$app->MainLoop();
} main();
|