Home > Archive > PerlTk > June 2004 > Re: Shell-alike Perl/Tk window scrolling content - CNetwork.pm (0/1)
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 |
Re: Shell-alike Perl/Tk window scrolling content - CNetwork.pm (0/1)
|
|
| Markus Mohr 2004-05-24, 8:38 pm |
| On Mon, 24 May 2004 18:11:49 -0400, zentara <zentara@highstream.net>
wrote:
>On Mon, 24 May 2004 11:17:54 +0200, Markus Mohr <markus.mohr@mazimoi.de>
>wrote:
>
>
>
>
>
>
>Remember when I said that you were sending the $anfrage as a slurped
>scalar, and you could send it line by line instead?
>Well now you see why.
>
>The way you are sending the data, I think it's going to block further
>processing until the send is complete. When the send is complete,
>it can move on and display the $anfrage in the text box. Now, if you
>want to put an "artificial delay" in the textbox printout, you can, but
>that would only be "faking it", and would be a disservice to the user.
>If you wanted to go that route, you just need to put a slight delay in
>the display sub, like:
>
>#faking the scroll
>
>sub display_sent() {
> my $data = shift;
> $mw->deiconify( );
> $mw->raise( );
>
>#first split the data into lines
>my @data = split( "\n ", $data);
>
>while(@data){
> $text->insert('end',$_);
> $text->see('end');
> $mw->after(50); # a 50 msec delay
> $mw->idletasks;
>}
>}
> ########################################
######
>Now if you want to do it so that the scroll actually
>reflects the data as it's being sent out of the socket,
>try something like this. Untested (and I'm not a socket details expert).
>Split your $anfrage into lines and send it line by line, then
>the textbox will show each line as it's sent.
>
>sub put($$) {
> my ($self, $anfrage, $konfiguration) = @_;
>
>#split to lines
>my @anfrage = split( "\n ", $anfrage);
>
># my $leng = length($anfrage);
> my $sock = server_connect($konfiguration);
> return unless defined $sock;
>
> while(@anfrage){
>
> my $leng = length($_);
>
> print $sock "PUT_ANF $leng\n";
> my ($reply, $id);
> $reply = <$sock>;
> if ($reply =~ /OK/) {
> $sock->send("$_\n");
> &display_sent($_);
> }
>
> } else {
> server_disconnect ($sock);
>
> &display_sent("Sorry not OK at Socket , no data sent !");
>
> return; }
>
> ($reply, $id) = split(/ /, <$sock> );
> unless ($reply =~ /OK/) { server_disconnect ($sock); return; }
> server_disconnect ($sock);
>
> &display_sent("\n\nFINISHED\n\n");
>
> chop($id);
> return $id;
>}
>[..]
>
> ########################################
##################
>
>The above is untested, and there may be some unforseen glitch
>due to the extra newlines being sent to the socket, but I think
>it should work.
Unfortunately doesn't. Maybe the while bracket is not defined
properly.
I have enclosed the whole file "CNetwork.pm" to see. The greatest
problem I do encounter is "my ($reply, $id) being subjected to the
while statement.
Sincerely
Markus Mohr
| |
| zentara 2004-06-03, 7:10 pm |
| On Tue, 25 May 2004 01:50:50 +0200, Markus Mohr <markus.mohr@mazimoi.de>
wrote:
>
>Unfortunately doesn't. Maybe the while bracket is not defined
>properly.
>
>I have enclosed the whole file "CNetwork.pm" to see. The greatest
>problem I do encounter is "my ($reply, $id) being subjected to the
>while statement.
The problem is this newsgroups strips attachments, so there is no
CNetwork.pm.
You say the biggest problem is "my ($reply, $id) being subjected to the
while statement". It also looks like there is a mistake in the if-else
clause. Sorry, I goofed that up.
This looks better.
There is also another problem, that maybe your $anfrage dosn't
split on newlines, as you havn't showed anydata, except to say it's XML.
Now I'm just ASSUMING :-) it's conventional XML with alot of newlines,
but maybe you have it setup as a long string? In that case you can
break it up into "network sized chunks" before sending, instead od
splitting on newlines? If it gets too much for you, go back to just
"faking it". :-)
sub put($$) {
my ($self, $anfrage, $konfiguration) = @_;
#split to lines
my @anfrage = split( "\n ", $anfrage);
my $leng = length($anfrage);
my $sock = server_connect($konfiguration);
return unless defined $sock;
my ($reply, $id);
$reply = <$sock>;
if ($reply =~ /OK/) {
print $sock "PUT_ANF $leng\n";
while(@anfrage){
$sock->send("$_\n");
&display_sent("$_\n");
}
} else {
server_disconnect ($sock);
&display_sent("Sorry not OK at Socket , no data sent !");
return; }
($reply, $id) = split(/ /, <$sock> );
unless ($reply =~ /OK/) { server_disconnect ($sock); return; }
server_disconnect ($sock);
&display_sent("\n\nFINISHED\n\n");
chop($id);
return $id;
}
[..]
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
| |
| Markus Mohr 2004-06-03, 7:10 pm |
| On Tue, 25 May 2004 11:27:35 -0400, zentara <zentara@highstream.net>
wrote:
[color=darkred]
>On Tue, 25 May 2004 01:50:50 +0200, Markus Mohr <markus.mohr@mazimoi.de>
>wrote:
>
Happily seeing your reply. The CNetwork.pm is contained in the
original thread as well in the next posting.
Meanwhile, I will try your changes and report.
Thank you
Markus
| |
| Markus Mohr 2004-06-03, 7:10 pm |
| On Tue, 25 May 2004 11:27:35 -0400, zentara <zentara@highstream.net>
wrote:
>On Tue, 25 May 2004 01:50:50 +0200, Markus Mohr <markus.mohr@mazimoi.de>
>wrote:
>
>You say the biggest problem is "my ($reply, $id) being subjected to the
>while statement". It also looks like there is a mistake in the if-else
>clause. Sorry, I goofed that up.
>This looks better.
>
>There is also another problem, that maybe your $anfrage dosn't
>split on newlines, as you havn't showed anydata, except to say it's XML.
>Now I'm just ASSUMING :-) it's conventional XML with alot of newlines,
>but maybe you have it setup as a long string? In that case you can
>break it up into "network sized chunks" before sending, instead od
>splitting on newlines? If it gets too much for you, go back to just
>"faking it". :-)
The splitting into new lines does not work, the display as a whole,
however, does. Is there a possibility to slow down the scrolling speed
to, say, the half?
Sincerely
Markus Mohr
| |
| zentara 2004-06-03, 7:10 pm |
| On Fri, 28 May 2004 16:05:21 +0200, Markus Mohr <markus.mohr@mazimoi.de>
wrote:
>On Tue, 25 May 2004 11:27:35 -0400, zentara <zentara@highstream.net>
>wrote:
>
>The splitting into new lines does not work, the display as a whole,
>however, does. Is there a possibility to slow down the scrolling speed
>to, say, the half?
I would say to split the $anfrage into 1024 bit chunks instead of
newlines.
Look at this code:
#!/usr/bin/perl
$string = 'foo' x 2048;
$n = 1024; # $n is group size.
@groups = unpack "a$n" x ((length($string)/$n)-1) . "a*", $string;
print join("\n\n\n",@groups),"\n\n";
########################################
#################
So do that to $anfrage.
sub put($$) {
my ($self, $anfrage, $konfiguration) = @_;
#split to 1k chunks
my $n = 1024;
my @anfrage = unpack "a$n" x ((length($anfrage)/$n)-1) . "a*", $anfrage;
my $leng = length($anfrage);
my $sock = server_connect($konfiguration);
return unless defined $sock;
my ($reply, $id);
$reply = <$sock>;
if ($reply =~ /OK/) {
print $sock "PUT_ANF $leng\n";
while(@anfrage){
$sock->send("$_");
&display_sent("$_");
}
print "\n\n";
} else {
server_disconnect ($sock);
&display_sent("Sorry not OK at Socket , no data sent !");
return; }
($reply, $id) = split(/ /, <$sock> );
unless ($reply =~ /OK/) { server_disconnect ($sock); return; }
server_disconnect ($sock);
&display_sent("\n\nFINISHED\n\n");
chop($id);
return $id;
}
[..]
########################################
############
If you just want to fake the scrolling, go back to the original method
of sending $anfrage as a string. Then after it is sent, fake the scroll
like this:
#faking the scroll
sub display_sent() {
my $data = shift;
$mw->deiconify( );
$mw->raise( );
#split to 1k chunks
my $n = 1024;
my @data = unpack "a$n" x ((length($data)/$n)-1) . "a*", $data;
while(@data){
$text->insert('end',$_);
$text->see('end');
$mw->after(50); # a 50 msec delay
$mw->idletasks;
}
}
########################################
##################
Thats about all I can show you. :-)
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
| |
| Markus Mohr 2004-06-03, 7:10 pm |
| On Sat, 29 May 2004 08:29:18 -0400, zentara <zentara@highstream.net>
wrote:
>On Fri, 28 May 2004 16:05:21 +0200, Markus Mohr <markus.mohr@mazimoi.de>
>wrote:
>
>
>
>I would say to split the $anfrage into 1024 bit chunks instead of
>newlines.
>
>Look at this code:
>#!/usr/bin/perl
>
>$string = 'foo' x 2048;
>$n = 1024; # $n is group size.
>@groups = unpack "a$n" x ((length($string)/$n)-1) . "a*", $string;
>
>print join("\n\n\n",@groups),"\n\n";
> ########################################
#################
>
>So do that to $anfrage.
>
>sub put($$) {
> my ($self, $anfrage, $konfiguration) = @_;
>
>#split to 1k chunks
>my $n = 1024;
>my @anfrage = unpack "a$n" x ((length($anfrage)/$n)-1) . "a*", $anfrage;
>
> my $leng = length($anfrage);
> my $sock = server_connect($konfiguration);
> return unless defined $sock;
>
> my ($reply, $id);
> $reply = <$sock>;
> if ($reply =~ /OK/) {
> print $sock "PUT_ANF $leng\n";
>
> while(@anfrage){
> $sock->send("$_");
> &display_sent("$_");
> }
> print "\n\n";
> } else {
> server_disconnect ($sock);
> &display_sent("Sorry not OK at Socket , no data sent !");
>
> return; }
>
> ($reply, $id) = split(/ /, <$sock> );
> unless ($reply =~ /OK/) { server_disconnect ($sock); return; }
> server_disconnect ($sock);
>
> &display_sent("\n\nFINISHED\n\n");
>
> chop($id);
> return $id;
>}
>[..]
>
>
> ########################################
############
>If you just want to fake the scrolling, go back to the original method
>of sending $anfrage as a string. Then after it is sent, fake the scroll
>like this:
>
>#faking the scroll
>sub display_sent() {
> my $data = shift;
> $mw->deiconify( );
> $mw->raise( );
>
>#split to 1k chunks
>my $n = 1024;
>my @data = unpack "a$n" x ((length($data)/$n)-1) . "a*", $data;
>
>while(@data){
> $text->insert('end',$_);
> $text->see('end');
> $mw->after(50); # a 50 msec delay
> $mw->idletasks;
>}
>}
>
> ########################################
##################
>
>Thats about all I can show you. :-)
You have done a hell of a lot for me, thank you really very much for
that all.
Maybe inn case of a future problem I can come back to questioning you?
Many greetings
Markus Mohr
| |
| zentara 2004-06-03, 7:10 pm |
| On Sun, 30 May 2004 03:33:06 +0200, Markus Mohr <markus.mohr@mazimoi.de>
wrote:
>Maybe inn case of a future problem I can come back to questioning you?
>Many greetings
>Markus Mohr
I'm happy to help spread the usefulness of PerlTk. Ask your questions
here, because others are alot smarter than me, and may have better
answers.
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
| |
| John W. Krahn 2004-06-03, 7:10 pm |
| zentara wrote:
>
> On Fri, 28 May 2004 16:05:21 +0200, Markus Mohr <markus.mohr@mazimoi.de>
> wrote:
>
>
>
> I would say to split the $anfrage into 1024 bit chunks instead of
> newlines.
>
> Look at this code:
> #!/usr/bin/perl
>
> $string = 'foo' x 2048;
> $n = 1024; # $n is group size.
> @groups = unpack "a$n" x ((length($string)/$n)-1) . "a*", $string;
Or you could do it like this:
@groups = $string =~ /.{0,$n}/sg;
:-)
John
--
use Perl;
program
fulfillment
|
|
|
|
|