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

#initialize(files, options = {}) ⇒ Window

Returns a new instance of Window.



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

def initialize(files, options={})
  super()
  @files = files
  @font = options[:font]

  @paned = Gtk::Paned.new(:horizontal)
  add(@paned)

  @navigator = Navigator.new(self, files, options)
  @paned.add(@navigator)

  @main_vbox = Gtk::Box.new(:vertical)
  @paned.add(@main_vbox)

  @scroll = Gtk::ScrolledWindow.new
  @scroll.set_policy(:automatic, :automatic)
  @main_vbox.pack_start(@scroll, :expand  => true,
                                 :fill    => true,
                                 :padding => 0)

  @status_bar = StatusBar.new
  @main_vbox.pack_end(@status_bar, :expand  => false,
                                   :fill    => false,
                                   :padding => 0)

  @default_width = options[:width] || 800
  @default_height = options[:height] || 600
  set_default_size(@default_width, @default_height)
  signal_connect("destroy") do
    Gtk.main_quit
  end

  define_keybind
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



24
25
26
# File 'lib/mireru/window.rb', line 24

def file
  @file
end

Instance Method Details

#add_from_file(file, chupa = false) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/mireru/window.rb', line 60

def add_from_file(file, chupa=false)
  @scroll.hadjustment.value = 0
  @scroll.vadjustment.value = 0
  @scroll.each do |child|
    @scroll.remove(child)
    child.destroy
  end
  width = @scroll.allocated_width - 10
  height = @scroll.allocated_height - 10
  @widget = Mireru::Widget.create(file, width, height, chupa)
  @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
  @status_bar.set_file(file)
  show_all
end

#runObject



80
81
82
83
# File 'lib/mireru/window.rb', line 80

def run
  show_all
  Gtk.main
end