ffi-tk 2010.08.23 → 2018.02.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +7 -0
  4. data/.rubocop_todo.yml +371 -0
  5. data/AUTHORS +4 -2
  6. data/CHANGELOG +302 -262
  7. data/Gemfile +10 -0
  8. data/Gemfile.lock +45 -0
  9. data/MANIFEST +6 -6
  10. data/README.md +1 -1
  11. data/Rakefile +12 -11
  12. data/bin/rwish +6 -5
  13. data/example/choose_color.rb +5 -4
  14. data/example/choose_directory.rb +5 -4
  15. data/example/dialog.rb +9 -8
  16. data/example/hello.rb +2 -1
  17. data/example/message_box.rb +8 -5
  18. data/example/option_menu.rb +4 -3
  19. data/example/popup.rb +4 -3
  20. data/example/set_palette.rb +5 -4
  21. data/example/text.rb +30 -30
  22. data/example/tile/kroc_demo_small.rb +51 -55
  23. data/example/tile/kroc_rb_demo.rb +74 -83
  24. data/example/tile/notebook.rb +6 -9
  25. data/example/tile/theme_hello.rb +6 -8
  26. data/example/tile/themes.rb +4 -2
  27. data/example/tile/treeview.rb +16 -14
  28. data/example/tkgo.rb +120 -88
  29. data/example/various.rb +8 -7
  30. data/example/wait.rb +3 -2
  31. data/ffi-tk.gemspec +21 -20
  32. data/gemset.nix +134 -0
  33. data/lib/ffi-tk.rb +10 -11
  34. data/lib/ffi-tk/command.rb +3 -2
  35. data/lib/ffi-tk/command/after.rb +8 -7
  36. data/lib/ffi-tk/command/bell.rb +2 -1
  37. data/lib/ffi-tk/command/bind.rb +1 -0
  38. data/lib/ffi-tk/command/bindtags.rb +1 -0
  39. data/lib/ffi-tk/command/cget.rb +31 -24
  40. data/lib/ffi-tk/command/choose_color.rb +2 -1
  41. data/lib/ffi-tk/command/choose_directory.rb +2 -1
  42. data/lib/ffi-tk/command/clipboard.rb +6 -5
  43. data/lib/ffi-tk/command/configure.rb +23 -21
  44. data/lib/ffi-tk/command/destroy.rb +2 -1
  45. data/lib/ffi-tk/command/dialog.rb +4 -3
  46. data/lib/ffi-tk/command/event.rb +1 -0
  47. data/lib/ffi-tk/command/focus.rb +2 -1
  48. data/lib/ffi-tk/command/font.rb +12 -9
  49. data/lib/ffi-tk/command/get_open_file.rb +1 -0
  50. data/lib/ffi-tk/command/get_save_file.rb +1 -0
  51. data/lib/ffi-tk/command/grab.rb +2 -1
  52. data/lib/ffi-tk/command/grid.rb +7 -6
  53. data/lib/ffi-tk/command/image.rb +5 -4
  54. data/lib/ffi-tk/command/lower.rb +1 -0
  55. data/lib/ffi-tk/command/message_box.rb +2 -1
  56. data/lib/ffi-tk/command/option_menu.rb +3 -2
  57. data/lib/ffi-tk/command/pack.rb +5 -4
  58. data/lib/ffi-tk/command/place.rb +5 -4
  59. data/lib/ffi-tk/command/popup.rb +2 -1
  60. data/lib/ffi-tk/command/raise.rb +1 -0
  61. data/lib/ffi-tk/command/scrollable.rb +7 -10
  62. data/lib/ffi-tk/command/selection.rb +4 -3
  63. data/lib/ffi-tk/command/set_palette.rb +2 -1
  64. data/lib/ffi-tk/command/tk_cmd.rb +1 -0
  65. data/lib/ffi-tk/command/vars.rb +2 -1
  66. data/lib/ffi-tk/command/wait.rb +2 -1
  67. data/lib/ffi-tk/command/winfo.rb +9 -8
  68. data/lib/ffi-tk/command/wm.rb +11 -10
  69. data/lib/ffi-tk/core_extensions.rb +5 -4
  70. data/lib/ffi-tk/event/data.rb +32 -31
  71. data/lib/ffi-tk/event/handler.rb +4 -3
  72. data/lib/ffi-tk/ffi/tcl.rb +42 -31
  73. data/lib/ffi-tk/ffi/tcl/cmd_proc.rb +2 -1
  74. data/lib/ffi-tk/ffi/tcl/eval_result.rb +47 -8
  75. data/lib/ffi-tk/ffi/tcl/interp.rb +7 -4
  76. data/lib/ffi-tk/ffi/tcl/obj.rb +7 -32
  77. data/lib/ffi-tk/ffi/tcl/time.rb +2 -1
  78. data/lib/ffi-tk/ffi/tk.rb +8 -7
  79. data/lib/ffi-tk/geometry.rb +20 -17
  80. data/lib/ffi-tk/thread_sender.rb +1 -0
  81. data/lib/ffi-tk/tk.rb +23 -23
  82. data/lib/ffi-tk/variable.rb +25 -3
  83. data/lib/ffi-tk/version.rb +1 -1
  84. data/lib/ffi-tk/widget.rb +2 -1
  85. data/lib/ffi-tk/widget/button.rb +4 -1
  86. data/lib/ffi-tk/widget/canvas.rb +18 -15
  87. data/lib/ffi-tk/widget/canvas/arc.rb +2 -1
  88. data/lib/ffi-tk/widget/canvas/bitmap.rb +2 -1
  89. data/lib/ffi-tk/widget/canvas/image.rb +2 -1
  90. data/lib/ffi-tk/widget/canvas/item.rb +4 -4
  91. data/lib/ffi-tk/widget/canvas/line.rb +2 -1
  92. data/lib/ffi-tk/widget/canvas/oval.rb +2 -1
  93. data/lib/ffi-tk/widget/canvas/polygon.rb +2 -1
  94. data/lib/ffi-tk/widget/canvas/rectangle.rb +2 -1
  95. data/lib/ffi-tk/widget/canvas/text.rb +2 -1
  96. data/lib/ffi-tk/widget/canvas/window.rb +2 -1
  97. data/lib/ffi-tk/widget/checkbutton.rb +4 -1
  98. data/lib/ffi-tk/widget/entry.rb +4 -1
  99. data/lib/ffi-tk/widget/frame.rb +4 -1
  100. data/lib/ffi-tk/widget/label.rb +4 -1
  101. data/lib/ffi-tk/widget/labelframe.rb +4 -1
  102. data/lib/ffi-tk/widget/listbox.rb +5 -2
  103. data/lib/ffi-tk/widget/menu.rb +4 -1
  104. data/lib/ffi-tk/widget/menubutton.rb +4 -1
  105. data/lib/ffi-tk/widget/message.rb +4 -1
  106. data/lib/ffi-tk/widget/panedwindow.rb +5 -2
  107. data/lib/ffi-tk/widget/radiobutton.rb +4 -1
  108. data/lib/ffi-tk/widget/root.rb +1 -0
  109. data/lib/ffi-tk/widget/scale.rb +4 -1
  110. data/lib/ffi-tk/widget/scrollbar.rb +4 -1
  111. data/lib/ffi-tk/widget/spinbox.rb +4 -1
  112. data/lib/ffi-tk/widget/text.rb +20 -16
  113. data/lib/ffi-tk/widget/text/peer.rb +1 -0
  114. data/lib/ffi-tk/widget/tile.rb +2 -1
  115. data/lib/ffi-tk/widget/tile/button.rb +4 -1
  116. data/lib/ffi-tk/widget/tile/checkbutton.rb +4 -1
  117. data/lib/ffi-tk/widget/tile/combobox.rb +5 -2
  118. data/lib/ffi-tk/widget/tile/entry.rb +4 -1
  119. data/lib/ffi-tk/widget/tile/frame.rb +4 -1
  120. data/lib/ffi-tk/widget/tile/label.rb +4 -2
  121. data/lib/ffi-tk/widget/tile/labelframe.rb +4 -1
  122. data/lib/ffi-tk/widget/tile/menubutton.rb +4 -1
  123. data/lib/ffi-tk/widget/tile/notebook.rb +4 -1
  124. data/lib/ffi-tk/widget/tile/panedwindow.rb +4 -1
  125. data/lib/ffi-tk/widget/tile/progressbar.rb +4 -2
  126. data/lib/ffi-tk/widget/tile/radiobutton.rb +4 -1
  127. data/lib/ffi-tk/widget/tile/scale.rb +4 -1
  128. data/lib/ffi-tk/widget/tile/scrollbar.rb +7 -4
  129. data/lib/ffi-tk/widget/tile/separator.rb +4 -1
  130. data/lib/ffi-tk/widget/tile/sizegrip.rb +4 -1
  131. data/lib/ffi-tk/widget/tile/style.rb +16 -17
  132. data/lib/ffi-tk/widget/tile/treeview.rb +11 -5
  133. data/lib/ffi-tk/widget/toplevel.rb +4 -1
  134. data/shell.nix +19 -0
  135. data/spec/ffi-tk/command/bind.rb +5 -4
  136. data/spec/ffi-tk/command/bindtags.rb +2 -1
  137. data/spec/ffi-tk/command/clipboard.rb +4 -3
  138. data/spec/ffi-tk/command/font.rb +20 -19
  139. data/spec/ffi-tk/command/image.rb +13 -5
  140. data/spec/ffi-tk/command/pack.rb +3 -2
  141. data/spec/ffi-tk/command/place.rb +4 -3
  142. data/spec/ffi-tk/command/selection.rb +2 -1
  143. data/spec/ffi-tk/command/vars.rb +3 -2
  144. data/spec/ffi-tk/command/winfo.rb +10 -10
  145. data/spec/ffi-tk/command/wm.rb +23 -22
  146. data/spec/ffi-tk/event.rb +23 -21
  147. data/spec/ffi-tk/tile/button.rb +8 -8
  148. data/spec/ffi-tk/tile/checkbutton.rb +1 -1
  149. data/spec/ffi-tk/tile/combobox.rb +11 -12
  150. data/spec/ffi-tk/tile/entry.rb +18 -19
  151. data/spec/ffi-tk/tile/frame.rb +13 -13
  152. data/spec/ffi-tk/tile/label.rb +2 -2
  153. data/spec/ffi-tk/tile/labelframe.rb +1 -1
  154. data/spec/ffi-tk/tile/menubutton.rb +1 -1
  155. data/spec/ffi-tk/tile/notebook.rb +22 -20
  156. data/spec/ffi-tk/tile/panedwindow.rb +1 -1
  157. data/spec/ffi-tk/tile/progressbar.rb +1 -1
  158. data/spec/ffi-tk/tile/radiobutton.rb +1 -1
  159. data/spec/ffi-tk/tile/scale.rb +1 -1
  160. data/spec/ffi-tk/tile/scrollbar.rb +1 -16
  161. data/spec/ffi-tk/tile/separator.rb +2 -2
  162. data/spec/ffi-tk/tile/sizegrip.rb +1 -1
  163. data/spec/ffi-tk/tile/style.rb +63 -65
  164. data/spec/ffi-tk/tile/treeview.rb +11 -10
  165. data/spec/ffi-tk/variable.rb +5 -4
  166. data/spec/ffi-tk/widget/button.rb +3 -2
  167. data/spec/ffi-tk/widget/canvas.rb +59 -58
  168. data/spec/ffi-tk/widget/checkbutton.rb +6 -5
  169. data/spec/ffi-tk/widget/entry.rb +112 -103
  170. data/spec/ffi-tk/widget/frame.rb +2 -1
  171. data/spec/ffi-tk/widget/label.rb +2 -1
  172. data/spec/ffi-tk/widget/labelframe.rb +1 -0
  173. data/spec/ffi-tk/widget/listbox.rb +5 -4
  174. data/spec/ffi-tk/widget/menu.rb +3 -2
  175. data/spec/ffi-tk/widget/menubutton.rb +1 -0
  176. data/spec/ffi-tk/widget/message.rb +1 -0
  177. data/spec/ffi-tk/widget/panedwindow.rb +1 -0
  178. data/spec/ffi-tk/widget/radiobutton.rb +1 -0
  179. data/spec/ffi-tk/widget/root.rb +2 -1
  180. data/spec/ffi-tk/widget/scale.rb +1 -0
  181. data/spec/ffi-tk/widget/scrollbar.rb +1 -0
  182. data/spec/ffi-tk/widget/spinbox.rb +1 -0
  183. data/spec/ffi-tk/widget/text.rb +63 -54
  184. data/spec/ffi-tk/widget/toplevel.rb +1 -0
  185. data/spec/helper.rb +3 -1
  186. data/tasks/authors.rake +3 -2
  187. data/tasks/bacon.rake +13 -11
  188. data/tasks/changelog.rake +1 -0
  189. data/tasks/gem.rake +13 -11
  190. data/tasks/manifest.rake +2 -1
  191. data/tasks/release.rake +11 -32
  192. data/tasks/reversion.rake +2 -1
  193. metadata +52 -75
  194. data/spec/ffi-tk/command/grid.rb +0 -6
  195. data/tasks/gem_setup.rake +0 -113
  196. data/tasks/grancher.rake +0 -12
  197. data/tasks/rcov.rake +0 -17
  198. data/tasks/setup.rake +0 -12
  199. data/tasks/ycov.rake +0 -84
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module FFI
2
3
  module Tcl
