groonga-database-viewer-gtk 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 1fda9b07864087f8a3d2c871764520900aa608ba
4
- data.tar.gz: 53596509c98d1ee9cca7a79feee50445a8f4f24d
3
+ metadata.gz: 9a123ff921e425f0c0c97ba55f8f92c05c04d45b
4
+ data.tar.gz: 7aafad21070d426840271ffb2621641f10e1d172
5
5
  SHA512:
6
- metadata.gz: 3460cf8e7d0b9843f3d9bf2695b549011cba95dd08055fa43d37f4e0e7c2aa17ca6eeb1260ef7565164dbc081581df8f3046a7d1f57e253245d9251fb994fac0
7
- data.tar.gz: f6c08d4c8d7f785c734b83e2823b558dfcd3cf81bf98e57101380701e9796c1dfd1882e6d6bfae84363d9caf3993068dade718b8b563c9a88aa53b4f55a3417a
6
+ metadata.gz: 305720b3522cc67da8a962388a9aafd0afe607b23abcaaeed99d0f3525c780bf4d3a4b7bcaeb5a7733e868692541fc009c9875a56bd25766c577abad6916b7a2
7
+ data.tar.gz: f3ca5901a8172848aa7e9f37e2cc4c01f57b055f33f4715e78ecc4038c393e35c290c1cdc92cbfb637eee559ad35e222d434aad0cffe24b48c4cd3a51bd6fcf5
data/NEWS.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # NEWS
2
2
 
3
+ ## 0.0.2: 2014-10-01
4
+
5
+ ### Changes
6
+
7
+ * Improvements
8
+ * Set a limit to "100" as default
9
+ * Support raw query search
10
+ * Set title to window
11
+
3
12
  ## 0.0.1: 2014-08-05
4
13
 
5
14
  Initial release!
@@ -14,5 +14,5 @@
14
14
  # License along with this library; if not, write to the Free Software
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
- require "groonga/database_viewer_gtk/version"
18
- require "groonga/database_viewer_gtk/window"
17
+ require "groonga/database-viewer-gtk/version"
18
+ require "groonga/database-viewer-gtk/window"
@@ -0,0 +1,125 @@
1
+ # Copyright (C) 2014 Masafumi Yokoyama <myokoym@gmail.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "groonga"
18
+ require "gtk2"
19
+
20
+ module Groonga
21
+ module DatabaseViewerGtk
22
+ class Table < Gtk::TreeView
23
+ ID_COLUMN_INDEX = 0
24
+ KEY_COLUMN_INDEX = 1
25
+
26
+ attr_reader :updated
27
+ attr_reader :grn_table
28
+
29
+ def initialize(grn_table, db_path)
30
+ super()
31
+ @grn_table = grn_table
32
+ @db_path = db_path
33
+ @updated = false
34
+ @threads = []
35
+ signal_connect("destroy") do
36
+ @threads.each do |thread|
37
+ thread.kill
38
+ end
39
+ end
40
+ create_tree_view
41
+ end
42
+
43
+ def create_tree_view
44
+ self.rules_hint = true
45
+
46
+ create_column("_id", ID_COLUMN_INDEX)
47
+ create_column("_key", KEY_COLUMN_INDEX)
48
+
49
+ @grn_table.columns.each_with_index do |grn_column, i|
50
+ create_column(grn_column.local_name, i + 2)
51
+ end
52
+ end
53
+
54
+ def create_column(name, index)
55
+ gtk_column = Gtk::TreeViewColumn.new
56
+ gtk_column.title = name.gsub(/_/, "__")
57
+ gtk_column.resizable = true
58
+ gtk_column.set_sort_column_id(index)
59
+ append_column(gtk_column)
60
+
61
+ renderer = Gtk::CellRendererText.new
62
+ gtk_column.pack_start(renderer, :expand => false)
63
+ gtk_column.add_attribute(renderer, :text, index)
64
+ end
65
+
66
+ def update_model(limit, query=nil)
67
+ @threads.reject! do |thread|
68
+ thread.kill
69
+ true
70
+ end
71
+
72
+ column_types = @grn_table.columns.collect do |column|
73
+ # TODO
74
+ String
75
+ end
76
+ column_types.unshift(String) # _key
77
+ column_types.unshift(Integer) # _id
78
+
79
+ model = Gtk::ListStore.new(*column_types)
80
+ self.model = model
81
+
82
+ thread = Thread.new do
83
+ each_records(limit, query).each do |grn_record|
84
+ load_record(model, grn_record)
85
+ end
86
+ end
87
+ @threads << thread
88
+
89
+ @updated = true
90
+ end
91
+
92
+ def load_record(model, grn_record)
93
+ iter = model.append
94
+ iter.set_value(ID_COLUMN_INDEX, grn_record._id)
95
+ iter.set_value(KEY_COLUMN_INDEX, grn_record._key) if grn_record.respond_to?(:_key)
96
+ @grn_table.columns.each_with_index do |grn_column, i|
97
+ value = grn_record[grn_column.local_name]
98
+ iter.set_value(i + 2, value.to_s)
99
+ if grn_column.index?
100
+ ids = grn_column.search(grn_record._id).records.collect {|record| record._id}
101
+ value = "#{ids.size}, #{ids.to_s}"
102
+ else
103
+ value = grn_record[grn_column.local_name].to_s
104
+ end
105
+ iter.set_value(2 + i, value)
106
+ GC.start if i % 100 == 0
107
+ end
108
+ end
109
+
110
+ def each_records(limit, query=nil)
111
+ grn_records = Groonga[@grn_table.name]
112
+ if query
113
+ grn_records = grn_records.select(query)
114
+ end
115
+ if block_given?
116
+ grn_records.take(limit).each do |grn_record|
117
+ yield(grn_record)
118
+ end
119
+ else
120
+ grn_records.take(limit)
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Groonga
18
18
  module DatabaseViewerGtk
