<s> """<STR_LIT>""" <EOL> __author__ = "<STR_LIT>" <EOL> __date__ = "<STR_LIT>" <EOL> import wx <EOL> from aui_constants import * <EOL> if wx . Platform == "<STR_LIT>" : <EOL> import Carbon . Appearance <EOL> def BlendColour ( fg , bg , alpha ) : <EOL> """<STR_LIT>""" <EOL> result = bg + ( alpha * ( fg - bg ) ) <EOL> if result < <NUM_LIT:0.0> : <EOL> result = <NUM_LIT:0.0> <EOL> if result > <NUM_LIT:255> : <EOL> result = <NUM_LIT:255> <EOL> return result <EOL> def StepColour ( c , ialpha ) : <EOL> """<STR_LIT>""" <EOL> if ialpha == <NUM_LIT:100> : <EOL> return c <EOL> r , g , b = c . Red ( ) , c . Green ( ) , c . Blue ( ) <EOL> ialpha = min ( ialpha , <NUM_LIT:200> ) <EOL> ialpha = max ( ialpha , <NUM_LIT:0> ) <EOL> alpha = ( ialpha - <NUM_LIT> ) / <NUM_LIT> <EOL> if ialpha > <NUM_LIT:100> : <EOL> bg = <NUM_LIT:255> <EOL> alpha = <NUM_LIT:1.0> - alpha <EOL> else : <EOL> bg = <NUM_LIT:0> <EOL> alpha = <NUM_LIT:1.0> + alpha <EOL> r = BlendColour ( r , bg , alpha ) <EOL> g = BlendColour ( g , bg , alpha ) <EOL> b = BlendColour ( b , bg , alpha ) <EOL> return wx . Colour ( r , g , b ) <EOL> def LightContrastColour ( c ) : <EOL> """<STR_LIT>""" <EOL> amount = <NUM_LIT> <EOL> if c . Red ( ) < <NUM_LIT> and c . Green ( ) < <NUM_LIT> and c . Blue ( ) < <NUM_LIT> : <EOL> amount = <NUM_LIT> <EOL> return StepColour ( c , amount ) <EOL> def ChopText ( dc , text , max_size ) : <EOL> """<STR_LIT>""" <EOL> x , y , dummy = dc . GetMultiLineTextExtent ( text ) <EOL> if x <= max_size : <EOL> return text <EOL> textLen = len ( text ) <EOL> last_good_length = <NUM_LIT:0> <EOL> for i in xrange ( textLen , - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> s = text [ <NUM_LIT:0> : i ] <EOL> s += "<STR_LIT>" <EOL> x , y = dc . GetTextExtent ( s ) <EOL> last_good_length = i <EOL> if x < max_size : <EOL> break <EOL> ret = text [ <NUM_LIT:0> : last_good_length ] + "<STR_LIT>" <EOL> return ret <EOL> def BitmapFromBits ( bits , w , h , colour ) : <EOL> """<STR_LIT>""" <EOL> img = wx . BitmapFromBits ( bits , w , h ) . ConvertToImage ( ) <EOL> img . Replace ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> img . Replace ( <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT:255> , colour . Red ( ) , colour . Green ( ) , colour . Blue ( ) ) <EOL> img . SetMaskColour ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> return wx . BitmapFromImage ( img ) <EOL> def IndentPressedBitmap ( rect , button_state ) : <EOL> """<STR_LIT>""" <EOL> if button_state == AUI_BUTTON_STATE_PRESSED : <EOL> rect . x += <NUM_LIT:1> <EOL> rect . y += <NUM_LIT:1> <EOL> return rect <EOL> def GetBaseColour ( ) : <EOL> """<STR_LIT>""" <EOL> if wx . Platform == "<STR_LIT>" : <EOL> if hasattr ( wx , '<STR_LIT>' ) : <EOL> base_colour = wx . MacThemeColour ( Carbon . Appearance . kThemeBrushToolbarBackground ) <EOL> else : <EOL> brush = wx . Brush ( wx . BLACK ) <EOL> brush . MacSetTheme ( Carbon . Appearance . kThemeBrushToolbarBackground ) <EOL> base_colour = brush . GetColour ( ) <EOL> else : <EOL> base_colour = wx . SystemSettings . GetColour ( wx . SYS_COLOUR_3DFACE ) <EOL> if ( ( <NUM_LIT:255> - base_colour . Red ( ) ) + <EOL> ( <NUM_LIT:255> - base_colour . Green ( ) ) + <EOL> ( <NUM_LIT:255> - base_colour . Blue ( ) ) < <NUM_LIT> ) : <EOL> base_colour = StepColour ( base_colour , <NUM_LIT> ) <EOL> return base_colour <EOL> def MakeDisabledBitmap ( bitmap ) : <EOL> """<STR_LIT>""" <EOL> anImage = bitmap . ConvertToImage ( ) <EOL> factor = <NUM_LIT> <EOL> if anImage . HasMask ( ) : <EOL> maskColour = ( anImage . GetMaskRed ( ) , anImage . GetMaskGreen ( ) , anImage . GetMaskBlue ( ) ) <EOL> else : <EOL> maskColour = None <EOL> data = map ( ord , list ( anImage . GetData ( ) ) ) <EOL> for i in range ( <NUM_LIT:0> , len ( data ) , <NUM_LIT:3> ) : <EOL> pixel = ( data [ i ] , data [ i + <NUM_LIT:1> ] , data [ i + <NUM_LIT:2> ] ) <EOL> pixel = MakeGray ( pixel , factor , maskColour ) <EOL> for x in range ( <NUM_LIT:3> ) : <EOL> data [ i + x ] = pixel [ x ] <EOL> anImage . SetData ( '<STR_LIT>' . join ( map ( chr , data ) ) ) <EOL> return anImage . ConvertToBitmap ( ) <EOL> def MakeGray ( rgbTuple , factor , maskColour ) : <EOL> """<STR_LIT>""" <EOL> if rgbTuple != maskColour : <EOL> r , g , b = rgbTuple <EOL> return map ( lambda x : int ( ( <NUM_LIT> - x ) * factor ) + x , ( r , g , b ) ) <EOL> else : <EOL> return rgbTuple <EOL> def Clip ( a , b , c ) : <EOL> """<STR_LIT>""" <EOL> return ( ( a < b and [ b ] ) or [ ( a > c and [ c ] or [ a ] ) [ <NUM_LIT:0> ] ] ) [ <NUM_LIT:0> ] <EOL> def LightColour ( colour , percent ) : <EOL> """<STR_LIT>""" <EOL> end_colour = wx . WHITE <EOL> rd = end_colour . Red ( ) - colour . Red ( ) <EOL> gd = end_colour . Green ( ) - colour . Green ( ) <EOL> bd = end_colour . Blue ( ) - colour . Blue ( ) <EOL> high = <NUM_LIT:100> <EOL> i = percent <EOL> r = colour . Red ( ) + ( ( i * rd * <NUM_LIT:100> ) / high ) / <NUM_LIT:100> <EOL> g = colour . Green ( ) + ( ( i * gd * <NUM_LIT:100> ) / high ) / <NUM_LIT:100> <EOL> b = colour . Blue ( ) + ( ( i * bd * <NUM_LIT:100> ) / high ) / <NUM_LIT:100> <EOL> return wx . Colour ( r , g , b ) <EOL> def PaneCreateStippleBitmap ( ) : <EOL> """<STR_LIT>""" <EOL> data = [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> img = wx . EmptyImage ( <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> counter = <NUM_LIT:0> <EOL> for ii in xrange ( <NUM_LIT:2> ) : <EOL> for jj in xrange ( <NUM_LIT:2> ) : <EOL> img . SetRGB ( ii , jj , data [ counter ] , data [ counter + <NUM_LIT:1> ] , data [ counter + <NUM_LIT:2> ] ) <EOL> counter = counter + <NUM_LIT:3> <EOL> return img . ConvertToBitmap ( ) <EOL> def DrawMACCloseButton ( colour , backColour = None ) : <EOL> """<STR_LIT>""" <EOL> bmp = wx . EmptyBitmapRGBA ( <NUM_LIT:16> , <NUM_LIT:16> ) <EOL> dc = wx . MemoryDC ( ) <EOL> dc . SelectObject ( bmp ) <EOL> gc = wx . GraphicsContext . Create ( dc ) <EOL> gc . SetBrush ( wx . Brush ( colour ) ) <EOL> path = gc . CreatePath ( ) <EOL> path . AddCircle ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> ) <EOL> path . CloseSubpath ( ) <EOL> gc . FillPath ( path ) <EOL> path = gc . CreatePath ( ) <EOL> if backColour is not None : <EOL> pen = wx . Pen ( backColour , <NUM_LIT:2> ) <EOL> else : <EOL> pen = wx . Pen ( "<STR_LIT>" , <NUM_LIT:2> ) <EOL> pen . SetCap ( wx . CAP_BUTT ) <EOL> pen . SetJoin ( wx . JOIN_BEVEL ) <EOL> gc . SetPen ( pen ) <EOL> path . MoveToPoint ( <NUM_LIT> , <NUM_LIT:4> ) <EOL> path . AddLineToPoint ( <NUM_LIT> , <NUM_LIT:10> ) <EOL> path . MoveToPoint ( <NUM_LIT> , <NUM_LIT:10> ) <EOL> path . AddLineToPoint ( <NUM_LIT> , <NUM_LIT:4> ) <EOL> path . CloseSubpath ( ) <EOL> gc . DrawPath ( path ) <EOL> dc . SelectObject ( wx . NullBitmap ) <EOL> return bmp <EOL> def DarkenBitmap ( bmp , caption_colour , new_colour ) : <EOL> """<STR_LIT>""" <EOL> image = bmp . ConvertToImage ( ) <EOL> red = caption_colour . Red ( ) / float ( new_colour . Red ( ) ) <EOL> green = caption_colour . Green ( ) / float ( new_colour . Green ( ) ) <EOL> blue = caption_colour . Blue ( ) / float ( new_colour . Blue ( ) ) <EOL> image = image . AdjustChannels ( red , green , blue ) <EOL> return image . ConvertToBitmap ( ) <EOL> def DrawGradientRectangle ( dc , rect , start_colour , end_colour , direction , offset = <NUM_LIT:0> , length = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if direction == AUI_GRADIENT_VERTICAL : <EOL> dc . GradientFillLinear ( rect , start_colour , end_colour , wx . SOUTH ) <EOL> else : <EOL> dc . GradientFillLinear ( rect , start_colour , end_colour , wx . EAST ) <EOL> def FindFocusDescendant ( ancestor ) : <EOL> """<STR_LIT>""" <EOL> focusWin = wx . Window . FindFocus ( ) <EOL> win = focusWin <EOL> while win : <EOL> if win == ancestor : <EOL> break <EOL> else : <EOL> win = win . GetParent ( ) <EOL> if win is None : <EOL> focusWin = None <EOL> return focusWin <EOL> def GetLabelSize ( dc , label , vertical ) : <EOL> """<STR_LIT>""" <EOL> text_width = text_height = <NUM_LIT:0> <EOL> dummy , text_height = dc . GetTextExtent ( "<STR_LIT>" ) <EOL> if label . strip ( ) : <EOL> text_width , dummy = dc . GetTextExtent ( label ) <EOL> if vertical : <EOL> tmp = text_height <EOL> text_height = text_width <EOL> text_width = tmp <EOL> return wx . Size ( text_width , text_height ) <EOL> class TabDragImage ( wx . DragImage ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , notebook , page , button_state , tabArt ) : <EOL> """<STR_LIT>""" <EOL> self . _backgroundColour = wx . NamedColour ( "<STR_LIT>" ) <EOL> self . _bitmap = self . CreateBitmap ( notebook , page , button_state , tabArt ) <EOL> wx . DragImage . __init__ ( self , self . _bitmap ) <EOL> def CreateBitmap ( self , notebook , page , button_state , tabArt ) : <EOL> """<STR_LIT>""" <EOL> control = page . control <EOL> memory = wx . MemoryDC ( wx . EmptyBitmap ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> tab_size , x_extent = tabArt . GetTabSize ( memory , notebook , page . caption , page . bitmap , page . active , <EOL> button_state , control ) <EOL> tab_width , tab_height = tab_size <EOL> rect = wx . Rect ( <NUM_LIT:0> , <NUM_LIT:0> , tab_width , tab_height ) <EOL> bitmap = wx . EmptyBitmap ( tab_width + <NUM_LIT:1> , tab_height + <NUM_LIT:1> ) <EOL> memory . SelectObject ( bitmap ) <EOL> if wx . Platform == "<STR_LIT>" : <EOL> memory . SetBackground ( wx . TRANSPARENT_BRUSH ) <EOL> else : <EOL> memory . SetBackground ( wx . Brush ( self . _backgroundColour ) ) <EOL> memory . SetBackgroundMode ( wx . TRANSPARENT ) <EOL> memory . Clear ( ) <EOL> paint_control = wx . Platform != "<STR_LIT>" <EOL> tabArt . DrawTab ( memory , notebook , page , rect , button_state , paint_control = paint_control ) <EOL> memory . SetBrush ( wx . TRANSPARENT_BRUSH ) <EOL> memory . SetPen ( wx . BLACK_PEN ) <EOL> memory . DrawRoundedRectangle ( <NUM_LIT:0> , <NUM_LIT:0> , tab_width + <NUM_LIT:1> , tab_height + <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> memory . SelectObject ( wx . NullBitmap ) <EOL> if wx . Platform != '<STR_LIT>' : <EOL> timg = bitmap . ConvertToImage ( ) <EOL> if not timg . HasAlpha ( ) : <EOL> timg . InitAlpha ( ) <EOL> for y in xrange ( timg . GetHeight ( ) ) : <EOL> for x in xrange ( timg . GetWidth ( ) ) : <EOL> pix = wx . Colour ( timg . GetRed ( x , y ) , <EOL> timg . GetGreen ( x , y ) , <EOL> timg . GetBlue ( x , y ) ) <EOL> if pix == self . _backgroundColour : <EOL> timg . SetAlpha ( x , y , <NUM_LIT:0> ) <EOL> bitmap = timg . ConvertToBitmap ( ) <EOL> return bitmap <EOL> def GetDockingImage ( direction , useAero , center ) : <EOL> """<STR_LIT>""" <EOL> suffix = ( center and [ "<STR_LIT>" ] or [ "<STR_LIT>" ] ) [ <NUM_LIT:0> ] <EOL> prefix = "<STR_LIT>" <EOL> if useAero == <NUM_LIT:2> : <EOL> prefix = "<STR_LIT>" <EOL> elif useAero == <NUM_LIT:1> : <EOL> prefix = "<STR_LIT>" <EOL> if direction == wx . TOP : <EOL> bmp_unfocus = eval ( "<STR_LIT>" % ( prefix , suffix ) ) . GetBitmap ( ) <EOL> bmp_focus = eval ( "<STR_LIT>" % ( prefix , suffix ) ) . GetBitmap ( ) <EOL> elif direction == wx . BOTTOM : <EOL> bmp_unfocus = eval ( "<STR_LIT>" % ( prefix , suffix ) ) . GetBitmap ( ) <EOL> bmp_focus = eval ( "<STR_LIT>" % ( prefix , suffix ) ) . GetBitmap ( ) <EOL> elif direction == wx . LEFT : <EOL> bmp_unfocus = eval ( "<STR_LIT>" % ( prefix , suffix ) ) . GetBitmap ( ) <EOL> bmp_focus = eval ( "<STR_LIT>" % ( prefix , suffix ) ) . GetBitmap ( ) <EOL> elif direction == wx . RIGHT : <EOL> bmp_unfocus = eval ( "<STR_LIT>" % ( prefix , suffix ) ) . GetBitmap ( ) <EOL> bmp_focus = eval ( "<STR_LIT>" % ( prefix , suffix ) ) . GetBitmap ( ) <EOL> else : <EOL> bmp_unfocus = eval ( "<STR_LIT>" % ( prefix , suffix ) ) . GetBitmap ( ) <EOL> bmp_focus = eval ( "<STR_LIT>" % ( prefix , suffix ) ) . GetBitmap ( ) <EOL> return bmp_unfocus , bmp_focus <EOL> def TakeScreenShot ( rect ) : <EOL> """<STR_LIT>""" <EOL> dcScreen = wx . ScreenDC ( ) <EOL> bmp = wx . EmptyBitmap ( rect . width , rect . height ) <EOL> memDC = wx . MemoryDC ( ) <EOL> memDC . SelectObject ( bmp ) <EOL> memDC . Blit ( <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> rect . width , <EOL> rect . height , <EOL> dcScreen , <EOL> rect . x , <EOL> rect . y <EOL> ) <EOL> memDC . SelectObject ( wx . NullBitmap ) <EOL> return bmp <EOL> def RescaleScreenShot ( bmp , thumbnail_size = <NUM_LIT:200> ) : <EOL> """<STR_LIT>""" <EOL> bmpW , bmpH = bmp . GetWidth ( ) , bmp . GetHeight ( ) <EOL> img = bmp . ConvertToImage ( ) <EOL> newW , newH = bmpW , bmpH <EOL> if bmpW > bmpH : <EOL> if bmpW > thumbnail_size : <EOL> ratio = bmpW / float ( thumbnail_size ) <EOL> newW , newH = int ( bmpW / ratio ) , int ( bmpH / ratio ) <EOL> img . Rescale ( newW , newH , wx . IMAGE_QUALITY_HIGH ) <EOL> else : <EOL> if bmpH > thumbnail_size : <EOL> ratio = bmpH / float ( thumbnail_size ) <EOL> newW , newH = int ( bmpW / ratio ) , int ( bmpH / ratio ) <EOL> img . Rescale ( newW , newH , wx . IMAGE_QUALITY_HIGH ) <EOL> newBmp = img . ConvertToBitmap ( ) <EOL> otherBmp = wx . EmptyBitmap ( newW + <NUM_LIT:5> , newH + <NUM_LIT:5> ) <EOL> memDC = wx . MemoryDC ( ) <EOL> memDC . SelectObject ( otherBmp ) <EOL> memDC . SetBackground ( wx . WHITE_BRUSH ) <EOL> memDC . Clear ( ) <EOL> memDC . SetPen ( wx . TRANSPARENT_PEN ) <EOL> pos = <NUM_LIT:0> <EOL> for i in xrange ( <NUM_LIT:5> , <NUM_LIT:0> , - <NUM_LIT:1> ) : <EOL> brush = wx . Brush ( wx . Colour ( <NUM_LIT:50> * i , <NUM_LIT:50> * i , <NUM_LIT:50> * i ) ) <EOL> memDC . SetBrush ( brush ) <EOL> memDC . DrawRoundedRectangle ( <NUM_LIT:0> , <NUM_LIT:0> , newW + <NUM_LIT:5> - pos , newH + <NUM_LIT:5> - pos , <NUM_LIT:2> ) <EOL> pos += <NUM_LIT:1> <EOL> memDC . DrawBitmap ( newBmp , <NUM_LIT:0> , <NUM_LIT:0> , True ) <EOL> memDC . SelectObject ( wx . NullBitmap ) <EOL> return otherBmp <EOL> def GetSlidingPoints ( rect , size , direction ) : <EOL> """<STR_LIT>""" <EOL> if direction == AUI_DOCK_LEFT : <EOL> startX , startY = rect . x + rect . width + <NUM_LIT:2> , rect . y <EOL> elif direction == AUI_DOCK_TOP : <EOL> startX , startY = rect . x , rect . y + rect . height + <NUM_LIT:2> <EOL> elif direction == AUI_DOCK_RIGHT : <EOL> startX , startY = rect . x - size . x - <NUM_LIT:2> , rect . y <EOL> elif direction == AUI_DOCK_BOTTOM : <EOL> startX , startY = rect . x , rect . y - size . y - <NUM_LIT:2> <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> caption_height = wx . SystemSettings . GetMetric ( wx . SYS_CAPTION_Y ) <EOL> frame_border_x = wx . SystemSettings . GetMetric ( wx . SYS_FRAMESIZE_X ) <EOL> frame_border_y = wx . SystemSettings . GetMetric ( wx . SYS_FRAMESIZE_Y ) <EOL> stopX = size . x + caption_height + frame_border_x <EOL> stopY = size . x + frame_border_y <EOL> return startX , startY , stopX , stopY <EOL> def CopyAttributes ( newArt , oldArt ) : <EOL> """<STR_LIT>""" <EOL> attrs = dir ( oldArt ) <EOL> for attr in attrs : <EOL> if attr . startswith ( "<STR_LIT:_>" ) and ( attr . endswith ( "<STR_LIT>" ) or attr . endswith ( "<STR_LIT>" ) or attr . endswith ( "<STR_LIT>" ) or attr . endswith ( "<STR_LIT>" ) or attr . endswith ( "<STR_LIT>" ) or attr . endswith ( "<STR_LIT>" ) ) : <EOL> setattr ( newArt , attr , getattr ( oldArt , attr ) ) <EOL> return newArt </s>
