knjrbfw 0.0.92 → 0.0.93

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.92
1
+ 0.0.93
data/knjrbfw.gemspec CHANGED
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{knjrbfw}
8
- s.version = "0.0.92"
7
+ s.name = "knjrbfw"
8
+ s.version = "0.0.93"
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 = %q{2012-09-03}
13
- s.description = %q{Including stuff for HTTP, SSH and much more.}
14
- s.email = %q{k@spernj.org}
12
+ s.date = "2012-09-04"
13
+ s.description = "Including stuff for HTTP, SSH and much more."
14
+ s.email = "k@spernj.org"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.rdoc"
@@ -263,11 +263,11 @@ Gem::Specification.new do |s|
263
263
  "spec/web_spec.rb",
264
264
  "testfiles/image.jpg"
265
265
  ]
266
- s.homepage = %q{http://github.com/kaspernj/knjrbfw}
266
+ s.homepage = "http://github.com/kaspernj/knjrbfw"
267
267
  s.licenses = ["MIT"]
268
268
  s.require_paths = ["lib"]
269
- s.rubygems_version = %q{1.6.2}
270
- s.summary = %q{A framework with lots of stuff for Ruby.}
269
+ s.rubygems_version = "1.8.24"
270
+ s.summary = "A framework with lots of stuff for Ruby."
271
271
 
272
272
  if s.respond_to? :specification_version then
273
273
  s.specification_version = 3
data/lib/knj/arrayext.rb CHANGED
@@ -1,5 +1,3 @@
1
- require "php4r"
2
-
3
1
  module Knj::ArrayExt
4
2
  def self.join(args = {}, key = nil, sep = nil)
5
3
  if args.is_a?(Array) and sep
@@ -15,6 +13,7 @@ module Knj::ArrayExt
15
13
  str = ""
16
14
  first = true
17
15
 
16
+ require "php4r"
18
17
  Php4r.foreach(args[:arr]) do |key, value|
19
18
  if first
20
19
  first = false
@@ -213,6 +212,7 @@ module Knj::ArrayExt
213
212
  def self.clone_encode(hash, encoding, args = {})
214
213
  return hash if !hash
215
214
 
215
+ require "php4r"
216
216
  hash = hash.clone
217
217
  Php4r.foreach(hash) do |key, val|
218
218
  if val.is_a?(String)
data/lib/knj/gtk2_cb.rb CHANGED
@@ -1,43 +1,41 @@
1
1
  module Knj::Gtk2::Cb
2
+ #This method can be used to invoke autoloading of this file.
2
3
  def self.init(paras)
3
4
  return paras["cb"].init(paras["items"])
4
5
  end
5
6
 
7
+ #This method can be used to invoke autoloading of this file.
6
8
  def self.sel(cb)
7
9
  return cb.sel
8
10
  end
9
11
  end
10
12
 
11
13
  class Gtk::ComboBox
14
+ #Shortcut to initialize a combobox with items (or models).
12
15
  def init(items)
13
16
  @knj = {
14
17
  :items => []
15
18
  }
16
19
 
17
- ls = Gtk::ListStore.new(String, String)
20
+ @ls = Gtk::ListStore.new(String, String)
18
21
  cr = Gtk::CellRendererText.new
19
22
  self.pack_start(cr, false)
20
23
  self.add_attribute(cr, "text", 0)
21
24
 
22
25
  if items.is_a?(Array)
23
26
  items.each do |appendob|
24
- iter = ls.append
25
-
26
27
  if appendob.is_a?(String)
28
+ iter = @ls.append
27
29
  iter[0] = appendob
28
30
  elsif appendob.respond_to?(:is_knj?)
29
- iter[0] = appendob.title
30
- @knj[:items] << {
31
- :iter => iter,
32
- :object => appendob
33
- }
31
+ self.append_model(:model => appendob)
34
32
  end
35
33
  end
36
34
  elsif items.is_a?(Hash)
37
35
  @knj[:type] = :hash
38
36
 
39
37
  items.each do |key, val|
40
- iter = ls.append
38
+ iter = @ls.append
41
39
  iter[0] = val
42
40
 
43
41
  @knj[:items] << {
@@ -49,10 +47,32 @@ class Gtk::ComboBox
49
47
  raise "Unsupported type: '#{items.class.name}'."
50
48
  end
51
49
 
52
- self.model = ls
50
+ self.model = @ls
53
51
  self.active = 0
54
52
  end
55
53
 
54
+ #Appens a model to the list-store.
55
+ def append_model(args)
56
+ iter = @ls.append
57
+ appendob = args[:model]
58
+
59
+ if appendob.respond_to?(:name)
60
+ iter[0] = appendob.name
61
+ elsif appendob.respond_to?(:title)
62
+ iter[0] = appendob.title
63
+ else
64
+ raise "Could not figure out of the name of the object."
65
+ end
66
+
67
+ @knj[:items] << {
68
+ :iter => iter,
69
+ :object => appendob
70
+ }
71
+
72
+ return {}
73
+ end
74
+
75
+ #Returns the active item (or model) for the combobox.
56
76
  def sel
57
77
  iter = self.active_iter
58
78
 
@@ -72,6 +92,7 @@ class Gtk::ComboBox
72
92
  end
73
93
  end
74
94
 
95
+ #Sets the active element (or model) in the combobox.
75
96
  def sel=(actob)
76
97
  if actob.respond_to?(:is_knj?)
77
98
  @knj[:items].each do |item|
@@ -100,4 +121,24 @@ class Gtk::ComboBox
100
121
 
101
122
  raise "Could not find such a row: '#{actob}'."
102
123
  end
124
+
125
+ #Resorts all items in the list-store. If an item doesnt have an ID, then that item will be put first (for 'Choose', 'All' and such options).
126
+ def resort
127
+ @ls.set_sort_column_id(0)
128
+ @ls.set_sort_func(0, &lambda{|iter1, iter2|
129
+ item_id_1 = iter1[1].to_i
130
+ item_id_2 = iter2[1].to_i
131
+
132
+ item_name_1 = iter1[0].to_s.downcase
133
+ item_name_2 = iter2[0].to_s.downcase
134
+
135
+ if item_id_1 == 0
136
+ return -1
137
+ elsif item_id_2 == 0
138
+ return 1
139
+ else
140
+ return item_name_1 <=> item_name_2
141
+ end
142
+ })
143
+ end
103
144
  end
data/lib/knj/objects.rb CHANGED
@@ -149,11 +149,21 @@ class Knj::Objects
149
149
 
150
150
  #Unconnects a connect by 'object' and 'conn_id'.
151
151
  def unconnect(args)
152
- raise "No object given." if !args["object"]
153
- raise "No conn-ID given." if !args["conn_id"]
154
- raise "Object doesnt exist: '#{args["object"]}'." if !@callbacks.key?(args["object"].to_sym)
155
- raise "Conn ID doest exist: '#{args["conn_id"]}'." if !@callbacks[args["object"].to_sym].key?(args["conn_id"])
156
- @callbacks[args["object"].to_sym].delete(args["conn_id"])
152
+ raise ArgumentError, "No object given." if !args["object"]
153
+ raise ArgumentError, "Object doesnt exist: '#{args["object"]}'." if !@callbacks.key?(args["object"].to_sym)
154
+
155
+ if args["conn_id"]
156
+ conn_ids = [args["conn_id"]]
157
+ elsif args["conn_ids"]
158
+ conn_ids = args["conn_ids"]
159
+ else
160
+ raise ArgumentError, "Could not figure out connection IDs."
161
+ end
162
+
163
+ conn_ids.each do |conn_id|
164
+ raise Errno::ENOENT, "Conn ID doest exist: '#{conn_id}' (#{args})." if !@callbacks[args["object"].to_sym].key?(conn_id)
165
+ @callbacks[args["object"].to_sym].delete(conn_id)
166
+ end
157
167
  end
158
168
 
159
169
  #This method is used to call the connected callbacks for an event.
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: knjrbfw
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.92
5
+ version: 0.0.93
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
@@ -10,8 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-09-03 00:00:00 +02:00
14
- default_executable:
13
+ date: 2012-09-04 00:00:00 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: wref
@@ -378,7 +377,6 @@ files:
378
377
  - spec/strings_spec.rb
379
378
  - spec/web_spec.rb
380
379
  - testfiles/image.jpg
381
- has_rdoc: true
382
380
  homepage: http://github.com/kaspernj/knjrbfw
383
381
  licenses:
384
382
  - MIT
@@ -392,7 +390,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
392
390
  requirements:
393
391
  - - ">="
394
392
  - !ruby/object:Gem::Version
395
- hash: -538892594692910848
393
+ hash: -3932683874553081
396
394
  segments:
397
395
  - 0
398
396
  version: "0"
@@ -405,7 +403,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
405
403
  requirements: []
406
404
 
407
405
  rubyforge_project:
408
- rubygems_version: 1.6.2
406
+ rubygems_version: 1.8.24
409
407
  signing_key:
410
408
  specification_version: 3
411
409
  summary: A framework with lots of stuff for Ruby.