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.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +371 -0
- data/AUTHORS +4 -2
- data/CHANGELOG +302 -262
- data/Gemfile +10 -0
- data/Gemfile.lock +45 -0
- data/MANIFEST +6 -6
- data/README.md +1 -1
- data/Rakefile +12 -11
- data/bin/rwish +6 -5
- data/example/choose_color.rb +5 -4
- data/example/choose_directory.rb +5 -4
- data/example/dialog.rb +9 -8
- data/example/hello.rb +2 -1
- data/example/message_box.rb +8 -5
- data/example/option_menu.rb +4 -3
- data/example/popup.rb +4 -3
- data/example/set_palette.rb +5 -4
- data/example/text.rb +30 -30
- data/example/tile/kroc_demo_small.rb +51 -55
- data/example/tile/kroc_rb_demo.rb +74 -83
- data/example/tile/notebook.rb +6 -9
- data/example/tile/theme_hello.rb +6 -8
- data/example/tile/themes.rb +4 -2
- data/example/tile/treeview.rb +16 -14
- data/example/tkgo.rb +120 -88
- data/example/various.rb +8 -7
- data/example/wait.rb +3 -2
- data/ffi-tk.gemspec +21 -20
- data/gemset.nix +134 -0
- data/lib/ffi-tk.rb +10 -11
- data/lib/ffi-tk/command.rb +3 -2
- data/lib/ffi-tk/command/after.rb +8 -7
- data/lib/ffi-tk/command/bell.rb +2 -1
- data/lib/ffi-tk/command/bind.rb +1 -0
- data/lib/ffi-tk/command/bindtags.rb +1 -0
- data/lib/ffi-tk/command/cget.rb +31 -24
- data/lib/ffi-tk/command/choose_color.rb +2 -1
- data/lib/ffi-tk/command/choose_directory.rb +2 -1
- data/lib/ffi-tk/command/clipboard.rb +6 -5
- data/lib/ffi-tk/command/configure.rb +23 -21
- data/lib/ffi-tk/command/destroy.rb +2 -1
- data/lib/ffi-tk/command/dialog.rb +4 -3
- data/lib/ffi-tk/command/event.rb +1 -0
- data/lib/ffi-tk/command/focus.rb +2 -1
- data/lib/ffi-tk/command/font.rb +12 -9
- data/lib/ffi-tk/command/get_open_file.rb +1 -0
- data/lib/ffi-tk/command/get_save_file.rb +1 -0
- data/lib/ffi-tk/command/grab.rb +2 -1
- data/lib/ffi-tk/command/grid.rb +7 -6
- data/lib/ffi-tk/command/image.rb +5 -4
- data/lib/ffi-tk/command/lower.rb +1 -0
- data/lib/ffi-tk/command/message_box.rb +2 -1
- data/lib/ffi-tk/command/option_menu.rb +3 -2
- data/lib/ffi-tk/command/pack.rb +5 -4
- data/lib/ffi-tk/command/place.rb +5 -4
- data/lib/ffi-tk/command/popup.rb +2 -1
- data/lib/ffi-tk/command/raise.rb +1 -0
- data/lib/ffi-tk/command/scrollable.rb +7 -10
- data/lib/ffi-tk/command/selection.rb +4 -3
- data/lib/ffi-tk/command/set_palette.rb +2 -1
- data/lib/ffi-tk/command/tk_cmd.rb +1 -0
- data/lib/ffi-tk/command/vars.rb +2 -1
- data/lib/ffi-tk/command/wait.rb +2 -1
- data/lib/ffi-tk/command/winfo.rb +9 -8
- data/lib/ffi-tk/command/wm.rb +11 -10
- data/lib/ffi-tk/core_extensions.rb +5 -4
- data/lib/ffi-tk/event/data.rb +32 -31
- data/lib/ffi-tk/event/handler.rb +4 -3
- data/lib/ffi-tk/ffi/tcl.rb +42 -31
- data/lib/ffi-tk/ffi/tcl/cmd_proc.rb +2 -1
- data/lib/ffi-tk/ffi/tcl/eval_result.rb +47 -8
- data/lib/ffi-tk/ffi/tcl/interp.rb +7 -4
- data/lib/ffi-tk/ffi/tcl/obj.rb +7 -32
- data/lib/ffi-tk/ffi/tcl/time.rb +2 -1
- data/lib/ffi-tk/ffi/tk.rb +8 -7
- data/lib/ffi-tk/geometry.rb +20 -17
- data/lib/ffi-tk/thread_sender.rb +1 -0
- data/lib/ffi-tk/tk.rb +23 -23
- data/lib/ffi-tk/variable.rb +25 -3
- data/lib/ffi-tk/version.rb +1 -1
- data/lib/ffi-tk/widget.rb +2 -1
- data/lib/ffi-tk/widget/button.rb +4 -1
- data/lib/ffi-tk/widget/canvas.rb +18 -15
- data/lib/ffi-tk/widget/canvas/arc.rb +2 -1
- data/lib/ffi-tk/widget/canvas/bitmap.rb +2 -1
- data/lib/ffi-tk/widget/canvas/image.rb +2 -1
- data/lib/ffi-tk/widget/canvas/item.rb +4 -4
- data/lib/ffi-tk/widget/canvas/line.rb +2 -1
- data/lib/ffi-tk/widget/canvas/oval.rb +2 -1
- data/lib/ffi-tk/widget/canvas/polygon.rb +2 -1
- data/lib/ffi-tk/widget/canvas/rectangle.rb +2 -1
- data/lib/ffi-tk/widget/canvas/text.rb +2 -1
- data/lib/ffi-tk/widget/canvas/window.rb +2 -1
- data/lib/ffi-tk/widget/checkbutton.rb +4 -1
- data/lib/ffi-tk/widget/entry.rb +4 -1
- data/lib/ffi-tk/widget/frame.rb +4 -1
- data/lib/ffi-tk/widget/label.rb +4 -1
- data/lib/ffi-tk/widget/labelframe.rb +4 -1
- data/lib/ffi-tk/widget/listbox.rb +5 -2
- data/lib/ffi-tk/widget/menu.rb +4 -1
- data/lib/ffi-tk/widget/menubutton.rb +4 -1
- data/lib/ffi-tk/widget/message.rb +4 -1
- data/lib/ffi-tk/widget/panedwindow.rb +5 -2
- data/lib/ffi-tk/widget/radiobutton.rb +4 -1
- data/lib/ffi-tk/widget/root.rb +1 -0
- data/lib/ffi-tk/widget/scale.rb +4 -1
- data/lib/ffi-tk/widget/scrollbar.rb +4 -1
- data/lib/ffi-tk/widget/spinbox.rb +4 -1
- data/lib/ffi-tk/widget/text.rb +20 -16
- data/lib/ffi-tk/widget/text/peer.rb +1 -0
- data/lib/ffi-tk/widget/tile.rb +2 -1
- data/lib/ffi-tk/widget/tile/button.rb +4 -1
- data/lib/ffi-tk/widget/tile/checkbutton.rb +4 -1
- data/lib/ffi-tk/widget/tile/combobox.rb +5 -2
- data/lib/ffi-tk/widget/tile/entry.rb +4 -1
- data/lib/ffi-tk/widget/tile/frame.rb +4 -1
- data/lib/ffi-tk/widget/tile/label.rb +4 -2
- data/lib/ffi-tk/widget/tile/labelframe.rb +4 -1
- data/lib/ffi-tk/widget/tile/menubutton.rb +4 -1
- data/lib/ffi-tk/widget/tile/notebook.rb +4 -1
- data/lib/ffi-tk/widget/tile/panedwindow.rb +4 -1
- data/lib/ffi-tk/widget/tile/progressbar.rb +4 -2
- data/lib/ffi-tk/widget/tile/radiobutton.rb +4 -1
- data/lib/ffi-tk/widget/tile/scale.rb +4 -1
- data/lib/ffi-tk/widget/tile/scrollbar.rb +7 -4
- data/lib/ffi-tk/widget/tile/separator.rb +4 -1
- data/lib/ffi-tk/widget/tile/sizegrip.rb +4 -1
- data/lib/ffi-tk/widget/tile/style.rb +16 -17
- data/lib/ffi-tk/widget/tile/treeview.rb +11 -5
- data/lib/ffi-tk/widget/toplevel.rb +4 -1
- data/shell.nix +19 -0
- data/spec/ffi-tk/command/bind.rb +5 -4
- data/spec/ffi-tk/command/bindtags.rb +2 -1
- data/spec/ffi-tk/command/clipboard.rb +4 -3
- data/spec/ffi-tk/command/font.rb +20 -19
- data/spec/ffi-tk/command/image.rb +13 -5
- data/spec/ffi-tk/command/pack.rb +3 -2
- data/spec/ffi-tk/command/place.rb +4 -3
- data/spec/ffi-tk/command/selection.rb +2 -1
- data/spec/ffi-tk/command/vars.rb +3 -2
- data/spec/ffi-tk/command/winfo.rb +10 -10
- data/spec/ffi-tk/command/wm.rb +23 -22
- data/spec/ffi-tk/event.rb +23 -21
- data/spec/ffi-tk/tile/button.rb +8 -8
- data/spec/ffi-tk/tile/checkbutton.rb +1 -1
- data/spec/ffi-tk/tile/combobox.rb +11 -12
- data/spec/ffi-tk/tile/entry.rb +18 -19
- data/spec/ffi-tk/tile/frame.rb +13 -13
- data/spec/ffi-tk/tile/label.rb +2 -2
- data/spec/ffi-tk/tile/labelframe.rb +1 -1
- data/spec/ffi-tk/tile/menubutton.rb +1 -1
- data/spec/ffi-tk/tile/notebook.rb +22 -20
- data/spec/ffi-tk/tile/panedwindow.rb +1 -1
- data/spec/ffi-tk/tile/progressbar.rb +1 -1
- data/spec/ffi-tk/tile/radiobutton.rb +1 -1
- data/spec/ffi-tk/tile/scale.rb +1 -1
- data/spec/ffi-tk/tile/scrollbar.rb +1 -16
- data/spec/ffi-tk/tile/separator.rb +2 -2
- data/spec/ffi-tk/tile/sizegrip.rb +1 -1
- data/spec/ffi-tk/tile/style.rb +63 -65
- data/spec/ffi-tk/tile/treeview.rb +11 -10
- data/spec/ffi-tk/variable.rb +5 -4
- data/spec/ffi-tk/widget/button.rb +3 -2
- data/spec/ffi-tk/widget/canvas.rb +59 -58
- data/spec/ffi-tk/widget/checkbutton.rb +6 -5
- data/spec/ffi-tk/widget/entry.rb +112 -103
- data/spec/ffi-tk/widget/frame.rb +2 -1
- data/spec/ffi-tk/widget/label.rb +2 -1
- data/spec/ffi-tk/widget/labelframe.rb +1 -0
- data/spec/ffi-tk/widget/listbox.rb +5 -4
- data/spec/ffi-tk/widget/menu.rb +3 -2
- data/spec/ffi-tk/widget/menubutton.rb +1 -0
- data/spec/ffi-tk/widget/message.rb +1 -0
- data/spec/ffi-tk/widget/panedwindow.rb +1 -0
- data/spec/ffi-tk/widget/radiobutton.rb +1 -0
- data/spec/ffi-tk/widget/root.rb +2 -1
- data/spec/ffi-tk/widget/scale.rb +1 -0
- data/spec/ffi-tk/widget/scrollbar.rb +1 -0
- data/spec/ffi-tk/widget/spinbox.rb +1 -0
- data/spec/ffi-tk/widget/text.rb +63 -54
- data/spec/ffi-tk/widget/toplevel.rb +1 -0
- data/spec/helper.rb +3 -1
- data/tasks/authors.rake +3 -2
- data/tasks/bacon.rake +13 -11
- data/tasks/changelog.rake +1 -0
- data/tasks/gem.rake +13 -11
- data/tasks/manifest.rake +2 -1
- data/tasks/release.rake +11 -32
- data/tasks/reversion.rake +2 -1
- metadata +52 -75
- data/spec/ffi-tk/command/grid.rb +0 -6
- data/tasks/gem_setup.rake +0 -113
- data/tasks/grancher.rake +0 -12
- data/tasks/rcov.rake +0 -17
- data/tasks/setup.rake +0 -12
- data/tasks/ycov.rake +0 -84
data/lib/ffi-tk/ffi/tcl/obj.rb
CHANGED
@@ -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,
|
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|
|
21
|
-
|
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
|
-
|
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,
|
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
|
-
|
60
|
+
'#<Obj bytes=%p type=%p>' % [self[:bytes], pretty_type]
|
86
61
|
end
|
87
62
|
end
|
88
63
|
end
|
data/lib/ffi-tk/ffi/tcl/time.rb
CHANGED
data/lib/ffi-tk/ffi/tk.rb
CHANGED
@@ -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, [
|
35
|
-
attach_function :Tk_GetColor, [
|
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
|
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
|
69
|
+
raise message
|
69
70
|
end
|
70
71
|
end
|
71
72
|
end
|
data/lib/ffi-tk/geometry.rb
CHANGED
@@ -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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
self.width
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
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
|
-
|
25
|
+
'=%dx%d%+d%+d' % [width, height, x, y]
|
23
26
|
elsif width && height
|
24
|
-
|
27
|
+
'=%dx%d%' % [width, height]
|
25
28
|
elsif x && y
|
26
|
-
|
29
|
+
'=+d%+d' % [x, y]
|
27
30
|
else
|
28
|
-
raise
|
31
|
+
raise 'Incomplete geometry: %p' % [self]
|
29
32
|
end
|
30
33
|
end
|
31
34
|
end
|
32
|
-
end
|
35
|
+
end
|
data/lib/ffi-tk/thread_sender.rb
CHANGED
data/lib/ffi-tk/tk.rb
CHANGED
@@ -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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
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.
|
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(
|
100
|
-
raise
|
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(
|
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(
|
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
|
150
|
+
array.map do |e|
|
153
151
|
obj = FFI::Tcl::EvalResult.guess(interp, e)
|
154
152
|
case obj
|
155
|
-
when
|
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
|
-
|
176
|
+
pathname
|
177
177
|
end
|
178
178
|
|
179
179
|
def unregister_object(object)
|
180
|
-
@widgets.delete_if{|
|
180
|
+
@widgets.delete_if { |_path, obj| obj == object }
|
181
181
|
end
|
182
182
|
|
183
183
|
def unregister_objects(*objects)
|
184
|
-
@widgets.delete_if{|
|
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
|
-
|
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)
|
data/lib/ffi-tk/variable.rb
CHANGED
@@ -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}"
|
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
|
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
|
data/lib/ffi-tk/version.rb
CHANGED
data/lib/ffi-tk/widget.rb
CHANGED
@@ -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
|
66
|
+
@tk_pathname ||= Tk.register_object(tk_parent, self)
|
66
67
|
end
|
67
68
|
end
|
68
69
|
end
|
data/lib/ffi-tk/widget/button.rb
CHANGED
@@ -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
|
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)
|
data/lib/ffi-tk/widget/canvas.rb
CHANGED
@@ -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
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
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
|
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 =
|
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 =
|
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
|
|