LoginSignup
12
12

More than 5 years have passed since last update.

shoesを使って簡単なGUIを作成する

Last updated at Posted at 2013-09-11

RubyのGUIライブラリにはWxRuby, FxRuby, QtRubyなど様々なものがあるようだが、その中の一つに shoes がある。
簡易な記述でGUIアプリが作れるGUI界のSinatra的存在(?)。

インストールして最初のアプリを作るまで

ダウンロードページ からshoesをダウンロード。
Mac OSXの場合、.app形式として配布されている。
shoes.app を起動して「Open an App」をクリックし、rubyのスクリプトを開くとGUIアプリケーションが起動できる。

スクリプトは以下のように書く。詳細はドキュメントを参照。

Shoes.app do
   button("Click me").click do
     alert("Hello world")
   end
end

いちいちshoes.appを起動するのは面倒なので、コマンドラインから実行する。(Mac OSXの場合)

/Applications/Shoes.app/Contents/MacOS/shoes hello.rb

デバッグのためにコンソールを見たい時はアプリ上で alt + / を押す。

変更後すぐにアプリを起動する

Guardを使って、rubyを保存するとすぐにアプリが起動するように設定する。
Gemfileを編集する。

source "https://rubygems.org"
gem "guard"
gem "guard-shell"

bundle install 後にGuardfileを以下のように編集する。

guard 'shell' do
  watch(/(.*)\.rb$/) {|m| `/Applications/Shoes.app/Contents/MacOS/shoes #{m[0]}` }
end

bundle exec guard を実行してはguardを起動しておけばよい。

12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12