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
|
#!/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;
require Tk::Font;
use utf8;
no utf8;
#
#
my $tit;
my $can;
my $prv;
my $nxt;
my $img;
my $dest;
my $warning;
my $mw;
my $usedfont;
my $fmain;
my $fbuttons;
my $ftitle;
my $counter;
my $lineskip;
my $LEFT = 130;
my $RIGHT = 50;
my $TOP = 50;
my $BOTTOM = 50;
my $INF = 300;
my $MWIDTH = 730;
my $MHEIGHT = 480;
my $TITLEHEIGHT = 30;
my $BUTTONSHEIGHT = 50;
my $INNERWIDTH = ($MWIDTH - $LEFT - $RIGHT);
my $INNERHEIGHT = ($MHEIGHT - $TOP - $TITLEHEIGHT - $BOTTOM - $BUTTONSHEIGHT);
our %text;
our %labels;
require("installer/install-translations.pl");
# the main installer runs %{$::run_menu}
$::run_menu = \&run_menu_wizard;
######################################################################
# From here on only function definitions
# ####################################################################
sub setup_hooks_wizard {
@::info_hook = ();
push @::info_hook,
sub {
return unless defined($mw);
wizard_update_status(join(" ",@_));
$mw->update;
};
@::warn_hook = ();
push @::warn_hook,
sub {
return unless defined($mw);
wizard_update_status(join(" ",@_));
$mw->update;
};
@::install_packages_hook = ();
push @::install_packages_hook, \&wizard_update_progressbar;
push @::install_packages_hook, sub { $mw->update; };
}
sub wizard_update_status {
my ($p) = @_;
$::progressw->insert("end", "$p");
$::progressw->see("end");
}
sub wizard_update_progressbar {
my ($n,$total) = @_;
if (defined($n) && defined($total)) {
$::progress->value(int($n*100/$total));
}
}
################# WELCOME SCREEN ######################################
sub run_menu_wizard {
$mw = Tk::MainWindow->new(-width => $MWIDTH, -height => $MHEIGHT);
setup_hooks_wizard();
$dest = $vars{'TEXDIR'};
my $img = $mw->Photo(-format => 'png', -file => "$::installerdir/tlpkg/installer/texlive2008-wizard.png");
$mw->Label(-image => $img, -background => "#0078b8")->place(-x => 0, -y => 0);
$ftitle = $mw->Frame(-height => $TITLEHEIGHT, -width => $INNERWIDTH);
$ftitle->update;
$ftitle->place(-x => $LEFT, -y => $TOP);
$tit = $ftitle->Label(-text => $text{'title'});
$usedfont= $tit->cget("-font");
$lineskip = $usedfont->metrics("-linespace");
$tit->place(-x => 0, -y => 0);
$counter = $ftitle->Label(-text => "1/4");
$counter->place(-x => $INNERWIDTH, -y => 0, -anchor => "ne");
$fmain = $mw->Frame(-height => $INNERHEIGHT, -width => $INNERWIDTH);
#, -borderwidth => 1, -relief => "ridge");
$fmain->place(-x => $LEFT, -y => ($TOP + $TITLEHEIGHT));
$can = $mw->Button(-width => 10, -relief => "ridge", -text => $text{'cancel'},
-command => sub { $return = $MENU_ABORT; $mw->destroy; });
$nxt = $mw->Button(-width => 10, -relief => "ridge", -text => $text{'next'});
$prv = $mw->Button(-width => 10, -relief => "ridge", -text => $text{'prev'});
$can->place(-x => $LEFT, -y => ($MHEIGHT - $BOTTOM), -anchor => "sw");
my $rb = $MWIDTH - $RIGHT;
$nxt->place(-x => ($MWIDTH - $RIGHT) ,
-y => ($MHEIGHT - $BOTTOM), -anchor => "se");
reset_start();
Tk::MainLoop();
return($return);
}
sub reset_start {
for ($fmain->children) {
$_->destroy;
}
$counter->configure(-text => "1/4");
$prv->placeForget;
my $inf = $fmain->Label(-text => $text{'wizhello'}, -justify => "left");
$inf->place(-x => 0, -y => 100);
$nxt->configure(-text => $text{'next'}, -command => \&ask_path );
$nxt->configure(-state => "normal");
}
################## PATH SCREEN ################################
sub ask_path {
for ($fmain->children) {
$_->destroy;
}
$counter->configure(-text => "2/4");
my $lab = $fmain->Label(-text => $text{'destfolder'});
my $val = $fmain->Label(-textvar => \$dest);
my $but = $fmain->Button(-text => $text{'change'}, -command => \&change_path,
-relief => "ridge", -width => 10);
my $pa = $fmain->Checkbutton(-text => $labels{'optletter'},
-variable => \$vars{"option_letter"});
#
# disable the "Advanced Configuration" button switching to the
# perltk installer
#
#my $cb = $fmain->Button(-text => $text{'advcustom'},
# -relief => "ridge",
# -command => sub { $mw->destroy;
# require("installer/install-menu-perltk.pl");
# setup_hooks_perltk();
# $return = run_menu_perltk();
# });
calc_depends();
$fmain->Label(-text => $text{'pathinfo'},
-justify => "left")->place(-x => 0, -y => 30);
my $ytmp = 100;
$lab->place(-x => 0, -y => $ytmp, -anchor => "w");
$ytmp += ($lineskip + 10);
$val->place(-x => 0, -y => $ytmp, -anchor => "w");
$but->place(-x => $INNERWIDTH, -y => $ytmp, -anchor => "e");
$warning = $fmain->Label(-foreground => "red");
check_show_warning();
$ytmp += ($lineskip + 10);
$warning->place(-x => 0, -y => $ytmp, -anchor => "w");
$pa->place(-x => 0, -y => $ytmp + 30);
#$cb->place(-x => $INNERWIDTH, -y => $INNERHEIGHT, -anchor => "se");
$fmain->Label(-text => "$text{'diskreq'}: $vars{'total_size'} MB",
-justify => "left"
)->place(-x => 0, -y => $fmain->height, -anchor => "sw");
$prv->configure(-text => $text{'prev'}, -command => \&reset_start );
$nxt->configure(-text => $text{'next'}, -command => \&ask_go );
my $rb = $MWIDTH - $RIGHT;
$rb -= $nxt->width;
$rb -= 30;
$prv->place(-x => $rb, -y => ($MHEIGHT - $BOTTOM), -anchor => "se");
}
sub check_show_warning {
if (TeXLive::TLUtils::texdir_check($vars{'TEXDIR'})) {
$warning->configure(-text => "");
$nxt->configure(-state => "normal");
} else {
$warning->configure(-text => $text{'notwritable'});
$nxt->configure(-state => "disabled");
}
}
sub change_path {
my $val = $dest;
my $sw = $mw->Toplevel(-title => "Changing TEXDIR");
$sw->transient($mw);
$sw->grab();
$sw->Label(-text => $text{'enterpath'} . " TEXDIR: ")->pack(-padx => "2m", -pady => "2m");
my $entry = $sw->Entry(-textvariable => $val, -width => 60);
$entry->pack(-padx => "2m", -pady => "2m");
my $f = $sw->Frame;
my $okbutton = $f->Button(-text => $text{'ok'}, -width => 10,
-relief => "ridge",
-command => sub { $val = $entry->get; callback_change_texdir($val) ; $sw->destroy })->pack(-side => 'left', -padx => "2m", -pady => "2m");
my $cancelbutton = $f->Button(-text => $text{'cancel'}, -relief => "ridge",
-width => 10,
-command => sub { $sw->destroy })->pack(-side => 'right', -padx => "2m", -pady => "2m");
$f->pack(-expand => 'x');
# bindings
$sw->bind('<Return>' => [ $okbutton, 'Invoke']);
$sw->bind('<Escape>' => [ $cancelbutton, 'Invoke']);
}
sub callback_change_texdir {
my ($val) = @_;
my $home = getenv('HOME');
if (win32()) {
$home = getenv('USERPROFILE');
$home =~ s!\\!/!g;
}
$home ||= '~';
$val =~ s!\\!/!g;
$vars{'TEXDIR'} = $val;
$vars{'TEXDIR'} =~ s/^~/$home/;
$vars{'TEXMFLOCAL'} =~ s/^~/$home/;
$vars{'TEXMFSYSVAR'} =~ s/^~/$home/;
$vars{'TEXMFSYSCONFIG'} =~ s/^~/$home/;
# only if we set TEXDIR we set the others in parallel
if ($vars{'TEXDIR'}=~/^(.*)\/$texlive_release$/) {
$vars{'TEXMFLOCAL'}="$1/texmf-local";
$vars{'TEXMFSYSVAR'}="$1/$texlive_release/texmf-var";
$vars{'TEXMFSYSCONFIG'}="$1/$texlive_release/texmf-config";
} elsif ($vars{'TEXDIR'}=~/^(.*)$/) {
$vars{'TEXMFLOCAL'}="$1/texmf-local";
$vars{'TEXMFSYSVAR'}="$1/texmf-var";
$vars{'TEXMFSYSCONFIG'}="$1/texmf-config";
}
$vars{'TEXDIRW'}=$vars{'TEXDIR'};
$dest = $vars{'TEXDIR'};
check_show_warning();
}
################## INSTALL SCREEN #############################
sub ask_go {
for ($fmain->children) {
$_->destroy;
}
$counter->configure(-text => "3/4");
my $inf = $fmain->Label(-justify => "left", -text => $text{'readyinst'} . "\n\n" . $text{'destfolder'} . ": $dest");
$inf->place(-x => 0, -y => 100);
$nxt->configure(-text => $text{'instshort'},
-command => \&wizard_installation_window);
$prv->configure(-text => $text{'prev'}, -command => \&ask_path);
}
sub wizard_installation_window {
for ($fmain->children) {
$_->destroy;
}
$counter->configure(-text => "4/4");
# create a progress bar window
# compute the height of the Text by the given font
$::progressw = $fmain->Scrolled("ROText", -scrollbars => "e",
-wrap => "word");
# we want to have the progressbar about 20px wide, so compute how
# many lines of the current font do fit into the remaining area
my $lines = int( ($INNERHEIGHT - 20) / $lineskip);
# it seems that on Windows the computation is not right, the
# progress bar overwrites the last line of the text widget
# remove one line here
$lines-- if win32();
$::progressw->configure(-height => $lines);
$::progressw->place(-x => 0, -y => 0, -width => $INNERWIDTH);
# that is necessary otherwise the progressbar gets very strange dimensions
$fmain->update;
my $percent_done = 0;
# compute the remaining space in pixel for the progressbar
my $pw = $INNERHEIGHT - ($lines * $lineskip) - 5;
# make sure that the line we remove above for Windows is not re-added
# to the size of the progressbar. The 7 was found by trial and error
$pw -= ($lineskip + 7) if win32();
$::progress = $fmain->ProgressBar(-variable => \$percent_done,
-width => $pw, -length => $INNERWIDTH,
-from => 0, -to => 110, -blocks => 10,
-colors => [ 0, '#0078b8' ]);
$::progress->place(-x => 0, -y => $INNERHEIGHT, -anchor => "sw");
#
# change the buttons so that the Prev disappears, the Next becomes
# Cancel, and the Cancel button disappears
$prv->placeForget;
$can->placeForget;
$nxt->configure(-text => $text{'cancel'},
-command => sub { $return = $MENU_ABORT; $mw->destroy; });
calc_depends();
do_installation();
$::progress->value(110);
$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;
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");
$nxt->configure(-text => $text{'finbut'},
-command => sub { $mw->destroy; });
}
################### END OF MODULE RETURN 1 FOR REQUIRE ###########
1;
__END__
### Local Variables:
### perl-indent-level: 2
### tab-width: 2
### indent-tabs-mode: nil
### End:
# vim:set tabstop=2 expandtab: #
|