{"action":"opened","issue":{"url":"https://api.github.com/repos/ruby-gnome2/ruby-gnome2/issues/517","labels_url":"https://api.github.com/repos/ruby-gnome2/ruby-gnome2/issues/517/labels{/name}","comments_url":"https://api.github.com/repos/ruby-gnome2/ruby-gnome2/issues/517/comments","events_url":"https://api.github.com/repos/ruby-gnome2/ruby-gnome2/issues/517/events","html_url":"https://github.com/ruby-gnome2/ruby-gnome2/issues/517","id":102844775,"number":517,"title":"Exampleapp6 from gtk+ examples in ruby","user":{"login":"cedlemo","id":1135841,"avatar_url":"https://avatars.githubusercontent.com/u/1135841?v=3","gravatar_id":"","url":"https://api.github.com/users/cedlemo","html_url":"https://github.com/cedlemo","followers_url":"https://api.github.com/users/cedlemo/followers","following_url":"https://api.github.com/users/cedlemo/following{/other_user}","gists_url":"https://api.github.com/users/cedlemo/gists{/gist_id}","starred_url":"https://api.github.com/users/cedlemo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cedlemo/subscriptions","organizations_url":"https://api.github.com/users/cedlemo/orgs","repos_url":"https://api.github.com/users/cedlemo/repos","events_url":"https://api.github.com/users/cedlemo/events{/privacy}","received_events_url":"https://api.github.com/users/cedlemo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-24T17:03:52Z","updated_at":"2015-08-24T17:03:52Z","closed_at":null,"body":"@kou , I have almost finished the example 6  \r\n\r\n```ruby\r\nrequire \"gtk3\"\r\n\r\nrequire \"fileutils\"\r\n\r\ncurrent_path = File.expand_path(File.dirname(__FILE__))\r\nfile_pattern = File.basename(__FILE__).gsub(\".rb\",\"\")\r\nDATA_PATH = \"#{current_path}/data/#{file_pattern}\"\r\n\r\ngresource_bin = \"#{DATA_PATH}/exampleapp.gresource\"\r\ngresource_xml = \"#{DATA_PATH}/exampleapp.gresource.xml\"\r\n\r\nsystem(\"glib-compile-resources\",\r\n       \"--target\", gresource_bin,\r\n       \"--sourcedir\", DATA_PATH,\r\n       gresource_xml)\r\n\r\ngschema_bin = \"#{DATA_PATH}/gschemas.compiled\"\r\ngschema_xml = \"#{DATA_PATH}/org.gtk.exampleapp.gschema.xml\"\r\n\r\nsystem(\"glib-compile-schemas\", DATA_PATH)\r\n\r\n\r\nat_exit do\r\n  FileUtils.rm_f([gresource_bin, gschema_bin])\r\nend\r\n\r\nresource = Gio::Resource.load(gresource_bin)\r\nGio::Resources.register(resource)\r\n\r\nGio::SettingsSchemaSource.new(DATA_PATH,\r\n                              Gio::SettingsSchemaSource.default,\r\n                              false)\r\n\r\nclass ExampleAppPrefs < Gtk::Dialog\r\n  type_register\r\n  class << self\r\n    def init\r\n      set_template(:resource => \"/org/gtk/exampleapp/prefs.ui\")\r\n      bind_template_child(\"font\")\r\n      bind_template_child(\"transition\")\r\n    end\r\n  end\r\n  def initialize(args)\r\n    parent = args[:transient_for]\r\n    bar = args[:use_header_bar]\r\n    super(:transient_for => parent, :use_header_bar => 1)\r\n    init_template\r\n    settings = Gio::Settings.new(\"org.gtk.exampleapp\")\r\n    settings.bind(\"font\",\r\n                  font,\r\n                  \"font\",\r\n                  Gio::SettingsBindFlags::DEFAULT)\r\n    settings.bind(\"transition\",\r\n                  transition,\r\n                  \"active-id\",\r\n                  Gio::SettingsBindFlags::DEFAULT)\r\n  end\r\nend\r\n\r\nclass ExampleAppWindow < Gtk::ApplicationWindow\r\n  # https://github.com/ruby-gnome2/ruby-gnome2/pull/445\r\n  # https://github.com/ruby-gnome2/ruby-gnome2/issues/503\r\n  type_register\r\n  class << self\r\n    def init\r\n      set_template(:resource => \"/org/gtk/exampleapp/window.ui\")\r\n      bind_template_child(\"stack\")\r\n    end\r\n  end\r\n\r\n  def initialize(application)\r\n    super(:application => application)\r\n    # load settings from gschemas.compiled in a directory\r\n    # see https://developer.gnome.org/gio/unstable/gio-GSettingsSchema-GSettingsSchemaSource.html#g-settings-schema-source-new-from-directory\r\n    # check ruby-gnome Gio::Settings.new or Gio::Schemas ??\r\n    @settings = Gio::Settings.new(\"org.gtk.exampleapp\")\r\n    @settings.bind(\"transition\",\r\n                  stack,\r\n                  \"transition-type\",\r\n                  Gio::SettingsBindFlags::DEFAULT)\r\n  end\r\n\r\n  def open(file)\r\n    basename = file.basename\r\n    scrolled = Gtk::ScrolledWindow.new\r\n    scrolled.show\r\n    scrolled.set_hexpand(true)\r\n    scrolled.set_vexpand(true)\r\n    view = Gtk::TextView.new\r\n    view.set_editable(false)\r\n    view.set_cursor_visible(false)\r\n    view.show\r\n    scrolled.add(view)\r\n    stack.add_titled(scrolled, basename, basename)\r\n    stream = file.read\r\n    buffer = view.buffer\r\n    buffer.text = stream.read\r\n    tag = buffer.create_tag() \r\n    @settings.bind(\"font\", tag, \"font\", Gio::SettingsBindFlags::DEFAULT)\r\n    buffer.apply_tag(tag, buffer.start_iter, buffer.end_iter)\r\n  end\r\nend\r\n\r\nclass ExampleApp < Gtk::Application\r\n  def initialize\r\n    super(\"org.gtk.exampleapp\", :handles_open)\r\n\r\n    signal_connect \"startup\" do |application|\r\n      quit_accels = [\"<Ctrl>Q\"]\r\n      action = Gio::SimpleAction.new(\"quit\")\r\n      action.signal_connect(\"activate\") do |_action, _parameter|\r\n        application.quit\r\n      end\r\n      application.add_action(action)\r\n      application.set_accels_for_action(\"app.quit\", quit_accels)\r\n\r\n      action = Gio::SimpleAction.new(\"preferences\")\r\n      action.signal_connect(\"activate\") do |_action, _parameter|\r\n        win = application.windows.first\r\n\r\n        prefs = ExampleAppPrefs.new(:transient_for => win,\r\n                                    :use_header_bar => true)\r\n        prefs.present\r\n      end\r\n      application.add_action(action)\r\n\r\n      builder = Gtk::Builder.new(:resource => \"/org/gtk/exampleapp/app-menu.ui\")\r\n      app_menu = builder.get_object(\"appmenu\")\r\n      application.set_app_menu(app_menu)\r\n\r\n    end\r\n    signal_connect \"activate\" do |application|\r\n      window = ExampleAppWindow.new(application)\r\n      window.present\r\n    end\r\n\r\n    signal_connect \"open\" do |application, files, hint|\r\n      windows = application.windows\r\n      win = nil\r\n      unless windows.empty?\r\n        win = windows.first\r\n      else\r\n        win = ExampleAppWindow.new(application)\r\n      end\r\n\r\n      files.each { |file| win.open(file) }\r\n\r\n      win.present\r\n    end\r\n\r\n  end\r\nend\r\n\r\napp = ExampleApp.new\r\n\r\nputs app.run([$0] + ARGV)\r\n```\r\n\r\nYou can find the full examples here in order to try:\r\n\r\nhttps://github.com/cedlemo/ruby-gtk3-tutorial\r\n\r\nI have an issue when I display the preference dialog:\r\n\r\n![2015-08-24-185824_1920x1080_scrot](https://cloud.githubusercontent.com/assets/1135841/9446480/40911fd2-4a92-11e5-97fe-3d75bc871597.png)\r\n\r\n\r\nAs You can see in the preferences dialog, I have 2 font selections and 2 transition selection. I should only have one. Any ideas what I am doing wrong?\r\n\r\nWhen the examples 5 and 6 will be finished, I will send you a pull request."}}