ffi-tk 2010.03 → 2010.06

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/AUTHORS CHANGED
@@ -1,6 +1,6 @@
1
1
  Following persons have contributed to ffi-tk.
2
2
  (Sorted by number of submitted patches, then alphabetically)
3
3
 
4
- 225 Michael Fellinger <m.fellinger@gmail.com>
4
+ 239 Michael Fellinger <m.fellinger@gmail.com>
5
5
  19 Julian Langschaedel <meta.rb@gmail.com>
6
6
  1 unknown <manveru@.(none)>
data/CHANGELOG CHANGED
@@ -1,3 +1,59 @@
1
+ [8d78da8 | 2010-06-02 16:15:20 UTC] Michael Fellinger <m.fellinger@gmail.com>
2
+
3
+ * Version 2010.06
4
+
5
+ [c2d350b | 2010-06-02 16:13:10 UTC] Michael Fellinger <m.fellinger@gmail.com>
6
+
7
+ * ComboBox is not an Entry
8
+
9
+ [ff17848 | 2010-06-02 16:12:59 UTC] Michael Fellinger <m.fellinger@gmail.com>
10
+
11
+ * Fix pathname generation
12
+
13
+ [0747bc3 | 2010-03-12 05:14:57 UTC] Michael Fellinger <m.fellinger@gmail.com>
14
+
15
+ * Add tcl/tk 8.6 as working versions
16
+
17
+ [80c4cb4 | 2010-03-10 16:07:57 UTC] Michael Fellinger <m.fellinger@gmail.com>
18
+
19
+ * Name the mysterious eval flag
20
+
21
+ [28aff12 | 2010-03-10 16:07:41 UTC] Michael Fellinger <m.fellinger@gmail.com>
22
+
23
+ * Use better array retrieval
24
+
25
+ [4916cfb | 2010-03-10 15:53:06 UTC] Michael Fellinger <m.fellinger@gmail.com>
26
+
27
+ * Let other function calls panic too
28
+
29
+ [2caf7a1 | 2010-03-10 15:52:51 UTC] Michael Fellinger <m.fellinger@gmail.com>
30
+
31
+ * Don't try to convert event data if it's ??
32
+
33
+ [77dce01 | 2010-03-10 15:52:30 UTC] Michael Fellinger <m.fellinger@gmail.com>
34
+
35
+ * Improve EvalResult::map_list_core
36
+
37
+ [6f328f6 | 2010-03-10 08:03:10 UTC] Michael Fellinger <m.fellinger@gmail.com>
38
+
39
+ * Handle the % sequence in events
40
+
41
+ [795e77d | 2010-03-09 07:36:38 UTC] Michael Fellinger <m.fellinger@gmail.com>
42
+
43
+ * Rename Event::Data.sequence to Event::Data.pattern
44
+
45
+ [bc3f560 | 2010-03-07 16:04:59 UTC] Michael Fellinger <m.fellinger@gmail.com>
46
+
47
+ * Split up the LIBPATH Hash into two constant Arrays, fix bug on osx
48
+
49
+ [c98168e | 2010-03-07 15:59:15 UTC] Michael Fellinger <m.fellinger@gmail.com>
50
+
51
+ * A little bit of restructure, don't require the 'Apple_PubSub_Socket_Render' env to be set, but allow TK_LIBPATH and TCL_LIBPATH to be
52
+
53
+ [865fd4b | 2010-03-05 17:41:38 UTC] Michael Fellinger <m.fellinger@gmail.com>
54
+
55
+ * Working implementation of WM::protocol
56
+
1
57
  [920e7c5 | 2010-03-02 05:07:40 UTC] Michael Fellinger <m.fellinger@gmail.com>
2
58
 
3
59
  * Version 2010.03
data/ffi-tk.gemspec CHANGED
@@ -2,24 +2,24 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ffi-tk}
5
- s.version = "2010.03"
5
+ s.version = "2010.06"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.3.3") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Michael 'manveru' Fellinger"]
9
- s.date = %q{2010-03-02}
9
+ s.date = %q{2010-06-03}
10
10
  s.description = %q{Pure Ruby FFI wrapper for the Tk GUI toolkit.}
11
11
  s.email = %q{m.fellinger@gmail.com}
12
12
  s.files = [".gitignore", "AUTHORS", "CHANGELOG", "MANIFEST", "README.md", "Rakefile", "TODO.md", "bin/rwish", "doc/MIT_LICENSE", "doc/TCL_LICENSE", "example/choose_color.rb", "example/choose_directory.rb", "example/dialog.rb", "example/hello.rb", "example/message_box.rb", "example/option_menu.rb", "example/popup.rb", "example/set_palette.rb", "example/text.rb", "example/tile/kroc_demo_small.rb", "example/tile/kroc_rb_demo.rb", "example/tile/notebook.rb", "example/tile/theme_hello.rb", "example/tile/themes.rb", "example/tile/treeview.rb", "example/tkgo.rb", "example/various.rb", "example/wait.rb", "ffi-tk.gemspec", "lib/ffi-tk.rb", "lib/ffi-tk/command.rb", "lib/ffi-tk/command/after.rb", "lib/ffi-tk/command/bell.rb", "lib/ffi-tk/command/bind.rb", "lib/ffi-tk/command/bindtags.rb", "lib/ffi-tk/command/cget.rb", "lib/ffi-tk/command/choose_color.rb", "lib/ffi-tk/command/choose_directory.rb", "lib/ffi-tk/command/clipboard.rb", "lib/ffi-tk/command/configure.rb", "lib/ffi-tk/command/destroy.rb", "lib/ffi-tk/command/dialog.rb", "lib/ffi-tk/command/event.rb", "lib/ffi-tk/command/focus.rb", "lib/ffi-tk/command/font.rb", "lib/ffi-tk/command/get_open_file.rb", "lib/ffi-tk/command/get_save_file.rb", "lib/ffi-tk/command/grab.rb", "lib/ffi-tk/command/grid.rb", "lib/ffi-tk/command/image.rb", "lib/ffi-tk/command/lower.rb", "lib/ffi-tk/command/message_box.rb", "lib/ffi-tk/command/option_menu.rb", "lib/ffi-tk/command/pack.rb", "lib/ffi-tk/command/place.rb", "lib/ffi-tk/command/popup.rb", "lib/ffi-tk/command/raise.rb", "lib/ffi-tk/command/scrollable.rb", "lib/ffi-tk/command/selection.rb", "lib/ffi-tk/command/set_palette.rb", "lib/ffi-tk/command/tk_cmd.rb", "lib/ffi-tk/command/vars.rb", "lib/ffi-tk/command/wait.rb", "lib/ffi-tk/command/winfo.rb", "lib/ffi-tk/command/wm.rb", "lib/ffi-tk/core_extensions.rb", "lib/ffi-tk/event/data.rb", "lib/ffi-tk/event/handler.rb", "lib/ffi-tk/ffi/tcl.rb", "lib/ffi-tk/ffi/tcl/cmd_proc.rb", "lib/ffi-tk/ffi/tcl/eval_result.rb", "lib/ffi-tk/ffi/tcl/interp.rb", "lib/ffi-tk/ffi/tcl/obj.rb", "lib/ffi-tk/ffi/tcl/time.rb", "lib/ffi-tk/ffi/tk.rb", "lib/ffi-tk/geometry.rb", "lib/ffi-tk/thread_sender.rb", "lib/ffi-tk/tk.rb", "lib/ffi-tk/variable.rb", "lib/ffi-tk/version.rb", "lib/ffi-tk/widget.rb", "lib/ffi-tk/widget/button.rb", "lib/ffi-tk/widget/canvas.rb", "lib/ffi-tk/widget/canvas/arc.rb", "lib/ffi-tk/widget/canvas/bitmap.rb", "lib/ffi-tk/widget/canvas/image.rb", "lib/ffi-tk/widget/canvas/item.rb", "lib/ffi-tk/widget/canvas/line.rb", "lib/ffi-tk/widget/canvas/oval.rb", "lib/ffi-tk/widget/canvas/polygon.rb", "lib/ffi-tk/widget/canvas/rectangle.rb", "lib/ffi-tk/widget/canvas/text.rb", "lib/ffi-tk/widget/canvas/window.rb", "lib/ffi-tk/widget/checkbutton.rb", "lib/ffi-tk/widget/entry.rb", "lib/ffi-tk/widget/frame.rb", "lib/ffi-tk/widget/label.rb", "lib/ffi-tk/widget/labelframe.rb", "lib/ffi-tk/widget/listbox.rb", "lib/ffi-tk/widget/menu.rb", "lib/ffi-tk/widget/menubutton.rb", "lib/ffi-tk/widget/message.rb", "lib/ffi-tk/widget/panedwindow.rb", "lib/ffi-tk/widget/radiobutton.rb", "lib/ffi-tk/widget/root.rb", "lib/ffi-tk/widget/scale.rb", "lib/ffi-tk/widget/scrollbar.rb", "lib/ffi-tk/widget/spinbox.rb", "lib/ffi-tk/widget/text.rb", "lib/ffi-tk/widget/text/peer.rb", "lib/ffi-tk/widget/tile.rb", "lib/ffi-tk/widget/tile/button.rb", "lib/ffi-tk/widget/tile/checkbutton.rb", "lib/ffi-tk/widget/tile/combobox.rb", "lib/ffi-tk/widget/tile/entry.rb", "lib/ffi-tk/widget/tile/frame.rb", "lib/ffi-tk/widget/tile/label.rb", "lib/ffi-tk/widget/tile/labelframe.rb", "lib/ffi-tk/widget/tile/menubutton.rb", "lib/ffi-tk/widget/tile/notebook.rb", "lib/ffi-tk/widget/tile/panedwindow.rb", "lib/ffi-tk/widget/tile/progressbar.rb", "lib/ffi-tk/widget/tile/radiobutton.rb", "lib/ffi-tk/widget/tile/scale.rb", "lib/ffi-tk/widget/tile/scrollbar.rb", "lib/ffi-tk/widget/tile/separator.rb", "lib/ffi-tk/widget/tile/sizegrip.rb", "lib/ffi-tk/widget/tile/style.rb", "lib/ffi-tk/widget/tile/treeview.rb", "lib/ffi-tk/widget/toplevel.rb", "spec/ffi-tk/command/bind.rb", "spec/ffi-tk/command/bindtags.rb", "spec/ffi-tk/command/clipboard.rb", "spec/ffi-tk/command/font.rb", "spec/ffi-tk/command/grid.rb", "spec/ffi-tk/command/image.rb", "spec/ffi-tk/command/pack.rb", "spec/ffi-tk/command/place.rb", "spec/ffi-tk/command/selection.rb", "spec/ffi-tk/command/vars.rb", "spec/ffi-tk/command/winfo.rb", "spec/ffi-tk/command/wm.rb", "spec/ffi-tk/event.rb", "spec/ffi-tk/tile/button.rb", "spec/ffi-tk/tile/checkbutton.rb", "spec/ffi-tk/tile/combobox.rb", "spec/ffi-tk/tile/entry.rb", "spec/ffi-tk/tile/frame.rb", "spec/ffi-tk/tile/label.rb", "spec/ffi-tk/tile/labelframe.rb", "spec/ffi-tk/tile/menubutton.rb", "spec/ffi-tk/tile/notebook.rb", "spec/ffi-tk/tile/panedwindow.rb", "spec/ffi-tk/tile/progressbar.rb", "spec/ffi-tk/tile/radiobutton.rb", "spec/ffi-tk/tile/scale.rb", "spec/ffi-tk/tile/scrollbar.rb", "spec/ffi-tk/tile/separator.rb", "spec/ffi-tk/tile/sizegrip.rb", "spec/ffi-tk/tile/style.rb", "spec/ffi-tk/tile/treeview.rb", "spec/ffi-tk/variable.rb", "spec/ffi-tk/widget/button.rb", "spec/ffi-tk/widget/canvas.rb", "spec/ffi-tk/widget/checkbutton.rb", "spec/ffi-tk/widget/entry.rb", "spec/ffi-tk/widget/frame.rb", "spec/ffi-tk/widget/label.rb", "spec/ffi-tk/widget/labelframe.rb", "spec/ffi-tk/widget/listbox.rb", "spec/ffi-tk/widget/menu.rb", "spec/ffi-tk/widget/menubutton.rb", "spec/ffi-tk/widget/message.rb", "spec/ffi-tk/widget/panedwindow.rb", "spec/ffi-tk/widget/radiobutton.rb", "spec/ffi-tk/widget/root.rb", "spec/ffi-tk/widget/scale.rb", "spec/ffi-tk/widget/scrollbar.rb", "spec/ffi-tk/widget/spinbox.rb", "spec/ffi-tk/widget/text.rb", "spec/ffi-tk/widget/toplevel.rb", "spec/helper.rb", "tasks/authors.rake", "tasks/bacon.rake", "tasks/changelog.rake", "tasks/gem.rake", "tasks/gem_setup.rake", "tasks/grancher.rake", "tasks/manifest.rake", "tasks/rcov.rake", "tasks/release.rake", "tasks/reversion.rake", "tasks/setup.rake", "tasks/ycov.rake"]
