Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Gtk2 Scrolling Text

by zentara (Archbishop)
on Sep 08, 2007 at 14:23 UTC ( #637831=snippet: print w/replies, xml ) Need Help??
Description: A simple efficient way to scroll alot of text, like for a teleprompter. It scrolls fast for demo, just slow it down. It also only handles plain text, trying to display html or code, will interfere with the markup process.
#!/usr/bin/perl
use warnings;
use strict;
use Gtk2 '-init';
use Gnome2::Canvas;
use constant TRUE=>1;
use constant FALSE=>0;

my $ts ;

if($ARGV[0]){
    open (FH,"< $ARGV[0]");
    read( FH, $ts, -s FH );                    
    close FH;
}else{
  while(<DATA>){ $ts .= $_ }
}

$ts =~ tr[\x0a\x0d][  ]d; #strip newlines

my $width = 650;
my $height = 60;

my $window = Gtk2::Window->new();

my $canvas = Gnome2::Canvas->new_aa();
my $black = Gtk2::Gdk::Color->new (0x0000,0x0000,0x0000);
$canvas->modify_bg('normal',$black);
$window->add($canvas);

$window->signal_connect('destroy'=>\&_closeapp);

$window->set_default_size($width,$height);

my $root   = $canvas->root;

my $markup = "<span  foreground= '#00FF00' size='50000' 
              weight = 'ultralight'><i><u> $ts </u></i></span>";

my $text = Gnome2::Canvas::Item->new($root, 'Gnome2::Canvas::Text',
              #text => $markup,
              markup => $markup,
              fill_color => 'green',  
              anchor => 'w',
              justification => 'left',
              x=>0, 
              x_offset=> -$width/3,
              y=>30);

$text->raise_to_top();
$window->show_all();

my $timer = Glib::Timeout->add(1000/24, \&timer);

my ($x1, $y1, $x2, $y2) = $text->get_bounds;
print "$x2\n";
my $right_bound = $x2 + $width;

Gtk2->main();

sub timer {
        $text->move( -20, 0 ); 
        my ($x1, $y1, $x2, $y2) = $text->get_bounds;
        print "$x2\n";
        if($x2 < -40){
             $text->move( $right_bound + 60, 0 );
        
            }
        
        return 1;
}

sub _closeapp{
    Gtk2->main_quit();
    return 0;
}

__DATA__
This article is Copyright 1990-2004 by Steve Summit.  Content from the
book _C Programming FAQs: Frequently Asked Questions_ is made availabl
+e
here by permission of the author and the publisher as a service to the
community.  It is intended to complement the use of the published text
and is protected by international copyright laws.  The on-line content
may be accessed freely for personal use but may not be republished
without permission.
__END__
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: snippet [id://637831]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2022-07-04 00:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?