todo: Not using Gtk2::Embed any more.
[techtalk-pse.git] / techtalk-pse.pl
index 85104a6..71a4ee2 100755 (executable)
@@ -69,20 +69,21 @@ there is a discussion on L<WHAT MAKES A GOOD TALK>.
 
 =head1 RUNNING THE TOOL FROM THE COMMAND LINE
 
 
 =head1 RUNNING THE TOOL FROM THE COMMAND LINE
 
-Tech Talk PSE talks are just directories containing C<*.html> and
-C<*.sh> (shell script) files:
+Tech Talk PSE talks are just directories containing C<*.html>,
+C<*.sh> (shell script) and C<*.term> (terminal) files:
 
  0010-introduction.html
  0500-demonstration.sh
 
  0010-introduction.html
  0500-demonstration.sh
+ 0600-command-line.term
  9900-conclusion.html
 
 The filenames that Tech Talk PSE considers to be slides have to match
 the regular expression:
 
  9900-conclusion.html
 
 The filenames that Tech Talk PSE considers to be slides have to match
 the regular expression:
 
- ^(\d+)(?:-.*)\.(html|sh)$
+ ^(\d+)(?:-.*)\.(html|sh|term)$
 
 
-(any other file or subdirectory is ignored).  Shell scripts I<must>
-be executable.
+(any other file or subdirectory is ignored).  Shell scripts and
+terminal files I<must> be executable.
 
 =head2 DISPLAYING AN EXISTING TALK
 
 
 =head2 DISPLAYING AN EXISTING TALK
 
@@ -212,12 +213,14 @@ my $webkit = Gtk2::WebKit::WebView->new ();
 my $vte = Gnome2::Vte::Terminal->new ();
 my $notebook = Gtk2::Notebook->new ();
 my $splash = make_splash_page ();
 my $vte = Gnome2::Vte::Terminal->new ();
 my $notebook = Gtk2::Notebook->new ();
 my $splash = make_splash_page ();
+my $emptylabel = Gtk2::Label->new ();
 
 my $webkitscroll = Gtk2::ScrolledWindow->new ();
 $webkitscroll->add ($webkit);
 $webkitscroll->set_policy('automatic', 'automatic');
 
 my $webkitpage = $notebook->append_page ($webkitscroll);
 
 my $webkitscroll = Gtk2::ScrolledWindow->new ();
 $webkitscroll->add ($webkit);
 $webkitscroll->set_policy('automatic', 'automatic');
 
 my $webkitpage = $notebook->append_page ($webkitscroll);
+my $shpage = $notebook->append_page ($emptylabel);
 my $vtepage = $notebook->append_page ($vte);
 my $splashpage = $notebook->append_page ($splash);
 
 my $vtepage = $notebook->append_page ($vte);
 my $splashpage = $notebook->append_page ($splash);
 