3
4
  # Nicer introspection and some accessors.
@@ -8,7 +9,7 @@ module FFI
8
9
  CODE
9
10
 
10
11
  def self.layout(*kvs)
11
- kvs.each_slice(2) do |key, value|
12
+ kvs.each_slice(2) do |key, _value|
12
13
  eval ACCESSOR_CODE.gsub(/\{(.*?)\}/, '{name}' => key, '{sym}' => ":#{key}")
13
14
  end
14
15
 
@@ -17,8 +18,8 @@ module FFI
17
18
 
18
19
  def inspect
19
20
  kvs = members.zip(values)
20
- kvs.map!{|key, value| "%s=%s" % [key, value.inspect] }
21
- "<%s %s>" % [self.class, kvs.join(' ')]
21
+ kvs.map! { |key, value| '%s=%s' % [key, value.inspect] }
22
+ '<%s %s>' % [self.class, kvs.join(' ')]
22
23
  end
23
24
  end
24
25
 
@@ -39,42 +40,16 @@ module FFI
39
40
  end
40
41
 
41
42
  def inspect
42
- "#<ObjType name=%p>" % [self[:name]]
43
+ '#<ObjType name=%p>' % [self[:name]]
43
44
  end
44
45
  end
45
46
 
46
47
  class Obj < PrettyStruct
