Posted By

illuzian on 12/04/10


Tagged

menu generator windows


Versions (?)

menu_gen.pl


 / Published in: Perl
 

Generates a crappy menu from some text files.

  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Tk;
  5. use Win32::FileOp qw(ShellExecute);
  6. #Open the menu file with the formatted menu name + filename list
  7. #file format:
  8. #Menu Name,TextFileName.txt
  9. open(MENULIST, "<", "./menu.txt") or
  10. die("Error: cannot open file 'menu.txt'\n");
  11. my @menu = <MENULIST>;
  12. my $mw =MainWindow->new;
  13.  
  14. my $frame = $mw->Frame->pack;
  15.  
  16. mainmenu();
  17. #Generate the main menu
  18. sub mainmenu {
  19.  
  20. $frame->destroy;
  21. $frame = $mw->Frame->pack;
  22. @menu = sort(@menu);
  23. foreach(@menu) {
  24. chomp $_;
  25. my ($menuname, $listfile) = split(",", $_);
  26. $frame->Button(-text => "$menuname", -width => 15, -command => sub { genlist("$listfile") } )->pack;
  27. }
  28.  
  29. $frame->Button(-text => "Big List", -width => 15, -command => sub { genbiglist() } )->pack;
  30.  
  31. }
  32. #Generate the submenu list based on the file passed to the sub
  33. #file formate:
  34. #Button Name,http://ButtonAddress
  35. sub genlist {
  36. $frame->destroy;
  37. $frame = $mw->Frame->pack;
  38. my ($listfile) = (@_);
  39. #Open the file
  40. open(LIST, "<", $listfile) or
  41. die("Error: cannot open file $listfile\n");
  42. my @addlist = <LIST>;
  43. close (LIST);
  44. @addlist = sort(@addlist);
  45. foreach(@addlist) {
  46. chomp $_;
  47. my ($aname, $aurl) = split(",",$_);
  48. $frame->Button(-text => "$aname", -width => 15, -command => sub { openbrowser("$aurl") }, )->pack;
  49. }
  50.  
  51. $frame->Button(-text => "Menu", -command => sub { mainmenu() })->pack;
  52. }
  53.  
  54. sub genbiglist {
  55. my @bigflist;
  56. my @bigfitems;
  57. $frame->destroy;
  58. $frame = $mw->Frame->pack;
  59. foreach(@menu) {
  60. chomp $_;
  61. my (undef, $txtf) = split(",", $_);
  62. push @bigflist, $txtf;
  63. }
  64.  
  65. foreach(@bigflist) {
  66. open(BIGMENU, "<", $_);
  67. push(@bigfitems, <BIGMENU>);
  68.  
  69. }
  70. @bigfitems = sort(@bigfitems);
  71. foreach (@bigfitems) {
  72. chomp $_;
  73. my ($aname, $aurl) = split(",",$_);
  74. $frame->Button(-text => "$aname", -width => 15, -command => sub { openbrowser("$aurl") }, )->pack;
  75. }
  76. $frame->Button(-text => "Menu", -command => sub { mainmenu() })->pack;
  77. }
  78.  
  79.  
  80. sub openbrowser {
  81. my ($url) = (@_);
  82. #Actually open the webrowser, this method causes lag - to update to an API module at a later stage.
  83. ShellExecute("$url");
  84.  
  85. }
  86.  
  87. MainLoop;

Report this snippet  

You need to login to post a comment.