y_support 2.0.19 → 2.0.20
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 +4 -4
- data/lib/y_support/version.rb +1 -1
- data/lib/y_support/x.rb +60 -58
- data/test/x_test.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b352e0007b5e318e5c95c58725ea49240d283a8d
|
4
|
+
data.tar.gz: e82fac18c9c94700166f7ce1858bb79f671c5c96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6acfc2dee84cf9e609a2ee271ea67161ee70abb0a912735c8e2b3f8fe37b7c32ab1ed2bb8a8879341bb19b9fd30345cc805d9396100e14fb05e0fa64b951d90d
|
7
|
+
data.tar.gz: 69c8f221798a650bc8f33093e9f058555c1a8744d3aeb6c83823121d0fac7ecb59d63a693c6256a57efc252af46b973e0d4a7f33e703a9b62de3669c9bf3c6e1
|
data/lib/y_support/version.rb
CHANGED
data/lib/y_support/x.rb
CHANGED
@@ -1,68 +1,70 @@
|
|
1
1
|
require 'y_support'
|
2
|
+
require 'gtk2'
|
2
3
|
|
3
4
|
module YSupport::X
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
# Echo a string to the secondary X clip with `xsel -b -i`.
|
12
|
-
#
|
13
|
-
def echo_secondary_clipboard( string )
|
14
|
-
system 'echo -n "' + string + '" | xsel -s -i'
|
15
|
-
end
|
16
|
-
|
17
|
-
# Dialog box querying for a string.
|
18
|
-
#
|
19
|
-
def query_box( dialog_text, prompt: '> ', title_bar: 'User input required', &block )
|
20
|
-
title_bar_text = title_bar
|
21
|
-
prompt_label_text = prompt
|
22
|
-
|
23
|
-
w = Gtk::Window.new( Gtk::Window::TOPLEVEL )
|
24
|
-
w.set_title( title_bar_text )
|
25
|
-
w.border_width = 10
|
26
|
-
w.signal_connect 'delete_event' do Gtk.main_quit end # cc
|
27
|
-
|
28
|
-
tlabel_widget = Gtk::Label.new( dialog_text )
|
29
|
-
plabel_widget = Gtk::Label.new( prompt_label_text )
|
30
|
-
ebox_widget = Gtk::Entry.new
|
31
|
-
ebox_widget.visibility = true # cc
|
32
|
-
|
33
|
-
hbox = Gtk::HBox.new(false, 5) # cc
|
34
|
-
hbox.pack_start_defaults( plabel_widget ) # cc
|
35
|
-
hbox.pack_start_defaults( ebox_widget )
|
36
|
-
vbox = Gtk::VBox.new(false, 5)
|
37
|
-
vbox.pack_start_defaults( tlabel_widget )
|
38
|
-
vbox.pack_start_defaults( hbox )
|
39
|
-
w.add(vbox)
|
5
|
+
# Echo a string to the primary X clip with `xsel -b -i`.
|
6
|
+
#
|
7
|
+
def echo_primary_clipboard( string )
|
8
|
+
system 'echo -n ' + string.inspect + ' | xsel -b -i'
|
9
|
+
end
|
40
10
|
|
41
|
-
|
42
|
-
|
11
|
+
# Echo a string to the secondary X clip with `xsel -b -i`.
|
12
|
+
#
|
13
|
+
def echo_secondary_clipboard( string )
|
14
|
+
system 'echo -n "' + string.inspect + '" | xsel -s -i'
|
15
|
+
end
|
43
16
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
17
|
+
# Dialog box querying for a string.
|
18
|
+
#
|
19
|
+
def query_box( dialog_text, prompt: '> ', title_bar: 'User input required', &block )
|
20
|
+
title_bar_text = title_bar
|
21
|
+
prompt_label_text = prompt
|
22
|
+
|
23
|
+
w = Gtk::Window.new( Gtk::Window::TOPLEVEL )
|
24
|
+
w.set_title( title_bar_text )
|
25
|
+
w.border_width = 10
|
26
|
+
w.signal_connect 'delete_event' do Gtk.main_quit end # cc
|
27
|
+
|
28
|
+
tlabel_widget = Gtk::Label.new( dialog_text )
|
29
|
+
plabel_widget = Gtk::Label.new( prompt_label_text )
|
30
|
+
ebox_widget = Gtk::Entry.new
|
31
|
+
ebox_widget.visibility = true # cc
|
32
|
+
|
33
|
+
hbox = Gtk::HBox.new(false, 5) # cc
|
34
|
+
hbox.pack_start_defaults( plabel_widget ) # cc
|
35
|
+
hbox.pack_start_defaults( ebox_widget )
|
36
|
+
vbox = Gtk::VBox.new(false, 5)
|
37
|
+
vbox.pack_start_defaults( tlabel_widget )
|
38
|
+
vbox.pack_start_defaults( hbox )
|
39
|
+
w.add(vbox)
|
40
|
+
|
41
|
+
memo = ""
|
42
|
+
memo_closure = -> txt { memo << txt }
|
43
|
+
|
44
|
+
ebox_widget.signal_connect "key-release-event" do |sender, event| # cc
|
45
|
+
kn = Gdk::Keyval.to_name( event.keyval )
|
46
|
+
if kn == "Return"
|
47
|
+
memo_closure.( sender.text )
|
48
|
+
block.( sender.text ) if block
|
49
|
+
Gtk.main_quit
|
51
50
|
end
|
52
|
-
|
53
|
-
memo.tap { w.show_all; Gtk.main }
|
54
51
|
end
|
52
|
+
|
53
|
+
memo.tap { w.show_all; Gtk.main }
|
54
|
+
end
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
alias popup message_box
|
56
|
+
# Message box.
|
57
|
+
#
|
58
|
+
def message_box( message="Press any key to close this window!" )
|
59
|
+
w = Gtk::Window.new
|
60
|
+
w.add_events Gdk::Event::KEY_PRESS
|
61
|
+
w.add Gtk::Label.new( message )
|
62
|
+
w.signal_connect "key-release-event" do Gtk.main_quit end
|
63
|
+
w.set_default_size( 600, 120 )
|
64
|
+
w.show_all
|
65
|
+
Gtk.main
|
67
66
|
end
|
67
|
+
alias popup message_box
|
68
|
+
|
69
|
+
extend self
|
68
70
|
end # module YSupport::X
|
data/test/x_test.rb
CHANGED
@@ -8,12 +8,12 @@ require './../lib/y_support/x'
|
|
8
8
|
class XTest < Test::Unit::TestCase
|
9
9
|
context "X" do
|
10
10
|
setup do
|
11
|
-
YSupport::X.echo_primary_clipboard "
|
12
|
-
YSupport::X.echo_secondary_clipboard "
|
11
|
+
YSupport::X.echo_primary_clipboard '"foo"'
|
12
|
+
YSupport::X.echo_secondary_clipboard "bar"
|
13
13
|
end
|
14
14
|
|
15
15
|
should "have clipboard as expected" do
|
16
|
-
assert_equal "
|
16
|
+
assert_equal '"foo" bar', [`xsel -b`, `xsel -s`].join(' ')
|
17
17
|
end
|
18
18
|
end # context X
|
19
19
|
end # class XTest
|