473,394 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

non blocked read in tk

62
Hi!

I tryed this script to non blocked read in tk

Expand|Select|Wrap|Line Numbers
  1. use Tk;                        
  2. use Term::ReadKey;
  3.  
  4. ReadMode 4, STDIN;
  5. $in = \*STDIN;
  6.  
  7. $mw=MainWindow->new();    
  8. $mw->maxsize(500,800);                                
  9. $mw->minsize(500,800);
  10.  
  11. $text=$mw->Text( -width=>65,            
  12.                  -height=>5,
  13.                 );
  14.     $text->place(-x => 20,-y => 700);
  15. $text->focus();
  16.  
  17. $g2 = $mw->Button(-text => "Button",                    
  18.                  -command => sub{ &rutin}
  19.                             );
  20. $g2->place(-x => 240, -y => 100);
  21.  
  22. Mainloop();
  23.  
  24. sub rutin
  25.        {
  26.             while(1)
  27.                   {
  28.                        $k = "";
  29.                 $k=ReadKey(-1, $in);
  30.                     if($k ne "")
  31.                         {
  32.                             $text->insert('insert',$k);
  33.                             $text->focus();
  34.                             last;
  35.                         }
  36.                   }
  37.  
  38.        }

It doesnt work just if I change to the prompt shell and there hit a key.
Have anybody idea how possible take non blocked read whithout this

WIN XP, Active Perl 5.10
Oct 23 '08 #1
9 1883
Icecrack
174 Expert 100+
Hi!

I tryed this script to non blocked read in tk

Expand|Select|Wrap|Line Numbers
  1. use Tk;                        
  2. use Term::ReadKey;
  3.  
  4. ReadMode 4, STDIN;
  5. $in = \*STDIN;
  6.  
  7. $mw=MainWindow->new();    
  8. $mw->maxsize(500,800);                                
  9. $mw->minsize(500,800);
  10.  
  11. $text=$mw->Text( -width=>65,            
  12.                  -height=>5,
  13.                 );
  14.     $text->place(-x => 20,-y => 700);
  15. $text->focus();
  16.  
  17. $g2 = $mw->Button(-text => "Button",                    
  18.                  -command => sub{ &rutin}
  19.                             );
  20. $g2->place(-x => 240, -y => 100);
  21.  
  22. Mainloop();
  23.  
  24. sub rutin
  25.        {
  26.             while(1)
  27.                   {
  28.                        $k = "";
  29.                 $k=ReadKey(-1, $in);
  30.                     if($k ne "")
  31.                         {
  32.                             $text->insert('insert',$k);
  33.                             $text->focus();
  34.                             last;
  35.                         }
  36.                   }
  37.  
  38.        }

It doesnt work just if I change to the prompt shell and there hit a key.
Have anybody idea how possible take non blocked read whithout this

WIN XP, Active Perl 5.10
Change This:

Expand|Select|Wrap|Line Numbers
  1. $g2 = $mw->Button(-text => "Button",                    
  2.                  -command => sub{ &rutin}
  3.                             );
to:
Expand|Select|Wrap|Line Numbers
  1. $g2 = $mw->Button(-text => "Button",                    
  2.                  -command => sub \&rutin
  3.                             );
Oct 23 '08 #2
KevinADC
4,059 Expert 2GB
You can't say "sub \&rutin". "sub" needs brackets

Expand|Select|Wrap|Line Numbers
  1. sub {anonymous function};
  2.  
  3. sub named_function {
  4. ....
  5. }
So this will work:

Expand|Select|Wrap|Line Numbers
  1. $command =  sub {&foo};
  2. $command->();
  3. sub foo {
  4.    print "here we are";
  5. }
  6.  
and this will work the same

Expand|Select|Wrap|Line Numbers
  1. $command =  \&foo;
  2. $command->();
  3. sub foo {
  4.    print "here we are";
  5. }
Oct 23 '08 #3
Icecrack
174 Expert 100+
My Bad, I made a mistake it was meant to be
Expand|Select|Wrap|Line Numbers
  1. $g2 = $mw->Button(-text => "Button",                    
  2.                  -command => \&rutin
  3.                             );
Thank you for picking that up kevin
Oct 23 '08 #4
KevinADC
4,059 Expert 2GB
My Bad, I made a mistake it was meant to be
Expand|Select|Wrap|Line Numbers
  1. $g2 = $mw->Button(-text => "Button",                    
  2.                  -command => \&rutin
  3.                             );
Thank you for picking that up kevin
"Experts" are allowed two mistakes a year otherwise they get demoted to "Amatuer". ;)
Oct 24 '08 #5
Icecrack
174 Expert 100+
Also Mainloop(); is wrong

Case its meant to be MainLoop(); with the upper case L in Loop.

Expand|Select|Wrap|Line Numbers
  1. MainLoop();
Oct 24 '08 #6
KevinADC
4,059 Expert 2GB
Anyways.....

http://www.tek-tips.com/viewthread.c...1508918&page=1
Oct 24 '08 #7
Icecrack
174 Expert 100+
"Experts" are allowed two mistakes a year otherwise they get demoted to "Amatuer". ;)

at least i found the problem :P
Oct 24 '08 #8
Icecrack
174 Expert 100+
Anyways.....

http://www.tek-tips.com/viewthread.c...1508918&page=1

i guess he found his answer.
Oct 24 '08 #9
Arepi
62
i guess he found his answer.
No im not, my problem is different:
http://www.tek-tips.com/viewthread.c...1508918&page=1

Any idea?

Thanks!
Oct 24 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Jay Vinton | last post by:
I recently posted my first .aspx effort and am getting calls from users saying the page is being blocked and they can't view it. They got a hyperlink in an e-mail (see below). Most have been...
2
by: jfradette | last post by:
Hello, all of my JavaScript are blocked by the latest version of Explorer. What can I add to my scripts to prevent browsers from blocking it? I am using scripts for a drop-down menu to jump to a...
17
by: laurenq uantrell | last post by:
In master.dbo.sysprocesses I can filter for blocked users (Blocked >0) and I can create a self join(ON SPID = Blocked) to see what user Loginame is causing the block. In the column I can see the...
1
by: Yim | last post by:
In below codes, After 10 seconds, function t() was called. So far everything is ok. Then I want to awake blocked read(). So want to exit program. In t(), how to do? (in t(), close(sockfd) don't...
4
by: Dr. J | last post by:
How to terminate a blocked thread? In my form's "load" I launch a TCP listening thread that stays in an infinite loop waiting for incoming TCP packets. In this form's "closing" I try to...
2
by: Qindong Zhang | last post by:
My socket application blocked at socket.receiver() after received all information from sender. Should socket.Receive() return 0 after no more data available? Note: My socket object was not close on...
1
by: MrS4T4n | last post by:
Hi! I wrote a windows service, this service read a txt file and make some task... the service works at 00:00, 00:30, 01:00, 01:30 etc... (every half hour) The problem is the txt, there is a...
4
by: dd | last post by:
I have a scenario where my popups are being blocked by IE6+ and Firefox. The problem is that although the popup is a direct result of the user clicking on the link (meaning that they WANT the...
5
by: Damien582 | last post by:
Hi everyone, I am working with a library (HIDLibrary) to read from and hid device (eHome Infraread Transceiver, aka Windows Media Center Remote) to read from a universal remote control. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.