Thread XTerm in Tk-Oberfläche (7 answers)
Opened by Crian at 2004-06-03 14:54

Crian
 2004-06-03 14:54
#42152 #42152
User since
2003-08-04
5871 Artikel
ModeratorIn
[Homepage]
user image
Ein Snippet, wie man ein XTerm-Fenster in Tk einbettet, findet man hier:

embedding xterm into a Tk app

Ich hab den Code nochmal optisch etwas verschönert:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/perl
#
# This is just a simple demo of how to embed an xterm into a Tk application.
# This one puts it into a canvas, which opens the possibilities of using
# various backgrounds. I got the idea from a posting on the Tk::Zinc maillist
# by Christophe Mertz.
#
# von zentara (Perlmonks)
# "schön" gemacht von Crian
#

use strict;
use warnings;
use Tk;

# Idea ripped from a script by Christophe Mertz of the
# Tk::Zinc module, to work with a plain canvas.
# The Zinc module has much more flexibility in how
# you can hide windows. I had to mask the xterm with a
# toplevel to hide it in the plain old canvas.
#

my $mw = new MainWindow;

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>", \&hide_show);

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 hide_show {
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;
}
} # sub hide_show
# -----------------------------------------------------------------------------


Man müsste nur noch irgendwie ein exit im eingebetteten xterm abfangen und daraufhin ein neues starten. Aber ein sehr nettes Snippet :-)
s--Pevna-;s.([a-z]).chr((ord($1)-84)%26+97).gee; s^([A-Z])^chr((ord($1)-52)%26+65)^gee;print;

use strict; use warnings; Link zu meiner Perlseite

View full thread XTerm in Tk-Oberfläche