Changeset 5251ec6 in sasview for src/sas/sasgui/plottools/binder.py


Ignore:
Timestamp:
Oct 11, 2018 2:20:56 PM (6 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1249
Children:
98b9f32
Parents:
67ed543
Message:

improved support for py37 in sasgui

File:
1 edited

Legend:

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

    r20fa5fe r5251ec6  
    2828        return self.artist is not other.artist 
    2929 
    30     def __nonzero__(self): 
     30    def __bool__(self): 
    3131        return self.artist is not None 
     32 
     33    __nonzero__ = __bool__ 
    3234 
    3335 
    3436class BindArtist(object): 
    3537    """ 
     38    Track keyboard modifiers for events. 
    3639    """ 
    37     # Track keyboard modifiers for events. 
    3840    # TODO: Move keyboard modifier support into the backend.  We cannot 
    3941    # TODO: properly support it from outside the windowing system since there 
     
    6567            ] 
    6668        except: 
    67             print("bypassing scroll_event: wrong matplotlib version") 
     69            logger.warn("bypassing scroll_event: wrong matplotlib version") 
    6870            self._connections = [ 
    6971                canvas.mpl_connect('motion_notify_event', self._onMotion), 
     
    7476            ] 
    7577 
     78        # Turn off picker if it hasn't already been done 
     79        try: 
     80            canvas.mpl_disconnect(canvas.button_pick_id) 
     81            canvas.mpl_disconnect(canvas.scroll_pick_id) 
     82        except Exception as exc: 
     83            logger.error(exc) 
     84 
    7685        self._current = None 
    7786        self._actions = {} 
     
    8796        Use clearall() to reset all connections. 
    8897        """ 
    89  
    9098        for h in artists: 
    9199            for a in self.events: 
     
    123131        """ 
    124132        try: 
    125             for cid in self._connections: self.canvas.mpl_disconnect(cid) 
    126         except: 
    127             logger.error("Error disconnection canvas: %s" % sys.exc_value) 
     133            for cid in self._connections: 
     134                self.canvas.mpl_disconnect(cid) 
     135        except Exception as exc: 
     136            logger.error("Error disconnection canvas: %s" % exc) 
    128137        self._connections = [] 
    129138 
     
    172181        sure it applies.  E.g., the callback for 'press' might be: 
    173182            if event.button == 1 and event.shift: process Shift-click 
    174  
    175         TODO: Only receive events with the correct modifiers (e.g., S-click, 
    176         TODO:   or *-click for any modifiers). 
    177         TODO: Only receive button events for the correct button (e.g., click1 
    178         TODO:   release3, or dclick* for any button) 
    179         TODO: Support virtual artist, so that and artist can be flagged as 
    180         TODO:   having a tag list and receive the correct events 
    181         TODO: Support virtual events for binding to button-3 vs shift button-1 
    182         TODO:   without changing callback code 
    183         TODO: Attach multiple callbacks to the same event? 
    184         TODO: Clean up interaction with toolbar modes 
    185         TODO: push/pushclear/pop context so that binding changes for 
    186              the duration 
    187         TODO:   e.g., to support ? context sensitive help 
    188         """ 
     183        """ 
     184        #TODO: Only receive events with the correct modifiers (e.g., S-click, 
     185        #TODO:   or *-click for any modifiers). 
     186        #TODO: Only receive button events for the correct button (e.g., click1 
     187        #TODO:   release3, or dclick* for any button) 
     188        #TODO: Support virtual artist, so that and artist can be flagged as 
     189        #TODO:   having a tag list and receive the correct events 
     190        #TODO: Support virtual events for binding to button-3 vs shift button-1 
     191        #TODO:   without changing callback code 
     192        #TODO: Attach multiple callbacks to the same event? 
     193        #TODO: Clean up interaction with toolbar modes 
     194        #TODO: push/pushclear/pop context so that binding changes for the duration 
     195        #TODO:   e.g., to support ? context sensitive help 
     196 
    189197        # Check that the trigger is valid 
    190198        if trigger not in self._actions: 
    191             raise ValueError, "%s invalid --- valid triggers are %s"\ 
    192                  % (trigger, ", ".join(self.events)) 
     199            raise ValueError("%s invalid --- valid triggers are %s" 
     200                % (trigger, ", ".join(self.events))) 
    193201 
    194202        # Register the trigger callback 
     
    205213        """ 
    206214        if action not in self.events: 
    207             raise ValueError, "Trigger expects " + ", ".join(self.events) 
     215            raise ValueError("Trigger expects " + ", ".join(self.events)) 
    208216 
    209217        # Tag the event with modifiers 
     
    214222        setattr(ev, 'prop', {}) 
    215223 
    216         # Fallback scheme.  If the event does not return false, pass to parent. 
     224        # Fallback scheme. If the event does not return false, pass to parent. 
    217225        processed = False 
    218226        artist, prop = actor.artist, actor.prop 
     
    237245        """ 
    238246        # TODO: sort by zorder of axes then by zorder within axes 
    239         self._artists.sort(cmp=lambda x, y: cmp(y.zorder, x.zorder)) 
     247        self._artists.sort(key=lambda x: x.zorder, reverse=True) 
    240248        found = Selection() 
    241249        for artist in self._artists: 
     
    276284 
    277285            transform = self._hasclick.artist.get_transform() 
    278             # x,y = event.xdata,event.ydata 
     286            #x,y = event.xdata,event.ydata 
    279287            x, y = event.x, event.y 
    280288            try: 
     
    286294                    # #transform ="CompositeGenericTransform" crash 
    287295                    pass 
    288             except: 
    289                 # # CRUFT matplotlib-0.91 support 
     296            except: # CRUFT: matplotlib-0.91 support 
    290297                # # exception for transform ="CompositeGenericTransform" 
    291298                # # crashes also here 
    292299                x, y = transform.inverse_xy_tup((x, y)) 
    293300 
    294             # event.xdata, event.ydata = x, y 
     301            #TODO: why compute (x,y) if it isn't being used? 
     302            #event.xdata, event.ydata = x, y 
    295303            self.trigger(self._hasclick, 'drag', event) 
    296304        else: 
Note: See TracChangeset for help on using the changeset viewer.