47
- class InternalRep < Union
48
- class TwoPtrValue < PrettyStruct
49
- layout(
50
- :ptr1, :pointer,
51
- :ptr2, :pointer
52
- )
53
- end
54
-
55
- class PtrAndLongRep < PrettyStruct
56
- layout(
57
- :ptr, :pointer,
58
- :value, :ulong
59
- )
60
- end
61
-
62
- layout(
63
- :longValue, :long,
64
- :doubleValue, :double,
65
- :otherValuePtr, :pointer,
66
- :wideValue, :int64,
67
- :twoPtrValue, TwoPtrValue,
68
- :ptrAndLongRep, PtrAndLongRep
69
- )
70
- end
71
-
72
48
  layout(
73
49
  :refCount, :int,
74
50
  :bytes, :string,
75
51
  :length, :int,
76
- :type, ObjType,
77
- :internalRep, InternalRep
52
+ :type, :pointer
78
53
  )
79
54
 
80
55
  def pretty_type
@@ -82,7 +57,7 @@ module FFI
82
57
  end
83
58
 
84
59
  def inspect
85
- "#<Obj bytes=%p type=%p>" % [self[:bytes], pretty_type]
60
+ '#<Obj bytes=%p type=%p>' % [self[:bytes], pretty_type]
86
61
  end
