Class: GloudApp::Tray
- Inherits:
-
Object
- Object
- GloudApp::Tray
- Defined in:
- lib/gloudapp.rb
Instance Method Summary collapse
- #add_action(title, options = {}, &proc) ⇒ Object
- #add_separator ⇒ Object
- #icon=(icon) ⇒ Object
-
#initialize(options = {}, &default) ⇒ Tray
constructor
A new instance of Tray.
- #message=(message) ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize(options = {}, &default) ⇒ Tray
Returns a new instance of Tray.
251 252 253 254 |
# File 'lib/gloudapp.rb', line 251 def initialize( = {}, &default) @options = {:tooltip => 'GloudApp', :icon => GloudApp::Icon.normal_path}.merge() @options[:default] = default unless @options[:default].is_a?(Proc) end |
Instance Method Details
#add_action(title, options = {}, &proc) ⇒ Object
256 257 258 259 260 261 262 |
# File 'lib/gloudapp.rb', line 256 def add_action(title, = {}, &proc) @actions ||= [] = {} unless .is_a?(Hash) [:action] = proc unless [:action].is_a?(Proc) [:title] = title unless [:title].is_a?(String) @actions << end |
#add_separator ⇒ Object
264 265 266 267 |
# File 'lib/gloudapp.rb', line 264 def add_separator() @actions ||= [] @actions << {:separator => true} end |
#icon=(icon) ⇒ Object
303 304 305 306 307 308 309 |
# File 'lib/gloudapp.rb', line 303 def icon=(icon) @si.pixbuf = Gdk::Pixbuf.new(icon) if not @ai.nil? # this relies on direct local file paths which works though it shouldn't @ai.set_icon(icon) end end |
#message=(message) ⇒ Object
311 312 313 |
# File 'lib/gloudapp.rb', line 311 def () @si.tooltip = .nil? ? @options[:tooltip] : .to_s end |
#run! ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/gloudapp.rb', line 269 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 @si.signal_connect('popup-menu') do |tray, , 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_path self. = nil @menu.popup(nil, nil, , time) end end begin require 'ruby-libappindicator' puts "Initialize AppIndicator..." # params: id, icon name, category @ai = AppIndicator::AppIndicator.new("gloudapp", GloudApp::Icon.normal_path, AppIndicator::Category::APPLICATION_STATUS); @ai.(@menu) @ai.set_status(AppIndicator::Status::ACTIVE) rescue LoadError puts "No AppIndicator support available." end end |