How to set actions to widgets different from Gio.Application inheritances?

SongCard.blp

... some code ...

menu cover_action {
  section {
    item {
      label: _("Set cover");
      action: "card.change_cover";
    }

    item {
      label: _("Remove cover");
      action: "card.remove_cover";
    }
  }
}

I have a class which’s using template from above file.

self.install_action("card.change_cover", None, self.metadata_change_cover)
self.install_action("card.remove_cover", None, self.metadata_remove_cover)

I’m trying to bind this actions to menu items from template, but nothing happens. How to bind this actions to menu items?

install_action should be applied to the button to which menu is bound.

Hi,

be careful with install_action, it’s supposed to be called on a class instead of on self, or it may not work as you intend.

See this topic for details: Multiple Window - Action received in wrong window

Oh, god! Thank you so much! Recently, I have experienced some troubles that these actions didn’t work as I expected. In some files cover changes was successful, but in most of them functions bound to the actions triggered, but nothing changes. And it seems that it was caused by incorrect class instance binding using install_action. Migrating to Gio.SimpleActonGroup and inserting it into the self.metadata_editor_cover_button solved that issue. Thanks a lot, one more time!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.