phew 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76bdc848ba00cbe93dcbd8bd4f18255af08e7b11eb35704404a4e80fe9d3d06a
4
- data.tar.gz: a15961a04d5673672b9d3deec4f58e9ec559a9c925b2608648def511249aab82
3
+ metadata.gz: cff9393daf26cbbd2eb966bbb810a5218cdba85c5a97d06837e92ff7e8554ba3
4
+ data.tar.gz: 65083fa7e4189889205a70d61fc3824ae0f2eb62ec5cf31bcb61444f3ecc5bf3
5
5
  SHA512:
6
- metadata.gz: 6999d0de88e2e3feae5d92d7556821dbeff21f3fbb3968ab698a0f28611f0d098ef03414d3d8691761cd748300af5495812afcb4161ada42d05df4426df0933d
7
- data.tar.gz: fc76fd22022ef3883ffae54df23e0a207c3d836de672a47def2204e3d3e48a5032e759945c082b3fafce5dbbaea7aec8b0cf9e3af61492411958bfdf63e3d40f
6
+ metadata.gz: 5ef231b206e5d251169dc0a3b0fc9f4de004cf5f512a13d3c761c5537bb431425c824bbd237ca9df1bafcc729989ff5e1e4c8ed8f7a37830c53ff927ca46f18a
7
+ data.tar.gz: 3cdfa3b3c0af96afed9edc88bc4f9fdf78c94403b7cd7a541899fea9cb24589a00c9cdde4def70ba0fbbd25d96267a49f64f54ceafb11a07dc7e19baa71e4197
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  # The gem's dependencies are specified in the gemspec
6
6
  gemspec
data/Rakefile CHANGED
@@ -1,27 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rake/clean'
4
- require 'bundler/gem_helper'
5
- require 'rake/testtask'
3
+ require "rake/clean"
4
+ require "bundler/gem_helper"
5
+ require "rake/testtask"
6
6
 
7
7
  Bundler::GemHelper.install_tasks
8
8
 
9
9
  namespace :test do
10
10
  Rake::TestTask.new(:unit) do |t|
11
- t.libs = ['lib']
12
- t.test_files = FileList['test/**/*_test.rb']
11
+ t.libs = ["lib"]
12
+ t.test_files = FileList["test/**/*_test.rb"]
13
13
  t.warning = true
14
14
  end
15
15
 
16
16
  Rake::TestTask.new(:features) do |t|
17
- t.libs = ['lib']
18
- t.test_files = FileList['features/**/*_test.rb']
17
+ t.libs = ["lib"]
18
+ t.test_files = FileList["features/**/*_test.rb"]
19
19
  t.warning = true
20
20
  end
21
21
 
22
22
  task all: [:unit, :features]
23
23
  end
24
24
 
25
- task test: 'test:all'
25
+ task test: "test:all"
26
26
 
27
- task default: 'test'
27
+ task default: "test"
data/bin/phew CHANGED
@@ -1,147 +1,29 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'phew'
4
+ require "phew"
5
5
 
6
- Gtk.init
6
+ myapp = Gtk::Application.new("net.matijs.phew", { none: true })
7
7
 
8
- module Phew
9
- # Drop-down list of available scripts.
10
- class ScriptList < Gtk::ComboBoxText
11
- # FIXME: Should be able to fill inside #initialize
12
- def fill
13
- Pango::Script::Enum.symbols.
14
- map(&:to_s).
15
- each { |str| append str, str }
16
- end
17
- end
8
+ myapp.signal_connect "startup" do |app|
9
+ action = Gio::SimpleAction.new("quit", nil)
10
+ action.signal_connect("activate") { app.quit }
11
+ myapp.add_action action
18
12
 
19
- # Main Phew window
20
- class Window < Gtk::Window
21
- # Set up generic signal handlers for the window:
22
- # - Closing the window ends the application
23
- # - Pressing Ctrl-Q closes the window.
24
- def connect_signals
25
- signal_connect('destroy') { on_destroy_event }
26
- signal_connect('key-press-event') { |_, evt, _| on_key_press_event evt }
27
- end
13
+ myapp.set_accels_for_action "app.quit", ["<Ctrl>Q"]
28
14
 
29
- def on_destroy_event
30
- Gtk.main_quit
31
- false
32
- end
15
+ # Add menu so Atspi has a way to access the actions
16
+ menu = Gio::Menu.new
17
+ file_menu = Gio::Menu.new
18
+ file_menu.append "Quit", "app.quit"
19
+ menu.append_submenu "File", file_menu
33
20
 