@@ -295,13 +298,13 @@ $w->signal_connect (
 
 
 $w->add ($vbox);
 
 
 $w->add ($vbox);
-$w->show_all ();
 
 
-$w->set_decorated (0);
-$w->fullscreen ();
-$w->move (0,0);
+# This allows us to resize the window in window_in_corner().
+$w->set_geometry_hints ($w, { min_width => 100 }, qw(min-size));
+
+$w->show_all ();
 
 
-my $scr = $w->get_screen();
+window_fullscreen ();
 
 &update_slide();
 
 
 &update_slide();
 
@@ -315,13 +318,13 @@ sub reread_directory
 
     my $i = 0;
     foreach (glob ("*")) {
 
     my $i = 0;
     foreach (glob ("*")) {
-        if (/^(\d+)(?:-.*)\.(html|sh)$/) {
+        if (/^(\d+)(?:-.*)\.(html|sh|term)$/) {
             print STDERR "reading $_\n" if $verbose;
 
             my $seq = $1;
             my $ext = $2;
             warn "techtalk-pse: $_: command file is not executable (+x)\n"
             print STDERR "reading $_\n" if $verbose;
 
             my $seq = $1;
             my $ext = $2;
             warn "techtalk-pse: $_: command file is not executable (+x)\n"
-                if $ext eq "sh" && ! -x $_;
+                if ($ext eq "sh" || $ext eq "term") && ! -x $_;
 
             my $h = { name => $_, seq => $1, ext => $2, i => $i };
             push @files, $h;
 
             my $h = { name => $_, seq => $1, ext => $2, i => $i };
             push @files, $h;
@@ -355,6 +358,25 @@ sub reread_directory
     }
 }
 
     }
 }
 
+sub window_fullscreen
+{
+    $w->set_decorated (0);
+    $w->fullscreen ();
+    $w->move (0,0);
+}
+
+sub window_in_corner
+{
+    $w->set_decorated (1);
+    $w->unfullscreen ();
+
+    my $root = Gtk2::Gdk->get_default_root_window ();
+    my ($width, $height) = $root->get_size;
+
+    $w->resize ($width/2, $height/4);
+    $w->move ($width/2, 64);
+}
+
 sub run_process
 {
     $pid = $vte->fork_command("./" . $current->{name}, [], [], undef, 0, 0, 0);
 sub run_process
 {
     $pid = $vte->fork_command("./" . $current->{name}, [], [], undef, 0, 0, 0);
@@ -376,6 +398,8 @@ sub switch_slide
 {
     my $action = shift;
 
 {
     my $action = shift;
 
+    window_fullscreen ();
+
     if ($pid) {
        kill_process ();
     }
     if ($pid) {
        kill_process ();
     }
@@ -429,6 +453,13 @@ sub update_slide
        }
        # Run a shell command.
        elsif ($current->{ext} eq "sh") {
        }
        # Run a shell command.
        elsif ($current->{ext} eq "sh") {
+            window_in_corner ();
+
+           $notebook->set_current_page ($shpage);
+           run_process ();
+       }
+        # Open a VTE terminal.
+       elsif ($current->{ext} eq "term") {
            $notebook->set_current_page ($vtepage);
            $vte->grab_focus ();
            run_process ();
            $notebook->set_current_page ($vtepage);
            $vte->grab_focus ();
            run_process ();
@@ -626,8 +657,8 @@ somewhere:
 
 A tech talk consists of HTML files ("slides") and shell scripts.  The
 filenames must start with a number, followed optionally by a
 
 A tech talk consists of HTML files ("slides") and shell scripts.  The
 filenames must start with a number, followed optionally by a
-description, followed by the extension (C<.html> or C<.sh>).  So to
-start our talk with two slides:
+description, followed by the extension (C<.html>, C<.sh> or C<.term>).
+So to start our talk with two slides:
 
  echo "This is the introduction" > 0010-introduction.html
  echo "This is the second slide" > 0020-second.html
 
  echo "This is the introduction" > 0010-introduction.html
  echo "This is the second slide" > 0020-second.html
@@ -695,9 +726,10 @@ styles as I edit them.  Just start firefox in the talk directory:
 When you edit an HTML file, click the Firefox reload button to
 immediately see your changes.
 
 When you edit an HTML file, click the Firefox reload button to
 immediately see your changes.
 
-Tech Talk PSE uses Mozilla embedding to display HTML, which uses the
-same Mozilla engine as Firefox, so what you should see in Firefox
-should be identical to what Tech Talk PSE displays.
+Tech Talk PSE uses WebKit embedding to display HTML.  HTML is
+standardized enough nowadays that what you see in Firefox and other
+browsers should be the same as what Tech Talk PSE displays.
+WebKit-based browsers (Chrome, Safari) should be identical.
 
 =head2 CREATING FIGURES
 
 
 =head2 CREATING FIGURES
 
@@ -707,8 +739,8 @@ an C<E<lt>imgE<gt>> tag, eg:
 
  <img src="fig1.gif">
 
 
  <img src="fig1.gif">
 
-Suitable tools include: XFig, GnuPlot, GraphViz, and many TeX tools
-such as PicTex and in particular TikZ.
+Suitable tools include: Inkscape, XFig, GnuPlot, GraphViz, and many
+TeX tools such as PicTex and in particular TikZ.
 
 =head2 EMBEDDING VIDEOS, ANIMATIONS, ETC.
 
 
 =head2 EMBEDDING VIDEOS, ANIMATIONS, ETC.
 
@@ -737,9 +769,14 @@ either rename or make a symbolic link to the slide name:
 
 =head2 TIPS FOR WRITING SHELL SCRIPTS
 
 
 =head2 TIPS FOR WRITING SHELL SCRIPTS
 
-Make sure each C<*.sh> file you write is executable, otherwise Tech
-Talk PSE won't be able to run it.  (The program gives a warning if you
-forget this).
+Make sure each C<*.sh> or C<*.term> file you write is executable,
+otherwise Tech Talk PSE won't be able to run it.  (The program gives a
+warning if you forget this).
+
+The difference between C<*.sh> (shell script) and C<*.term> (a
+terminal script) is that a shell script runs any commands, usually
+graphical commands, whereas a terminal script runs in a full screen
+terminal.
 
 A good idea is to start each script by sourcing some common functions.
 All my scripts start with:
 
 A good idea is to start each script by sourcing some common functions.
 All my scripts start with:
@@ -776,30 +813,21 @@ In C<functions>, I have:
      # when it exits.
      chmod -w $HISTFILE
  
      # when it exits.
      chmod -w $HISTFILE
  
-     # Run gnome-terminal.
-     exec \
-         gnome-terminal \
-         --window \
-         --geometry=+100+100 \
-         --hide-menubar \
-         --disable-factory \
-         -e '/bin/bash --norc' \
-         "$@"
+     # Execute a shell.
+     bash --norc "$@"
  }
 
 By initializing the shell history, during your talk you can rapidly
 recall commands to start parts of the demonstration just by hitting
  }
 
 By initializing the shell history, during your talk you can rapidly
 recall commands to start parts of the demonstration just by hitting
-the Up arrow.  A complete shell script from one of my talks would look
-like this:
+the Up arrow.  A complete terminal script from one of my talks would
+look like this:
 
  #!/bin/bash -
  source functions
  add_history guestfish -i debian.img
 
  #!/bin/bash -
  source functions
  add_history guestfish -i debian.img
- terminal --title="Examining a Debian guest image in guestfish"
+ terminal
 
 
-This is just a starting point for your own scripts.  You may want to
-use a different terminal, such as xterm, and you may want to adjust
-terminal fonts.
+This is just a starting point for your own scripts.
 
 =head1 REFERENCE
 
 
 =head1 REFERENCE
 
@@ -809,7 +837,7 @@ Tech Talk PSE displays the slides in the directory in lexicographic
 order (the same order as C<LANG=C ls -1>).  Only files matching the
 following regexp are considered:
 
 order (the same order as C<LANG=C ls -1>).  Only files matching the
 following regexp are considered:
 
- ^(\d+)(?:-.*)\.(html|sh)$
+ ^(\d+)(?:-.*)\.(html|sh|term)$
 
 For future compatibility, you should ensure that every slide has a
 unique numeric part (ie. I<don't> have C<0010-aaa.html> and
 
 For future compatibility, you should ensure that every slide has a
 unique numeric part (ie. I<don't> have C<0010-aaa.html> and
@@ -877,7 +905,7 @@ that it took to get them all in one place.
 
 I don't think you can get away with spending less than two full days
 preparing a talk, if you want to master the topic and draw up accurate
 
 I don't think you can get away with spending less than two full days
 preparing a talk, if you want to master the topic and draw up accurate
-slides.  Steve Jobs is reputed to spend weeks preparing his annual
+slides.  Steve Jobs was reputed to spend weeks preparing his annual
 sales talk to the Apple faithful.
 
 B<Thirdly:> Now that you're going to write your talk as an essay, what
 sales talk to the Apple faithful.
 
 B<Thirdly:> Now that you're going to write your talk as an essay, what
@@ -908,9 +936,11 @@ The Cognitive Style of PowerPoint, Tufte, Edward R.
 
 Richard W.M. Jones L<http://people.redhat.com/~rjones/>
 
 
 Richard W.M. Jones L<http://people.redhat.com/~rjones/>
 
+Daniel BerrangĂ© L<http://berrange.com/>
+
 =head1 COPYRIGHT
 
 =head1 COPYRIGHT
 
-Copyright (C) 2010 Red Hat Inc.
+Copyright (C) 2010-2012 Red Hat Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by