SHARE
TWEET

Scarlett's Conky LUA 2013

mousers3 Mar 29th, 2013 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require 'cairo'
  2.  
  3. function conky_main()
  4.  
  5.  
  6.         if conky_window == nil then return end
  7.  
  8.         local cs = cairo_xlib_surface_create(conky_window.display,conky_window.drawable,conky_window.visual, conky_window.width, conky_window.height)
  9.         cr = cairo_create(cs)
  10.  
  11.         local updates=tonumber(conky_parse('${updates}'))
  12.  
  13.         if updates>5 then
  14.  
  15.   conky_image_func()
  16.   conky_name_func()
  17.   conky_cname_func()
  18.   conky_time_func()
  19.   conky_fs_func()
  20.   conky_net_func()
  21.   conky_resource_func()
  22.  
  23.         end-- if updates>5
  24.         cairo_surface_destroy (image);
  25.         cairo_destroy(cr)
  26.         cairo_surface_destroy(cs)
  27.         cr=nil
  28. end-- end main function
  29.  
  30. --Image
  31. --###################          
  32. function conky_image_func()
  33.   image = cairo_image_surface_create_from_png ("archtuxsm.png");
  34. cairo_set_source_surface (cr, image, 0, 0);
  35. cairo_paint (cr);      
  36. end
  37.  
  38. function conky_name_func()
  39. --Title
  40. --###################
  41. red=88/255
  42. green=155/255
  43. blue=200/255
  44.  
  45. cairo_select_font_face (cr, "Trade Winds", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_BOLD);
  46. cairo_set_font_size (cr, 26);
  47. cairo_set_source_rgba (cr,.8,.8,.8,1);
  48. cairo_move_to (cr,47,25);
  49. cairo_show_text (cr,"Scarlett's Computer");
  50. cairo_set_source_rgba (cr,red,green,blue,1);
  51. cairo_move_to (cr,49,26);
  52. cairo_show_text (cr,"Scarlett's Computer");
  53. cairo_stroke (cr)
  54. end
  55.  
  56. function conky_cname_func()
  57. --Computer Name
  58. --##################
  59. red=88/255
  60. green=155/255
  61. blue=200/255
  62.  
  63. cairo_select_font_face (cr, "Droid Serif", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_BOLD);
  64. cairo_set_font_size (cr, 16);
  65. cairo_set_source_rgba (cr,red,green,blue,1);
  66. local Cnamehandle = io.popen("uname -smr");
  67. local Cname = Cnamehandle:read("*a");
  68. Cnamehandle:close();
  69. cairo_move_to (cr, 75,70);
  70. cairo_show_text (cr, Cname);
  71.                
  72.  
  73. --##################
  74. cairo_set_line_width (cr,5);
  75. cairo_set_line_cap (cr,CAIRO_LINE_CAP_ROUND);
  76. cairo_set_source_rgba (cr,.8,.8,.8,1);
  77. cairo_move_to (cr,0,90);
  78. cairo_rel_line_to (cr,350,0);
  79. cairo_stroke (cr);
  80. --##################
  81. end
  82.  
  83. function conky_time_func()
  84. --Time
  85. --##################
  86. local mytime = os.date("%D      %I:%M:%S");
  87. cairo_move_to (cr,75,120);
  88. cairo_show_text (cr, mytime);
  89.  
  90. --##################
  91. cairo_set_line_width (cr,5);
  92. cairo_set_line_cap (cr,CAIRO_LINE_CAP_ROUND);
  93. cairo_set_source_rgba (cr,.8,.8,.8,1);
  94. cairo_move_to (cr,0,135);
  95. cairo_rel_line_to (cr,350,0);
  96. cairo_stroke (cr);
  97. --##################
  98. end
  99.  
  100. function conky_uptime_func()
  101. --Uptime
  102. --##################
  103. local uptimehandle = io.popen("uptime | awk '{print substr($3,1,length($3)-1)}'");
  104. local uptime = uptimehandle:read("*a");
  105. uptimehandle:close();
  106. cairo_move_to (cr, 25,170);
  107. cairo_show_text (cr, "Uptime");
  108. cairo_move_to (cr,100,170);
  109. cairo_show_text (cr,uptime);   
  110. cairo_move_to (cr,155,170);
  111. cairo_show_text (cr,"hours");  
  112.  
  113.  
  114. --##################
  115. cairo_set_line_width (cr,5);
  116. cairo_set_line_cap (cr,CAIRO_LINE_CAP_ROUND);
  117. cairo_set_source_rgba (cr,0.5,0.5,0.5,1);
  118. cairo_move_to (cr,25,180);
  119. cairo_rel_line_to (cr,250,0);
  120. cairo_stroke (cr);
  121. --##################
  122. end
  123. --CPU
  124. --##################
  125. function conky_fs_func()
  126. --##################
  127. cairo_set_line_width (cr,5);
  128. cairo_set_line_cap (cr,CAIRO_LINE_CAP_ROUND);
  129. cairo_set_source_rgba (cr,.8,.8,.8,1);
  130. cairo_move_to (cr,0,375);
  131. cairo_rel_line_to (cr,350,0);
  132. cairo_stroke (cr);
  133. --##################
  134. --section
  135. red=88/255
  136. green=155/255
  137. blue=200/255
  138. cairo_select_font_face (cr, "Trade Winds", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_BOLD);
  139. cairo_set_font_size (cr, 26);
  140. cairo_set_source_rgba (cr,red,green,blue,1);
  141. cairo_move_to (cr,05,400);
  142. cairo_show_text (cr,"Filesystem:");
  143. cairo_select_font_face (cr, "Droid Serif", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_BOLD);
  144. cairo_set_font_size (cr, 12);
  145. cairo_set_source_rgba (cr,red,green,blue,1);
  146. cairo_move_to (cr,0,428);
  147. cairo_show_text (cr,"Root    /");
  148.  
  149. cairo_move_to (cr,0,458);
  150. cairo_show_text (cr,"Home    /home");
  151.  
  152. --Settings
  153. ind_red=245/255
  154. ind_green=248/255
  155. ind_blue=196/255
  156. bar_bottom_left_X=100
  157. bar_bottom_left_Y=415
  158. bar_W=100
  159. bar_H=15
  160. max_value=100
  161. --disk size
  162. local fshandle = io.popen("df /dev/sda6 | awk 'NR==2 {print $2}'");
  163. local fstotal = tonumber(fshandle:read("*a"));
  164. fshandle:close();
  165. --used
  166. local fshandle = io.popen("df /dev/sda6 | awk 'NR==2 {print $3}'");
  167. local fsused = tonumber(fshandle:read("*a"));
  168. fshandle:close();
  169.  
  170. --draw
  171. cairo_set_source_rgba (cr,0.5,0.5,0.5,1);
  172. cairo_rectangle (cr, bar_bottom_left_X, bar_bottom_left_Y, bar_W, bar_H);
  173. cairo_fill (cr);
  174. value = fsused/fstotal;
  175. scale = bar_W/max_value
  176. indicator_width=scale*(value*100)
  177. cairo_set_source_rgba (cr,ind_red,ind_green,ind_blue,1);
  178. cairo_rectangle (cr, bar_bottom_left_X,bar_bottom_left_Y,indicator_width,bar_H)
  179. cairo_fill(cr)
  180. --##Second disk
  181. --settings
  182. bar_bottom_left_X2=100
  183. bar_bottom_left_Y2=445
  184. bar_W2=100
  185. bar_H2=15
  186. --disk size
  187. local fshandle = io.popen("df /dev/sda3 | awk 'NR==2 {print $2}'");
  188. local fstotal2 = tonumber(fshandle:read("*a"));
  189. fshandle:close();
  190. --used
  191. local fshandle = io.popen("df /dev/sda3 | awk 'NR==2 {print $3}'");
  192. local fsused2 = tonumber(fshandle:read("*a"));
  193. fshandle:close();
  194.  
  195. --draw
  196. cairo_set_source_rgba (cr,0.5,0.5,0.5,1);
  197. cairo_rectangle (cr, bar_bottom_left_X2, bar_bottom_left_Y2, bar_W2, bar_H2);
  198. cairo_fill (cr);
  199. value2 = fsused2/fstotal2;
  200. scale = bar_W2/max_value
  201. indicator_width2=scale*(value2*100)
  202. cairo_set_source_rgba (cr,ind_red,ind_green,ind_blue,1);
  203. cairo_rectangle (cr, bar_bottom_left_X2,bar_bottom_left_Y2,indicator_width2,bar_H2)
  204. cairo_fill(cr)
  205. end
  206.  
  207. function conky_net_func()
  208. --##################
  209. cairo_set_line_width (cr,5);
  210. cairo_set_line_cap (cr,CAIRO_LINE_CAP_ROUND);
  211. cairo_set_source_rgba (cr,.8,.8,.8,1);
  212. cairo_move_to (cr,0,475);
  213. cairo_rel_line_to (cr,350,0);
  214. cairo_stroke (cr);
  215. --##################
  216. --section
  217. red=88/255
  218. green=155/255
  219. blue=200/255
  220. cairo_select_font_face (cr, "Trade Winds", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_BOLD);
  221. cairo_set_font_size (cr, 26);
  222. cairo_set_source_rgba (cr,red,green,blue,1);
  223. cairo_move_to (cr,05,500);
  224. cairo_show_text (cr,"Network:");
  225. --#### TODO
  226. end
  227.  
  228. function conky_resource_func()
  229. --##################
  230. cairo_set_line_width (cr,5);
  231. cairo_set_line_cap (cr,CAIRO_LINE_CAP_ROUND);
  232. cairo_set_source_rgba (cr,.8,.8,.8,1);
  233. cairo_move_to (cr,0,600);
  234. cairo_rel_line_to (cr,350,0);
  235. cairo_stroke (cr);
  236. --##################
  237. --section
  238. red=88/255
  239. green=155/255
  240. blue=200/255
  241. cairo_select_font_face (cr, "Trade Winds", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_BOLD);
  242. cairo_set_font_size (cr, 26);
  243. cairo_set_source_rgba (cr,red,green,blue,1);
  244. cairo_move_to (cr,05,630);
  245. cairo_show_text (cr,"Top Resource Hogs:");
  246. --#### TODO
  247. end
RAW Paste Data
Top