19
- VERSION = "0.0.1"
19
+ VERSION = "0.0.2"
20
20
  end
21
21
  end
@@ -17,11 +17,16 @@
17
17
  require "groonga"
18
18
  require "gtk2"
19
19
 
20
+ require "groonga/database-viewer-gtk/table"
21
+
20
22
  module Groonga
21
23
  module DatabaseViewerGtk
22
24
  class Window < Gtk::Window
25
+ RAW_QUERY_MODE = "--query"
26
+
23
27
  def initialize(db_path)
24
28
  super()
29
+ self.title = db_path
25
30
  set_default_size(640, 480)
26
31
  @grn_database = Database.open(db_path)
27
32
  signal_connect("destroy") do
@@ -44,6 +49,7 @@ module Groonga
44
49
  Gtk.main
45
50
  end
46
51
 
52
+ private
47
53
  def init_view(page_num)
48
54
  target = get_tree_view(page_num)
49
55
  return unless target
@@ -55,6 +61,8 @@ module Groonga
55
61
  def select(column, word)
56
62
  if word.empty?
57
63
  query = nil
64
+ elsif column == RAW_QUERY_MODE
65
+ query = word
58
66
  elsif column == "_id"
59
67
  query = "#{column}:#{word}"
60
68
  else
@@ -70,7 +78,7 @@ module Groonga
70
78
  page_widget = @notebook.children[page_num]
71
79
  if page_widget.is_a?(Gtk::ScrolledWindow)
72
80
  page_widget.each do |child|
73
- if child.is_a?(TreeView)
81
+ if child.is_a?(Table)
74
82
  return child
75
83
  end
76
84
  end
@@ -78,7 +86,6 @@ module Groonga
78
86
  return nil
79
87
  end
80
88
 
81
- private
82
89
  def create_search_hbox
83
90
  hbox = Gtk::HBox.new
84
91
 
@@ -103,7 +110,7 @@ module Groonga
103
110
  @limit_combo.append_text(text)
104
111
  end
105
112
  @limit_combo.append_text("268,435,455")
106
- @limit_combo.active = 0
113
+ @limit_combo.active = 2
107
114
  hbox.pack_end(@limit_combo, false, false, 4)
108
115
 
109
116
  label = Gtk::Label.new("Limit:")
@@ -124,6 +131,7 @@ module Groonga
124
131
  target.grn_table.columns.each do |column|
125
132
  @combo_box.append_text(column.local_name)
126
133
  end
134
+ @combo_box.append_text(RAW_QUERY_MODE)
127
135
  @combo_box.active = 1
128
136
  end
129
137
  end
@@ -138,8 +146,8 @@ module Groonga
138
146
  scrolled_window = Gtk::ScrolledWindow.new
139
147
  scrolled_window.set_policy(:automatic, :automatic)
140
148
 
141
- tree_view = TreeView.new(grn_table, @grn_database.path)
142
- scrolled_window.add(tree_view)
149
+ table = Table.new(grn_table, @grn_database.path)
150
+ scrolled_window.add(table)
143
151
 
144
152
  label = Gtk::Label.new(grn_table.name)
145
153
  notebook.append_page(scrolled_window, label)
@@ -153,108 +161,5 @@ module Groonga
153
161
  notebook
