<s> import sys <EOL> from atom . api import Atom , Float , Int , Str , Typed , Value , set_default <EOL> from enaml . qt . QtCore import Qt , QRect , QPoint <EOL> from enaml . qt . QtGui import QFrame , QImage , QPainter <EOL> from . import dock_resources <EOL> class QGuideRose ( QFrame ) : <EOL> """<STR_LIT>""" <EOL> class Guide ( object ) : <EOL> """<STR_LIT>""" <EOL> NoGuide = <NUM_LIT:0> <EOL> BorderNorth = <NUM_LIT:1> <EOL> BorderEast = <NUM_LIT:2> <EOL> BorderSouth = <NUM_LIT:3> <EOL> BorderWest = <NUM_LIT:4> <EOL> CompassNorth = <NUM_LIT:5> <EOL> CompassEast = <NUM_LIT:6> <EOL> CompassSouth = <NUM_LIT:7> <EOL> CompassWest = <NUM_LIT:8> <EOL> CompassCenter = <NUM_LIT:9> <EOL> CompassExNorth = <NUM_LIT:10> <EOL> CompassExEast = <NUM_LIT:11> <EOL> CompassExSouth = <NUM_LIT:12> <EOL> CompassExWest = <NUM_LIT> <EOL> SplitVertical = <NUM_LIT> <EOL> SplitHorizontal = <NUM_LIT:15> <EOL> AreaCenter = <NUM_LIT:16> <EOL> BorderExNorth = <NUM_LIT> <EOL> BorderExEast = <NUM_LIT> <EOL> BorderExSouth = <NUM_LIT> <EOL> BorderExWest = <NUM_LIT:20> <EOL> class Mode ( object ) : <EOL> """<STR_LIT>""" <EOL> NoMode = <NUM_LIT> <EOL> Border = <NUM_LIT> <EOL> Compass = <NUM_LIT> <EOL> CompassEx = <NUM_LIT> <EOL> SplitHorizontal = <NUM_LIT> <EOL> SplitVertical = <NUM_LIT> <EOL> AreaCenter = <NUM_LIT> <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( QGuideRose , self ) . __init__ ( ) <EOL> if sys . platform == '<STR_LIT>' : <EOL> self . setAttribute ( Qt . WA_MacNoShadow , True ) <EOL> flags = Qt . ToolTip <EOL> else : <EOL> flags = Qt . Tool <EOL> self . setAttribute ( Qt . WA_TranslucentBackground , True ) <EOL> flags |= Qt . WindowStaysOnTopHint | Qt . FramelessWindowHint <EOL> self . setWindowFlags ( flags ) <EOL> self . _mode = self . Mode . NoMode <EOL> self . _center_point = QPoint ( ) <EOL> self . _border_guide = BorderGuide ( ) <EOL> self . _compass_guide = CompassGuide ( ) <EOL> self . _compass_ex_guide = CompassExGuide ( ) <EOL> self . _vsplit_guide = SplitVerticalGuide ( ) <EOL> self . _hsplit_guide = SplitHorizontalGuide ( ) <EOL> self . _area_guide = AreaCenterGuide ( ) <EOL> def _layoutGuides ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _border_guide . layout ( self . rect ( ) ) <EOL> self . _compass_guide . layout ( self . _center_point ) <EOL> self . _compass_ex_guide . layout ( self . _center_point ) <EOL> self . _vsplit_guide . layout ( self . _center_point ) <EOL> self . _hsplit_guide . layout ( self . _center_point ) <EOL> self . _area_guide . layout ( self . _center_point ) <EOL> def centerPoint ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _center_point <EOL> def setCenterPoint ( self , pos ) : <EOL> """<STR_LIT>""" <EOL> if pos != self . _center_point : <EOL> self . _center_point = pos <EOL> self . _layoutGuides ( ) <EOL> self . update ( ) <EOL> def mode ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _mode <EOL> def setMode ( self , mode ) : <EOL> """<STR_LIT>""" <EOL> if mode != self . _mode : <EOL> self . _mode = mode <EOL> self . update ( ) <EOL> def mouseOver ( self , pos ) : <EOL> """<STR_LIT>""" <EOL> self . _border_guide . mouse_over ( pos ) <EOL> self . _compass_guide . mouse_over ( pos ) <EOL> self . _compass_ex_guide . mouse_over ( pos ) <EOL> self . _vsplit_guide . mouse_over ( pos ) <EOL> self . _hsplit_guide . mouse_over ( pos ) <EOL> self . _area_guide . mouse_over ( pos ) <EOL> self . update ( ) <EOL> def guideAt ( self , pos , mode = None ) : <EOL> """<STR_LIT>""" <EOL> Guide = self . Guide <EOL> Mode = self . Mode <EOL> mode = mode if mode is not None else self . _mode <EOL> if mode & Mode . Border : <EOL> g = self . _border_guide . guide_at ( pos ) <EOL> if g != Guide . NoGuide : <EOL> return g <EOL> if mode & Mode . Compass : <EOL> g = self . _compass_guide . guide_at ( pos ) <EOL> if g != Guide . NoGuide : <EOL> return g <EOL> elif mode & Mode . CompassEx : <EOL> g = self . _compass_ex_guide . guide_at ( pos ) <EOL> if g != Guide . NoGuide : <EOL> return g <EOL> elif mode & Mode . SplitHorizontal : <EOL> g = self . _hsplit_guide . guide_at ( pos ) <EOL> if g != Guide . NoGuide : <EOL> return g <EOL> elif mode & Mode . SplitVertical : <EOL> g = self . _vsplit_guide . guide_at ( pos ) <EOL> if g != Guide . NoGuide : <EOL> return g <EOL> elif mode & Mode . AreaCenter : <EOL> g = self . _area_guide . guide_at ( pos ) <EOL> if g != Guide . NoGuide : <EOL> return g <EOL> return Guide . NoGuide <EOL> def resizeEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . _layoutGuides ( ) <EOL> def paintEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> super ( QGuideRose , self ) . paintEvent ( event ) <EOL> painter = QPainter ( self ) <EOL> Mode = self . Mode <EOL> mode = self . _mode <EOL> if mode & Mode . Border : <EOL> self . _border_guide . paint ( painter ) <EOL> if mode & Mode . Compass : <EOL> self . _compass_guide . paint ( painter ) <EOL> elif mode & Mode . CompassEx : <EOL> self . _compass_ex_guide . paint ( painter ) <EOL> elif mode & Mode . SplitHorizontal : <EOL> self . _hsplit_guide . paint ( painter ) <EOL> elif mode & Mode . SplitVertical : <EOL> self . _vsplit_guide . paint ( painter ) <EOL> elif mode & Mode . AreaCenter : <EOL> self . _area_guide . paint ( painter ) <EOL> class GuideImage ( Atom ) : <EOL> """<STR_LIT>""" <EOL> TRANSPARENT = <NUM_LIT> <EOL> OPAQUE = <NUM_LIT:1.0> <EOL> image = Typed ( QImage , factory = lambda : QImage ( ) ) <EOL> rect = Typed ( QRect , factory = lambda : QRect ( ) ) <EOL> opacity = Float ( TRANSPARENT ) <EOL> _images = { } <EOL> @ classmethod <EOL> def load_image ( cls , name ) : <EOL> """<STR_LIT>""" <EOL> image = cls . _images . get ( name ) <EOL> if image is None : <EOL> image = QImage ( '<STR_LIT>' % name ) <EOL> cls . _images [ name ] = image <EOL> return image <EOL> def __init__ ( self , name ) : <EOL> """<STR_LIT>""" <EOL> self . image = self . load_image ( name ) <EOL> def opacify ( self ) : <EOL> """<STR_LIT>""" <EOL> self . opacity = self . OPAQUE <EOL> def transparentize ( self ) : <EOL> """<STR_LIT>""" <EOL> self . opacity = self . TRANSPARENT <EOL> def contains ( self , point ) : <EOL> """<STR_LIT>""" <EOL> return self . rect . contains ( point ) <EOL> def paint ( self , painter ) : <EOL> """<STR_LIT>""" <EOL> image = self . image <EOL> if image . isNull ( ) : <EOL> return <EOL> painter . save ( ) <EOL> painter . setOpacity ( self . opacity ) <EOL> painter . drawImage ( self . rect , image ) <EOL> painter . restore ( ) <EOL> class GuideHandler ( Atom ) : <EOL> """<STR_LIT>""" <EOL> _last_guide = Typed ( GuideImage ) <EOL> def iterguides ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def iterboxes ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def guide_at ( self , pos ) : <EOL> """<STR_LIT>""" <EOL> for enum , guide in self . iterguides ( ) : <EOL> if guide . contains ( pos ) : <EOL> return enum <EOL> return QGuideRose . Guide . NoGuide <EOL> def mouse_over ( self , pos ) : <EOL> """<STR_LIT>""" <EOL> for ignored , guide in self . iterguides ( ) : <EOL> if guide . contains ( pos ) : <EOL> last = self . _last_guide <EOL> if last is not None and last is not guide : <EOL> last . transparentize ( ) <EOL> guide . opacify ( ) <EOL> self . _last_guide = guide <EOL> break <EOL> else : <EOL> if self . _last_guide is not None : <EOL> self . _last_guide . transparentize ( ) <EOL> def paint ( self , painter ) : <EOL> """<STR_LIT>""" <EOL> for box in self . iterboxes ( ) : <EOL> box . paint ( painter ) <EOL> for ignored , guide in self . iterguides ( ) : <EOL> guide . paint ( painter ) <EOL> class BorderGuide ( GuideHandler ) : <EOL> """<STR_LIT>""" <EOL> _guides = Value ( factory = lambda : { <EOL> QGuideRose . Guide . BorderNorth : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . BorderExNorth : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . BorderEast : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . BorderExEast : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . BorderSouth : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . BorderExSouth : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . BorderWest : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . BorderExWest : GuideImage ( '<STR_LIT>' ) , <EOL> } ) <EOL> _boxes = Value ( factory = lambda : { <EOL> QGuideRose . Guide . BorderNorth : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . BorderEast : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . BorderSouth : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . BorderWest : GuideImage ( '<STR_LIT>' ) , <EOL> } ) <EOL> def iterguides ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _guides . iteritems ( ) <EOL> def iterboxes ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _boxes . itervalues ( ) <EOL> def layout ( self , rect ) : <EOL> """<STR_LIT>""" <EOL> boxes = self . _boxes <EOL> guides = self . _guides <EOL> w = rect . width ( ) <EOL> h = rect . height ( ) <EOL> cx = rect . left ( ) + w / <NUM_LIT:2> <EOL> cy = rect . top ( ) + h / <NUM_LIT:2> <EOL> Guide = QGuideRose . Guide <EOL> guides [ Guide . BorderNorth ] . rect = QRect ( cx - <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . BorderExNorth ] . rect = QRect ( cx - <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT:10> ) <EOL> boxes [ Guide . BorderNorth ] . rect = QRect ( cx - <NUM_LIT:20> , <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . BorderEast ] . rect = QRect ( w - <NUM_LIT> , cy - <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . BorderExEast ] . rect = QRect ( w - <NUM_LIT> , cy - <NUM_LIT:15> , <NUM_LIT:10> , <NUM_LIT> ) <EOL> boxes [ Guide . BorderEast ] . rect = QRect ( w - <NUM_LIT:50> , cy - <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . BorderSouth ] . rect = QRect ( cx - <NUM_LIT:15> , h - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . BorderExSouth ] . rect = QRect ( cx - <NUM_LIT:15> , h - <NUM_LIT> , <NUM_LIT> , <NUM_LIT:10> ) <EOL> boxes [ Guide . BorderSouth ] . rect = QRect ( cx - <NUM_LIT:20> , h - <NUM_LIT:50> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . BorderWest ] . rect = QRect ( <NUM_LIT> , cy - <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . BorderExWest ] . rect = QRect ( <NUM_LIT:15> , cy - <NUM_LIT:15> , <NUM_LIT:10> , <NUM_LIT> ) <EOL> boxes [ Guide . BorderWest ] . rect = QRect ( <NUM_LIT:10> , cy - <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> ) <EOL> class CompassGuide ( GuideHandler ) : <EOL> """<STR_LIT>""" <EOL> _guides = Value ( factory = lambda : { <EOL> QGuideRose . Guide . CompassNorth : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . CompassEast : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . CompassSouth : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . CompassWest : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . CompassCenter : GuideImage ( '<STR_LIT>' ) , <EOL> } ) <EOL> _box = Value ( factory = lambda : GuideImage ( '<STR_LIT>' ) ) <EOL> def iterguides ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _guides . iteritems ( ) <EOL> def iterboxes ( self ) : <EOL> """<STR_LIT>""" <EOL> yield self . _box <EOL> def layout ( self , pos ) : <EOL> """<STR_LIT>""" <EOL> x = pos . x ( ) <EOL> y = pos . y ( ) <EOL> Guide = QGuideRose . Guide <EOL> guides = self . _guides <EOL> guides [ Guide . CompassNorth ] . rect = QRect ( x - <NUM_LIT:15> , y - <NUM_LIT:50> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . CompassEast ] . rect = QRect ( x + <NUM_LIT:20> , y - <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . CompassSouth ] . rect = QRect ( x - <NUM_LIT:15> , y + <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . CompassWest ] . rect = QRect ( x - <NUM_LIT:50> , y - <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . CompassCenter ] . rect = QRect ( x - <NUM_LIT:15> , y - <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> ) <EOL> self . _box . rect = QRect ( x - <NUM_LIT> , y - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> class CompassExGuide ( GuideHandler ) : <EOL> """<STR_LIT>""" <EOL> _guides = Value ( factory = lambda : { <EOL> QGuideRose . Guide . CompassNorth : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . CompassEast : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . CompassSouth : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . CompassWest : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . CompassCenter : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . CompassExNorth : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . CompassExEast : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . CompassExSouth : GuideImage ( '<STR_LIT>' ) , <EOL> QGuideRose . Guide . CompassExWest : GuideImage ( '<STR_LIT>' ) , <EOL> } ) <EOL> _box = Value ( factory = lambda : GuideImage ( '<STR_LIT>' ) ) <EOL> def iterguides ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _guides . iteritems ( ) <EOL> def iterboxes ( self ) : <EOL> """<STR_LIT>""" <EOL> yield self . _box <EOL> def layout ( self , pos ) : <EOL> """<STR_LIT>""" <EOL> x = pos . x ( ) <EOL> y = pos . y ( ) <EOL> Guide = QGuideRose . Guide <EOL> guides = self . _guides <EOL> guides [ Guide . CompassNorth ] . rect = QRect ( x - <NUM_LIT:15> , y - <NUM_LIT:64> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . CompassEast ] . rect = QRect ( x + <NUM_LIT> , y - <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . CompassSouth ] . rect = QRect ( x - <NUM_LIT:15> , y + <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . CompassWest ] . rect = QRect ( x - <NUM_LIT:64> , y - <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . CompassCenter ] . rect = QRect ( x - <NUM_LIT:15> , y - <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> ) <EOL> guides [ Guide . CompassExNorth ] . rect = QRect ( x - <NUM_LIT:15> , y - <NUM_LIT> , <NUM_LIT> , <NUM_LIT:10> ) <EOL> guides [ Guide . CompassExEast ] . rect = QRect ( x + <NUM_LIT:20> , y - <NUM_LIT:15> , <NUM_LIT:10> , <NUM_LIT> ) <EOL> guides [ Guide . CompassExSouth ] . rect = QRect ( x - <NUM_LIT:15> , y + <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT:10> ) <EOL> guides [ Guide . CompassExWest ] . rect = QRect ( x - <NUM_LIT> , y - <NUM_LIT:15> , <NUM_LIT:10> , <NUM_LIT> ) <EOL> self . _box . rect = QRect ( x - <NUM_LIT> , y - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> class SingleGuide ( GuideHandler ) : <EOL> """<STR_LIT>""" <EOL> guide_enum = Int ( QGuideRose . Guide . NoGuide ) <EOL> image_name = Str ( '<STR_LIT>' ) <EOL> _box = Value ( factory = lambda : GuideImage ( '<STR_LIT>' ) ) <EOL> _guide = Typed ( GuideImage ) <EOL> def _default__guide ( self ) : <EOL> """<STR_LIT>""" <EOL> return GuideImage ( self . image_name ) <EOL> def iterguides ( self ) : <EOL> """<STR_LIT>""" <EOL> yield ( self . guide_enum , self . _guide ) <EOL> def iterboxes ( self ) : <EOL> """<STR_LIT>""" <EOL> yield self . _box <EOL> def layout ( self , pos ) : <EOL> """<STR_LIT>""" <EOL> x = pos . x ( ) <EOL> y = pos . y ( ) <EOL> self . _guide . rect = QRect ( x - <NUM_LIT:15> , y - <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> ) <EOL> self . _box . rect = QRect ( x - <NUM_LIT:20> , y - <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> ) <EOL> class SplitHorizontalGuide ( SingleGuide ) : <EOL> """<STR_LIT>""" <EOL> guide_enum = set_default ( QGuideRose . Guide . SplitHorizontal ) <EOL> image_name = set_default ( '<STR_LIT>' ) <EOL> class SplitVerticalGuide ( SingleGuide ) : <EOL> """<STR_LIT>""" <EOL> guide_enum = set_default ( QGuideRose . Guide . SplitVertical ) <EOL> image_name = set_default ( '<STR_LIT>' ) <EOL> class AreaCenterGuide ( SingleGuide ) : <EOL> """<STR_LIT>""" <EOL> guide_enum = set_default ( QGuideRose . Guide . AreaCenter ) <EOL> image_name = set_default ( '<STR_LIT>' ) </s>