13
13
  s.homepage = %q{http://github.com/manveru/ffi-tk}
14
14
  s.require_paths = ["lib"]
15
- s.rubygems_version = %q{1.3.6}
15
+ s.rubygems_version = %q{1.3.7}
16
16
  s.summary = %q{Pure Ruby FFI wrapper for the Tk GUI toolkit.}
17
17
 
18
18
  if s.respond_to? :specification_version then
19
19
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
20
20
  s.specification_version = 3
21
21
 
22
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
22
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
23
23
  s.add_runtime_dependency(%q<ffi>, ["= 0.6.2"])
24
24
  s.add_development_dependency(%q<bacon>, [">= 1.1.0"])
25
25
  else
data/lib/ffi-tk.rb CHANGED
@@ -4,27 +4,41 @@ require 'ffi'
4
4
  $LOAD_PATH.unshift File.dirname(__FILE__)
5
5
 
6
6
  module Tk
7
- LIBPATH = { tcl: [], tk: [] }
8
-
9
- if ENV['Apple_PubSub_Socket_Render']
10
- RUN_EVENTLOOP_ON_MAIN_THREAD = true
7
+ TCL_LIBPATH = ENV['TCL_LIBPATH'].to_s.split(':')
8
+ TK_LIBPATH = ENV[ 'TK_LIBPATH'].to_s.split(':')
11
9
 
10
+ if FFI::Platform.mac?
12
11
  if ENV['NO_AQUA'] || ENV['USE_X11'] # macports-x11 libtk
13
- LIBPATH[:tcl] << '/opt/local/lib/libtcl8.5.dylib'
14
- LIBPATH[:tk] << '/opt/local/lib/libtk8.5.dylib'
12
+ TCL_LIBPATH << '/opt/local/lib/libtcl8.5.dylib'
13
+ TK_LIBPATH << '/opt/local/lib/libtk8.5.dylib'
15
14
  else # Tcl/Tk Aqua >= 8.5
16
- LIBPATH[:tcl] << '/Library/Frameworks/Tcl.framework/Tcl'
17
- LIBPATH[:tk] << '/Library/Frameworks/Tk.framework/Tk'
15
+ TCL_LIBPATH << '/Library/Frameworks/Tcl.framework/Tcl'
16
+ TK_LIBPATH << '/Library/Frameworks/Tk.framework/Tk'
18
17
  end
19
18
  end
20
- end
21
19
 
22
- require 'ffi-tk/thread_sender'
23
- require 'ffi-tk/ffi/tcl'
24
- require 'ffi-tk/ffi/tk'
20
+ TCL_LIBPATH << 'tcl' << 'tcl86' << 'tcl85' << 'tcl8.6' << 'tcl8.5'
21
+ TK_LIBPATH << 'tk' << 'tk86' << 'tk85' << 'tk8.6' << 'tk8.5'
25
22
 
26
- module Tk
27
- Error = Class.new(RuntimeError)
23
+ unless const_defined?(:RUN_EVENTLOOP_ON_MAIN_THREAD)
24
+ if FFI::Platform.mac?
25
+ # In some cases Tk has trouble running, this seems to happen on windows and
26
+ # OSX/TkAqua mostly.
27
+ # In these cases please use:
28
+ # module Tk; RUN_EVENTLOOP_ON_MAIN_THREAD = true; end
29
+ # before you require 'tk'
30
+ RUN_EVENTLOOP_ON_MAIN_THREAD = true
31
+ else
32
+ RUN_EVENTLOOP_ON_MAIN_THREAD = false
33
+ end
34
+ end
35
+
36
+ DONT_WAIT = 1 << 1
37
+ WINDOW_EVENTS = 1 << 2
38
+ FILE_EVENTS = 1 << 3
39
+ TIMER_EVENTS = 1 << 4
40
+ IDLE_EVENTS = 1 << 5
41
+ ALL_EVENTS = ~DONT_WAIT
28
42
 
29
43
  OK = 0
30
44
  ERROR = 1
@@ -32,6 +46,7 @@ module Tk
32
46
  BREAK = 3
33
47
  CONTINUE = 4
34
48
 
49
+ Error = Class.new(RuntimeError)
35
50
  None = Object.new
36
51
 
37
52
  class << None
@@ -40,7 +55,13 @@ module Tk
40
55
  def to_tcl_option?; self; end
41
56
  def inspect; '#<None>'; end
42
57
  end
58
+ end
59
+
60
+ require 'ffi-tk/thread_sender'
61
+ require 'ffi-tk/ffi/tcl'
62
+ require 'ffi-tk/ffi/tk'
43
63
 
64
+ module Tk
44
65
  autoload :Button, 'ffi-tk/widget/button'
45
66
  autoload :Canvas, 'ffi-tk/widget/canvas'
46
67
  autoload :CheckButton, 'ffi-tk/widget/checkbutton'
@@ -887,16 +887,29 @@ module Tk
887
887
  # received.
888
888
  def protocol(window, name = None, command = None, &block)
889
889
  command = block if block && !command.nil?
890
+ @commands ||= {}
891
+ key = [window, name]
890
892
 
891
893
  if name == None
892
894
  Tk.execute(:wm, :protocol, window).to_a
893
895
  elsif name != None && command == None
894
- Tk.execute(:wm, :protocol, name)
896
+ Tk.execute(:wm, :protocol, window, name)
895
897
  elsif name != None && command.nil?
896
- Tk.execute_only(:wm, :protocol, name, '')
898
+ if id = @commands[key]
899
+ Tk.unregister_proc(id)
900
+ @commands.delete(key)
901
+ end
902
+
903
+ Tk.execute_only(:wm, :protocol, window, name, '')
897
904
  elsif name != None && command
898
- command = register_command(:wm_protocol, &command)
899
- Tk.execute_only(:wm, :protocol, name, command)
905
+ if id = @commands[key]
906
+ Tk.unregister_proc(id)
907
+ end
908
+
909
+ id, tcl_command = Tk.register_proc(command, '')
910
+ @commands[key] = id
911
+
912
+ Tk.execute_only(:wm, :protocol, window, name, tcl_command)
900
913
  else
901
914
  raise ArgumentError
902
915
  end
@@ -1,11 +1,11 @@
1
1
  module Tk
2
2
  module Event
3
3
  Data = Struct.new(
4
- :id, :sequence, :border_width, :button, :count, :detail, :focus, :height,
4
+ :id, :pattern, :border_width, :button, :count, :detail, :focus, :height,
5
5
  :keycode, :keysym, :keysym_number, :mode, :mousewheel_delta,
6
- :override_redirect, :place, :property, :root, :send_event, :serial, :state,
7
- :subwindow, :time, :type, :unicode, :width, :window, :window_path, :x,
8
- :x_root, :y, :y_root
6
+ :override_redirect, :place, :property, :root, :send_event, :serial,
7
+ :state, :subwindow, :time, :type, :unicode, :width, :window,
8
+ :window_path, :x, :x_root, :y, :y_root
9
9
  )
10
10
 
11
11
  class Data
@@ -41,13 +41,14 @@ module Tk
41
41
  ['%Y', :Integer, :y_root ],
42
42
  ]
