From 2220cef163ff2fa5ac167cd078716ec6d6b25751 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Tue, 27 Jan 2009 18:36:30 +0000 Subject: add a wizard UI to the installer, selectable with install-tl -ui wizard (mind -ui, not -gui) git-svn-id: svn://tug.org/texlive/trunk@11994 c570f23f-e606-0410-a88d-b1316a301751 --- Master/install-tl | 9 +- Master/tlpkg/installer/install-menu-wizard.pl | 366 ++++++++++++++++++++++++++ 2 files changed, 373 insertions(+), 2 deletions(-) create mode 100644 Master/tlpkg/installer/install-menu-wizard.pl diff --git a/Master/install-tl b/Master/install-tl index ae8e3e8606c..b412f17da00 100755 --- a/Master/install-tl +++ b/Master/install-tl @@ -141,6 +141,7 @@ our %vars=( # 'n_' means 'number of'. # option handling my $opt_from_dvd = ""; my $opt_gui = 0; +my $opt_ui = "text"; # default UI my $opt_help = 0; my $opt_location = ""; my $opt_no_gui = 0; @@ -179,6 +180,7 @@ GetOptions( "fancyselector" => \$::alternative_selector, "from_dvd" => \$opt_from_dvd, "gui" => \$opt_gui, + "ui=s" => \$opt_ui, "lang=s" => \$::opt_lang, "location|url=s" => \$opt_location, "no-cls", # $::opt_no_cls in install-menu-text-pl @@ -404,9 +406,12 @@ if ($opt_profile eq "") { our $MENU_ABORT = 1; our $MENU_QUIT = 2; our $MENU_ALREADYDONE = 3; - if ($opt_gui && !$opt_no_gui) { - require("installer/install-menu-perltk.pl"); + $opt_ui = "perltk" if ($opt_gui && !$opt_no_gui); + if (-r "tlpkg/installer/install-menu-${opt_ui}.pl") { + require("installer/install-menu-${opt_ui}.pl"); } else { + tlwarn("UI plugin $opt_ui not found,\n"); + tlwarn("Using text mode installer.\n"); require("installer/install-menu-text.pl"); } my $ret = run_menu(); diff --git a/Master/tlpkg/installer/install-menu-wizard.pl b/Master/tlpkg/installer/install-menu-wizard.pl new file mode 100644 index 00000000000..12386d2d375 --- /dev/null +++ b/Master/tlpkg/installer/install-menu-wizard.pl @@ -0,0 +1,366 @@ +#!/usr/bin/env perl +# $Id$ +# +# Copyright 2009 Norbert Preining +# This file is licensed under the GNU General Public License version 2 +# or any later version. +# + +use strict; +$^W = 1; + +my $svnrev = '$Revision: 11925 $'; +$svnrev =~ m/: ([0-9]+) /; +$::menurevision = $1; + + +our %vars; +our $tlpdb; +our $texlive_release; + +our $MENU_INSTALL = 0; +our $MENU_ABORT = 1; +our $MENU_QUIT = 2; +our $MENU_ALREADYDONE = 3; + +my $return = $MENU_INSTALL; + +require Tk; +require Tk::Dialog; +require Tk::DialogBox; +require Tk::PNG; +require Tk::ROText; +require Tk::ProgressBar; + +use utf8; +no utf8; + +my $lab; +my $val; +my $but; + +if (defined($::opt_lang)) { + $::lang = $::opt_lang; + if ($::lang eq "zh") { + # set language to simplified chinese + $::lang = "zh-cn"; + } +} else { + if ($^O =~ /^MSWin(32|64)$/i) { + # trying to deduce automatically the country code + my $foo = TeXLive::TLWinGoo::reg_country(); + if ($foo) { + $::lang = $foo; + } else { + debug("Didn't get any usuful code from reg_country: $foo...\n"); + } + } else { + # we load POSIX and locale stuff + require POSIX; + import POSIX qw/locale_h/; + # now we try to deduce $::lang + my $loc = setlocale(&POSIX::LC_MESSAGES); + my ($lang,$area,$codeset); + if ($loc =~ m/^([^_.]*)(_([^.]*))?(\.([^@]*))?(@.*)?$/) { + $lang = defined($1)?$1:""; + $area = defined($3)?$3:""; + if ($lang eq "zh") { + if ($area =~ m/^(TW|HK)$/i) { + $lang = "zh-tw"; + } else { + # fallback to zh-cn for anything else, that is + # zh-cn, zh-sg, zh, and maybe something else + $lang = "zh-cn"; + } + } + } + $::lang = $lang if ($lang); + } +} + +my $dest = "/usr/local/texlive/2008"; + +my $mw; + +sub ask_path { + $lab->configure(-text => "Destination Folder:"); + $val->configure(-textvar => \$dest); + $but->configure(-text => "Change", -command => \&change_path); + my $nx = $mw->Button(-text => "Next", -command => \&installation_window); + $nx->pack; +} + +sub change_path { + my $val = $dest; + my $sw = $mw->Toplevel(-title => "Changing TEXDIR"); + $sw->transient($mw); + $sw->grab(); + $sw->Label(-text => "Please enter path for TEXDIR")->pack; + my $entry = $sw->Entry(-textvariable => $val, -width => 60); + $entry->pack; + my $f = $sw->Frame; + my $okbutton = $f->Button(-text => "Ok", + -command => sub { $val = $entry->get; $dest = $val ; $sw->destroy })->pack(-side => 'left', -padx => "2m", -pady => "2m"); + my $cancelbutton = $f->Button(-text => "Cancel", + -command => sub { $sw->destroy })->pack(-side => 'right', -padx => "2m", -pady => "2m"); + $f->pack(-expand => 'x'); +} + + +###################################################################### + +push @::info_hook, + sub { + update_status(join(" ",@_)); + $mw->update; + }; +push @::warn_hook, + sub { + update_status(join(" ",@_)); + $mw->update; + }; +push @::install_packages_hook, \&update_progressbar; +push @::install_packages_hook, + sub { $mw->update; $::sww->update; }; + +sub update_status { + my ($p) = @_; + $::progressw->insert("end", "$p"); + $::progressw->see("end"); +} +sub update_progressbar { + my ($n,$total) = @_; + if (defined($n) && defined($total)) { + $::progress->value(int($n*100/$total)); + } +} + +my %text = ( title => 'TeX Live 2008 Installation', + basicinfo => 'Basic Information', + custom => 'Further Customization', + dirsetup => "Directory setup", + options => 'Options', + sysint => 'System Integration', + change => 'Change', + toggle => 'Toggle', + install => 'Install TeX Live', + finbut => 'Finish', + quit => 'Quit', + ok => 'Ok', + cancel => 'Cancel', + status => 'Status output', + changevar => 'Change variable value', + enterpath => 'Enter path for', + hinthome => '(use ~ for %%%)', + selectscheme => 'Select a scheme', + selectstdcol => 'Select the collections to be installed', + selectall => 'Select All', + selectnone => 'Deselect All', + selectlang => 'Select language support', + selectdoc => 'Select language-specific documentation', + createsym => 'create symlinks in standard directories', + binto => 'binaries to', + manto => 'manpages to', + infoto => 'info to', + selectsys => 'Select arch-os', + outof => 'out of', + collof => 'collections out of', + diskreq => 'disk space required', + yes => 'Yes', + no => 'No', + notwritable => '(default not writable - please change!)', + changetexdir => '(please change TEXDIR first!)', + nolangcol => '(no language collection selected!)', + finished => 'See TEXDIR/index.html for links to documentation.\nThe TeX Live web site\n(http://tug.org/texlive/) contains any updates and corrections.\nTeX Live is a joint project of the TeX user groups around the world;\nplease consider supporting it by joining the group best for you. The\nlist of groups is available on the web at http://tug.org/usergroups.html.', + finishedpath => 'Add TEXDIR/texmf/doc/man to MANPATH.\nAdd TEXDIR/texmf/doc/info to INFOPATH.\nMost importantly, add TEXDIR/bin/PLATFORM\nto your PATH for current and future sessions.', + welcome => 'Welcome to TeX Live!', + ); + + +my %labels = ( binsys => 'Binary System(s)', + scheme => 'Selected Scheme', + stdcoll => 'Standard Collections', + langcoll => 'Language Collections', + texdir => 'TEXDIR (the main TeX directory)', + localdir => 'TEXMFLOCAL (directory for site-wide local files)', + sysvardir => 'TEXMFSYSVAR (directory for autogenerated data)', + sysconfigdir => 'TEXMFSYSCONFIG (directory for local config)', + texmfhome => 'TEXMFHOME (directory for user-specific files)', + optletter => 'Use letter size instead of A4 by default', + optfmt => 'Create all format files', + optdoc => 'Install font/macro doc tree', + optsrc => 'Install font/macro source tree', + symlink => 'Create symlinks in system directories', + ); + +if (($::lang ne "en") && ($::lang ne "C")) { + if (! -r "$::installerdir/tlpkg/installer/lang/perltk-$::lang") { + tlwarn ("\n Sorry, no translations available for $::lang; falling back to English. + (If you'd like to help translate the installer's messages, please see + http://tug.org/texlive/doc.html#install-tl-xlate for information.)\n\n"); + } else { + # merge the translated strings into the text string + open(LANG, "<$::installerdir/tlpkg/installer/lang/perltk-$::lang"); + my %trans; + while () { + chomp; + next if m/^\s*#/; + next if m/^\s*$/; + my ($a,$b) = split(/:/,$_,2); + $b =~ s/^\s*([^\s])/$1/; + $b =~ s/\s*$//; + if (!utf8::decode($b)) { + warn("decoding string to utf8 didn't work:$b\n"); + } + $trans{"$a"} = "$b"; + } + close(LANG); + foreach my $k (keys %text) { + $text{$k} = $trans{"text.$k"} if defined($trans{"text.$k"}); + } + foreach my $k (keys %labels) { + $labels{$k} = $trans{"label.$k"} if defined($trans{"label.$k"}); + } + } +} + +sub run_menu { + calc_depends(); + $mw = Tk::MainWindow->new; + $lab = $mw->Label(-text => "TeX Live 2008"); + $val = $mw->Label(); + $but = $mw->Button(-text => "Next", -command => \&ask_path); + $lab->pack(-side => "left"); + $val->pack(-side => "left"); + $but->pack(-side => "left"); + Tk::MainLoop(); + return($return); +} + +sub installation_window { + # create a progress bar window + $::sww = $mw->Toplevel(-title => "installation process", + -width => 400); + $::sww->transient($mw); + $::sww->grab(); + $::sww->Label(-text => "Installation process")->pack; + $::progressw = $::sww->Scrolled("ROText", -scrollbars => "e", -height => 16); + $::progressw->pack(-expand => 1, -fill => "both"); + my $percent_done = 0; + $::progress = $::sww->ProgressBar(-variable => \$percent_done, + -width => 20, -length => 400, -from => 0, -to => 100, -blocks => 10, + -colors => [ 0, '#0078b8' ]); + $::progress->pack(-fill => "x"); + my $f = $::sww->Frame; + my $b = $f->Button(-text => $text{'cancel'}, + -command => sub { $::sww->destroy; $mw->destroy; + do_cleanup(); exit(1); } + )->pack(-pady => "2m"); + $f->pack; + # set the vars + $vars{'TEXDIR'} = $dest; + $vars{'TEXDIRW'} = $dest; + $vars{'TEXMFHOME'} = "~/texmf"; + $vars{'TEXMFSYSVAR'} = "$dest/texmf-var"; + $vars{'TEXMFSYSCONFIG'} = "$dest/texmf-config"; + $vars{'TEXMFLOCAL'} = dirname($dest) . "/texmf-local"; + do_installation(); + $return = $MENU_ALREADYDONE; + my $t = $text{'finished'}; + if (!win32()) { + $t .= "\n\n$text{'finishedpath'}"; + } + $t .= "\n\n$text{'welcome'}"; + $t =~ s/TEXDIR/$::vars{'TEXDIR'}/g; + $t =~ s/PLATFORM/$::vars{'this_platform'}/g; + $t =~ s/\\n/\n/g; + $::progressw->insert("end", "\n"); + my $linechar = $::progressw->index("end"); + $::progressw->markSet("finaltext", $linechar); + $::progressw->markGravity("finaltext", "left"); + $::progressw->insert("end", "\n$t"); + $::progressw->see("end"); + $::progressw->tagAdd("centered", $linechar, "end"); + $::progressw->tagConfigure("centered", -justify => "center"); + $b->configure(-text => $text{'finbut'}, + -command => sub { $mw->destroy; }); +} + +sub menu_edit_texdir { + my $key = shift; + our $addyear = 1; + our $addtexlive = 1; + my $val = $vars{$key}; + our $currsel; + our $entry; + sub update_label { + my $t = $currsel; + $t .= "/texlive" if ($addtexlive); + $t .= "/$texlive_release" if ($addyear); + $entry->configure(-text => "$t"); + } + my $hint_var; + if ($key ne 'TEXMFHOME') { + $hint_var = win32() ? $ENV{'USERPROFILE'} : $ENV{'HOME'}; + } else { + $hint_var = win32() ? '%USERPROFILE%' : '$HOME'; + } + my $hint_text = $text{'hinthome'}; + $hint_text =~ s/%%%/$hint_var/; + if ($val =~ m!^(.*)/texlive/$texlive_release$!) { + $currsel = "$1"; + $addyear = 1; + $addtexlive = 1; + } elsif ($val =~ m!^(.*)/$texlive_release$!) { + $currsel = "$1"; + $addyear = 1; + $addtexlive = 0; + } elsif ($val =~ m!^(.*)/texlive$!) { + $currsel = "$1"; + $addyear = 0; + $addtexlive = 1; + } else { + $addyear = 0; + $addtexlive = 0; + $currsel = $val; + } + my $sw = $mw->Toplevel(-title => $text{'changevar'}); + $sw->transient($mw); + $sw->grab(); + $sw->Label(-text => $text{'enterpath'} . " $key: " . $hint_text)->pack(-padx => "2m", -pady => "2m"); + $entry = $sw->Entry(-width => 60)->pack(-padx => "2m", -pady => "2m"); + my $f = $sw->Frame; + my $c1 = $f->Checkbutton(-text => 'Add "texlive"', -variable => \$addtexlive, + -command => \&update_label); + my $c2 = $f->Checkbutton(-text => "Add \"$texlive_release\"", -variable => \$addyear, + -command => \&update_label); + my $foo = $sw->Scrolled("DirTree", -scrollbars => "osoe", + -browsecmd => sub { my ($d) = @_; $currsel = $d; update_label(); }, + -directory => "$currsel"); + my $ff = $sw->Frame; + my $ok = $ff->Button(-text => $text{'ok'}, -command => sub { $val = $entry->get; callback_edit_directories($key,$val); $sw->destroy; }); + my $cancel = $ff->Button(-text => $text{'cancel'}, -command => sub { $sw->destroy; }); + update_label(); + $c1->pack(-side => 'left', -padx => "2m", -pady => "2m"); + $c2->pack(-side => 'right', -padx => "2m", -pady => "2m"); + $f->pack; + $foo->pack(-fill => "both", -expand => 1); + $ok->pack(-side => 'left' , -padx => "2m", -pady => "2m"); + $cancel->pack(-side => 'right', -padx => "2m", -pady => "2m"); + $ff->pack; + # bindings + $sw->bind('' => [ $ok, 'Invoke']); + $sw->bind('' => [ $cancel, 'Invoke']); +} + +1; + +__END__ + +### Local Variables: +### perl-indent-level: 2 +### tab-width: 2 +### indent-tabs-mode: nil +### End: +# vim:set tabstop=2 expandtab: # + -- cgit v1.2.3