LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Ruby-Gtk3 anybody? Which API-reference do you use? (https://www.linuxquestions.org/questions/programming-9/ruby-gtk3-anybody-which-api-reference-do-you-use-4175611978/)

Michael Uplawski 08-15-2017 02:54 AM

Ruby-Gtk3 anybody? Which API-reference do you use?
 
The API-reference for Ruby-Gtk that I can find on the web appears to be terribly outdated. So maybe there is one that I cannot find or something else, that I have missed.

Luckily, I have a few code-examples around and can try to apply the information from the old documentation to the current Gtk3 library and Ruby-Gem. But this is awfully inefficient.

Today, I get my hints by
1.) looking at the code, like in:
In deed, the option hash is named ‘options’ in Button::initialize()
2.) checking the available methods, like in:
Code:

irb(main):008:0> require 'gtk3'
=> true
irb(main):009:0> Gtk::Button.public_methods.sort

=> [:!, :!=, :!~, :<, :<=, :<=>, :==, :===, :=~, :>, :>=, :__id__, :__send__,
:accessible_role=, :accessible_type=, :allocate, :ancestors, :append_features,
:autoload, :autoload?, :bind_template_callback_full, :bind_template_child,
:bind_template_child_full, :child_properties, :child_property, :class,
:class_eval, :class_exec, :class_variable_defined?, :class_variable_get,
:class_variable_set, :class_variables, :clone, (...)

3.) Calling ri because I am a believer:
Code:

:~$ ri Gtk::Button.new
= Gtk::Button.new
(from gem gtk3-3.1.8)
=== Implementation from Button
------------------------------------------------------------------------------
  new(options={})
------------------------------------------------------------------------------

4.) trying what I consider possibly correct usage of a method, like in:
Code:

