Class: Object

Inherits:
BasicObject
Includes:
Types
Defined in:
lib/shoes/ruby.rb,
lib/green_shoes.rb,
lib/plugins/thread.rb,
lib/ext/hpricot/blankslate.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.hpricot_slate_method_addedObject



53
# File 'lib/ext/hpricot/blankslate.rb', line 53

alias_method :hpricot_slate_method_added, :method_added

.method_added(name) ⇒ Object

Detect method additions to Object and remove them in the BlankSlate class.



57
58
59
60
61
# File 'lib/ext/hpricot/blankslate.rb', line 57

def method_added(name)
  hpricot_slate_method_added(name)
  return if self != Object
  Hpricot::BlankSlate.hide(name)
end

Instance Method Details

#alert(msg, options = {:block => true}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/shoes/ruby.rb', line 20

def alert msg, options={:block => true}
  $dde = true
  dialog = Gtk::MessageDialog.new(
    get_win,
    Gtk::Dialog::MODAL,
    Gtk::MessageDialog::INFO,
    Gtk::MessageDialog::BUTTONS_OK,
    msg.to_s
  )
  dialog.title = options.has_key?(:title) ? options[:title] : "Green Shoes says:"
  if options[:block]
    dialog.run
    dialog.destroy
  else
    dialog.signal_connect("response"){ dialog.destroy }
    dialog.show
  end
end

#ask(msg, args = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/shoes/ruby.rb', line 56

def ask msg, args={}
  $dde = true
  dialog = Gtk::Dialog.new(
    "Green Shoes asks:", 
    get_win,
    Gtk::Dialog::MODAL | Gtk::Dialog::DESTROY_WITH_PARENT,
    [Gtk::Stock::OK, Gtk::Dialog::RESPONSE_ACCEPT],
    [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_REJECT]
  )
  dialog.vbox.add Gtk::Label.new msg
  dialog.vbox.add(el = Gtk::Entry.new)
  el.visibility = false if args[:secret]
  dialog.set_size_request 300, 100
  dialog.show_all
  ret = dialog.run == Gtk::Dialog::RESPONSE_ACCEPT ? el.text : nil
  dialog.destroy
  ret
end

#ask_color(title = 'Pick a color...') ⇒ Object



107
108
109
110
111
112
113
114
115
# File 'lib/shoes/ruby.rb', line 107

def ask_color title = 'Pick a color...'
  $dde = true
  dialog = Gtk::ColorSelectionDialog.new title
  dialog.icon = Gdk::Pixbuf.new File.join(DIR, '../static/gshoes-icon.png')
  dialog.run
  ret = dialog.colorsel.current_color.to_a.map{|c| c / 65535.0}
  dialog.destroy
  ret
end

#ask_open_file(path = nil) ⇒ Object



75
76
77
# File 'lib/shoes/ruby.rb', line 75

def ask_open_file path = nil
  dialog_chooser "Open File...", Gtk::FileChooser::ACTION_OPEN, Gtk::Stock::OPEN, path
end

#ask_open_folder(path = nil) ⇒ Object



83
84
85
# File 'lib/shoes/ruby.rb', line 83

def ask_open_folder path = nil
  dialog_chooser "Open Folder...", Gtk::FileChooser::ACTION_SELECT_FOLDER, Gtk::Stock::OPEN, path
end

#ask_save_file(path = nil) ⇒ Object



79
80
81
# File 'lib/shoes/ruby.rb', line 79

def ask_save_file path = nil
  dialog_chooser "Save File...", Gtk::FileChooser::ACTION_SAVE, Gtk::Stock::SAVE, path
end

#ask_save_folder(path = nil) ⇒ Object



87
88
89
# File 'lib/shoes/ruby.rb', line 87

def ask_save_folder path = nil
  dialog_chooser "Save Folder...", Gtk::FileChooser::ACTION_CREATE_FOLDER, Gtk::Stock::SAVE, path
end

#confirm(msg) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/shoes/ruby.rb', line 39

def confirm msg
  $dde = true
  dialog = Gtk::Dialog.new(
    "Green Shoes asks:", 
    get_win,
    Gtk::Dialog::MODAL | Gtk::Dialog::DESTROY_WITH_PARENT,
    [Gtk::Stock::OK, Gtk::Dialog::RESPONSE_ACCEPT],
    [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_REJECT]
  )
  dialog.vbox.add Gtk::Label.new msg
  dialog.set_size_request 300, 100
  dialog.show_all
  ret = dialog.run == Gtk::Dialog::RESPONSE_ACCEPT ? true : false
  dialog.destroy
  ret
end

#dialog_chooser(title, action, button, path) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/shoes/ruby.rb', line 91

def dialog_chooser title, action, button, path
  $dde = true
  dialog = Gtk::FileChooserDialog.new(
    title,
    get_win,
    action,
    nil,
    [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
    [button, Gtk::Dialog::RESPONSE_ACCEPT]
  )
  dialog.current_folder = path if path
  ret = dialog.run == Gtk::Dialog::RESPONSE_ACCEPT ? dialog.filename : nil
  dialog.destroy
  ret
end

#get_winObject



121
122
123
124
125
# File 'lib/shoes/ruby.rb', line 121

def get_win
  Gtk::Window.new.tap do |s|
    s.icon = Gdk::Pixbuf.new File.join(DIR, '../static/gshoes-icon.png')
  end
end

#invoke_in_shoes_mainloop(&blk) ⇒ Object



4
5
6
7
8
# File 'lib/plugins/thread.rb', line 4

def invoke_in_shoes_mainloop(&blk)
  return unless defined?($__shoes_app__)
  return unless Shoes::App===$__shoes_app__
  $__shoes_app__.get_queue().push( blk )
end

#to_sObject



117
118
119
# File 'lib/shoes/ruby.rb', line 117

def to_s
  super.gsub '<', '&lt;'
end