Advertisement
aesc22

clock_rings.lua

Oct 2nd, 2011
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.95 KB | None | 0 0
  1. --[[
  2. Clock Rings by Linux Mint (2011) reEdited by westkid
  3.  
  4. This script draws percentage meters as rings, and also draws clock hands if you want! It is fully customisable; all options are described in the script. This script is based off a combination of my clock.lua script and my rings.lua script.
  5.  
  6. IMPORTANT: if you are using the 'cpu' function, it will cause a segmentation fault if it tries to draw a ring straight away. The if statement on line 145 uses a delay to make sure that this doesn't happen. It calculates the length of the delay by the number of updates since Conky started. Generally, a value of 5s is long enough, so if you update Conky every 1s, use update_num>5 in that if statement (the default). If you only update Conky every 2s, you should change it to update_num>3; conversely if you update Conky every 0.5s, you should use update_num>10. ALSO, if you change your Conky, is it best to use "killall conky; conky" to update it, otherwise the update_num will not be reset and you will get an error.
  7.  
  8. To call this script in Conky, use the following (assuming that you save this script to ~/scripts/rings.lua):
  9. lua_load ~/scripts/clock_rings.lua
  10. lua_draw_hook_pre clock_rings
  11.  
  12. Changelog:
  13. + v1.0 -- Original release (30.09.2009)
  14. v1.1p -- Jpope edit londonali1010 (05.10.2009)
  15. *v Mint-lua -- reEdit despot77 (18.02.2011)
  16. Mint-lua -- reEdit westkid (23.08.2011)
  17. ]]
  18.  
  19. settings_table = {
  20.  
  21. {
  22. name='cpu',
  23. arg='cpu0',
  24. max=100,
  25. bg_colour=0xffffff,
  26. bg_alpha=0.2,
  27. fg_colour=0xd54d23,
  28. fg_alpha=0.6,
  29. x=90, y=120,
  30. radius=80,
  31. thickness=5,
  32. start_angle=-160,
  33. end_angle=90
  34. },
  35. {
  36. name='cpu',
  37. arg='cpu1',
  38. max=100,
  39. bg_colour=0xffffff,
  40. bg_alpha=0.2,
  41. fg_colour=0xd54d23,
  42. fg_alpha=0.6,
  43. x=90, y=120,
  44. radius=74,
  45. thickness=5,
  46. start_angle=-160,
  47. end_angle=90
  48. },
  49. {
  50. name='memperc',
  51. arg='',
  52. max=100,
  53. bg_colour=0xffffff,
  54. bg_alpha=0.2,
  55. fg_colour=0xd54d23,
  56. fg_alpha=0.6,
  57. x=60, y=245,
  58. radius=25,
  59. thickness=8,
  60. start_angle=-180,
  61. end_angle=90
  62. },
  63. {
  64. name='fs_used_perc',
  65. arg='/',
  66. max=100,
  67. bg_colour=0xffffff,
  68. bg_alpha=0.2,
  69. fg_colour=0xed54d23,
  70. fg_alpha=0.6,
  71. x=60, y=348,
  72. radius=25,
  73. thickness=8,
  74. start_angle=-180,
  75. end_angle=90
  76. },
  77. {
  78. name='fs_used_perc',
  79. arg='/home',
  80. max=100,
  81. bg_colour=0xffffff,
  82. bg_alpha=0.2,
  83. fg_colour=0xed54d23,
  84. fg_alpha=0.6,
  85. x=60, y=448,
  86. radius=25,
  87. thickness=8,
  88. start_angle=-180,
  89. end_angle=90
  90. },
  91. {
  92. name='upspeedf',
  93. arg='wlan0',
  94. max=100,
  95. bg_colour=0xffffff,
  96. bg_alpha=0.2,
  97. fg_colour=0xed54d23,
  98. fg_alpha=0.6,
  99. x=60, y=558,
  100. radius=25,
  101. thickness=4,
  102. start_angle=-180,
  103. end_angle=90
  104. },
  105. {
  106. name='downspeedf',
  107. arg='wlan0',
  108. max=284,
  109. bg_colour=0xffffff,
  110. bg_alpha=0.2,
  111. fg_colour=0xaa0315,
  112. fg_alpha=0.6,
  113. x=60, y=558,
  114. radius=20,
  115. thickness=4,
  116. start_angle=-180,
  117. end_angle=90
  118. },
  119.  
  120.  
  121.  
  122. }
  123.  
  124. -- Use these settings to define the origin and extent of your clock.
  125.  
  126. clock_r=65
  127.  
  128. -- "clock_x" and "clock_y" are the coordinates of the centre of the clock, in pixels, from the top left of the Conky window.
  129.  
  130. clock_x=100
  131. clock_y=150
  132.  
  133. show_seconds=true
  134.  
  135. require 'cairo'
  136.  
  137. function rgb_to_r_g_b(colour,alpha)
  138. return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
  139. end
  140.  
  141. function draw_ring(cr,t,pt)
  142. local w,h=conky_window.width,conky_window.height
  143.  
  144. local xc,yc,ring_r,ring_w,sa,ea=pt['x'],pt['y'],pt['radius'],pt['thickness'],pt['start_angle'],pt['end_angle']
  145. local bgc, bga, fgc, fga=pt['bg_colour'], pt['bg_alpha'], pt['fg_colour'], pt['fg_alpha']
  146.  
  147. local angle_0=sa*(2*math.pi/360)-math.pi/2
  148. local angle_f=ea*(2*math.pi/360)-math.pi/2
  149. local t_arc=t*(angle_f-angle_0)
  150.  
  151. -- Draw background ring
  152.  
  153. cairo_arc(cr,xc,yc,ring_r,angle_0,angle_f)
  154. cairo_set_source_rgba(cr,rgb_to_r_g_b(bgc,bga))
  155. cairo_set_line_width(cr,ring_w)
  156. cairo_stroke(cr)
  157.  
  158. -- Draw indicator ring
  159.  
  160. cairo_arc(cr,xc,yc,ring_r,angle_0,angle_0+t_arc)
  161. cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga))
  162. cairo_stroke(cr)
  163. end
  164.  
  165. function draw_clock_hands(cr,xc,yc)
  166. local secs,mins,hours,secs_arc,mins_arc,hours_arc
  167. local xh,yh,xm,ym,xs,ys
  168.  
  169. secs=os.date("%S")
  170. mins=os.date("%M")
  171. hours=os.date("%I")
  172.  
  173. secs_arc=(2*math.pi/60)*secs
  174. mins_arc=(2*math.pi/60)*mins+secs_arc/60
  175. hours_arc=(2*math.pi/12)*hours+mins_arc/12
  176.  
  177. end
  178.  
  179. function conky_clock_rings()
  180. local function setup_rings(cr,pt)
  181. local str=''
  182. local value=0
  183.  
  184. str=string.format('${%s %s}',pt['name'],pt['arg'])
  185. str=conky_parse(str)
  186.  
  187. value=tonumber(str)
  188. pct=value/pt['max']
  189.  
  190. draw_ring(cr,pct,pt)
  191. end
  192.  
  193. -- Check that Conky has been running for at least 5s
  194.  
  195. if conky_window==nil then return end
  196. local cs=cairo_xlib_surface_create(conky_window.display,conky_window.drawable,conky_window.visual, conky_window.width,conky_window.height)
  197.  
  198. local cr=cairo_create(cs)
  199.  
  200. local updates=conky_parse('${updates}')
  201. update_num=tonumber(updates)
  202.  
  203. if update_num>10 then
  204. for i in pairs(settings_table) do
  205. setup_rings(cr,settings_table[i])
  206. end
  207. end
  208.  
  209. draw_clock_hands(cr,clock_x,clock_y)
  210. end
  211.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement