class DistanceWindow(Gtk.Box): print("Loading GUI from Template") __gtype_name__ = 'DistanceWindow' measure_button1 = GtkTemplate.Child() Labelbox = GtkTemplate.Child() SaveCSV_Button = GtkTemplate.Child() distance1_label3 = GtkTemplate.Child() print("Loaded GUI elements") def __init__(self): #super(Gtk.Box, self).__init__() print("Initializing GUI") super().__init__() self.init_template() #self.measure_button1.clicked() @GtkTemplate.Callback def measure_button1_clicked_cb(self, widget): distance = measure_distance(self) print("The distance is:" + str(distance)) self.distance1_label3.set_markup( _('<span size="large">Distance 1 is:' + str(distance) + '</span>'))
class MiApp(Gtk.Window): __gtype_name__='MiApp' txt1 =GtkTemplate.Child() txt2 =GtkTemplate.Child() txt3 =GtkTemplate.Child() def __init__(self): Gtk.Window.__init__(self) self.init_template() self.personas=[] @GtkTemplate.Callback def _agregar_clicked_cb(self, button): nombre =self.txt1.get_text() apellido=self.txt2.get_text() carrera=self.txt3.get_text() self.personas.append((nombre, apellido, carrera)) @GtkTemplate.Callback def _destroy_cb(self, widget): f=open("personas.txt","a") for persona in self.personas: nombre=persona[0] apellido=persona[1] carrera=persona[2] f.write(nombre +" " + apellido +" "+ carrera+"\n") f.close() Gtk.main_quit()
class MyWidget(Gtk.Box): # Required else you would need to specify the full module # name in mywidget.ui (__main__+MyWidget) __gtype_name__ = 'MyWidget' entry = GtkTemplate.Child() # Alternative way to specify multiple widgets #label1, entry = GtkTemplate.Child.widgets(2) def __init__(self, text): super(Gtk.Box, self).__init__() # This must occur *after* you initialize your base self.init_template() self.entry.set_text(text) @GtkTemplate.Callback def button_clicked(self, widget, user_data): # 'object' attribute (user-data in glade) is set print("The button was clicked with entry text: %s" % self.entry.get_text()) print("The user-data is %s" % user_data) @GtkTemplate.Callback def entry_changed(self, widget): # 'object' attribute (user-data in glade) is not set print("The entry text changed: %s" % self.entry.get_text()) @GtkTemplate.Callback def on_MyWidget_destroy(self, widget): print("MyWidget destroyed")
class netSidepaneWidget(g.Box): # Required else you would need to specify the full module # name in mywidget.ui (__main__+MyWidget) __gtype_name__ = 'netSidepaneWidget' netsidepanetextlabel = GtkTemplate.Child() netsidepanelabelvalue = GtkTemplate.Child() netsidepanedrawarea = GtkTemplate.Child() net_switcher_button = GtkTemplate.Child() # Alternative way to specify multiple widgets #label1, entry = GtkTemplate.Child.widgets(2) def __init__(self): super(g.Box, self).__init__() # This must occur *after* you initialize your base self.init_template() self.netmxScalingFactor = 1 def givedata(self, secondself, index): self.netRecSpeedArray = secondself.netReceiveArray[index] self.netSendSpeedArray = secondself.netSendArray[index] @GtkTemplate.Callback def on_netSidepaneDrawArea_draw(self, dr, cr): cr.set_line_width(2) w = self.netsidepanedrawarea.get_allocated_width() h = self.netsidepanedrawarea.get_allocated_height() speedstep = 250 * 1024 #250KB/s maximumcurrentspeed = max(max(self.netRecSpeedArray), max(self.netSendSpeedArray)) currentscalespeed = self.netmxScalingFactor * speedstep while (currentscalespeed < maximumcurrentspeed): self.netmxScalingFactor += 1 currentscalespeed = self.netmxScalingFactor * speedstep while (currentscalespeed > maximumcurrentspeed and self.netmxScalingFactor > 1): self.netmxScalingFactor -= 1 currentscalespeed = self.netmxScalingFactor * speedstep scalingfactor = h / currentscalespeed #creating outer rectangle cr.set_source_rgba(.458, .141, .141, 1) cr.set_line_width(3) cr.rectangle(0, 0, w, h) cr.stroke() stepsize = w / 99.0 #print("in draw stepsize",stepsize) # for i in range(0,99): # # not effcient way to fill the bars (drawing) # cr.set_source_rgba(.709,.164,.164,.2) #for changing the fill color # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.netRecSpeedArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(currentscalespeed-self.netRecSpeedArray[i+1])+2) # cr.line_to((i+1)*stepsize,h) # cr.line_to(i*stepsize,h) # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.netRecSpeedArray[i])+2) # cr.fill() # cr.stroke() # # for outer line read speed # cr.set_line_width(1.5) # cr.set_source_rgba(.709,.164,.164,1) #for changing the outer line color # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.netRecSpeedArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(currentscalespeed-self.netRecSpeedArray[i+1])+2) # cr.stroke() # #for write # cr.set_source_rgba(1,.313,.313,.2) #for changing the fill color # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.netSendSpeedArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(currentscalespeed-self.netSendSpeedArray[i+1])+2) # cr.line_to((i+1)*stepsize,h) # cr.line_to(i*stepsize,h) # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.netSendSpeedArray[i])+2) # cr.fill() # cr.stroke() # # cr.set_dash([5.0]) # cr.set_source_rgba(1,.313,.313,1) #for changing the outer line color # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.netSendSpeedArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(currentscalespeed-self.netSendSpeedArray[i+1])+2) # cr.stroke() #efficient receive speed drawing cr.set_source_rgba(.709, .164, .164, 1) #for changing the outer line color cr.set_line_width(1.5) cr.move_to( 0, scalingfactor * (currentscalespeed - self.netRecSpeedArray[0]) + 2) for i in range(0, 99): cr.line_to((i + 1) * stepsize, scalingfactor * (currentscalespeed - self.netRecSpeedArray[i + 1]) + 2) cr.stroke_preserve() cr.set_source_rgba(.709, .164, .164, .2) #for changing the fill color cr.line_to(w, h) cr.line_to(0, h) cr.move_to( 0, scalingfactor * (currentscalespeed - self.netRecSpeedArray[0]) + 2) cr.fill() cr.stroke() #efficient drawing for send cr.set_source_rgba(1, .313, .313, 1) #for changing the outer line color cr.move_to( 0, scalingfactor * (currentscalespeed - self.netSendSpeedArray[0]) + 2) cr.set_line_width(1.5) for i in range(0, 99): cr.line_to((i + 1) * stepsize, scalingfactor * (currentscalespeed - self.netSendSpeedArray[i + 1]) + 2) cr.stroke_preserve() cr.set_source_rgba(1, .313, .313, .2) #for changing the fill color cr.line_to(w, h) cr.line_to(0, h) cr.move_to( 0, scalingfactor * (currentscalespeed - self.netSendSpeedArray[0]) + 2) cr.fill() cr.stroke() return False
class gpuSidepaneWidget(g.Box): # Required else you would need to specify the full module # name in mywidget.ui (__main__+MyWidget) __gtype_name__ = 'gpuSidepaneWidget' gpusidepanetextlabel = GtkTemplate.Child() gpusidepanelabelvalue = GtkTemplate.Child() gpusidepanedrawarea = GtkTemplate.Child() gpu_switcher_button = GtkTemplate.Child() # Alternative way to specify multiple widgets #label1, entry = GtkTemplate.Child.widgets(2) def __init__(self): super(g.Box, self).__init__() # This must occur *after* you initialize your base self.init_template() def givedata(self, secondself): self.gpuutilArray = secondself.gpuUtilArray @GtkTemplate.Callback def gpuSidepaneDrawArea_draw(self, dr, cr): cr.set_line_width(2) w = self.gpusidepanedrawarea.get_allocated_width() h = self.gpusidepanedrawarea.get_allocated_height() scalingfactor = h / 100.0 #creating outer rectangle cr.set_source_rgba(0, .454, .878, 1) cr.set_line_width(3) cr.rectangle(0, 0, w, h) cr.stroke() stepsize = w / 99.0 #print("in draw stepsize",stepsize) # for i in range(0,99): # # not effcient way to fill the bars (drawing) # cr.set_source_rgba(.588,.823,.98,0.25) #for changing the fill color # cr.move_to(i*stepsize,scalingfactor*(100-self.gpuutilArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(100-self.gpuutilArray[i+1])+2) # cr.line_to((i+1)*stepsize,h) # cr.line_to(i*stepsize,h) # cr.move_to(i*stepsize,scalingfactor*(100-self.gpuutilArray[i])+2) # cr.fill() # cr.stroke() # # for outer line # cr.set_line_width(1.5) # cr.set_source_rgba(.384,.749,1.0,1) #for changing the outer line color # cr.move_to(i*stepsize,scalingfactor*(100-self.gpuutilArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(100-self.gpuutilArray[i+1])+2) # cr.stroke() cr.set_line_width(1.5) cr.set_source_rgba(.384, .749, 1.0, 1) #for changing the outer line color cr.move_to(0, scalingfactor * (100 - self.gpuutilArray[0])) for i in range(0, 99): cr.line_to((i + 1) * stepsize, scalingfactor * (100 - self.gpuutilArray[i + 1])) cr.stroke_preserve() cr.set_source_rgba(.588, .823, .98, 0.25) #for changing the fill color cr.line_to(w, h) cr.line_to(0, h) cr.move_to(0, scalingfactor * (100 - self.gpuutilArray[0])) cr.fill() cr.stroke() return False
class diskTabWidget(g.ScrolledWindow): # Required else you would need to specify the full module # name in mywidget.ui (__main__+MyWidget) __gtype_name__ = 'diskTabWidget' disktextlabel = GtkTemplate.Child() diskinfolabel = GtkTemplate.Child() diskdrawarea1 = GtkTemplate.Child() diskdrawarea2 = GtkTemplate.Child() disktextlabel = GtkTemplate.Child() diskactivelabelvalue = GtkTemplate.Child() diskreadlabelvalue = GtkTemplate.Child() diskwritelabelvalue = GtkTemplate.Child() diskcurrenspeedlabelvalue = GtkTemplate.Child() diskUsagesTreeView = GtkTemplate.Child() # Alternative way to specify multiple widgets #label1, entry = GtkTemplate.Child.widgets(2) def __init__(self): super(g.ScrolledWindow, self).__init__() # This must occur *after* you initialize your base self.init_template() self.diskmxfactor = 1 #for the scaling of maximum value on the graph def givedata(self, secondself, index): self.diskactiveArray = secondself.diskActiveArray[index] self.diskreadArray = secondself.diskReadArray[index] self.diskwriteArray = secondself.diskWriteArray[index] @GtkTemplate.Callback def on_diskDrawArea2_draw(self, dr, cr): cr.set_line_width(2) w = self.diskdrawarea2.get_allocated_width() h = self.diskdrawarea2.get_allocated_height() speedstep = 100 maximumcurrentspeed = max(max(self.diskreadArray), max(self.diskwriteArray)) currentscalespeed = self.diskmxfactor * speedstep if (currentscalespeed < maximumcurrentspeed): while (currentscalespeed < maximumcurrentspeed): self.diskmxfactor += 1 currentscalespeed = self.diskmxfactor * speedstep else: while (currentscalespeed > maximumcurrentspeed + speedstep and self.diskmxfactor > 1): self.diskmxfactor -= 1 currentscalespeed = self.diskmxfactor * speedstep self.diskcurrenspeedlabelvalue.set_text(str(currentscalespeed) + 'MB') scalingfactor = h / currentscalespeed #creating outer rectangle cr.set_source_rgba(.109, .670, .0588, 1) cr.set_line_width(3) cr.rectangle(0, 0, w, h) cr.stroke() # creating grid lines verticalGap = int(h / 10) horzontalGap = int(w / 10) for i in range(1, 10): cr.set_source_rgba(.109, .670, .0588, 1) #for changing the outer line color cr.set_line_width(0.5) cr.move_to(0, i * verticalGap) cr.line_to(w, i * verticalGap) cr.move_to(i * horzontalGap, 0) cr.line_to(i * horzontalGap, h) cr.stroke() cr.stroke() stepsize = w / 99.0 #print("in draw stepsize",stepsize) # for i in range(0,99): # # not effcient way to fill the bars (drawing) # cr.set_source_rgba(.431,1,.04,0.25) #for changing the fill color # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.diskreadArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(currentscalespeed-self.diskreadArray[i+1])+2) # cr.line_to((i+1)*stepsize,h) # cr.line_to(i*stepsize,h) # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.diskreadArray[i])+2) # cr.fill() # cr.stroke() # # for outer line read speed # cr.set_line_width(1.5) # cr.set_source_rgba(.109,.670,.0588,1) #for changing the outer line color # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.diskreadArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(currentscalespeed-self.diskreadArray[i+1])+2) # cr.stroke() # #for write # cr.set_source_rgba(.207,.941,.682,0.3) #for changing the fill color # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.diskwriteArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(currentscalespeed-self.diskwriteArray[i+1])+2) # cr.line_to((i+1)*stepsize,h) # cr.line_to(i*stepsize,h) # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.diskwriteArray[i])+2) # cr.fill() # cr.stroke() # #cr.set_dash([1.0]) # cr.set_source_rgba(.207,.941,.682,1) #for changing the outer line color # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.diskwriteArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(currentscalespeed-self.diskwriteArray[i+1])+2) # cr.stroke() #efficient read speed drawing cr.set_source_rgba(.109, .670, .0588, 1) #for changing the outer line color cr.set_line_width(1.5) cr.move_to( 0, scalingfactor * (currentscalespeed - self.diskreadArray[0]) + 2) for i in range(0, 99): cr.line_to((i + 1) * stepsize, scalingfactor * (currentscalespeed - self.diskreadArray[i + 1]) + 2) cr.stroke_preserve() cr.set_source_rgba(.431, 1, .04, 0.25) #for changing the fill color cr.line_to(w, h) cr.line_to(0, h) cr.move_to( 0, scalingfactor * (currentscalespeed - self.diskreadArray[i]) + 2) cr.fill() cr.stroke() #efficient drawing for write cr.set_source_rgba(.207, .941, .682, 1) #for changing the outer line color cr.set_line_width(1.5) cr.move_to( 0, scalingfactor * (currentscalespeed - self.diskwriteArray[0]) + 2) for i in range(0, 99): cr.line_to((i + 1) * stepsize, scalingfactor * (currentscalespeed - self.diskwriteArray[i + 1]) + 2) cr.stroke_preserve() cr.set_source_rgba(.207, .941, .682, 0.3) #for changing the fill color cr.line_to(w, h) cr.line_to(0, h) cr.move_to( 0, scalingfactor * (currentscalespeed - self.diskwriteArray[0]) + 2) cr.fill() cr.stroke() return False @GtkTemplate.Callback def on_diskDrawArea1_draw(self, dr, cr): cr.set_line_width(2) w = self.diskdrawarea1.get_allocated_width() h = self.diskdrawarea1.get_allocated_height() scalingfactor = h / 100.0 #creating outer rectangle cr.set_source_rgba(.109, .670, .0588, 1) cr.set_line_width(3) cr.rectangle(0, 0, w, h) cr.stroke() # creating grid lines verticalGap = int(h / 10) horzontalGap = int(w / 10) for i in range(1, 10): cr.set_source_rgba(.109, .670, .0588, 1) #for changing the outer line color cr.set_line_width(0.5) cr.move_to(0, i * verticalGap) cr.line_to(w, i * verticalGap) cr.move_to(i * horzontalGap, 0) cr.line_to(i * horzontalGap, h) cr.stroke() cr.stroke() stepsize = w / 99.0 #print("in draw stepsize",stepsize) # for i in range(0,99): # # not effcient way to fill the bars (drawing) # cr.set_source_rgba(.431,1,.04,0.25) #for changing the fill color # cr.move_to(i*stepsize,scalingfactor*(100-self.diskactiveArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(100-self.diskactiveArray[i+1])+2) # cr.line_to((i+1)*stepsize,h) # cr.line_to(i*stepsize,h) # cr.move_to(i*stepsize,scalingfactor*(100-self.diskactiveArray[i])+2) # cr.fill() # cr.stroke() # # for outer line # cr.set_line_width(1.5) # cr.set_source_rgba(.109,.670,.0588,1) #for changing the outer line color # cr.move_to(i*stepsize,scalingfactor*(100-self.diskactiveArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(100-self.diskactiveArray[i+1])+2) # cr.stroke() cr.set_source_rgba(.109, .670, .0588, 1) #for changing the outer line color cr.set_line_width(1.5) cr.move_to(0, scalingfactor * (100 - self.diskactiveArray[0]) + 2) for i in range(0, 99): cr.line_to((i + 1) * stepsize, scalingfactor * (100 - self.diskactiveArray[i + 1]) + 2) cr.stroke_preserve() cr.set_source_rgba(.431, 1, .04, 0.25) #for changing the fill color cr.line_to(w, h) cr.line_to(0, h) cr.move_to(0, scalingfactor * (100 - self.diskactiveArray[0]) + 2) cr.fill() cr.stroke() return False
class networkWidget(g.ScrolledWindow): # Required else you would need to specify the full module # name in mywidget.ui (__main__+MyWidget) __gtype_name__ = 'networkWidget' nettextlabel= GtkTemplate.Child() netinfolabel= GtkTemplate.Child() netdrawarea=GtkTemplate.Child() netspeedscalelabelvalue= GtkTemplate.Child() netreclabelvalue= GtkTemplate.Child() nettotalreclabelvalue= GtkTemplate.Child() netsendlabelvalue= GtkTemplate.Child() nettotalsentlabelvalue= GtkTemplate.Child() net4addrlablevalue= GtkTemplate.Child() net6addrlabelvalue= GtkTemplate.Child() net_mac_addr_label_value= GtkTemplate.Child() # Alternative way to specify multiple widgets #label1, entry = GtkTemplate.Child.widgets(2) def __init__(self): super(g.ScrolledWindow, self).__init__() # This must occur *after* you initialize your base self.init_template() self.netmxScalingFactor=1 #for the scaling of maximum value on the graph def givedata(self,secondself,index): self.netRecSpeedArray=secondself.netReceiveArray[index] self.netSendSpeedArray=secondself.netSendArray[index] @GtkTemplate.Callback def on_netDrawArea_draw(self,dr,cr): cr.set_line_width(2) w=self.netdrawarea.get_allocated_width() h=self.netdrawarea.get_allocated_height() speedstep=250*1024 #500KB/s maximumcurrentspeed=max(max(self.netRecSpeedArray),max(self.netSendSpeedArray)) currentscalespeed=self.netmxScalingFactor*speedstep while(currentscalespeed<maximumcurrentspeed): self.netmxScalingFactor+=1 currentscalespeed=self.netmxScalingFactor*speedstep while(currentscalespeed>maximumcurrentspeed and self.netmxScalingFactor>1): self.netmxScalingFactor-=1 currentscalespeed=self.netmxScalingFactor*speedstep self.netspeedscalelabelvalue.set_text(byte_to_human(currentscalespeed)) scalingfactor=h/currentscalespeed #creating outer rectangle cr.set_source_rgba(.458,.141,.141,1) cr.set_line_width(3) cr.rectangle(0,0,w,h) cr.stroke() # creating grid lines verticalGap=int(h/10) horzontalGap=int(w/10) for i in range(1,10): cr.set_source_rgba(.58,.196,.196,1) #for changing the outer line color cr.set_line_width(0.5) cr.move_to(0,i*verticalGap) cr.line_to(w,i*verticalGap) cr.move_to(i*horzontalGap,0) cr.line_to(i*horzontalGap,h) cr.stroke() cr.stroke() stepsize=w/99.0 #print("in draw stepsize",stepsize) # for i in range(0,99): # # not effcient way to fill the bars (drawing) # cr.set_source_rgba(.709,.164,.164,.2) #for changing the fill color # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.netRecSpeedArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(currentscalespeed-self.netRecSpeedArray[i+1])+2) # cr.line_to((i+1)*stepsize,h) # cr.line_to(i*stepsize,h) # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.netRecSpeedArray[i])+2) # cr.fill() # cr.stroke() # # for outer line read speed # cr.set_line_width(1.5) # cr.set_source_rgba(.709,.164,.164,1) #for changing the outer line color # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.netRecSpeedArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(currentscalespeed-self.netRecSpeedArray[i+1])+2) # cr.stroke() # #for write # cr.set_source_rgba(1,.313,.313,.2) #for changing the fill color # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.netSendSpeedArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(currentscalespeed-self.netSendSpeedArray[i+1])+2) # cr.line_to((i+1)*stepsize,h) # cr.line_to(i*stepsize,h) # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.netSendSpeedArray[i])+2) # cr.fill() # cr.stroke() # # cr.set_dash([5.0]) # cr.set_source_rgba(1,.313,.313,1) #for changing the outer line color # cr.move_to(i*stepsize,scalingfactor*(currentscalespeed-self.netSendSpeedArray[i])+2) # cr.line_to((i+1)*stepsize,scalingfactor*(currentscalespeed-self.netSendSpeedArray[i+1])+2) # cr.stroke() #efficient receive speed drawing cr.set_source_rgba(.709,.164,.164,1) #for changing the outer line color cr.set_line_width(1.5) cr.move_to(0,scalingfactor*(currentscalespeed-self.netRecSpeedArray[0])+2) for i in range(0,99): cr.line_to((i+1)*stepsize,scalingfactor*(currentscalespeed-self.netRecSpeedArray[i+1])+2) cr.stroke_preserve() cr.set_source_rgba(.709,.164,.164,.2) #for changing the fill color cr.line_to(w,h) cr.line_to(0,h) cr.move_to(0,scalingfactor*(currentscalespeed-self.netRecSpeedArray[0])+2) cr.fill() cr.stroke() #efficient drawing for write cr.set_source_rgba(1,.313,.313,1) #for changing the outer line color cr.move_to(0,scalingfactor*(currentscalespeed-self.netSendSpeedArray[0])+2) cr.set_line_width(1.5) for i in range(0,99): cr.line_to((i+1)*stepsize,scalingfactor*(currentscalespeed-self.netSendSpeedArray[i+1])+2) cr.stroke_preserve() cr.set_source_rgba(1,.313,.313,.2) #for changing the fill color cr.line_to(w,h) cr.line_to(0,h) cr.move_to(0,scalingfactor*(currentscalespeed-self.netSendSpeedArray[0])+2) cr.fill() cr.stroke() return False
class diskSidepaneWidget(g.Box): # Required else you would need to specify the full module # name in mywidget.ui (__main__+MyWidget) __gtype_name__ = 'diskSidepaneWidget' disksidepanetextlabel = GtkTemplate.Child() disksidepanelabelvalue = GtkTemplate.Child() disksidepanedrawarea = GtkTemplate.Child() # Alternative way to specify multiple widgets #label1, entry = GtkTemplate.Child.widgets(2) def __init__(self): super(g.Box, self).__init__() # This must occur *after* you initialize your base self.init_template() def givedata(self, secondself, index): self.diskactiveArray = secondself.diskActiveArray[index] @GtkTemplate.Callback def on_diskSidepaneDrawArea_draw(self, dr, cr): cr.set_line_width(2) w = self.disksidepanedrawarea.get_allocated_width() h = self.disksidepanedrawarea.get_allocated_height() scalingfactor = h / 100.0 #creating outer rectangle cr.set_source_rgba(.109, .670, .0588, 1) cr.set_line_width(3) cr.rectangle(0, 0, w, h) cr.stroke() stepsize = w / 99.0 #print("in draw stepsize",stepsize) for i in range(0, 99): # not effcient way to fill the bars (drawing) cr.set_source_rgba(.431, 1, .04, 0.25) #for changing the fill color cr.move_to(i * stepsize, scalingfactor * (100 - self.diskactiveArray[i]) + 2) cr.line_to((i + 1) * stepsize, scalingfactor * (100 - self.diskactiveArray[i + 1]) + 2) cr.line_to((i + 1) * stepsize, h) cr.line_to(i * stepsize, h) cr.move_to(i * stepsize, scalingfactor * (100 - self.diskactiveArray[i]) + 2) cr.fill() cr.stroke() # for outer line cr.set_line_width(1.5) cr.set_source_rgba(.109, .670, .0588, 1) #for changing the outer line color cr.move_to(i * stepsize, scalingfactor * (100 - self.diskactiveArray[i]) + 2) cr.line_to((i + 1) * stepsize, scalingfactor * (100 - self.diskactiveArray[i + 1]) + 2) cr.stroke() return False
class gpuTabWidget(g.ScrolledWindow): # Required else you would need to specify the full module # name in mywidget.ui (__main__+MyWidget) __gtype_name__ = 'gpuTabWidget' gpuinfolabel = GtkTemplate.Child() gpuutildrawarea = GtkTemplate.Child() gpuvramdrawarea = GtkTemplate.Child() gpuencodingdrawarea = GtkTemplate.Child() gpudecodingdrawarea = GtkTemplate.Child() gpuvramlabelvalue = GtkTemplate.Child() gpuutilisationlabelvalue = GtkTemplate.Child() gpuvramusagelabelvalue = GtkTemplate.Child() gputemplabelvalue = GtkTemplate.Child() gpushaderspeedlabelvalue = GtkTemplate.Child() gpudriverlabelvalue = GtkTemplate.Child() gpucudalabelvalue = GtkTemplate.Child() gpumaxspeedlabelvalue = GtkTemplate.Child() gpuvramspeedlabelvalue = GtkTemplate.Child() gpuvrammaxspeedlabelvalue = GtkTemplate.Child() # Alternative way to specify multiple widgets #label1, entry = GtkTemplate.Child.widgets(2) def __init__(self): super(g.ScrolledWindow, self).__init__() # This must occur *after* you initialize your base self.init_template() # self.gpumxfactor=1 #for the scaling of maximum value on the graph def givedata(self, secondself): self.gpuutilArray = secondself.gpuUtilArray self.gpuvramArray = secondself.gpuVramArray self.gpuencodingArray = secondself.gpuEncodingArray self.gpudecodingArray = secondself.gpuDecodingArray self.gputotalvram = int(secondself.totalvram[:-3]) @GtkTemplate.Callback def gpuutildrawarea_draw(self, dr, cr): #print("idsaf") cr.set_line_width(2) w = self.gpuutildrawarea.get_allocated_width() h = self.gpuutildrawarea.get_allocated_height() scalingfactor = h / 100.0 #creating outer rectangle cr.set_source_rgba(0, .454, .878, 1) cr.set_line_width(3) cr.rectangle(0, 0, w, h) cr.stroke() # creating grid lines verticalGap = int(h / 10) horzontalGap = int(w / 10) for i in range(1, 10): cr.set_source_rgba(.384, .749, 1.0, 1) #for changing the outer line color cr.set_line_width(0.5) cr.move_to(0, i * verticalGap) cr.line_to(w, i * verticalGap) cr.move_to(i * horzontalGap, 0) cr.line_to(i * horzontalGap, h) cr.stroke() cr.stroke() stepsize = w / 99.0 #print("in draw stepsize",stepsize) # for i in range(0,99): # # not effcient way to fill the bars (drawing) # cr.set_source_rgba(.588,.823,.98,0.25) #for changing the fill color # cr.move_to(i*stepsize,scalingfactor*(100-self.gpuutilArray[i])) # cr.line_to((i+1)*stepsize,scalingfactor*(100-self.gpuutilArray[i+1])) # cr.line_to((i+1)*stepsize,h) # cr.line_to(i*stepsize,h) # cr.move_to(i*stepsize,scalingfactor*(100-self.gpuutilArray[i])) # cr.fill() # cr.stroke() # # for outer line # cr.set_line_width(1.5) # cr.set_source_rgba(.384,.749,1.0,1) #for changing the outer line color # cr.move_to(i*stepsize,scalingfactor*(100-self.gpuutilArray[i])) # cr.line_to((i+1)*stepsize,scalingfactor*(100-self.gpuutilArray[i+1])) # cr.stroke() cr.set_line_width(1.5) cr.set_source_rgba(.384, .749, 1.0, 1) #for changing the outer line color cr.move_to(0, scalingfactor * (100 - self.gpuutilArray[0])) for i in range(0, 99): cr.line_to((i + 1) * stepsize, scalingfactor * (100 - self.gpuutilArray[i + 1])) cr.stroke_preserve() cr.set_source_rgba(.588, .823, .98, 0.25) #for changing the fill color cr.line_to(w, h) cr.line_to(0, h) cr.move_to(0, scalingfactor * (100 - self.gpuutilArray[0])) cr.fill() cr.stroke() return False @GtkTemplate.Callback def gpuencodingdrawarea_draw(self, dr, cr): #print("idsaf") cr.set_line_width(2) w = self.gpuencodingdrawarea.get_allocated_width() h = self.gpuencodingdrawarea.get_allocated_height() scalingfactor = h / 100.0 #creating outer rectangle cr.set_source_rgba(0, .454, .878, 1) cr.set_line_width(3) cr.rectangle(0, 0, w, h) cr.stroke() # creating grid lines verticalGap = int(h / 10) horzontalGap = int(w / 10) for i in range(1, 10): cr.set_source_rgba(.384, .749, 1.0, 1) #for changing the outer line color cr.set_line_width(0.5) cr.move_to(0, i * verticalGap) cr.line_to(w, i * verticalGap) cr.move_to(i * horzontalGap, 0) cr.line_to(i * horzontalGap, h) cr.stroke() cr.stroke() stepsize = w / 99.0 #print("in draw stepsize",stepsize) # for i in range(0,99): # # not effcient way to fill the bars (drawing) # cr.set_source_rgba(.588,.823,.98,0.25) #for changing the fill color # cr.move_to(i*stepsize,scalingfactor*(100-self.gpuencodingArray[i])) # cr.line_to((i+1)*stepsize,scalingfactor*(100-self.gpuencodingArray[i+1])) # cr.line_to((i+1)*stepsize,h) # cr.line_to(i*stepsize,h) # cr.move_to(i*stepsize,scalingfactor*(100-self.gpuencodingArray[i])) # cr.fill() # cr.stroke() # # for outer line # cr.set_line_width(1.5) # cr.set_source_rgba(.384,.749,1.0,1) #for changing the outer line color # cr.move_to(i*stepsize,scalingfactor*(100-self.gpuencodingArray[i])) # cr.line_to((i+1)*stepsize,scalingfactor*(100-self.gpuencodingArray[i+1])) # cr.stroke() #efficient encoding drawing cr.set_line_width(1.5) cr.set_source_rgba(.384, .749, 1.0, 1) #for changing the outer line color cr.move_to(0, scalingfactor * (100 - self.gpuencodingArray[0])) for i in range(0, 99): cr.line_to((i + 1) * stepsize, scalingfactor * (100 - self.gpuencodingArray[i + 1])) cr.stroke_preserve() cr.set_source_rgba(.588, .823, .98, 0.25) #for changing the fill color cr.line_to(w, h) cr.line_to(0, h) cr.move_to(0, scalingfactor * (100 - self.gpuencodingArray[0])) cr.fill() cr.stroke() return False @GtkTemplate.Callback def gpudecodingdrawarea_draw(self, dr, cr): #print("idsaf") cr.set_line_width(2) w = self.gpudecodingdrawarea.get_allocated_width() h = self.gpudecodingdrawarea.get_allocated_height() scalingfactor = h / 100.0 #creating outer rectangle cr.set_source_rgba(0, .454, .878, 1) cr.set_line_width(3) cr.rectangle(0, 0, w, h) cr.stroke() # creating grid lines verticalGap = int(h / 10) horzontalGap = int(w / 10) for i in range(1, 10): cr.set_source_rgba(.384, .749, 1.0, 1) #for changing the outer line color cr.set_line_width(0.5) cr.move_to(0, i * verticalGap) cr.line_to(w, i * verticalGap) cr.move_to(i * horzontalGap, 0) cr.line_to(i * horzontalGap, h) cr.stroke() cr.stroke() stepsize = w / 99.0 #print("in draw stepsize",stepsize) # for i in range(0,99): # # not effcient way to fill the bars (drawing) # cr.set_source_rgba(.588,.823,.98,0.25) #for changing the fill color # cr.move_to(i*stepsize,scalingfactor*(100-self.gpudecodingArray[i])) # cr.line_to((i+1)*stepsize,scalingfactor*(100-self.gpudecodingArray[i+1])) # cr.line_to((i+1)*stepsize,h) # cr.line_to(i*stepsize,h) # cr.move_to(i*stepsize,scalingfactor*(100-self.gpudecodingArray[i])) # cr.fill() # cr.stroke() # # for outer line # cr.set_line_width(1.5) # cr.set_source_rgba(.384,.749,1.0,1) #for changing the outer line color # cr.move_to(i*stepsize,scalingfactor*(100-self.gpudecodingArray[i])) # cr.line_to((i+1)*stepsize,scalingfactor*(100-self.gpudecodingArray[i+1])) # cr.stroke() cr.set_line_width(1.5) cr.set_source_rgba(.384, .749, 1.0, 1) #for changing the outer line color cr.move_to(0, scalingfactor * (100 - self.gpudecodingArray[0])) for i in range(0, 99): cr.line_to((i + 1) * stepsize, scalingfactor * (100 - self.gpudecodingArray[i + 1])) cr.stroke_preserve() cr.set_source_rgba(.588, .823, .98, 0.25) #for changing the fill color cr.line_to(w, h) cr.line_to(0, h) cr.move_to(0, scalingfactor * (100 - self.gpudecodingArray[0])) cr.fill() cr.stroke() return False @GtkTemplate.Callback def gpuvramdrawarea_draw(self, dr, cr): # print('heloow gpu') cr.set_line_width(2) w = self.gpuvramdrawarea.get_allocated_width() h = self.gpuvramdrawarea.get_allocated_height() scalingfactor = h / self.gputotalvram # print(self.gputotalvram) #creating outer rectangle cr.set_source_rgba(0, .454, .878, 1) ##need tochange the color cr.set_line_width(3) cr.rectangle(0, 0, w, h) cr.stroke() # creating grid lines verticalGap = int(h / 10) horzontalGap = int(w / 10) for i in range(1, 10): cr.set_source_rgba(.384, .749, 1.0, 1) #for changing the outer line color cr.set_line_width(0.5) cr.move_to(0, i * verticalGap) cr.line_to(w, i * verticalGap) cr.move_to(i * horzontalGap, 0) cr.line_to(i * horzontalGap, h) cr.stroke() stepsize = w / 99.0 #print("in draw stepsize",stepsize) # for i in range(0,99): # # not effcient way to fill the bars (drawing) # cr.set_source_rgba(.588,.823,.98,0.25) #for changing the fill color # cr.move_to(i*stepsize,scalingfactor*(self.gputotalvram-self.gpuvramArray[i])) # cr.line_to((i+1)*stepsize,scalingfactor*(self.gputotalvram-self.gpuvramArray[i+1])) # cr.line_to((i+1)*stepsize,h) # cr.line_to(i*stepsize,h) # cr.move_to(i*stepsize,scalingfactor*(self.gputotalvram-self.gpuvramArray[i])) # cr.fill() # cr.stroke() # # for outer line # cr.set_line_width(1.5) # cr.set_source_rgba(.384,.749,1.0,1) #for changing the outer line color # cr.move_to(i*stepsize,scalingfactor*(self.gputotalvram-self.gpuvramArray[i])) # cr.line_to((i+1)*stepsize,scalingfactor*(self.gputotalvram-self.gpuvramArray[i+1])) # cr.stroke() cr.set_line_width(1.5) cr.set_source_rgba(.384, .749, 1.0, 1) #for changing the outer line color cr.move_to(0, scalingfactor * (self.gputotalvram - self.gpuvramArray[0])) for i in range(0, 99): cr.line_to( (i + 1) * stepsize, scalingfactor * (self.gputotalvram - self.gpuvramArray[i + 1])) cr.stroke_preserve() cr.set_source_rgba(.588, .823, .98, 0.25) #for changing the fill color cr.line_to(w, h) cr.line_to(0, h) cr.move_to(0, scalingfactor * (self.gputotalvram - self.gpuvramArray[0])) cr.fill() cr.stroke() return False