Re: embed application into tk gui



On 21 Jul 2005 08:22:21 -0700, "ennitao@xxxxxxxxx" <ennitao@xxxxxxxxx>
wrote:

>Cygwin has X11 libraries. Although a Unix platform on top of a Windows
>is not the same as linux, how would you do it on linux? Btw, I'm not
>using perl/tk just tk.
>
>Thanks,
>Elizabeth

On linux, you setup a "container", certain widgets like Frame, Canvas,
and Text support the container option. Once you have the container, you
get it's Xserver window id.
Now you need an app, that supports the option to use a specified
window-id. Xterm. mplayer, xv, and I'm sure there are others, support
the wid option.

Here is an example with mplayer:
http://perlmonks.org?node_id=417164


Or here is a simple xterm embed:
(You can't hide a container, except by masking over it)

#!/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__


--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
.



Relevant Pages

  • Re: Disk image viewable in Windows/Linux
    ... mount the container on Linux or Windows to read the files and their contents in a record-oriented sense; I want to be able to examine the binary disk structure, the location and contents of the meta-data, the location and contents of the files/directories/other stuff. ... And you would not need a container file either. ...
    (comp.os.vms)
  • Re: cryptsetup in Windows und Linux gemeinsam nutzen?
    ... Hallo Frank Albrecht, II, am 28 Dez 2005 schriebst du: ... > den Container in Windows und Linux wahlwiese nutze kann, ...
    (de.comp.security.misc)
  • Re: communication among CPU cores
    ... different in Windows. ... A process is merely a container for a memory space and ... that's basically true under Linux as well. ...
    (comp.lang.asm.x86)
  • Re: Disk image viewable in Windows/Linux
    ... mount the container on Linux or Windows to read the files and their ... the binary disk structure, the location and contents of the ... windows or Linux. ... And you would not need a container file either. ...
    (comp.os.vms)
  • Re: ucb logo
    ... Been using Linux ... but in this case it is *not* Windows ... creation of Emacs logo-mode. ... This behavior is exactly the same as launching xterm from another xterm. ...
    (comp.lang.logo)