Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

embedding xterm in perl/tk window

by diamantis (Beadle)
on Oct 07, 2007 at 05:24 UTC ( [id://643221]=perlquestion: print w/replies, xml ) Need Help??

diamantis has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks! I was trying to embed an xterm as described here (embedding xterm into a Tk app)
my $terminal = $mw->Toplevel(); my $xtid = $terminal->id(); my ($xtId) = sprintf hex $xtid; system("xterm -into $xtId -hold -e ls &");
Is there a way of resizing the toplevel window $terminal so xterm can fit in it nicely? Can I somehow find the width and height of the xterm? Thank you very much

Edit: g0n - linkified URL

Replies are listed 'Best First'.
Re: embedding xterm in perl/tk window
by graff (Chancellor) on Oct 07, 2007 at 08:00 UTC
    Can I somehow find the width and height of the xterm?

    Assuming a bash shell, you can add these two lines to your .bashrc:

    export LINES export COLUMNS
    The xterm sets those two environment variables to the window's height and width, respectively, in characters, but since the xterm being run by your Perl/Tk script is in a sub-shell, the values for that particular xterm window won't be accessible by the perl script. (You only get to see the values for the xterm shell from which the perl script was run, as $ENV{LINES}, $ENV{COLUMNS}.

    You can control the xterm size on start-up by adding this option:  -geometry WxH (where W and H are width and height in characters). In the code that you cited (embedding xterm into a Tk app by zentara) just add that option to the string being passed to system() at line 46.

    Using "-geometry 78x23" actually improved its behavior for me; YMMV. It seems that 80x24 is the typical default xterm size, but if your font is different from the one zentara used, your display might not seem to work right.

    You'll probably need to experiment for a while with font sizes for the xterm and pixel sizes for the containing widget, to get a feel for how they relate.

    (BTW, check out What shortcuts can I use for linking to other information? to see the easy way to link to other nodes at the monastery. -- Update: I changed this link, because Writeup Formatting Tips isn't the direct source for info about linking.)

      After managing to find the right size I've stuck into another problem. I am opening xterm and executing a program

      xterm -into $someid -e programname

      but when the program finishes xterm disapears without leaving time to view what happened.

      I tried xterm -into $someid -hold -e programname, but then when I close the container window an xterm process keeps staying running!

      I could not figure out a simple way to make it behave in a "Press any key to end" way, without depending on the program executed to do so.

      Thank you for the linking help also!

        Let's take a step back and talk about why you are using an xterm this way. What does the xterm process give you that a basic Tk::Text window does not? If you are simply trying to display the output of a unix shell command inside a Perl/Tk app, the usual way to do that is:
        use strict; use Tk; my $mw = MainWindow->new; my $tx = $mw->Scrolled('Text', -height => 24, -width => 90)->pack(); my $data = `programname`; $tx->insert( '0.0', $data ); MainLoop;
        (That worked pretty well for me when I put "ls" in place of "programname".)

        Presumably there's more to your app than that, but you get the idea. If that's the sort of thing you're after, using an embedded xterm, while really cool, is more complicated than it needs to be. If you need something more, what would that be, exactly?

        This is an old thread, but I have ta solution to keep the xterm active. Adding bash command to -e.
        $cmd = "\'ls; bash\'"; system("xterm -into $xtId -hold -e $cmd &");

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-20 04:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found