Guest User

Untitled

a guest
Jan 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. --[[
  2. Ring Meters by londonali1010 (2009)
  3.  
  4. This script draws percentage meters as rings. It is fully customisable; all options are described in the 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 near the end of the script 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/rings-v1.2.1.lua
  10. lua_draw_hook_pre ring_stats
  11.  
  12. Changelog:
  13. + v1.2.1 -- Fixed minor bug that caused script to crash if conky_parse() returns a nil value (20.10.2009)
  14. + v1.2 -- Added option for the ending angle of the rings (07.10.2009)
  15. + v1.1 -- Added options for the starting angle of the rings, and added the "max" variable, to allow for variables that output a numerical value rather than a percentage (29.09.2009)
  16. + v1.0 -- Original release (28.09.2009)
  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=0xff7607,
  28. fg_alpha=0.8,
  29. x=210, y=115,
  30. radius=30,
  31. thickness=9,
  32. start_angle=0,
  33. end_angle=270
  34. },
  35. {
  36. name='memperc',
  37. arg='',
  38. max=100,
  39. bg_colour=0xffffff,
  40. bg_alpha=0.2,
  41. fg_colour=0xff7607,
  42. fg_alpha=0.8,
  43. x=212, y=226,
  44. radius=28,
  45. thickness=9,
  46. start_angle=0,
  47. end_angle=270
  48. },
  49. {
  50. name='swapperc',
  51. arg='',
  52. max=100,
  53. bg_colour=0xffffff,
  54. bg_alpha=0.2,
  55. fg_colour=0xff7607,
  56. fg_alpha=0.8,
  57. x=112, y=465,
  58. radius=23,
  59. thickness=9,
  60. start_angle=0,
  61. end_angle=270
  62. },
  63. {
  64. name='fs_used_perc',
  65. arg='/',
  66. max=100,
  67. bg_colour=0xffffff,
  68. bg_alpha=0.2,
  69. fg_colour=0xff7607,
  70. fg_alpha=0.8,
  71. x=209, y=330,
  72. radius=35,
  73. thickness=9,
  74. start_angle=0,
  75. end_angle=270
  76. },
  77. {
  78. name='downspeedf',
  79. arg='ttyUSB0',
  80. max=1000,
  81. bg_colour=0xffffff,
  82. bg_alpha=0.2,
  83. fg_colour=0x36a007,
  84. fg_alpha=0.8,
  85. x=185, y=443,
  86. radius=31,
  87. thickness=9,
  88. start_angle=0,
  89. end_angle=270
  90. },
  91. {
  92. name='upspeedf',
  93. arg='ttyUSB0',
  94. max=100,
  95. bg_colour=0xffffff,
  96. bg_alpha=0.2,
  97. fg_colour=0xf8ce58,
  98. fg_alpha=0.8,
  99. x=185, y=443,
  100. radius=17,
  101. thickness=9,
  102. start_angle=0,
  103. end_angle=270
  104. },
  105. }
  106.  
  107. require 'cairo'
  108.  
  109. function rgb_to_r_g_b(colour,alpha)
  110. return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
  111. end
  112.  
  113. function draw_ring(cr,t,pt)
  114. local w,h=conky_window.width,conky_window.height
  115.  
  116. local xc,yc,ring_r,ring_w,sa,ea=pt['x'],pt['y'],pt['radius'],pt['thickness'],pt['start_angle'],pt['end_angle']
  117. local bgc, bga, fgc, fga=pt['bg_colour'], pt['bg_alpha'], pt['fg_colour'], pt['fg_alpha']
  118.  
  119. local angle_0=sa*(2*math.pi/360)-math.pi/2
  120. local angle_f=ea*(2*math.pi/360)-math.pi/2
  121. local t_arc=t*(angle_f-angle_0)
  122.  
  123. -- Draw background ring
  124.  
  125. cairo_arc(cr,xc,yc,ring_r,angle_0,angle_f)
  126. cairo_set_source_rgba(cr,rgb_to_r_g_b(bgc,bga))
  127. cairo_set_line_width(cr,ring_w)
  128. cairo_stroke(cr)
  129.  
  130. -- Draw indicator ring
  131.  
  132. cairo_arc(cr,xc,yc,ring_r,angle_0,angle_0+t_arc)
  133. cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga))
  134. cairo_stroke(cr)
  135. end
  136.  
  137. function conky_ring_stats()
  138. local function setup_rings(cr,pt)
  139. local str=''
  140. local value=0
  141.  
  142. str=string.format('${%s %s}',pt['name'],pt['arg'])
  143. str=conky_parse(str)
  144.  
  145. value=tonumber(str)
  146. if value == nil then value = 0 end
  147. pct=value/pt['max']
  148.  
  149. draw_ring(cr,pct,pt)
  150. end
  151.  
  152. if conky_window==nil then return end
  153. local cs=cairo_xlib_surface_create(conky_window.display,conky_window.drawable,conky_window.visual, conky_window.width,conky_window.height)
  154.  
  155. local cr=cairo_create(cs)
  156.  
  157. local updates=conky_parse('${updates}')
  158. update_num=tonumber(updates)
  159.  
  160. if update_num>5 then
  161. for i in pairs(settings_table) do
  162. setup_rings(cr,settings_table[i])
  163. end
  164. end
  165. end
Add Comment
Please, Sign In to add comment