Changeset 2df0b74 in sasview for src/sas/plottools/binder.py
- Timestamp:
- Mar 5, 2015 9:17:05 AM (10 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 3477478
- Parents:
- dca6188
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/plottools/binder.py
r79492222 r2df0b74 3 3 """ 4 4 import sys 5 6 7 class Selection :5 import logging 6 7 class Selection(object): 8 8 """ 9 9 Store and compare selections. … … 11 11 # TODO: We need some way to check in prop matches, preferably 12 12 # TODO: without imposing structure on prop. 13 13 14 14 artist = None 15 15 prop = {} 16 16 17 17 def __init__(self, artist=None, prop={}): 18 18 self.artist, self.prop = artist, self.prop 19 19 20 20 def __eq__(self, other): 21 21 return self.artist is other.artist 22 22 23 23 def __ne__(self, other): 24 24 return self.artist is not other.artist 25 25 26 26 def __nonzero__(self): 27 27 return self.artist is not None 28 28 29 29 30 class BindArtist :30 class BindArtist(object): 31 31 """ 32 32 """ … … 41 41 dclick_threshhold = 0.25 42 42 _last_button, _last_time = None, 0 43 43 44 44 # Mouse/keyboard events we can bind to 45 45 events = ['enter', 'leave', 'motion', 'click', 'dclick', 'drag', 'release', 46 'scroll', 'key', 'keyup']46 'scroll', 'key', 'keyup'] 47 47 # TODO: Need our own event structure 48 48 49 49 def __init__(self, figure): 50 50 canvas = figure.canvas … … 69 69 canvas.mpl_connect('key_release_event', self._onKeyRelease), 70 70 ] 71 71 72 72 self._current = None 73 73 self._actions = {} … … 75 75 self.figure = figure 76 76 self.clearall() 77 77 78 78 def clear(self, *artists): 79 79 """ 80 80 self.clear(h1,h2,...) 81 81 Remove connections for artists h1, h2, ... 82 82 83 83 Use clearall() to reset all connections. 84 84 """ … … 96 96 if self._haskey.artist in artists: 97 97 self._haskey = Selection() 98 98 99 99 def clearall(self): 100 100 """ 101 101 Clear connections to all artists. 102 102 103 103 Use clear(h1,h2,...) to reset specific artists. 104 104 """ … … 121 121 for cid in self._connections: self.canvas.mpl_disconnect(cid) 122 122 except: 123 print "Error disconnection canvas: %s" % sys.exc_value 124 pass 123 logging.error("Error disconnection canvas: %s" % sys.exc_value) 125 124 self._connections = [] 126 125 … … 130 129 def __call__(self, trigger, artist, action): 131 130 """Register a callback for an artist to a particular trigger event. 132 131 133 132 usage: 134 133 self.connect(eventname,artist,action) 135 134 136 135 where: 137 136 eventname is a string … … 153 152 key: key pressed when mouse is on the artist 154 153 keyrelease: key released for the artist 155 154 156 155 The event received by action has a number of attributes: 157 156 name is the event name which was triggered … … 165 164 details is a dictionary of artist specific details, such as the 166 165 id(s) of the point that were clicked. 167 166 168 167 When receiving an event, first check the modifier state to be 169 168 sure it applies. E.g., the callback for 'press' might be: … … 203 202 if action not in self.events: 204 203 raise ValueError, "Trigger expects " + ", ".join(self.events) 205 204 206 205 # Tag the event with modifiers 207 206 for mod in ('alt', 'control', 'shift', 'meta'): … … 210 209 setattr(ev, 'action', action) 211 210 setattr(ev, 'prop', {}) 212 211 213 212 # Fallback scheme. If the event does not return false, pass to parent. 214 213 processed = False … … 249 248 found.artist, found.prop = artist, prop 250 249 break 251 250 252 251 # TODO: how to check if prop is equal? 253 252 if found != self._current: … … 257 256 258 257 return found 259 258 260 259 def _onMotion(self, event): 261 260 """ … … 263 262 other artists are invisible. 264 263 """ 265 # # Can't kill double-click on motion since Windows produces266 # # spurious motion events.267 # self._last_button = None268 264 # # Can't kill double-click on motion since Windows produces 265 # # spurious motion events. 266 # self._last_button = None 267 269 268 # Dibs on the motion event for the clicked artist 270 269 if self._hasclick: 271 270 # Make sure the x,y data use the coordinate system of the 272 271 # artist rather than the default axes coordinates. 273 272 274 273 transform = self._hasclick.artist.get_transform() 275 # x,y = event.xdata,event.ydata274 # x,y = event.xdata,event.ydata 276 275 x, y = event.x, event.y 277 276 try: … … 279 278 x, y = transform.inverted().transform((x, y)) 280 279 else: 281 # # For interactive plottable apply transform is not working282 # # don't know why maybe marker definition283 # #transform ="CompositeGenericTransform" crash280 # # For interactive plottable apply transform is not working 281 # # don't know why maybe marker definition 282 # #transform ="CompositeGenericTransform" crash 284 283 pass 285 284 except: 286 # # CRUFT matplotlib-0.91 support287 # # exception for transform ="CompositeGenericTransform"288 # # crashes also here285 # # CRUFT matplotlib-0.91 support 286 # # exception for transform ="CompositeGenericTransform" 287 # # crashes also here 289 288 x, y = transform.inverse_xy_tup((x, y)) 290 289 291 # event.xdata, event.ydata = x, y290 # event.xdata, event.ydata = x, y 292 291 self.trigger(self._hasclick, 'drag', event) 293 292 else: … … 300 299 """ 301 300 import time 302 301 303 302 # Check for double-click 304 303 event_time = time.time() … … 310 309 self._last_button = event.button 311 310 self._last_time = event_time 312 311 313 312 # If an artist is already dragging, feed any additional button 314 313 # presses to that artist. … … 320 319 else: 321 320 found = self._find_current(event) 322 # print "button %d pressed"%event.button321 # print "button %d pressed"%event.button 323 322 # Note: it seems like if "click" returns False then hasclick should 324 323 # not be set. The problem is that there are two reasons it can … … 355 354 self.trigger(self._hasclick, 'release', event) 356 355 self._hasclick = Selection() 357 356 358 357 def _onKey(self, event): 359 358 """ … … 377 376 self.trigger(found, 'key', event) 378 377 self._haskey = found 379 378 380 379 def _onKeyRelease(self, event): 381 380 """ … … 385 384 setattr(self, event.key, False) 386 385 return 387 386 388 387 if self._haskey: 389 388 self.trigger(self._haskey, 'keyup', event)
Note: See TracChangeset
for help on using the changeset viewer.