ffi-tk 2009.11.29

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.
Files changed (189) hide show
  1. data/CHANGELOG +748 -0
  2. data/MANIFEST +188 -0
  3. data/README.md +85 -0
  4. data/Rakefile +47 -0
  5. data/TODO.md +62 -0
  6. data/bin/rwish +33 -0
  7. data/doc/MIT_LICENSE +18 -0
  8. data/doc/TCL_LICENSE +39 -0
  9. data/example/choose_color.rb +22 -0
  10. data/example/choose_directory.rb +22 -0
  11. data/example/dialog.rb +37 -0
  12. data/example/hello.rb +11 -0
  13. data/example/message_box.rb +26 -0
  14. data/example/option_menu.rb +17 -0
  15. data/example/popup.rb +24 -0
  16. data/example/set_palette.rb +32 -0
  17. data/example/text.rb +47 -0
  18. data/example/tile/kroc_demo_small.rb +123 -0
  19. data/example/tile/kroc_rb_demo.rb +135 -0
  20. data/example/tile/notebook.rb +48 -0
  21. data/example/tile/theme_hello.rb +38 -0
  22. data/example/tile/treeview.rb +71 -0
  23. data/example/various.rb +25 -0
  24. data/example/wait.rb +16 -0
  25. data/ffi-tk.gemspec +33 -0
  26. data/lib/ffi-tk.rb +76 -0
  27. data/lib/ffi-tk/command.rb +39 -0
  28. data/lib/ffi-tk/command/after.rb +36 -0
  29. data/lib/ffi-tk/command/bell.rb +34 -0
  30. data/lib/ffi-tk/command/bind.rb +11 -0
  31. data/lib/ffi-tk/command/bindtags.rb +69 -0
  32. data/lib/ffi-tk/command/cget.rb +92 -0
  33. data/lib/ffi-tk/command/choose_color.rb +29 -0
  34. data/lib/ffi-tk/command/choose_directory.rb +45 -0
  35. data/lib/ffi-tk/command/clipboard.rb +102 -0
  36. data/lib/ffi-tk/command/configure.rb +88 -0
  37. data/lib/ffi-tk/command/destroy.rb +12 -0
  38. data/lib/ffi-tk/command/dialog.rb +54 -0
  39. data/lib/ffi-tk/command/event.rb +79 -0
  40. data/lib/ffi-tk/command/focus.rb +70 -0
  41. data/lib/ffi-tk/command/font.rb +124 -0
  42. data/lib/ffi-tk/command/get_open_file.rb +85 -0
  43. data/lib/ffi-tk/command/get_save_file.rb +83 -0
  44. data/lib/ffi-tk/command/grab.rb +141 -0
  45. data/lib/ffi-tk/command/grid.rb +246 -0
  46. data/lib/ffi-tk/command/image.rb +79 -0
  47. data/lib/ffi-tk/command/lower.rb +23 -0
  48. data/lib/ffi-tk/command/message_box.rb +65 -0
  49. data/lib/ffi-tk/command/option_menu.rb +8 -0
  50. data/lib/ffi-tk/command/pack.rb +99 -0
  51. data/lib/ffi-tk/command/place.rb +91 -0
  52. data/lib/ffi-tk/command/popup.rb +14 -0
  53. data/lib/ffi-tk/command/raise.rb +25 -0
  54. data/lib/ffi-tk/command/scrollable.rb +151 -0
  55. data/lib/ffi-tk/command/selection.rb +132 -0
  56. data/lib/ffi-tk/command/set_palette.rb +9 -0
  57. data/lib/ffi-tk/command/tk_cmd.rb +155 -0
  58. data/lib/ffi-tk/command/vars.rb +82 -0
  59. data/lib/ffi-tk/command/wait.rb +39 -0
  60. data/lib/ffi-tk/command/winfo.rb +668 -0
  61. data/lib/ffi-tk/command/wm.rb +1025 -0
  62. data/lib/ffi-tk/core_extensions.rb +154 -0
  63. data/lib/ffi-tk/event/data.rb +60 -0
  64. data/lib/ffi-tk/event/handler.rb +44 -0
  65. data/lib/ffi-tk/ffi/tcl.rb +92 -0
  66. data/lib/ffi-tk/ffi/tcl/cmd_proc.rb +10 -0
  67. data/lib/ffi-tk/ffi/tcl/eval_result.rb +148 -0
  68. data/lib/ffi-tk/ffi/tcl/interp.rb +95 -0
  69. data/lib/ffi-tk/ffi/tcl/obj.rb +89 -0
  70. data/lib/ffi-tk/ffi/tcl/time.rb +36 -0
  71. data/lib/ffi-tk/ffi/tk.rb +35 -0
  72. data/lib/ffi-tk/geometry.rb +32 -0
  73. data/lib/ffi-tk/thread_sender.rb +26 -0
  74. data/lib/ffi-tk/tk.rb +222 -0
  75. data/lib/ffi-tk/variable.rb +46 -0
  76. data/lib/ffi-tk/widget.rb +68 -0
  77. data/lib/ffi-tk/widget/button.rb +41 -0
  78. data/lib/ffi-tk/widget/canvas.rb +806 -0
  79. data/lib/ffi-tk/widget/canvas/arc.rb +18 -0
  80. data/lib/ffi-tk/widget/canvas/bitmap.rb +13 -0
  81. data/lib/ffi-tk/widget/canvas/image.rb +10 -0
  82. data/lib/ffi-tk/widget/canvas/item.rb +170 -0
  83. data/lib/ffi-tk/widget/canvas/line.rb +16 -0
  84. data/lib/ffi-tk/widget/canvas/oval.rb +15 -0
  85. data/lib/ffi-tk/widget/canvas/polygon.rb +16 -0
  86. data/lib/ffi-tk/widget/canvas/rectangle.rb +15 -0
  87. data/lib/ffi-tk/widget/canvas/text.rb +15 -0
  88. data/lib/ffi-tk/widget/canvas/window.rb +11 -0
  89. data/lib/ffi-tk/widget/checkbutton.rb +63 -0
  90. data/lib/ffi-tk/widget/entry.rb +208 -0
  91. data/lib/ffi-tk/widget/frame.rb +12 -0
  92. data/lib/ffi-tk/widget/label.rb +26 -0
  93. data/lib/ffi-tk/widget/labelframe.rb +7 -0
  94. data/lib/ffi-tk/widget/listbox.rb +192 -0
  95. data/lib/ffi-tk/widget/menu.rb +318 -0
  96. data/lib/ffi-tk/widget/menubutton.rb +7 -0
  97. data/lib/ffi-tk/widget/message.rb +36 -0
  98. data/lib/ffi-tk/widget/panedwindow.rb +164 -0
  99. data/lib/ffi-tk/widget/radiobutton.rb +43 -0
  100. data/lib/ffi-tk/widget/root.rb +8 -0
  101. data/lib/ffi-tk/widget/scale.rb +44 -0
  102. data/lib/ffi-tk/widget/scrollbar.rb +114 -0
  103. data/lib/ffi-tk/widget/spinbox.rb +198 -0
  104. data/lib/ffi-tk/widget/text.rb +893 -0
  105. data/lib/ffi-tk/widget/text/peer.rb +10 -0
  106. data/lib/ffi-tk/widget/tile.rb +70 -0
  107. data/lib/ffi-tk/widget/tile/button.rb +8 -0
  108. data/lib/ffi-tk/widget/tile/checkbutton.rb +8 -0
  109. data/lib/ffi-tk/widget/tile/combobox.rb +43 -0
  110. data/lib/ffi-tk/widget/tile/entry.rb +8 -0
  111. data/lib/ffi-tk/widget/tile/frame.rb +13 -0
  112. data/lib/ffi-tk/widget/tile/label.rb +9 -0
  113. data/lib/ffi-tk/widget/tile/labelframe.rb +8 -0
  114. data/lib/ffi-tk/widget/tile/menubutton.rb +8 -0
  115. data/lib/ffi-tk/widget/tile/notebook.rb +93 -0
  116. data/lib/ffi-tk/widget/tile/panedwindow.rb +9 -0
  117. data/lib/ffi-tk/widget/tile/progressbar.rb +59 -0
  118. data/lib/ffi-tk/widget/tile/radiobutton.rb +8 -0
  119. data/lib/ffi-tk/widget/tile/scale.rb +8 -0
  120. data/lib/ffi-tk/widget/tile/scrollbar.rb +41 -0
  121. data/lib/ffi-tk/widget/tile/separator.rb +23 -0
  122. data/lib/ffi-tk/widget/tile/sizegrip.rb +24 -0
  123. data/lib/ffi-tk/widget/tile/style.rb +114 -0
  124. data/lib/ffi-tk/widget/tile/treeview.rb +414 -0
  125. data/lib/ffi-tk/widget/toplevel.rb +14 -0
  126. data/spec/ffi-tk/command/bindtags.rb +18 -0
  127. data/spec/ffi-tk/command/clipboard.rb +18 -0
  128. data/spec/ffi-tk/command/font.rb +67 -0
  129. data/spec/ffi-tk/command/grid.rb +6 -0
  130. data/spec/ffi-tk/command/image.rb +26 -0
  131. data/spec/ffi-tk/command/pack.rb +20 -0
  132. data/spec/ffi-tk/command/place.rb +20 -0
  133. data/spec/ffi-tk/command/selection.rb +13 -0
  134. data/spec/ffi-tk/command/vars.rb +32 -0
  135. data/spec/ffi-tk/command/winfo.rb +233 -0
  136. data/spec/ffi-tk/command/wm.rb +185 -0
  137. data/spec/ffi-tk/event.rb +95 -0
  138. data/spec/ffi-tk/tile/button.rb +51 -0
  139. data/spec/ffi-tk/tile/checkbutton.rb +13 -0
  140. data/spec/ffi-tk/tile/combobox.rb +65 -0
  141. data/spec/ffi-tk/tile/entry.rb +61 -0
  142. data/spec/ffi-tk/tile/frame.rb +65 -0
  143. data/spec/ffi-tk/tile/label.rb +17 -0
  144. data/spec/ffi-tk/tile/labelframe.rb +13 -0
  145. data/spec/ffi-tk/tile/menubutton.rb +13 -0
  146. data/spec/ffi-tk/tile/notebook.rb +103 -0
  147. data/spec/ffi-tk/tile/panedwindow.rb +13 -0
  148. data/spec/ffi-tk/tile/progressbar.rb +78 -0
  149. data/spec/ffi-tk/tile/radiobutton.rb +13 -0
  150. data/spec/ffi-tk/tile/scale.rb +13 -0
  151. data/spec/ffi-tk/tile/scrollbar.rb +43 -0
  152. data/spec/ffi-tk/tile/separator.rb +22 -0
  153. data/spec/ffi-tk/tile/sizegrip.rb +13 -0
  154. data/spec/ffi-tk/tile/style.rb +161 -0
  155. data/spec/ffi-tk/tile/treeview.rb +101 -0
  156. data/spec/ffi-tk/variable.rb +24 -0
  157. data/spec/ffi-tk/widget/button.rb +22 -0
  158. data/spec/ffi-tk/widget/canvas.rb +169 -0
  159. data/spec/ffi-tk/widget/checkbutton.rb +44 -0
  160. data/spec/ffi-tk/widget/entry.rb +155 -0
  161. data/spec/ffi-tk/widget/frame.rb +8 -0
  162. data/spec/ffi-tk/widget/label.rb +16 -0
  163. data/spec/ffi-tk/widget/labelframe.rb +12 -0
  164. data/spec/ffi-tk/widget/listbox.rb +19 -0
  165. data/spec/ffi-tk/widget/menu.rb +12 -0
  166. data/spec/ffi-tk/widget/menubutton.rb +12 -0
  167. data/spec/ffi-tk/widget/message.rb +12 -0
  168. data/spec/ffi-tk/widget/panedwindow.rb +12 -0
  169. data/spec/ffi-tk/widget/radiobutton.rb +12 -0
  170. data/spec/ffi-tk/widget/root.rb +9 -0
  171. data/spec/ffi-tk/widget/scale.rb +12 -0
  172. data/spec/ffi-tk/widget/scrollbar.rb +12 -0
  173. data/spec/ffi-tk/widget/spinbox.rb +12 -0
  174. data/spec/ffi-tk/widget/text.rb +246 -0
  175. data/spec/ffi-tk/widget/toplevel.rb +12 -0
  176. data/spec/helper.rb +3 -0
  177. data/tasks/authors.rake +21 -0
  178. data/tasks/bacon.rake +66 -0
  179. data/tasks/changelog.rake +18 -0
  180. data/tasks/gem.rake +22 -0
  181. data/tasks/gem_setup.rake +113 -0
  182. data/tasks/grancher.rake +12 -0
  183. data/tasks/manifest.rake +4 -0
  184. data/tasks/rcov.rake +17 -0
  185. data/tasks/release.rake +65 -0
  186. data/tasks/reversion.rake +8 -0
  187. data/tasks/setup.rake +12 -0
  188. data/tasks/ycov.rake +84 -0
  189. metadata +261 -0
