remi-simpletray 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc ADDED
@@ -0,0 +1,60 @@
1
+ = simpletray
2
+
3
+ simpletray is a gem for making it really easy to make wxruby-based system tray applications
4
+
5
+ == installation
6
+
7
+ simpletray uses wxWidgets, so you need to install wx: http://www.wxwidgets.org/
8
+
9
+ a binary should be available for Windows users. Mac/Linux should be able to use your packaging systems.
10
+
11
+ now, install the required rubygems ...
12
+
13
+ $ sudo gem install wxruby activesupport
14
+
15
+ and ... simpletray! (NOTE: at the time of writing, github still hasn't generated by gem, so you need to manually download from github)
16
+
17
+ $ sudo gem install remi-simpletray -s http://gems.github.com
18
+
19
+ == usage
20
+
21
+ #! /usr/bin/env ruby
22
+ require 'simpletray'
23
+
24
+ # icon my_cool_app.png will be used for the tray icon
25
+ SimpleTray.app 'My Cool App' do
26
+
27
+ # this makes a single item 'About' (about.png will be used if found)
28
+ # which pops up a message box when clicked
29
+ about { msgbox "Hello! This is my app!" }
30
+
31
+ # this makes a submenu 'Dogs' with rover/spot/rex subitems.
32
+ # dogs.png, rover.png, spot.png, rex.png will all be looked for
33
+ _dogs_ {
34
+ rover { puts "..." }
35
+ spot { puts "..." }
36
+ rex { msgbox "w00f, my name is rex!" }
37
+ }
38
+
39
+ # adds an item (the same as saying my_custom_item) with a custom icon
40
+ item 'My Custom Item', 'custom-icon.png' do
41
+ # ...
42
+ end
43
+
44
+ # adds an menu (the same as saying _my_custom_menu_) with a custom icon
45
+ menu 'My Custom Menu', 'custom-menu-icon.png' do
46
+ item1 { }
47
+ item2 { }
48
+ end
49
+
50
+ # this adds a seperator and then a special 'exit' item to quit the application
51
+ ____
52
+ exit
53
+
54
+ end
55
+
56
+ Also, see examples/first.rb (the first file I used for testing), which shows how to add
57
+ your own helper methods
58
+
59
+ Note, currently I'm only supporting PNGs. I'll fix this to support ICO/PNG/BMP/JPG/etc.
60
+ My TODO list is long :P
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rake/rdoctask'
2
+
3
+ Rake::RDocTask.new do |rdoc|
4
+ files = ['README.rdoc','lib/**/*.rb', 'doc/**/*.rdoc', 'test/*.rb']
5
+ rdoc.rdoc_files.add(files)
6
+ rdoc.main = 'README.rdoc'
7
+ rdoc.title = 'SimpleTray'
8
+ rdoc.rdoc_dir = 'doc'
9
+ rdoc.options << '--line-numbers' << '--inline-source'
10
+ end
data/examples/first.rb ADDED
@@ -0,0 +1,46 @@
1
+ #! /usr/bin/env ruby
2
+ $:.unshift File.join( File.dirname(__FILE__), '..', 'lib' )
3
+ require 'rubygems'
4
+ require 'simpletray'
5
+
6
+ module SimpleTray::Builder
7
+ def popup name, message
8
+ item( name ){ msgbox message }
9
+ end
10
+ end
11
+
12
+ SimpleTray.app 'My Cool App' do
13
+
14
+ popup 'testing 1,2,3', 'this is my message'
15
+
16
+ about { puts "this is my tray app!" }
17
+
18
+ msgbox_hi { msgbox "hello!" }
19
+ _____
20
+
21
+ item 'My Name' do
22
+ end
23
+
24
+ item 'blah', lambda { puts 'hello from blah' }
25
+
26
+ _menu_ 'xxx' do
27
+ menu_item_1 { msgbox "you clicked menu item 1!" }
28
+ ___
29
+ menu_item_2 { puts "clicked number 2 !!!!!" }
30
+ end
31
+
32
+ options { puts "on click" }
33
+
34
+ _options_ do
35
+ profile { puts "your profile" }
36
+ neato { puts "blah!" }
37
+ _nested_ do
38
+ _more_ do
39
+ clicky { msgbox "yay!" }
40
+ end
41
+ end
42
+ end
43
+
44
+ exit
45
+
46
+ end
data/lib/simpletray.rb ADDED
@@ -0,0 +1,176 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ %w( rubygems wx activesupport ).each {|lib| require lib }
3
+
4
+ class SimpleTray
5
+ cattr_accessor :icon_directory
6
+
7
+ # Use this to run your SimpleTray application
8
+ #
9
+ # SimpleTray.app 'My Cool App' do
10
+ # about { msgbox "My App!" }
11
+ # exit
12
+ # end
13
+ #
14
+ def self.app title, &block
15
+ Wx::App.run { Icon.new title, &block }
16
+ end
17
+
18
+ # This is where the magic happens.
19
+ #
20
+ # Any methods you add to this module will be available in the DSL
21
+ #
22
+ # module SimpleTray::Builder
23
+ # def popup name, message
24
+ # item( name ){ msgbox message }
25
+ # end
26
+ # end
27
+ #
28
+ # SimpleTray.app 'My Cool App' do
29
+ # popup 'Click Me', 'Hello! This is my message!'
30
+ # end
31
+ #
32
+ # Whatever you do, do NOT override the methods used
33
+ # in this module, *especially* not #method_missing.
34
+ #
35
+ # If you want to override the behavior of one of these
36
+ # methods, ***PLEASE*** use #alias_method_chain.
37
+ #
38
+ module Builder
39
+
40
+ def item name, icon = nil, &block
41
+ if block.nil? and icon.respond_to?:call
42
+ block = icon
43
+ icon = nil
44
+ end
45
+ item = Wx::MenuItem.new @menu, -1, name
46
+
47
+ icon ||= name.titleize.gsub(' ','').underscore + '.png' # 'My Cool App' => 'my_cool_app.png'
48
+ icon = File.join SimpleTray.icon_directory, icon unless File.file?icon
49
+ if File.file?icon
50
+ icon = Wx::Bitmap.new icon, Wx::BITMAP_TYPE_PNG
51
+ item.set_bitmap icon
52
+ end
53
+
54
+ @menu.append_item item
55
+ @menu.evt_menu(item){ block.call }
56
+ item
57
+ end
58
+
59
+ def menu name, icon = nil, &block
60
+ if block.nil? and icon.respond_to?:call
61
+ block = icon
62
+ icon = nil
63
+ end
64
+ item = SimpleTray::MenuItem.new @menu, name, icon, &block
65
+ @menu.append_item item
66
+ end
67
+
68
+ def seperator
69
+ @menu.append_separator
70
+ end
71
+
72
+ def exit name = 'Quit'
73
+ @menu.append Wx::ID_EXIT, name
74
+ @menu.evt_menu(Wx::ID_EXIT){ Kernel::exit }
75
+ end
76
+
77
+ alias quit exit
78
+
79
+ def msgbox msg
80
+ Wx::MessageDialog.new(@frame, msg, 'Ashacache', Wx::OK, Wx::DEFAULT_POSITION ).show_modal
81
+ end
82
+
83
+ def method_missing method, *args, &block
84
+ method = method.to_s
85
+ if method[/^_*$/]
86
+ seperator
87
+ elsif method[/^_.*_$/]
88
+ menu method.titleize.strip, *args, &block
89
+ else
90
+ item method.titleize, *args, &block
91
+ end
92
+ end
93
+ end
94
+
95
+ # Used *internally* by SimpleTray
96
+ #
97
+ # Represents a menu item that has a web menu.
98
+ #
99
+ # This dynamically creates the menu when your mouse
100
+ # highlights / hovers over the menu. See #on_highlight
101
+ #
102
+ class MenuItem < Wx::MenuItem
103
+ include Builder
104
+
105
+ def initialize menu, name, icon = nil, &block
106
+ super menu, -1, name
107
+ @menu = menu
108
+ @name = name
109
+ @icon = icon || @name.titleize.gsub(' ','').underscore + '.png' # 'My Cool App' => 'my_cool_app.png'
110
+ @icon = File.join SimpleTray.icon_directory, @icon unless File.file?@icon
111
+ init_icon
112
+ @item_block = block
113
+ self.get_menu.evt_menu_highlight(self){ |evt| on_highlight(evt) }
114
+ @menu = Wx::Menu.new
115
+ self.set_sub_menu @menu
116
+ end
117
+
118
+ def init_icon
119
+ if File.file?@icon
120
+ icon = Wx::Bitmap.new @icon, Wx::BITMAP_TYPE_PNG
121
+ set_bitmap icon
122
+ end
123
+ end
124
+
125
+ def on_highlight(evt)
126
+ instance_eval &@item_block if @menu.get_menu_item_count == 0
127
+ end
128
+ end
129
+
130
+ # Used *internally* by SimpleTray
131
+ #
132
+ # Represents the top-level system tray icon
133
+ #
134
+ # Menu items are dynamically created each time you click on
135
+ # the system tray icon. See #create_popup_menu
136
+ #
137
+ class Icon < Wx::TaskBarIcon
138
+ include Builder
139
+
140
+ def initialize title, icon = nil, &block
141
+ super()
142
+ @title = title
143
+ @icon = icon || @title.titleize.gsub(' ','').underscore + '.png' # 'My Cool App' => 'my_cool_app.png'
144
+ @icon = File.join SimpleTray.icon_directory, @icon unless File.file?@icon
145
+ init_icon
146
+ @item_block = block
147
+ end
148
+
149
+ def icon= path
150
+ @icon = path
151
+ end
152
+
153
+ def init_icon
154
+ unless File.file?@icon
155
+ raise "SimpleTray icon not found! #{ @icon }. Try: SimpleTray.app 'title', 'path to icon'. " +
156
+ "Or set SimpleTray.icon_directory to the directory where your icons reside."
157
+ else
158
+ refresh_icon
159
+ end
160
+ end
161
+
162
+ def refresh_icon
163
+ set_icon Wx::Icon.new( @icon, Wx::BITMAP_TYPE_PNG ), @title if File.file?@icon
164
+ end
165
+
166
+ def create_popup_menu
167
+ @menu = Wx::Menu.new
168
+ instance_eval &@item_block
169
+ @menu
170
+ end
171
+ end
172
+
173
+ end
174
+
175
+ # default the icon directory to what we *think* is the path of the script being run
176
+ SimpleTray.icon_directory = File.expand_path(File.dirname($0))
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = "simpletray"
4
+ s.version = "0.0.6"
5
+ s.date = "2008-09-26"
6
+ s.summary = "Ruby gem that provides a DSL for creating system tray icon applications *really* easily."
7
+ s.email = "remi@remitaylor.com"
8
+ s.homepage = "http://github.com/remi/simpletray"
9
+ s.description = "Ruby gem that provides a DSL for creating system tray icon applications *really* easily."
10
+ s.has_rdoc = true
11
+ s.rdoc_options = ["--quiet", "--title", "SimpleTray - creating system tray icons", "--opname", "index.html", "--line-numbers", "--main", "SimpleTray", "--inline-source"]
12
+ s.authors = ["remi Taylor"]
13
+
14
+ # generate using: $ ruby -e "puts Dir['**/**'].select{|x| File.file?x}.inspect"
15
+ s.files = ["examples/first.rb", "lib/simpletray.rb", "README.rdoc", "simpletray.gemspec", "Rakefile"]
16
+
17
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remi-simpletray
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - remi Taylor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-09-26 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Ruby gem that provides a DSL for creating system tray icon applications *really* easily.
17
+ email: remi@remitaylor.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - examples/first.rb
26
+ - lib/simpletray.rb
27
+ - README.rdoc
28
+ - simpletray.gemspec
29
+ - Rakefile
30
+ has_rdoc: true
31
+ homepage: http://github.com/remi/simpletray
32
+ post_install_message:
33
+ rdoc_options:
34
+ - --quiet
35
+ - --title
36
+ - SimpleTray - creating system tray icons
37
+ - --opname
38
+ - index.html
39
+ - --line-numbers
40
+ - --main
41
+ - SimpleTray
42
+ - --inline-source
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.2.0
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: Ruby gem that provides a DSL for creating system tray icon applications *really* easily.
64
+ test_files: []
65
+