AsymLabs
AsymLabs

Reputation: 963

Glade as a starting point for GTK3/4/5 (instead of Gnome-Builder)

Have now spent some time coming to grips with Gnome Builder, Glade, Vala and Genie - and considering the excellent Gnome Human Interface Guidelines (GHIG) - why isn't Glade the starting point for almost all GTK GUI applications?

For example, are there any programs that will take a Glade (template) xml file and auto-generate the corresponding programmatic Vala or Genie source code? If there were standard Gtk.ApplicationWindow Glade xml files, for example, that followed the GHIG that were shipped with Glade/Gnome these could be quickly adapted for a specific project and a Genie class template with signals auto-generated - plus a full gresource/meson/flatpak structure. This would simply be imported directly into Gnome-Builder as a starting point. Has anything like this been done?

Update

The following file application.gs is auto-generated from application.ui using Genie attributes composition. Don't want to reinvent the wheel here - hence the reason for this question. The following has some fields removed but the actual file is fully complete and ready to use. The only information required in addition to the content of 'application.ui' is the resource path and ui file name. Everything is already contained within the Glade file.

/*
  {PROJECT_SPACE}

  '{PROJECT_NAME}' is a command line tool that will parse a glade ui
  template and generate a skeleton class in the Genie language
  with composite widgets. It will generate GTKTemplate, GTKChild
  and GTKCallback entries.

  '{PROJECT_NAME}' exists within the {PROJECT_NAMESPACE} namespace.

  Copyright (C) 2018 {AUTHOR_NAME} {AUTHOR_EMAIL}

  This library is free software; you can redistribute it and or
  or modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (as you wish) a later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the:

      Free Software Foundation, Inc.
      51 Franklin Street, Fifth Floor
      Boston, MA  02110-1301
      USA

*/

[indent=4]

namespace {PROJECT_NAMESPACE}

    [GtkTemplate (ui = "{RESOURCE_URI}/application.ui")]
    class ApplicationWindow:Gtk.ApplicationWindow

        [GtkChild]
        application_grid:Gtk.Fixed

        [GtkChild]
        application_status_bar:Gtk.Statusbar

        [GtkChild]
        header_bar:Gtk.HeaderBar

        [GtkChild]
        application_button:Gtk.MenuButton

        [GtkChild]
        window_title:Gtk.Label

        [GtkChild]
        window_subtitle:Gtk.Label

        [GtkChild]
        tools_button:Gtk.MenuButton

        [GtkChild]
        application_popover:Gtk.PopoverMenu

        [GtkChild]
        home_menu:Gtk.Box

        [GtkChild]
        project_settings:Gtk.ModelButton

        [GtkChild]
        lateral_pressure:Gtk.ModelButton

        [GtkChild]
        service_life:Gtk.ModelButton

        [GtkChild]
        mixture_analysis:Gtk.ModelButton

        [GtkChild]
        general_simulation:Gtk.ModelButton

        [GtkChild]
        exit_application:Gtk.ModelButton

        [GtkChild]
        projects_menu:Gtk.Box

        [GtkChild]
        exit_projects:Gtk.ModelButton

        [GtkChild]
        new_project:Gtk.ModelButton

        [GtkChild]
        open_project:Gtk.ModelButton

        [GtkChild]
        save_project:Gtk.ModelButton

        [GtkChild]
        pressure_menu:Gtk.Box

        [GtkChild]
        exit_pressure:Gtk.ModelButton

        [GtkChild]
        boussinesq_3d:Gtk.ModelButton

        [GtkChild]
        strip_loading:Gtk.ModelButton

        [GtkChild]
        line_loading:Gtk.ModelButton

        [GtkChild]
        point_loading:Gtk.ModelButton

        [GtkChild]
        log_spiral:Gtk.ModelButton

        [GtkChild]
        service_life_menu:Gtk.Box

        [GtkChild]
        exit_service_life:Gtk.ModelButton

        [GtkChild]
        stratful_equation:Gtk.ModelButton

        [GtkChild]
        clear_equation:Gtk.ModelButton

        [GtkChild]
        relative_life:Gtk.ModelButton

        [GtkChild]
        diffusion_theory:Gtk.ModelButton

        [GtkChild]
        what_if_analysis:Gtk.ModelButton

        [GtkChild]
        mixture_analysis_menu:Gtk.Box

        [GtkChild]
        exit_mixture_analysis:Gtk.ModelButton

        [GtkChild]
        mixture_design:Gtk.ModelButton

        [GtkChild]
        volumetric_analysis:Gtk.ModelButton

        [GtkChild]
        particulate_analysis:Gtk.ModelButton

        [GtkChild]
        general_simulation_menu:Gtk.Box

        [GtkChild]
        exit_general_simulation:Gtk.ModelButton

        [GtkChild]
        construction_simulation:Gtk.ModelButton

        [GtkChild]
        mixture_simulation:Gtk.ModelButton

        [GtkChild]
        thermal_simulation:Gtk.ModelButton

        [GtkCallback]
        def on_exit_application_clicked( exit_application:Gtk.ModelButton )
            print "Signal handler 'on_exit_application_clicked' was called ..."

        [GtkCallback]
        def on_new_project_clicked( new_project:Gtk.ModelButton )
            print "Signal handler 'on_new_project_clicked' was called ..."

        [GtkCallback]
        def on_open_project_clicked( open_project:Gtk.ModelButton )
            print "Signal handler 'on_open_project_clicked' was called ..."

        [GtkCallback]
        def on_save_project_clicked( save_project:Gtk.ModelButton )
            print "Signal handler 'on_save_project_clicked' was called ..."

        [GtkCallback]
        def on_boussinesq_3d_clicked( boussinesq_3d:Gtk.ModelButton )
            print "Signal handler 'on_boussinesq_3d_clicked' was called ..."

        [GtkCallback]
        def on_strip_loading_clicked( strip_loading:Gtk.ModelButton )
            print "Signal handler 'on_strip_loading_clicked' was called ..."

        [GtkCallback]
        def on_line_loading_clicked( line_loading:Gtk.ModelButton )
            print "Signal handler 'on_line_loading_clicked' was called ..."

        [GtkCallback]
        def on_point_loading_clicked( point_loading:Gtk.ModelButton )
            print "Signal handler 'on_point_loading_clicked' was called ..."

        [GtkCallback]
        def on_log_spiral_clicked( log_spiral:Gtk.ModelButton )
            print "Signal handler 'on_log_spiral_clicked' was called ..."

        [GtkCallback]
        def on_stratful_equation_clicked( stratful_equation:Gtk.ModelButton )
            print "Signal handler 'on_stratful_equation_clicked' was called ..."

        [GtkCallback]
        def on_clear_equation_clicked( clear_equation:Gtk.ModelButton )
            print "Signal handler 'on_clear_equation_clicked' was called ..."

        [GtkCallback]
        def on_relative_life_clicked( relative_life:Gtk.ModelButton )
            print "Signal handler 'on_relative_life_clicked' was called ..."

        [GtkCallback]
        def on_diffusion_theory_clicked( diffusion_theory:Gtk.ModelButton )
            print "Signal handler 'on_diffusion_theory_clicked' was called ..."

        [GtkCallback]
        def on_what_if_analysis_clicked( what_if_analysis:Gtk.ModelButton )
            print "Signal handler 'on_what_if_analysis_clicked' was called ..."

        [GtkCallback]
        def on_mixture_design_clicked( mixture_design:Gtk.ModelButton )
            print "Signal handler 'on_mixture_design_clicked' was called ..."

        [GtkCallback]
        def on_volumetric_analysis_clicked( volumetric_analysis:Gtk.ModelButton )
            print "Signal handler 'on_volumetric_analysis_clicked' was called ..."

        [GtkCallback]
        def on_particulate_analysis_clicked( particulate_analysis:Gtk.ModelButton )
            print "Signal handler 'on_particulate_analysis_clicked' was called ..."

        [GtkCallback]
        def on_construction_simulation_clicked( construction_simulation:Gtk.ModelButton )
            print "Signal handler 'on_construction_simulation_clicked' was called ..."

        [GtkCallback]
        def on_mixture_simulation_clicked( mixture_simulation:Gtk.ModelButton )
            print "Signal handler 'on_mixture_simulation_clicked' was called ..."

        [GtkCallback]
        def on_thermal_simulation_clicked( thermal_simulation:Gtk.ModelButton )
            print "Signal handler 'on_thermal_simulation_clicked' was called ..."

        construct()
            print "On construction do stuff ..."

        final()
            print "On destruction do stuff ..."

        def activate()
            print "On activation do stuff ..."

        def process()
            print "On processing do stuff ..."

        def run()
            print "On run do stuff ..."

/* End of file */

Upvotes: 1

Views: 1608

Answers (1)

liberforce
liberforce

Reputation: 11454

For example, are there any programs that will take a Glade (template) xml file and auto-generate the corresponding programmatic Vala or Genie source code?

Forget it. Glade once had an embedded feature of generating the corresponding code that would create the UI. This is has been removed for a good reason: it makes the application code unmaintainable, as you modify generated code by hand, and if you want to change your UI you have to regenerate the source and resolve all the conflicts.

Using a UI file generated by Glade is nowadays a couple of lines of code to use GtkBuilder. I agree though that being able to insert in your code the callback with the right signature would be a plus. Maybe GNOME Builder planned to do it? You may want to check GNOME Builder developper's blog.

Upvotes: 6

Related Questions