@@ -0,0 +1,92 @@
1
+ module Tk
2
+ module Cget
3
+ CGET_MAP = {}
4
+
5
+ insert = lambda{|type, array|
6
+ array.each{|option| CGET_MAP["-#{option}"] = type } }
7
+
8
+ insert[:integer, %w[
9
+ height width maxundo spacing1 spacing2 spacing3 borderwidth bd
10
+ highlightthickness insertborderwidth insertofftime insertontime
11
+ insertwidth padx pady selectborderwidth endline startline length
12
+ maximum
13
+ ]]
14
+ insert[:boolean, %w[
15
+ autoseparators blockcursor undo exportselection setgrid takefocus
16
+ ]]
17
+ insert[:color, %w[
18
+ inactiveselectbackground disabledbackground disabledforeground background
19
+ bg foreground fg highlightbackground highlightcolor insertbackground
20
+ selectbackground selectforeground readonlybackground
21
+ ]]
22
+ insert[:command, %w[
23
+ invalidcommand invcmd yscrollcommand xscrollcommand validatecommand
24
+ command vcmd
25
+ ]]
26
+ insert[:string, %w[ tabs cursor text show default class ]]
27
+ insert[:font, %w[ font ]]
28
+ insert[:symbol, %w[ wrap tabstyle relief justify validate orient mode selectmode ]]
29
+ insert[:variable, %w[ textvariable ]]
30
+ insert[:bitmap, %w[ stipple ]]
31
+ insert[:list, %w[ padding state style columns displaycolumns ]]
32
+
33
+ def cget(option)
34
+ option = option.to_tcl_option
35
+ Cget.option_to_ruby(option, execute('cget', option))
36
+ end
37
+
38
+ module_function
39
+
40
+ def option_to_ruby(name, value)
41
+ if type = CGET_MAP[name.to_tcl_option]
42
+ type_to_ruby(type, value)
43
+ else
44
+ raise "Unknown type for %p: %p" % [name, value]
45
+ end
46
+ end
47
+
48
+ def type_to_ruby(type, value)
49
+ case type
50
+ when :integer
51
+ value.to_i
52
+ when :symbol
53
+ value.to_sym?
54
+ when :boolean
55
+ Tk.boolean(value)
56
+ when :color, :string, :font, :bitmap
57
+ value.respond_to?(:to_s?) ? value.to_s? : value
58
+ when :variable
59
+ if name = value.to_s?
60
+ Variable.new(name)
61
+ end
62
+ when :list
63
+ value.to_a
64
+ when :float
65
+ value.to_f
66
+ when :pathname
67
+ Tk.pathname_to_widget(value.to_s)
68
+ when :command
69
+ string = value.to_s
70
+ string unless string.empty?
71
+ else
72
+ raise "Unknown type: %p: %p" % [type, value]
73
+ end
74
+ end
75
+
76
+ def option_hash_to_tcl(hash)
77
+ result = {}
78
+
79
+ hash.each do |key, value|
80
+ case type = CGET_MAP[option = key.to_tcl_option]
81
+ when :command
82
+ command = register_command(key, &value)
83
+ result[option] = command
84
+ else
85
+ result[option] = value
86
+ end
87
+ end
88
+
89
+ result
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,29 @@
1
+ module Tk
2
+ module_function
3
+
4
+ # Pops up a dialog box for the user to select a color.
5
+ #
6
+ # If the user selects a color, this method will return the name of the color.
7
+ # If the user cancels the dialog, nil will be returned.
8
+ #
9
+ # The following options are possible:
10
+ #
11
+ # initialcolor: color
12
+ # Specifies the color to display in the dialog.
13
+ #
14
+ # parent: window
15
+ # Makes window the logical parent of the color dialog.
16
+ # The dialog is displayed on top of its parent window.
17
+ #
18
+ # title: string
19
+ # Specifies a string to display as the title of the dialog box.
20
+ # If this option is not specified, then a default title will be displayed.
21
+ #
22
+ # @example usage
23
+ #
24
+ # Tk::Button.new(Tk.root,
25
+ # bg: Tk.choose_color(initial_color: 'gray', title: 'Choose color'))
26
+ def choose_color(options = None)
27
+ Tk.execute(:tk_chooseColor, options.to_tcl_options?).to_s?
28
+ end
29
+ end
@@ -0,0 +1,45 @@
1
+ module Tk
2
+ module_function
3
+
4
+ # Pops up a dialog box for the user to select a directory.
5
+ #
6
+ # The following options are possible:
7
+ #
8
+ # initialdir: dirname
9
+ # Specifies that the directories in directory should be displayed when the
10
+ # dialog pops up.
11
+ # If this parameter is not specified, then the directories in the current
12
+ # working directory are displayed.
13
+ # If the parameter specifies a relative path, the return value will
14
+ # convert the relative path to an absolute path.
15
+ #
16
+ # mustexist: boolean
17
+ # Specifies whether the user may specify non-existent directories.
18
+ # If this parameter is true, then the user may only select directories
19
+ # that already exist.
20
+ # The default value is false.
21
+ #
22
+ # parent: window
23
+ # Makes window the logical parent of the dialog.
24
+ # The dialog is displayed on top of its parent window.
25
+ # On Mac OS X, this turns the file dialog into a sheet attached to the
26
+ # parent window.
27
+ #
28
+ # title: string
29
+ # Specifies a string to display as the title of the
30
+ # dialog box.
31
+ # If this option is not specified, then a default title will be displayed.
32
+ #
33
+ # @example usage
34
+ #
35
+ # dir = Tk.choose_directory(initialdir: '~', title: 'Choose a directory')
36
+ #
37
+ # if dir
38
+ # Tk::Label.new(Tk.root, text: "Selected #{dir}")
39
+ # else
40
+ # Tk::Label.new(Tk.root, text: 'No directory selected')
41
+ # end
42
+ def choose_directory(options = None)
43
+ Tk.execute(:tk_chooseDirectory, options.to_tcl_options?).to_s?
44
+ end
45
+ end
@@ -0,0 +1,102 @@
1
+ module Tk
2
+ # Manipulate Tk clipboard
3
+ #
4
+ # This command provides an interface to the Tk clipboard, which stores data
5
+ # for later retrieval.
6
+ # In order to copy data into the clipboard, [Clipboard.clear] must be called,
7
+ # followed by a sequence of one or more calls to [Clipboard.append].
8
+ # To ensure that the clipboard is updated atomically, all appends should be
9
+ # completed before returning to the event loop.
10
+ module Clipboard
11
+ def clipboard_clear
12
+ Clipboard.clear(self)
13
+ end
14
+
15
+ def clipboard_append(options = {})
16
+ Clipboard.append({displayof: self}.merge(options))
17
+ end
18
+
19
+ def clipboard_get(type = None)
20
+ Clipboard.get(self, type)
21
+ end
22
+
23
+ def clipboard_set(string, options = {})
24
+ clipboard_clear
25
+ clipboard_append(options.merge(data: string))
26
+ end
27
+
28
+ module_function
29
+
30
+ # Claims ownership of the clipboard on window's display and removes any
31
+ # previous contents.
32
+ # Window defaults to ".".
33
+ def clear(window = None)
34
+ if None == window
35
+ Tk.execute_only(:clipboard, :clear)
36
+ else
37
+ Tk.execute_only(:clipboard, :clear, '-displayof', window)
38
+ end
39
+ end
40
+
41
+ # Appends data to the clipboard on window's display in the form given by
42
+ # +type+ with the representation given by +format+ and claims ownership of
43
+ # the clipboard on window's display.
44
+ #
45
+ # +type+ specifies the form in which the selection is to be returned (the
46
+ # desired "target" for conversion, in ICCCM terminology), and should be an
47
+ # atom name such as STRING or FILE_NAME; see the Inter-Client Communication
48
+ # Conventions Manual for complete details.
49
+ # +type+ defaults to STRING.
50
+ #
51
+ # The +format+ argument specifies the representation that should be used to
52
+ # transmit the selection to the requester (the second column of Table 2 of
53
+ # the ICCCM), and defaults to STRING.
54
+ #
55
+ # If +format+ is STRING, the selection is transmitted as 8-bit ASCII
56
+ # characters. If +format+ is ATOM, then the data is divided into fields
57
+ # separated by white space; each field is converted to its atom value, and
58
+ # the 32-bit atom value is transmitted instead of the atom name.
59
+ # For any other +format+, data is divided into fields separated by white
60
+ # space and each field is converted to a 32-bit integer; an array of
61
+ # integers is transmitted to the selection requester.
62
+ # Note that strings passed to clipboard append are concatenated before
63
+ # conversion, so the caller must take care to ensure appropriate spacing
64
+ # across string boundaries.
65
+ # All items appended to the clipboard with the same +type+ must have the
66
+ # same +format+.
67
+ # The +format+ is needed only for compatibility with clipboard requesters
68
+ # that do not use Tk.
69
+ # If the Tk toolkit is being used to retrieve the CLIPBOARD selection then
70
+ # the value is converted back to a string at the requesting end, so +format+
71
+ # is irrelevant.
72
+ def append(options = {})
73
+ args = []
74
+
75
+ displayof, format, type, data =
76
+ options.values_at(:displayof, :format, :type, :data)
77
+
78
+ format = format.to_s.upcase if format
79
+
80
+ args << "-displayof" << displayof if displayof
81
+ args << "-format" << format.to_s.upcase if format
82
+ args << "-type" << type.to_s.upcase if type
83
+ args << "--" << data.to_s
84
+
85
+ Tk.execute_only(:clipboard, :append, *args)
86
+ end
87
+
88
+ # Retrieve data from the clipboard on +window+'s display.
89
+ # +window+ defaults to ".".
90
+ # +type+ specifies the form in which the data is to be returned and should be
91
+ # an atom name such as STRING or FILE_NAME.
92
+ # +type+ defaults to STRING.
93
+ # This is equivalent to `Selection.get(selection: :clipboard)`.
94
+ def get(window = None, type = None)
95
+ options = {}
96
+ options[:displayof] = window unless None == window
97
+ options[:type] = type.to_s.upcase unless None == type
98
+
99
+ Tk.execute(:clipboard, :get, options.to_tcl_options).to_s
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,88 @@
1
+ module Tk
2
+ module Configure
3
+ # Query or modify the configuration options of the widget.
4
+ # If no option is specified, returns a list describing all of the available
5
+ # options for pathName (see Tk_ConfigureInfo for information on the format
6
+ # of this list).
7
+ # If option is specified with no value, then the command returns a list
8
+ # describing the one named option (this list will be identical to the
9
+ # corresponding sublist of the value returned if no option is specified).
10
+ # If one or more option-value pairs are specified, then the command modifies
11
+ # the given widget option(s) to have the given value(s); in this case the
12
+ # command returns an empty string.
13
+ # Option may have any of the values accepted by the text command.
14
+ #
15
+ # @example Usage
16
+ # text.configure(width: 100, height: 200)
17
+ # text.configure(:width)
18
+ # text.configure
19
+ def configure(argument = None, hints = {})
20
+ common_configure([:configure], argument, hints)
21
+ end
22
+
23
+ private
24
+
25
+ def self.common(receiver, invocation, argument, hints = {})
26
+ result =
27
+ if None == argument
28
+ receiver.execute(*invocation)
29
+ elsif argument.respond_to?(:to_tcl_options)
30
+ receiver.execute_only(*invocation, argument.to_tcl_options)
31
+ elsif argument.respond_to?(:to_tcl_option)
32
+ receiver.execute(*invocation, argument.to_tcl_option)
33
+ else
34
+ raise ArgumentError, "Invalid argument: %p" % [argument]
35
+ end
36
+
37
+ if result.respond_to?(:tcl_options_to_hash)
38
+ result.tcl_options_to_hash(hints)
39
+ else
40
+ result
41
+ end
42
+ end
43
+
44
+ def common_configure(invocation, argument, hints = {})
45
+ Configure.common(self, invocation, argument, hints)
46
+ end
47
+
48
+ def register_command(name, &block)
49
+ case name
50
+ when :validatecommand
51
+ # %d Type of action: 1 for insert, 0 for delete, or -1 for focus, forced
52
+ # or textvariable validation.
53
+ # %i Index of char string to be inserted/deleted, if any, otherwise -1.
54
+ # %P The value of the entry if the edit is allowed.
55
+ # If you are configuring the entry widget to have a new textvariable,
56
+ # this will be the value of that textvariable.
57
+ # %s The current value of entry prior to editing.
58
+ # %S The text string being inserted/deleted, if any, {} otherwise.
59
+ # %v The type of validation currently set.
60
+ # %V The type of validation that triggered the callback (key, focusin,
61
+ # focusout, forced).
62
+ # %W The name of the entry widget.
63
+ arg = '%d %i %P %s %S %v %V %W'
64
+ else
65
+ arg = ''
66
+ end
67
+
68
+ @commands ||= {}
69
+
70
+ unregister_command(name)
71
+ id, command = Tk.register_proc(block, arg)
72
+ @commands[name] = id
73
+
74
+ return command
75
+ end
76
+
77
+ def unregister_command(name, id = @commands[name])
78
+ return unless id
79
+ @commands.delete(id)
80
+ Tk.unregister_proc(id)
81
+ end
82
+
83
+ def unregister_commands
84
+ return unless @commands
85
+ @commands.each{|name, id| unregister_command(name, id) }
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,12 @@
1
+ module Tk
2
+ module Destroy
3
+ def self.destroy(*windows)
4
+ Tk.unregister_objects(*windows)
5
+ Tk.execute_only('destroy', *windows)
6
+ end
7
+
8
+ def destroy
9
+ Destroy.destroy(self)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,54 @@
1
+ module Tk
2
+ module_function
3
+
4
+ # Create modal dialog and wait for response
5
+ #
6
+ # @param window
7
+ # Name of top-level window to use for dialog.
8
+ # Any existing window by this name is destroyed.
9
+ #
10
+ # @param title [String]
11
+ # Text to appear in the window manager's title bar for the dialog.
12
+ #
13
+ # @param text [String]
14
+ # Message to appear in the top portion of the dialog box.
15
+ #
16
+ # @param bitmap [nil String]
17
+ # If non-nil, specifies a bitmap to display in the top portion of the
18
+ # dialog, to the left of the text.
19
+ # If this is nil then no bitmap is displayed in the dialog.
20
+ #
21
+ # @param default [nil Fixnum]
22
+ # If this is an integer greater than or equal to zero, then it gives the
23
+ # index of the button that is to be the default button for the dialog (0 for
24
+ # the leftmost button, and so on).
25
+ # If less than zero or nil then there will not be any default button.
26
+ #
27
+ # @param answers
28
+ # There will be one button for each of these arguments.
29
+ # Each answer element specifies text to display in a button, in order from
30
+ # left to right.
31
+ #
32
+ # After creating a dialog box, [dialog] waits for the user to select one of
33
+ # the buttons either by clicking on the button with the mouse or by typing
34
+ # return to invoke the default button (if any).
35
+ #
36
+ # Then it returns the index of the selected button: 0 for the leftmost button,
37
+ # 1 for the button next to it, and so on.
38
+ # If the dialog's window is destroyed before the user selects one of the
39
+ # buttons, then nil is returned.
40
+ #
41
+ # While waiting for the user to respond, [dialog] sets a local grab.
42
+ # This prevents the user from interacting with the application in any way
43
+ # except to invoke the dialog box.
44
+ #
45
+ # @example usage
46
+ #
47
+ # reply = Tk.dialog('.foo', 'The Title', 'Do you want to say yes?',
48
+ # 'questhead', 0, 'Yes', 'No', "I'm not sure")
49
+ def dialog(window, title, text, bitmap, default, *answers)
50
+ answer = Tk.execute(:tk_dialog,
51
+ window, title, text, bitmap, default, *answers).to_i
52
+ return answer unless answer == -1
53
+ end
54
+ end
@@ -0,0 +1,79 @@
1
+ module Tk
2
+ # Miscellaneous event facilities: define virtual events and generate events
3
+ #
4
+ # The event command provides several facilities for dealing with window system
5
+ # events, such as defining virtual events and synthesizing events.
6
+ #
7
+ # Please note that virtual event means events that are generated inside the
8
+ # application and are written as "<<virtual>>", where virtual is the name of the
9
+ # event.
10
+ #
11
+ # Sequences are names for single keys, or key combinations, also various other
12
+ # actions create events, such as <MouseWheel> or <Destroy>.
13
+ # A sequence is written as "<Control-Alt-Delete>", so only one enclosing <>
14
+ # pair to distinguish them from virtual events.
15
+ module Event
16
+ # Associates the virtual event virtual with the physical event sequence(s)
17
+ # given by the sequence arguments, so that the virtual event will trigger
18
+ # whenever any one of the sequences occurs.
19
+ # Virtual may be any string value and sequence may have any of the values
20
+ # allowed for the sequence argument to the bind command.
21
+ # If virtual is already defined, the new physical event sequences add to the
22
+ # existing sequences for the event.
23
+ def self.add(virtual, *sequences)
24
+ Tk.execute_only(:event, :add, virtual, *sequences)
25
+ end
26
+
27
+ # Deletes each of the sequences from those associated with the virtual event
28
+ # given by virtual.
29
+ # Virtual may be any string value and sequence may have any of the values
30
+ # allowed for the sequence argument to the bind command.
31
+ # Any sequences not currently associated with virtual are ignored.
32
+ # If no sequence argument is provided, all physical event sequences are
33
+ # removed for virtual, so that the virtual event will not trigger anymore.
34
+ def self.delete(virtual, *sequences)
35
+ Tk.execute_only(:event, :delete, virtual, *sequences)
36
+ end
37
+
38
+ # Generates a window event and arranges for it to be processed just as if it
39
+ # had come from the window system.
40
+ # +window+ gives the path name of the window for which the event will be
41
+ # generated; it may also be an identifier (such as returned by winfo id) as
42
+ # long as it is for a window in the current application.
43
+ # Event provides a basic description of the event, such as <Shift-Button-2>
44
+ # or <<Paste>>.
45
+ # If +window+ is empty the whole screen is meant, and coordinates are
46
+ # relative to the screen.
47
+ # Event may have any of the forms allowed for the sequence argument of the
48
+ # bind command except that it must consist of a single event pattern, not a
49
+ # sequence.
50
+ #
51
+ # +options+ may be used to specify additional attributes of the event, such
52
+ # as the x and y mouse position.
53
+ # See the documentation of [EventData] for a comprehensive list.
54
+ #
55
+ # If the :when option is not specified, the event is processed immediately:
56
+ # all of the handlers for the event will complete before the event generate
57
+ # command returns
58
+ #
59
+ # If the :when option is specified then it determines when the event is
60
+ # processed. Certain events, such as key events, require that the window has
61
+ # focus to receive the event properly.
62
+ def self.generate(window = None, event = None, options = {})
63
+ Tk.execute_only(:event, :generate, window, event, options)
64
+ end
65
+
66
+ # Returns information about virtual events.
67
+ # If the <<virtual>> argument is omitted, the return value is a list of all
68
+ # the virtual events that are currently defined.
69
+ #
70
+ # If <<virtual>> is specified then the return value is a list whose elements
71
+ # are the physical event sequences currently defined for the given virtual
72
+ # event; if the virtual event is not defined then an empty string is
73
+ # returned. Note that virtual events that that are not bound to physical
74
+ # event sequences are not returned by event info.
75
+ def self.info(virtual = None)
76
+ Tk.execute(:event, :info, virtual).to_a
77
+ end
78
+ end
79
+ end