Module: YSupport::X
Overview
Assets related to X windows control.
Instance Method Summary collapse
-
#echo_primary_clipboard(string) ⇒ Object
Echo a string to the primary X clip; ‘xsel -b -i`.
-
#echo_secondary_clipboard(string) ⇒ Object
Echo a string to the secondary X clip; ‘xsel -b -i`.
-
#message_box(message = "Press any key to close this window!") ⇒ Object
(also: #popup)
Message box.
-
#query_box(dialog_text, prompt: '> ', title_bar: 'User input required', &block) ⇒ Object
Dialog box querying for a string.
Instance Method Details
#echo_primary_clipboard(string) ⇒ Object
Echo a string to the primary X clip; ‘xsel -b -i`.
9 10 11 12 |
# File 'lib/y_support/x.rb', line 9 def echo_primary_clipboard string s = 'echo -n ' + string.inspect + ' | xsel -b -i' system s end |
#echo_secondary_clipboard(string) ⇒ Object
Echo a string to the secondary X clip; ‘xsel -b -i`.
16 17 18 19 |
# File 'lib/y_support/x.rb', line 16 def echo_secondary_clipboard string s = 'echo -n ' + string.inspect + ' | xsel -s -i' system s end |
#message_box(message = "Press any key to close this window!") ⇒ Object Also known as: popup
Message box.
62 63 64 65 66 67 68 69 70 |
# File 'lib/y_support/x.rb', line 62 def ( ="Press any key to close this window!" ) w = Gtk::Window.new w.add_events Gdk::Event::KEY_PRESS w.add Gtk::Label.new( ) w.signal_connect "key-release-event" do Gtk.main_quit end w.set_default_size( 600, 120 ) w.show_all Gtk.main end |
#query_box(dialog_text, prompt: '> ', title_bar: 'User input required', &block) ⇒ Object
Dialog box querying for a string.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/y_support/x.rb', line 23 def query_box( dialog_text, prompt: '> ', title_bar: 'User input required', &block ) = prompt_label_text = prompt w = Gtk::Window.new( Gtk::Window::TOPLEVEL ) w.set_title( ) w.border_width = 10 w.signal_connect 'delete_event' do Gtk.main_quit end # cc = Gtk::Label.new( dialog_text ) = Gtk::Label.new( prompt_label_text ) = Gtk::Entry.new .visibility = true # cc hbox = Gtk::HBox.new(false, 5) # cc hbox.pack_start_defaults( ) # cc hbox.pack_start_defaults( ) vbox = Gtk::VBox.new(false, 5) vbox.pack_start_defaults( ) vbox.pack_start_defaults( hbox ) w.add(vbox) memo = "" memo_closure = -> txt { memo << txt } .signal_connect "key-release-event" do |sender, event| # cc kn = Gdk::Keyval.to_name( event.keyval ) if kn == "Return" memo_closure.( sender.text ) block.( sender.text ) if block Gtk.main_quit end end memo.tap { w.show_all; Gtk.main } end |