Created
July 21, 2011 16:52
-
-
Save glurp/1097613 to your computer and use it in GitHub Desktop.
systray api for green_shoes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'gtk2' | |
############################ SysTray ############################### | |
module Gtk | |
class SysTray < StatusIcon | |
def initialize(window,title="title?",config) | |
$statusIcon=self | |
@bshow=[] | |
@popup_tray=Menu.new | |
file= (config[:icon] && File.exist?(config[:icon])) ? config[:icon] : nil | |
config.each do |label,proc| | |
if Proc === proc | |
@bshow << CheckMenuItem.new(label) | |
@bshow.last.signal_connect("toggled") { proc.call(window.visible?) } | |
@popup_tray.append(@bshow.last) | |
end | |
end | |
if config[:quit] | |
@bquit_tray=ImageMenuItem.new(Stock::QUIT) | |
@bquit_tray.signal_connect("activate"){window.main_quit} | |
@popup_tray.append(SeparatorMenuItem.new) | |
@popup_tray.append(@bquit_tray) | |
end | |
@popup_tray.show_all | |
super() | |
self.pixbuf=if file then Gdk::Pixbuf.new(file) ;else nil ; end | |
self.tooltip=title||"" | |
self.signal_connect('activate'){ | |
window.visible? ? window.hide : window.show } | |
self.signal_connect('popup-menu'){|tray, button, time| | |
@popup_tray.popup(nil, nil, button, time) | |
} | |
end | |
end | |
end | |
class Shoes | |
class App | |
def systray_setup(config) | |
@systray=::Gtk::SysTray.new(self.win, | |
@owner.instance_variable_get('@title'), | |
config) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment