00001 ## @package objects.gui.threads 00002 # 00003 # The threads package contains various thread derived classes which handle periodic, 00004 # non-user driven events, like redrawing or tracking mouse activity (for map tooltips) 00005 # 00006 # 00007 # 00008 # Copyright (C) 2008-2009 Mark Hanegraaff 00009 # 00010 # This program is free software: you can redistribute it and/or modify 00011 # it under the terms of the GNU General Public License as published by 00012 # the Free Software Foundation, either version 3 of the License, or 00013 # (at your option) any later version. 00014 # 00015 # This program is distributed in the hope that it will be useful, 00016 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 # GNU General Public License for more details. 00019 # 00020 # You should have received a copy of the GNU General Public License 00021 # along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 00023 import wx 00024 import time 00025 from objects.logic.common.logger import logger 00026 00027 from objects.logic.common.threads.appThreadBase import appThreadBase 00028 00029 EVT_DISPLAY_TOOLINFOWIN = wx.NewId() 00030 00031 ## The mouseHoverThread is used to track when the mouse has stopped moving over the map. 00032 # This class is used to determine if a tool tip must be drawn onto the screen 00033 # (if course the mouse has stopped right on top of an Endpoint). 00034 class mouseHoverThread(appThreadBase): 00035 00036 ## Thread class run method. This method will essentially detect when the mouse has stopped moving 00037 # (since lack of movement does not generate a UI event), and determine if a tool tip window needs to be displayed. 00038 # This method will end when the parent.killMouseHoverThread flag is set 00039 def run(self): 00040 self.iterationTime = None 00041 self.lastMousePosition = None 00042 00043 # true if the lastMousePosition was already processed 00044 self.positionChecked = False 00045 00046 try: 00047 while(self.killSwitch == False): 00048 self.threadEvent.clear() 00049 time.sleep(0.5) 00050 00051 if self.parent.currentMousePosition != None: 00052 currentMousePos = wx.Point() 00053 currentMousePos.x = self.parent.currentMousePosition.x 00054 currentMousePos.y = self.parent.currentMousePosition.y 00055 00056 lastMouseMovTim = self.parent.lastMouseMoveTime 00057 00058 self.iterationTime = time.time() 00059 00060 # if mouse is over the figure 00061 if self.parent.fig_axes.axes.in_axes(currentMousePos.x, currentMousePos.y): 00062 #MH##if self.parent.fig_axes.axes.in_axes(currentMousePos): 00063 # and if mouse position has not changed over some period of time 00064 if (self.lastMousePosition == currentMousePos) \ 00065 and abs(self.iterationTime - lastMouseMovTim) > .5: 00066 00067 # if this particular spot has not already been checked... 00068 if self.positionChecked == False: 00069 #check this position 00070 00071 entList = self.parent.hitTest(currentMousePos) 00072 if entList is not None: 00073 00074 self.createTipWindow(entList) 00075 00076 self.positionChecked = True 00077 else: 00078 self.positionChecked = False 00079 self.lastMousePosition = currentMousePos 00080 else: 00081 self.positionChecked = False 00082 00083 finally: 00084 self.threadEvent.set() 00085 self.threadEvent.clear() 00086 00087 logger.log(__name__ + ": Mouse Hover Thread Done") 00088 00089 00090 ## Sends a message back to the Mainframe, in order to displays a tool tip window showing varied information on the Endpoint(s) right underneath the mouse 00091 # Note that there may be more than one Endpoint sharing the same space 00092 # @param entList List of endpoints (usually just a single item list) underneath the mouse 00093 def createTipWindow(self, entList): 00094 evt = wx.PyEvent() 00095 evt.SetEventType(EVT_DISPLAY_TOOLINFOWIN) 00096 evt.entityList = entList 00097 00098 wx.PostEvent(self.parent, evt) 00099
1.5.8