Wondering if someone might be able to give me some help, I have a simple Perl program to control a telnet session, using Net::Telnet I would like to have I/O redirected to a Tk GUI, but am a little confused about how to this. I have the Tk GUI written, just confused about what type of widget I should use in the GUI and how to get the Input and Output from my terminal to the gui.
> Wondering if someone might be able to give me some help, I have a > simple Perl program to control a telnet session, using Net::Telnet I > would like to have I/O redirected to a Tk GUI, but am a little > confused about how to this. I have the Tk GUI written, just confused > about what type of widget I should use in the GUI and how to get the > Input and Output from my terminal to the gui.
I'm just guessing here, but I think I'd just use a scrolled list box ( $listBox = ??->Scrolled('Listbox', ... ) and feed the output of you $telnet->cmd call returns into the box (possibly interspersed with the commands you sent (possibly with different markings or colors to denote cmds from replies) using a $ListBox->insert('end', ... ). Hope that makes sense.
>> Wondering if someone might be able to give me some help, I have a >> simple Perl program to control a telnet session, using Net::Telnet I >> would like to have I/O redirected to a Tk GUI, but am a little >> confused about how to this. I have the Tk GUI written, just confused >> about what type of widget I should use in the GUI and how to get the >> Input and Output from my terminal to the gui.
> I'm just guessing here, but I think I'd just use a scrolled list box > ( $listBox = ??->Scrolled('Listbox', ... ) and feed the output of you > $telnet->cmd call returns into the box (possibly interspersed with the > commands you sent (possibly with different markings or colors to denote > cmds from replies) using a $ListBox->insert('end', ... ). Hope that > makes sense.
Another option is to dump the output to a Text widget.
Opt 1) I have never used Net::Telnet before - but it seems you should be able to capture the output and "manually" write it to the text widget. The drawback is that this would one way - writing.
Opt 2) You didn't mention your platform - but if it is NOT windows AND you are willing to forego Net::Telnet, then you can also try launching a telnet session using IPC::Open2 and use fileevent to trigger the writing to the Text widget.This would also allow input to be read if you trigger reading from the text widget (trigger on hitting the Enter key). This should offer you two way input/output.
Opt 3) Embed an actual xterm into a Tk window (Frame) using the -container option and the xterm -into option. The last time I tried to do this was a number of years ago and I didn't like how it remained a fixed size. This way you can type your commands in to an actual terminal window.
> > On 2/28/2011 11:04 PM, Matt wrote: > >> Hi guys,
> >> Wondering if someone might be able to give me some help, I have a > >> simple Perl program to control a telnet session, using Net::Telnet I > >> would like to have I/O redirected to a Tk GUI, but am a little > >> confused about how to this. I have the Tk GUI written, just confused > >> about what type of widget I should use in the GUI and how to get the > >> Input and Output from my terminal to the gui.
> > I'm just guessing here, but I think I'd just use a scrolled list box > > ( $listBox = ??->Scrolled('Listbox', ... ) and feed the output of you > > $telnet->cmd call returns into the box (possibly interspersed with the > > commands you sent (possibly with different markings or colors to denote > > cmds from replies) using a $ListBox->insert('end', ... ). Hope that > > makes sense.
> Another option is to dump the output to a Text widget.
> Opt 1) I have never used Net::Telnet before - but it seems you should be > able to capture the output and "manually" write it to the text widget. > The drawback is that this would one way - writing.
> Opt 2) You didn't mention your platform - but if it is NOT windows AND > you are willing to forego Net::Telnet, then you can also try launching a > telnet session using IPC::Open2 and use fileevent to trigger the writing > to the Text widget.This would also allow input to be read if you trigger > reading from the text widget (trigger on hitting the Enter key). This > should offer you two way input/output.
> Opt 3) Embed an actual xterm into a Tk window (Frame) using the > -container option and the xterm -into option. The last time I tried to > do this was a number of years ago and I didn't like how it remained a > fixed size. This way you can type your commands in to an actual terminal > window.
> Jack
Hi,
Thanks very much for the help-I decided to experiment with embedding the xterm in the Tk window. This worked, but I am using Tk::NoteBook and it seems that the SAME xterm process gets embedded in each tab of the NoteBook. Is there a way to insert a different xterm process into each page of the notebook?
> On Mar 1, 11:34 pm, Jack<goodca...@hotmail.com> wrote: >> On 01/03/2011 5:11 PM, $Bill wrote:
>>> On 2/28/2011 11:04 PM, Matt wrote: >>>> Hi guys,
>>>> Wondering if someone might be able to give me some help, I have a >>>> simple Perl program to control a telnet session, using Net::Telnet I >>>> would like to have I/O redirected to a Tk GUI, but am a little >>>> confused about how to this. I have the Tk GUI written, just confused >>>> about what type of widget I should use in the GUI and how to get the >>>> Input and Output from my terminal to the gui.
>>> I'm just guessing here, but I think I'd just use a scrolled list box >>> ( $listBox = ??->Scrolled('Listbox', ... ) and feed the output of you >>> $telnet->cmd call returns into the box (possibly interspersed with the >>> commands you sent (possibly with different markings or colors to denote >>> cmds from replies) using a $ListBox->insert('end', ... ). Hope that >>> makes sense.
>> Another option is to dump the output to a Text widget.
>> Opt 1) I have never used Net::Telnet before - but it seems you should be >> able to capture the output and "manually" write it to the text widget. >> The drawback is that this would one way - writing.
>> Opt 2) You didn't mention your platform - but if it is NOT windows AND >> you are willing to forego Net::Telnet, then you can also try launching a >> telnet session using IPC::Open2 and use fileevent to trigger the writing >> to the Text widget.This would also allow input to be read if you trigger >> reading from the text widget (trigger on hitting the Enter key). This >> should offer you two way input/output.
>> Opt 3) Embed an actual xterm into a Tk window (Frame) using the >> -container option and the xterm -into option. The last time I tried to >> do this was a number of years ago and I didn't like how it remained a >> fixed size. This way you can type your commands in to an actual terminal >> window.
>> Jack
> Hi,
> Thanks very much for the help-I decided to experiment with embedding > the xterm in the Tk window. This worked, but I am using Tk::NoteBook > and it seems that the SAME xterm process gets embedded in each tab of > the NoteBook. Is there a way to insert a different xterm process into > each page of the notebook?
Barring a cosmic shift in reality, Tk::Notebook is doing what your program tells it to. Post some code and let's see.
> > On Mar 1, 11:34 pm, Jack<goodca...@hotmail.com> wrote: > >> On 01/03/2011 5:11 PM, $Bill wrote:
> >>> On 2/28/2011 11:04 PM, Matt wrote: > >>>> Hi guys,
> >>>> Wondering if someone might be able to give me some help, I have a > >>>> simple Perl program to control a telnet session, using Net::Telnet I > >>>> would like to have I/O redirected to a Tk GUI, but am a little > >>>> confused about how to this. I have the Tk GUI written, just confused > >>>> about what type of widget I should use in the GUI and how to get the > >>>> Input and Output from my terminal to the gui.
> >>> I'm just guessing here, but I think I'd just use a scrolled list box > >>> ( $listBox = ??->Scrolled('Listbox', ... ) and feed the output of you > >>> $telnet->cmd call returns into the box (possibly interspersed with the > >>> commands you sent (possibly with different markings or colors to denote > >>> cmds from replies) using a $ListBox->insert('end', ... ). Hope that > >>> makes sense.
> >> Another option is to dump the output to a Text widget.
> >> Opt 1) I have never used Net::Telnet before - but it seems you should be > >> able to capture the output and "manually" write it to the text widget. > >> The drawback is that this would one way - writing.
> >> Opt 2) You didn't mention your platform - but if it is NOT windows AND > >> you are willing to forego Net::Telnet, then you can also try launching a > >> telnet session using IPC::Open2 and use fileevent to trigger the writing > >> to the Text widget.This would also allow input to be read if you trigger > >> reading from the text widget (trigger on hitting the Enter key). This > >> should offer you two way input/output.
> >> Opt 3) Embed an actual xterm into a Tk window (Frame) using the > >> -container option and the xterm -into option. The last time I tried to > >> do this was a number of years ago and I didn't like how it remained a > >> fixed size. This way you can type your commands in to an actual terminal > >> window.
> >> Jack
> > Hi,
> > Thanks very much for the help-I decided to experiment with embedding > > the xterm in the Tk window. This worked, but I am using Tk::NoteBook > > and it seems that the SAME xterm process gets embedded in each tab of > > the NoteBook. Is there a way to insert a different xterm process into > > each page of the notebook?
> Barring a cosmic shift in reality, Tk::Notebook is doing what your > program tells it to. Post some code and let's see.
Ah yes, sorry.
#$mw is the main window variable #@hosts is the array contain each host to telnet to.
my $book = $canv->NoteBook()->pack(-fill=>'both', -expand=>1);
for my $host (@hosts) { my $tab = $book->add ("$host", -label => $host, -createcmd=>sub { create($host) });
}
MainLoop;
sub create { my $host = shift;
#This code from perlmonks on embedding xterm windows:
## 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;
I have tried changing the value of $xtId to try and force it to recognize multiple sessions, but that prevents the terminal window from being created at all. Am I perhaps missing something in the NoteBook tab generation to recognize multiple xterms?
>>> Thanks very much for the help-I decided to experiment with embedding >>> the xterm in the Tk window. This worked, but I am using Tk::NoteBook >>> and it seems that the SAME xterm process gets embedded in each tab of >>> the NoteBook. Is there a way to insert a different xterm process into >>> each page of the notebook?
>> Barring a cosmic shift in reality, Tk::Notebook is doing what your >> program tells it to. Post some code and let's see.
> Ah yes, sorry.
> #$mw is the main window variable > #@hosts is the array contain each host to telnet to.
> my $book = $canv->NoteBook()->pack(-fill=>'both', -expand=>1);
> for my $host (@hosts) { > my $tab = $book->add ("$host", -label => $host, -createcmd=>sub > { create($host) }); > }
> MainLoop;
> sub create { > my $host = shift;
> #This code from perlmonks on embedding xterm windows:
> ## 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;
> I have tried changing the value of $xtId to try and force it to > recognize multiple sessions, but that prevents the terminal window > from being created at all. Am I perhaps missing something in the > NoteBook tab generation to recognize multiple xterms?
> Thanks.
I see the problem right away. You are packing a Frame into a "window" into a canvas. And you are doing the same thing in the same place for each of your hosts.
I think you really want to pack the xterm into each frame of the Notebook right? Remember that when you "add" a page in a Notebook it returns a Tk::Frame. I believe though that the -container option *must* be specified at creation. (i.e. You cannot configure it afterwards according to the documentation for Tk::Frame). I am not sure if the "add" method will support this. Typically any extra options will be passed to the base widget. If not - then you can just as easily pack another frame into each page of the notebook using the -container option - then use *that* winID in your xterm command.
I'm on windows right now - but I'll log into work to see if I can come up with some working code using a linux machine.
Stay tuned - unless someone (even yourself) beats me to it ;)
>>>> Thanks very much for the help-I decided to experiment with embedding >>>> the xterm in the Tk window. This worked, but I am using Tk::NoteBook >>>> and it seems that the SAME xterm process gets embedded in each tab of >>>> the NoteBook. Is there a way to insert a different xterm process into >>>> each page of the notebook?
>>> Barring a cosmic shift in reality, Tk::Notebook is doing what your >>> program tells it to. Post some code and let's see.
>> Ah yes, sorry.
>> #$mw is the main window variable >> #@hosts is the array contain each host to telnet to.
>> my $xtermWidth = 400; >> my $xtermHeight = 300;
>> my $book = $canv->NoteBook()->pack(-fill=>'both', -expand=>1);
>> for my $host (@hosts) { >> my $tab = $book->add ("$host", -label => $host, -createcmd=>sub >> { create($host) }); >> }
>> MainLoop;
>> sub create { >> my $host = shift;
>> #This code from perlmonks on embedding xterm windows:
>> ## 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;
>> I have tried changing the value of $xtId to try and force it to >> recognize multiple sessions, but that prevents the terminal window >> from being created at all. Am I perhaps missing something in the >> NoteBook tab generation to recognize multiple xterms?
>> Thanks.
> I see the problem right away. You are packing a Frame into a "window" > into a canvas. And you are doing the same thing in the same place for > each of your hosts.
> I think you really want to pack the xterm into each frame of the > Notebook right? Remember that when you "add" a page in a Notebook it > returns a Tk::Frame. I believe though that the -container option *must* > be specified at creation. (i.e. You cannot configure it afterwards > according to the documentation for Tk::Frame). I am not sure if the > "add" method will support this. Typically any extra options will be > passed to the base widget. If not - then you can just as easily pack > another frame into each page of the notebook using the -container option > - then use *that* winID in your xterm command.
> I'm on windows right now - but I'll log into work to see if I can come > up with some working code using a linux machine.
> Stay tuned - unless someone (even yourself) beats me to it ;)
> Jack
Okay here is a working example:
#!/usr/bin/perl -w
use strict; use Tk; use Tk::NoteBook; my %page;
my $mw = tkinit; my $nb = $mw->NoteBook()->pack(-expand=>1, -fill=>'both');