Changeset 2df0b74 in sasview for src/sas/plottools/binder.py


Ignore:
Timestamp:
Mar 5, 2015 9:17:05 AM (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:
3477478
Parents:
dca6188
Message:

pylint fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/plottools/binder.py

    r79492222 r2df0b74  
    33""" 
    44import sys 
    5  
    6  
    7 class Selection: 
     5import logging 
     6 
     7class Selection(object): 
    88    """ 
    99    Store and compare selections. 
     
    1111    # TODO: We need some way to check in prop matches, preferably 
    1212    # TODO: without imposing structure on prop. 
    13          
     13 
    1414    artist = None 
    1515    prop = {} 
    16      
     16 
    1717    def __init__(self, artist=None, prop={}): 
    1818        self.artist, self.prop = artist, self.prop 
    19          
     19 
    2020    def __eq__(self, other): 
    2121        return self.artist is other.artist 
    22      
     22 
    2323    def __ne__(self, other): 
    2424        return self.artist is not other.artist 
    25      
     25 
    2626    def __nonzero__(self): 
    2727        return self.artist is not None 
    2828 
    2929 
    30 class BindArtist: 
     30class BindArtist(object): 
    3131    """ 
    3232    """ 
     
    4141    dclick_threshhold = 0.25 
    4242    _last_button, _last_time = None, 0 
    43      
     43 
    4444    # Mouse/keyboard events we can bind to 
    4545    events = ['enter', 'leave', 'motion', 'click', 'dclick', 'drag', 'release', 
    46              'scroll', 'key', 'keyup'] 
     46              'scroll', 'key', 'keyup'] 
    4747    # TODO: Need our own event structure 
    48      
     48 
    4949    def __init__(self, figure): 
    5050        canvas = figure.canvas 
     
    6969                canvas.mpl_connect('key_release_event', self._onKeyRelease), 
    7070            ] 
    71              
     71 
    7272        self._current = None 
    7373        self._actions = {} 
     
    7575        self.figure = figure 
    7676        self.clearall() 
    77          
     77 
    7878    def clear(self, *artists): 
    7979        """ 
    8080        self.clear(h1,h2,...) 
    8181            Remove connections for artists h1, h2, ... 
    82              
     82 
    8383        Use clearall() to reset all connections. 
    8484        """ 
     
    9696        if self._haskey.artist in artists: 
    9797            self._haskey = Selection() 
    98          
     98 
    9999    def clearall(self): 
    100100        """ 
    101101        Clear connections to all artists. 
    102          
     102 
    103103        Use clear(h1,h2,...) to reset specific artists. 
    104104        """ 
     
    121121            for cid in self._connections: self.canvas.mpl_disconnect(cid) 
    122122        except: 
    123             print "Error disconnection canvas: %s" % sys.exc_value 
    124             pass 
     123            logging.error("Error disconnection canvas: %s" % sys.exc_value) 
    125124        self._connections = [] 
    126125 
     
    130129    def __call__(self, trigger, artist, action): 
    131130        """Register a callback for an artist to a particular trigger event. 
    132          
     131 
    133132        usage: 
    134133            self.connect(eventname,artist,action) 
    135      
     134 
    136135        where: 
    137136            eventname is a string 
     
    153152            key: key pressed when mouse is on the artist 
    154153            keyrelease: key released for the artist 
    155      
     154 
    156155        The event received by action has a number of attributes: 
    157156            name is the event name which was triggered 
     
    165164            details is a dictionary of artist specific details, such as the 
    166165                id(s) of the point that were clicked. 
    167                  
     166 
    168167        When receiving an event, first check the modifier state to be 
    169168        sure it applies.  E.g., the callback for 'press' might be: 
     
    203202        if action not in self.events: 
    204203            raise ValueError, "Trigger expects " + ", ".join(self.events) 
    205          
     204 
    206205        # Tag the event with modifiers 
    207206        for mod in ('alt', 'control', 'shift', 'meta'): 
     
    210209        setattr(ev, 'action', action) 
    211210        setattr(ev, 'prop', {}) 
    212          
     211 
    213212        # Fallback scheme.  If the event does not return false, pass to parent. 
    214213        processed = False 
     
    249248                found.artist, found.prop = artist, prop 
    250249                break 
    251          
     250 
    252251        # TODO: how to check if prop is equal? 
    253252        if found != self._current: 
     
    257256 
    258257        return found 
    259          
     258 
    260259    def _onMotion(self, event): 
    261260        """ 
     
    263262        other artists are invisible. 
    264263        """ 
    265         ## Can't kill double-click on motion since Windows produces 
    266         ## spurious motion events. 
    267         #self._last_button = None 
    268          
     264        # # Can't kill double-click on motion since Windows produces 
     265        # # spurious motion events. 
     266        # self._last_button = None 
     267 
    269268        # Dibs on the motion event for the clicked artist 
    270269        if self._hasclick: 
    271270            # Make sure the x,y data use the coordinate system of the 
    272271            # artist rather than the default axes coordinates. 
    273              
     272 
    274273            transform = self._hasclick.artist.get_transform() 
    275             #x,y = event.xdata,event.ydata 
     274            # x,y = event.xdata,event.ydata 
    276275            x, y = event.x, event.y 
    277276            try: 
     
    279278                    x, y = transform.inverted().transform((x, y)) 
    280279                else: 
    281                     ## For interactive plottable apply transform is not working 
    282                     ## don't know why maybe marker definition 
    283                     ##transform ="CompositeGenericTransform" crash 
     280                    # # For interactive plottable apply transform is not working 
     281                    # # don't know why maybe marker definition 
     282                    # #transform ="CompositeGenericTransform" crash 
    284283                    pass 
    285284            except: 
    286                 ## CRUFT matplotlib-0.91 support 
    287                 ## exception for transform ="CompositeGenericTransform" 
    288                 ## crashes also here 
     285                # # CRUFT matplotlib-0.91 support 
     286                # # exception for transform ="CompositeGenericTransform" 
     287                # # crashes also here 
    289288                x, y = transform.inverse_xy_tup((x, y)) 
    290289 
    291             #event.xdata, event.ydata = x, y 
     290            # event.xdata, event.ydata = x, y 
    292291            self.trigger(self._hasclick, 'drag', event) 
    293292        else: 
     
    300299        """ 
    301300        import time 
    302          
     301 
    303302        # Check for double-click 
    304303        event_time = time.time() 
     
    310309        self._last_button = event.button 
    311310        self._last_time = event_time 
    312          
     311 
    313312        # If an artist is already dragging, feed any additional button 
    314313        # presses to that artist. 
     
    320319        else: 
    321320            found = self._find_current(event) 
    322         #print "button %d pressed"%event.button 
     321        # print "button %d pressed"%event.button 
    323322        # Note: it seems like if "click" returns False then hasclick should 
    324323        # not be set.  The problem is that there are two reasons it can 
     
    355354        self.trigger(self._hasclick, 'release', event) 
    356355        self._hasclick = Selection() 
    357              
     356 
    358357    def _onKey(self, event): 
    359358        """ 
     
    377376        self.trigger(found, 'key', event) 
    378377        self._haskey = found 
    379      
     378 
    380379    def _onKeyRelease(self, event): 
    381380        """ 
     
    385384            setattr(self, event.key, False) 
    386385            return 
    387          
     386 
    388387        if self._haskey: 
    389388            self.trigger(self._haskey, 'keyup', event) 
Note: See TracChangeset for help on using the changeset viewer.