lib/wait_up/application.rb in wait_up-0.1.0 vs lib/wait_up/application.rb in wait_up-0.1.1
- old
+ new
@@ -1,7 +1,9 @@
-require 'gtk3'
+# frozen_string_literal: true
+require "gtk3"
+
module WaitUp
# Main Wait Up application class
class Application
def initialize
setup_gui
@@ -17,49 +19,61 @@
connect_slide_signal
connect_file_chooser_signal
end
def connect_destroy_signal
- @win.signal_connect('destroy') { Gtk.main_quit }
+ @win.signal_connect("destroy") { Gtk.main_quit }
end
def connect_key_press_event_signal
- @win.signal_connect 'key-press-event' do |_wdg, evt, _ud|
+ @win.signal_connect "key-press-event" do |_wdg, evt, _ud|
handle_key(evt) if evt.state.control_mask?
false
end
end
def handle_key(evt)
case evt.keyval
- when 'q'.ord
+ when "q".ord
@win.destroy
end
end
def connect_slide_signal
- @timeline.signal_connect 'format-value' do |_scale, value, _user_data|
+ timeline.signal_connect "format-value" do |_scale, value, _user_data|
">#{value}<"
end
end
def connect_file_chooser_signal
- @chooser.signal_connect 'file-set' do |_widget, _user_data|
- puts @chooser.filename
+ chooser.signal_connect "file-set" do |_widget, _user_data|
+ puts chooser.filename
end
end
def setup_gui
@win = Gtk::Window.new :toplevel
- @grid = Gtk::Grid.new
- @grid.orientation = :vertical
- @win.add @grid
- @chooser = Gtk::FileChooserButton.new('Hello!', :open)
- @grid.add @chooser
- @timeline = Gtk::Scale.new :horizontal, 0.0, 10.0, 0.1
- @timeline.hexpand = true
- @grid.add @timeline
- @volume = Gtk::VolumeButton.new
- @grid.add @volume
+ @win.add grid
+ end
+
+ def grid
+ @grid ||=
+ Gtk::Grid.new.tap do |grid|
+ grid.orientation = :vertical
+ grid.add chooser
+ grid.add timeline
+ grid.add Gtk::VolumeButton.new
+ end
+ end
+
+ def timeline
+ @timeline ||=
+ Gtk::Scale.new(:horizontal, 0.0, 10.0, 0.1).tap do |it|
+ it.hexpand = true
+ end
+ end
+
+ def chooser
+ @chooser ||= Gtk::FileChooserButton.new("Hello!", :open)
end
end
end