Ignore:
Timestamp:
11/12/12 20:04:40 (17 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Added link AnchorLayout class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/canvas/items/utils.py

    r11172 r11180  
    11import numpy 
    22 
    3 from PyQt4.QtGui import QColor, QRadialGradient, QGraphicsItem 
     3import sip 
     4 
     5from PyQt4.QtGui import QColor, QRadialGradient 
     6from PyQt4.QtCore import QObject, QSignalMapper 
     7from PyQt4.QtCore import pyqtSignal as Signal 
    48 
    59 
     
    5458    obj = item.toGraphicsObject() 
    5559    return item if obj is None else obj 
     60 
     61 
     62def typed_signal_mapper(pyType): 
     63    """Create a TypedSignalMapper class supporting signal 
     64    mapping for `pyType` (the default QSigalMapper only supports 
     65    int, string, QObject and QWidget (but not for instance QGraphicsItem). 
     66 
     67    """ 
     68 
     69    def unwrap(obj): 
     70        return sip.unwrapinstance(sip.cast(obj, QObject)) 
     71 
     72    class TypedSignalMapper(QSignalMapper): 
     73        pyMapped = Signal(pyType) 
     74 
     75        def __init__(self, parent=None): 
     76            QSignalMapper.__init__(self, parent) 
     77            self.__mapping = {} 
     78 
     79        def setPyMapping(self, sender, mapped): 
     80            sender_id = unwrap(sender) 
     81            self.__mapping[sender_id] = mapped 
     82            sender.destroyed.connect(self.removePyMappings) 
     83 
     84        def removePyMappings(self, sender): 
     85            sender_id = unwrap(sender) 
     86            del self.__mapping[sender_id] 
     87            sender.destroyed.disconnect(self.removePyMappings) 
     88 
     89        def pyMap(self, sender=None): 
     90            if sender is None: 
     91                sender = self.sender() 
     92 
     93            sender_id = unwrap(sender) 
     94            mapped = self.__mapping[sender_id] 
     95            self.pyMapped.emit(mapped) 
     96 
     97    return TypedSignalMapper 
Note: See TracChangeset for help on using the changeset viewer.