Adding data to a Adw NavigationPage on Push

Hi folks!

I’m learning the Adw/Gtk template system, using Python. At this point I have three templates set up. This is in the main application window:

<object class="AdwNavigationView">
    <child>
        <object class="SpeciesList"/>
    </child>
    <child>
        <object class="SpeciesDetails"/>
    </child>
</object>

With the following templates:

<?xml version='1.0' encoding='UTF-8'?>
<interface>
    <template class="SpeciesList" parent="AdwNavigationPage">
        <property name="title">Species List</property>
        <property name="child">
            <object class="GtkButton">
                <property name="label">Go To Species Details</property>
                <property name="halign">center</property>
                <property name="valign">center</property>
                <property name="action-name">navigation.push</property>
                <property name="action-target">'species-details'</property>
            </object>
        </property>
    </template>
</interface>
<?xml version='1.0' encoding='UTF-8'?>
<interface>
    <template class="SpeciesDetails" parent="AdwNavigationPage">
        <property name="title">Species Details</property>
        <property name="tag">species-details</property>
        <property name="child">
            <object class="AdwToolbarView">
                <child type="top">
                    <object class="AdwHeaderBar">
                        <property name="show-end-title-buttons">false</property>
                    </object>
                </child>
                <property name="content">
                    <object class="GtkButton">
                        <property name="label">Go To Species List</property>
                        <property name="halign">center</property>
                        <property name="valign">center</property>
                        <property name="action-name">navigation.pop</property>
                    </object>
                </property>
            </object>
        </property>
    </template>
</interface>

I’d like to initialise the SpeciesDetails object with either an “add” state or “edit” state, with the latter filling out the form before it is displayed to the user.

At this point there’s very little python involved, and I’d like to know the best way to do this.

Many thanks,

J.R.

I think ideally the two AdwNavigationPage objects should talk to one another.

When implemented, the SpeciesList page will allow either a new species or and update to an existing species in the SpeciesDetails page. SpeciesList should pass a “new species” message with no payload or a “modify species” message with a string payload representing the species reference. SpeciesDetails then takes care of creation, modification or deletion.

The window containing the AdwNavigationView need not know anything about these messages. I’m new to GTK so I’m not sure how to handle this idiomatically.

Here is my initial solution:

@Gtk.Template(resource_path="/org/bswa/Leaftracker/ui/main_window.ui")
class MainWindow(Adw.ApplicationWindow):
    __gtype_name__ = "MainWindow"

    species_details: SpeciesDetails = Gtk.Template.Child()
    species_list: SpeciesList = Gtk.Template.Child()

    def __init__(self, application: Adw.Application):
        super().__init__(application=application)
        self.species_list.set_details_page(self.species_details)

The MainWindow class contains, amongst other things, an Adw.NavigationView with the two pages divided into their own templates:

@Gtk.Template(resource_path="/org/bswa/Leaftracker/ui/species_details.ui")
class SpeciesDetails(Adw.NavigationPage):
...

@Gtk.Template(resource_path="/org/bswa/Leaftracker/ui/species_list.ui")
class SpeciesList(Adw.NavigationPage):
...

So we’re just jamming one page into the other. I suspect there is a cleaner way to do this, using signals.

Any thoughts on this approach are most welcome.

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