34
- def on_key_press_event(evt)
35
- destroy if evt.state[:control_mask] && evt.keyval == 'q'.ord
36
- false
37
- end
38
- end
39
-
40
- # Main Phew application.
41
- class Application
42
- def combo
43
- @combo ||= ScriptList.new.tap(&:fill)
44
- end
45
-
46
- def textview
47
- @textview ||= Gtk::TextView.new
48
- end
49
-
50
- def build_vbox
51
- vbox = Gtk::VBox.new false, 0
52
-
53
- vbox.pack_start combo, false, false, 0
54
- vbox.pack_start textview, false, false, 0
55
- vbox.pack_start script_list_scroller, true, true, 0
56
- vbox
57
- end
58
-
59
- def vbox
60
- @vbox ||= build_vbox
61
- end
62
-
63
- def script_list_scroller
64
- @script_list_scroller ||= Gtk::ScrolledWindow.new(nil, nil).tap do |scr|
65
- lst = script_list
66
- scr.add lst
67
- lst.hadjustment = scr.hadjustment
68
- lst.vadjustment = scr.vadjustment
69
- end
70
- end
71
-
72
- def script_list
73
- @script_list ||= Gtk::TreeView.new_with_model(scriptmodel).tap do |view|
74
- renderer = Gtk::CellRendererText.new
75
- col = Gtk::TreeViewColumn.new
76
- col.set_title 'Font Name'
77
- col.pack_start renderer, true
78
- col.add_attribute renderer, 'text', 0
79
- view.append_column col
80
- end
81
- end
82
-
83
- def scriptmodel
84
- @scriptmodel ||= Gtk::ListStore.new [GObject::TYPE_STRING]
85
- end
86
-
87
- def build_win
88
- win = Window.new :toplevel
89
- win.add vbox
90
- win
91
- end
92
-
93
- def win
94
- @win ||= build_win
95
- end
96
-
97
- # Set up all signal handlers
98
- def connect_signals
99
- win.connect_signals
100
- combo.signal_connect('changed') { on_combo_changed_signal }
101
- end
102
-
103
- def on_combo_changed_signal
104
- script = Script.new combo.active_text.to_sym
105
- # FIXME: Add override for Gtk::TextBuffer.set_text so #text= works properly
106
- textview.buffer.set_text script.sample_string, -1
107
- fill_font_list script
108
- end
109
-
110
- def initialize
111
- @context = Gdk.pango_context_get
112
- @font_repository = FontRepository.new @context
113
- connect_signals
114
- win.show_all
115
- end
116
-
117
- def fill_font_list(script)
118
- scriptmodel.clear
119
-
120
- font_families.each do |fam|
121
- font = @font_repository.get_font fam.name
122
-
123
- if sample_coverage(font, script) == :exact
124
- row = scriptmodel.append
125
- scriptmodel.set_value row, 0, fam.name
126
- end
127
- end
128
- end
129
-
130
- def sample_coverage(font, script)
131
- sample_cov = font.coverage_summary script.sample_string
132
- [:none, :fallback, :approximate, :exact].max_by { |i| sample_cov[i] }
133
- end
134
-
135
- def font_families
136
- fontmap = @context.get_font_map
137
-
138
- fontmap.list_families
139
- end
21
+ myapp.menubar = menu
22
+ end
140
23
 
141
- def run
142
- Gtk.main
143
- end
144
- end
24
+ myapp.signal_connect "activate" do |app, _user_data|
25
+ @app ||= Phew::Application.new(app)
26
+ @app.present
145
27
  end
146
28
 
