Glade作为GTK3 / 4/5的起点(而不是Gnome-Builder)

问题描述 投票:1回答:1

现在已经花了一些时间来处理Gnome Builder,Glade,Vala和Genie - 并考虑到优秀的Gnome人机界面指南(GHIG) - 为什么Glade不是几乎所有GTK GUI应用程序的起点?

例如,是否有任何程序将采用Glade(模板)xml文件并自动生成相应的程序化Vala或Genie源代码?如果有标准的Gtk.ApplicationWindow Glade xml文件,例如,随Glade / Gnome附带的GHIG,这些文件可以快速适应特定项目和带有信号自动生成的Genie类模板 - 加上完整的gresource / meson / flatpak结构。这只是直接导入Gnome-Builder作为起点。有这样的事吗?

更新

以下文件application.gs是使用Genie属性组合从application.ui自动生成的。不想在这里重新发明轮子 - 因此这个问题的原因。以下删除了一些字段,但实际文件已完全填写并可以使用。除了'application.ui'的内容之外,唯一需要的信息是资源路径和ui文件名。一切都已包含在Glade文件中。

/*
  {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 */
gtk gtk3 gnome glade
1个回答
6
投票

例如,是否有任何程序将采用Glade(模板)xml文件并自动生成相应的程序化Vala或Genie源代码?

算了吧。 Glade曾经有一个嵌入式功能,可以生成相应的代码来创建UI。这已被移除有一个很好的理由:它使应用程序代码无法维护,因为您手动修改生成的代码,如果您想要更改UI,则必须重新生成源并解决所有冲突。

使用Glade生成的UI文件现在需要使用GtkBuilder的几行代码。我同意,虽然能够在您的代码中插入具有正确签名的回调将是一个加号。也许GNOME Builder计划这样做?你可能想检查GNOME Builder developper's blog

© www.soinside.com 2019 - 2024. All rights reserved.