gtk3assist 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
data/gtk3assist.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "gtk3assist"
8
- s.version = "0.0.6"
8
+ s.version = "0.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
12
- s.date = "2012-09-19"
12
+ s.date = "2012-09-30"
13
13
  s.description = "A class for making it easier to develop Gtk3 based applications with the 'gir_ffi-gtk'-gem."
14
14
  s.email = "k@spernj.org"
15
15
  s.extra_rdoc_files = [
data/lib/gtk3assist.rb CHANGED
@@ -9,4 +9,13 @@ class Gtk3assist
9
9
  raise "Still not defined: '#{name}'." if !Gtk3assist.const_defined?(name)
10
10
  return Gtk3assist.const_get(name)
11
11
  end
12
+
13
+ #Sends the given text to GetText or returns the string if GetText is not loaded.
14
+ def self._(str)
15
+ if ::Kernel.const_defined?(:GetText)
16
+ ::GetText._(str)
17
+ else
18
+ return str
19
+ end
20
+ end
12
21
  end
@@ -11,6 +11,15 @@ class Gtk3assist::Msgbox
11
11
  #The result of the dialog.
12
12
  attr_reader :result
13
13
 
14
+ def self.error(e, args = {})
15
+ msg = Gtk3assist._("An error occurred.")
16
+ msg << "\n\n"
17
+ msg << "<#{e.class.name}: #{e.message}>\n"
18
+ msg << e.backtrace.join("\n")
19
+
20
+ return Gtk3assist::Msgbox.new(args.merge(:type => :warning, :msg => msg))
21
+ end
22
+
14
23
  def self.current
15
24
  raise "No current showing message-box." if !DATA[:current]
16
25
  end
@@ -28,11 +37,11 @@ class Gtk3assist::Msgbox
28
37
  if !args[:title]
29
38
  case args[:type]
30
39
  when :warning
31
- args[:title] = _("Warning")
40
+ args[:title] = Gtk3assist._("Warning")
32
41
  when :yesno
33
- args[:title] = _("Question")
42
+ args[:title] = Gtk3assist._("Question")
34
43
  when :info
35
- args[:title] = _("Information")
44
+ args[:title] = Gtk3assist._("Information")
36
45
  else
37
46
  raise "Unknown type: '#{args[:type]}'."
38
47
  end
@@ -139,14 +148,4 @@ class Gtk3assist::Msgbox
139
148
  raise "No result yet." if !@result
140
149
  return Gtk::ResponseType[@result].to_sym
141
150
  end
142
-
143
- #Contains a fallback method for '_' which is used to translate texts in the GetText-library.
144
- def method_missing(method, *args, &block)
145
- case method
146
- when :_
147
- return args[0]
148
- else
149
- raise NameError, "No such method: '#{method}'."
150
- end
151
- end
152
151
  end
@@ -24,11 +24,17 @@ class Gtk3assist::Threadding
24
24
  Thread.pass
25
25
  t_run = Time.now.to_f - t_begin
26
26
 
27
- if t_run < 0.0001
27
+ if t_run < 0.00001
28
+ #Somehow the idle or timeout gets ignored unless this is here.
29
+ Thread.pass
30
+
28
31
  #Run again after a small amount of time to prevent 100% CPU.
29
32
  GLib.timeout_add(GLib::PRIORITY_DEFAULT_IDLE, @time, self.method(:enable_threadding_pass), nil, nil)
30
33
  return false
31
34
  else
35
+ #Somehow the idle or timeout gets ignored unless this is here.
36
+ Thread.pass
37
+
32
38
  #Run again on next idle.
33
39
  GLib.idle_add(GLib::PRIORITY_DEFAULT_IDLE, self.method(:enable_threadding_pass), nil, nil)
34
40
  return false
@@ -7,7 +7,7 @@ class Gtk3assist::Treeview
7
7
  attr_reader :model
8
8
 
9
9
  #An array of allowed arguments for the 'initialize'-method.
10
- ALLOWED_ARGS = [:tv, :cols, :model]
10
+ ALLOWED_ARGS = [:tv, :cols, :model, :sort_col]
11
11
 
12
12
  #Constructor.
13
13
  def initialize(args)
@@ -17,6 +17,7 @@ class Gtk3assist::Treeview
17
17
  end
18
18
 
19
19
  @columns = []
20
+ @column_count = 0
20
21
  @tv = args[:tv]
21
22
  raise "No ':tv' argument was given." if !@tv.is_a?(Gtk::TreeView)
22
23
 
@@ -33,6 +34,8 @@ class Gtk3assist::Treeview
33
34
  raise "Unknown model: '#{args[:model]}'."
34
35
  end
35
36
  end
37
+
38
+ self.sort_col = args[:sort_col] if args.key?(:sort_col)
36
39
  end
37
40
 
38
41
  #Initializes a new list-store on the treeview.
@@ -50,6 +53,20 @@ class Gtk3assist::Treeview
50
53
  @tv.set_model(@model)
51
54
  end
52
55
 
56
+ def sort_col=(col_id)
57
+ count = 0
58
+ @columns.each do |col_data|
59
+ if col_data[:id] == col_id
60
+ @model.set_sort_column_id(count, Gtk::SortType[:ascending])
61
+ return nil
62
+ end
63
+
64
+ count += 1
65
+ end
66
+
67
+ raise "Could not find a column by that ID: '#{col_id}'."
68
+ end
69
+
53
70
  #Adds a new column to the treeview.
54
71
  def add_column(args)
55
72
  if args.is_a?(Hash)
@@ -70,6 +87,7 @@ class Gtk3assist::Treeview
70
87
 
71
88
  lab.show
72
89
  @tv.append_column(col)
90
+ count = @column_count
73
91
 
74
92
  @columns << {
75
93
  :col => col,
@@ -119,6 +137,33 @@ class Gtk3assist::Treeview
119
137
  end
120
138
  end
121
139
 
140
+ def rows_remove(args = nil)
141
+ #Containing the ID's that should be removed (minus length to account for cursor changes).
142
+ removes = []
143
+
144
+ #Avoid counting length of 'removes' all the time.
145
+ removes_count = 0
146
+
147
+ #Calculate which rows should be removed by yield'ing and checking for true. Then adding ID (minus remove-count) to 'removes'-array.
148
+ self.rows(args) do |data|
149
+ res = yield(data)
150
+
151
+ if res == true
152
+ removes << @model.path(data[:iter]).to_string.to_i - removes_count
153
+ removes_count += 1
154
+ end
155
+ end
156
+
157
+ #Remove rows by their IDs (minus removes-count).
158
+ removes.each do |id|
159
+ path = Gtk::TreePath.new_from_string(id.to_s)
160
+ iter = @model.iter(path).last
161
+ @model.remove(iter)
162
+ end
163
+
164
+ return nil
165
+ end
166
+
122
167
  #Enumerates over every row in the treeview.
123
168
  def rows(args = nil, &block)
124
169
  enum = Enumerator.new do |y|
@@ -156,6 +201,7 @@ class Gtk3assist::Treeview
156
201
 
157
202
  if block
158
203
  enum.each(&block)
204
+ return nil
159
205
  else
160
206
  return enum
161
207
  end
@@ -17,5 +17,13 @@ describe "Gtk3assist_msgbox" do
17
17
  msg.respond(:yes)
18
18
  res = msg.result_text
19
19
  raise "Expected yes but got: '#{res}'." if res != :yes
20
+
21
+
22
+ begin
23
+ raise "test"
24
+ rescue => e
25
+ msg = Gtk3assist::Msgbox.error(e, :run => false)
26
+ msg.respond(:ok)
27
+ end
20
28
  end
21
29
  end
@@ -22,6 +22,14 @@ describe "Gtk3assist_treeview" do
22
22
  :id => 2,
23
23
  :name => "Christina"
24
24
  })