147
- Phew::Application.new.run
29
+ exit(myapp.run([$PROGRAM_NAME] + ARGV))
@@ -1,8 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'gir_ffi-gtk3'
4
- require 'gir_ffi-pango'
5
-
6
- require 'phew/script'
7
- require 'phew/font'
8
- require 'phew/font_repository'
3
+ require "phew/application"
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "gir_ffi-gtk3"
4
+
5
+ require "phew/font_repository"
6
+ require "phew/script"
7
+ require "phew/script_list"
8
+
9
+ module Phew
10
+ # Main Phew application.
11
+ class Application
12
+ def initialize(gtk_application)
13
+ @gtk_application = gtk_application
14
+ @context = Gdk.pango_context_get
15
+ @font_repository = FontRepository.new @context
16
+ connect_signals
17
+ end
18
+
19
+ def present
20
+ win.show_all
21
+ win.children.first.visible = false if win.show_menubar
22
+ win.present
23
+ end
24
+
25
+ private
26
+
27
+ def combo
28
+ @combo ||= ScriptList.new.tap(&:fill)
29
+ end
30
+
31
+ def textview
32
+ @textview ||= Gtk::TextView.new
33
+ end
34
+
35
+ def build_vbox
36
+ vbox = Gtk::VBox.new false, 0
37
+
38
+ vbox.pack_start combo, false, false, 0
39
+ vbox.pack_start textview, false, false, 0
40
+ vbox.pack_start script_list_scroller, true, true, 0
41
+ vbox
42
+ end
43
+
44
+ def vbox
45
+ @vbox ||= build_vbox
46
+ end
47
+
48
+ def script_list_scroller
49
+ @script_list_scroller ||= Gtk::ScrolledWindow.new(nil, nil).tap do |scr|
50
+ lst = script_list
51
+ scr.add lst
52
+ lst.hadjustment = scr.hadjustment
53
+ lst.vadjustment = scr.vadjustment
54
+ end
55
+ end
56
+
57
+ def script_list
58
+ @script_list ||= Gtk::TreeView.new_with_model(scriptmodel).tap do |view|
59
+ renderer = Gtk::CellRendererText.new
60
+ col = Gtk::TreeViewColumn.new
61
+ col.set_title "Font Name"
62
+ col.pack_start renderer, true
63
+ col.add_attribute renderer, "text", 0
64
+ view.append_column col
65
+ end
66
+ end
67
+
68
+ def scriptmodel
69
+ @scriptmodel ||= Gtk::ListStore.new [GObject::TYPE_STRING]
70
+ end
71
+
72
+ def build_win
73
+ win = Gtk::ApplicationWindow.new @gtk_application
74
+ win.add vbox
75
+ win
76
+ end
77
+
78
+ def win
79
+ @win ||= build_win
80
+ end
81
+
82
+ # Set up all signal handlers
83
+ def connect_signals
84
+ combo.signal_connect("changed") { on_combo_changed_signal }
85
+ end
86
+
87
+ def on_combo_changed_signal
88
+ script = Script.new combo.active_text.to_sym
89
+ # FIXME: Add override for Gtk::TextBuffer.set_text so #text= works properly
90
+ textview.buffer.set_text script.sample_string, -1
91
+ fill_font_list script
92
+ end
93
+
94
+ def fill_font_list(script)
95
+ scriptmodel.clear
96
+
97
+ font_families.each do |fam|
98
+ font = @font_repository.get_font fam.name
99
+
100
+ if sample_coverage(font, script) == :exact
101
+ row = scriptmodel.append
102
+ scriptmodel.set_value row, 0, fam.name
103
+ end
104
+ end
105
+ end
106
+
107
+ def sample_coverage(font, script)
108
+ sample_cov = font.coverage_summary script.sample_string
109
+ [:none, :fallback, :approximate, :exact].max_by { |i| sample_cov[i] }
110
+ end
111
+
112
+ def font_families
113
+ fontmap = @context.get_font_map
114
+
115
+ fontmap.list_families
116
+ end
117
+ end
118
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "gir_ffi-pango"
4
+
3
5
  module Phew
4
6
  # Font family. Handles coverage, among other things.
5
7
  class Font
@@ -10,6 +12,7 @@ module Phew
10
12
  # @param [String] text_description Description of the font to create.
11
13
  def initialize(context, text_description)
12
14
  fd = Pango::FontDescription.from_string text_description
15
+ fd.size = 10
13
16
  fontmap = context.get_font_map
14
17
  @font = fontmap.load_font context, fd
15
18
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "phew/font"
4
+
3
5
  module Phew
4
6
  # Cache for font information retrieved from a Pango context
5
7
  class FontRepository
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "gir_ffi-pango"
4
+
3
5
  module Phew
4
6
  # A script.
5
7
  class Script
@@ -11,7 +13,7 @@ module Phew
11
13
 
12
14
  def sample_string
13
15
  if @lang.nil?
14
- 'No sample available'
16
+ "No sample available"
15
17
  else
16
18
  @lang.get_sample_string
17
19
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "gir_ffi-gtk3"
4
+ require "gir_ffi-pango"
5
+
6
+ module Phew
7
+ # Drop-down list of available scripts.
8
+ class ScriptList < Gtk::ComboBoxText
9
+ # FIXME: Should be able to fill inside #initialize
10
+ def fill
11
+ Pango::Script::Enum.symbols
12
+ .map(&:to_s)
13
+ .each { |str| append str, str }
14
+ end
15
+ end
16
+ end
@@ -1,22 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../test_helper'
3
+ require_relative "../test_helper"
4
4
 
5
5
  describe Phew::FontRepository do
6
- describe '#get_font' do
7
- it 'returns an instance of Phew::Font' do
6
+ describe "#get_font" do
7
+ it "returns an instance of Phew::Font" do
8
8
  ctx = Gdk.pango_context_get
9
9
  repo = Phew::FontRepository.new ctx
