00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 import wx
00018 import images
00019 from threading import Event, RLock
00020
00021 from matplotlib.figure import Figure
00022
00023 import time
00024 import copy
00025
00026 import webbrowser
00027
00028 from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
00029
00030 from objects.logic.common.exception import exception
00031 from objects.logic.common.globalStrings import globalStrings
00032 from objects.logic.common.logger import logger
00033 from networkSettings import networkSettings
00034 from figureAxesWrapper import figureAxesWrapper
00035 from objects.gui.displayer.applicationEntityDisplayer import applicationEntityDisplayer
00036 from objects.logic.entity.networkEntity import networkEntity
00037
00038 from objects.gui.displaySettings import displaySettings
00039 from objects.gui.filterSettings import filterSettings
00040 from objects.gui.appOptions import appOptions
00041
00042 from objects.gui.peerGridDisplay import peerGridDisplay
00043 from objects.gui.mainFrameToolbar import mainFrameToolbar
00044 from objects.gui.mainFrameMenuBar import mainFrameMenuBar
00045 from objects.gui.mainFrameToolWindow import mainFrameToolWindow
00046 from objects.gui.pictureSaverDialog import pictureSaverDialog
00047 from objects.gui.traceDisplayDialog import traceDisplayDialog
00048 from objects.gui.aboutDialog import aboutDialog
00049 from objects.gui.mainFrameMap import mainFrameMap
00050
00051 from objects.gui.mainFramePopupMenu import mainFramePopupMenu
00052
00053
00054 from objects.logic.entity.filter.baseFilter import baseFilter
00055 from objects.logic.entity.filter.customFilter import customFilter
00056 from objects.gui.animatedLoaderIcon import animatedLoaderIcon
00057 from objects.gui.startupSplashScreen import startupSplashScreen
00058
00059 from objects.gui.threads.mouseHoverThread import mouseHoverThread, EVT_DISPLAY_TOOLINFOWIN
00060 from objects.gui.threads.redrawThread import redrawThread
00061
00062 from objects.geoip.geoIPUtils import geoIPUtils
00063
00064
00065
00066 VIEW_STATE_ZOOM = "VIEW_STATE_ZOOM"
00067 VIEW_STATE_PAN = "VIEW_STATE_PAN"
00068 VIEW_STATE_UNDEFINED = "VIEW_STATE_UNDEFINED"
00069 VIEW_STATE_SETHOMELOC = "VIEW_STATE_SETHOMELOC"
00070
00071
00072
00073
00074
00075
00076
00077 class NoRepaintCanvas(FigureCanvasWxAgg):
00078 def __init__(self, *args, **kwargs):
00079 FigureCanvasWxAgg.__init__(self, *args, **kwargs)
00080 self._drawn = 0
00081
00082 def _onPaint(self, evt):
00083
00084
00085
00086 if not self._isRealized:
00087 self.realize()
00088 if self._drawn < 2:
00089 self.draw(repaint = False)
00090 self._drawn += 1
00091 self.gui_repaint(drawDC=wx.PaintDC(self))
00092
00093
00094
00095
00096
00097 class mainFrame(wx.Frame):
00098
00099 def __init__(self, parent, id, title, eyeSpyApp, displayConfig, appConfig, color = None,\
00100 dpi = None, style = wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs):
00101
00102 startupSplah = startupSplashScreen(None)
00103
00104 self.mainApp = eyeSpyApp
00105 self.selectedNetworkDevice = None
00106
00107 self.dispConf = displayConfig
00108 self.optConfig = appConfig
00109
00110 wx.Frame.__init__(self, parent, id, title)
00111
00112
00113 appIcon = wx.Icon(globalStrings.eyespy_icon, wx.BITMAP_TYPE_ICO)
00114 self.SetIcon(appIcon)
00115
00116
00117 try:
00118
00119 self.toolbarContainer = mainFrameToolbar(self)
00120 self.createStatusBar()
00121 self.createPanel()
00122 except exception, e:
00123 startupSplah.Close()
00124 self.die(e.reason)
00125 return
00126
00127
00128 self.rubber_start = wx.Point(0,0)
00129 self.rubber_end = wx.Point(0,0)
00130
00131 self.lbuttonDown = False
00132
00133 self.initializeThreads()
00134
00135
00136 self.displayMode = VIEW_STATE_ZOOM
00137 self.displayer = applicationEntityDisplayer(self.dispConf)
00138
00139 self.cursor = wx.StockCursor(wx.CURSOR_ARROW)
00140
00141 self.currentZoomLevel = None
00142
00143
00144 saveDeviceSelection = appConfig.network_getSaveDeviceSelection()
00145
00146 if saveDeviceSelection == True:
00147 self.selectedNetworkDevice = appConfig.network_getSelectedDevice()
00148
00149
00150
00151 self.currentMousePosition = None
00152 self.lastMouseMoveTime = None
00153
00154 self.numPeers = 0
00155 self.numDisplayedPeers = 0
00156
00157
00158 self.tipWin = None
00159 self.canDisplayTipWin = True
00160
00161
00162 self.PeerFilter = customFilter()
00163
00164
00165 self.isWindowMinimined = False
00166
00167
00168 self.figure = Figure(None, dpi)
00169 self.canavas = NoRepaintCanvas(self.panel, -1, self.figure)
00170
00171
00172 self.createMap(self.dispConf.map_getMapDetail(), self.dispConf.map_getDrawCSBorders(), self.dispConf.map_getDrawRivers())
00173
00174
00175 self._resizeflag = True
00176 self._SetSize()
00177
00178
00179 self.rclickMenu = mainFramePopupMenu(self)
00180
00181
00182 self.doBindings()
00183
00184 self.animLoaderIcon = animatedLoaderIcon(self.toolbarContainer.toolbar, globalStrings.animated_img_in_progress, (800 - 50,3))
00185
00186 self.startMouseHoverThread()
00187
00188 startupSplah.Close()
00189
00190 self.redrawCycle()
00191
00192
00193
00194
00195
00196 geoUtils = geoIPUtils("")
00197 if (geoUtils.isGEOIPDatabaseInstalled() == False):
00198
00199 msg = "EyeSpy makes use of a non free GEO IP Database which is not shipped with the application.\n\n"
00200 msg += "EyeSpy supports the MaxMind Database which is available by either purchasing a commercial license from MaxMind "
00201 msg += "or by downloading a free, personal use copy of it from their web site. Once downloaded, the database can be imported using EyeSpy's 'About' page.\n\n"
00202
00203 msg += "Although EyeSpy is a free application, usage of the GEO IP Database is still bound by MaxMind's terms.\n\n"
00204
00205 msg += "For additional Information, please visit EyeSpy's home page."
00206 msg += "\n\n"
00207 msg += "( " + self.optConfig.navigation_getAppHomePage() + " )"
00208
00209 dlg = wx.MessageDialog(None, msg, 'Please Note...', wx.ICON_WARNING)
00210 result = dlg.ShowModal()
00211 dlg.Destroy()
00212
00213
00214
00215
00216 def initializeThreads(self):
00217 self.lck = RLock()
00218
00219
00220 self.autoRedrawThread = None
00221
00222
00223 self.mouseHoverThread = None
00224
00225
00226
00227
00228
00229
00230
00231
00232 def hitTest(self, pos):
00233 entityDict = self.mainApp.entityMan.getSafeFilteredEntityCollectionByGeoLoc(None)
00234
00235 w_h = self.canavas.get_width_height()
00236 x,y = pos.x, w_h[1] - pos.y
00237
00238
00239 zoomFactor = self.fig_axes.getZoomFactor()
00240
00241
00242 hitRange = zoomFactor/90
00243
00244 mouseMapX, mouseMapY = self.fig_axes.getAxesXYFromMouseXY( x, y)
00245
00246 for key, entList in entityDict.iteritems():
00247
00248 entX, entY = self.worldMainMap.main_map(key[0], key[1])
00249
00250
00251 deltaX = abs(entX - mouseMapX)
00252 deltaY = abs(entY - mouseMapY)
00253
00254 if (mouseMapX >= entX - hitRange and mouseMapX <= entX + hitRange):
00255 if (mouseMapY >= entY - hitRange and mouseMapY <= entY + hitRange):
00256
00257 return entList
00258 return None
00259
00260
00261
00262
00263
00264 def _OnSize(self, event):
00265 size = event.GetSize()
00266 self._resizeflag = True
00267
00268 self.panelSize = size
00269
00270
00271
00272
00273
00274
00275 def _OnMinimize(self, event):
00276 self.isWindowMinimined = not self.isWindowMinimined
00277 print "Minimized"
00278
00279
00280 if self.isWindowMinimined == False:
00281 self.redrawCycle()
00282
00283
00284
00285
00286
00287 def _OnLButtonDown(self, event):
00288 if not event: return
00289
00290 pos = event.GetPosition()
00291
00292
00293 if not self.fig_axes.axes.in_axes(pos.x, pos.y): return
00294
00295
00296 if self.displayMode == VIEW_STATE_ZOOM or self.displayMode == VIEW_STATE_PAN:
00297
00298
00299 self.rubber_start = event.GetPosition()
00300
00301 self.rubber_end = self.rubber_start
00302 self.lbuttonDown = True
00303
00304
00305
00306
00307
00308 def _OnMouseWheel(self, event):
00309 rot = event.GetWheelRotation()
00310
00311 if rot >= 0:
00312 self.handleZoomIn(None)
00313 else:
00314 self.handleZoomOut(None)
00315
00316
00317
00318
00319
00320 def _OnIdle(self, evt):
00321 if self._resizeflag:
00322
00323
00324 self.lck.acquire(1)
00325 try:
00326 self.SetSizeWH(self.panelSize.width, self.panelSize.height)
00327 self.panel.SetSize( wx.Size( self.panelSize.width, self.panelSize.height ) )
00328
00329
00330 self._resizeflag = False
00331 self._SetSize()
00332 finally:
00333 self.lck.release()
00334
00335
00336 self.animLoaderIcon.changePos((self.panelSize.width - 50, 3))
00337
00338
00339
00340
00341
00342 def _OnMouseMove(self, event):
00343 if not event: return
00344
00345 pos = event.GetPosition()
00346
00347
00348 self.currentMousePosition = pos
00349 self.lastMouseMoveTime = time.time()
00350
00351 self.setStatusBarText(pos);
00352
00353
00354 if self.displayMode == VIEW_STATE_PAN:
00355 self.rubber_end = event.GetPosition()
00356 pass
00357
00358 elif self.displayMode == VIEW_STATE_ZOOM:
00359 if self.lbuttonDown:
00360 dc= wx.ClientDC(self.canavas)
00361
00362
00363
00364 dc.SetLogicalFunction(wx.XOR)
00365
00366 wbrush = wx.Brush(wx.Colour(255,255,255), wx.TRANSPARENT)
00367 wpen = wx.Pen(wx.Colour(200, 200, 200), 1, wx.DOT)
00368
00369 dc.SetBrush(wbrush)
00370 dc.SetPen(wpen)
00371
00372
00373 dc.ResetBoundingBox()
00374 dc.BeginDrawing()
00375
00376 w = (self.rubber_end.x - self.rubber_start.x)
00377 h = (self.rubber_end.y - self.rubber_start.y)
00378
00379
00380
00381 dc.DrawRectangle(self.rubber_start.x, self.rubber_start.y, w, h)
00382
00383
00384 self.rubber_end = event.GetPosition()
00385
00386 w = (self.rubber_end.x - self.rubber_start.x)
00387 h = (self.rubber_end.y - self.rubber_start.y)
00388
00389
00390 dc.SetClippingRegion(self.rubber_start.x, self.rubber_start.y, w,h)
00391 dc.DrawRectangle(self.rubber_start.x, self.rubber_start.y, w, h)
00392 dc.EndDrawing()
00393
00394
00395
00396
00397
00398 def _OnLButtonUp(self, event):
00399 if not event: return
00400
00401 self.canDisplayTipWin = True
00402
00403 if self.displayMode == VIEW_STATE_PAN:
00404 self._OnPan(event)
00405
00406
00407 elif self.displayMode == VIEW_STATE_ZOOM:
00408 self._OnZoom(event)
00409
00410 elif self.displayMode == VIEW_STATE_SETHOMELOC:
00411 self._OnSetHomeLocation(event)
00412
00413
00414
00415
00416
00417 def _OnZoom(self, event):
00418 pos = event.GetPosition()
00419 if not self.fig_axes.axes.in_axes(pos.x, pos.y):
00420
00421 self.lbuttonDown = False
00422 self.rubber_start = None
00423 self.rubber_end = None
00424
00425 self.redrawCanavasLock()
00426
00427 return
00428 self.rubber_end = event.GetPosition()
00429
00430 if (self.rubber_end == None or self.rubber_start == None): return
00431 if abs(self.rubber_end.x-self.rubber_start.x)<5 or abs(self.rubber_end.y-self.rubber_start.y)<5:
00432 self.rubber_start = None
00433 self.rubber_end = None
00434 self.lbuttonDown = False
00435 self.redrawCanavasLock()
00436 return
00437
00438
00439 w_h = self.canavas.get_width_height()
00440 self.rubber_start.y = w_h[1] - self.rubber_start.y
00441 self.rubber_end.y = w_h[1] - self.rubber_end.y
00442
00443
00444
00445
00446 newZoomFactor = None
00447 filter = baseFilter()
00448
00449 self.lck.acquire(1)
00450 try:
00451 self.fig_axes.freeZoomChangeAspect(self.rubber_start, self.rubber_end, self.canavas.GetSize())
00452 newZoomLevel = filter.getUserFriendlyZoomLevel(self.fig_axes.getZoomFactor())
00453 finally:
00454 self.lck.release()
00455
00456
00457 if self.currentZoomLevel is not None and (self.currentZoomLevel != newZoomLevel):
00458 self.redrawCycle()
00459
00460 self.currentZoomLevel = newZoomLevel
00461
00462 self.redrawCanavasLock()
00463
00464 self.lbuttonDown = False
00465 self.rubber_start = None
00466 self.rubber_end = None
00467
00468
00469
00470
00471
00472 def _OnPan(self, event):
00473 self.rubber_end = event.GetPosition()
00474
00475 self.lck.acquire(1)
00476 try:
00477 self.fig_axes.pan(self.rubber_start, self.rubber_end)
00478 finally:
00479 self.lck.release()
00480
00481 self.redrawCanavasLock()
00482
00483 self.lbuttonDown = False
00484 self.rubber_start = None
00485 self.rubber_end = None
00486
00487
00488
00489
00490
00491 def _OnSetHomeLocation(self, event):
00492 pos = event.GetPosition()
00493
00494
00495 w_h = self.canavas.get_width_height()
00496 x,y = pos.x, w_h[1] - pos.y
00497 lon, lat = self.fig_axes.getLonLatFromMouseXY(x,y, self.worldMainMap.main_map)
00498
00499 strLon = "%3.2f" % (lon)
00500 strLat = "%3.2f" % (lat)
00501
00502 strLon = strLon.rjust(10, " ")
00503 strLat = strLat.rjust(10, " ")
00504
00505 msg = "Would you like to make:\n\nLon:%s\nLat:%s\n\nYour new home location?" % (strLon, strLat)
00506
00507
00508 dlg = wx.MessageDialog(None, msg, 'Please Confirm...', wx.YES_NO | wx.ICON_QUESTION)
00509 result = dlg.ShowModal()
00510 dlg.Destroy()
00511
00512 if result == wx.ID_YES:
00513
00514 self.optConfig.ident_setManualCoord((lon, lat))
00515 self.optConfig.ident_setIdentByCoord()
00516
00517 self.redrawCycle()
00518
00519
00520
00521
00522
00523
00524 def _OnRButtonUp(self, event):
00525
00526 pos = event.GetPosition()
00527
00528 self.canDisplayTipWin = False
00529
00530 self.entListSelection = self.hitTest(pos)
00531 if self.entListSelection is not None:
00532 self.entListSelection = copy.deepcopy(self.entListSelection)
00533
00534
00535 self.rclickMenu.buildMenuFromEntList(self.entListSelection)
00536
00537 popupMenu = self.rclickMenu.getMenu()
00538
00539 try:
00540 self.PopupMenu(popupMenu, event.GetPosition())
00541 except Exception, e:
00542 logger.log(__name__ + ": Exception creating popup menu:")
00543 logger.log(__name__ + str(e))
00544
00545
00546
00547
00548
00549
00550 def _SetSize(self, pixels = None):
00551
00552 if not pixels:
00553 pixels = self.GetClientSize()
00554
00555 self.fig_axes.adjustAxisToCanavas( pixels )
00556
00557
00558 self.canavas.SetSize(pixels)
00559 self.figure.set_size_inches(pixels[0]/self.figure.get_dpi(),
00560 pixels[1]/self.figure.get_dpi())
00561
00562
00563 self.redrawCanavasLock()
00564
00565
00566
00567
00568
00569 def setStatusBarText(self, pos):
00570 if pos == None: return
00571
00572 filter = baseFilter()
00573 zoomLevel = filter.getUserFriendlyZoomLevel(self.fig_axes.getZoomFactor())
00574
00575 w_h = self.canavas.get_width_height()
00576 x,y = pos.x, w_h[1] - pos.y
00577 lon, lat = self.fig_axes.getLonLatFromMouseXY(x,y, self.worldMainMap.main_map)
00578 statusText = "lon:%4.2f, lat:%4.2f -- Zoom: %s -- Tracking: %d Peers -- Displaying: %d Peers" % (lon, lat, zoomLevel, self.numPeers, self.numDisplayedPeers)
00579 self.statusBar.SetStatusText(statusText)
00580
00581
00582
00583
00584
00585
00586
00587
00588 def createMap(self, mapDetail, drawCSBorders, drawRivers):
00589 ax = self.figure.add_axes([0,0,0.99,0.99])
00590 self.fig_axes = figureAxesWrapper(ax)
00591 self.fig_axes.axes.set_axis_bgcolor('aqua')
00592
00593 self.worldMainMap = mainFrameMap(self.fig_axes)
00594 self.worldMainMap.createMap(mapDetail, drawCSBorders, drawRivers)
00595
00596
00597 self.fig_axes.computeFullXYLim()
00598 self.fig_axes.resetZoom()
00599
00600 filter = baseFilter()
00601 self.currentZoomLevel = filter.getUserFriendlyZoomLevel(self.fig_axes.getZoomFactor())
00602
00603
00604
00605
00606
00607
00608
00609 def recreateMap(self, mapDetail, drawCSBorders, drawRivers):
00610
00611 recycleThreads = self.redrawThreadIsRunning()
00612
00613 popup = wx.SplashScreen(wx.Image(name = globalStrings.redraw_map_message).ConvertToBitmap(),
00614 wx.SPLASH_CENTRE_ON_SCREEN , -1, self)
00615
00616 if recycleThreads:
00617 self.stopAllThreads()
00618 else:
00619 self.stopMouseHoverThread()
00620
00621 xlim, ylim = self.fig_axes.getCurrentXYLim()
00622 self.figure.clear()
00623 del self.worldMainMap
00624 del self.fig_axes.axes
00625 del self.fig_axes
00626
00627 self.createMap(mapDetail, drawCSBorders, drawRivers)
00628
00629 self.fig_axes.computeFullXYLim()
00630 self.fig_axes.setCurrentXYLim(xlim, ylim)
00631
00632 if recycleThreads:
00633 self.startAllThreads()
00634 else:
00635 self.startMouseHoverThread()
00636
00637 popup.Close()
00638
00639
00640
00641
00642
00643 def redrawCycle(self, userPriority = False):
00644
00645 if userPriority == True and self.lbuttonDown == True:
00646 return
00647
00648 start = time.time()
00649
00650
00651
00652 displayConfigIsGood = True
00653
00654
00655 try:
00656 self.dispConf.loadConfig()
00657 except Exception, ex:
00658 print "there was an exception loading the display configuration: " + str(ex)
00659
00660 self.PeerFilter.setFromDisplayConfig(self.dispConf, self.fig_axes.getZoomFactor())
00661
00662 try:
00663 self.optConfig.loadConfig()
00664 except Exception, ex:
00665 print "there was an exception loading the display configuration: " + str(ex)
00666
00667
00668 homeLon, homeLat, locValid = self.optConfig.ident_getConfigCoordinates()
00669
00670 latitudes = list()
00671 longitudes= list()
00672
00673 entityDict = self.mainApp.entityMan.getSafeFilteredEntityCollectionByGeoLoc(self.PeerFilter)
00674
00675 showLines = self.PeerFilter.shouldDisplayLines()
00676 showLabels = self.PeerFilter.shouldDisplayLabels()
00677
00678 self.displayer.setDisplayConfigurator(self.dispConf)
00679
00680
00681 self.lck.acquire(1)
00682 try:
00683
00684 displayedItems = self.worldMainMap.draw(entityDict, self.displayer,
00685 showLines, showLabels,
00686 homeLon, homeLat)
00687
00688 self.canavas.draw()
00689
00690 self.numPeers = self.mainApp.entityMan.getEntityCollectionSize()
00691 self.numDisplayedPeers = displayedItems
00692
00693 except Exception, e:
00694 logger.log(__name__ + ": Exception during redraw cycle.")
00695 logger.log(e)
00696 finally:
00697 end = time.time()
00698
00699 self.lck.release()
00700
00701 self.setStatusBarText(self.currentMousePosition)
00702
00703
00704
00705
00706
00707 def createPanel(self):
00708
00709 self.sizer = wx.BoxSizer(wx.VERTICAL)
00710 self.SetSizer(self.sizer)
00711 self.SetSize( wx.Size( 800, 600 ) )
00712
00713 self.Centre()
00714
00715 self.panel = wx.Panel(self)
00716
00717 self.sizer.Add(self.panel, 1, wx.EXPAND)
00718 self.Layout()
00719
00720
00721
00722
00723 def doBindings(self):
00724
00725 self.Bind(wx.EVT_SIZE, self._OnSize)
00726 self.Bind(wx.EVT_IDLE, self._OnIdle)
00727
00728 self.Bind(wx.EVT_ICONIZE, self._OnMinimize)
00729
00730 self.canavas.Bind(wx.EVT_LEFT_DOWN, self._OnLButtonDown)
00731 self.canavas.Bind(wx.EVT_MOUSEWHEEL, self._OnMouseWheel)
00732
00733 self.canavas.Bind(wx.EVT_LEFT_UP, self._OnLButtonUp)
00734 self.canavas.Bind(wx.EVT_RIGHT_UP, self._OnRButtonUp)
00735 self.canavas.Bind(wx.EVT_MOTION, self._OnMouseMove)
00736
00737
00738 self.Connect(-1, -1, EVT_DISPLAY_TOOLINFOWIN, self.handleDisplayToolWindow)
00739
00740 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
00741
00742
00743
00744
00745
00746 def handleMonitorErrorCallback(self, errorMsg):
00747 self.handleStopMonitoring(None)
00748
00749 err = "There was an error monitoring the network. Monitoring will now stop:\n\n%s" % errorMsg
00750 dlg = wx.MessageDialog(None, err, 'Error', wx.ICON_ERROR)
00751 result = dlg.ShowModal()
00752 dlg.Destroy()
00753
00754
00755
00756
00757
00758 def handleStartMonitoring(self, event):
00759 if self.redrawThreadIsRunning():
00760 return
00761
00762 if self.selectedNetworkDevice == None:
00763
00764 dlg = wx.MessageDialog(None, 'No network device was selected, would you like to choose one now?',
00765 'Please Confirm', wx.YES_NO | wx.ICON_QUESTION)
00766 result = dlg.ShowModal()
00767 dlg.Destroy()
00768
00769 if result == wx.ID_YES:
00770 self.handleConfigureNetwork(event)
00771 else:
00772 return
00773
00774
00775
00776 if self.selectedNetworkDevice != None:
00777
00778
00779 if self.mainApp.entityMan.getEntityCollectionSize() > 0:
00780 dlg = wx.MessageDialog(None, 'Would you like to clear all data before proceeing?',
00781 'Please Confirm', wx.YES_NO | wx.ICON_QUESTION)
00782 result = dlg.ShowModal()
00783 dlg.Destroy()
00784
00785 if result == wx.ID_YES:
00786 self.mainApp.entityMan.removeAllEntities()
00787 self.mainApp.initStorage(True, True)
00788 else:
00789 self.mainApp.initStorage(False, True)
00790 else:
00791 self.mainApp.initStorage(True, True)
00792
00793 try:
00794 self.mainApp.startStorageManager()
00795
00796 self.mainApp.netMon.networkIface.registerErrorCallBackFunc(self.handleMonitorErrorCallback)
00797 self.mainApp.netMon.startListening(self.selectedNetworkDevice)
00798 except exception, e:
00799 dlg = wx.MessageDialog(None, e.reason, 'Error', wx.ICON_ERROR)
00800 result = dlg.ShowModal()
00801 dlg.Destroy()
00802 else:
00803
00804 self.startRedrawthread()
00805 self.animLoaderIcon.play()
00806
00807
00808
00809
00810 def handleStopMonitoring(self, event):
00811
00812 if self.selectedNetworkDevice != None:
00813 self.mainApp.shutdownStorage()
00814 self.mainApp.netMon.stopListening()
00815
00816
00817 self.stopRedrawThread()
00818 self.animLoaderIcon.stop()
00819
00820
00821
00822
00823
00824 def handleGoHome(self, event):
00825
00826 self.lck.acquire(1)
00827 try:
00828 self.fig_axes.resetZoom()
00829 finally:
00830 self.lck.release()
00831
00832
00833 filter = baseFilter()
00834 newZoomLevel = filter.getUserFriendlyZoomLevel(self.fig_axes.getZoomFactor())
00835
00836 if self.currentZoomLevel is not None and (self.currentZoomLevel != newZoomLevel):
00837 self.redrawCycle()
00838
00839 self.currentZoomLevel = newZoomLevel
00840
00841
00842
00843 self.redrawCanavasLock()
00844
00845
00846
00847
00848
00849 def handlePan(self, event):
00850 self.displayMode = VIEW_STATE_PAN
00851 self.cursor = wx.StockCursor(wx.CURSOR_SIZING)
00852
00853 self.canavas.SetCursor(self.cursor)
00854
00855
00856
00857
00858
00859 def handleFreeZoom(self, event):
00860 self.cursor = wx.StockCursor(wx.CURSOR_ARROW)
00861 self.displayMode = VIEW_STATE_ZOOM
00862
00863 self.canavas.SetCursor(self.cursor)
00864
00865
00866
00867
00868
00869 def handleZoomIn(self, event):
00870 self.lck.acquire(1)
00871 try:
00872 self.fig_axes.zoomIn(self.canavas.GetSize())
00873 finally:
00874 self.lck.release()
00875
00876 self.redrawCanavasLock()
00877
00878
00879
00880
00881
00882 def handleZoomOut(self, event):
00883 self.lck.acquire(1)
00884 try:
00885 self.fig_axes.zoomOut(self.canavas.GetSize())
00886 finally:
00887 self.lck.release()
00888
00889 self.redrawCanavasLock()
00890
00891
00892
00893
00894
00895 def handleCaptureScreenshot(self, event):
00896 saveDlg = pictureSaverDialog(self, self.figure)
00897
00898
00899
00900
00901
00902 def handleConfigureNetwork(self, event):
00903 try:
00904 devDict = self.mainApp.netMon.getDeviceProperties()
00905 except exception, e:
00906 dlg = wx.MessageDialog(None, e.reason, 'Error', wx.ICON_ERROR)
00907 result = dlg.ShowModal()
00908 dlg.Destroy()
00909 logger.log(__name__ + ": " + e.reason)
00910 else:
00911 try:
00912 self.optConfig.loadConfig()
00913 except Exception, e:
00914 errMsg = "There was an error reading the options configuration file\nAlthough you configuration will be restored all application options will be set to their starting values. \nThis is usually due to a missing or corrupt configuration file\n\nDetailed Error:\n%s " % (str(e))
00915
00916 dlg = wx.MessageDialog(None, errMsg, 'Error', wx.ICON_ERROR)
00917 result = dlg.ShowModal()
00918 dlg.Destroy()
00919
00920 try:
00921 netSettings = networkSettings(self, devDict)
00922 netSettings.loadConfig(self.optConfig)
00923 except Exception, ex:
00924 errMsg = "Could not display Network Settings window: %s" % (str(ex))
00925
00926 dlg = wx.MessageDialog(None, errMsg, 'Error', wx.ICON_ERROR)
00927 result = dlg.ShowModal()
00928 dlg.Destroy()
00929 return
00930 try:
00931 if netSettings.ShowModal() == wx.ID_OK:
00932 self.selectedNetworkDevice = netSettings.chosenDevice
00933 saveDeviceSelection = netSettings.saveSelection
00934
00935 self.optConfig.network_setSaveDeviceSelection(saveDeviceSelection)
00936
00937 if saveDeviceSelection == True:
00938 self.optConfig.network_setSelectedDevice(self.selectedNetworkDevice)
00939
00940 except Exception, e:
00941 errMsg = "Could not save network settings: %s" % (str(e))
00942
00943 dlg = wx.MessageDialog(None, errMsg, 'Error', wx.ICON_ERROR)
00944 result = dlg.ShowModal()
00945 dlg.Destroy()
00946
00947 finally:
00948 if netSettings != None:
00949 netSettings.Destroy()
00950
00951
00952
00953
00954
00955 def handleSetHomeLocation(self, event):
00956 self.cursor = wx.StockCursor(wx.CURSOR_BULLSEYE)
00957 self.canavas.SetCursor(self.cursor)
00958
00959 self.displayMode = VIEW_STATE_SETHOMELOC
00960
00961
00962
00963
00964
00965
00966 def handleOptions(self, event):
00967 try:
00968 self.optConfig.loadConfig()
00969 except Exception, e:
00970 errMsg = "There was an error reading the options configuration file\nAlthough you configuration will be restored all application options will be set to their starting values. \nThis is usually due to a missing or corrupt configuration file\n\nDetailed Error:\n%s " % (str(e))
00971
00972 dlg = wx.MessageDialog(None, errMsg, 'Error', wx.ICON_ERROR)
00973 result = dlg.ShowModal()
00974 dlg.Destroy()
00975
00976 try:
00977 opt = appOptions(self, self.mainApp.entityMan.geoIP)
00978 opt.loadConfiguration(self.optConfig)
00979 except Exception, e:
00980 errMsg = "There was an error displaying application options%s" % (str(e))
00981
00982 dlg = wx.MessageDialog(None, errMsg, 'Error', wx.ICON_ERROR)
00983 result = dlg.ShowModal()
00984 dlg.Destroy()
00985
00986 return
00987
00988 try:
00989 if opt.ShowModal() == wx.ID_OK:
00990
00991 if opt.ipAddrValid == True:
00992 self.optConfig.ident_setIPAddr(opt.getIPAddress())
00993 self.optConfig.ident_setIPGeoInfo(opt.getIPGeoInfo())
00994
00995 if opt.coordValid == True:
00996 self.optConfig.ident_setManualCoord(opt.getCoordinates())
00997
00998 if opt.getIdentifyByIP() == True:
00999 self.optConfig.ident_setIdentByIPAddr()
01000 else:
01001 self.optConfig.ident_setIdentByCoord()
01002
01003 self.optConfig.ident_setConfigValid(opt.getConfigValid())
01004
01005 self.optConfig.network_setRecordTraffic(opt.getNetworkRecordTraffic())
01006 self.optConfig.network_setNeverStopRecording(opt.getNetworkUnlimitedCapture())
01007 self.optConfig.network_setRecordingMaxLimit(opt.getNetworkMaxStorage())
01008
01009 if opt.networkSettingsChanged == True and self.redrawThreadIsRunning() == True:
01010 try:
01011 dlg = wx.MessageDialog(None, "Network Settings will take effect when monitoring is restarted", 'Info', wx.ICON_EXCLAMATION)
01012 result = dlg.ShowModal()
01013 finally:
01014 dlg.Destroy()
01015
01016
01017 self.redrawCycle()
01018
01019 except Exception, e:
01020 errMsg = "There was an error saving options.\nDetailed Error:\n%s " % (str(e))
01021
01022 dlg = wx.MessageDialog(None, errMsg, 'Error', wx.ICON_ERROR)
01023 result = dlg.ShowModal()
01024 dlg.Destroy()
01025 finally:
01026 if opt is not None:
01027 opt.Destroy()
01028
01029
01030
01031
01032
01033 def handleViewFilter(self, event):
01034 fs = None
01035
01036 try:
01037 fs = filterSettings(self, self.PeerFilter)
01038 if fs.ShowModal() == wx.ID_OK:
01039 if fs.somethingRemoved == True:
01040 self.redrawCycle()
01041
01042 finally:
01043 if fs is not None: fs.Destroy()
01044
01045
01046
01047
01048
01049 def handleDisplaySettings(self, event):
01050 try:
01051 self.dispConf.loadConfig()
01052 except Exception, ex:
01053 errMsg = "There was an error reading the display settings configuration file\nAlthough you configuration will be restored all display settings parameters will be set to their starting values. \nThis is usually due to a missing or corrupt configuration file\n\nDetailed Error:\n%s " % (str(ex))
01054
01055 dlg = wx.MessageDialog(None, errMsg, 'Error', wx.ICON_ERROR)
01056 result = dlg.ShowModal()
01057 dlg.Destroy()
01058
01059 ds = None
01060
01061 try:
01062 ds = displaySettings(self)
01063 ds.loadConfiguration(self.dispConf)
01064 except Exception, e:
01065 errMsg = "There was an error opening Display Settings window.\nDetailed Error:\n%s" % (str(e))
01066
01067 dlg = wx.MessageDialog(None, errMsg, 'Error', wx.ICON_ERROR)
01068 result = dlg.ShowModal()
01069 dlg.Destroy()
01070 return
01071 try:
01072 if ds.ShowModal() == wx.ID_OK:
01073
01074 self.dispConf.glb_setMinXferOptions(ds.getGlbPeerXferOptions())
01075 self.dispConf.glb_setMaxIdleOptions(ds.getGlbPeerIdleOptions())
01076
01077 self.dispConf.glb_setLineOptions(ds.getGlbLineOptions())
01078 self.dispConf.glb_setLabelOptions(ds.getGlbLabelOptions())
01079
01080 self.dispConf.glb_setDisplayScale(ds.getGlbDisplayScale())
01081 self.dispConf.glb_setRefreshRate(ds.getGlbRefreshRate())
01082 self.dispConf.glb_setDisplayLabel(ds.getGlbDisplayLabel())
01083
01084 self.dispConf.app_setProcessColorCodes(ds.getAppColorDict())
01085 self.dispConf.app_setProcessDefaultColor(ds.getAppDefaultColor())
01086
01087 if ds.refreshRateConfigChanged == True and self.redrawThreadIsRunning() == True:
01088 try:
01089 dlg = wx.MessageDialog(None, "Refresh Rate change will take effect once monitoring is restarted.", 'Info', wx.ICON_EXCLAMATION)
01090 dlg.ShowModal()
01091 finally:
01092 dlg.Destroy()
01093
01094
01095 self.dispConf.map_setMapDetail(ds.getMapDetailLevel())
01096 self.dispConf.map_setDrawCSBorders(ds.getMapDrawCSBorders())
01097 self.dispConf.map_setDrawRivers(ds.getMapDrawRivers())
01098
01099 if ds.mapOptionsChanged:
01100 self.recreateMap(self.dispConf.map_getMapDetail(), self.dispConf.map_getDrawCSBorders(), self.dispConf.map_getDrawRivers())
01101
01102
01103 self.redrawCycle()
01104 except Exception, e:
01105 errMsg = "There was an error saving display settings.\nDetailed Error:\n%s " % (str(e))
01106
01107 dlg = wx.MessageDialog(None, errMsg, 'Error', wx.ICON_ERROR)
01108 result = dlg.ShowModal()
01109 dlg.Destroy()
01110
01111 finally:
01112 if ds is not None: ds.Destroy()
01113
01114
01115
01116
01117
01118 def handleShowAbout(self, event):
01119 aboutDlg = aboutDialog(self, self.optConfig)
01120 aboutDlg.ShowModal()
01121 aboutDlg.Destroy()
01122
01123
01124
01125
01126
01127 def handleExit(self, event):
01128 self.OnCloseWindow(event)
01129
01130
01131
01132
01133
01134 def handleDisplayToolWindow(self, event):
01135 if self.canDisplayTipWin == False: return
01136
01137 entList = copy.deepcopy(event.entityList)
01138
01139 x,y = self.currentMousePosition.x, self.currentMousePosition.y
01140
01141
01142 x,y=self.ClientToScreen((x,y))
01143
01144 entList = copy.deepcopy(entList)
01145
01146 tipWin = mainFrameToolWindow(self, entList, x, y)
01147
01148
01149
01150
01151
01152 def createStatusBar(self):
01153 self.statusBar = self.CreateStatusBar()
01154
01155
01156 """
01157 Threading functions
01158 """
01159
01160
01161
01162 def startAllThreads(self):
01163 self.stopRedrawThread()
01164 self.stopMouseHoverThread()
01165
01166 self.startRedrawthread()
01167 self.startMouseHoverThread()
01168
01169
01170
01171
01172 def stopAllThreads(self):
01173 self.stopRedrawThread()
01174 self.stopMouseHoverThread()
01175
01176
01177
01178
01179 def startRedrawthread(self):
01180 if self.redrawThreadIsRunning() == True:
01181 return
01182
01183 logger.log(__name__ + "Starting Redraw Thread")
01184
01185
01186 self.autoRedrawThread = redrawThread(self)
01187 self.autoRedrawThread.reset()
01188
01189
01190 refreshInterval = self.dispConf.glb_getRefreshRate()
01191
01192 self.autoRedrawThread.setRefreshInterval(refreshInterval)
01193
01194
01195 self.autoRedrawThread.start()
01196
01197
01198
01199
01200 def stopRedrawThread(self):
01201
01202 logger.log(__name__ + ": Stopping Redraw Thread")
01203
01204
01205
01206 if (self.redrawThreadIsRunning() == True):
01207 self.autoRedrawThread.killSignalAndWait(5)
01208
01209
01210
01211
01212 def redrawThreadIsRunning(self):
01213 if self.autoRedrawThread != None and self.autoRedrawThread.isAlive() == True:
01214 return True
01215 else:
01216 return False
01217
01218
01219
01220
01221
01222 def mouseHoverThreadIsRunning(self):
01223 if self.mouseHoverThread != None and self.mouseHoverThread.isAlive() == True:
01224 return True
01225 else:
01226 return False
01227
01228
01229
01230
01231 def startMouseHoverThread(self):
01232
01233 if self.mouseHoverThreadIsRunning() == True:
01234 return
01235
01236 logger.log(__name__ + "Starting Mouse Hover Thread")
01237
01238
01239
01240 self.mouseHoverThread = mouseHoverThread(self)
01241 self.mouseHoverThread.reset()
01242
01243 self.mouseHoverThread.start()
01244
01245
01246
01247 def stopMouseHoverThread(self):
01248
01249 logger.log(__name__ + "Stopping Mouse Hover Thread")
01250
01251
01252
01253 if (self.mouseHoverThread != None):
01254 self.mouseHoverThread.killSignalAndWait(10);
01255
01256 """
01257 context menu related
01258 """
01259
01260
01261
01262
01263 def popupMenuCallBack(self, event):
01264 itemTuple = self.rclickMenu.getMenuItem(event.GetId())
01265
01266 menuName, menuCat, menuParam = itemTuple
01267
01268 if menuCat == "DISPLAY_SETTING":
01269 self.handleDisplaySettings(event)
01270
01271 if menuCat == "SHOW_OPTIONS":
01272 self.handleOptions(None)
01273
01274 if menuCat == "VIEW_FILTERS":
01275 self.handleViewFilter(None)
01276
01277 if menuCat == "SHOWDETAILS":
01278 peerList = peerGridDisplay(self)
01279 peerList.fromEntList(self.entListSelection)
01280 peerList.Show(True)
01281
01282 if menuCat == "SHOWDETAILSVIS":
01283 entDict = self.mainApp.entityMan.getSafeFilteredEntityCollectionByGeoLoc(None)
01284
01285 peerList = peerGridDisplay(self)
01286
01287 peerList.fromEntGeoLocDict(entDict)
01288 peerList.Show(True)
01289
01290 if menuCat == "SHOWDETAILSALL":
01291 entDict = self.mainApp.entityMan.getSafeEntityCollectionByPK()
01292
01293 peerList = peerGridDisplay(self)
01294 peerList.fromEntDict(entDict)
01295 peerList.Show(True)
01296
01297 if menuCat == "FILTERITEM":
01298 self.PeerFilter.addToFilter(menuParam)
01299 self.redrawCycle()
01300
01301 if menuCat == "DISPLAY_TRACE":
01302
01303
01304 if len(self.entListSelection) == 0:
01305 return
01306
01307 ent = self.entListSelection[0]
01308
01309 traceDisplay = traceDisplayDialog(self, ent.foreignIPAddress, ent.selfPort, ent.foreignPort)
01310 traceDisplay.ShowModal()
01311
01312
01313 self.canDisplayTipWin = True
01314
01315
01316
01317
01318 """
01319 global redrawing functions
01320 """
01321
01322
01323
01324
01325 def redrawCanavasLock(self):
01326
01327 self.lck.acquire(1)
01328 try:
01329 self.canavas.draw()
01330 finally:
01331 self.lck.release()
01332
01333 """
01334 misc
01335 """
01336
01337
01338
01339
01340
01341 def die(self, why):
01342 dlg = wx.MessageDialog(None, why, 'Error', wx.ICON_ERROR)
01343 result = dlg.ShowModal()
01344 dlg.Destroy()
01345
01346 self.stopAllThreads()
01347 self.Destroy()
01348
01349
01350
01351
01352 def OnCloseWindow(self, event):
01353 self.stopAllThreads()
01354 self.Destroy()
01355
01356 self.mainApp.shutdownStorage()
01357 self.mainApp.storage.deleteStorage()
01358
01359 def doNothing(self):
01360 pass
01361
01362
01363
01364
01365