87
62
  end
88
63
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module FFI
2
3
  module Tcl
3
4
  class TclTime < PrettyStruct
@@ -33,4 +34,4 @@ module FFI
33
34
  alias usec= microseconds=
34
35
  end
35
36
  end
36
- end
37
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module FFI
2
3
  module Tk
3
4
  extend FFI::Library
@@ -31,8 +32,8 @@ module FFI
31
32
  end
32
33
 
33
34
  attach_function :Tk_Init, [:pointer], :int
34
- attach_function :Tk_MainWindow, [Tcl::Interp], Window
35
- attach_function :Tk_GetColor, [Tcl::Interp, Window, name = :string], XColor
35
+ attach_function :Tk_MainWindow, [:pointer], :pointer
36
+ attach_function :Tk_GetColor, [:pointer, :pointer, name = :string], :pointer
36
37
  attach_function :Tk_MainLoop, [], :void
37
38
 
38
39
  module_function
@@ -41,9 +42,9 @@ module FFI
41
42
  if ::Tk::RUN_EVENTLOOP_ON_MAIN_THREAD
42
43
  XColor.new(Tk_GetColor(interp, Tk_MainWindow(interp), string))
43
44
  else
44
- Tcl.thread_sender.thread_send{
45
+ Tcl.thread_sender.thread_send do
45
46
  XColor.new(Tk_GetColor(interp, Tk_MainWindow(interp), string))
46
- }
47
+ end
47
48
  end
