mireru2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 40b5b0af8c993d651df699c79cbf5a029b4c4dcf
4
+ data.tar.gz: cd7ab5de65fafae37ecc1e92c39c88119d556b3a
5
+ SHA512:
6
+ metadata.gz: a8c309dec63404ab3fba38cd850861ee3b876a8f110eab2af95b414b72996053785d097a9d7450c1a3333b2412768cf0eb37a6288793ea217ff16993e2e751ac
7
+ data.tar.gz: 4d2e964918a6a1990fdb760bfe9a9b6d1d6565f9b74dfc062122b168f6615bd68e58b5557fc75f37762bcb1067325e7e4ab95ee3d404443206ef2b38a664ddb2
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mireru2.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Masafumi Yokoyama
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/NEWS.md ADDED
@@ -0,0 +1,5 @@
1
+ # NEWS
2
+
3
+ ## 0.0.1: 2013-09-12
4
+
5
+ Initial release!
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Mireru2 - Flexible File Viewer Keyboard Friend
2
+
3
+ A file viewer with a focus on flexibility by Ruby/GTK2.
4
+
5
+ A friend of a keyboard.
6
+
7
+ ## Requirements
8
+
9
+ * Ruby/GTK2, Ruby/GtkSourceView2 in
10
+ [Ruby-GNOME2](http://ruby-gnome2.sourceforge.jp/)
11
+
12
+ ## Installation
13
+
14
+ $ gem install mireru2
15
+
16
+ ## Usage
17
+
18
+ ### Launch
19
+
20
+ $ mireru2 [OPTION]... [FILE]...
21
+
22
+ If no argument, then search current directory.
23
+
24
+ ### Options
25
+
26
+ -R, --recursive<br />
27
+ recursive search as "**/*"
28
+
29
+ -f, --font NAME<br />
30
+ set font such as "Monospace 16"
31
+
32
+ ### Keybind
33
+
34
+ #### Common
35
+
36
+ n: next<br />
37
+ p: prev<br />
38
+ r: reload<br />
39
+ e: expand path<br />
40
+ q: quit<br />
41
+
42
+ #### Scroll
43
+
44
+ h: left<br />
45
+ j: down<br />
46
+ k: up<br />
47
+ l: right<br />
48
+
49
+ #### Scale
50
+
51
+ +: larger<br />
52
+ -: smaller<br />
53
+
54
+ #### Special
55
+
56
+ T: thumbnail
57
+
58
+ #### Image
59
+
60
+ f: fits window size<br />
61
+ o: original size<br />
62
+
63
+ #### Text
64
+
65
+ f: change font (at random)<br />
66
+
67
+ ## Contributing
68
+
69
+ 1. Fork it
70
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
71
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
72
+ 4. Push to the branch (`git push origin my-new-feature`)
73
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Run test"
4
+ task :test do
5
+ Bundler::GemHelper.install_tasks
6
+ ruby("-rubygems", "test/run-test.rb")
7
+ end
8
+
9
+ task :default => :test
data/bin/mireru2 ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "mireru2/command/mireru2"
4
+
5
+ Mireru2::Command::Mireru2.run(*ARGV)
data/images/sorry.png ADDED
Binary file
data/lib/mireru2.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "mireru2/version"
2
+
3
+ module Mireru2
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,147 @@
1
+ require "gtk2"
2
+ require "mireru2/logger"
3
+ require "mireru2/window"
4
+ require "mireru2/container"
5
+ require "mireru2/version"
6
+
7
+ module Mireru2
8
+ module Command
9
+ class Mireru2
10
+ USAGE = "Usage: mireru2 [OPTION]... [FILE]..."
11
+
12
+ class << self
13
+ def run(*arguments)
14
+ new.run(arguments)
15
+ end
16
+ end
17
+
18
+ def initialize
19
+ @logger = ::Mireru2::Logger.new
20
+ end
21
+
22
+ def run(arguments)
23
+ if /\A(-h|--help)\z/ =~ arguments[0]
24
+ write_help_message
25
+ exit(true)
26
+ elsif /\A(-v|--version)\z/ =~ arguments[0]
27
+ write_version_message
28
+ exit(true)
29
+ end
30
+
31
+ font = purge_option(arguments, /\A(-f|--font)\z/, true)
32
+
33
+ files = files_from_arguments(arguments)
34
+ file_container = ::Mireru2::Container.new(files)
35
+
36
+ if file_container.empty?
37
+ write_empty_message
38
+ exit(false)
39
+ end
40
+
41
+ window = ::Mireru2::Window.new
42
+ window.font = font if font
43
+ window.add_container(file_container)
44
+
45
+ Gtk.main
46
+ end
47
+
48
+ private
49
+ def files_from_arguments(arguments)
50
+ if arguments.empty?
51
+ files = Dir.glob("*")
52
+ elsif purge_option(arguments, /\A(-R|--recursive|-d|--deep)\z/)
53
+ if arguments.empty?
54
+ files = Dir.glob("**/*")
55
+ else
56
+ files = []
57
+ arguments.each do |f|
58
+ if File.directory?(f)
59
+ files << Dir.glob("#{f}/**/*")
60
+ else
61
+ files << f
62
+ end
63
+ end
64
+ files.flatten!
65
+ end
66
+ elsif arguments.all? {|v| File.directory?(v) }
67
+ files = []
68
+ arguments.each do |f|
69
+ files << Dir.glob("#{f}/*")
70
+ end
71
+ files.flatten!
72
+ else
73
+ files = arguments
74
+ end
75
+ files
76
+ end
77
+
78
+ def purge_option(arguments, regexp, has_value=false)
79
+ index = arguments.find_index {|arg| regexp =~ arg }
80
+ return false unless index
81
+ if has_value
82
+ arguments.delete_at(index) # flag
83
+ arguments.delete_at(index) # value
84
+ else
85
+ arguments.delete_at(index)
86
+ end
87
+ end
88
+
89
+ def write_help_message
90
+ message = <<-EOM
91
+ #{USAGE}
92
+ If no argument, then search current directory.
93
+ Options:
94
+ -R, --recursive
95
+ recursive search as "**/*"
96
+ -f, --font NAME
97
+ set font such as "Monospace 16"
98
+ Keybind:
99
+ n: next
100
+ p: prev
101
+ r: reload
102
+ e: expand path
103
+ q: quit
104
+
105
+ scroll:
106
+ h: left
107
+ j: down
108
+ k: up
109
+ l: right
110
+
111
+ scale:
112
+ +: larger
113
+ -: smaller
114
+
115
+ image:
116
+ f: fits window size
117
+ o: original size
118
+
119
+ text:
120
+ f: change font (at random)
121
+ EOM
122
+ @logger.info(message)
123
+ end
124
+
125
+ def write_version_message
126
+ message = <<-EOM
127
+ #{::Mireru2::VERSION}
128
+ EOM
129
+ @logger.info(message)
130
+ end
131
+
132
+ def write_empty_message
133
+ message = <<-EOM
134
+ Warning: file not found.
135
+ #{USAGE}
136
+ If no argument, then search current directory.
137
+ Options:
138
+ -R, --recursive
139
+ recursive search as "**/*"
140
+ -f, --font NAME
141
+ set font such as "Monospace 16"
142
+ EOM
143
+ @logger.error(message)
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,38 @@
1
+ module Mireru2
2
+ class Container
3
+ def initialize(files=[])
4
+ @files = files.select {|file| file?(file) }
5
+ end
6
+
7
+ def empty?
8
+ @files.empty?
9
+ end
10
+
11
+ def size
12
+ @files.size
13
+ end
14
+
15
+ def pop(complement_file=nil)
16
+ @files.unshift(complement_file) if complement_file
17
+ @files.pop
18
+ end
19
+
20
+ def shift(complement_file=nil)
21
+ @files.push(complement_file) if complement_file
22
+ @files.shift
23
+ end
24
+
25
+ private
26
+ def file?(file)
27
+ unless file
28
+ return false
29
+ end
30
+
31
+ unless File.file?(file)
32
+ return false
33
+ end
34
+
35
+ true
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ module Mireru2
2
+ class Logger
3
+ def initialize
4
+ end
5
+
6
+ def info(message)
7
+ puts(message)
8
+ end
9
+
10
+ def error(message)
11
+ $stderr.puts(message)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,44 @@
1
+ require "gtk2"
2
+ require "mireru2/widget"
3
+
4
+ module Mireru2
5
+ class Thumbnail
6
+ class << self
7
+ def create(files, width, height)
8
+ nums_in_a_row = Math.sqrt(files.size)
9
+ rows = Gtk::Box.new(:vertical)
10
+ files.each_slice(nums_in_a_row) do |a_row_files|
11
+ row = Gtk::Box.new(:horizontal)
12
+ a_row_files.each do |file|
13
+ cell_width = width / nums_in_a_row
14
+ cell_height = height / nums_in_a_row
15
+ if Widget.image?(file)
16
+ image = image_from_file(file, cell_width, cell_height)
17
+ row.add(image)
18
+ else
19
+ label = label_from_file(file, cell_width, cell_height)
20
+ row.add(label)
21
+ end
22
+ end
23
+ rows.add(row)
24
+ end
25
+ rows
26
+ end
27
+
28
+ private
29
+ def image_from_file(file, width=100, height=100)
30
+ image = Gtk::Image.new
31
+ pixbuf = Gdk::Pixbuf.new(file, width, height)
32
+ image.pixbuf = pixbuf
33
+ image
34
+ end
35
+
36
+ def label_from_file(file, width=100, height=100)
37
+ label = Gtk::Label.new(File.basename(file))
38
+ label.set_size_request(width, height)
39
+ label.wrap = true
40
+ label
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Mireru2
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,30 @@
1
+ # NOTE: Ruby/ClutterGTK is for Ruby/GTK3.
2
+ =begin
3
+ require "clutter-gtk"
4
+ require "clutter-gst"
5
+ require "mireru2/widget"
6
+
7
+ module Mireru2
8
+ class Video
9
+ class << self
10
+ def create(file)
11
+ clutter = ClutterGtk::Embed.new
12
+ stage = clutter.stage
13
+ stage.background_color = Clutter::Color.new(:black)
14
+ video_texture = ClutterGst::VideoTexture.new
15
+ stage.add_child(video_texture)
16
+ video_texture.signal_connect("eos") do |_video_texture|
17
+ _video_texture.progress = 0.0
18
+ _video_texture.playing = true
19
+ end
20
+ video_texture.filename = file
21
+ video_texture.playing = true
22
+ clutter.signal_connect("destroy") do
23
+ video_texture.playing = false
24
+ end
25
+ clutter
26
+ end
27
+ end
28
+ end
29
+ end
30
+ =end
@@ -0,0 +1,74 @@
1
+ require "gtk2"
2
+ require "gtksourceview2"
3
+ require "mireru2/video"
4
+
5
+ module Mireru2
6
+ class Error < StandardError
7
+ end
8
+
9
+ class Widget
10
+ class << self
11
+ def create(file, width=10000, height=10000)
12
+ if image?(file)
13
+ image = Gtk::Image.new
14
+ pixbuf = Gdk::Pixbuf.new(file)
15
+ if pixbuf.width > width || pixbuf.height > height
16
+ pixbuf = Gdk::Pixbuf.new(file, width, height)
17
+ end
18
+ image.pixbuf = pixbuf
19
+ widget = image
20
+ elsif video?(file)
21
+ widget = Mireru2::Video.create(file)
22
+ else
23
+ begin
24
+ buffer = buffer_from_file(file)
25
+ rescue Mireru2::Error
26
+ return sorry
27
+ end
28
+ view = Gtk::SourceView.new(buffer)
29
+ view.show_line_numbers = true
30
+ lang = Gtk::SourceLanguageManager.new.get_language("ruby")
31
+ view.buffer.language = lang
32
+ view.buffer.highlight_syntax = true
33
+ view.buffer.highlight_matching_brackets = true
34
+ view.editable = false
35
+ # TODO: NoMethodError
36
+ #view.override_font(Pango::FontDescription.new("Monospace"))
37
+ widget = view
38
+ end
39
+ widget
40
+ end
41
+
42
+ def image?(file)
43
+ /\.(png|jpe?g|gif|ico|ani|bmp|pnm|ras|tga|tiff|xbm|xpm)\z/i =~ file
44
+ end
45
+
46
+ def video?(file)
47
+ /\.(ogm|mp4|flv|mpe?g2?|ts|mov|avi|divx|mkv|wmv|asf|wmx)\z/i =~ file
48
+ end
49
+
50
+ private
51
+ def buffer_from_file(file)
52
+ text = File.open(file).read
53
+ buffer_from_text(text)
54
+ end
55
+
56
+ def buffer_from_text(text)
57
+ raise Mireru2::Error unless text.valid_encoding?
58
+ text.encode!("utf-8") unless text.encoding == "utf-8"
59
+ buffer = Gtk::SourceBuffer.new
60
+ buffer.text = text
61
+ buffer
62
+ end
63
+
64
+ def sorry
65
+ image = Gtk::Image.new
66
+ base_dir = File.join(File.dirname(__FILE__), "..", "..")
67
+ images_dir = File.join(base_dir, "images")
68
+ image_path = File.expand_path(File.join(images_dir, "sorry.png"))
69
+ image.file = image_path
70
+ image
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,127 @@
1
+ require "gtk2"
2
+ require "mireru2/widget"
3
+ require "mireru2/thumbnail"
4
+
5
+ module Mireru2
6
+ class Window < Gtk::Window
7
+ attr_accessor :font
8
+ def initialize
9
+ super
10
+ @scroll = Gtk::ScrolledWindow.new
11
+ @scroll.set_policy(:automatic, :automatic)
12
+ self.add(@scroll)
13
+ self.set_default_size(640, 640)
14
+ self.signal_connect("destroy") do
15
+ Gtk.main_quit
16
+ end
17
+ end
18
+
19
+ def add_container(container)
20
+ @container = container
21
+
22
+ @file = @container.shift
23
+ self.add_from_file(@file)
24
+
25
+ self.signal_connect("key_press_event") do |w, e|
26
+ case e.keyval
27
+ when Gdk::Keyval::GDK_KEY_n
28
+ @file = @container.shift(@file)
29
+ self.add_from_file(@file)
30
+ when Gdk::Keyval::GDK_KEY_p
31
+ @file = @container.pop(@file)
32
+ self.add_from_file(@file)
33
+ when Gdk::Keyval::GDK_KEY_r
34
+ self.add_from_file(@file)
35
+ when Gdk::Keyval::GDK_KEY_e
36
+ self.title = File.expand_path(@file)
37
+ when Gdk::Keyval::GDK_KEY_f
38
+ if Mireru2::Widget.image?(@file)
39
+ pixbuf = Gdk::Pixbuf.new(@file, *self.size)
40
+ @widget.pixbuf = pixbuf
41
+ elsif @widget.is_a?(Gtk::TextView)
42
+ font = @widget.pango_context.families.sample.name
43
+ @widget.override_font(Pango::FontDescription.new(font))
44
+ self.title = "#{File.basename(@file)} (#{font})"
45
+ end
46
+ when Gdk::Keyval::GDK_KEY_o
47
+ if Mireru2::Widget.image?(@file)
48
+ pixbuf = Gdk::Pixbuf.new(@file)
49
+ @widget.pixbuf = pixbuf
50
+ end
51
+ when Gdk::Keyval::GDK_KEY_T
52
+ files = @container.instance_variable_get(:@files)
53
+ self.add_from_file(files)
54
+ when Gdk::Keyval::GDK_KEY_plus
55
+ if Mireru2::Widget.image?(@file)
56
+ width = @widget.pixbuf.width
57
+ height = @widget.pixbuf.height
58
+ scale = 1.1
59
+ pixbuf = Gdk::Pixbuf.new(@file,
60
+ width * scale,
61
+ height * scale)
62
+ @widget.pixbuf = pixbuf
63
+ elsif @widget.is_a?(Gtk::TextView)
64
+ font = @widget.pango_context.font_description.to_s
65
+ font_size = font.scan(/\d+\z/).first.to_i
66
+ font = font.sub(/\d+\z/, (font_size + 1).to_s)
67
+ @widget.override_font(Pango::FontDescription.new(font))
68
+ end
69
+ when Gdk::Keyval::GDK_KEY_minus
70
+ if Mireru2::Widget.image?(@file)
71
+ width = @widget.pixbuf.width
72
+ height = @widget.pixbuf.height
73
+ scale = 0.9
74
+ pixbuf = Gdk::Pixbuf.new(@file,
75
+ width * scale,
76
+ height * scale)
77
+ @widget.pixbuf = pixbuf
78
+ elsif @widget.is_a?(Gtk::TextView)
79
+ font = @widget.pango_context.font_description.to_s
80
+ font_size = font.scan(/\d+\z/).first.to_i
81
+ font = font.sub(/\d+\z/, (font_size - 1).to_s)
82
+ @widget.override_font(Pango::FontDescription.new(font))
83
+ end
84
+ when Gdk::Keyval::GDK_KEY_h
85
+ @scroll.hadjustment.value -= 17
86
+ when Gdk::Keyval::GDK_KEY_j
87
+ @scroll.vadjustment.value += 17
88
+ when Gdk::Keyval::GDK_KEY_k
89
+ @scroll.vadjustment.value -= 17
90
+ when Gdk::Keyval::GDK_KEY_l
91
+ @scroll.hadjustment.value += 17
92
+ when Gdk::Keyval::GDK_KEY_H
93
+ @scroll.hadjustment.value -= 1000000
94
+ when Gdk::Keyval::GDK_KEY_J, Gdk::Keyval::GDK_KEY_G
95
+ @scroll.vadjustment.value += 1000000
96
+ when Gdk::Keyval::GDK_KEY_K
97
+ @scroll.vadjustment.value -= 1000000
98
+ when Gdk::Keyval::GDK_KEY_L
99
+ @scroll.hadjustment.value += 1000000
100
+ when Gdk::Keyval::GDK_KEY_q
101
+ Gtk.main_quit
102
+ end
103
+ end
104
+ end
105
+
106
+ def add_from_file(file)
107
+ @scroll.hadjustment.value = 0
108
+ @scroll.vadjustment.value = 0
109
+ @scroll.each {|child| child.destroy }
110
+ if file.is_a?(Enumerable)
111
+ @widget = Mireru2::Thumbnail.create(file, *self.size)
112
+ self.title = "Thumbnails: #{file.size} / #{file.size}"
113
+ else
114
+ @widget = Mireru2::Widget.create(file, *self.size)
115
+ self.title = File.basename(file)
116
+ end
117
+ @widget.override_font(Pango::FontDescription.new(@font)) if @font
118
+ # TODO: improve condition
119
+ if @widget.is_a?(Gtk::TextView)
120
+ @scroll.add(@widget)
121
+ else
122
+ @scroll.add_with_viewport(@widget)
123
+ end
124
+ self.show_all
125
+ end
126
+ end
127
+ end
data/mireru2.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mireru2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mireru2"
8
+ spec.version = Mireru2::VERSION
9
+ spec.authors = ["Masafumi Yokoyama"]
10
+ spec.email = ["myokoym@gmail.com"]
11
+ spec.summary = %q{Flexible File Viewer Keyboard Friend}
12
+ spec.description = %q{A file viewer with a focus on flexibility by Ruby/GTK2. A friend of a keyboard.}
13
+ spec.homepage = "https://github.com/myokoym/mireru2"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency("gtk2")
22
+ spec.add_runtime_dependency("gtksourceview2")
23
+ # NOTE: Ruby/ClutterGTK is for Ruby/GTK3.
24
+ #spec.add_runtime_dependency("clutter-gtk")
25
+ #spec.add_runtime_dependency("clutter-gstreamer", "= 2.0.2")
26
+
27
+ spec.add_development_dependency("test-unit")
28
+ spec.add_development_dependency("test-unit-notify")
29
+ spec.add_development_dependency("test-unit-rr")
30
+ spec.add_development_dependency("bundler", "~> 1.3")
31
+ spec.add_development_dependency("rake")
32
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Masafumi Yokoyama
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Binary file
@@ -0,0 +1,35 @@
1
+ require 'cairo'
2
+
3
+ w = 400
4
+ h = 400
5
+
6
+ Cairo::ImageSurface.new(w, h) do |surface|
7
+ context = Cairo::Context.new(surface)
8
+
9
+ # 放射グラデーション
10
+ pattern = Cairo::RadialPattern.new(w/3, h/3, 330, w/3, h/3, 0)
11
+ start = 1.0
12
+ [:white,
13
+ :red,
14
+ :orange,
15
+ :yellow,
16
+ :green,
17
+ :aqua,
18
+ :blue,
19
+ :purple,
20
+ :black].each do |c|
21
+ pattern.add_color_stop(start -= 0.1, c)
22
+ end
23
+ context.set_source(pattern)
24
+
25
+ # 背景
26
+ #context.paint(0.1)
27
+
28
+ # 文字
29
+ context.select_font_face('Ubuntu')
30
+ context.move_to(60, 350)
31
+ context.font_size = 250
32
+ context.show_text("my")
33
+
34
+ surface.write_to_png("nijip.png")
35
+ end
File without changes
data/test/run-test.rb ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "test-unit"
4
+ require "test/unit/notify"
5
+ require "test/unit/rr"
6
+
7
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
8
+ $LOAD_PATH.unshift(File.join(base_dir, "lib"))
9
+ $LOAD_PATH.unshift(File.join(base_dir, "test"))
10
+
11
+ exit Test::Unit::AutoRunner.run(true)
@@ -0,0 +1,50 @@
1
+ require "mireru2/container"
2
+
3
+ class ContainerTest < Test::Unit::TestCase
4
+ def setup
5
+ @container = Mireru2::Container.new
6
+ end
7
+
8
+ def test_size
9
+ assert_equal(0, @container.size)
10
+ files = @container.instance_variable_get(:@files)
11
+ files << __FILE__
12
+ assert_equal(1, @container.size)
13
+ files << __FILE__
14
+ assert_equal(2, @container.size)
15
+ end
16
+
17
+ def test_no_argument
18
+ valid = @container.__send__(:file?, nil)
19
+ assert_false(valid)
20
+ end
21
+
22
+ def test_missing_file
23
+ valid = @container.__send__(:file?, "hoge")
24
+ assert_false(valid)
25
+ end
26
+
27
+ def test_no_extention_file_type
28
+ file = File.join(File.dirname(__FILE__), "fixtures", "no-extention")
29
+ valid = @container.__send__(:file?, file)
30
+ assert_true(valid)
31
+ end
32
+
33
+ def test_png_file
34
+ file = File.join(File.dirname(__FILE__), "fixtures", "nijip.png")
35
+ valid = @container.__send__(:file?, file)
36
+ assert_true(valid)
37
+ end
38
+
39
+ def test_txt_file
40
+ file = File.join(File.dirname(__FILE__), "fixtures", "LICENSE.txt")
41
+ valid = @container.__send__(:file?, file)
42
+ assert_true(valid)
43
+ end
44
+
45
+ def test_rb_file
46
+ file = File.join(File.dirname(__FILE__), "fixtures", "nijip.rb")
47
+ valid = @container.__send__(:file?, file)
48
+ assert_true(valid)
49
+ end
50
+ end
@@ -0,0 +1,39 @@
1
+ require "mireru2/logger"
2
+ require "stringio"
3
+
4
+ class LoggerTest < Test::Unit::TestCase
5
+ def setup
6
+ @logger = Mireru2::Logger.new
7
+ end
8
+
9
+ def test_info
10
+ s = ""
11
+ io = StringIO.new(s)
12
+ $stdout = io
13
+ message = <<-EOM
14
+ #{Mireru2::Command::Mireru2::USAGE}
15
+ If no argument, then search current directory.
16
+ Keybind:
17
+ n: next
18
+ p: prev
19
+ q: quit
20
+ EOM
21
+ @logger.info(message)
22
+ $stdout = STDOUT
23
+ assert_equal(message, s)
24
+ end
25
+
26
+ def test_error
27
+ s = ""
28
+ io = StringIO.new(s)
29
+ $stderr = io
30
+ message = <<-EOM
31
+ Warning: valid file not found.
32
+ #{Mireru2::Command::Mireru2::USAGE}
33
+ Support file types: png, gif, jpeg(jpg). The others are...yet.
34
+ EOM
35
+ @logger.error(message)
36
+ $stderr = STDERR
37
+ assert_equal(message, s)
38
+ end
39
+ end
@@ -0,0 +1,101 @@
1
+ require "mireru2/command/mireru2"
2
+ require "mireru2/container"
3
+
4
+ class Mireru2Test < Test::Unit::TestCase
5
+ def setup
6
+ @mireru2 = Mireru2::Command::Mireru2.new
7
+ end
8
+
9
+ def test_run_help_option
10
+ arguments = %w(--help)
11
+ mock(@mireru2).write_help_message
12
+ assert_raise SystemExit do
13
+ @mireru2.run(arguments)
14
+ end
15
+ end
16
+
17
+ def test_run_help_option_sugar
18
+ arguments = %w(-h)
19
+ mock(@mireru2).write_help_message
20
+ assert_raise SystemExit do
21
+ @mireru2.run(arguments)
22
+ end
23
+ end
24
+
25
+ def test_run_version_option
26
+ arguments = %w(--version)
27
+ mock(@mireru2).write_version_message
28
+ assert_raise SystemExit do
29
+ @mireru2.run(arguments)
30
+ end
31
+ end
32
+
33
+ def test_run_empty
34
+ arguments = %w(hoge)
35
+ stub(@mireru2).files_from_arguments { arguments }
36
+ mock.instance_of(Mireru2::Container).empty? { true }
37
+ mock(@mireru2).write_empty_message
38
+ assert_raise SystemExit do
39
+ @mireru2.run(arguments)
40
+ end
41
+ end
42
+
43
+ def test_files_from_arguments_no_argument
44
+ arguments = %w()
45
+ expected = %w(dir1 file1 dir2)
46
+ mock(Dir).glob("*") { expected }
47
+ files = @mireru2.__send__(:files_from_arguments, arguments)
48
+ assert_equal(files, expected)
49
+ end
50
+
51
+ def test_files_from_arguments_recursive_option_only
52
+ arguments = %w(-R)
53
+ expected = %w(dir1 file1 dir2 dir1/file1 dir1/file2 dir2/file1)
54
+ mock(Dir).glob("**/*") { expected }
55
+ files = @mireru2.__send__(:files_from_arguments, arguments)
56
+ assert_equal(files, expected)
57
+ end
58
+
59
+ def test_files_from_arguments_recursive_option_and_dir
60
+ arguments = %w(-R dir1 file1 dir2)
61
+ expected_dir1 = %w(dir1/file1 dir1/file2)
62
+ expected_dir2 = %w(dir2/file1)
63
+ expected = [expected_dir1, "file1", expected_dir2].flatten
64
+ mock(File).directory?("dir1") { true }
65
+ mock(File).directory?("file1") { false }
66
+ mock(File).directory?("dir2") { true }
67
+ mock(Dir).glob("dir1/**/*") { expected_dir1 }
68
+ mock(Dir).glob("dir2/**/*") { expected_dir2 }
69
+ files = @mireru2.__send__(:files_from_arguments, arguments)
70
+ assert_equal(files, expected)
71
+ end
72
+
73
+ def test_files_from_arguments_all_dir
74
+ arguments = %w(dir1 dir2)
75
+ expected_dir1 = %w(dir1/file1 dir1/file2)
76
+ expected_dir2 = %w(dir2/file1)
77
+ expected = [expected_dir1, expected_dir2].flatten
78
+ mock(File).directory?("dir1") { true }
79
+ mock(File).directory?("dir2") { true }
80
+ mock(Dir).glob("dir1/*") { expected_dir1 }
81
+ mock(Dir).glob("dir2/*") { expected_dir2 }
82
+ files = @mireru2.__send__(:files_from_arguments, arguments)
83
+ assert_equal(files, expected)
84
+ end
85
+
86
+ def test_files_from_arguments_else
87
+ arguments = %w(dir1 file1 dir2)
88
+ files = @mireru2.__send__(:files_from_arguments, arguments)
89
+ assert_equal(files, arguments)
90
+ end
91
+
92
+ def test_purge_option
93
+ arguments = %w(-R -f ubuntu dir1 file1 dir2)
94
+ flag = @mireru2.__send__(:purge_option, arguments, /\A(-R|--recursive)\z/)
95
+ assert_not_nil(flag)
96
+ assert_equal(%w(-f ubuntu dir1 file1 dir2), arguments)
97
+ value = @mireru2.__send__(:purge_option, arguments, /\A-f\z/, true)
98
+ assert_equal("ubuntu", value)
99
+ assert_equal(%w(dir1 file1 dir2), arguments)
100
+ end
101
+ end
@@ -0,0 +1,15 @@
1
+ require "mireru2/thumbnail"
2
+
3
+ class ThumbnailTest < Test::Unit::TestCase
4
+ def test_image_from_file
5
+ widget = Mireru2::Thumbnail.__send__(:image_from_file,
6
+ "test/fixtures/nijip.png")
7
+ assert_equal(Gtk::Image, widget.class)
8
+ end
9
+
10
+ def test_label_from_fil
11
+ widget = Mireru2::Thumbnail.__send__(:label_from_file,
12
+ __FILE__)
13
+ assert_equal(Gtk::Label, widget.class)
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # NOTE: Ruby/ClutterGTK is for Ruby/GTK3.
2
+ =begin
3
+ require "mireru2/video"
4
+ require "clutter-gtk"
5
+
6
+ class VideoTest < Test::Unit::TestCase
7
+ def test_create
8
+ filename = "XXX.ogm"
9
+ widget = Mireru2::Video.create(filename)
10
+ assert_not_nil(widget)
11
+ assert_equal(ClutterGtk::Embed, widget.class)
12
+ widget.destroy
13
+ end
14
+ end
15
+ =end
@@ -0,0 +1,33 @@
1
+ require "mireru2/widget"
2
+
3
+ class WidgetTest < Test::Unit::TestCase
4
+ def test_image?
5
+ assert_nil(Mireru2::Widget.image?(__FILE__))
6
+ assert_not_nil(Mireru2::Widget.image?("test/fixtures/nijip.png"))
7
+ assert_not_nil(Mireru2::Widget.image?("hoge.PNG"))
8
+ assert_not_nil(Mireru2::Widget.image?("hoge.jpg"))
9
+ assert_not_nil(Mireru2::Widget.image?("hoge.jpeg"))
10
+ assert_not_nil(Mireru2::Widget.image?("hoge.gif"))
11
+ end
12
+
13
+ def test_buffer_from_file_of_text
14
+ widget = Mireru2::Widget.__send__(:buffer_from_file, __FILE__)
15
+ assert_equal(Gtk::SourceBuffer, widget.class)
16
+ end
17
+
18
+ def test_buffer_from_file_of_binary
19
+ assert_raise Mireru2::Error do
20
+ Mireru2::Widget.__send__(:buffer_from_file, "test/fixtures/nijip.png")
21
+ end
22
+ end
23
+
24
+ def test_buffer_from_text_of_utf8
25
+ widget = Mireru2::Widget.__send__(:buffer_from_text, "御庭番")
26
+ assert_equal(Gtk::SourceBuffer, widget.class)
27
+ end
28
+
29
+ def test_buffer_from_text_of_sjis
30
+ widget = Mireru2::Widget.__send__(:buffer_from_text, "御庭番".encode("SJIS"))
31
+ assert_equal(Gtk::SourceBuffer, widget.class)
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ require "mireru2/window"
2
+
3
+ class WindowTest < Test::Unit::TestCase
4
+ def setup
5
+ @window = Mireru2::Window.new
6
+ end
7
+
8
+ def test_add_container
9
+ container = %w(a, b, c)
10
+ mock(container).shift { "a" }
11
+ mock(@window).add_from_file("a")
12
+ @window.add_container(container)
13
+ end
14
+
15
+ def test_add_from_file_of_scrollable
16
+ file = __FILE__
17
+ mock(Mireru2::Widget).create(file, *@window.size) do
18
+ Gtk::TextView.new
19
+ end
20
+ mock(@window).show_all
21
+ @window.add_from_file(file)
22
+ assert_equal(Gtk::ScrolledWindow, @window.child.class)
23
+ assert_equal(Gtk::TextView, @window.child.child.class)
24
+ end
25
+
26
+ def test_add_from_file_of_no_scrollable
27
+ file = "fixtures/nijip.png"
28
+ mock(Mireru2::Widget).create(file, *@window.size) do
29
+ Gtk::Image.new
30
+ end
31
+ mock(@window).show_all
32
+ @window.add_from_file(file)
33
+ assert_equal(Gtk::ScrolledWindow, @window.child.class)
34
+ assert_equal(Gtk::Viewport, @window.child.child.class)
35
+ assert_equal(Gtk::Image, @window.child.child.child.class)
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mireru2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masafumi Yokoyama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gtk2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gtksourceview2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit-notify
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit-rr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A file viewer with a focus on flexibility by Ruby/GTK2. A friend of a
112
+ keyboard.
113
+ email:
114
+ - myokoym@gmail.com
115
+ executables:
116
+ - mireru2
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - .gitignore
121
+ - .travis.yml
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - NEWS.md
125
+ - README.md
126
+ - Rakefile
127
+ - bin/mireru2
128
+ - images/sorry.png
129
+ - lib/mireru2.rb
130
+ - lib/mireru2/command/mireru2.rb
131
+ - lib/mireru2/container.rb
132
+ - lib/mireru2/logger.rb
133
+ - lib/mireru2/thumbnail.rb
134
+ - lib/mireru2/version.rb
135
+ - lib/mireru2/video.rb
136
+ - lib/mireru2/widget.rb
137
+ - lib/mireru2/window.rb
138
+ - mireru2.gemspec
139
+ - test/fixtures/LICENSE.txt
140
+ - test/fixtures/nijip.png
141
+ - test/fixtures/nijip.rb
142
+ - test/fixtures/no-extention
143
+ - test/run-test.rb
144
+ - test/test-container.rb
145
+ - test/test-logger.rb
146
+ - test/test-mireru.rb
147
+ - test/test-thumbnail.rb
148
+ - test/test-video.rb
149
+ - test/test-widget.rb
150
+ - test/test-window.rb
151
+ homepage: https://github.com/myokoym/mireru2
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.0.3
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Flexible File Viewer Keyboard Friend
175
+ test_files:
176
+ - test/fixtures/LICENSE.txt
177
+ - test/fixtures/nijip.png
178
+ - test/fixtures/nijip.rb
179
+ - test/fixtures/no-extention
180
+ - test/run-test.rb
181
+ - test/test-container.rb
182
+ - test/test-logger.rb
183
+ - test/test-mireru.rb
184
+ - test/test-thumbnail.rb
185
+ - test/test-video.rb
186
+ - test/test-widget.rb
187
+ - test/test-window.rb
188
+ has_rdoc: