dk / Prima

prima.eu.org
Other
106 stars 27 forks source link

Getting error when "run prima" a second time in same script #88

Closed rementis closed 1 year ago

rementis commented 1 year ago

I have a subroutine that shows the user a menu. The last two lines are "run prima" and then "return $buffer". This sub works great the first time it's called. The second time it's called the script crashes with:

Illegal 'owner' reference passed to Prima::Widget::init.

This is on strawberry perl running on Windows 10x64

Here is the entire subroutine:

sub newPlayerWindow{
  my $m1=Prima::MainWindow->new(text => 'New Player',
                                size => [ 400, 200]);
  my $buffer;
  $m1->insert( 'Prima::Label',
                text      => 'Player Name:',
                origin    => [  50,150]);
  my $player_in = $m1->insert("Prima::InputLine",
                text => 'Shooter McPlayerson',
                maxLen => 130,
                size    => [ 200, 30],
                hint   => 'Player name (alpha characters only)',
                origin => [  175,150]);
  $m1->insert( 'Prima::Label',
                text      => 'Fargo Rating:',
                origin    => [  50,120]);
  my $fargo_in = $m1->insert("Prima::InputLine",
                text => '450',
                maxLen => 130,
                size    => [ 200, 30],
                hint   => 'Fargo Rating (digits only)',
                origin => [  175,120]);
  $m1->insert( 'Prima::Label',
                text      => 'Chips:',
                origin    => [  50,90]);
  my $chips_in = $m1->insert("Prima::InputLine",
                text => '3',
                maxLen => 130,
                size    => [ 200, 30],
                hint   => 'Number of chips (digits only)',
                origin => [  175,90]);
  $m1->insert( 'Prima::Label',
                text      => 'Phone Number:',
                origin    => [  50,60]);
  my $phone_in = $m1->insert("Prima::InputLine",
                text => '4800000000',
                maxLen => 130,
                size    => [ 200, 30],
                hint   => 'Phone Number (digits only)',
                origin => [  175,60]);
  my $btn = $m1-> insert( 'Prima::Button',text => 'Enter',
                origin => [  175,10],
                onClick => sub { 
             $buffer = $player_in->text;
             $buffer .= ",".$fargo_in->text;
             $buffer .= ",".$chips_in->text;
             $buffer .= ",".$phone_in->text;
             $m1-> close },);
  run Prima;
  return $buffer
}
dk commented 1 year ago

Hi

That's because you create MainWindow twice - and MainWindow is a special beast, it closes the application after the window is closed, so naturally, there's no such owner for the window anymore.

I'd recommend you to replace MainWindow to just a Window, and run Prima to $m1->execute (you'd need to check the modalResult or execute return value then) instead

/dk

rementis commented 1 year ago

I figured out a workaround.   I simply put each prima menu into it's own script, then call them using backticks.

Works great, each menu gets it's own process and is happy.

Thanks again for the great software!

On 3/13/2023 4:53 AM, Dmitry Karasik wrote:

Hi

That's because you create MainWindow twice - and MainWindow is a special beast, it closes the application after the window is closed, so naturally, there's no such owner for the window anymore.

I'd recommend you to replace MainWindow to just a Window, and |run Prima| to |$m1->execute| (you'd need to check the modalResult or execute return value then) instead

/dk

— Reply to this email directly, view it on GitHub https://github.com/dk/Prima/issues/88#issuecomment-1466002442, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARK5ASWMUUGYAL2XQT3KQ3W34DCHANCNFSM6AAAAAAVYHTSPM. You are receiving this because you authored the thread.Message ID: @.***>