Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
5分で学ぶGTK+
Search
Masafumi Yokoyama
March 16, 2014
Technology
78
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
5分で学ぶGTK+
デスクトップアプリケーションを作る会@札幌 2014-03-16の資料です。
Masafumi Yokoyama
March 16, 2014
More Decks by Masafumi Yokoyama
See All by Masafumi Yokoyama
Rabbit on Sinatra
myokoym
1
160
文字コード略歴
myokoym
1
430
Other Decks in Technology
See All in Technology
慶應義塾大学 AI実践05 論文執筆の仕組み化
keio_smilab
PRO
7
3.8k
令和の今、あらためて IAM を考える。アクセスキーを「無くせない現実」との向き合い方
kazzpapa3
0
540
AIエージェントの監視、思考を見るか行動を見るか / Monitoring AI Agents: Thoughts or Actions
yusukeshimizu
2
170
evcc & Home Assistant
naltatis
0
400
AI時代における医療情報システムのセキュリティ / Security of Healthcare IT Systems in the AI Era
henryofficial
0
130
AI時代に求められる優秀なTechLeadの振る舞い
pospome
11
15k
顧客合意を取りながら進めるAWSコスト削減の実践
optim
0
150
IBC 2026 動画技術関連レポート / IBC 2026 Report
cyberagentdevelopers
PRO
2
450
ゼロから作るWebアプリの新定番!?Amplify Gen 2 × AWS Blocksで実現する「開発速度とRDBの柔軟性のいいとこ取り」
amixedcolor
1
180
AIコーディングはじめました
miso
0
160
ライフワーク「猫でもわかるDirectConnect」
kentapapa
0
300
The future of architectural work
ufried
0
190
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
350
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
390
The Limits of Empathy - UXLibs8
cassininazir
2
770
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
450
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
670
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.2k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.4k
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
890
A Soul's Torment
seathinner
8
3.9k
Visualization
eitanlees
153
17k
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
Transcript
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 5分で学ぶGTK+ Ruby/GTK2のサンプルもあるよ! @myokoym
Ruby-GNOME2 Project Team デスクトップアプリケーションを作る会 2014/03/16
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 はじめに ハンズオンだと思う者には ハンズオンであり、もくもく
会だと思う者にはもくもく会 である
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 もくもく会だと思う⼈ もくもくしてください 相談などはいつでもどうぞ
:-) ✓ ✓
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 ハンズオンだと思う⼈ スライドにサンプルコードを映 すので、参考にしながら進めて
ください ✓
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 ここでアンケートです
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 Q.1 Ruby(1.9.3以降)はインストー ル済みですか?
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 Noの⽅ 個別に対応します ✓
2014年3⽉16⽇現在、Ruby/GTK2はWindows用のRuby x64版では動かないため、x86版をインストールしてくださ い
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 Q.2 Ruby/GTK2はインストール済み ですか?
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 Noの⽅ Ruby 1.9.3
or 2.0.0 or 2.1.x $ gem install gtk2 ✓ Ruby 2.2.0-dev $ git clone https://github.com/ruby-gnome2/ruby-gnome2 $ cd ruby-gnome2 $ rake gem:install ✓
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 インストールを待つ間に GTK+ の紹介をします
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 GTK+ とは GUIツールキット
オープンソース ✓ マルチプラットフォーム ✓ ⾊々な⾔語から使える ✓ ✓
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 用語 ウィジェット ✓
イベント(シグナル) ✓ メインループ ✓
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 ウィジェット GUIを構成する部品 ウィンドウ
✓ ボタン ✓ など ✓ ✓
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 イベント(シグナル) ユーザーの操作で発⽣ ウィンドウを閉じる
✓ ボタンをクリックする ✓ など ✓ ✓
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 メインループ イベントを待つ 1.
イベントに応じて処理を⾏う 2. 1に戻る 3.
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 座学は以上ですが、そろそろ インストールできましたか?
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 では、実際に⼿を動かして Ruby/GTK2を使ったデスク トップアプリケーションを作
成していきます
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 サンプルコード全⽂ https://gist.github.com/myokoym/9489619
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 Hello, GUI! require
"gtk2" window = Gtk::Window.new window.signal_connect("destroy") do Gtk.main_quit end window.show_all Gtk.main
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 Hello, GUI! require
"gtk2" #Ruby/GTK2を使う準備 # ウィンドウ・ウィジェットのオブジェクトを作成 window = Gtk::Window.new # ウィンドウが閉じられたら処理が実行される window.signal_connect("destroy") do Gtk.main_quit #メインループ終了 end window.show_all #ウィジェットを画面に表示 Gtk.main #メインループ開始
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 実⾏ $ ruby
hello_gui.rb
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 タイトルを設定 window =
Gtk::Window.new # ウィンドウのtitleプロパティに設定 window.title = "Image Viewer sample" window.signal_connect("destroy") do Gtk.main_quit end
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 画像を表⽰ window.signal_connect("destroy") do
Gtk.main_quit end path = ARGV[0] image = Gtk::Image.new image.pixbuf = Gdk::Pixbuf.new(path) window.add(image) #ウィンドウに画像を追加
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 実⾏ $ ruby
image-viewer.rb ファイル名
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 画像を2枚以上並べる hbox =
Gtk::HBox.new(false, 8) hbox.border_width = 8 window.add(hbox) ARGV.each do |path| image = Gtk::Image.new image.pixbuf = Gdk::Pixbuf.new(path) hbox.add(image) end
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 実⾏ $ ruby
image-viewer.rb ファイル名 ファイル名
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 ワイルドカードを許容 ARGV.each do
|path_or_wildcard| Dir.glob(path_or_wildcard) do |path| image = Gtk::Image.new image.pixbuf = Gdk::Pixbuf.new(path) hbox.add(image) end end
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 実⾏ $ ruby
image-viewer.rb ディレクトリ名/*.png
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 画像以外をスキップ begin pixbuf
= Gdk::Pixbuf.new(path) rescue GLib::FileError, Gdk::PixbufError $stderr.puts($!.message) next end image = Gtk::Image.new image.pixbuf = pixbuf hbox.add(image)
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 実⾏ $ ruby
image-viewer.rb ディレクトリ名/*
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 デフォルトサイズを設定 window =
Gtk::Window.new window.title = "Image Viewer sample" window.set_default_size(640, 480) window.signal_connect("destroy") do Gtk.main_quit end
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 スクロールバーを追加 scrolled_window =
Gtk::ScrolledWindow.new window.add(scrolled_window) hbox = Gtk::HBox.new(false, 8) hbox.border_width = 8 scrolled_window.add_with_viewport(hbox)
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 スクロール不要時は消す scrolled_window =
Gtk::ScrolledWindow.new scrolled_window.set_policy(:automatic, :automatic) window.add(scrolled_window) hbox = Gtk::HBox.new(false, 8) hbox.border_width = 8 scrolled_window.add_with_viewport(hbox)
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 右クリックメニューの準備 scrolled_window.add_with_viewport(hbox) menu
= Gtk::Menu.new menu_item = Gtk::ImageMenuItem.new(Gtk::Stock::DELETE) menu_item.signal_connect("activate") do hbox.remove(menu.attach_widget) end menu.append(menu_item) menu.show_all
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 右クリックで削除機能 event_box.signal_connect("button-press-event") do
|widget, event| if event.kind_of?(Gdk::EventButton) and event.button == 3 menu.attach_widget = widget menu.popup(nil, nil, event.button, event.time) end end hbox.add(event_box) image = Gtk::Image.new image.pixbuf = pixbuf event_box.add(image)
5分で学ぶGTK+ - Ruby/GTK2のサンプルもあるよ! Powered by Rabbit 2.1.2 参考リンク Ruby/GTK2 チュートリアル
http://ruby-gnome2.sourceforge.jp/ja/hiki.cgi?gtk2-tut Ruby/GTK2 sample https://github.com/ruby-gnome2/ruby-gnome2/tree/ master/gtk2/sample Ruby/GTK3 sample https://github.com/ruby-gnome2/ruby-gnome2/tree/ master/gtk3/sample