Class: GloudApp::Tray

Inherits:
Object
  • Object
show all
Defined in:
lib/gloudapp.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &default) ⇒ Tray

Returns a new instance of Tray.



229
230
231
232
# File 'lib/gloudapp.rb', line 229

def initialize(options = {}, &default)
  @options = {:tooltip => 'GloudApp', :icon => GloudApp::Icon.normal_path}.merge(options)
  @options[:default] = default unless @options[:default].is_a?(Proc)
end

Instance Method Details

#add_action(title, options = {}, &proc) ⇒ Object



234
235
236
237
238
239
240
# File 'lib/gloudapp.rb', line 234

def add_action(title, options = {}, &proc)
  @actions ||= []
  options = {} unless options.is_a?(Hash)
  options[:action] = proc unless options[:action].is_a?(Proc)
  options[:title] = title unless options[:title].is_a?(String)
  @actions << options
end

#add_separatorObject



242
243
244
245
# File 'lib/gloudapp.rb', line 242

def add_separator()
  @actions ||= []
  @actions << {:separator => true}
end

#icon=(icon) ⇒ Object



270
271
272
# File 'lib/gloudapp.rb', line 270

def icon=(icon)
  @si.pixbuf = icon.is_a?(Gdk::Pixbuf) ? icon : Gdk::Pixbuf.new(icon)
end

#message=(message) ⇒ Object



274
275
276
# File 'lib/gloudapp.rb', line 274

def message=(message)
  @si.tooltip = message.nil? ? @options[:tooltip] : message.to_s
end

#run!Object



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/gloudapp.rb', line 247

def run!
  @si = Gtk::StatusIcon.new
  @si.pixbuf = Gdk::Pixbuf.new(@options[:icon])
  @si.tooltip = @options[:tooltip]
  @si.signal_connect('activate') do
    run_action @options[:default]
  end

  create_menu
  @si.signal_connect('popup-menu') do |tray, button, time|
    if not @working
      @actions.each do |action|
        if action[:show].is_a?(Proc)
          action[:show].call(action[:item])
        end
      end
      self.icon = Icon.normal
      self.message = nil
      @menu.popup(nil, nil, button, time)
    end
  end
end