Gtk.在 Sprite 中的应用

标签 gtk gtk3 genie

我在 Genie 中找不到有关“Gtk.Application”的信息或示例。

在 Genie 中使用 Gtk.Application 类的正确方法是什么?

美好的一天,谢谢

编辑:我不知道这是否是最好的方法,但我的代码是这样的:

// compila con valac --pkg gtk+-3.0 nombre_archivo.gs
uses Gtk

class MyApplication : Gtk.Application   
    def override activate ()        
        var window = new Gtk.ApplicationWindow (this)
        window.title = "Welcome to GNOME"
        window.set_default_size (400, 400)
        window.show ()

init
    new MyApplication ().run (args)

最佳答案

您的示例对我来说似乎是一个很好的开始,但我认为您应该添加一个应用程序 ID 和一些应用程序标志。

三个好资源是GTK+3 Reference Manual's documentation for GtkApplication ,GNOME Wiki“HowDoI”部分的页面称为 "Using GtkApplication"GIO Reference Manual's documentation for GApplication . GApplication 或 Vala 绑定(bind)中的 GLib.Application 是 GtkApplication 的父类。

“HowDoI”页面建议:

GtkApplication does not implement main() for you. You must do so yourself. Your main() function should be as small as possible and do almost nothing except creating your GtkApplication and running it. The "real work" should always be done in response to the signals fired by GtkApplication.



您的 main() Genie 中的功能是:
init
    new MyApplication().run( args )

这就像你能得到的一样简单。

“HowDoI”页面还建议:

When your application starts, the startup signal will be fired. This gives you a chance to perform initialisation tasks that are not directly related to showing a new window. After this, depending on how the application is started, either activate or open will be called next.



您没有使用示例执行任何启动任务,这很好。所以没有必要使用 startup信号,但您使用的是 activate通过使用 def override activate () 覆盖虚函数来发出信号. activate当 Gtk.Application 运行时实际上是默认信号,但是当适当的 ApplicatonFlags 时可以发出替代信号被设置。例如,如果 HANDLES_OPEN标志被设置然后 open如果有未解析的命令行参数,将发送信号。未解析的参数被视为文件名或 URI。默认标志是 FLAGS_NONE稍后将在示例代码中明确说明。

GTK+3 引用手册中关于 GtkApplication 的部分指出:

Currently, GtkApplication handles GTK+ initialization, application uniqueness, session management, provides some basic scriptability and desktop shell integration by exporting actions and menus and manages a list of toplevel windows whose life-cycle is automatically tied to the life-cycle of your application...If no application ID is given then some features (most notably application uniqueness) will be disabled. A null application ID is only allowed with GTK+ 3.6 or later.



应用程序 ID 应由至少两个用点分隔的名称组成。如果应用程序第二次运行,那么第二个实例的窗口将成为第一个应用程序的一部分,但随后会关闭第二个应用程序实例。这是应用程序唯一性功能,可以使用 ApplicationFlags.NON_UNIQUE 禁用。 .应用程序使用应用程序 ID 在 session 总线上注册。如果你使用的是 Linux,你可以使用像 D-Feet 这样的工具。查看应用程序出现在 session 总线上以及再次运行应用程序时会发生什么(您需要刷新 View )。

一些代码的时间:
// compila con valac --pkg gtk+-3.0 nombre_archivo.gs
[indent=4]
uses Gtk

init
    new MyApplication( "org.genie.Example.SimpleGtkApplication",
                     ApplicationFlags.FLAGS_NONE
                     ).run( args )

class MyApplication:Gtk.Application
    construct( application_id:string, flags:ApplicationFlags )
        if !id_is_valid( application_id )
            error( "application id %s is not valid", application_id )
        this.application_id = application_id
        this.flags = flags

    def override activate ()
        var window = new Gtk.ApplicationWindow( this )
        window.title = "Welcome to GNOME"
        window.set_default_size( 400, 400 )
        window.show_all()

这将添加一个应用程序 ID 并使 ApplicationFlags明确的。

关于Gtk.在 Sprite 中的应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41967926/

相关文章:

python - 如何将 Python 的 GTK 与 gevent 集成?

python - Windows下的PyGObject : Could not locate gdk_pixbuf_new_from_file

c - Gtk2 使用同一按钮从 2 个条目获取数据

vala - Flatpak Meson 没有从 Gnome Builder 中找到 Vala 库

python - 相当于 Genie/vala 中的 raw_input()?

qt - XCB中如何唤醒GUI线程?

linux - 由 init 脚本启动的程序中的 GTK+ 对话框

window - 如何获得 Gdk.Window 任务图标或标题?

c - 如何在 GtkTreeView 中使特定行子项可编辑

c - 键盘助记符不起作用