48
49
  end
49
50
 
@@ -51,7 +52,7 @@ module FFI
51
52
  if ::Tk::RUN_EVENTLOOP_ON_MAIN_THREAD
52
53
  Tk_MainLoop()
53
54
  else
54
- Tcl.thread_sender.thread_send{ Tk_MainLoop() }
55
+ Tcl.thread_sender.thread_send { Tk_MainLoop() }
55
56
  end
56
57
  end
57
58
 
@@ -59,13 +60,13 @@ module FFI
59
60
  if ::Tk::RUN_EVENTLOOP_ON_MAIN_THREAD
60
61
  if Tk_Init(interp) == 1
61
62
  message = Tcl.Tcl_GetStringResult(interp)
62
- raise RuntimeError, message
63
+ raise message
63
64
  end
64
65
  else
65
66
  Tcl.thread_sender.thread_send do
66
67
  if Tk_Init(interp) == 1
67
68
  message = Tcl.Tcl_GetStringResult(interp)
68
- raise RuntimeError, message
69
+ raise message
69
70
  end
70
71
  end
71
72
  end
@@ -1,32 +1,35 @@
1
+ # frozen_string_literal: true
1
2
  module Tk
2
3
  class TkGeometry < Struct.new(:original, :width, :height, :x, :y)
3
4
  def initialize(tcl_string)
4
- case tcl_string.to_s
5
- when /^\=?(?<width>\d+)x(?<height>\d+)(?<x>[+-]\d+)(?<y>[+-]\d+)$/
6
- md = $~
7
- self.width, self.height, self.x, self.y =
8
- md[:width].to_i, md[:height].to_i, md[:x].to_i, md[:y].to_i
9
- when /^\=?(?<width>\d+)x(?<height>\d+)$/
10
- md = $~
11
- self.width, self.height = md[:width].to_i, md[:height].to_i
12
- when /^\=?(?<x>[+-]\d+)(?<y>[+-]\d+)$/
13
- md = $~
14
- self.x, self.y = md[:x].to_i, md[:y].to_i
5
+ str = tcl_string.to_s
6
+
7
+ if /^\=?(?<width>\d+)x(?<height>\d+)(?<x>[+-]\d+)(?<y>[+-]\d+)$/ =~ str
8
+ self.width = Integer(width)
9
+ self.height = Integer(height)
10
+ self.x = Integer(x)
11
+ self.y = Integer(y)
12
+ elsif /^\=?(?<width>\d+)x(?<height>\d+)$/ =~ str
13
+ self.width = Integer(width)
14
+ self.height = Integer(height)
15
+ elsif /^\=?(?<x>[+-]\d+)(?<y>[+-]\d+)$/ =~ str
16
+ self.x = Integer(x)
17
+ self.y = Integer(y)
15
18
  else
