Class: Mireru::Window
- Inherits:
-
Gtk::Window
- Object
- Gtk::Window
- Mireru::Window
- Defined in:
- lib/mireru/window.rb
Instance Attribute Summary collapse
-
#font ⇒ Object
Returns the value of attribute font.
Instance Method Summary collapse
- #add_container(container) ⇒ Object
- #add_from_file(file) ⇒ Object
-
#initialize ⇒ Window
constructor
A new instance of Window.
Constructor Details
#initialize ⇒ Window
Returns a new instance of Window.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/mireru/window.rb', line 8 def initialize super @scroll = Gtk::ScrolledWindow.new @scroll.set_policy(:automatic, :automatic) self.add(@scroll) self.set_default_size(640, 640) self.signal_connect("destroy") do Gtk.main_quit end end |
Instance Attribute Details
#font ⇒ Object
Returns the value of attribute font.
7 8 9 |
# File 'lib/mireru/window.rb', line 7 def font @font end |
Instance Method Details
#add_container(container) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/mireru/window.rb', line 19 def add_container(container) @container = container @file = @container.shift self.add_from_file(@file) self.signal_connect("key_press_event") do |w, e| case e.keyval when Gdk::Keyval::GDK_KEY_n @file = @container.shift(@file) self.add_from_file(@file) when Gdk::Keyval::GDK_KEY_p @file = @container.pop(@file) self.add_from_file(@file) when Gdk::Keyval::GDK_KEY_r self.add_from_file(@file) when Gdk::Keyval::GDK_KEY_e self.title = File.(@file) when Gdk::Keyval::GDK_KEY_f if Mireru::Widget.image?(@file) pixbuf = Gdk::Pixbuf.new(@file, *self.size) @widget.pixbuf = pixbuf elsif @widget.is_a?(Gtk::TextView) font = @widget.pango_context.families.sample.name @widget.override_font(Pango::FontDescription.new(font)) self.title = "#{File.basename(@file)} (#{font})" end when Gdk::Keyval::GDK_KEY_o if Mireru::Widget.image?(@file) pixbuf = Gdk::Pixbuf.new(@file) @widget.pixbuf = pixbuf end when Gdk::Keyval::GDK_KEY_T files = @container.instance_variable_get(:@files) self.add_from_file(files) when Gdk::Keyval::GDK_KEY_plus if Mireru::Widget.image?(@file) width = @widget.pixbuf.width height = @widget.pixbuf.height scale = 1.1 pixbuf = Gdk::Pixbuf.new(@file, width * scale, height * scale) @widget.pixbuf = pixbuf elsif @widget.is_a?(Gtk::TextView) font = @widget.pango_context.font_description.to_s font_size = font.scan(/\d+\z/).first.to_i font = font.sub(/\d+\z/, (font_size + 1).to_s) @widget.override_font(Pango::FontDescription.new(font)) end when Gdk::Keyval::GDK_KEY_minus if Mireru::Widget.image?(@file) width = @widget.pixbuf.width height = @widget.pixbuf.height scale = 0.9 pixbuf = Gdk::Pixbuf.new(@file, width * scale, height * scale) @widget.pixbuf = pixbuf elsif @widget.is_a?(Gtk::TextView) font = @widget.pango_context.font_description.to_s font_size = font.scan(/\d+\z/).first.to_i font = font.sub(/\d+\z/, (font_size - 1).to_s) @widget.override_font(Pango::FontDescription.new(font)) end when Gdk::Keyval::GDK_KEY_h @scroll.hadjustment.value -= 17 when Gdk::Keyval::GDK_KEY_j @scroll.vadjustment.value += 17 when Gdk::Keyval::GDK_KEY_k @scroll.vadjustment.value -= 17 when Gdk::Keyval::GDK_KEY_l @scroll.hadjustment.value += 17 when Gdk::Keyval::GDK_KEY_H @scroll.hadjustment.value -= 1000000 when Gdk::Keyval::GDK_KEY_J, Gdk::Keyval::GDK_KEY_G @scroll.vadjustment.value += 1000000 when Gdk::Keyval::GDK_KEY_K @scroll.vadjustment.value -= 1000000 when Gdk::Keyval::GDK_KEY_L @scroll.hadjustment.value += 1000000 when Gdk::Keyval::GDK_KEY_q Gtk.main_quit end end end |
#add_from_file(file) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/mireru/window.rb', line 106 def add_from_file(file) @scroll.hadjustment.value = 0 @scroll.vadjustment.value = 0 @scroll.each {|child| child.destroy } if file.is_a?(Enumerable) @widget = Mireru::Thumbnail.create(file, *self.size) self.title = "Thumbnails: #{file.size} / #{file.size}" else @widget = Mireru::Widget.create(file, *self.size) self.title = File.basename(file) end @widget.override_font(Pango::FontDescription.new(@font)) if @font if @widget.is_a?(Gtk::Scrollable) @scroll.add(@widget) else @scroll.(@widget) end self.show_all end |