Merge lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/demo_ruby into lp:~cairo-dock-team/cairo-dock-plug-ins-extras/third-party
- demo_ruby
- Merge into third-party
Proposed by
Eduardo Mucelli Rezende Oliveira
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/demo_ruby |
Merge into: | lp:~cairo-dock-team/cairo-dock-plug-ins-extras/third-party |
Diff against target: |
397 lines (+323/-6) 7 files modified
RubyBattery/RubyBattery (+5/-4) RubyBattery/RubyBattery.conf (+1/-1) RubyBattery/auto-load.conf (+1/-1) demos/demo_ruby/README (+19/-0) demos/demo_ruby/auto-load.conf (+13/-0) demos/demo_ruby/demo_ruby (+183/-0) demos/demo_ruby/demo_ruby.conf (+101/-0) |
To merge this branch: | bzr merge lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/demo_ruby |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Matthieu Baerts | duplicated branch | Disapprove | |
Review via email: mp+22228@code.launchpad.net |
Commit message
New applet demo_ruby
Description of the change
A applet for demonstration of Ruby Dbus and Cairo-Dock interaction.
To post a comment you must log in.
Revision history for this message
Matthieu Baerts (matttbe) : | # |
review:
Disapprove
(duplicated branch)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'RubyBattery/RubyBattery' |
2 | --- RubyBattery/RubyBattery 2010-03-25 01:38:53 +0000 |
3 | +++ RubyBattery/RubyBattery 2010-03-26 15:07:19 +0000 |
4 | @@ -56,7 +56,7 @@ |
5 | MenuShowCharge = 1 |
6 | MenuShowAlert = 2 |
7 | |
8 | - DialogActiveTime = 5 |
9 | + DialogActiveTime = 5 # dialog windows will keep opened this value in seconds |
10 | |
11 | def initialize (applet, conf) |
12 | @icon = applet |
13 | @@ -83,6 +83,7 @@ |
14 | |
15 | def set_initial_graphic_configurations |
16 | @icon.SetLabel(@conf.params['Icon']['name']) |
17 | + p "GAUGE #{@conf.params['Configuration']['theme']}" |
18 | @icon.AddDataRenderer("gauge", 1, @conf.params['Configuration']['theme']) # o padrao é Ruby-Battery |
19 | end |
20 | |
21 | @@ -159,12 +160,12 @@ |
22 | def retrieve_battery_information |
23 | raw_info = "" |
24 | raw_temperature = "" |
25 | - IO.popen("acpi -t") { |f| |
26 | + IO.popen("acpi -b") { |f| # charge and status in its raw form |
27 | raw_info = f.first.chomp.strip.split(':').last.strip.split(',') |
28 | + } |
29 | + IO.popen("acpi -t") {|f| # temperature in its raw form |
30 | raw_temperature = f.readlines.last.chomp.strip.split(',').last.strip |
31 | } |
32 | - # o raw_info tem [status, carga] quando a bateria esta ligada e [status, carga, mensagem] quando desligada "Discharging" |
33 | - # remove-se o valor "mensagem" e mantem-se pegando o primeiro e o ultimo elemento |
34 | if raw_info.first == "Discharging" || raw_info.first == "Charging" |
35 | raw_info.delete raw_info.last |
36 | end |
37 | |
38 | === modified file 'RubyBattery/RubyBattery.conf' |
39 | --- RubyBattery/RubyBattery.conf 2010-03-25 01:38:53 +0000 |
40 | +++ RubyBattery/RubyBattery.conf 2010-03-26 15:07:19 +0000 |
41 | @@ -91,5 +91,5 @@ |
42 | [Configuration] |
43 | |
44 | #h+[/usr/share/cairo-dock/gauges;gauges;gauges] Choose one of the available themes :/ |
45 | -# Remember that there is a gauge made to this applet, Ruby-Batter. Read the README file. |
46 | +# Remember that there is a gauge made to this applet, Ruby-Battery. Read the README file. |
47 | theme = Battery |
48 | |
49 | === modified file 'RubyBattery/auto-load.conf' |
50 | --- RubyBattery/auto-load.conf 2010-03-25 01:38:53 +0000 |
51 | +++ RubyBattery/auto-load.conf 2010-03-26 15:07:19 +0000 |
52 | @@ -10,4 +10,4 @@ |
53 | category = 2 |
54 | |
55 | # Version of the applet; change it everytime you change something in the config file. Don't forget to update the version both in this file and in the config file. |
56 | -version = 0.0.1 |
57 | +version = 0.0.2 |
58 | |
59 | === added directory 'demos/demo_ruby' |
60 | === added file 'demos/demo_ruby/README' |
61 | --- demos/demo_ruby/README 1970-01-01 00:00:00 +0000 |
62 | +++ demos/demo_ruby/README 2010-03-26 15:07:19 +0000 |
63 | @@ -0,0 +1,19 @@ |
64 | +In order to use this applet, it is necessary to install Ruby, Rubygems and the gems rbus and parseconfig. |
65 | + |
66 | +# Installation process (Debian/Ubuntu) |
67 | + |
68 | +* Ruby: (sudo) apt-get install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 rubygems1.8 acpi |
69 | +* Gem Rbus: (sudo) gem install rbus |
70 | +* Gem parseconfig: (sudo) gem install parseconfig |
71 | +(if you don't have Rubygems: Instructions are neatly described in http://rubygems.org/pages/download) |
72 | + |
73 | +# Tips |
74 | + |
75 | +When running Cairo-Dock through terminal, for example, cairo-dock -c, check if any message regarding execution permission is being shown. If so, set execution permission to the applet, chmod a+x 755 demo_ruby |
76 | + |
77 | +# Contact me |
78 | + |
79 | +Any doubt, suggestion or anything else, except asking for some money, I would be pleased to received a message from you. |
80 | + |
81 | +Author: Eduardo Mucelli Rezende Oliveira |
82 | +E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br |
83 | |
84 | === added file 'demos/demo_ruby/auto-load.conf' |
85 | --- demos/demo_ruby/auto-load.conf 1970-01-01 00:00:00 +0000 |
86 | +++ demos/demo_ruby/auto-load.conf 2010-03-26 15:07:19 +0000 |
87 | @@ -0,0 +1,13 @@ |
88 | +[Register] |
89 | + |
90 | +# Author of the applet |
91 | +author = Eduardo Mucelli Rezende Oliveira |
92 | + |
93 | +# A short description of the applet and how to use it. |
94 | +description = This is a distant applet\nIt simulates a counter:\n Scroll up/down to increase/decrease the counter,\n Click/middle-click to increase/decrease the counter by 10\n Drop some text to set it as the label. |
95 | + |
96 | +# Category of the applet : 2 = accessory, 3 = Desktop, 4 = Controler |
97 | +category = 2 |
98 | + |
99 | +# Version of the applet; change it everytime you change something in the config file. Don't forget to update the version both in this file and in the config file. |
100 | +version = 0.0.1 |
101 | |
102 | === added file 'demos/demo_ruby/demo_ruby' |
103 | --- demos/demo_ruby/demo_ruby 1970-01-01 00:00:00 +0000 |
104 | +++ demos/demo_ruby/demo_ruby 2010-03-26 15:07:19 +0000 |
105 | @@ -0,0 +1,183 @@ |
106 | +#!/usr/bin/ruby |
107 | + |
108 | +# This is a part of the external demo_ruby applet for Cairo-Dock |
109 | +# |
110 | +# Author: Eduardo Mucelli Rezende Oliveira |
111 | +# E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br |
112 | +# |
113 | +# This program is free software: you can redistribute it and/or modify |
114 | +# it under the terms of the GNU General Public License as published by |
115 | +# the Free Software Foundation, either version 3 of the License, or |
116 | +# (at your option) any later version. |
117 | + |
118 | +# This program is distributed in the hope that it will be useful, |
119 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
120 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
121 | +# GNU General Public License for more details. |
122 | + |
123 | +# This very simple applet features a counter from 0 to max_value. It displays the counter on the icon with a gauge and a quick info. |
124 | +# Scroll on the icon increase or decrease the counter |
125 | +# The menu offers the possibility to set some default value |
126 | +# Left click on the icon will set a random value |
127 | +# Middle click on the icon will raise a dialog asking you to set the value you want |
128 | +# If you drop some text on the icon, it will be used as the icon's label |
129 | +# Be aware to the messages, they are very wise :-) |
130 | + |
131 | +require 'rubygems' |
132 | +require 'rbus' |
133 | +require 'parseconfig' |
134 | + |
135 | +applet_name = File.basename(Dir.getwd) # nome do applet, neste caso é demo_ruby |
136 | +applet_path = "/org/cairodock/CairoDock/#{applet_name}" # path where our object is stored on the bus |
137 | + |
138 | +bus = RBus.session_bus |
139 | +applet_object = bus.get_object('org.cairodock.CairoDock', applet_path) # the main icon object |
140 | +applet_object.interface!('org.cairodock.CairoDock.applet') # get the services available to the main icon |
141 | + |
142 | +applet_sub_icons_object = bus.get_object("org.cairodock.CairoDock", "#{applet_path}/sub_icons") |
143 | +applet_sub_icons_object.interface!("org.cairodock.CairoDock.subapplet") # list of icons contained in our sub-dock, or in our desklet |
144 | + |
145 | +conf_file = "#{Dir.getwd}/#{applet_name}.conf" # configuration file does not need to be verified |
146 | +conf = ParseConfig.new(conf_file) |
147 | + |
148 | +class String |
149 | + def to_b # string to boolean |
150 | + ["true", "1", "T", "t"].include?(self.downcase) |
151 | + end |
152 | +end |
153 | + |
154 | +class Applet |
155 | + attr_accessor :counter, :configuration |
156 | + def initialize (applet, applet_sub_icons, conf) |
157 | + @icon = applet |
158 | + @sub_icons = applet_sub_icons |
159 | + @conf = conf |
160 | + self.counter = 0 |
161 | + self.configuration = get_configuration_parameters |
162 | + end |
163 | + def start |
164 | + @icon.ShowDialog("I'm connected to Cairo-Dock !", 4) # show a dialog with this message for 4 seconds |
165 | + @icon.SetQuickInfo("#{self.counter}") # write the counter value on the icon |
166 | + @icon.AddDataRenderer("gauge", 1, self.configuration['theme']) # set 1 gauge with the theme read in config |
167 | + @icon.RenderValues([Float(self.counter)/self.configuration['max_value']]) # draw the gauge with an initial value |
168 | + |
169 | + @sub_icons.AddSubIcons(["icon 1", "firefox-3.0", "id1", "icon 3", "thunderbird", "id3", "icon 4", "nautilus", "id4"]) |
170 | + @sub_icons.RemoveSubIcon("id2") # remove the 2nd icon of our sub-dock |
171 | + @sub_icons.SetQuickInfo("1", "id1") # write the ID on each icon of the sub-dock |
172 | + @sub_icons.SetQuickInfo("3", "id3") |
173 | + @sub_icons.SetQuickInfo("4", "id4") |
174 | + get_user_actions |
175 | + end |
176 | + def get_configuration_parameters |
177 | + c = {} |
178 | + c['max_value'] = @conf.params['Configuration']['max value'].to_i |
179 | + c['theme'] = @conf.params['Configuration']['theme'] |
180 | + c['yes_no'] = @conf.params['Configuration']['yesno'].to_b |
181 | + c |
182 | + end |
183 | + def get_user_actions |
184 | + @icon.connect!(:on_click) do |param| |
185 | + action_on_click |
186 | + end |
187 | + @icon.connect!(:on_build_menu) do |param| # when user right-clicks on our applet (which builds the menu) |
188 | + action_on_build_menu |
189 | + end |
190 | + @icon.connect!(:on_menu_select) do |menu_id| # when the user selected some menu build on build_menu action |
191 | + action_on_menu_select menu_id |
192 | + end |
193 | + @icon.connect!(:on_scroll) do |scroll_direction| # when the user scroll the mouse up or down on the icon |
194 | + action_on_scroll scroll_direction # scroll down param = false, scroll up param = true |
195 | + end |
196 | + @icon.connect!(:on_drop_data) do |dropped_date| # something was dragged n dropped into the icon |
197 | + action_on_drop_data dropped_date |
198 | + end |
199 | + @icon.connect!(:on_middle_click) do |param| |
200 | + action_on_middle_click |
201 | + end |
202 | + @icon.connect!(:on_answer) do |answer| # answer from some Ask* method |
203 | + action_on_answer answer |
204 | + end |
205 | + @icon.connect!(:on_stop_module) do |param| |
206 | + action_on_stop # DBus plug-in or applet deactivated, or Cairo-Dock stopped |
207 | + end |
208 | + @sub_icons.connect!(:on_click_sub_icon) do |state, icon_id| |
209 | + action_on_click_sub_icon state, icon_id # when the user left-clicks on a sub-icon |
210 | + end |
211 | + end |
212 | + |
213 | + # callbacks on the main icon |
214 | + def action_on_click |
215 | + p "[+] roger, right-click" |
216 | + render_counter (rand self.configuration['max_value']) |
217 | + end |
218 | + def action_on_middle_click |
219 | + p "[+] yes sir, middle-click received" |
220 | + @icon.AskValue("Set the value you want", self.counter, self.configuration['max_value']) |
221 | + end |
222 | + def action_on_build_menu |
223 | + p "[+] let's build the menu" |
224 | + @icon.PopulateMenu(["set min value", "set medium value", "set max value"]) |
225 | + end |
226 | + def action_on_menu_select param |
227 | + p "[+] let me guess, somebody chose the menu identified by the ID #{param}" |
228 | + if param == 0 |
229 | + render_counter 0 |
230 | + elsif param == 1 |
231 | + render_counter self.configuration['max_value']/2 |
232 | + else |
233 | + render_counter self.configuration['max_value'] |
234 | + end |
235 | + end |
236 | + def action_on_scroll scroll_up |
237 | + p "[+] is there anybody out there scrolling #{scroll_up ? "up" : "down"} on my icon ?" |
238 | + if scroll_up |
239 | + count = [self.configuration['max_value'], self.counter + 1].min |
240 | + else |
241 | + count = [0, self.counter - 1].max |
242 | + end |
243 | + render_counter count |
244 | + end |
245 | + def action_on_drop_data dropped_data |
246 | + print "[+] ops, someone let #{dropped_data} fall into my icon" |
247 | + @icon.SetLabel(dropped_data) |
248 | + end |
249 | + def action_on_answer answer |
250 | + p "[+] answer: #{answer}" |
251 | + render_counter answer |
252 | + end |
253 | + |
254 | + # callbacks on the applet |
255 | + def action_on_stop |
256 | + p "[+] bye bye" |
257 | + exit |
258 | + end |
259 | + def action_on_reload config_has_changed |
260 | + p "[+] our module was reloaded, welcome back!" |
261 | + if config_has_changed |
262 | + p "[+] and our config has been changed" |
263 | + self.configuration = get_configuration_parameters |
264 | + @icon.AddDataRenderer("gauge", 1, myApplet.config['theme']) |
265 | + @icon.RenderValues([Float(self.counter)/self.configuration['max_value']]) |
266 | + @sub_icons.RemoveSubIcon("any") |
267 | + @sub_icons.AddSubIcons(["icon 1", "firefox-3.0", "id1", "icon 2", "natilus", "id2", "icon 3", "thunderbird", "id3"]) |
268 | + else |
269 | + p "[-] but the config is the same" |
270 | + end |
271 | + end |
272 | + |
273 | + # callbacks on the sub-icons |
274 | + def action_on_click_sub_icon state, icon_id |
275 | + p "[+] something tells me that you clicked on the icon #{icon_id}" |
276 | + end |
277 | + |
278 | + def render_counter cont |
279 | + self.counter = cont # equivalent to the set_count method in demo_python |
280 | + percent = Float(self.counter) / self.configuration['max_value'] |
281 | + @icon.RenderValues([percent]) |
282 | + @icon.SetQuickInfo("#{self.counter.to_i}") |
283 | + end |
284 | +end |
285 | + |
286 | +applet = Applet.new applet_object, applet_sub_icons_object, conf |
287 | +applet.start |
288 | +RBus.mainloop |
289 | |
290 | === added file 'demos/demo_ruby/demo_ruby.conf' |
291 | --- demos/demo_ruby/demo_ruby.conf 1970-01-01 00:00:00 +0000 |
292 | +++ demos/demo_ruby/demo_ruby.conf 2010-03-26 15:07:19 +0000 |
293 | @@ -0,0 +1,101 @@ |
294 | +#!en;0.0.2 |
295 | + |
296 | +#[gtk-about] |
297 | +[Icon] |
298 | +#j+[0;128] Desired icon size for this applet |
299 | +#{Set to 0 to use the default applet size} |
300 | +icon size = 0;0 |
301 | + |
302 | +#s Name of the icon as it will appear in its label in the dock : |
303 | +name = Dbus Applet |
304 | + |
305 | +#S+ Image's filename : |
306 | +#{Let empty to use the default one.} |
307 | +icon = |
308 | + |
309 | +#d Name of the dock it belongs to: |
310 | +dock name = |
311 | + |
312 | +order= |
313 | + |
314 | +#F[Applet's Handbook] |
315 | +frame_hand= |
316 | +#A |
317 | +handbook=demo_ruby |
318 | + |
319 | +#[gtk-convert] |
320 | +[Desklet] |
321 | + |
322 | +#j+[48;512] Desklet's dimension (width x height) : |
323 | +#{Depending on your WindowManager, you can resize it with ALT + middle_click or ALT + left_click for exemple.} |
324 | +size = 164;96 |
325 | + |
326 | +#i[-2048;2048] Desklet's position (x ; y) : |
327 | +#{Depending on your WindowManager, you can move it with ALT + left_click} |
328 | +x position=0 |
329 | +#i[-2048;2048] ... |
330 | +y position=0 |
331 | + |
332 | +#b Is detached from the dock ? |
333 | +initially detached=false |
334 | +#l[Normal;Keep above;Keep below;On Widget Layer;Reserve space] Accessibility : |
335 | +#{for CompizFusion's "widget layer", set behaviour in Compiz to: (class=Cairo-dock & type=utility)} |
336 | +accessibility=0 |
337 | +#b Should be visible on all desktops ? |
338 | +sticky=true |
339 | + |
340 | +#b Lock position ? |
341 | +#{If locked, the desklet can't be moved by simply dragging it with the left mouse button. Of course you can still move it with ALT + left_click.} |
342 | +locked = false |
343 | + |
344 | +#I[-180;180] Rotation : |
345 | +#{in degrees.} |
346 | +rotation = 0 |
347 | + |
348 | +use size= |
349 | + |
350 | +#F[Decorations;gtk-orientation-portrait] |
351 | +frame_deco= |
352 | + |
353 | +#o+ Choose a decoration theme for this desklet : |
354 | +#{Choose the 'personnal' one to define your own decorations below.} |
355 | +decorations = default |
356 | + |
357 | +#v |
358 | +sep_deco = |
359 | + |
360 | +#S+ Background image : |
361 | +#{It's an image that will be displayed below the drawings, like a frame for exemple. Let empty to not use any.} |
362 | +bg desklet = |
363 | +#e+[0;1] Background tansparency : |
364 | +bg alpha = 1 |
365 | +#i+[0;256] Left offset : |
366 | +#{in pixels. Use this to adjust the left position of the drawings.} |
367 | +left offset = 0 |
368 | +#i+[0;256] Top offset : |
369 | +#{in pixels. Use this to adjust the top position of the drawings.} |
370 | +top offset = 0 |
371 | +#i+[0;256] Right offset : |
372 | +#{in pixels. Use this to adjust the right position of the drawings.} |
373 | +right offset = 0 |
374 | +#i+[0;256] Bottom offset : |
375 | +#{in pixels. Use this to adjust the bottom position of the drawings.} |
376 | +bottom offset = 0 |
377 | +#S+ Foreground image : |
378 | +#{It's an image that will be displayed above the drawings, like a reflect for exemple. Let empty to not use any.} |
379 | +fg desklet = |
380 | +#e+[0;1] Foreground tansparency : |
381 | +fg alpha = 1 |
382 | + |
383 | +#[gtk-preferences] |
384 | +[Configuration] |
385 | + |
386 | +#h+[/usr/share/cairo-dock/gauges;gauges;gauges] Choose one of the available themes :/ |
387 | +theme = Turbo-night |
388 | + |
389 | +#i[10;100] Max value : |
390 | +max value = 100 |
391 | + |
392 | +#b Yes / No ? |
393 | +yesno = false |
394 | + |
395 | |
396 | === added file 'demos/demo_ruby/icon' |
397 | Binary files demos/demo_ruby/icon 1970-01-01 00:00:00 +0000 and demos/demo_ruby/icon 2010-03-26 15:07:19 +0000 differ |