16
- raise "Invalid geometry: %p" % [tcl_string]
19
+ raise 'Invalid geometry: %p' % [tcl_string]
17
20
  end
18
21
  end
19
22
 
20
23
  def to_tcl
21
24
  if width && height && x && y
22
- "=%dx%d%+d%+d" % [width, height, x, y]
25
+ '=%dx%d%+d%+d' % [width, height, x, y]
23
26
  elsif width && height
24
- "=%dx%d%" % [width, height]
27
+ '=%dx%d%' % [width, height]
25
28
  elsif x && y
26
- "=+d%+d" % [x, y]
29
+ '=+d%+d' % [x, y]
27
30
  else
28
- raise "Incomplete geometry: %p" % [self]
31
+ raise 'Incomplete geometry: %p' % [self]
29
32
  end
30
33
  end
31
34
  end
32
- end
35
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class ThreadSender
2
3
  def initialize
3
4
  @queue = Queue.new
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Object
2
3
  undef :type if respond_to?(:type)
3
4
  end
@@ -14,13 +15,12 @@ module Tk
14
15
 
15
16
  module_function
16
17
 
17
-
18
18
  def init
19
- if RUN_EVENTLOOP_ON_MAIN_THREAD
20
- @interp = FFI::Tcl.setup_eventloop_on_main_thread
21
- else
22
- @interp = FFI::Tcl.setup_eventloop_on_new_thread
23
- end
19
+ @interp = if RUN_EVENTLOOP_ON_MAIN_THREAD
20
+ FFI::Tcl.setup_eventloop_on_main_thread
21
+ else
22
+ FFI::Tcl.setup_eventloop_on_new_thread
23
+ end
24
24
 
25
25
  FFI::Tcl.init(@interp)
26
26
  FFI::Tcl::EvalResult.reset_types(@interp)
@@ -35,7 +35,7 @@ module Tk
35
35
 
36
36
  module_eval('class << Tk; attr_reader :interp, :root; end')
37
37
 
38
- return @interp
38
+ @interp
39
39
  end
40
40
 
41
41
  # A little something so people don't have to call Tk.init
@@ -53,9 +53,7 @@ module Tk
53
53
  def mainloop
54
54
  @running = true
55
55
 
56
- while @running && interp.wait_for_event(0.1)
57
- interp.do_one_event(0)
58
- end
56
+ interp.do_one_event(0) while @running && interp.wait_for_event(0.05)
59
57
  end
60
58
 
61
59
  def stop
@@ -72,7 +70,7 @@ module Tk
72
70
 
73
71
  def execute(*args)
74
72
  interp.eval(convert_arguments(*args))
75
- result
73
+ result.tap{|r| puts "eval= %p" % [r] if $DEBUG }
76
74
  end
77
75
 
78
76
  def result
@@ -96,14 +94,14 @@ module Tk
96
94
  end
97
95
 
98
96
  # without our callbacks, nothing goes anymore, abort mission
99
- def tcl_delete(client_data)
100
- raise RuntimeError, "tcl function is going to be removed"
97
+ def tcl_delete(_client_data)
98
+ raise 'tcl function is going to be removed'
101
99
  end
102
100
  TCL_DELETE = method(:tcl_delete)
103
101
 
104
102
  # TODO: support for break and continue return status (by catch/throw)
105
103
  # 1 means true, 0 means false.
106
- def tcl_callback(client_data, interp, objc, objv)
104
+ def tcl_callback(_client_data, interp, objc, objv)
107
105
  cmd, id, *args = tcl_cmd_args(interp, objc, objv)
108
106
  id = id.first if id.is_a?(Array)
109
107
 
@@ -126,7 +124,7 @@ module Tk
126
124
  TCL_CALLBACK = method(:tcl_callback)
127
125
 
128
126
  # TODO: support for break and continue return status (by catch/throw)
129
- def tcl_event(client_data, interp, objc, objv)
127
+ def tcl_event(_client_data, interp, objc, objv)
130
128
  cmd, id, sequence, *args = tcl_cmd_args(interp, objc, objv)
