pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

pastebin private pastebin - collaborative debugging tool What's a private pastebin?

Posted by fruitbat on Sat 11th Oct 17:20
download | new post

  1. #!/usr/bin/python
  2. # 127Krellm
  3. # 127001.org
  4. #
  5. # Somewhat dodgy replacement for the cpu portion of GKrellm
  6. # Will shortly be client/server, i'm sure.
  7. #
  8. # <LMB> + DRAG to move the window
  9. # <RMB> to quit
  10. #
  11.  
  12. import Pmw,Tkinter,statgrab
  13.  
  14. fgcolor = "green"
  15.  
  16. def go():
  17.         #CPU
  18.         cpu.delete(0)
  19.         cpuinfo = statgrab.sg_get_cpu_percents()
  20. #       cputotal = cpuinfo["kernel"] + cpuinfo["user"]
  21.         cputotal = 100-cpuinfo["idle"]
  22.         cpu.append(cputotal)
  23.         scpu = "CPU: %d %%" % cputotal
  24.         g.marker_configure("CPUperc", text=scpu)
  25.        
  26.         #Net
  27.         # Maths and junk required...
  28.         # average of 2 calls?
  29.         nettx.delete(0)
  30.         netrx.delete(0)
  31.         netstat = statgrab.sg_get_network_io_stats_diff()
  32.         netrxv = netstat[1]["rx"]
  33.         nettxv = netstat[1]["tx"]
  34.         nettx.append(0-nettxv)
  35.         netrx.append(netrxv)
  36.         blah2 = "Net: %d K/s" % ((netrxv + nettxv) / 1024)
  37.         h.marker_configure("NETspeed", text=blah2)
  38.         txmax=nettx.min()
  39.         rxmax=netrx.max()
  40.         theMax=(txmax > rxmax and txmax or rxmax)
  41.         h.yaxis_configure(min=-theMax, max=theMax)
  42.         master.update_idletasks()
  43.         master.after(1000,go)
  44.  
  45. def stopDragging():
  46.         global drag_x, drag_y
  47.         drag_x = None
  48.         drag_y = None
  49.  
  50. def dragged(event):
  51.         global drag_x,drag_y
  52.         if (drag_x != None and drag_y != None):
  53.                 window_x=master.winfo_rootx()+event.x_root-drag_x
  54.                 window_y=master.winfo_rooty()+event.y_root-drag_y
  55.                 master.geometry("+" + str(window_x) + "+" + str(window_y))
  56.                 #print event.x
  57.                 #print "-----"
  58.                 #print(d        ir(master))
  59.                 #print master.winfo_rootx()
  60.         drag_x = event.x_root
  61.         drag_y = event.y_root
  62.         master.update_idletasks()
  63.  
  64.  
  65. def buttonPressed(event):
  66.         master.lift()
  67.         if (event.num == 3):
  68.                 master.quit()
  69.  
  70. def buttonReleased(event):
  71.         if (event.num == 1):
  72.                 stopDragging()
  73.  
  74. def ahooo(event):
  75.         print event.x,event.y,event.x_root,event.y_root 
  76.  
  77.  
  78. #This is a difference; the first call returns total counters since boot, so throw that away
  79. statgrab.sg_get_network_io_stats_diff()
  80.  
  81.  
  82. master = Tkinter.Tk()
  83. master.geometry("68x200")
  84.  
  85. #Temp fix for multi-monitor problem
  86. #If someone's left hand monitor does not extend at least as high as all others, 0x0 will be above the screen
  87. #TODO: Develop proper solution
  88. master.geometry("+300+300")
  89.  
  90. master.title("127Krellm")
  91. master.overrideredirect(1)
  92. master.configure(bg="cyan",padx=0,pady=0)
  93. drag_x = None
  94. drag_y = None
  95.  
  96.  
  97. cpu = Pmw.Blt.Vector()
  98. nettx = Pmw.Blt.Vector()
  99. netrx = Pmw.Blt.Vector()
  100.  
  101. time = []
  102. for x in range(60):
  103.         time.append(x)
  104. time = tuple(time)
  105.  
  106. for y in range(60):
  107.         cpu.append(0)
  108.         nettx.append(0)
  109.         netrx.append(0)
  110.  
  111.  
  112. #CPU graph
  113. g = Pmw.Blt.Graph(master)
  114. g.pack(expand=1, fill="both",padx=0,pady=0,ipadx=0,ipady=0)
  115.  
  116. g.xaxis_configure(min=0, max=60, hide=1)
  117. g.yaxis_configure(min=0, max=100, hide=1)
  118. g.legend_configure(hide=1)
  119. g.marker_create("text",name="CPUperc",coords=("-Inf","Inf"),anchor="nw",under=1,foreground="white")
  120. g.bar_create("CPU",barwidth=0.1,relief="flat",xdata=time,ydata=cpu,foreground=fgcolor)
  121. #print g.element_show()
  122. g.configure(width=1,height=1,plotbackground="black",plotborderwidth=0,relief="flat",plotpadx=0,plotpady=0,topmargin=1,bottommargin=1,leftmargin=1,rightmargin=1,background="red")
  123.  
  124. #Net graph
  125. h = Pmw.Blt.Graph(master)
  126. h.pack(expand=1, fill="both",padx=0,pady=0,ipadx=10,ipady=0)
  127.  
  128. h.xaxis_configure(hide=1, min=0, max=60)
  129. h.yaxis_configure(hide=1)
  130. h.legend_configure(hide=1)
  131. h.marker_create("text",name="NETspeed",coords=("-Inf","Inf"),anchor="nw",under=1,text="Net!",foreground="white")
  132. h.bar_create("NETtx",barwidth=0.1,relief="flat",xdata=time,ydata=nettx,foreground=fgcolor)
  133. h.bar_create("NETrx",barwidth=0.1,relief="flat",xdata=time,ydata=netrx,foreground=fgcolor)
  134. h.configure(width=1,height=1,plotbackground="black",plotborderwidth=0,relief="flat",plotpadx=0,plotpady=0,leftmargin=1,topmargin=1,bottommargin=1,rightmargin=1,background="red")
  135.  
  136. master.bind("<ButtonPress>", buttonPressed)
  137. master.bind("<ButtonRelease>", buttonReleased)
  138. master.bind("<B1-Motion>", dragged)
  139. master.after(1,go)
  140.  
  141. master.mainloop()  # and wait...

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings