Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Win32::SysTray Issue

by pryrt (Abbot)
on Oct 21, 2020 at 20:54 UTC ( [id://11123043]=note: print w/replies, xml ) Need Help??


in reply to Win32::SysTray Issue

Since you seem to be spinning your wheels on the console-based prompt function, why not make use of the fact that you're in a GUI environment, and make a Win32::GUI::DialogBox?

Add an entry to your tray, like

$tray->setMenu ( "> &Test" => sub { print "Hello from the Tray\n"; }, "> &Dialog" => \&interact_using_dialog, ">-" => 0, "> E&xit" => sub { return -1 }, );
then define the sub interact_using_dialog(), where it creates a new Win32::GUI::Dialog with the appropriate form entries, and on clicking OK in that Dialog, grab the values from the form and close the Dialog, sending the data on to whatever data structures you are trying to populate.

I would think that would be a faster debug path than continuing to play with trying to get console and GUI to mesh together properly.

edit: fix link to Win32::GUI::DialogBox

Replies are listed 'Best First'.
Re^2: Win32::SysTray Issue
by pryrt (Abbot) on Oct 22, 2020 at 17:05 UTC
    For example,
    #!perl # # [id://11122933] use 5.012; # strict, // use warnings; use Win32::SysTray; use Win32 qw/MB_ICONEXCLAMATION MB_ICONSTOP MB_ICONQUESTION MB_ICONINF +ORMATION/; $| = 1; my $tray = new Win32::SysTray ( 'icon' => 'C:\images\logo.ico', 'single' => 1, ) or exit 0; # each row of @choices needs a hashref, with the keys name, text, and +action -- name should be a perl-safe-identifier (single word), text i +s visible string, and action is a coderef my @choices = ( { name => 'EmployeeManagement', text => 'Employee Management', act +ion => sub { Win32::MsgBox("Do some management task", 0 | MB_ICONINFO +RMATION, 'Employee Management')} }, { name => 'Quit', text => 'Quit', action => sub { print "Exiting p +er user request\n"; exit 0 } }, ); my $DIALOG = create_dialog(); $tray->setMenu ( "> Show &Dialog" => sub { $DIALOG->Show() }, # can re-show +the dialog, too ">-" => 0, "> E&xit" => sub { return -1 }, ); $DIALOG->Show(); # if you want this dialog to default to visible; o +therwise, remove this line and rely on the tray to start it Win32::GUI::Dialog(); exit; sub create_dialog { my $dlg = Win32::GUI::DialogBox->new( -name => 'DlgBox', -text => 'Option Menu', -width => 300, -height => 120 + 20*@choices, ); $dlg->AddLabel( -text => 'Please make a selection', -pos => [15,10], -size => [$dlg->ScaleWidth() - 30 , 30], ); $dlg->AddButton( -text => 'Ok', -default => 1, -ok => 1, -size => [60,20], -pos => [$dlg->ScaleWidth() - 140, $dlg->ScaleHeight - 30], -onClick => \&DlgBox_Process, ); $dlg->AddButton( -text => 'Cancel', -cancel => 1, -size => [60,20], -pos => [$dlg->ScaleWidth() - 70, $dlg->ScaleHeight - 30], -onClick => \&DlgBox_Terminate, ); my $top = 50; for my $opt ( @choices ) { $dlg->AddRadioButton( -name => $opt->{name}, -size => [15,15], -pos => [15, $top], ); $dlg->AddLabel( -text => $opt->{text}, -pos => [45, $top], -size => [$dlg->ScaleWidth() - 45 - 10,15], ); $top += 20; } return $dlg; } sub DlgBox_Process { my $action = undef; for my $opt ( @choices ) { if( $DIALOG->{$opt->{name}}->Checked()) { $action = $opt->{action}; last; } } if(defined $action) { $DIALOG->Hide(); $action->(); #$DIALOG->Show(); # un-comment to automatically re-show the ma +in input dialog } else { Win32::MsgBox("Programmer needs to define action!", 0 | MB_ICO +NEXCLAMATION, 'ERROR in Management Dialog!') } return 0; } sub DlgBox_Terminate { $DIALOG->Hide(); return 0; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found