Merge lp:~doctormo/indiv-screenlets/color-changing-ringsensor into lp:indiv-screenlets

Proposed by Martin Owens
Status: Merged
Approved by: Märt Põder
Approved revision: 874
Merge reported by: Märt Põder
Merged at revision: not available
Proposed branch: lp:~doctormo/indiv-screenlets/color-changing-ringsensor
Merge into: lp:indiv-screenlets
Diff against target: 173 lines (+73/-43)
1 file modified
src/RingSensors/RingSensorsScreenlet.py (+73/-43)
To merge this branch: bzr merge lp:~doctormo/indiv-screenlets/color-changing-ringsensor
Reviewer Review Type Date Requested Status
Märt Põder Approve
Review via email: mp+55178@code.launchpad.net

Description of the change

Adds some new colour options into the ring screenlet. Fancy and awesome.

To post a comment you must log in.
Revision history for this message
Märt Põder (boamaod) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/RingSensors/RingSensorsScreenlet.py'
--- src/RingSensors/RingSensorsScreenlet.py 2011-02-23 23:36:12 +0000
+++ src/RingSensors/RingSensorsScreenlet.py 2011-03-28 16:18:30 +0000
@@ -17,7 +17,8 @@
1717
18import screenlets18import screenlets
19from screenlets import sensors19from screenlets import sensors
20from screenlets.options import FloatOption, BoolOption, StringOption, IntOption, ColorOption20from screenlets.options import FloatOption, BoolOption, StringOption,\
21 IntOption, ColorOption, ColorsOption
21import cairo22import cairo
22import pango23import pango
23import sys24import sys
@@ -57,8 +58,9 @@
57 linear = ''58 linear = ''
58 hourMiddle = False59 hourMiddle = False
59 color_back = (1,1,1,0.6)60 color_back = (1,1,1,0.6)
60 color_front =(1, 1, 1, 0.9)61 color_front = (1, 1, 1, 0.9)
61 color_text = (1, 1, 1, 1)62 color_text = (1, 1, 1, 1)
63 style_front = 'Fan'
62 graph_type = 'Graph'64 graph_type = 'Graph'
63 thickness = 24.065 thickness = 24.0
64 ringSpacing = 26.066 ringSpacing = 26.0
@@ -71,7 +73,7 @@
71 new_cpu = 073 new_cpu = 0
72 wire_list = []74 wire_list = []
73 wire_data = []75 wire_data = []
74 big_bars = True76 segment_count = 12
7577
76 down = 078 down = 0
77 download = 079 download = 0
@@ -139,16 +141,23 @@
139 self.add_option(ColorOption(_('Sensors'),'color_back', 141 self.add_option(ColorOption(_('Sensors'),'color_back',
140 self.color_back, 'background color', ''))142 self.color_back, 'background color', ''))
141143
142 self.add_option(ColorOption(_('Sensors'),'color_front', 144 self.add_option(ColorsOption(_('Sensors'),'color_front',
143 self.color_front, _('Front color'), 145 default=self.color_front, label=_('Active Color')))
144 ''))146
147 self.add_option(StringOption(_('Sensors'),'style_front',
148 default=self.style_front, label=_('Active Style'),
149 choices=['Fan', 'Grad']))
150
145 self.add_option(ColorOption(_('Sensors'),'color_text', 151 self.add_option(ColorOption(_('Sensors'),'color_text',
146 self.color_text, _('Text color'), 152 self.color_text, _('Text color'),
147 ''))153 ''))
148 self.add_option(FloatOption(_('Sensors'), 'thickness', self.thickness, _('Ring Thickness'), '',min=0.0, max=500.0, increment=0.1))154 self.add_option(FloatOption(_('Sensors'), 'thickness', self.thickness, _('Ring Thickness'), '',min=0.0, max=500.0, increment=0.1))
149 self.add_option(FloatOption(_('Sensors'), 'blockSpacing', self.blockSpacing, _('Block Spacing'), '',min=0.0, max=6.0, increment=0.1))155 self.add_option(FloatOption(_('Sensors'), 'blockSpacing', self.blockSpacing, _('Block Spacing'), '',min=0.0, max=6.0, increment=0.1))
150 self.add_option(BoolOption(_('Sensors'), 'big_bars',156
151 self.big_bars, _('Use Big bars'), ''))157 self.add_option(IntOption(_('Sensors'), 'segment_count',
158 default=self.segment_count, label=_('Number of Segments'),
159 desc=_('Big Bars is 12, Small is 60'), min=10, max=80))
160
152 self.add_option(FloatOption(_('Sensors'), 'max_download', self.max_download, _('Max dl speed (kilobytes/s)'), '',min=0.0, max=1000000.0, increment=10))161 self.add_option(FloatOption(_('Sensors'), 'max_download', self.max_download, _('Max dl speed (kilobytes/s)'), '',min=0.0, max=1000000.0, increment=10))
153 self.add_option(FloatOption(_('Sensors'), 'max_upload', self.max_upload, _('Max ul speed (kilobytes/s)'), '',min=0.0, max=1000000.0, increment=10))162 self.add_option(FloatOption(_('Sensors'), 'max_upload', self.max_upload, _('Max ul speed (kilobytes/s)'), '',min=0.0, max=1000000.0, increment=10))
154163
@@ -278,54 +287,75 @@
278 self.redraw_canvas()287 self.redraw_canvas()
279 return True288 return True
280289
290 def gradiant_colours(self, colours, index, max):
291 """Take a set of colours and make a pretty rainbow."""
292 # These first checks provide compatability and stop wasteful
293 # Mathamatics when we know the outcome.
294 if type(colours[0]) in [float, int]:
295 return colours
296 if len(colours) == 1:
297 return colours[0]
298 if index == max:
299 return colours[-1]
300
301 grad = float(index) / max
302 isect = len(colours) - 1
303 sect = int(grad * isect)
304 grad = (float(index) - (max / isect * sect)) / (max / isect)
305 first = colours[sect]
306 second = colours[sect+1]
307 return (
308 first[0] + (second[0] - first[0]) * grad,
309 first[1] + (second[1] - first[1]) * grad,
310 first[2] + (second[2] - first[2]) * grad,
311 first[3] + (second[3] - first[3]) * grad,
312 )
281313
282 def on_draw(self, ctx):314 def on_draw(self, ctx):
283315 """Draw a rainbow coloured arc as the sensor value."""
284 ctx.scale(self.scale, self.scale)316 ctx.scale(self.scale, self.scale)
285 # draw bg (if theme available)317 # draw bg (if theme available)
286 ctx.set_operator(cairo.OPERATOR_ADD)318 ctx.set_operator(cairo.OPERATOR_ADD)
287 319
288320 startrad = self.size-(self.thickness/2.0)
289 startrad = self.size-(self.thickness/2.0) 321 ctx.set_line_width( self.thickness )
290 a = float(self.load*11)/100322
291 323 # This could now be made into a more variable option.
292 324 segments = self.segment_count
293 ctx.set_line_width( self.thickness ) 325 fract = float(self.load * (segments-1)) / 100
294 if self.big_bars:326
295 for i in range(12):327 col = (0, 0, 0, 1)
296 if i == a or (i<=a ): col = self.color_front328 if self.style_front == 'Fan':
297 else: col = self.color_back329 col = self.gradiant_colours(self.color_front, fract, segments - 1)
298 if self.hourMiddle: radius = startrad-(self.ringSpacing*2.0)330
299 else: radius = startrad331 for i in range(segments):
300 pos = -90+(self.blockSpacing/2.0)+(i*30)332 if i > fract:
301 333 col = self.color_back
302 ctx.arc( 100, 100, radius, math.radians(pos), math.radians(pos+30-self.blockSpacing) )334 elif self.style_front == 'Grad':
303 ctx.set_source_rgba(col[0],col[1],col[2],col[3])335 col = self.gradiant_colours(self.color_front, i, segments - 1)
304 ctx.stroke()336
305 else:337 if self.hourMiddle:
306 a = float(self.load*59)/100338 radius = startrad-(self.ringSpacing*2.0)
307 for i in range(60):339 else:
308 if i == a or (i<=a ): col = self.color_front340 radius = startrad
309 else: col = self.color_back341
310 if self.hourMiddle: radius = startrad-(self.ringSpacing*2.0)342 rad_width = 360 / segments
311 else: radius = startrad343 pos = -90 + (self.blockSpacing / 2.0) + (i * rad_width)
312 pos = -90+(self.blockSpacing/2.0)+(i*6)344 rad_from = math.radians(pos)
313 345 rad_to = math.radians(pos + rad_width - self.blockSpacing)
314 ctx.arc( 100, 100, radius, math.radians(pos), math.radians(pos+6-self.blockSpacing) )346 ctx.arc( 100, 100, radius, rad_from, rad_to )
315 ctx.set_source_rgba(col[0],col[1],col[2],col[3])347 ctx.set_source_rgba(col[0], col[1], col[2], col[3])
316 ctx.stroke()348 ctx.stroke()
349
317 if len(str(self.load))==1:350 if len(str(self.load))==1:
318 self.load = "0" + str(self.load)351 self.load = "0" + str(self.load)
319 ctx.set_source_rgba(self.color_text[0],self.color_text[1],self.color_text[2],self.color_text[3])352 ctx.set_source_rgba(self.color_text[0],self.color_text[1],self.color_text[2],self.color_text[3])
320 if self.sensor.endswith('RPM') or self.sensor.endswith('C') or self.sensor.endswith('V') or self.sensor.find(':') != -1:353 if self.sensor.endswith('RPM') or self.sensor.endswith('C') or self.sensor.endswith('V') or self.sensor.find(':') != -1:
321 text = '<small><small><small><small>' +str(self.sensor.split(':')[0]) +'</small></small></small></small>\n'+str(self.sensor.split(':')[1]) 354 text = '<small><small><small><small>' +str(self.sensor.split(':')[0]) +'</small></small></small></small>\n'+str(self.sensor.split(':')[1])
322 else:355 else:
323 text = '<small><small><small><small>' +self.sensor +'</small></small></small></small>\n'+self.text_prefix + str(self.load) + self.text_suffix356 text = '<small><small><small><small>' +self.sensor +'</small></small></small></small>\n'+self.text_prefix + str(self.load) + self.text_suffix
324 ctx.set_operator(cairo.OPERATOR_OVER)357 ctx.set_operator(cairo.OPERATOR_OVER)
325 if self.show_text and self.theme:self.theme.draw_text(ctx,text, 0, 70, 'Free Sans', 25, self.width,pango.ALIGN_CENTER)358 if self.show_text and self.theme:self.theme.draw_text(ctx,text, 0, 70, 'Free Sans', 25, self.width,pango.ALIGN_CENTER)
326
327
328
329359
330 def on_draw_shape(self,ctx):360 def on_draw_shape(self,ctx):
331 self.on_draw(ctx)361 self.on_draw(ctx)

Subscribers

People subscribed via source and target branches