GTK Application Window doesn't work


(Sascha Manns) #1

Hello list,

currently i'm trying to build a little application with Ruby and Gtk+
(See [1]).

I have such files:

bin/latex_curriculum_vitae:

···

===========================
#!/usr/bin/env ruby

require 'gtk3'
require 'fileutils'

# Require all ruby files in the application folder recursively
application_root_path = File.expand_path(__dir__)
Dir[File.join(application_root_path, '..', 'application', '**',
'*.rb')].each { |file| require file }

# Define the source & target files of the glib-compile-resources
command
resource_xml = File.join(application_root_path, '..', 'resources',
'gresources.xml')
resource_bin = File.join(application_root_path, '..', 'gresource.bin')

# Build the binary
system("glib-compile-resources",
       "--target", resource_bin,
       "--sourcedir", File.dirname(resource_xml),
       resource_xml)

resource = Gio::Resource.load(resource_bin)
Gio::Resources.register(resource)

at_exit do
  # Before existing, please remove the binary we produced, thanks.
  FileUtils.rm_f(resource_bin)
end

app = LatexCurriculumVitae::Application.new

puts app.run

application/ui/latex_curriculum_vitae/application.rb

module LatexCurriculumVitae
  class Application < Gtk::Application
    def initialize
      super 'net.launchpad.saigkill.latex_curriculum_vitae',
Gio::ApplicationFlags::FLAGS_NONE

      signal_connect :activate do |application|
        window = Gtk::ApplicationWindow.new(application)
        window.present
      end
    end
  end
end

application/ui/latex_curriculum_vitae/application_window.rb

module LatexCurriculumVitae
  class ApplicationWindow < Gtk::ApplicationWindow
    # LatexCurriculumVitaeApplicationWindow
    # Register the class in the GLib world
    type_register

    class << self
      def init
        # Set the template from the resources binary
        set_template resource:
'/net/launchpad/saigkill/latex_curriculum_vitae/ui/application_window.u
i'
      end
    end

    def initialize(application)
      super application: application

      set_title 'Latex Curriculum Vitae'
    end
  end
end

The gresources file on [2] refers just to the application_window.ui on
[3]. It just contains three buttons.

The current result of running the start script is [4]. So i can see,
that the set_title was ignored, and also the refered ui aren't visible.

Is there any problem with my code? Is this the right place to ask or
should i ask on a GNOME/GTK list?

Greetings
Sascha

[1] https://github.com/saigkill/test
[2] https://github.com/saigkill/test/blob/master/resources/gresources.x
ml
[3] https://github.com/saigkill/test/blob/master/resources/ui/applicati
on_window.ui
[4] https://pasteboard.co/Hfv2RzY.png


(Tsuyoshi Morita) #2

Hi Sascha,

I'm using Ubuntu 16.04 64bit.
When I run your code, I get below message.

Gtk-CRITICAL **: Error building template class 'LatexCurriculumVitaeApplicationWindow'
for an instance of type 'LatexCurriculumVitaeApplicationWindow': .:3:50 Required gtk+
version 3.20, current version is 3.18

So I changed 'application_window.ui' like below.
It seems that the application window has no problem for me.

ubuntu16:~/test/test/resources/ui$ git diff application_window.ui
diff --git a/resources/ui/application_window.ui b/resources/ui/application_window.ui
index d381a4f..50097d6 100644
--- a/resources/ui/application_window.ui
+++ b/resources/ui/application_window.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<interface>
- <requires lib="gtk+" version="3.20"/>
+ <requires lib="gtk+" version="3.18"/>
   <template class="LatexCurriculumVitaeApplicationWindow" parent="GtkApplicationWindow">
     <property name="can_focus">False</property>
     <child>

···

--
Tsuyoshi Morita <golirev@gmail.com>