131
129
 
132
130
  catch :callback_break do
@@ -149,15 +147,17 @@ module Tk
149
147
  def tcl_cmd_args(interp, objc, objv)
150
148
  length = FFI::MemoryPointer.new(0)
151
149
  array = objv.read_array_of_pointer(objc)
152
- array.map{|e|
150
+ array.map do |e|
153
151
  obj = FFI::Tcl::EvalResult.guess(interp, e)
154
152
  case obj
155
- when Fixnum, Float
153
+ when Integer, Float
156
154
  obj
155
+ when nil
156
+ nil
157
157
  else
158
158
  obj.respond_to?(:dup) ? obj.dup : obj
159
159
  end
160
- }
160
+ end
161
161
  end
162
162
 
163
163
  def handle_callback(id, *args)
@@ -173,20 +173,20 @@ module Tk
173
173
  pathname = [parent_name, id].join('.').squeeze('.')
174
174
  @widgets[pathname] = object
175
175
 
176
- return pathname
176
+ pathname
177
177
  end
178
178
 
179
179
  def unregister_object(object)
180
- @widgets.delete_if{|path, obj| obj == object }
180
+ @widgets.delete_if { |_path, obj| obj == object }
181
181
  end
182
182
 
183
183
  def unregister_objects(*objects)
184
- @widgets.delete_if{|path, obj| objects.include?(obj) }
184
+ @widgets.delete_if { |_path, obj| objects.include?(obj) }
185
185
  end
186
186
 
187
187
  def register_proc(proc, argument_string = '')
