Home > Archive > PerlTk > March 2005 > How to integrate a shell into a perl Tk application
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to integrate a shell into a perl Tk application
|
|
| arulk77 2005-03-18, 3:58 pm |
| How do I integrate a "Bash Shell prompt" into one my perl Tk
application.
Is it possible to integrate a "shell" into one of the Frame widget ?
| |
| zentara 2005-03-18, 3:58 pm |
| On 18 Mar 2005 09:01:35 -0800, "arulk77" <arul_enggus@yahoo.com> wrote:
>How do I integrate a "Bash Shell prompt" into one my perl Tk
>application.
>Is it possible to integrate a "shell" into one of the Frame widget ?
Yeah, you can put an xterm with a bash shell into a "window". There
is a trick to it, with finding the window id. Alot of Tk widgets,
Canvas, Text, Frame, support windows.
The thing about a window, is that it will like to take the highest
display priority(on a canvas), so the only way to mask it, is to put
something over it.
Here is a canvas example, followed by a Frame example.
########################################
#########
#!/usr/bin/perl -w
use strict;
use Tk;
my $mw = MainWindow->new();
my $canv = $mw->Canvas(-bg => 'lightsteelblue',
-relief => 'sunken',
-width => 550,
-height => 350)->pack(-expand => 1, -fill => 'both');
my $xtermWidth = 400;
my $xtermHeight = 300;
## this Frame is needed for including the xterm in Tk::Canvas
my $xtermContainer = $canv->Frame(-container => 1);
my $xtid = $xtermContainer->id();
# converting the id from HEX to decimal as xterm requires a decimal Id
my ($xtId) = sprintf hex $xtid;
my $dcontitem = $canv->createWindow(275,175,
-window => $xtermContainer,
-width => $xtermWidth+100,
-height => $xtermHeight,
-state => 'normal');
my $label = $canv->createText( 275,10,
-text => "Hide xterm",
);
$canv->Tk::bind("<Button-1>", \&hideShow);
my $width = $xtermWidth;
my $height = $xtermHeight;
$mw->Button(-text => "Exit", -command => [sub{Tk::exit}] )->pack( );
my $tl; #used to mask xterm
system("xterm -into $xtId &");
MainLoop();
sub hideShow {
if ($canv->itemcget($label, -text) =~ /Hide/) {
$canv->itemconfigure($label,
-fill => 'white',
-text => "Show xterm");
$tl = $mw->Toplevel(-use=>$xtId );
} else {
$canv->itemconfigure($label,
-fill => 'black',
-text => "Hide xterm");
$tl->withdraw;
}
}
__END__
########################################
###########
#!/usr/bin/perl
use strict;
use Tk;
my $mw = MainWindow->new( -bg => 'white' );
my $frame1 = $mw->Frame(
-height => 30,
-bg => 'lightblue',
)->pack( -fill => 'x', -side => 'top' );
my $frame;
my $button = $frame1->Button(
-text => 'Open window',
-command => sub { open_w($frame) },
)->pack;
$frame = $mw->Frame(
-container => 1,
-bg => 'white',
)->pack( -fill => 'y', -side => 'left' );
MainLoop();
sub open_w {
my ($f) = @_;
my $id = sprintf hex $f->id;
my $t = $mw->Toplevel( -use => $id );
system("xterm -into $id &");
}
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
| |
| Ala Qumsieh 2005-03-18, 3:58 pm |
| zentara wrote:
> system("xterm -into $xtId &");
Not all versions of xterm recognize the -into option.
Some version (ex, the default one on Solaris) doesn't, and I couldn't
find a way to do it on that platform :(
--Ala
| |
| Steve Lidie 2005-03-18, 3:58 pm |
| arulk77 <arul_enggus@yahoo.com> wrote:
> How do I integrate a "Bash Shell prompt" into one my perl Tk
> application.
> Is it possible to integrate a "shell" into one of the Frame widget ?
>
Tk::ExecuteCommand is a possibility.
| |
| arulk77 2005-03-18, 8:56 pm |
| Where can I get the Tk:ExecuteCommand package.
It is not included with the default perl tk package.
| |
| zentara 2005-03-19, 8:56 am |
| On Fri, 18 Mar 2005 18:48:48 GMT, Ala Qumsieh <notvalid@email.com>
wrote:
>zentara wrote:
>
>
>Not all versions of xterm recognize the -into option.
>Some version (ex, the default one on Solaris) doesn't, and I couldn't
>find a way to do it on that platform :(
>
>--Ala
Yeah, I've heard that before. Old versions of xterm don't
have -into. If I recall correctly , it was around
version 152 , where it was added.
You could compile it yourself
ftp://invisible-island.net/xterm/xterm.tar.gz
The xterm which comes bundled with the latest X server
from Xorg, is version 197.
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
| |
| Ala Qumsieh 2005-03-20, 3:57 am |
| arulk77 wrote:
> Where can I get the Tk:ExecuteCommand package.
CPAN: search.cpan.org
--Ala
|
|
|
|
|