43
43
 
44
- def initialize(id, sequence, *properties)
45
- super id, sequence
44
+ def initialize(id, pattern, *properties)
45
+ super id, pattern
46
46
 
47
47
  PROPERTIES.each do |code, conv, name|
48
48
  value = properties.shift
49
- converted = __send__(conv, value)
49
+ converted = String(value)
50
50
  next if converted == '??'
51
+ converted = __send__(conv, value)
51
52
  self[name] = converted
52
53
  end
53
54
  end
@@ -64,7 +65,7 @@ module Tk
64
65
  value = self[name]
65
66
 
66
67
  case name
67
- when :id, :sequence, :border_width, :button, :count, :focus, :height,
68
+ when :id, :pattern, :border_width, :button, :count, :focus, :height,
68
69
  :keycode, :keysym, :keysym_number, :mode, :mousewheel_delta,
69
70
  :override_redirect, :place, :property, :root, :send_event,
70
71
  :subwindow, :type, :unicode, :width, :window, :window_path
@@ -85,6 +86,11 @@ module Tk
85
86
  def widget
86
87
  Tk.widgets[window_path]
87
88
  end
89
+
90
+ def sequence
91
+ Kernel.warn("#{self.class}.sequence deprecated, use #{self.class}.pattern")
92
+ pattern
93
+ end
88
94
  end
