Class: MittensUi::Image

Inherits:
Core
  • Object
show all
Defined in:
lib/mittens_ui/image.rb

Instance Attribute Summary collapse

Attributes inherited from Core

#core_widget

Instance Method Summary collapse

Methods inherited from Core

#hidden?, #hide, #remove, #show

Methods included from Helpers

#icon_map, #list_system_icons, #set_margin_from_opts_for

Constructor Details

#initialize(path, options = {}) ⇒ Image

Returns a new instance of Image.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mittens_ui/image.rb', line 7

def initialize(path, options = {})
  @path = File.join(path.strip)

  tooltip_text = options[:tooltip_text].nil? ? "" : options[:tooltip_text]
  width        = options[:width].nil?        ? 80 : options[:width]
  height       = options[:height].nil?       ? 80 : options[:height]

  pixbuf = nil

  args_to_send = {}

  if path.include?(".gif")
    pixbuf = GdkPixbuf::PixbufAnimation.new(@path)
    args_to_send[:animation] = pixbuf
  else
    pixbuf = GdkPixbuf::Pixbuf.new(file: @path, width: width, height: height)
    args_to_send[:pixbuf] = pixbuf
  end
  
  @image = Gtk::Image.new(args_to_send)
  @image.tooltip_text = tooltip_text

  @event_box = Gtk::EventBox.new.add_child(@image)

  super(@image, options)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/mittens_ui/image.rb', line 5

def path
  @path
end

Instance Method Details

#clickObject



34
35
36
37
38
# File 'lib/mittens_ui/image.rb', line 34

def click 
  @event_box.signal_connect("button_press_event") do
    yield
  end    
end

#renderObject



40
41
42
43
# File 'lib/mittens_ui/image.rb', line 40

def render
  $vertical_box.pack_start(@event_box)
  return self
end