154
162
  end
155
163
  end
156
-
157
- class TreeView < Gtk::TreeView
158
- ID_COLUMN_INDEX = 0
159
- KEY_COLUMN_INDEX = 1
160
-
161
- attr_reader :updated
162
- attr_reader :grn_table
163
-
164
- def initialize(grn_table, db_path)
165
- super()
166
- @grn_table = grn_table
167
- @db_path = db_path
168
- @updated = false
169
- @threads = []
170
- signal_connect("destroy") do
171
- @threads.each do |thread|
172
- thread.kill
173
- end
174
- end
175
- create_tree_view
176
- end
177
-
178
- def create_tree_view
179
- self.rules_hint = true
180
-
181
- create_column("_id", ID_COLUMN_INDEX)
182
- create_column("_key", KEY_COLUMN_INDEX)
183
-
184
- @grn_table.columns.each_with_index do |grn_column, i|
185
- create_column(grn_column.local_name, i + 2)
186
- end
187
- end
188
-
189
- def create_column(name, index)
190
- gtk_column = Gtk::TreeViewColumn.new
191
- gtk_column.title = name.gsub(/_/, "__")
192
- gtk_column.resizable = true
193
- gtk_column.set_sort_column_id(index)
194
- append_column(gtk_column)
195
-
196
- renderer = Gtk::CellRendererText.new
197
- gtk_column.pack_start(renderer, :expand => false)
198
- gtk_column.add_attribute(renderer, :text, index)
199
- end
200
-
201
- def update_model(limit, query=nil)
202
- @threads.reject! do |thread|
203
- thread.kill
204
- true
205
- end
206
-
207
- column_types = @grn_table.columns.collect do |column|
208
- # TODO
209
- String
210
- end
211
- column_types.unshift(String) # _key
212
- column_types.unshift(Integer) # _id
213
-
214
- model = Gtk::ListStore.new(*column_types)
215
- self.model = model
216
-
217
- thread = Thread.new do
218
- each_records(limit, query).each do |grn_record|
219
- load_record(model, grn_record)
220
- end
221
- end
222
- @threads << thread
223
-
224
- @updated = true
225
- end
226
-
227
- def load_record(model, grn_record)
228
- iter = model.append
229
- iter.set_value(ID_COLUMN_INDEX, grn_record._id)
230
- iter.set_value(KEY_COLUMN_INDEX, grn_record._key) if grn_record.respond_to?(:_key)
231
- @grn_table.columns.each_with_index do |grn_column, i|
232
- value = grn_record[grn_column.local_name]
233
- iter.set_value(i + 2, value.to_s)
234
- if grn_column.index?
235
- ids = grn_column.search(grn_record._id).records.collect {|record| record._id}
236
- value = "#{ids.size}, #{ids.to_s}"
237
- else
238
- value = grn_record[grn_column.local_name].to_s
239
- end
240
- iter.set_value(2 + i, value)
241
- GC.start if i % 100 == 0
242
- end
243
- end
244
-
245
- def each_records(limit, query=nil)
246
- grn_records = Groonga[@grn_table.name]
247
- if query
248
- grn_records = grn_records.select(query)
249
- end
250
- if block_given?
251
- grn_records.take(limit).each do |grn_record|
252
- yield(grn_record)
253
- end
254
- else
255
- grn_records.take(limit)
256
- end
257
- end
258
- end
259
164
  end
260
165
  end
data/test/test-window.rb CHANGED
@@ -26,6 +26,11 @@ class WindowTest < Test::Unit::TestCase
26
26
  FileUtils.mkdir_p(@tmpdir)
27
27
  @db_path = File.join(@tmpdir, "test.db")
28
28
  Groonga::Database.create(:path => @db_path)
29
+ Groonga::Schema.define do |schema|
30
+ schema.create_table("Texts", :type => :hash) do |table|
31
+ table.text("text")
32
+ end
33
+ end
29
34
  end
30
35
 
31
36
  def teardown
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groonga-database-viewer-gtk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masafumi Yokoyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-05 00:00:00.000000000 Z
11
+ date: 2014-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rroonga
@@ -109,6 +109,7 @@ files:
109
109
  - bin/groonga-database-viewer-gtk
110
110
  - groonga-database-viewer-gtk.gemspec
111
111
  - lib/groonga/database-viewer-gtk.rb
112
+ - lib/groonga/database-viewer-gtk/table.rb
112
113
  - lib/groonga/database-viewer-gtk/version.rb
113
114
  - lib/groonga/database-viewer-gtk/window.rb
114
115
  - test/run-test.rb