89
95
  end
90
96
  end
@@ -27,7 +27,15 @@ module Tk
27
27
 
28
28
  def register(tag, sequence, &block)
29
29
  id = register_block(block)
30
- Tk.interp.eval(@callback % [tag, sequence, id, sequence])
30
+ if sequence.to_s == '%'
31
+ Tk.interp.eval(
32
+ @callback % [tag, '%%'.to_tcl, id, '%%'.to_tcl]
33
+ )
34
+ else
35
+ Tk.interp.eval(
36
+ @callback % [tag, sequence.to_tcl, id, sequence.to_tcl]
37
+ )
38
+ end
31
39
  @bound[[tag, sequence]] = block
32
40
  id
33
41
  end
@@ -7,7 +7,7 @@ require 'ffi-tk/ffi/tcl/eval_result'
7
7
  module FFI
8
8
  module Tcl
9
9
  extend FFI::Library
10
- ffi_lib [*::Tk::LIBPATH[:tcl], 'libtcl', 'tcl85', 'libtcl8.5']
10
+ ffi_lib ::Tk::TCL_LIBPATH
11
11
 
12
12
  attach_function :Tcl_AppendAllObjTypes, [Interp, Obj], :int
13
13
  attach_function :Tcl_CreateInterp, [], Interp
@@ -9,19 +9,22 @@ module FFI
9
9
  list = Tcl.new_list_obj(0, nil)
10
10
  Tcl.append_all_obj_types(interp, list)
11
11
 
12
- result_pointer = MemoryPointer.new(:pointer)
13
- count_pointer = MemoryPointer.new(:int)
14
- length_pointer = MemoryPointer.new(:int)
15
-
16
- Tcl.list_obj_length(interp, list, count_pointer)
17
- count = count_pointer.get_int(0)
18
-
19
- (0...count).each do |idx|
20
- Tcl.list_obj_index(interp, list, idx, result_pointer)
21
- element_pointer = result_pointer.get_pointer(0)
22
- name = Tcl.get_string_from_obj(element_pointer, length_pointer)
23
- type = Tcl.get_obj_type(name)
24
- TYPES[type.to_i] = name.to_sym
12
+ objc_ptr = MemoryPointer.new(:int)
13
+ objv_ptr = MemoryPointer.new(:pointer)
14
+
15
+ string_length_ptr = MemoryPointer.new(:int)
16
+
17
+ if Tcl.list_obj_get_elements(interp, list, objc_ptr, objv_ptr) == 0
18
+ array_ptr = objv_ptr.get_pointer(0)
19
+ array_length = objc_ptr.get_int(0)
20
+ array = array_ptr.read_array_of_pointer(array_length)
21
+ array.each do |type_ptr|
22
+ name = Tcl.get_string_from_obj(type_ptr, string_length_ptr)
23
+ type = Tcl.get_obj_type(name)
24
+ TYPES[type.to_i] = name.to_sym
25
+ end
26
+ else
27
+ panic 'Tcl_ListObjGetElements'
25
28
  end
26
29
  end
27
30
 
@@ -65,38 +68,56 @@ module FFI
65
68
  end
66
69
  end
67
70
 
68
- def self.map_list_core(interp, obj)
69
- result_pointer = MemoryPointer.new(:pointer)
70
- count_pointer = MemoryPointer.new(:int)
71
- length_pointer = MemoryPointer.new(:int)
72
-
73
- Tcl.list_obj_length(interp, obj, count_pointer)
74
- count = count_pointer.get_int(0)
71
+ def self.map_list_core(interp, obj, &block)
72
+ objc_ptr = MemoryPointer.new(:int)
73
+ objv_ptr = MemoryPointer.new(:pointer)
75
74
 
76
- (0...count).map do |idx|
77
- Tcl.list_obj_index(interp, obj, idx, result_pointer)
78
- yield result_pointer.get_pointer(0)
75
+ if Tcl.list_obj_get_elements(interp, obj, objc_ptr, objv_ptr) == 0
76
+ objv_ptr.get_pointer(0).
77
+ read_array_of_pointer(objc_ptr.get_int(0)).
78
+ map(&block)
79
+ else
80
+ panic(interp, 'Tcl_ListObjGetElements')
79
81
  end
80
82
  end
81
83
 
82
84
  def self.to_boolean(interp, obj)
83
85
  boolean_pointer = MemoryPointer.new(:int)
84
- Tcl.get_boolean_from_obj(interp, obj, boolean_pointer)
85
- boolean_pointer.get_int(0) == 1
86
+
87
+ if Tcl.get_boolean_from_obj(interp, obj, boolean_pointer) == 0
88
+ boolean_pointer.get_int(0) == 1
89
+ else
90
+ panic(interp, 'Tcl_GetBooleanFromObj')
91
+ end
86
92
  end
87
93
 
88
94
  def self.to_int(interp, obj)
89
95
  int_pointer = MemoryPointer.new(:int)
90
- Tcl.get_int_from_obj(interp, obj, int_pointer)
91
- int_pointer.get_int(0)
96
+
97
+ if Tcl.get_int_from_obj(interp, obj, int_pointer) == 0
98
+ int_pointer.get_int(0)
99
+ else
100
+ panic(interp, 'Tcl_GetIntFromObj')
101
+ end
92
102
  end
93
103
 
94
104
  def self.to_string(interp, obj)
95
105
  length_pointer = MemoryPointer.new(:int)
106
+
96
107
  string = Tcl.get_string_from_obj(obj, length_pointer)
97
108
  string.force_encoding(Encoding.default_external)
98
109
  end
99
110
 
111
+ def self.panic(interp, function)
112
+ message = guess(interp, Obj.new(Tcl.get_obj_result(interp))).to_s
113
+
114
+ if message.empty?
115
+ raise 'Failure during call of: %p' % [function]
116
+ else
117
+ raise '%s during call of: %p' % [message, function]
118
+ end
119
+ end
120
+
100
121
  def to_a(&block)
101
122
  self.class.to_list(interp, obj, &block)
102
123
  end
@@ -7,6 +7,9 @@ module FFI
7
7
  :errorLine, :int
8
8
  )
9
9
 
10
+ EVAL_GLOBAL = 0x20000
11
+ EVAL_DIRECT = 0x40000
12
+
10
13
  def inspect
11
14
  "Interp"
12
15
  end
@@ -82,7 +85,7 @@ module FFI
82
85
  end
83
86
  end
84
87
 
85
- code = Tcl.eval_ex(self, string, string.bytesize, 0x40000)
88
+ code = Tcl.eval_ex(self, string, string.bytesize, EVAL_DIRECT)
86
89
  return true if code == 0
87
90
 
88
91
  message = guess_result.to_s
data/lib/ffi-tk/ffi/tk.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module FFI
2
2
  module Tk
3
3
  extend FFI::Library
4
- ffi_lib [*::Tk::LIBPATH[:tk], 'libtk', 'tk85', 'libtk8.5']
4
+ ffi_lib ::Tk::TK_LIBPATH
5
5
 
6
6
  class XColor < FFI::Struct
7
7
  layout(
data/lib/ffi-tk/tk.rb CHANGED
@@ -14,21 +14,6 @@ module Tk
14
14
 
15
15
  module_function
16
16
 
17
- unless const_defined?(:RUN_EVENTLOOP_ON_MAIN_THREAD)
18
- # In some cases Tk has trouble running, this seems to happen on windows and
19
- # OSX/TkAqua mostly.
20
- # In these cases please use:
21
- # module Tk; RUN_EVENTLOOP_ON_MAIN_THREAD = true; end
22
- # before you require 'tk'
23
- RUN_EVENTLOOP_ON_MAIN_THREAD = false
24
- end
25
-
26
- DONT_WAIT = 1 << 1
27
- WINDOW_EVENTS = 1 << 2
28
- FILE_EVENTS = 1 << 3
29
- TIMER_EVENTS = 1 << 4
30
- IDLE_EVENTS = 1 << 5
31
- ALL_EVENTS = ~DONT_WAIT
32
17
 
33
18
  def init
34
19
  if RUN_EVENTLOOP_ON_MAIN_THREAD
@@ -184,7 +169,7 @@ module Tk
184
169
  parent_name = parent.respond_to?(:tk_pathname) ? parent.tk_pathname : parent
185
170
  cmd = object.class.tk_command
186
171
 
187
- id = "#{cmd}#{uuid(cmd)}"
172
+ id = "#{cmd}#{uuid(cmd)}".gsub('::', '__') # :: is namespace convention.
188
173
  pathname = [parent_name, id].join('.').squeeze('.')
189
174
  @widgets[pathname] = object
190
175
 
@@ -1,3 +1,3 @@
1
1
  module FFI::Tk
2
- VERSION = "2010.03"
2
+ VERSION = "2010.06"
3
3
  end
@@ -2,10 +2,15 @@ module Tk
2
2
  module Tile
3
3
  # combobox combines a text field with a pop-down list of values.
4
4
  # the user may select the value of the text field from among the values in the list.
5
- class ComboBox < Tile::Entry
5
+ class ComboBox < Widget
6
6
  def self.tk_command; 'ttk::combobox'; end
7
+
7
8
  include TileWidget
8
- # include Cget, Configure
9
+ include Cget, Configure
10
+
11
+ def initialize(parent = Tk.root, options = {})
12
+ super
13
+ end
9
14
 
10
15
  def postcommand(&block)
11
16
  configure(:postcommand => block) if block
metadata CHANGED
@@ -1,11 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-tk
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 8047
4
5
  prerelease: false
5
6
  segments:
6
7
  - 2010
7
- - 3
8
- version: "2010.03"
8
+ - 6
9
+ version: "2010.06"
9
10
  platform: ruby
10
11
  authors:
11
12
  - Michael 'manveru' Fellinger
@@ -13,16 +14,18 @@ autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
16
 
16
- date: 2010-03-02 00:00:00 +09:00
17
+ date: 2010-06-03 00:00:00 +09:00
17
18
  default_executable:
18
19
  dependencies:
19
20
  - !ruby/object:Gem::Dependency
20
21
  name: ffi
21
22
  prerelease: false
22
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
23
25
  requirements:
24
26
  - - "="
25
27
  - !ruby/object:Gem::Version
28
+ hash: 3
26
29
  segments:
27
30
  - 0
28
31
  - 6
@@ -34,9 +37,11 @@ dependencies:
34
37
  name: bacon
35
38
  prerelease: false
36
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
37
41
  requirements:
38
42
  - - ">="
39
43
  - !ruby/object:Gem::Version
44
+ hash: 19
40
45
  segments:
41
46
  - 1
42
47
  - 1
@@ -257,16 +262,20 @@ rdoc_options: []
257
262
  require_paths:
258
263
  - lib
259
264
  required_ruby_version: !ruby/object:Gem::Requirement
265
+ none: false
260
266
  requirements:
261
267
  - - ">="
262
268
  - !ruby/object:Gem::Version
269
+ hash: 3
263
270
  segments:
264
271
  - 0
265
272
  version: "0"
266
273
  required_rubygems_version: !ruby/object:Gem::Requirement
274
+ none: false
267
275
  requirements:
268
276
  - - ">="
269
277
  - !ruby/object:Gem::Version
278
+ hash: 29
270
279
  segments:
271
280
  - 1
272
281
  - 3
@@ -275,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
275
284
  requirements: []
276
285
 
277
286
  rubyforge_project:
278
- rubygems_version: 1.3.6
287
+ rubygems_version: 1.3.7
279
288
  signing_key:
280
289
  specification_version: 3
281
290
  summary: Pure Ruby FFI wrapper for the Tk GUI toolkit.