Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot call method from outside of a GTK:: object (Any::IterateOneWithoutPhasers.push-all) #41

Open
hythm7 opened this issue Nov 5, 2019 · 0 comments

Comments

@hythm7
Copy link
Collaborator

hythm7 commented Nov 5, 2019

The below code example creates a FlowBox with random children in it, when a child gets activated, all similar children will be selected (I.e, if double-clicked or hit space on child 'a', all children with label 'a' get selected)

the issue is it is not consistent, it works sometimes but if continue activating children it throws the error.


use GTK::Raw::Types;
use GTK::Compat::Types;
use GTK::Application;
use GTK::FlowBox;
use GTK::Label;
use GTK::Button;
use GTK::Box;

my $app = GTK::Application.new(
  title  => 'org.genex.test.widget',
  width  => 400,
  height => 400
);

$app.activate.tap({
  CATCH { default { .message.say; $app.exit } }

  my GTK::Button $exit .= new_with_label: <exit>;
  $exit.clicked.tap: { $app.exit  };

  my $str = qq:to/END/;
  { ('a' .. 'z').pick( * ).join }
  { ('a' .. 'z').pick( * ).join }
  { ('a' .. 'z').pick( * ).join }
  { ('a' .. 'z').pick( * ).join }
  { ('a' .. 'z').pick( * ).join }
  END

  my $flowbox = GTK::FlowBox.new;

  $flowbox.halign = GTK_ALIGN_START;
  $flowbox.valign = GTK_ALIGN_START;
  $flowbox.homogeneous = True;
  $flowbox.selection-mode = GTK_SELECTION_MULTIPLE;
  $flowbox.min_children_per_line = 26;
  $flowbox.max_children_per_line = 26;
  $flowbox.activate-on-single-click = False;

  $flowbox.child-activated.tap( -> ( $f, $c, $p, $r ) {
    my $sym   = $f.get-selected-children.head.get-child.label;
    my @child = $f.get-children.grep({ .get-child.label ~~ $sym });

    @child.map( -> $child { $f.select-child: $child } );

  } );

  for $str.words.join.comb -> $sym {
    my $child = GTK::FlowBoxChild.new;
    #$child.add-events: GDK_BUTTON_PRESS_MASK;
    $child.add: GTK::Label.new: $sym;
    $flowbox.add: $child;
  }

  my $box = GTK::Box.new-vbox();
  $box.pack_start($flowbox, False, False, 0);
  $box.pack_start($exit, False, False, 0);

  $app.window.add: $box;
  $app.show_all;

});

$app.run;

### ERROR:
Cannot call method from outside of a GTK:: object (Any::IterateOneWithoutPhasers.push-all)
  in method IS-PROTECTED at /home/hythm/dev/GTK/p6-GtkPlus/lib/GTK/Roles/Protection.pm6 (GTK::Roles::Protection) line 66
  in block  at tmp/sym.p6 line 43
  in block  at /home/hythm/dev/GTK/p6-GtkPlus/lib/GTK/Roles/Signals/FlowBox.pm6 (GTK::Roles::Signals::FlowBox) line 29
  in block  at /home/hythm/.rakudobrew/versions/moar-blead/install/share/perl6/core/sources/947BDAB9F96E0E5FCCB383124F923A6BF6F8D76B (NativeCall) line 583
  in method run at /home/hythm/dev/GTK/p6-GtkPlus/lib/GTK/Application.pm6 (GTK::Application) line 219
  in block <unit> at tmp/sym.p6 line 68

I though not to report this since FlowBox.pm6 might not be ready yet,(because I needed to make changes to it to make this example work, "diff below", However the reason I reported it is because I think it's related to #40

Changes to FlowBox.pm6:

8  use GTK::Roles::Orientable;
9 +use GTK::Roles::Signals::FlowBox;

16    also does GTK::Roles::Orientable;
17 +  also does GTK::Roles::Signals::FlowBox;

34 -    my $to-be-selected = self!resolve-selected-child;
35 +    my $to-be-selected = self!resolve-selected-child($child);

43 -    my $to-be-unselected = self!resolve-selected-child;
44 +    my $to-be-unselected = self!resolve-selected-child($child);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant