Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^5: Win32::SysTray Issue ( Win32::GUI::DoEvents )

by jcb (Vicar)
on Oct 21, 2020 at 01:23 UTC ( #11123025=note: print w/replies, xml ) Need Help??

in reply to Re^4: Win32::SysTray Issue ( Win32::GUI::DoEvents )
in thread Win32::SysTray Issue

This whole program probably would make more sense using Tk for a full GUI, but the Prompt sub I gave you earlier should handle the non-blocking input problem you have. Add $| = 1; just after line 9 above, paste in the sub Prompt somewhere and replace lines 23-25 with: my $input = Prompt("? ");

Replies are listed 'Best First'.
Re^6: Win32::SysTray Issue ( Win32::GUI::DoEvents )
by PilotinControl (Pilgrim) on Oct 21, 2020 at 02:15 UTC

    If these are the correct changes to be made from the code you still does not work. In fact none of the input choices work now.

    #!/usr/bin/perl -w use strict; use warnings; use diagnostics; use Term::ANSIScreen; use Win32::Console; use Win32::SysTray; no warnings 'numeric'; $| = 1; # ADDED tray(); begin(); sub begin { # START BEGIN print "-------------------------------------------\n"; print "Please Choose One of the Following Options:\n"; print "-------------------------------------------\n\n\n"; print "(1) EMPLOYEE MANAGEMENT \n\n"; print "(Q) QUIT \n\n"; print " \n\n\n\n"; my $input = Prompt("? "); # ADDED if ($input){ if ( $input == 1 ){ sleep(3); begin(); } if ( $input eq "q" ) { sleep 3; exit; } } # END INPUT } # END BEGIN sub tray { my $stray = new Win32::SysTray ( 'name' => 'TEST', 'icon' => 'C:\images\logo.ico', 'single' => 1, ) or exit 0; $stray->setMenu ( "> &Test" => sub { print "Hello from the Tray\n"; }, ">-" => 0, "> E&xit" => sub { exit; }, ); } sub Prompt { my $prompt = shift; print "\n$prompt "; my $response = ''; my $rsel = ''; my $rrdy; vec($rsel,fileno(STDIN),1) = 1; CHAR: while (1) { die "user quit" if -1 == Win32::GUI::DoEvents(); while (select($rrdy=$rsel, undef, undef, 0.10)) { sysread(STDIN, $response, 1, length $response) == 1 or die "read error"; } last CHAR if chomp($response); } return $response; }

      It is possible that select does not work on a console on Windows. If that is the case, then I have no idea how to fix it without moving to a better operating system.

      I also wonder if letting a Win32::SysTray object go out of scope causes the tray icon to be deleted. If that is your problem, changing my to our on line 42 should prevent the object from being destroyed.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11123025]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2020-11-27 09:41 GMT
Find Nodes?
    Voting Booth?

    No recent polls found