mireru 0.2.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/NEWS.md +21 -0
- data/README.md +33 -17
- data/lib/mireru.rb +1 -1
- data/lib/mireru/command/mireru.rb +33 -55
- data/lib/mireru/navigator.rb +166 -0
- data/lib/mireru/version.rb +1 -1
- data/lib/mireru/widget.rb +18 -12
- data/lib/mireru/widget/binary.rb +16 -22
- data/lib/mireru/widget/image.rb +11 -7
- data/lib/mireru/widget/pdf.rb +38 -20
- data/lib/mireru/widget/svg.rb +20 -16
- data/lib/mireru/widget/text.rb +22 -24
- data/lib/mireru/widget/video.rb +35 -34
- data/lib/mireru/window.rb +149 -90
- data/mireru.gemspec +3 -2
- data/test/test-logger.rb +2 -1
- data/test/test-mireru.rb +4 -53
- data/test/test-window.rb +3 -16
- data/test/widget/test-binary.rb +3 -3
- data/test/widget/test-pdf.rb +3 -3
- data/test/widget/test-svg.rb +3 -3
- data/test/widget/test-text.rb +10 -6
- data/test/widget/test-video.rb +3 -3
- data/website/locales/en.yml +8 -7
- data/website/locales/ja.yml +5 -4
- data/website/source/localizable/index.haml +2 -2
- data/website/source/localizable/usage.html.erb +11 -10
- metadata +6 -11
- data/lib/mireru/container.rb +0 -38
- data/lib/mireru/widget/thumbnail.rb +0 -43
- data/test/test-container.rb +0 -52
- data/test/widget/test-thumbnail.rb +0 -18
data/lib/mireru/version.rb
CHANGED
data/lib/mireru/widget.rb
CHANGED
@@ -4,26 +4,23 @@ require "mireru/widget/pdf"
|
|
4
4
|
require "mireru/widget/svg"
|
5
5
|
require "mireru/widget/text"
|
6
6
|
require "mireru/widget/binary"
|
7
|
-
require "mireru/widget/thumbnail"
|
8
7
|
|
9
8
|
module Mireru
|
10
9
|
module Widget
|
11
10
|
module_function
|
12
|
-
def create(file, width
|
11
|
+
def create(file, width, height)
|
13
12
|
if image?(file)
|
14
|
-
widget = Mireru::Widget::Image.
|
15
|
-
elsif video?(file)
|
16
|
-
widget = Mireru::Widget::Video.
|
13
|
+
widget = Mireru::Widget::Image.new(file, width, height)
|
14
|
+
elsif video?(file) or music?(file)
|
15
|
+
widget = Mireru::Widget::Video.new(file)
|
17
16
|
elsif pdf?(file)
|
18
|
-
widget = Mireru::Widget::PDF.
|
17
|
+
widget = Mireru::Widget::PDF.new(file)
|
19
18
|
elsif svg?(file)
|
20
|
-
widget = Mireru::Widget::SVG.
|
19
|
+
widget = Mireru::Widget::SVG.new(file)
|
21
20
|
elsif text?(file)
|
22
|
-
widget = Mireru::Widget::Text.
|
23
|
-
elsif file.is_a?(Enumerable)
|
24
|
-
widget = Mireru::Widget::Thumbnail.create(file, width, height)
|
21
|
+
widget = Mireru::Widget::Text.new(file)
|
25
22
|
else
|
26
|
-
widget = Mireru::Widget::Binary.
|
23
|
+
widget = Mireru::Widget::Binary.new(file)
|
27
24
|
end
|
28
25
|
widget
|
29
26
|
end
|
@@ -32,8 +29,12 @@ module Mireru
|
|
32
29
|
/\.(png|jpe?g|gif|ico|ani|bmp|pnm|ras|tga|tiff|xbm|xpm)\z/i =~ file
|
33
30
|
end
|
34
31
|
|
32
|
+
def music?(file)
|
33
|
+
/\.(og[ag]|wav|acc|mp3|m4a|wma|flac|tta|aiff|ape|tak)\z/i =~ file
|
34
|
+
end
|
35
|
+
|
35
36
|
def video?(file)
|
36
|
-
/\.(ogm|mp4|flv|mpe?g2?|ts|mov|avi|divx|mkv|wmv|asf|wmx)\z/i =~ file
|
37
|
+
/\.(ogm|mp4|m4v|flv|mpe?g2?|ts|mov|avi|divx|mkv|wmv|asf|wmx)\z/i =~ file
|
37
38
|
end
|
38
39
|
|
39
40
|
def pdf?(file)
|
@@ -45,7 +46,12 @@ module Mireru
|
|
45
46
|
end
|
46
47
|
|
47
48
|
def text?(file)
|
49
|
+
return false if binary?(file)
|
48
50
|
File.read(file).valid_encoding?
|
49
51
|
end
|
52
|
+
|
53
|
+
def binary?(file)
|
54
|
+
/\.(la|lo|o|so|a|dll|exe|msi|tar|gz|zip|7z|lzh|rar|iso)\z/i =~ file
|
55
|
+
end
|
50
56
|
end
|
51
57
|
end
|
data/lib/mireru/widget/binary.rb
CHANGED
@@ -1,31 +1,25 @@
|
|
1
|
+
require "gtk3"
|
1
2
|
require "stringio"
|
2
3
|
require "hexdump"
|
3
4
|
|
4
5
|
module Mireru
|
5
6
|
module Widget
|
6
|
-
class Binary
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
io = StringIO.new
|
16
|
-
bytes = File.open(file, "rb").read(20 * 1024)
|
17
|
-
Hexdump.dump(bytes, :output => io)
|
18
|
-
io
|
19
|
-
end
|
7
|
+
class Binary < Gtk::TextView
|
8
|
+
def initialize(file)
|
9
|
+
text = hexdump(file).string
|
10
|
+
buffer = Gtk::TextBuffer.new
|
11
|
+
buffer.text = text
|
12
|
+
super(buffer)
|
13
|
+
editable = false
|
14
|
+
override_font(Pango::FontDescription.new("Monospace"))
|
15
|
+
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
view
|
28
|
-
end
|
17
|
+
private
|
18
|
+
def hexdump(file)
|
19
|
+
io = StringIO.new
|
20
|
+
bytes = File.open(file, "rb").read(20 * 1024)
|
21
|
+
Hexdump.dump(bytes, :output => io)
|
22
|
+
io
|
29
23
|
end
|
30
24
|
end
|
31
25
|
end
|
data/lib/mireru/widget/image.rb
CHANGED
@@ -1,15 +1,19 @@
|
|
1
|
+
require "gtk3"
|
2
|
+
|
1
3
|
module Mireru
|
2
4
|
module Widget
|
3
|
-
class Image
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class Image < Gtk::Image
|
6
|
+
def initialize(file, width, height)
|
7
|
+
super()
|
8
|
+
pixbuf_animation = Gdk::PixbufAnimation.new(file)
|
9
|
+
if pixbuf_animation.static_image?
|
10
|
+
pixbuf = pixbuf_animation.static_image
|
8
11
|
if pixbuf.width > width || pixbuf.height > height
|
9
12
|
pixbuf = Gdk::Pixbuf.new(file, width, height)
|
10
13
|
end
|
11
|
-
|
12
|
-
|
14
|
+
self.pixbuf = pixbuf
|
15
|
+
else
|
16
|
+
self.pixbuf_animation = pixbuf_animation
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
data/lib/mireru/widget/pdf.rb
CHANGED
@@ -1,31 +1,49 @@
|
|
1
|
+
require "gtk3"
|
1
2
|
require "poppler"
|
2
3
|
|
3
4
|
module Mireru
|
4
5
|
module Widget
|
5
|
-
class PDF
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
class PDF < Gtk::DrawingArea
|
7
|
+
def initialize(file)
|
8
|
+
super()
|
9
|
+
document = Poppler::Document.new(file)
|
10
|
+
@page_index = 0
|
11
|
+
@page_max = document.size - 1
|
12
|
+
width, height = document.first.size
|
13
|
+
set_size_request(width, height)
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
context.show_page
|
23
|
-
true
|
15
|
+
signal_connect("draw") do |widget, event|
|
16
|
+
context = widget.window.create_cairo_context
|
17
|
+
window_width = widget.allocated_width
|
18
|
+
window_height = widget.allocated_height
|
19
|
+
width_scale = window_width.to_f / width
|
20
|
+
height_scale = window_height.to_f / height
|
21
|
+
scale = [width_scale, height_scale].min
|
22
|
+
begin
|
23
|
+
context.scale(scale, scale)
|
24
|
+
rescue => e
|
25
|
+
$stderr.puts("#{e.class}: #{e.message}")
|
26
|
+
$stderr.puts(e.backtrace)
|
24
27
|
end
|
25
|
-
|
26
|
-
|
28
|
+
context.render_poppler_page(document[@page_index])
|
29
|
+
context.show_page
|
30
|
+
true
|
27
31
|
end
|
28
32
|
end
|
33
|
+
|
34
|
+
def next
|
35
|
+
@page_index += 1
|
36
|
+
@page_index = @page_max if @page_index > @page_max
|
37
|
+
hide
|
38
|
+
show
|
39
|
+
end
|
40
|
+
|
41
|
+
def prev
|
42
|
+
@page_index -= 1
|
43
|
+
@page_index = 0 if @page_index < 0
|
44
|
+
hide
|
45
|
+
show
|
46
|
+
end
|
29
47
|
end
|
30
48
|
end
|
31
49
|
end
|
data/lib/mireru/widget/svg.rb
CHANGED
@@ -1,25 +1,29 @@
|
|
1
|
+
require "gtk3"
|
1
2
|
require "rsvg2"
|
2
3
|
|
3
4
|
module Mireru
|
4
5
|
module Widget
|
5
|
-
class SVG
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
class SVG < Gtk::DrawingArea
|
7
|
+
def initialize(file)
|
8
|
+
super()
|
9
|
+
handle = RSVG::Handle.new_from_file(file)
|
10
|
+
width, height = handle.dimensions.to_a
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
signal_connect("draw") do |widget, event|
|
13
|
+
context = widget.window.create_cairo_context
|
14
|
+
window_width = widget.allocated_width
|
15
|
+
window_height = widget.allocated_height
|
16
|
+
width_scale = window_width.to_f / width
|
17
|
+
height_scale = window_height.to_f / height
|
18
|
+
scale = [width_scale, height_scale].min
|
19
|
+
begin
|
20
|
+
context.scale(scale, scale)
|
21
|
+
rescue => e
|
22
|
+
$stderr.puts("#{e.class}: #{e.message}")
|
23
|
+
$stderr.puts(e.backtrace)
|
20
24
|
end
|
21
|
-
|
22
|
-
|
25
|
+
context.render_rsvg_handle(handle)
|
26
|
+
true
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
data/lib/mireru/widget/text.rb
CHANGED
@@ -2,32 +2,30 @@ require "gtksourceview3"
|
|
2
2
|
|
3
3
|
module Mireru
|
4
4
|
module Widget
|
5
|
-
class Text
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
5
|
+
class Text < GtkSource::View
|
6
|
+
def initialize(file)
|
7
|
+
buffer = buffer_from_file(file)
|
8
|
+
super(buffer)
|
9
|
+
self.show_line_numbers = true
|
10
|
+
lang = GtkSource::LanguageManager.new.get_language("ruby")
|
11
|
+
self.buffer.language = lang
|
12
|
+
self.buffer.highlight_syntax = true
|
13
|
+
self.buffer.highlight_matching_brackets = true
|
14
|
+
self.editable = false
|
15
|
+
override_font(Pango::FontDescription.new("Monospace"))
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
private
|
19
|
+
def buffer_from_file(file)
|
20
|
+
text = File.open(file).read
|
21
|
+
buffer_from_text(text)
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
24
|
+
def buffer_from_text(text)
|
25
|
+
text.encode!("utf-8") unless text.encoding == "utf-8"
|
26
|
+
buffer = GtkSource::Buffer.new
|
27
|
+
buffer.text = text
|
28
|
+
buffer
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
data/lib/mireru/widget/video.rb
CHANGED
@@ -3,46 +3,47 @@ require "clutter-gst"
|
|
3
3
|
|
4
4
|
module Mireru
|
5
5
|
module Widget
|
6
|
-
class Video
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
video_texture.
|
20
|
-
|
21
|
-
clutter.signal_connect("destroy") do
|
22
|
-
video_texture.playing = false
|
23
|
-
end
|
24
|
-
clutter
|
6
|
+
class Video < ClutterGtk::Embed
|
7
|
+
def initialize(file)
|
8
|
+
super()
|
9
|
+
stage.background_color = Clutter::Color.new(:black)
|
10
|
+
@video_texture = ClutterGst::VideoTexture.new
|
11
|
+
stage.add_child(@video_texture)
|
12
|
+
@video_texture.signal_connect("eos") do |_video_texture|
|
13
|
+
_video_texture.progress = 0.0
|
14
|
+
_video_texture.playing = true
|
15
|
+
end
|
16
|
+
@video_texture.filename = file
|
17
|
+
@video_texture.playing = true
|
18
|
+
signal_connect("destroy") do
|
19
|
+
next if @video_texture.destroyed?
|
20
|
+
@video_texture.playing = false
|
25
21
|
end
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
case event.type
|
32
|
-
when Clutter::EventType::KEY_PRESS
|
33
|
-
animation = nil
|
34
|
-
case event.key_symbol
|
35
|
-
when Clutter::Keys::KEY_space
|
36
|
-
state = video_texture.playing?
|
37
|
-
video_texture.playing = state ? false : true
|
38
|
-
end
|
39
|
-
handled = true
|
40
|
-
end
|
23
|
+
@video_texture.signal_connect_after("size-change") do |texture, base_width, base_height|
|
24
|
+
stage_width, stage_height = stage.size
|
25
|
+
frame_width, frame_height = texture.size
|
41
26
|
|
42
|
-
|
27
|
+
new_height = (frame_height * stage_width) / frame_width
|
28
|
+
if new_height <= stage_height
|
29
|
+
new_width = stage_width
|
30
|
+
new_x = 0
|
31
|
+
new_y = (stage_height - new_height) / 2
|
32
|
+
else
|
33
|
+
new_width = (frame_width * stage_height) / frame_height
|
34
|
+
new_height = stage_height
|
35
|
+
new_x = (stage_width - new_width) / 2
|
36
|
+
new_y = 0
|
43
37
|
end
|
38
|
+
texture.set_position(new_x, new_y)
|
39
|
+
texture.set_size(new_width, new_height)
|
44
40
|
end
|
45
41
|
end
|
42
|
+
|
43
|
+
def pause_or_play
|
44
|
+
state = @video_texture.playing?
|
45
|
+
@video_texture.playing = state ? false : true
|
46
|
+
end
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
data/lib/mireru/window.rb
CHANGED
@@ -1,111 +1,43 @@
|
|
1
1
|
require "gtk3"
|
2
2
|
require "mireru/widget"
|
3
|
+
require "mireru/navigator"
|
3
4
|
|
4
5
|
module Mireru
|
5
6
|
class Window < Gtk::Window
|
6
7
|
attr_accessor :font
|
7
|
-
|
8
|
-
|
8
|
+
attr_accessor :file
|
9
|
+
def initialize(files)
|
10
|
+
super()
|
11
|
+
@files = files
|
12
|
+
|
13
|
+
@paned = Gtk::Paned.new(:horizontal)
|
14
|
+
add(@paned)
|
15
|
+
|
16
|
+
@navigator = Navigator.new(self, files)
|
17
|
+
@paned.add(@navigator)
|
18
|
+
|
9
19
|
@scroll = Gtk::ScrolledWindow.new
|
10
20
|
@scroll.set_policy(:automatic, :automatic)
|
11
|
-
add(@scroll)
|
12
|
-
|
21
|
+
@paned.add(@scroll)
|
22
|
+
|
23
|
+
set_default_size(800, 600)
|
13
24
|
signal_connect("destroy") do
|
14
25
|
Gtk.main_quit
|
15
26
|
end
|
16
|
-
end
|
17
27
|
|
18
|
-
|
19
|
-
@container = container
|
20
|
-
|
21
|
-
@file = @container.shift
|
22
|
-
add_from_file(@file)
|
23
|
-
|
24
|
-
signal_connect("key-press-event") do |widget, event|
|
25
|
-
case event.keyval
|
26
|
-
when Gdk::Keyval::GDK_KEY_n
|
27
|
-
@file = @container.shift(@file)
|
28
|
-
add_from_file(@file)
|
29
|
-
when Gdk::Keyval::GDK_KEY_p
|
30
|
-
@file = @container.pop(@file)
|
31
|
-
add_from_file(@file)
|
32
|
-
when Gdk::Keyval::GDK_KEY_r
|
33
|
-
add_from_file(@file)
|
34
|
-
when Gdk::Keyval::GDK_KEY_e
|
35
|
-
self.title = File.expand_path(@file)
|
36
|
-
when Gdk::Keyval::GDK_KEY_f
|
37
|
-
if Mireru::Widget.image?(@file)
|
38
|
-
pixbuf = Gdk::Pixbuf.new(@file, *self.size)
|
39
|
-
@widget.pixbuf = pixbuf
|
40
|
-
elsif @widget.is_a?(Gtk::TextView)
|
41
|
-
font = @widget.pango_context.families.sample.name
|
42
|
-
@widget.override_font(Pango::FontDescription.new(font))
|
43
|
-
self.title = "#{File.basename(@file)} (#{font})"
|
44
|
-
end
|
45
|
-
when Gdk::Keyval::GDK_KEY_o
|
46
|
-
if Mireru::Widget.image?(@file)
|
47
|
-
pixbuf = Gdk::Pixbuf.new(@file)
|
48
|
-
@widget.pixbuf = pixbuf
|
49
|
-
end
|
50
|
-
when Gdk::Keyval::GDK_KEY_T
|
51
|
-
files = @container.instance_variable_get(:@files)
|
52
|
-
add_from_file(files)
|
53
|
-
when Gdk::Keyval::GDK_KEY_plus
|
54
|
-
if Mireru::Widget.image?(@file)
|
55
|
-
pixbuf = @widget.pixbuf
|
56
|
-
scale = 1.1
|
57
|
-
@widget.pixbuf = pixbuf.scale(pixbuf.width * scale,
|
58
|
-
pixbuf.height * scale)
|
59
|
-
elsif @widget.is_a?(Gtk::TextView)
|
60
|
-
font = @widget.pango_context.font_description.to_s
|
61
|
-
font_size = font.scan(/\d+\z/).first.to_i
|
62
|
-
font = font.sub(/\d+\z/, (font_size + 1).to_s)
|
63
|
-
@widget.override_font(Pango::FontDescription.new(font))
|
64
|
-
end
|
65
|
-
when Gdk::Keyval::GDK_KEY_minus
|
66
|
-
if Mireru::Widget.image?(@file)
|
67
|
-
pixbuf = @widget.pixbuf
|
68
|
-
scale = 0.9
|
69
|
-
@widget.pixbuf = pixbuf.scale(pixbuf.width * scale,
|
70
|
-
pixbuf.height * scale)
|
71
|
-
elsif @widget.is_a?(Gtk::TextView)
|
72
|
-
font = @widget.pango_context.font_description.to_s
|
73
|
-
font_size = font.scan(/\d+\z/).first.to_i
|
74
|
-
font = font.sub(/\d+\z/, (font_size - 1).to_s)
|
75
|
-
@widget.override_font(Pango::FontDescription.new(font))
|
76
|
-
end
|
77
|
-
when Gdk::Keyval::GDK_KEY_h
|
78
|
-
@scroll.hadjustment.value -= 17
|
79
|
-
when Gdk::Keyval::GDK_KEY_j
|
80
|
-
@scroll.vadjustment.value += 17
|
81
|
-
when Gdk::Keyval::GDK_KEY_k
|
82
|
-
@scroll.vadjustment.value -= 17
|
83
|
-
when Gdk::Keyval::GDK_KEY_l
|
84
|
-
@scroll.hadjustment.value += 17
|
85
|
-
when Gdk::Keyval::GDK_KEY_H
|
86
|
-
@scroll.hadjustment.value -= 1000000
|
87
|
-
when Gdk::Keyval::GDK_KEY_J, Gdk::Keyval::GDK_KEY_G
|
88
|
-
@scroll.vadjustment.value += 1000000
|
89
|
-
when Gdk::Keyval::GDK_KEY_K
|
90
|
-
@scroll.vadjustment.value -= 1000000
|
91
|
-
when Gdk::Keyval::GDK_KEY_L
|
92
|
-
@scroll.hadjustment.value += 1000000
|
93
|
-
when Gdk::Keyval::GDK_KEY_q
|
94
|
-
destroy
|
95
|
-
end
|
96
|
-
end
|
28
|
+
define_keybind
|
97
29
|
end
|
98
30
|
|
99
31
|
def add_from_file(file)
|
100
32
|
@scroll.hadjustment.value = 0
|
101
33
|
@scroll.vadjustment.value = 0
|
102
|
-
@scroll.each
|
103
|
-
|
104
|
-
|
105
|
-
self.title = "Thumbnails: #{file.size} / #{file.size}"
|
106
|
-
else
|
107
|
-
self.title = File.basename(file)
|
34
|
+
@scroll.each do |child|
|
35
|
+
@scroll.remove(child)
|
36
|
+
child.destroy
|
108
37
|
end
|
38
|
+
width = @scroll.allocated_width - 10
|
39
|
+
height = @scroll.allocated_height - 10
|
40
|
+
@widget = Mireru::Widget.create(file, width, height)
|
109
41
|
@widget.override_font(Pango::FontDescription.new(@font)) if @font
|
110
42
|
if @widget.is_a?(Gtk::Scrollable)
|
111
43
|
@scroll.add(@widget)
|
@@ -114,5 +46,132 @@ module Mireru
|
|
114
46
|
end
|
115
47
|
show_all
|
116
48
|
end
|
49
|
+
|
50
|
+
def run
|
51
|
+
show_all
|
52
|
+
Gtk.main
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def define_keybind
|
57
|
+
signal_connect("key-press-event") do |widget, event|
|
58
|
+
handled = false
|
59
|
+
|
60
|
+
if event.state.control_mask?
|
61
|
+
handled = action_from_keyval_with_control_mask(event.keyval)
|
62
|
+
else
|
63
|
+
handled = action_from_keyval(event.keyval)
|
64
|
+
end
|
65
|
+
|
66
|
+
handled
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def action_from_keyval(keyval)
|
71
|
+
case keyval
|
72
|
+
when Gdk::Keyval::GDK_KEY_n
|
73
|
+
@navigator.next
|
74
|
+
when Gdk::Keyval::GDK_KEY_p
|
75
|
+
@navigator.prev
|
76
|
+
when Gdk::Keyval::GDK_KEY_r
|
77
|
+
add_from_file(@file) # reload
|
78
|
+
when Gdk::Keyval::GDK_KEY_e
|
79
|
+
@navigator.expand_toggle
|
80
|
+
when Gdk::Keyval::GDK_KEY_Return
|
81
|
+
@navigator.expand_toggle
|
82
|
+
when Gdk::Keyval::GDK_KEY_space
|
83
|
+
if @widget.is_a?(Widget::Video)
|
84
|
+
@widget.pause_or_play
|
85
|
+
end
|
86
|
+
when Gdk::Keyval::GDK_KEY_f
|
87
|
+
if Mireru::Widget.image?(@file)
|
88
|
+
width = @scroll.allocated_width - 10
|
89
|
+
height = @scroll.allocated_height - 10
|
90
|
+
pixbuf = Gdk::Pixbuf.new(@file, width, height)
|
91
|
+
@widget.pixbuf = pixbuf
|
92
|
+
elsif @widget.is_a?(Gtk::TextView)
|
93
|
+
font = @widget.pango_context.families.sample.name
|
94
|
+
@widget.override_font(Pango::FontDescription.new(font))
|
95
|
+
end
|
96
|
+
when Gdk::Keyval::GDK_KEY_o
|
97
|
+
if Mireru::Widget.image?(@file)
|
98
|
+
pixbuf = Gdk::Pixbuf.new(@file)
|
99
|
+
@widget.pixbuf = pixbuf
|
100
|
+
end
|
101
|
+
when Gdk::Keyval::GDK_KEY_plus
|
102
|
+
if Mireru::Widget.image?(@file)
|
103
|
+
pixbuf = @widget.pixbuf
|
104
|
+
scale = 1.1
|
105
|
+
@widget.pixbuf = pixbuf.scale(pixbuf.width * scale,
|
106
|
+
pixbuf.height * scale)
|
107
|
+
elsif @widget.is_a?(Gtk::TextView)
|
108
|
+
font = @widget.pango_context.font_description.to_s
|
109
|
+
font_size = font.scan(/\d+\z/).first.to_i
|
110
|
+
font = font.sub(/\d+\z/, (font_size + 1).to_s)
|
111
|
+
@widget.override_font(Pango::FontDescription.new(font))
|
112
|
+
end
|
113
|
+
when Gdk::Keyval::GDK_KEY_minus
|
114
|
+
if Mireru::Widget.image?(@file)
|
115
|
+
pixbuf = @widget.pixbuf
|
116
|
+
scale = 0.9
|
117
|
+
@widget.pixbuf = pixbuf.scale(pixbuf.width * scale,
|
118
|
+
pixbuf.height * scale)
|
119
|
+
elsif @widget.is_a?(Gtk::TextView)
|
120
|
+
font = @widget.pango_context.font_description.to_s
|
121
|
+
font_size = font.scan(/\d+\z/).first.to_i
|
122
|
+
font = font.sub(/\d+\z/, (font_size - 1).to_s)
|
123
|
+
@widget.override_font(Pango::FontDescription.new(font))
|
124
|
+
end
|
125
|
+
when Gdk::Keyval::GDK_KEY_h
|
126
|
+
@scroll.hadjustment.value -= 17
|
127
|
+
when Gdk::Keyval::GDK_KEY_j
|
128
|
+
if @widget.is_a?(Widget::PDF)
|
129
|
+
@widget.next
|
130
|
+
else
|
131
|
+
@scroll.vadjustment.value += 17
|
132
|
+
end
|
133
|
+
when Gdk::Keyval::GDK_KEY_k
|
134
|
+
if @widget.is_a?(Widget::PDF)
|
135
|
+
@widget.prev
|
136
|
+
else
|
137
|
+
@scroll.vadjustment.value -= 17
|
138
|
+
end
|
139
|
+
when Gdk::Keyval::GDK_KEY_l
|
140
|
+
@scroll.hadjustment.value += 17
|
141
|
+
when Gdk::Keyval::GDK_KEY_H
|
142
|
+
@scroll.hadjustment.value -= 17 * 100
|
143
|
+
when Gdk::Keyval::GDK_KEY_J
|
144
|
+
@scroll.vadjustment.value += 17 * 100
|
145
|
+
when Gdk::Keyval::GDK_KEY_G
|
146
|
+
@scroll.vadjustment.value = @scroll.vadjustment.upper
|
147
|
+
when Gdk::Keyval::GDK_KEY_K
|
148
|
+
@scroll.vadjustment.value -= 17 * 100
|
149
|
+
when Gdk::Keyval::GDK_KEY_L
|
150
|
+
@scroll.hadjustment.value += 17 * 100
|
151
|
+
when Gdk::Keyval::GDK_KEY_q
|
152
|
+
destroy
|
153
|
+
else
|
154
|
+
return false
|
155
|
+
end
|
156
|
+
true
|
157
|
+
end
|
158
|
+
|
159
|
+
def action_from_keyval_with_control_mask(keyval)
|
160
|
+
case keyval
|
161
|
+
when Gdk::Keyval::GDK_KEY_n
|
162
|
+
10.times { @navigator.next }
|
163
|
+
when Gdk::Keyval::GDK_KEY_p
|
164
|
+
10.times { @navigator.prev }
|
165
|
+
when Gdk::Keyval::GDK_KEY_e
|
166
|
+
@navigator.expand_toggle(true)
|
167
|
+
when Gdk::Keyval::GDK_KEY_h
|
168
|
+
@paned.position -= 2
|
169
|
+
when Gdk::Keyval::GDK_KEY_l
|
170
|
+
@paned.position += 2
|
171
|
+
else
|
172
|
+
return false
|
173
|
+
end
|
174
|
+
true
|
175
|
+
end
|
117
176
|
end
|
118
177
|
end
|