Ruby Programming Tutorial - Lesson 34 - Creating Desktop Application in ruby + gtk3

in programming •  2 months ago

Screenshot from 2018-03-23 21-16-45.png

In this example we are going to create a simple Deskop applicaiton for linux :)

I created many desktop applications using C# programming language, that includes a Calculator, Note pad, Searching tool, Facebook group posting software, Steemit posting software, A* algorithm, graphs maker and many others, but I never tried to make a desktop application in ruby,

I was searching for it and i found a resource that was created this year, so its pretty fresh .. I decided to utilized that and give you guys a starting point, if you want to create Desktop applications using Ruby programming language.
I will post a reference link at the end, where you can follow this guys's article and create an application for yourself.

GTK+ version

Make sure you have GTK+ installed.
The OS in which I developed the tutorial’s application is Ubuntu 16.04 which has GTK+ installed by default (version: 3.18).

You can check yours with the following command:

dpkg -l libgtk-3-0

I am using ruby 2.5.0rc1 version, so make sure you have similar ruby version .

I have taken the code from the guy, and created a Class out of it, so that we can use it with very simple way, We are going to create a simple application that has nothing in it :p in this example .. but it can make a foundation for you to add things on top of it .. and create a fully functional application.

The Task

Create a Desktop application for linux operating system, using ruby programming language and GTK+

You can use glade for interface design later on, using this command on linux you can install it

sudo apt install glade

For now we are not designing any interface so you can skip it as well :) But installing this gem is required

gtk3 gem

This gem provides the Ruby bindings for the GTK+ toolkit. In other words, it allows us to talk to the GTK+ API using the Ruby language.

Install the gem via:

gem install gtk3

I have created a class that creates an empty application for you.. lets look at the class.

require 'gtk3'

class DesktopApplicaiton
    def initialize(appname, title)
        @app = Gtk::Application.new appname, :flags_none

        @app.signal_connect :activate do |application|
        window = Gtk::ApplicationWindow.new(application)
        window.set_title title
        window.present
        end
    end
    def launch
        puts @app.run
    end
end

Screenshot from 2018-03-23 21-07-18.png

lets use this Class to create a simple application :)

require_relative 'Desktopapp'

_appName  = "com.berycoin.lovelyApp"
_appTitle = "Best Desktop Applicaiton" 

_myDesktopapp = DesktopApplicaiton.new(_appName, _appTitle)
_myDesktopapp.launch()

notice how easily we can create a Desktop application, just by using our Class .. creating an object from our class, and passing to it application name and, title

Screenshot from 2018-03-23 21-08-47.png

This is just an intro to Desktop applications made with ruby and GTK+ .. we can continue on this topic for a while, and create few interesting applications ..

for now, I want you guys to take a look at this reference link.. and study it to explore more about Desktop applications made with ruby and GTK+

This could be a foundation for you to create an awesome application which saw on top of this article ;)

https://iridakos.com/tutorials/2018/01/25/creating-a-gtk-todo-application-with-ruby.html

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE BEARS!