Class: Mireru::Window

Inherits:
Gtk::Window
  • Object
show all
Defined in:
lib/mireru/window.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWindow

Returns a new instance of Window.



7
8
9
10
11
12
13
14
15
16
# File 'lib/mireru/window.rb', line 7

def initialize
  super
  @scroll = Gtk::ScrolledWindow.new
  @scroll.set_policy(:automatic, :automatic)
  add(@scroll)
  set_default_size(640, 640)
  signal_connect("destroy") do
    Gtk.main_quit
  end
end

Instance Attribute Details

#fontObject

Returns the value of attribute font.



6
7
8
# File 'lib/mireru/window.rb', line 6

def font
  @font
end

Instance Method Details

#add_container(container) ⇒ Object



18
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
# File 'lib/mireru/window.rb', line 18

def add_container(container)
  @container = container

  @file = @container.shift
  add_from_file(@file)

  signal_connect("key-press-event") do |widget, event|
    case event.keyval
    when Gdk::Keyval::GDK_KEY_n
      @file = @container.shift(@file)
      add_from_file(@file)
    when Gdk::Keyval::GDK_KEY_p
      @file = @container.pop(@file)
      add_from_file(@file)
    when Gdk::Keyval::GDK_KEY_r
      add_from_file(@file)
    when Gdk::Keyval::GDK_KEY_e
      self.title = File.expand_path(@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)
      add_from_file(files)
    when Gdk::Keyval::GDK_KEY_plus
      if Mireru::Widget.image?(@file)
        pixbuf = @widget.pixbuf
        scale = 1.1
        @widget.pixbuf = pixbuf.scale(pixbuf.width  * scale,
                                      pixbuf.height * scale)
      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)
        pixbuf = @widget.pixbuf
        scale = 0.9
        @widget.pixbuf = pixbuf.scale(pixbuf.width  * scale,
                                      pixbuf.height * scale)
      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
      destroy
    end
  end
end

#add_from_file(file) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/mireru/window.rb', line 99

def add_from_file(file)
  @scroll.hadjustment.value = 0
  @scroll.vadjustment.value = 0
  @scroll.each {|child| child.destroy }
  @widget = Mireru::Widget.create(file, *self.size)
  if @widget.is_a?(Mireru::Widget::Thumbnail)
    self.title = "Thumbnails: #{file.size} / #{file.size}"
  else
    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.add_with_viewport(@widget)
  end
  show_all
end