Ignore:
Timestamp:
Mar 5, 2015 2:18:47 PM (10 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
b5de88e
Parents:
b9dbd6b
Message:

pylint fixes and remove old code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/guiframe/local_perspectives/plotting/binder.py

    r79492222 r824e488  
    22Extension to MPL to support the binding of artists to key/mouse events. 
    33""" 
    4  
    5 class Selection: 
     4import logging 
     5import sys 
     6 
     7class Selection(object): 
    68    """ 
    79    Store and compare selections. 
     
    911    # TODO: We need some way to check in prop matches, preferably 
    1012    # TODO: without imposing structure on prop. 
    11          
     13 
    1214    artist = None 
    1315    prop = {} 
    1416    def __init__(self, artist=None, prop={}): 
    1517        self.artist, self.prop = artist, self.prop 
    16          
     18 
    1719    def __eq__(self, other): 
    1820        return self.artist is other.artist 
    19      
     21 
    2022    def __ne__(self, other): 
    2123        return self.artist is not other.artist 
    22      
     24 
    2325    def __nonzero__(self): 
    2426        return self.artist is not None 
    2527 
    26 class BindArtist: 
    27  
    28     # Track keyboard modifiers for events. 
    29     # TODO: Move keyboard modifier support into the backend.  We cannot 
    30     # TODO: properly support it from outside the windowing system since there 
    31     # TODO: is no way to recognized whether shift is held down when the mouse 
    32     # TODO: first clicks on the the application window. 
     28class BindArtist(object): 
     29    """ 
     30        Track keyboard modifiers for events. 
     31        TODO: Move keyboard modifier support into the backend.  We cannot 
     32        TODO: properly support it from outside the windowing system since there 
     33        TODO: is no way to recognized whether shift is held down when the mouse 
     34        TODO: first clicks on the the application window. 
     35    """ 
    3336    control, shift, alt, meta = False, False, False, False 
    3437 
     
    3639    dclick_threshhold = 0.25 
    3740    _last_button, _last_time = None, 0 
    38      
     41 
    3942    # Mouse/keyboard events we can bind to 
    4043    events = ['enter', 'leave', 'motion', 'click', 'dclick', 'drag', 'release', 
    41              'scroll', 'key', 'keyup'] 
     44              'scroll', 'key', 'keyup'] 
    4245    # TODO: Need our own event structure 
    4346    def __init__(self, figure): 
     
    5457            ] 
    5558        except: 
    56             #print "bypassing scroll_event: wrong matplotlib version" 
     59            # print "bypassing scroll_event: wrong matplotlib version" 
    5760            self._connections = [ 
    5861                canvas.mpl_connect('motion_notify_event', self._onMotion), 
     
    6669            canvas.mpl_disconnect(canvas.button_pick_id) 
    6770            canvas.mpl_disconnect(canvas.scroll_pick_id) 
    68         except:  
    69             pass 
     71        except: 
     72            logging.error(sys.exc_value) 
    7073        self.canvas = canvas 
    7174        self.figure = figure 
    7275        self.clearall() 
    73          
     76 
    7477    def clear(self, *artists): 
    7578        """ 
    7679        self.clear(h1,h2,...) 
    7780            Remove connections for artists h1, h2, ... 
    78              
     81 
    7982        Use clearall() to reset all connections. 
    80          
     83 
    8184        """ 
    8285        for h in artists: 
     
    9295        if self._haskey.artist in artists: 
    9396            self._haskey = Selection() 
    94          
     97 
    9598    def clearall(self): 
    9699        """ 
    97100        Clear connections to all artists. 
    98          
     101 
    99102        Use clear(h1,h2,...) to reset specific artists. 
    100103        """ 
     
    113116        In case we need to disconnect from the canvas... 
    114117        """ 
    115         try:  
     118        try: 
    116119            for cid in self._connections: 
    117120                self.canvas.mpl_disconnect(cid) 
    118         except:  
     121        except: 
    119122            pass 
    120123        self._connections = [] 
     
    125128    def __call__(self, trigger, artist, action): 
    126129        """Register a callback for an artist to a particular trigger event. 
    127          
     130 
    128131        usage: 
    129132            self.connect(eventname,artist,action) 
    130      
     133 
    131134        where: 
    132135            eventname is a string 
     
    148151            key: key pressed when mouse is on the artist 
    149152            keyrelease: key released for the artist 
    150      
     153 
    151154        The event received by action has a number of attributes: 
    152155            name is the event name which was triggered 
     
    158161            shift,control,alt,meta are flags which are true if the 
    159162                corresponding key is pressed at the time of the event. 
    160             details is a dictionary of artist specific details, such as the  
     163            details is a dictionary of artist specific details, such as the 
    161164                id(s) of the point that were clicked. 
    162                  
     165 
    163166        When receiving an event, first check the modifier state to be 
    164167        sure it applies.  E.g., the callback for 'press' might be: 
     
    175178        :TODO: Attach multiple callbacks to the same event? 
    176179        :TODO: Clean up interaction with toolbar modes 
    177         :TODO: push/pushclear/pop context so that binding changes  
     180        :TODO: push/pushclear/pop context so that binding changes 
    178181            for the duration 
    179182        :TODO:   e.g., to support ? context sensitive help 
    180          
     183 
    181184        """ 
    182185        # Check that the trigger is valid 
     
    186189        # Register the trigger callback 
    187190        self._actions[trigger][artist] = action 
    188         #print "==> added",artist,[artist],"to",trigger,":", 
    189         #self._actions[trigger].keys() 
     191        # print "==> added",artist,[artist],"to",trigger,":", 
     192        # self._actions[trigger].keys() 
    190193        # Maintain a list of all artists 
    191         if artist not in self._artists:  
     194        if artist not in self._artists: 
    192195            self._artists.append(artist) 
    193196 
     
    231234        # print "search"," ".join([str(h) for h in self._artists]) 
    232235        found = Selection() 
    233         #print "searching in",self._artists 
     236        # print "searching in",self._artists 
    234237        for artist in self._artists: 
    235238            # TODO: should contains() return false if invisible? 
    236             if not artist.get_visible():  
     239            if not artist.get_visible(): 
    237240                continue 
    238241            # TODO: optimization - exclude artists not inaxes 
    239242            try: 
    240                 inside,prop = artist.contains(event) 
     243                inside, prop = artist.contains(event) 
    241244            except: 
    242245                # Probably an old version of matplotlib 
     
    245248                found.artist, found.prop = artist, prop 
    246249                break 
    247         #print "found",found.artist 
    248          
     250        # print "found",found.artist 
     251 
    249252        # TODO: how to check if prop is equal? 
    250253        if found != self._current: 
     
    253256        self._current = found 
    254257        return found 
    255          
     258 
    256259    def _onMotion(self, event): 
    257260        """ 
     
    259262        other artists are invisible. 
    260263        """ 
    261         ## Can't kill double-click on motion since Windows produces 
    262         ## spurious motion events. 
    263         #self._last_button = None 
    264          
     264        # # Can't kill double-click on motion since Windows produces 
     265        # # spurious motion events. 
     266        # self._last_button = None 
     267 
    265268        # Dibs on the motion event for the clicked artist 
    266269        if self._hasclick: 
    267270            # Make sure the x,y data use the coordinate system of the 
    268271            # artist rather than the default axes coordinates. 
    269              
     272 
    270273            transform = self._hasclick.artist.get_transform() 
    271             #x,y = event.xdata,event.ydata 
     274            # x,y = event.xdata,event.ydata 
    272275            x, y = event.x, event.y 
    273276            try: 
     
    280283        else: 
    281284            found = self._find_current(event) 
    282             #print "found",found.artist 
     285            # print "found",found.artist 
    283286            self.trigger(found, 'motion', event) 
    284287 
     
    288291        """ 
    289292        import time 
    290          
     293 
    291294        # Check for double-click 
    292295        event_time = time.time() 
    293         #print event_time,self._last_time,self.dclick_threshhold 
    294         #print (event_time > self._last_time + self.dclick_threshhold) 
    295         #print event.button,self._last_button 
     296        # print event_time,self._last_time,self.dclick_threshhold 
     297        # print (event_time > self._last_time + self.dclick_threshhold) 
     298        # print event.button,self._last_button 
    296299        if (event.button != self._last_button) or \ 
    297300                (event_time > self._last_time + self.dclick_threshhold): 
     
    301304        self._last_button = event.button 
    302305        self._last_time = event_time 
    303          
     306 
    304307        # If an artist is already dragging, feed any additional button 
    305308        # presses to that artist. 
     
    311314        else: 
    312315            found = self._find_current(event) 
    313         #print "button %d pressed"%event.button 
     316        # print "button %d pressed"%event.button 
    314317        # Note: it seems like if "click" returns False then hasclick should 
    315318        # not be set.  The problem is that there are two reasons it can 
     
    346349        self.trigger(self._hasclick, 'release', event) 
    347350        self._hasclick = Selection() 
    348              
     351 
    349352    def _onKey(self, event): 
    350353        """ 
     
    355358        # TODO: Can we tab between items? 
    356359        # TODO: How do unhandled events get propogated to axes, figure and 
    357         # TODO: finally to application?  Do we need to implement a full tags  
     360        # TODO: finally to application?  Do we need to implement a full tags 
    358361        # TODO: architecture a la Tk? 
    359362        # TODO: Do modifiers cause a grab?  Does the artist see the modifiers? 
     
    368371        self.trigger(found, 'key', event) 
    369372        self._haskey = found 
    370      
     373 
    371374    def _onKeyRelease(self, event): 
    372375        """ 
Note: See TracChangeset for help on using the changeset viewer.