25
+ tva.add_row(:data => {
26
+ :id => 3,
27
+ :name => "Matti"
28
+ })
29
+ tva.add_row(:data => {
30
+ :id => 4,
31
+ :name => "Nancy"
32
+ })
25
33
 
26
34
  count = 0
27
35
  tva.rows do |data|
@@ -29,7 +37,33 @@ describe "Gtk3assist_treeview" do
29
37
  #puts data
30
38
  end
31
39
 
32
- raise "Expected count to be 2 but it wasnt: '#{count}'." if count != 2
40
+ raise "Expected count to be 4 but it wasnt: '#{count}'." if count != 4
41
+
42
+ kasper_removed = false
43
+ last_data = nil
44
+
45
+ tva.rows_remove do |data|
46
+ last_data = data
47
+
48
+ if data[:data][:name] == "Kasper" or data[:data][:name] == "Matti"
49
+ kasper_removed = true
50
+ true
51
+ else
52
+ false
53
+ end
54
+ end
55
+
56
+ raise "Expected 'Kasper' to be removed but it wasnt." if !kasper_removed
57
+ raise "Expected last item to be 'Nancy' but it wasnt." if last_data[:data][:name] != "Nancy"
58
+
59
+ kasper_found = false
60
+ count = 0
61
+ tva.rows do |data|
62
+ raise "Didnt expect 'Kasper' or 'Matti' to still exist but it did." if data[:data][:name] == "Kasper" or data[:data][:name] == "Matti"
63
+ count += 1
64
+ end
65
+
66
+ raise "Expected count to be 4 but it wasnt: '#{count}'." if count != 2
33
67
 
34
68
  win.resize(640, 480)
35
69
  win.add(tv)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gtk3assist
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.6
5
+ version: 0.0.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-09-19 00:00:00 Z
13
+ date: 2012-09-30 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gir_ffi-gtk
@@ -122,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - ">="
124
124
  - !ruby/object:Gem::Version
125
- hash: -4599824558676846179
125
+ hash: -535183420519401515
126
126
  segments:
127
127
  - 0
128
128
  version: "0"