irb(main):010:0> require 'gtk3'
=> true
irb(main):011:0> bt = Gtk::Button.new('Whatever')
(irb):11:in `new': 'Gtk::Button#initialize(label_or_stock_id, use_underline =
nil)' style has been deprecated. Use 'Gtk::Button#initialize(:label => nil,
:use_underline => nil, :stock_id => nil)' style.
=> #<Gtk::Button:0x5605842187b8 ptr=0x560584674180>

(oh, cool. They use an option-hash, now)
Code:

irb(main):004:0> require 'gtk3'
=> true
irb(main):005:0> bt = Gtk::Button.new(:my_option => 'now what?')
irb(main):007:0> bt.to_s
=> "#<Gtk::Button:0x000055cd0b6870d0>"
irb(main):008:0> bt.inspect
=> "#<Gtk::Button:0x55cd0b6870d0 ptr=0x55cd0b688180>"
irb(main):009:0> bt.my_option
NoMethodError: undefined method `my_option' for #<Gtk::Button:0x55cd0b6870d0 ptr=0x55cd0b688180>
        from (irb):9
        from /usr/bin/irb:11:in `<main>'
irb(main):010:0> bt.options
NoMethodError: undefined method `options' for #<Gtk::Button:0x55cd0b6870d0 ptr=0x55cd0b688180>
        from (irb):10
        from /usr/bin/irb:11:in `<main>'
irb(main):010:0> drop dead!
NoMethodError: undefined method `dead!' for main:Object
        from (irb):11
        from /usr/bin/irb:11:in `<main>'

There must be a way ...
PSE note (just in case): I know how to create buttons (and derive/overwrite or use meta-classes) in Gtk3. This was an example. The question is in the subject!

astrogeek 08-17-2017 02:15 AM

Apparently there are not many active Ruby, or Ruby-Gtk programmers here at this time, myself included!

As no one else has stepped in I can only offer the results of my own online searches, hopefully there will be something different from yours.

Here is the most current Ruby-Gtk3 API I found. The most recent updates look like 25 days ago, then 4 and 5 months ago, but not a lot of activity.

I found this Ruby-Gtk Tutorial, dated 2014.

Then there is thi ruby-gtk3-tutorial. It is 2 years old and does not look to have much depth, but has quite a few examples. You might stumble across something relevant and not totally ancient there.


And this very old site, Programming Ruby/GTK, but it has several complete examples (of unknown applicability to current Ruby and Gtk). Perhaps it can lead to other references.

I bought the Pick Axe book long ago, intending to learn Ruby, but choked on the Preface and lost interest early as I recall! I had no actual use for it at the time and could not find its compelling "reason for being". ;) Maybe I should dust it off.

Michael Uplawski 08-17-2017 10:53 AM

Thank you astrogeek for all the effort...

Quote:

Originally Posted by astrogeek (Post 5749152)
Here is the most current Ruby-Gtk3 API I found. The most recent updates look like 25 days ago, then 4 and 5 months ago, but not a lot of activity.

As I installed the Gtk3-Gem and need the Gtk-development libraries anyway, the source-code of both, the library and the Ruby-bindings, is accessible on my machine, all the time.

Quote:

I found this Ruby-Gtk Tutorial, dated 2014.
A tutorial is more for newbies who need a complete overview over the library's and the gem's potential. I already program Ruby/Gtk and just need a reliable documentation on classes and methods. Normally RDoc and ri are there for exactly this purpose.
But when you try that on Gtk, ... oh my. All you get is the Gnu-GPL three or four times in a row and a list of constants and class-method names. Felicitations!

The classes aren't any better:
Code:

:~$ ri Gtk::ToggleButton
= Gtk::ToggleButton < Object

------------------------------------------------------------------------------
= Extended by:
GLib::Deprecatable (from gem gtk3-3.1.8)

(from gem gtk3-3.1.8)
------------------------------------------------------------------------------

------------------------------------------------------------------------------
= Class methods:

  new

= Instance methods:

  initialize_raw

The heck with it.

The Ruby/Gtk-documentation is a mess. The best you can do, is consult the API-docs of the C-Library. At least it is complete and explains... stuff. Unfortunately, though, the ruby-bindings make heavy use of Ruby-mechanisms, such as symbols and variable argument-lists. Only trial&error get you from a documented C-method to running Ruby-code, if there is nobody to explain the difference. Of course, you can *ALWAYS* read the code.

Quote:

I bought the Pick Axe book long ago, intending to learn Ruby, but choked on the Preface and lost interest early as I recall! I had no actual use for it at the time and could not find its compelling "reason for being". ;) Maybe I should dust it off.
I never bought the book. This is probably an error on my side, but after attending the 2nd. Rubylearning.org online-course (and tutoring some later courses), the books on Metaprogramming and, of course, “Design-Patterns in Ruby” were more interesting. If you want quick results, buy a pocket-reference and the Ruby-Cookbook.

Thanks again.

Michael
P.S.: I see that RubyLearning.org has not been updated and that Moodle had not been awful enough. The site and the courses are probably obsolete, now. Pity.

shevegen 09-06-2020 08:50 AM

It is indeed quite messy, but not totally dead; kou still maintains the ruby bindings to gtk here:

https://github.com/ruby-gnome/ruby-gnome

I am trying to collect lots of examples into this project here:

https://rubygems.org/gems/gtk_paradise

But it will be beta for years, simply due to my own lack of time. :\

My aim with gtk_paradise is to make everything nicer to use, simpler to use
too, in the long run. And to document a LOT - but sadly, writing documentation
is horribly boring so .......

I also have noticed that information is slowly vanishing. This is really bad. Most of my code
still is in gtk2; it seems as if the transition from gtk2 to gtk3 really took a big toll. I
can not say why ... perhaps it was the mobile area that also had to pay a toll? These days
I would honestly consider just using the www-stack. At the least that one is very active.

EdGr 09-06-2020 12:26 PM

I use GTK 3 with C++. A big problem with GTK 3 was that the API remained a moving target right up until the developers called GTK 3.24 "done" and moved on to GTK 4.

I suggest using the latest 3.24 with the native C API. A version from even two years ago is obsolete.
Ed

shevegen 04-30-2021 09:52 PM

Yeah, they focus mostly on gtk4 now upstream. I like the CSS of ruby-gtk3 though so I will
probably keep on using it for a longer while. It's more pleasant to work with than with
ruby-tk, and I can re-use the CSS (in part) that I use for web-related stuff.


All times are GMT -5. The time now is 05:32 PM.