def draw_icon(machine,color1,color2):
'''Draws a graph with 2 columns 1 for each percentage (1 is full, 0 is empty)'''
WIDTH, HEIGHT = 22, 22
if machine['nGPUs'] > 2:
WIDTH = 11*machine['nGPUs'] #if more than 1 GPU on a machine, each column is 11px wide (and not 22px)
surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context (surface)
ctx.scale (WIDTH/machine['nGPUs'], HEIGHT) # Normalizing the canvas coordinates go from (0,0) to (nGPUs,1)
for i in range(machine['nGPUs']):
gpu = machine['GPUs'][i]
percentage1,percentage2 = gpu['utilization']/100,gpu['used_mem']/gpu['memory']
ctx.rectangle (i, 1-percentage1, 0.5, percentage1) # Rectangle(x0, y0, x1, y1)
ctx.set_source_rgb(color1[0]/255,color1[1]/255,color1[2]/255)
ctx.fill ()
ctx.rectangle (i+0.5, 1-percentage2, 0.5, percentage2) # Rectangle(x0, y0, x1, y1)
ctx.set_source_rgb(color2[0]/255,color2[1]/255,color2[2]/255)
ctx.fill ()
if 'i' not in machine.keys():
machine['i'] = 0
png_name = os.path.join(config_folder,machine['name']+str(machine['i'])+'.png')
machine['i'] = (machine['i']+1)%2
surface.write_to_png (png_name) # Output to PNG
return(png_name)
client_smi_appindicator.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录