⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 np_plot.py

📁 该软件根据网络数据生成NetFlow记录。NetFlow可用于网络规划、负载均衡、安全监控等
💻 PY
📖 第 1 页 / 共 5 页
字号:
#! /usr/bin/env python################################################################################                                                                             ##   Copyright 2005 University of Cambridge Computer Laboratory.               ##                                                                             ##   This file is part of Nprobe.                                              ##                                                                             ##   Nprobe is free software; you can redistribute it and/or modify            ##   it under the terms of the GNU General Public License as published by      ##   the Free Software Foundation; either version 2 of the License, or         ##   (at your option) any later version.                                       ##                                                                             ##   Nprobe is distributed in the hope that it will be useful,                 ##   but WITHOUT ANY WARRANTY; without even the implied warranty of            ##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             ##   GNU General Public License for more details.                              ##                                                                             ##   You should have received a copy of the GNU General Public License         ##   along with Nprobe; if not, write to the Free Software                     ##   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA ##                                                                             ################################################################################################################################################################ ## ## Data plotting tool - callable from other tools, or as free-standing plotter## ################################################################################ ############################################################################ import stringimport osfrom sys import argvimport getoptfrom math import modffrom sys import exitfrom math import *from math import hypotfrom Tkinter import *from tkSimpleDialog import askstringfrom np_widgets import BarButton, TwoEntryDialogue, PCan, YSCROLLfrom minmax import *from np_drawutil import *#import np_tcp import np_printplotimport copyimport tkColorChooserfrom np_bitmaps import ccrossfrom np_data import DataSet, EmptyDataSetError, WrongDataTypeError, DataError, Plot_Decoration, DATA_TS, DATA_PDF, DATA_CDF, DATA_HIST, DATA_SM, DATA_RANGES, DataReader, AddFun, Dedit, EDIT, DELETE		############################################################################## ############################################################################### Dimensions etc.#B_WI = 750B_HT = 500## B_WI = 1500## B_HT = 1000B_TB_HT = 25#RootGeom = '%dx%d+%d+%d' % (B_WI, B_HT, B_XPOS, B_YPOS)#RootGeom = '%dx%d' % (B_WI, B_HT)C_LHMARGIN = 80C_RHMARGIN = 35C_TOPMARGIN = 50C_BOTMARGIN = 75C_TITLEMARGIN = 25MIN_XTIC_WI = 100MIN_YTIC_HI = 50TITLEFONT = ("helvetica", 10)LABELFONT = ("helvetica", 8)	    ############################################################################## ############################################################################### Data types and plotting modes#STYLE_POINTS = 0x1STYLE_LINES = 0x2STYLE_BARS = 0x4STYLE_EBARS = 0x8STYLE_EBARS_SD = 0x10 | STYLE_EBARSSTYLE_EBARS_SE = 0x20 | STYLE_EBARSMODE_TS = DATA_TSMODE_TS_SMOOTH = DATA_TS | DATA_SMMODE_PDF = DATA_PDFMODE_PDF_SMOOTH = DATA_PDF | DATA_SMMODE_CDF = DATA_CDFMODE_CDF_SMOOTH = DATA_CDF | DATA_SMMODE_HIST = DATA_HISTMODE_HIST_SMOOTH = DATA_HIST | DATA_SMMODE_RANGES = DATA_RANGESXLINE = 1YLINE = 2	    ############################################################################## #############################################################################class Plot_canv:    def __init__(self, plot, sets, mode=MODE_TS, 		 style=STYLE_POINTS, fgcol='white', bgcol='black', 		 scaledata=None, plotlinewidth=1, axislinewidth=1,                 zero_origin=1):	self.plot = plot	self.scaledata = scaledata	self.sets = sets        if sets:            self.dtype = sets[0].type	self.fgcol = fgcol	self.bgcol = bgcol        self.zero_origin = zero_origin	c = self.canv = Canvas(plot.frame)	c.config(bg='black', cursor=(ccross, 'orange'))	#c.config(bg='black', cursor=('@/usr/groups/nprobe/python/Python-2.2/Install/Misc/ccross.bmp', 'orange'))	#c.config(bg='black', cursor=('@/home/jch1003/work/python/ccross.bmp', 'orange'))	#c.config(bg='black', cursor=('@./ccross.bmp', 'orange'))	self.xorg = C_LHMARGIN	self.xwi = self.plot.wi - C_LHMARGIN - C_RHMARGIN	self.yorg = self.plot.ht - B_TB_HT - C_BOTMARGIN	self.yht = self.plot.ht - B_TB_HT -C_BOTMARGIN - C_TOPMARGIN	self.bounds = (self.xorg, self.xorg+self.xwi, self.yorg-self.yht, 		       self.yorg)	self.xlab = plot.xlab	self.ylab = plot.ylab	self.min_xtic_wi = MIN_XTIC_WI	self.min_ytic_ht = MIN_YTIC_HI	self.xfloats = self.yfloats = 0	self.style = style	self.mode = mode	self.rboxing = 0	self.rbox = None        c.sbox = None        c.sboxing = 0        c.slides = []        self.plotlinewidth = plotlinewidth        self.axislinewidth = axislinewidth	Widget.bind(c, "<1>", self.mouse_1_down)	Widget.bind(c, "<B1-Motion>", self.mouse_1_drag)	Widget.bind(c, "<ButtonRelease-1>", self.mouse_1_up)	Widget.bind(c, "<Double-Button-1>", self.plot.mouse_3_down)	Widget.bind(c, "<2>", self.mouse_2_down)	Widget.bind(c, "<B2-Motion>", self.mouse_2_drag)	Widget.bind(c, "<ButtonRelease-2>", self.mouse_2_up)	Widget.bind(c, "<Shift-Button-2>", self.mouse_2_shift_down)	Widget.bind(c, "<Shift-B2-Motion>", self.mouse_2_shift_drag)	Widget.bind(c, "<Shift-ButtonRelease-2>", self.mouse_2_up)	Widget.bind(c, "<3>", self.mouse_3_down)	Widget.bind(c, "<B3-Motion>", self.mouse_3_drag)	Widget.bind(c, "<ButtonRelease-3>", self.mouse_3_up)              	Widget.bind(c, "<Shift-Button-3>", self.mouse_3_shift_down)	Widget.bind(c, "<Shift-B3-Motion>", self.mouse_3_shift_drag)	Widget.bind(c, "<Shift-ButtonRelease-3>", self.mouse_3_up)	Widget.bind(c, "<Control-Button-3>", self.mouse_3_control_down)	Widget.bind(c, "<Control-B3-Motion>", self.mouse_3_control_drag)	Widget.bind(c, "<Control-ButtonRelease-3>", self.mouse_3_control_up)	self.setup()##############################################################################    def mouse_1_down(self, event):	# set origin of selection box	canv = event.widget	x = canv.canvasx(event.x)	y = canv.canvasy(event.y)	x = MAX(x, self.bounds[0])	x = MIN(x, self.bounds[1])	y = MIN(y, self.bounds[3])	y = MAX(y, self.bounds[2])	#print 'B1 %d, %d' % (x, y)	#self.rboxing = 1	canv.startx=x	canv.starty=y	canv.rbox = None##############################################################################    def mouse_1_drag(self, event):	# draw selection box	canv = event.widget	x = canv.canvasx(event.x)	y = canv.canvasy(event.y)	x = MAX(x, self.bounds[0])	x = MIN(x, self.bounds[1])	y = MIN(y, self.bounds[3])	y = MAX(y, self.bounds[2])    	#if self.rboxing and canv.startx != x  and canv.starty != y :	if canv.startx != x  and canv.starty != y :	    self.rboxing = 1 	    canv.delete(canv.rbox)	    canv.rbox = canv.create_rectangle(		canv.startx, canv.starty, x, y, outline='red', stipple='gray75')	    canv.lastx = x	    canv.lasty = y			    ##############################################################################		    def mouse_1_up(self, event):	canv = event.widget	if canv.rbox != None:	    canv.delete(canv.rbox)	    canv.rbox = None	if self.rboxing:	    self.rboxing = 0	else:	    return	x = canv.canvasx(event.x)	y = canv.canvasy(event.y)	x = MAX(x, self.bounds[0])	x = MIN(x, self.bounds[1])	y = MIN(y, self.bounds[3])	y = MAX(y, self.bounds[2])    	# don't zoom for small movement on dbl click	if abs(x-canv.startx) < 5 or abs(y-canv.starty) < 5:	    return	scaledata = self.find_indices(event, canv.startx, canv.starty, 1)	plot = self.plot	#scaledata = (xmaxval, xminval, ymaxval, yminval, xscalef, yscalef, xrangeval, yrangeval, self.xfloats, self.yfloats)        #print 'last top %d' % (plot.is_top[-1])	plot.is_top.append(self.plot.is_top[-1])	c = Plot_canv(plot, self.sets, style=self.style, mode=self.mode,                      scaledata=scaledata)	plot.canvasses[plot.canv_curr].canv.pack_forget()	plot.canvasses.append(c)	plot.canv_curr = plot.canv_curr + 1	c.canv.pack(side=LEFT, fill=BOTH, expand = 1)	#self.plot.is_top.append(self.plot.is_top[-1])##############################################################################    def mouse_2_down(self, event):	# set origin of selection box	canv = event.widget	x = canv.canvasx(event.x)	y = canv.canvasy(event.y)	#print 'B1 %d, %d' % (x, y)	#self.rboxing = 1	canv.start1x=x	canv.start1y=y	canv.sbox = None##############################################################################    def mouse_2_shift_down(self, event):	canv = event.widget	xpos = canv.canvasx(event.x)	ypos = canv.canvasy(event.y)	xpos = MAX(xpos, self.bounds[0])	xpos = MIN(xpos, self.bounds[1])	ypos = MIN(ypos, self.bounds[3])	ypos = MAX(ypos, self.bounds[2])        gt = canv.gettags        co = canv.coords        nr = canv.find_enclosed(xpos-10, ypos-10, xpos+10, ypos+10)        nrc = [n for n in nr if 'ctr' in gt(n)]        if nrc:            x = xpos            y = ypos            clo = nrc[0]            coords = co(clo)            dst = hypot(coords[0]-xpos, coords[1]-ypos)            for n in nrc[1:]:                coords = co(n)                ndst = hypot(coords[0]-xpos, coords[1]-ypos)                if ndst < dst:                    dst = ndst                    clo = n            coords = canv.coords(clo)            xpos, ypos = coords[0], coords[1]            canv.slidecol = canv.itemcget(clo, 'fill')            t = gt(clo)            canv.slides = canv.find_withtag(t[0])            canv.start1x = canv.lastx = x            canv.start1y = canv.lasty = y            self.postxt = canv.create_text(x, y, text='')##############################################################################    def mouse_2_shift_drag(self, event):        	canv = event.widget        if not canv.slides:            return        co = canv.coords        mv = canv.move	x = canv.canvasx(event.x)	y = canv.canvasy(event.y)        bb = canv.bbox(self.postxt)        xwi = bb[2] - bb[0]        canv.delete(self.postxt)        TEXT = canv.create_text        dx = x - canv.lastx        dy = y - canv.lasty        for i in canv.slides:            mv(i, dx, dy)        xv = ((x-canv.start1x)/self.xscalef)        yv = ((canv.start1y - y)/self.yscalef)        off = 10        if x + xwi - off < self.bounds[1]:            anch = W        else:            off = -off            anch = E        self.postxt = TEXT(x+off, y, text='%+f %+f' % (xv, yv),                           anchor=anch, fill=canv.slidecol,                           font=("helvetica", 10, "bold") )                    canv.lastx=x        canv.lasty=y##############################################################################    def mouse_2_drag(self, event):	# draw selection box	canv = event.widget	x = canv.canvasx(event.x)	y = canv.canvasy(event.y)    	#if self.rboxing and canv.startx != x  and canv.starty != y :	if canv.start1x != x  and canv.start1y != y :	    canv.sboxing = 1 	    canv.delete(canv.sbox)	    canv.sbox = canv.create_rectangle(		canv.start1x, canv.start1y, x, y, outline='blue', stipple='gray75')	    canv.lastx = x	    canv.lasty = y			    ##############################################################################		    def mouse_2_up(self, event):	canv = event.widget	if canv.sbox != None:	    canv.delete(canv.sbox)	    canv.sbox = None	x = canv.canvasx(event.x)	y = canv.canvasy(event.y)        if canv.slides:            mv = canv.move            dx = canv.start1x -  canv.lastx            dy = canv.start1y - canv.lasty             for i in canv.slides:                mv(i, dx, dy)            canv.slides = []	    canv.delete(self.postxt)            	if canv.sboxing:	    canv.sboxing = 0	else:	    return	if abs(x-canv.start1x) < 5 or abs(y-canv.start1y) < 5:	    return        	tdict = {}	scaledata = self.find_indices(event, canv.start1x, canv.start1y, 0)        xmin = scaledata[1]        xmax = scaledata[0]	ymin = scaledata[3]	ymax = scaledata[2]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -