Friday, September 9, 2011

Ruby GTK findings

I'm continuing to use my nascent Ruby skills for other purposes: in this case, a GTK app to cut down on repeated clicking of a FreeRDP launcher. People clicking on a RDP launcher multiple times tends to crash 2008 Terminal Server.

Ubuntu users need to install "ruby" and "libgnome2-ruby" to use this stuff.

#!/usr/bin/ruby

# Application desktop launcher
# Ubuntu requirement: apt-get install ruby libgnome2-ruby packages
# Reference: http://unquietwiki.blogspot.com/2011/09/ruby-gtk-findings.html
# Michael Adams, Sep 9, 2011
#
# Takes 1 argument: the username to login to

require 'gtk2'

class RubyApp < Gtk::Window

    def initialize
        super
        set_title "APPLICATION"
        signal_connect "destroy" do
            Gtk.main_quit
        end

        init_ui
        show_all
    end

    def init_ui
        fixed = Gtk::Fixed.new
        add fixed
        label = Gtk::Label.new
        message = "Application starting.\n\n If there has been a reboot, it may take 60 seconds.\n\n"
        message += "If your screen is frozen, reboot your computer.\n\n Thank you."
        label.set_text message
        fixed.put label, 10, 40
        set_default_size 350,200
        set_window_position Gtk::Window::POS_MOUSE
    end

end

Gtk.init
     command = "xfreerdp --plugin cliprdr --plugin rdpdr --data serial:COM1:/dev/ttyUSB0 -- -z -x m -g 961x691 -u "
     command += ARGV[0] + " -p PASSWORD SERVER"
     system(command) if fork.nil?
     window = RubyApp.new
Gtk.main

* Ruby-GNOME2 project for Ruby GTK
* Ruby GTK tutorials from ZetCode
* GTK reference manual
* Ruby process management

No comments:

Post a Comment