ffi-tk 2009.11.29

Sign up to get free protection for your applications and to get access to all the features.
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,91 @@
1
+ module Tk
2
+ # Geometry manager for fixed or rubber-sheet placement
3
+ #
4
+ # The placer is a geometry manager for Tk. It provides simple fixed placement
5
+ # of windows, where you specify the exact size and location of one window,
6
+ # called the slave, within another window, called the master.
7
+ # The placer also provides rubber-sheet placement, where you specify the size
8
+ # and location of the slave in terms of the dimensions of the master, so that
9
+ # the slave changes size and location in response to changes in the size of
10
+ # the master.
11
+ # Lastly, the placer allows you to mix these styles of placement so that, for
12
+ # example, the slave has a fixed width and height but is centered inside the
13
+ # master.
14
+ module Place
15
+ # Arrange for the placer to manage the geometry of a +window+.
16
+ # The remaining arguments consist of a hash that specifies the way in which
17
+ # +window+'s geometry is managed.
18
+ # Option may have any of the values accepted by [Place.configure].
19
+ def self.place(window, options = {})
20
+ args = options.map{|k,v| ["-#{k}", v] }.flatten
21
+ Tk.execute_only('place', window, *args)
22
+ end
23
+
24
+ # Query or modify the geometry options of the slave given by window.
25
+ # If no option is specified, this command returns a list describing the
26
+ # available options (see Tk_ConfigureInfo for information on the format of
27
+ # this list).
28
+ # If option is specified with no value, then the command returns a list
29
+ # describing the one named option (this list will be identical to the
30
+ # corresponding sublist of the value returned if no option is specified).
31
+ # If one or more options are specified, then the command modifies the given
32
+ # option(s) to have the given value(s); in this case the command returns
33
+ # nil.
34
+ def self.configure(window, options = None)
35
+ if options == None
36
+ Tk.execute('place', 'configure', window)
37
+ else
38
+ Tk.execute_only('place', 'configure', window, options)
39
+ end
40
+ end
41
+
42
+ def self.forget(window)
43
+ Tk.execute_only('place', 'forget', window)
44
+ end
45
+
46
+ def self.info(window)
47
+ info = Tk.execute('place', 'info', window).to_s
48
+
49
+ array = info.split.each_slice(2).map{|key, value|
50
+ case key = key[1..-1].to_sym
51
+ when :anchor, :in
52
+ [key, value]
53
+ when :bordermode
54
+ [key, value.to_sym]
55
+ when :height, :width, :x, :y
56
+ [key, value.to_i]
57
+ when :relheight, :relwidth, :relx, :rely
58
+ [key, value.to_f]
59
+ else
60
+ raise "Unknown info pair: %p => %p" % [key, value]
61
+ end
62
+ }
63
+
64
+ Hash[array]
65
+ end
66
+
67
+ def self.slaves(window)
68
+ Tk.execute('place', 'slaves', window)
69
+ end
70
+
71
+ def place(options = {})
72
+ Place.place(self, options)
73
+ end
74
+
75
+ def place_configure(options = None)
76
+ Place.configure(self, options)
77
+ end
78
+
79
+ def place_forget
80
+ Place.forget(self)
81
+ end
82
+
83
+ def place_info
84
+ Place.info(self)
85
+ end
86
+
87
+ def place_slaves
88
+ Place.slaves(self)
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,14 @@
1
+ module Tk
2
+ # This procedure posts a menu at a given position on the screen and configures
3
+ # Tk so that the menu and its cascaded children can be traversed with the
4
+ # mouse or the keyboard.
5
+ # +menu+ is the name of a menu widget and +x+ and +y+ are the root coordinates
6
+ # at which to display the menu.
7
+ # If +entry+ is omitted, the menu's upper left corner is positioned at the
8
+ # given point.
9
+ # Otherwise +entry gives the index of an entry in +menu+ and the menu will be
10
+ # positioned so that the +entry+ is positioned over the given point.
11
+ def self.popup(menu, x, y, entry = None)
12
+ Tk.execute_only(:tk_popup, menu, x, y, entry)
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ module Tk
2
+ # Change a window's position in the stacking order
3
+ #
4
+ # FIXME: this will shadow Kernel#raise, alternatives?
5
+ module Raise
6
+ def raise(above = None)
7
+ Raise.raise(self, above)
8
+ end
9
+
10
+ module_function
11
+
12
+ # If the +above+ argument is omitted then the command raises window so that
13
+ # it is above all of its siblings in the stacking order (it will not be
14
+ # obscured by any siblings and will obscure any siblings that overlap it).
15
+ #
16
+ # If +above+ is specified then it must be the path name of a window that is
17
+ # either a sibling of window or the descendant of a sibling of window.
18
+ # In this case the raise command will insert window into the stacking order
19
+ # just above +above+ or the ancestor of +above+ that is a sibling of
20
+ # window); this could end up either raising or lowering window.
21
+ def raise(window, above = None)
22
+ Tk.execute_only(:raise, window, above)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,151 @@
1
+ module Tk
2
+ module Scrollable
3
+
4
+ # Returns a list containing two elements.
5
+ # Each element is a real fraction between 0 and 1; together they describe
6
+ # the portion of the document's horizontal span that is visible in the
7
+ # window. For example, if the first element is .2 and the second element is
8
+ # .6, 20% of the text is off-screen to the left, the middle 40% is visible
9
+ # in the window, and 40% of the text is off-screen to the right.
10
+ # The fractions refer only to the lines that are actually visible in the
11
+ # window: if the lines in the window are all very short, so that they are
12
+ # entirely visible, the returned fractions will be 0 and 1, even if there
13
+ # are other lines in the text that are much wider than the window.
14
+ # These are the same values passed to scrollbars via the -xscrollcommand
15
+ # option.
16
+ def xview(index = None)
17
+ if None == index
18
+ execute(:xview).to_a(&:to_f)
19
+ else
20
+ execute_only(:xview, index)
21
+ end
22
+ end
23
+
24
+ # Adjusts the view in the window so that fraction of the horizontal span of
25
+ # the text is off-screen to the left.
26
+ # Fraction is a fraction between 0 and 1.
27
+ def xview_moveto(fraction)
28
+ execute_only(:xview, :moveto, fraction)
29
+ end
30
+
31
+ # This command shifts the view in the window left or right according to
32
+ # number and what.
33
+ # What must be units, pages or pixels.
34
+ # If what is units or pages then number │ must be an integer, otherwise
35
+ # number may be specified in any of the forms accept│ able to
36
+ # Tk_GetPixels, such as “2.0c” or “1i” (the result is rounded to the
37
+ # nearest │ integer value.
38
+ # If no units are given, pixels are assumed).
39
+ # If what is units, the │ view adjusts left or right by number
40
+ # average-width characters on the display; if │ it is pages then the view
41
+ # adjusts by number screenfuls; if it is pixels then the │ view adjusts by
42
+ # number pixels.
43
+ # If number is negative then characters farther to the left become visible;
44
+ # if it is positive then characters farther to the right become visible.
45
+ def xview_scroll(number, what)
46
+ execute_only(:xview, :scroll, number, what)
47
+ end
48
+
49
+ # Returns a list containing two elements, both of which are real fractions
50
+ # between 0 and 1.
51
+ # The first element gives the position of the first visible pixel of the
52
+ # first character (or image, etc) in the top line in the window, relative
53
+ # to the text as a whole (0.5 means it is halfway through the text, for
54
+ # example). The second element gives the position of the first pixel just
55
+ # after the last visible one in the bottom line of the window, relative to
56
+ # the text as a whole.
57
+ # These are the same values passed to scrollbars via the -yscrollcommand
58
+ # option.
59
+ #
60
+ # This command makes the first character on the line after the one given by
61
+ # number visible at the top of the window.
62
+ # Number must be an integer.
63
+ # This command used to be used for scrolling, but now it is obsolete.
64
+ def yview(index = None)
65
+ if None == index
66
+ execute(:yview).to_a(&:to_f)
67
+ else
68
+ execute_only(:yview, index)
69
+ end
70
+ end
71
+
72
+
73
+ # Adjusts the view in the window so that the pixel given by fraction
74
+ # appears at the top of the top line of the window.
75
+ # Fraction is a fraction between 0 and 1; 0 indicates the first pixel of
76
+ # the first character in the text, 0.33 indicates the pixel that is
77
+ # one-third the way through the text; and so on.
78
+ # Values close to 1 │ will indicate values close to the last pixel in the
79
+ # text (1 actually refers to one │ pixel beyond the last pixel), but in
80
+ # such cases the widget will never scroll │ beyond the last pixel, and so a
81
+ # value of 1 will effectively be rounded back to │ whatever fraction
82
+ # ensures the last pixel is at the bottom of the window, and some │ other
83
+ # pixel is at the top.
84
+ def yview_moveto(fraction)
85
+ execute_only(:yview, :moveto, fraction)
86
+ end
87
+
88
+ # This command adjust the view in the window up or down according to number
89
+ # and what.
90
+ # What must be units, pages or pixels.
91
+ # If what is units or pages then number │ must be an integer, otherwise
92
+ # number may be specified in any of the forms accept│ able to
93
+ # Tk_GetPixels, such as “2.0c” or “1i” (the result is rounded to the
94
+ # nearest │ integer value.
95
+ # If no units are given, pixels are assumed).
96
+ # If what is units, the │ view adjusts up or down by number lines on the
97
+ # display; if it is pages then the │ view adjusts by number screenfuls; if
98
+ # it is pixels then the view adjusts by number │ pixels.
99
+ # If number is negative then earlier positions in the text become visible;
100
+ # if it is positive then later positions in the text become visible.
101
+ def yview_scroll(number, what)
102
+ execute_only(:yview, :scroll, number, what)
103
+ end
104
+
105
+ # Changes the view in the widget's window to make index visible.
106
+ #
107
+ # The widget chooses where index appears in the window:
108
+ # [1] If index is already visible somewhere in the window then the command
109
+ # does nothing.
110
+ # [2] If index is only a few lines off-screen above the window then it will
111
+ # be positioned at the top of the window.
112
+ # [3] If index is only a few lines off-screen below the window then it will
113
+ # be positioned at the bottom of the window.
114
+ # [4] Otherwise, index will be centered in the window.
115
+ #
116
+ # The [yview_pickplace] method has been obsoleted by the [see] method.
117
+ # [see] handles both x- and y-motion to make a location visible, whereas the
118
+ # [yview_pickplace] mode only handles motion in y).
119
+ def yview_pickplace(index)
120
+ execute(:yview, '-pickplace', index)
121
+ end
122
+
123
+ def yscrollbar(sbar)
124
+ @yscrollbar = sbar
125
+ @yscrollbar.orient :vertical
126
+
127
+ self.yscrollcommand {|*arg| @yscrollbar.set(*arg); true }
128
+ @yscrollbar.command {|action,fraction| self.yview_moveto(fraction) }
129
+ @yscrollbar
130
+ end
131
+
132
+ def xscrollbar(sbar)
133
+ @xscrollbar = sbar
134
+ @xscrollbar.orient :horizontal
135
+
136
+ self.xscrollcommand {|*arg| @xscrollbar.set(*arg); true }
137
+ @xscrollbar.command {|action,fraction| self.xview_moveto(fraction) }
138
+ @xscrollbar
139
+ end
140
+
141
+ def xscrollcommand(&block)
142
+ configure(:xscrollcommand => block) if block
143
+ end
144
+
145
+ def yscrollcommand(&block)
146
+ configure(:yscrollcommand => block) if block
147
+ end
148
+
149
+ end
150
+ end
151
+
@@ -0,0 +1,132 @@
1
+ module Tk
2
+ # This command provides a Tcl interface to the X selection mechanism and
3
+ # implements the full selection functionality described in the X Inter-Client
4
+ # Communication Conventions Manual (ICCCM).
5
+ #
6
+ # Note that for management of the CLIPBOARD selection (see below), the
7
+ # clipboard command may also be used.
8
+ module Selection
9
+ def selection_clear(options = {})
10
+ Selection.clear({displayof: self}.merge(options))
11
+ end
12
+
13
+ def selection_get(options = {})
14
+ Selection.get({displayof: self}.merge(options))
15
+ end
16
+
17
+ def selection_handle(options = {}, &command)
18
+ Selection.handle(self, options, &command)
19
+ end
20
+
21
+ def selection_own(options, &command)
22
+ Selection.own(self, options, &command)
23
+ end
24
+
25
+ module_function
26
+
27
+ # If selection exists anywhere on window's display, clear it so that no
28
+ # window owns the selection anymore.
29
+ # Selection specifies the X selection that should be cleared, and should be
30
+ # an atom name such as PRIMARY or CLIPBOARD; see the Inter-Client
31
+ # Communication Conventions Manual for complete details.
32
+ # Selection defaults to PRIMARY and window defaults to ".".
33
+ def clear(options = {})
34
+ Tk.execute_only(:selection, :clear, options.to_tcl_options)
35
+ end
36
+
37
+ # Retrieves the value of selection from window's display and returns it as a
38
+ # result. Selection defaults to PRIMARY and window defaults to “.”.
39
+ # Type specifies the form in which the selection is to be returned (the
40
+ # desired “target” for conversion, in ICCCM terminology), and should be
41
+ # an atom name such as STRING or FILE_NAME; see the Inter-Client
42
+ # Communication Conventions Manual for complete details.
43
+ # Type defaults to STRING.
44
+ # The selection owner may choose to return the selection in any of several
45
+ # different representation formats, such as STRING, UTF8_STRING, ATOM,
46
+ # INTEGER, etc.
47
+ # (this format is different than the selection type; see the ICCCM for all
48
+ # the confusing details).
49
+ # If the selection is returned in a non-string format, such as INTEGER or
50
+ # ATOM, the selection command converts it to string format as a collection
51
+ # of fields separated by spaces: atoms are converted to their textual names,
52
+ # and anything else is converted to hexadecimal integers.
53
+ # Note that selection get does not retrieve the selection in the UTF8_STRING
54
+ # format unless told to.
55
+ def get(options = {})
56
+ Tk.execute(:selection, :get, options.to_tcl_options).to_s
57
+ end
58
+
59
+ # Creates a handler for selection requests, such that command will be
60
+ # executed whenever selection s is owned by window and someone attempts to
61
+ # retrieve it in the form given by type t (e.g.
62
+ # t is specified in the selection get command).
63
+ # S defaults to PRIMARY, t defaults to STRING, and f defaults to STRING.
64
+ # If command is an empty string then any existing handler for window, t, and
65
+ # s is removed.
66
+ # Note that when the selection is handled as type STRING it is also
67
+ # automatically handled as type UTF8_STRING as well.
68
+ #
69
+ # When selection is requested, window is the selection owner, and type is
70
+ # the requested type, command will be executed as a Tcl command with two
71
+ # additional numbers appended to it (with space separators).
72
+ # The two additional numbers are offset and maxChars: offset specifies a
73
+ # starting character position in the selection and maxChars gives the
74
+ # maximum number of characters to retrieve.
75
+ # The command should return a value consisting of at most maxChars of the
76
+ # selection, starting at position offset.
77
+ # For very large selections (larger than maxChars) the selection will be
78
+ # retrieved using several invocations of command with increasing offset
79
+ # values. If command returns a string whose length is less than maxChars,
80
+ # the return value is assumed to include all of the remainder of the
81
+ # selection; if the length of command's result is equal to maxChars then
82
+ # command will be invoked again, until it eventually returns a result
83
+ # shorter than maxChars.
84
+ # The value of maxChars will always be relatively large (thousands of
85
+ # characters). If command returns an error then the selection retrieval is
86
+ # rejected just as if the selection did not exist at all.
87
+ # The format argument specifies the representation that should be used to
88
+ # transmit the selection to the requester (the second column of Table 2 of
89
+ # the ICCCM), and defaults to STRING.
90
+ #
91
+ # If format is STRING, the selection is transmitted as 8-bit ASCII
92
+ # characters (i.e. just in the form returned by command, in the system
93
+ # encoding; the UTF8_STRING format always uses UTF-8 as its encoding).
94
+ #
95
+ # If format is ATOM, then the return value from command is divided into
96
+ # fields separated by white space; each field is converted to its atom
97
+ # value, and the 32-bit atom value is transmitted instead of the atom name.
98
+ # For any other format, the return value from command is divided into fields
99
+ # separated by white space and each field is converted to a 32-bit integer;
100
+ # an array of integers is transmitted to the selection requester.
101
+ #
102
+ # The format argument is needed only for compatibility with selection
103
+ # requesters that do not use Tk.
104
+ # If Tk is being used to retrieve the selection then the value is converted
105
+ # back to a string at the requesting end, so format is irrelevant.
106
+ def handle(window, options = {}, &command)
107
+ command = register_command(:selection_handle, &command)
108
+ Tk.execute_only(options.to_tcl_options, window, command)
109
+ end
110
+
111
+ # The first form of selection own returns the path name of the window in
112
+ # this application that owns selection on the display containing window, or
113
+ # an empty string if no window in this application owns the selection.
114
+ # Selection defaults to PRIMARY and window defaults to ".".
115
+ def own(window = None, options = {}, &command)
116
+ if window == None
117
+ Tk.execute(:selection, :own)
118
+ elsif window.is_a?(Hash)
119
+ options = window
120
+
121
+ if cmd = (options[:command] || command)
122
+ command = register_command(:selection_own, &cmd)
123
+ Tk.execute(:selection, :own, {command: command}.merge(options).to_tcl_options)
124
+ else
125
+ Tk.execute(:selection, :own, options.to_tcl_options)
126
+ end
127
+ else
128
+ Tk.execute(:selection, :own, options.to_tcl_options, window)
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,9 @@
1
+ module Tk
2
+ def self.set_palette(background, *rest)
3
+ if rest.empty?
4
+ Tk.execute(:tk_setPalette, background)
5
+ else
6
+ Tk.execute(:tk_setPalette, background, *rest)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,155 @@
1
+ # Manipulate Tk internal state
2
+ module Tk
3
+ module TkCmd
4
+ # @see TkCmd.appname
5
+ def tk_appname
6
+ TkCmd.appname(self)
7
+ end
8
+
9
+ # @see TkCmd.appname
10
+ def tk_appname=(new_name)
11
+ TkCmd.appname(self, new_name)
12
+ end
13
+
14
+ # @see TkCmd.caret
15
+ def tk_caret(options = None)
16
+ TkCmd.caret(self, options)
17
+ end
18
+
19
+ # @see TkCmd.scaling
20
+ def tk_scaling
21
+ TkCmd.scaling(None, self)
22
+ end
23
+
24
+ # @see TkCmd.scaling
25
+ def tk_scaling=(number)
26
+ TkCmd.scaling(number, self)
27
+ end
28
+
29
+ # @see TkCmd.inactive
30
+ def tk_inactive(reset = None)
31
+ TkCmd.inactive(reset, self)
32
+ end
33
+
34
+ # @see TkCmd.useinputmethods
35
+ def tk_useinputmethods
36
+ TkCmd.useinputmethods(None, self)
37
+ end
38
+
39
+ # @see TkCmd.useinputmethods
40
+ def tk_useinputmethods=(boolean)
41
+ TkCmd.useinputmethods(boolean, self)
42
+ end
43
+
44
+ def tk_windowingsystem
45
+ TkCmd.windowingsystem
46
+ end
47
+
48
+ module_function
49
+
50
+ # If newName is not specified, this command returns the name of the
51
+ # application (the name that may be used in send commands to communicate
52
+ # with the application).
53
+ # If newName is specified, then the name of the application is changed to
54
+ # newName. If the given name is already in use, then a suffix of the form “
55
+ # #2” or “ #3” is appended in order to make the name unique.
56
+ # The command's result is the name actually chosen.
57
+ # newName should not start with a capital letter.
58
+ # This will interfere with option processing, since names starting with
59
+ # capitals are assumed to be classes; as a result, Tk may not be able to
60
+ # find some options for the application.
61
+ # If sends have been disabled by deleting the send command, this command
62
+ # will reenable them and recreate the send command.
63
+ def appname(new_name = None)
64
+ Tk.execute(:tk, :appname, new_name)
65
+ end
66
+
67
+ # Sets and queries the caret location for the display of the specified Tk
68
+ # window window.
69
+ # The caret is the per-display cursor location used for indicating global
70
+ # focus (e.g.
71
+ # to comply with Microsoft Accessibility guidelines), as well as for
72
+ # location of the over-the-spot XIM (X Input Methods) or Windows IME
73
+ # windows. If no options are specified, the last values used for setting
74
+ # the caret are return in option-value pair format.
75
+ # -x and -y represent window-relative coordinates, and -height is the
76
+ # height of the current cursor location, or the height of the specified
77
+ # window if none is given.
78
+ def caret(window, options = None)
79
+ if None == options
80
+ Tk.execute(:tk, :caret, window).tcl_options_to_hash
81
+ else
82
+ Tk.execute_only(:tk, :caret, window, options.to_tcl_options)
83
+ end
84
+ end
85
+
86
+ # Sets and queries the current scaling factor used by Tk to convert between
87
+ # physical units (for example, points, inches, or millimeters) and pixels.
88
+ # The number argument is a floating point number that specifies the
89
+ # number of pixels per point on window's display.
90
+ # If the window argument is omitted, it defaults to the main window.
91
+ # If the number argument is omitted, the current value of the scaling
92
+ # factor is returned.
93
+ # A “point” is a unit of measurement equal to 1/72 inch.
94
+ # A scaling factor of 1.0 corresponds to 1 pixel per point, which is
95
+ # equivalent to a standard 72 dpi monitor.
96
+ # A scaling factor of 1.25 would mean 1.25 pixels per point, which is the
97
+ # setting for a 90 dpi monitor; setting the scaling factor to 1.25 on a 72
98
+ # dpi monitor would cause everything in the application to be displayed
99
+ # 1.25 times as large as normal.
100
+ # The initial value for the scaling factor is set when the application
101
+ # starts, based on properties of the installed monitor, but it can be
102
+ # changed at any time.
103
+ # Measurements made after the scaling factor is changed will use the new
104
+ # scaling factor, but it is undefined whether existing widgets will resize
105
+ # themselves dynamically to accommodate the new scaling factor.
106
+ def scaling(number = None, window = None)
107
+ if None == window
108
+ Tk.execute(:tk, :scaling, number)
109
+ else
110
+ Tk.execute(:tk, :scaling, '-displayof', window, number)
111
+ end
112
+ end
113
+
114
+ # Returns a positive integer, the number of milliseconds since the last
115
+ # time the user interacted with the system.
116
+ # If the -displayof option is given then the return value refers to the
117
+ # display of window; otherwise it refers to the display of the
118
+ # application's main window.
119
+ # tk inactive will return -1, if querying the user inactive time is not
120
+ # supported by the system, and in safe interpreters.
121
+ # If the literal string reset is given as an additional argument, the timer
122
+ # is reset and an empty string is returned.
123
+ # Resetting the inactivity time is forbidden in safe interpreters and will
124
+ # throw and error if tried.
125
+ def inactive(reset = None, window = None)
126
+ if None == window
127
+ Tk.execute(:tk, :inactive, reset)
128
+ else
129
+ Tk.execute(:tk, :inactive, '-displayof', window, reset)
130
+ end
131
+ end
132
+
133
+ # Sets and queries the state of whether Tk should use XIM (X Input Methods)
134
+ # for filtering events.
135
+ # The resulting state is returned.
136
+ # XIM is used in some locales (i.e., Japanese, Korean), to handle special
137
+ # input devices.
138
+ # This feature is only significant on X.
139
+ # If XIM support is not available, this will always return 0.
140
+ # If the window argument is omitted, it defaults to the main window.
141
+ # If the boolean argument is omitted, the current state is returned.
142
+ # This is turned on by default for the main display.
143
+ def useinputmethods(boolean = None, window = None)
144
+ if None == window
145
+ Tk.execute(:tk, :useinputmethods, boolean ? true : false)
146
+ else
147
+ Tk.execute(:tk, :useinputmethods, '-displayof', window, boolean ? true : false)
148
+ end
149
+ end
150
+
151
+ def windowingsystem
152
+ Tk.execute(:tk, :windowingsystem).to_sym
153
+ end
154
+ end
155
+ end