188
- id = uuid(:proc){|uuid| @callbacks[uuid] = proc }
189
- return id, %(RubyFFI::callback #{id} #{argument_string})
188
+ id = uuid(:proc) { |uuid| @callbacks[uuid] = proc }
189
+ [id, %(RubyFFI::callback #{id} #{argument_string})]
190
190
  end
191
191
 
192
192
  def unregister_proc(id)
@@ -1,11 +1,14 @@
1
+ # frozen_string_literal: true
1
2
  module Tk
2
3
  # This class is used for communication of variables with Tcl.
3
4
  class Variable
5
+ include Comparable
6
+
4
7
  attr_reader :name, :tcl_name, :bytesize
5
8
 
6
9
  def initialize(name, value = None)
7
10
  @name = name.freeze
8
- @tcl_name = "$#{name}".freeze
11
+ @tcl_name = "$#{name}"
9
12
  set(value) unless None == value
10
13
  end
11
14
 
@@ -36,11 +39,30 @@ module Tk
36
39
  end
37
40
 
38
41
  def to_boolean
39
- get.to_boolean
42
+ got = get
43
+
44
+ if got.respond_to?(:to_boolean)
45
+ got.to_boolean
46
+ elsif got == '0'
47
+ false
48
+ elsif got == '1'
49
+ true
50
+ else
51
+ got
52
+ end
40
53
  end
41
54
 
42
55
  def to_f
43
56
  get.to_f
44
57
  end
58
+
59
+ def <=>(other)
60
+ case other
61
+ when self.class
62
+ get <=> other.get
63
+ else
64
+ get <=> other
65
+ end
66
+ end
45
67
  end
46
- end
68
+ end
@@ -1,3 +1,3 @@
1
1
  module FFI::Tk
2
- VERSION = "2010.08.23"
2
+ VERSION = "2018.02.20"
3
3
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Tk
2
3
  class Widget
3
4
  include Pack, Destroy, Bind, Bindtags, WM, Winfo, Grid, Clipboard, Place, TkCmd
@@ -62,7 +63,7 @@ module Tk
62
63
  private
63
64
 
64
65
  def assign_pathname
65
- @tk_pathname = Tk.register_object(tk_parent, self)
66
+ @tk_pathname ||= Tk.register_object(tk_parent, self)
66
67
  end
67
68
  end
68
69
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Tk
2
3
  # A button is a widget that displays a textual string, bitmap or image.
3
4
  # If text is displayed, it must all be in a single font, but it can occupy
@@ -13,7 +14,9 @@ module Tk
13
14
  class Button < Widget
14
15
  include Cget, Configure
15
16
 
16
- def self.tk_command; 'button'; end
17
+ def self.tk_command
18
+ 'button'
19
+ end
17
20
 
18
21
  # TODO: implement custom procs
19
22
  def initialize(parent = Tk.root, options = None, &block)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Tk
2
3
  # Canvas widgets implement structured graphics.
3
4
  #
@@ -11,20 +12,22 @@ module Tk
11
12
  # mouse cursor over an item.
12
13
  # This means that items in a canvas can have behaviors defined.
13
14
  class Canvas < Widget
14
- require "ffi-tk/widget/canvas/item.rb"
15
- require "ffi-tk/widget/canvas/arc.rb"
16
- require "ffi-tk/widget/canvas/bitmap.rb"
17
- require "ffi-tk/widget/canvas/image.rb"
18
- require "ffi-tk/widget/canvas/line.rb"
19
- require "ffi-tk/widget/canvas/oval.rb"
20
- require "ffi-tk/widget/canvas/polygon.rb"
21
- require "ffi-tk/widget/canvas/rectangle.rb"
22
- require "ffi-tk/widget/canvas/text.rb"
23
- require "ffi-tk/widget/canvas/window.rb"
15
+ require 'ffi-tk/widget/canvas/item.rb'
16
+ require 'ffi-tk/widget/canvas/arc.rb'
17
+ require 'ffi-tk/widget/canvas/bitmap.rb'
18
+ require 'ffi-tk/widget/canvas/image.rb'
19
+ require 'ffi-tk/widget/canvas/line.rb'
20
+ require 'ffi-tk/widget/canvas/oval.rb'
21
+ require 'ffi-tk/widget/canvas/polygon.rb'
22
+ require 'ffi-tk/widget/canvas/rectangle.rb'
23
+ require 'ffi-tk/widget/canvas/text.rb'
24
+ require 'ffi-tk/widget/canvas/window.rb'
24
25
 
25
26
  include Cget, Configure
26
27
 
27
- def self.tk_command; 'canvas'; end
28
+ def self.tk_command
29
+ 'canvas'
30
+ end
28
31
 
29
32
  # For each item that meets the constraints specified by +search_spec+ and
30
33
  # the +args+, add +tag+ to the list of tags associated with the item if it
@@ -169,12 +172,12 @@ module Tk
169
172
  end
170
173
  end
171
174
 
172
- name = "#{tag_or_id}".scan(/\w+/).join('_')
175
+ name = tag_or_id.to_s.scan(/\w+/).join('_')
173
176
  @events ||= {}
174
177
  # unregister_event(name)
175
178
 
176
179
  Event::Handler.register_custom(script) do |id|
177
- code = "%s bind %s %s { ::RubyFFI::event %d %s %s }"
180
+ code = '%s bind %s %s { ::RubyFFI::event %d %s %s }'
178
181
  props = Event::Data::PROPERTIES.transpose[0].join(' ')
179
182
  tcl = code % [tk_pathname, tag_or_id, sequence, id, sequence, props]
180
183
  Tk.interp.eval(tcl)
@@ -250,7 +253,7 @@ module Tk
250
253
  # Line items support coordinate indexing operations using the methods
251
254
  # [dchars], [index], and [insert].
252
255
  def create_line(*arguments)
253
- options, coords = arguments.partition{|arg| arg.respond_to?(:to_tcl_options) }
256
+ options, coords = arguments.partition { |arg| arg.respond_to?(:to_tcl_options) }
254
257
  create(:line, coords, options.first)
255
258
  end
256
259
 
@@ -264,7 +267,7 @@ module Tk
264
267
  # display. Polygon items support coordinate indexing operations using the
265
268
  # methods [dchars], [index], or [insert].
266
269
  def create_polygon(*arguments)
267
- options, coords = arguments.partition{|arg| arg.respond_to?(:to_tcl_options) }
270
+ options, coords = arguments.partition { |arg| arg.respond_to?(:to_tcl_options) }
268
271
  create(:polygon, coords, options.first)
269
272
  end
270
273