10
- font = repo.get_font 'Sans'
11
- font.must_be_instance_of Phew::Font
10
+ font = repo.get_font "Sans"
11
+ _(font).must_be_instance_of Phew::Font
12
12
  end
13
13
 
14
- it 'returns the same object if called again with the same description' do
14
+ it "returns the same object if called again with the same description" do
15
15
  ctx = Gdk.pango_context_get
16
16
  repo = Phew::FontRepository.new ctx
17
- font = repo.get_font 'Sans'
18
- font_again = repo.get_font 'Sans'
19
- font_again.must_be_same_as font
17
+ font = repo.get_font "Sans"
18
+ font_again = repo.get_font "Sans"
19
+ _(font_again).must_be_same_as font
20
20
  end
21
21
  end
22
22
  end
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../test_helper'
3
+ require_relative "../test_helper"
4
4
 
5
5
  describe Phew::Font do
6
- describe '#coverage_summary' do
7
- it 'returns summarized coverage information for the given string' do
6
+ describe "#coverage_summary" do
7
+ it "returns summarized coverage information for the given string" do
8
8
  ctx = Gdk.pango_context_get
9
9
 
10
- pfont = Phew::Font.new ctx, 'Sans'
10
+ pfont = Phew::Font.new ctx, "Sans"
11
11
 
12
- test_string = 'This is a test'
13
- sum = pfont.coverage_summary test_string
12
+ test_string = "This is a test"
13
+ summary = pfont.coverage_summary test_string
14
14
 
15
- sum.keys.sort.must_equal [:none, :fallback, :approximate, :exact].sort
16
- sum.values.inject(:+).must_equal test_string.size
15
+ _(summary.keys.sort).must_equal [:none, :fallback, :approximate, :exact].sort
16
+ _(summary.values.sum).must_equal test_string.size
17
17
  end
18
18
  end
19
19
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'minitest/autorun'
3
+ require "minitest/autorun"
4
4
 
5
- require 'phew'
5
+ require "phew"
6
6
 
7
7
  # Gtk must be initialized for all the font retrieval methods to work.
8
8
  Gtk.init
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phew
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matijs van Zuijlen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-25 00:00:00.000000000 Z
11
+ date: 2021-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gir_ffi-gtk
@@ -16,70 +16,126 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.12.0
19
+ version: 0.15.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.12.0
26
+ version: 0.15.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: gir_ffi-pango
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.10
33
+ version: 0.0.14
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.10
40
+ version: 0.0.14
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: atspi_app_driver
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.3.0
47
+ version: 0.7.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.3.0
54
+ version: 0.7.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '5.5'
61
+ version: '5.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.13.0
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '5.5'
82
+ version: 0.13.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '12.0'
89
+ version: '13.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '13.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.8.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.8.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.10.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.10.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-performance
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.9.1
76
132
  type: :development
77
133
  prerelease: false
78
134
  version_requirements: !ruby/object:Gem::Requirement
79
135
  requirements:
80
136
  - - "~>"
81
137
  - !ruby/object:Gem::Version
82
- version: '12.0'
138
+ version: 1.9.1
83
139
  description: List and compare installed fonts on GNOME
84
140
  email:
85
141
  - matijs@matijs.net
@@ -100,9 +156,11 @@ files:
100
156
  - doc/prior-art.md
101
157
  - doc/waterfall.png
102
158
  - lib/phew.rb
159
+ - lib/phew/application.rb
103
160
  - lib/phew/font.rb
104
161
  - lib/phew/font_repository.rb
105
162
  - lib/phew/script.rb
163
+ - lib/phew/script_list.rb
106
164
  - test/phew/font_repository_test.rb
107
165
  - test/phew/font_test.rb
108
166
  - test/test_helper.rb
@@ -110,7 +168,7 @@ homepage: http://www.github.com/mvz/phew-font-viewer
110
168
  licenses:
111
169
  - GPL-3
112
170
  metadata: {}
113
- post_install_message:
171
+ post_install_message:
114
172
  rdoc_options:
115
173
  - "--main"
116
174
  - README.md
@@ -121,16 +179,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
179
  requirements:
122
180
  - - ">="
123
181
  - !ruby/object:Gem::Version
124
- version: 2.3.0
182
+ version: 2.5.0
125
183
  required_rubygems_version: !ruby/object:Gem::Requirement
126
184
  requirements:
127
185
  - - ">="
128
186
  - !ruby/object:Gem::Version
129
187
  version: '0'
130
188
  requirements: []
131
- rubyforge_project:
132
- rubygems_version: 2.7.6
133
- signing_key:
189
+ rubygems_version: 3.2.3
190
+ signing_key:
134
191
  specification_version: 4
135
192
  summary: A GNOME Font Viewer
136
193
  test_files: []