tk_paradise 0.0.13
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.
- checksums.yaml +7 -0
- data/README.md +387 -0
- data/doc/README.gen +325 -0
- data/lib/tk_paradise/base/base.rb +63 -0
- data/lib/tk_paradise/examples/001_dialog_box_example.rb +21 -0
- data/lib/tk_paradise/examples/002_draw_tiny_box.rb +22 -0
- data/lib/tk_paradise/examples/003_fun_with_cursors.rb +82 -0
- data/lib/tk_paradise/examples/004_hello_world_example.rb +23 -0
- data/lib/tk_paradise/examples/005_key_press_event_example.rb +21 -0
- data/lib/tk_paradise/examples/006_multiple_buttons.rb +30 -0
- data/lib/tk_paradise/examples/007_packing_example_in_tk.rb +28 -0
- data/lib/tk_paradise/examples/008_pig_latin_example.rb +70 -0
- data/lib/tk_paradise/examples/009_scrollbar_example.rb +44 -0
- data/lib/tk_paradise/examples/010_telnet_client.rb +106 -0
- data/lib/tk_paradise/examples/011_thermostat_example.rb +60 -0
- data/lib/tk_paradise/examples/012_tk_menu_example.rb +23 -0
- data/lib/tk_paradise/examples/013_tk_popup.rb +61 -0
- data/lib/tk_paradise/examples/014_tk_slider.rb +63 -0
- data/lib/tk_paradise/examples/015_choose_colour_example.rb +22 -0
- data/lib/tk_paradise/examples/016_spin_box_example.rb +28 -0
- data/lib/tk_paradise/examples/017_combo_box_example.rb +46 -0
- data/lib/tk_paradise/examples/018_tk_list_box_example.rb +18 -0
- data/lib/tk_paradise/examples/019_tk_curves.rb +33 -0
- data/lib/tk_paradise/examples/advanced/0001_example_showing_move_method.rb +32 -0
- data/lib/tk_paradise/examples/advanced/0019_tk_curves.rb +0 -0
- data/lib/tk_paradise/tk_classes/label.rb +18 -0
- data/lib/tk_paradise/tk_classes/root.rb +24 -0
- data/lib/tk_paradise/tk_paradise.rb +154 -0
- data/lib/tk_paradise/version/version.rb +19 -0
- data/lib/tk_paradise.rb +5 -0
- data/tk_paradise.gemspec +42 -0
- metadata +106 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'tk_paradise/base/base.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module Tk
|
8
|
+
|
9
|
+
class Base # === Tk::Base
|
10
|
+
|
11
|
+
require 'colours'
|
12
|
+
include Colours
|
13
|
+
|
14
|
+
# ========================================================================= #
|
15
|
+
# === initialize
|
16
|
+
# ========================================================================= #
|
17
|
+
def initialize(
|
18
|
+
i = ARGV
|
19
|
+
)
|
20
|
+
set_commandline_arguments(i)
|
21
|
+
reset
|
22
|
+
end
|
23
|
+
|
24
|
+
# ========================================================================= #
|
25
|
+
# === reset (reset tag)
|
26
|
+
# ========================================================================= #
|
27
|
+
def reset
|
28
|
+
# ======================================================================= #
|
29
|
+
# === @internal_hash
|
30
|
+
# ======================================================================= #
|
31
|
+
@internal_hash = {}
|
32
|
+
end
|
33
|
+
|
34
|
+
# ========================================================================= #
|
35
|
+
# === set_commandline_arguments
|
36
|
+
# ========================================================================= #
|
37
|
+
def set_commandline_arguments(i = '')
|
38
|
+
i = [i].flatten.compact
|
39
|
+
@commandline_arguments = i
|
40
|
+
end
|
41
|
+
|
42
|
+
# ========================================================================= #
|
43
|
+
# === commandline_arguments?
|
44
|
+
# ========================================================================= #
|
45
|
+
def commandline_arguments?
|
46
|
+
@commandline_arguments
|
47
|
+
end
|
48
|
+
|
49
|
+
# ========================================================================= #
|
50
|
+
# === first_argument?
|
51
|
+
# ========================================================================= #
|
52
|
+
def first_argument?
|
53
|
+
@commandline_arguments.first
|
54
|
+
end; alias first? first_argument? # === first?
|
55
|
+
|
56
|
+
# ========================================================================= #
|
57
|
+
# === tk_variable
|
58
|
+
# ========================================================================= #
|
59
|
+
def tk_variable
|
60
|
+
TkVariable.new
|
61
|
+
end
|
62
|
+
|
63
|
+
end; end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'tk'
|
6
|
+
|
7
|
+
root = TkRoot.new
|
8
|
+
root.title = 'Window'
|
9
|
+
root.geometry('800x600+0+0')
|
10
|
+
button_click = Proc.new {
|
11
|
+
Tk.getOpenFile
|
12
|
+
}
|
13
|
+
|
14
|
+
button = TkButton.new(root) {
|
15
|
+
text 'button'
|
16
|
+
pack(side: :left, padx: "50", pady: "50")
|
17
|
+
}
|
18
|
+
|
19
|
+
button.command = button_click
|
20
|
+
|
21
|
+
Tk.mainloop
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'tk'
|
6
|
+
|
7
|
+
root = TkRoot.new { title 'Click to draw a tiny box' }
|
8
|
+
TkLabel.new(root) { text 'Attention!'; font TkCaptionFont }
|
9
|
+
canvas = TkCanvas.new(root)
|
10
|
+
canvas.pack
|
11
|
+
canvas.bind('1', proc { |e|
|
12
|
+
p "#{e.x}, #{e.y}"
|
13
|
+
TkcRectangle.new(canvas, e.x,e.y,e.x-5, e.y-5)
|
14
|
+
})
|
15
|
+
root.bind('Any-Key-d',
|
16
|
+
proc { |event|
|
17
|
+
p "#{event.x}, #{event.y}"
|
18
|
+
TkcRectangle.new(canvas, event.x, event.y, event.x-5, event.y-5)
|
19
|
+
}
|
20
|
+
)
|
21
|
+
Tk.mainloop
|
22
|
+
# rb draw_tiny_box.rb
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'tk'
|
6
|
+
root = TkRoot.new { title 'Fun with Cursors'}
|
7
|
+
# =========================================================================== #
|
8
|
+
# Specify the Root Geometry
|
9
|
+
# =========================================================================== #
|
10
|
+
root.geometry '1250x1000+0+0'
|
11
|
+
|
12
|
+
TkMessage.new(root) { x='bottom_side';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
|
13
|
+
TkMessage.new(root) { x='bottom_side';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
14
|
+
TkMessage.new(root) { x='box_spiral';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
15
|
+
TkMessage.new(root) { x='center_ptr';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
16
|
+
TkMessage.new(root) { x='circle';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
17
|
+
TkMessage.new(root) { x='clock';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
18
|
+
TkMessage.new(root) { x='coffee_mug';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
19
|
+
TkMessage.new(root) { x='cross';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
20
|
+
TkMessage.new(root) { x='cross_reverse';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
21
|
+
TkMessage.new(root) { x='crosshair';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
22
|
+
TkMessage.new(root) { x='diamond_cross';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
23
|
+
TkMessage.new(root) { x='dot';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
24
|
+
TkMessage.new(root) { x='dotbox';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
25
|
+
TkMessage.new(root) { x='double_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
26
|
+
TkMessage.new(root) { x='draft_large';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
27
|
+
TkMessage.new(root) { x='draft_small';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
28
|
+
TkMessage.new(root) { x='draped_box';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
29
|
+
TkMessage.new(root) { x='exchange';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
30
|
+
TkMessage.new(root) { x='bottom_side';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
|
31
|
+
TkMessage.new(root) { x='bottom_side';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
|
32
|
+
TkMessage.new(root) { x='bottom_side';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
|
33
|
+
TkMessage.new(root) { x='bottom_side';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
|
34
|
+
TkMessage.new(root) { x='hand2';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
|
35
|
+
TkMessage.new(root) { x='heart';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
|
36
|
+
TkMessage.new(root) { x='icon';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
|
37
|
+
TkMessage.new(root) { x='iron_cross';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
|
38
|
+
TkMessage.new(root) { x='left_ptr';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
39
|
+
TkMessage.new(root) { x='left_side';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
40
|
+
TkMessage.new(root) { x='left_tee';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
41
|
+
TkMessage.new(root) { x='leftbutton';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
42
|
+
TkMessage.new(root) { x='ll_angle';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
|
43
|
+
TkMessage.new(root) { x='lr_angle';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
|
44
|
+
TkMessage.new(root) { x='man';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
|
45
|
+
TkMessage.new(root) { x='middlebutton';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
|
46
|
+
TkMessage.new(root) { x='mouse';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
47
|
+
TkMessage.new(root) { x='pencil';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
48
|
+
TkMessage.new(root) { x='pirate';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
49
|
+
TkMessage.new(root) { x='plus';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
50
|
+
TkMessage.new(root) { x='question_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
51
|
+
TkMessage.new(root) { x='right_ptr';text x;background 'green';cursor x}.pack('side'=>'bottom', padx: 4, 'padx'=>2)
|
52
|
+
TkMessage.new(root) { x='right_side';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
53
|
+
TkMessage.new(root) { x='right_tee';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
54
|
+
TkMessage.new(root) { x='rightbutton';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
55
|
+
TkMessage.new(root) { x='rtl_logo';text x;background 'green';cursor x}.pack('side'=>'bottom', padx: 4, 'padx'=>2)
|
56
|
+
TkMessage.new(root) { x='sailboat';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
57
|
+
TkMessage.new(root) { x='sb_down_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
58
|
+
TkMessage.new(root) { x='sb_h_double_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
59
|
+
TkMessage.new(root) { x='sb_left_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
60
|
+
TkMessage.new(root) { x='sb_right_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
61
|
+
TkMessage.new(root) { x='sb_up_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
62
|
+
TkMessage.new(root) { x='sb_v_double_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
63
|
+
TkMessage.new(root) { x='shuttle';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
|
64
|
+
TkMessage.new(root) { x='sizing';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
|
65
|
+
TkMessage.new(root) { x='spider';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
66
|
+
TkMessage.new(root) { x='spraycan';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
67
|
+
TkMessage.new(root) { x='star';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
68
|
+
TkMessage.new(root) { x='target';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
69
|
+
TkMessage.new(root) { x='tcross';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
70
|
+
TkMessage.new(root) { x='top_left_arrow';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
71
|
+
TkMessage.new(root) { x='top_left_corner';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
72
|
+
TkMessage.new(root) { x='top_right_corner';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
73
|
+
TkMessage.new(root) { x='top_side';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
74
|
+
TkMessage.new(root) { x='top_tee';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
75
|
+
TkMessage.new(root) { x='trek';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
76
|
+
TkMessage.new(root) { x='ul_angle';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
77
|
+
TkMessage.new(root) { x='umbrella';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
78
|
+
TkMessage.new(root) { x='ur_angle';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
79
|
+
TkMessage.new(root) { x='watch';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
80
|
+
TkMessage.new(root) { x='xterm';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
|
81
|
+
Tk.mainloop
|
82
|
+
# rb fun_with_cursors.rb
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'tk_paradise'
|
6
|
+
require 'colours/autoinclude'
|
7
|
+
|
8
|
+
root = TkRoot.new { title 'Hello, world!' }
|
9
|
+
|
10
|
+
TkLabel.new(root) {
|
11
|
+
text 'Hello, World!'
|
12
|
+
pack { padx 25 ; pady 25; side 'left' }
|
13
|
+
}
|
14
|
+
# Add the hello world button next:
|
15
|
+
button = TkButton.new(root) {
|
16
|
+
text 'Hello, World!'
|
17
|
+
}
|
18
|
+
button.command {
|
19
|
+
e 'HEY'
|
20
|
+
}
|
21
|
+
pp button.methods.sort
|
22
|
+
button.pack
|
23
|
+
Tk.mainloop
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'tk'
|
6
|
+
|
7
|
+
alias e puts
|
8
|
+
|
9
|
+
USE_THIS_FONT = TkFont.new(family: 'Helvetica', size: 20, weight: 'bold')
|
10
|
+
|
11
|
+
root = TkRoot.new
|
12
|
+
root.geometry('800x600+0+0')
|
13
|
+
entry = TkEntry.new(root) {
|
14
|
+
font USE_THIS_FONT
|
15
|
+
pack
|
16
|
+
}
|
17
|
+
entry.bind('Key', proc {|this_key|
|
18
|
+
e "This key was pressed: `#{this_key}`"
|
19
|
+
}, '%K')
|
20
|
+
|
21
|
+
Tk.mainloop
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'tk'
|
6
|
+
|
7
|
+
alias e puts
|
8
|
+
|
9
|
+
# =========================================================================== #
|
10
|
+
# === TITLE
|
11
|
+
# =========================================================================== #
|
12
|
+
TITLE = 'Several buttons'
|
13
|
+
root = TkRoot.new { title TITLE }
|
14
|
+
root.geometry('550x450+10+10')
|
15
|
+
buttons = %w( one and one ).map { |entry|
|
16
|
+
TkButton.new(root, text: entry)
|
17
|
+
}
|
18
|
+
TkGrid.grid(
|
19
|
+
buttons[0],
|
20
|
+
buttons[1],
|
21
|
+
buttons[2],
|
22
|
+
columnspan: 2
|
23
|
+
)
|
24
|
+
TkButton.new(root, text: 'is').grid(columnspan: 3, sticky: 'ew')
|
25
|
+
button2 = TkButton.new(root, text: 'button2', width: 50).
|
26
|
+
grid('row' => 1, 'column' => 3, 'columnspan' => 3)
|
27
|
+
button2.command {
|
28
|
+
e 'Hello from button2.'
|
29
|
+
}
|
30
|
+
Tk.mainloop
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'tk_paradise'
|
6
|
+
|
7
|
+
include Tk
|
8
|
+
|
9
|
+
IMAGE = '/home/x/DATA/images/HUE2.gif'
|
10
|
+
|
11
|
+
root = TkRoot.new() { title 'Packing Example' }
|
12
|
+
|
13
|
+
button = TkButton.new(root) { text 'First, rightmost' }
|
14
|
+
button.pack('side'=>'right', 'fill'=>'y')
|
15
|
+
|
16
|
+
entry = TkEntry.new(root).pack('side'=>'top', 'fill'=>'x')
|
17
|
+
entry.insert(0, 'Entry on the top')
|
18
|
+
|
19
|
+
label = tk_label('to the right', root) { :on_right }
|
20
|
+
|
21
|
+
our_image = tk_image(image, height: 50)
|
22
|
+
img_label = TkLabel.new(root) { image(our_image) }.pack('anchor'=>'e')
|
23
|
+
|
24
|
+
text = TkText.new(root) { width 20; height 5 }.pack('side'=>'left')
|
25
|
+
text.insert('end', 'Left in canvas')
|
26
|
+
|
27
|
+
tk_label('Message in the Bottom', root) { :on_bottom }
|
28
|
+
Tk.run
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'tk'
|
2
|
+
|
3
|
+
class PigBox
|
4
|
+
|
5
|
+
# ========================================================================= #
|
6
|
+
# === PADDING_TO_USE
|
7
|
+
# ========================================================================= #
|
8
|
+
PADDING_TO_USE = {
|
9
|
+
padx: 10,
|
10
|
+
pady: 10
|
11
|
+
}
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === initialize
|
15
|
+
# ========================================================================= #
|
16
|
+
def initialize
|
17
|
+
use_this_callback = proc { show_pig }
|
18
|
+
root = TkRoot.new { title 'Pig' }
|
19
|
+
top = TkFrame.new(root)
|
20
|
+
TkLabel.new(top) {
|
21
|
+
text 'Enter Text:'
|
22
|
+
pack(PADDING_TO_USE)
|
23
|
+
}
|
24
|
+
@text = TkVariable.new
|
25
|
+
@entry = TkEntry.new(top, textvariable: @text)
|
26
|
+
@entry.pack(PADDING_TO_USE)
|
27
|
+
TkButton.new(top) {
|
28
|
+
text 'Pig It'
|
29
|
+
command use_this_callback
|
30
|
+
pack PADDING_TO_USE
|
31
|
+
}
|
32
|
+
TkButton.new(top) {
|
33
|
+
text 'Exit'
|
34
|
+
command {proc exit}
|
35
|
+
pack PADDING_TO_USE
|
36
|
+
}
|
37
|
+
top.pack(fill: 'both', side: 'top')
|
38
|
+
end
|
39
|
+
|
40
|
+
# ========================================================================= #
|
41
|
+
# === pig
|
42
|
+
# ========================================================================= #
|
43
|
+
def pig(word)
|
44
|
+
leadingCap = word =~ /^A-Z/
|
45
|
+
word.downcase!
|
46
|
+
res =
|
47
|
+
case word
|
48
|
+
when /^aeiouy/
|
49
|
+
"#{word}way"
|
50
|
+
when /^([^aeiouy]+)(.*)/
|
51
|
+
$2+$1+"ay"
|
52
|
+
else
|
53
|
+
word
|
54
|
+
end
|
55
|
+
leadingCap ? res.capitalize : res
|
56
|
+
end
|
57
|
+
|
58
|
+
# ========================================================================= #
|
59
|
+
# === show_pig
|
60
|
+
# ========================================================================= #
|
61
|
+
def show_pig
|
62
|
+
@text.value = @text.value.split.collect{|w| pig(w)}.join(' ')
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
if __FILE__ == $PROGRAM_NAME
|
68
|
+
PigBox.new
|
69
|
+
Tk.mainloop
|
70
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'tk'
|
6
|
+
|
7
|
+
# =========================================================================== #
|
8
|
+
# Demonstrates adding a vertical row of buttons to a scrolling canvas.
|
9
|
+
# =========================================================================== #
|
10
|
+
Tk.root.title('Test')
|
11
|
+
Tk.root.geometry('800x600+0+0')
|
12
|
+
|
13
|
+
canvas = TkCanvas.new(Tk.root) {
|
14
|
+
width 320
|
15
|
+
height 200
|
16
|
+
scrollregion '0 0 400 400'
|
17
|
+
pack(side: :left, fill: :both, expand: :true )
|
18
|
+
}
|
19
|
+
|
20
|
+
# =========================================================================== #
|
21
|
+
# Create the scrollbar next:
|
22
|
+
# =========================================================================== #
|
23
|
+
vbar = TkScrollbar.new(Tk.root) {
|
24
|
+
orient 'vert'
|
25
|
+
pack(side: :right, fill: :y)
|
26
|
+
}
|
27
|
+
|
28
|
+
canvas.yscrollbar(vbar)
|
29
|
+
|
30
|
+
frame = TkFrame.new(canvas) { |entry|
|
31
|
+
(1 .. 12).each { |i|
|
32
|
+
TkButton.new(entry) {
|
33
|
+
text i
|
34
|
+
command { Tk.bell }
|
35
|
+
grid
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
TkcLine.new(canvas, 0, 0, 400, 400)
|
41
|
+
TkcLine.new(canvas, 0, 400, 400, 0)
|
42
|
+
TkcWindow.new(canvas, 200, 200, width: 100, height: 280, window: frame)
|
43
|
+
|
44
|
+
Tk.mainloop
|
@@ -0,0 +1,106 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require "tk"
|
6
|
+
|
7
|
+
def packing(padx, pady, side = "left", anchor = "n")
|
8
|
+
{ padx: padx, pady: pady, side: side, anchor: anchor }
|
9
|
+
end
|
10
|
+
|
11
|
+
root = TkRoot.new() { title "Telnet session" }
|
12
|
+
top = TkFrame.new(root)
|
13
|
+
fr1 = TkFrame.new(top)
|
14
|
+
fr1a = TkFrame.new(fr1)
|
15
|
+
fr1b = TkFrame.new(fr1)
|
16
|
+
fr2 = TkFrame.new(top)
|
17
|
+
fr3 = TkFrame.new(top)
|
18
|
+
fr4 = TkFrame.new(top)
|
19
|
+
|
20
|
+
LabelPack = packing(5, 5, "top", "w")
|
21
|
+
EntryPack = packing(5, 2, "top")
|
22
|
+
ButtonPack = packing(15, 5, "left", "center")
|
23
|
+
FramePack = packing(2, 2, "top")
|
24
|
+
Frame1Pack = packing(2, 2, "left")
|
25
|
+
|
26
|
+
var_host = TkVariable.new
|
27
|
+
var_port = TkVariable.new
|
28
|
+
var_user = TkVariable.new
|
29
|
+
var_pass = TkVariable.new
|
30
|
+
|
31
|
+
lab_host = TkLabel.new(fr1a) do
|
32
|
+
text "Host name"
|
33
|
+
pack LabelPack
|
34
|
+
end
|
35
|
+
|
36
|
+
ent_host = TkEntry.new(fr1a) do
|
37
|
+
textvariable var_host
|
38
|
+
font "{Helvetica} 10"
|
39
|
+
pack EntryPack
|
40
|
+
end
|
41
|
+
|
42
|
+
lab_port = TkLabel.new(fr1b) do
|
43
|
+
text "Port"
|
44
|
+
pack LabelPack
|
45
|
+
end
|
46
|
+
|
47
|
+
ent_port = TkEntry.new(fr1b) do
|
48
|
+
width 4
|
49
|
+
textvariable var_port
|
50
|
+
font "{Helvetica} 10"
|
51
|
+
pack EntryPack
|
52
|
+
end
|
53
|
+
|
54
|
+
lab_user = TkLabel.new(fr2) do
|
55
|
+
text "User name"
|
56
|
+
pack LabelPack
|
57
|
+
end
|
58
|
+
|
59
|
+
ent_user = TkEntry.new(fr2) do
|
60
|
+
width 21
|
61
|
+
font "{Helvetica} 12"
|
62
|
+
textvariable var_user
|
63
|
+
pack EntryPack
|
64
|
+
end
|
65
|
+
|
66
|
+
lab_pass = TkLabel.new(fr3) do
|
67
|
+
text "Password"
|
68
|
+
pack LabelPack
|
69
|
+
end
|
70
|
+
|
71
|
+
ent_pass = TkEntry.new(fr3) do
|
72
|
+
width 21
|
73
|
+
show "*"
|
74
|
+
textvariable var_pass
|
75
|
+
font "{Helvetica} 12"
|
76
|
+
pack EntryPack
|
77
|
+
end
|
78
|
+
|
79
|
+
btn_signon = TkButton.new(fr4) do
|
80
|
+
text "Sign on"
|
81
|
+
command {} # Does nothing!
|
82
|
+
pack ButtonPack
|
83
|
+
end
|
84
|
+
|
85
|
+
btn_cancel = TkButton.new(fr4) do
|
86
|
+
text "Cancel"
|
87
|
+
command { exit } # Just exits
|
88
|
+
pack ButtonPack
|
89
|
+
end
|
90
|
+
|
91
|
+
top.pack FramePack
|
92
|
+
fr1.pack FramePack
|
93
|
+
fr2.pack FramePack
|
94
|
+
fr3.pack FramePack
|
95
|
+
fr4.pack FramePack
|
96
|
+
fr1a.pack Frame1Pack
|
97
|
+
fr1b.pack Frame1Pack
|
98
|
+
|
99
|
+
var_host.value = "addison-wesley.com"
|
100
|
+
var_user.value = "debra"
|
101
|
+
var_port.value = 23
|
102
|
+
|
103
|
+
ent_pass.focus
|
104
|
+
foo = ent_user.font
|
105
|
+
|
106
|
+
Tk.mainloop
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
|
6
|
+
|
7
|
+
require 'tk'
|
8
|
+
|
9
|
+
# Common packing options...
|
10
|
+
top = { side: 'top', padx: 5, pady: 5 }
|
11
|
+
left = { side: 'left', padx: 5, pady: 5 }
|
12
|
+
bottom = { side: 'bottom', padx: 5, pady: 5 }
|
13
|
+
|
14
|
+
# Starting temperature...
|
15
|
+
temp = 74
|
16
|
+
|
17
|
+
root = TkRoot.new { title "Thermostat" }
|
18
|
+
tframe = TkFrame.new(root) { background "#606060" }
|
19
|
+
bframe = TkFrame.new(root)
|
20
|
+
|
21
|
+
tlab = TkLabel.new(tframe) do
|
22
|
+
text temp.to_s
|
23
|
+
font "{Helvetica} 54 {bold}"
|
24
|
+
foreground "green"
|
25
|
+
background "#606060"
|
26
|
+
pack left
|
27
|
+
end
|
28
|
+
|
29
|
+
# the "degree" symbol
|
30
|
+
TkLabel.new(tframe) do
|
31
|
+
text "o"
|
32
|
+
font "{Helvetica} 14 {bold}"
|
33
|
+
foreground "green"
|
34
|
+
background "#606060"
|
35
|
+
# Anchor-north above text like a degree symbol
|
36
|
+
pack left.update(anchor: 'n')
|
37
|
+
end
|
38
|
+
|
39
|
+
TkButton.new(bframe) do
|
40
|
+
text " Up "
|
41
|
+
pack left
|
42
|
+
command {
|
43
|
+
temp += 1
|
44
|
+
tlab.configure(text: temp.to_s)
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
TkButton.new(bframe) do
|
49
|
+
text "Down"
|
50
|
+
pack left
|
51
|
+
command {
|
52
|
+
temp -= 1
|
53
|
+
tlab.configure(text: temp.to_s)
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
tframe.pack top
|
58
|
+
bframe.pack bottom
|
59
|
+
|
60
|
+
Tk.mainloop
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'tk'
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
root = TkRoot.new() { title "Ruby/Tk Menu Example" }
|
6
|
+
|
7
|
+
bar = TkMenu.new()
|
8
|
+
|
9
|
+
sys = TkMenu.new(bar)
|
10
|
+
sys.add('command', 'label'=>"Quit", 'command'=>proc { root.destroy })
|
11
|
+
bar.add('cascade', 'menu'=>sys, 'label'=>"System")
|
12
|
+
|
13
|
+
file = TkMenu.new(bar)
|
14
|
+
file.add('command', 'label'=>"Open", 'command'=>proc { puts "Open..." })
|
15
|
+
file.add('command', 'label'=>"Close", 'command'=>proc { puts "Close..." })
|
16
|
+
bar.add('cascade', 'menu'=>file, 'label'=>"File")
|
17
|
+
|
18
|
+
root.menu(bar)
|
19
|
+
|
20
|
+
|
21
|
+
Tk.mainloop()
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# tkpopup.rb : wrapper for tk_popup
|
6
|
+
# by Masahiro SATO (m@sa.to)
|
7
|
+
# Time-stamp: <99/08/14 10:49:28 msato>
|
8
|
+
# =========================================================================== #
|
9
|
+
require 'tk'
|
10
|
+
|
11
|
+
class TkPopup < TkWindow
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === initialize
|
15
|
+
# ========================================================================= #
|
16
|
+
def initialize(menu, x = 0, y = 0, entry = '')
|
17
|
+
super()
|
18
|
+
@menu = menu
|
19
|
+
@x = x
|
20
|
+
@y = y
|
21
|
+
@entry = entry
|
22
|
+
INTERP._eval('tk_popup '+
|
23
|
+
[@menu.path, @x.to_s, @y.to_s, @entry.to_s].join(' '))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
######################################################################
|
28
|
+
# example
|
29
|
+
# You will see a popup menu by clicking Button-3
|
30
|
+
######################################################################
|
31
|
+
if __FILE__ == $0
|
32
|
+
color_ar = %w( blue yellow green pink grey )
|
33
|
+
color = color_ar[0]
|
34
|
+
|
35
|
+
TkRoot.new {|r|
|
36
|
+
title File.basename($0)
|
37
|
+
button = TkButton.new(r,
|
38
|
+
'text' => 'Quit',
|
39
|
+
'background' => color,
|
40
|
+
"activebackground" => "light " + color,
|
41
|
+
"command" => proc {r.destroy}
|
42
|
+
).pack "fill"=>"both", 'expand' => 'yes'
|
43
|
+
|
44
|
+
menu = TkMenu.new(button, 'tearoff' => false)
|
45
|
+
color_ar.each {|col|
|
46
|
+
menu.add("command",
|
47
|
+
"label" => col,
|
48
|
+
"command" => proc {
|
49
|
+
color = col
|
50
|
+
button.background color
|
51
|
+
button.activebackground 'light '+color
|
52
|
+
}
|
53
|
+
)
|
54
|
+
}
|
55
|
+
|
56
|
+
button.bind("Button-3", proc {|x, y|
|
57
|
+
TkPopup.new(menu, x, y, color_ar.index(color))
|
58
|
+
}, "%X %Y") # x_root and y_root
|
59
|
+
}
|
60
|
+
Tk.mainloop
|
61
|
+
end
|