Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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__

In reply to Gtk2 Scrolling Text by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-19 10:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found