Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
vyuka:cviceni:y36sps:semestralky:mandio1 [2009/05/27 17:16] – mandio1 | vyuka:cviceni:y36sps:semestralky:mandio1 [2009/05/27 17:22] (current) – mandio1 | ||
---|---|---|---|
Line 18: | Line 18: | ||
prace je implementovana v jednom davkovem souboru pri interpreter python. Konfirgurace je v prvnich radcich kodu v konstantach FROM, VERSION, apod. | prace je implementovana v jednom davkovem souboru pri interpreter python. Konfirgurace je v prvnich radcich kodu v konstantach FROM, VERSION, apod. | ||
- | zdrojovy kod aplikace je zde: | + | zdrojovy kod aplikace je zde: {{: |
- | <source lang=" | + | ===== Nasazeni ===== |
- | #!/usr/bin/python | + | Pro ilustrace moji prace je hlavnim bodem demonstrace jak s praci pracovat coz ukazuje nasladujici video: |
+ | //video se mi neporadilo vlozit na wiki, takze na pozadani zaslu mandio1@fel.cvut.cz// | ||
- | import os, wx, re, threading, time | ||
- | import wx.lib.plot as plot | ||
- | |||
- | ID_ABOUT = 101 | ||
- | ID_EXIT = 110 | ||
- | ID_REFRESH = 112 | ||
- | TIMER_ID = 100 | ||
- | |||
- | class SnmpGuiClient(wx.Frame): | ||
- | |||
- | FROM = ' | ||
- | |||
- | COMMUNITY = ' | ||
- | |||
- | VERSION = ' | ||
- | |||
- | DATA = [ | ||
- | (' | ||
- | (' | ||
- | (' | ||
- | ] | ||
- | |||
- | REFRESH_TIME = 400 | ||
- | |||
- | DATA_QUEUE_LENGTH = 100 | ||
- | |||
- | timer = None | ||
- | |||
- | plotter = None | ||
- | |||
- | dataQueue = [] | ||
- | |||
- | def __init__(self, | ||
- | self.frame = wx.Frame.__init__(self, | ||
- | |||
- | # | ||
- | plotPanel = wx.Panel(self) | ||
- | plotPanel.SetBackgroundColour(" | ||
- | vbox = wx.BoxSizer(wx.VERTICAL) | ||
- | plotPanel.SetSizer(vbox) | ||
- | |||
- | self.plotter = plot.PlotCanvas(plotPanel) | ||
- | vbox.Add(self.plotter, | ||
- | self.plotter.SetSize(size=(300, | ||
- | self.plotter.SetShowScrollbars(True) | ||
- | self.plotter.SetEnableZoom(False) | ||
- | self.plotter.SetEnableGrid(False) | ||
- | self.plotter.SetXSpec(type=' | ||
- | self.plotter.SetEnableLegend(True) | ||
- | |||
- | # Creting status bar | ||
- | self.CreateStatusBar() # A StatusBar in the bottom of the window | ||
- | |||
- | # Setting up the menu. | ||
- | filemenu= wx.Menu() | ||
- | filemenu.Append(ID_ABOUT, | ||
- | filemenu.AppendSeparator() | ||
- | filemenu.Append(ID_EXIT," | ||
- | |||
- | actionmenu = wx.Menu() | ||
- | actionmenu.Append(ID_REFRESH, | ||
- | |||
- | # Creating the menubars. | ||
- | menuBar = wx.MenuBar() | ||
- | menuBar.Append(filemenu,"& | ||
- | menuBar.Append(actionmenu,"& | ||
- | self.SetMenuBar(menuBar) | ||
- | |||
- | # Start timer | ||
- | self.timer = wx.Timer(self, | ||
- | self.timer.Start(self.REFRESH_TIME) | ||
- | |||
- | wx.EVT_MENU(self, | ||
- | wx.EVT_MENU(self, | ||
- | wx.EVT_MENU(self, | ||
- | wx.EVT_TIMER(self, | ||
- | |||
- | self.initQueue() | ||
- | self.refresh() | ||
- | self.Centre() | ||
- | self.Show(True) | ||
- | |||
- | def OnAbout(self, | ||
- | d= wx.MessageDialog( self, "A sample editor \n in wxPython"," | ||
- | d.ShowModal() | ||
- | d.Destroy() | ||
- | |||
- | def OnExit(self, | ||
- | self.Close(True) | ||
- | |||
- | def OnRefresh(self, | ||
- | self.refresh() | ||
- | |||
- | def OnTimer(self, | ||
- | self.refresh() | ||
- | self.timer.Start(self.REFRESH_TIME) | ||
- | |||
- | def initQueue(self): | ||
- | for i in range(0, | ||
- | self.dataQueue.insert(i, | ||
- | for j in range(0, | ||
- | self.dataQueue[i].insert(j, | ||
- | |||
- | def refresh(self): | ||
- | for i in range(0, | ||
- | self.dataQueue[i].pop(0) | ||
- | self.dataQueue[i].append(self.snmpGetInt(self.DATA[i][0])) | ||
- | self.redrawPlot() | ||
- | |||
- | def snmpGetInt(self, | ||
- | intRe = re.compile(" | ||
- | cmd = " | ||
- | pipe = os.popen(cmd) | ||
- | return int(intRe.match(pipe.read()).group(1)) | ||
- | |||
- | |||
- | def redrawPlot(self): | ||
- | lines = [] | ||
- | for i in range(0, | ||
- | data = [] | ||
- | for j in range(0, | ||
- | data.append((j, | ||
- | lines.insert(i, | ||
- | |||
- | gc = plot.PlotGraphics(lines, | ||
- | self.plotter.Draw(gc, | ||
- | |||
- | |||
- | |||
- | #Run main loop | ||
- | if __name__ == ' | ||
- | |||
- | app = wx.PySimpleApp() | ||
- | frame = SnmpGuiClient(None," | ||
- | app.MainLoop() | ||
- | |||
- | </ | ||
===== Presentace ===== | ===== Presentace ===== |