Module: YSupport::X

Extended by:
X
Included in:
X
Defined in:
lib/y_support/x.rb

Overview

Assets related to X windows control.

Instance Method Summary collapse

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 message_box( message="Press any key to close this window!" )
  w = Gtk::Window.new
  w.add_events Gdk::Event::KEY_PRESS
  w.add Gtk::Label.new( message )
  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 )
  title_bar_text = title_bar
  prompt_label_text = prompt
  
  w = Gtk::Window.new( Gtk::Window::TOPLEVEL )
  w.set_title( title_bar_text )
  w.border_width = 10
  w.signal_connect 'delete_event' do Gtk.main_quit end               # cc
  
  tlabel_widget = Gtk::Label.new( dialog_text )
  plabel_widget = Gtk::Label.new( prompt_label_text )
  ebox_widget = Gtk::Entry.new
  ebox_widget.visibility = true                                      # cc
  
  hbox = Gtk::HBox.new(false, 5)                                     # cc
  hbox.pack_start_defaults( plabel_widget )                          # cc
  hbox.pack_start_defaults( ebox_widget )
  vbox = Gtk::VBox.new(false, 5)
  vbox.pack_start_defaults( tlabel_widget )
  vbox.pack_start_defaults( hbox )
  w.add(vbox)
  
  memo = ""
  memo_closure = -> txt { memo << txt }
  
  ebox_widget.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