CraftLaunch APIリファレンス

clnch_plane3x3.py

00001 import Image
00002 import cterm
00003 
00004 class Plane3x3:
00005 
00006     def __init__( self, window, imgfile, priority=2 ):
00007 
00008         pil_img = Image.open( imgfile )
00009         pil_img = pil_img.convert( "RGBA" )
00010 
00011         self.img = [ [None,None,None], [None,None,None], [None,None,None] ]
00012         self.plane = [ [None,None,None], [None,None,None], [None,None,None] ]
00013 
00014         frame_width = pil_img.size[0] / 3
00015         frame_height = pil_img.size[1] / 3
00016         center_width = pil_img.size[0]-frame_width*2
00017         center_height = pil_img.size[1]-frame_height*2
00018 
00019         #print pil_img.size, frame_width, frame_height, center_width, center_height
00020 
00021         self.frame_width = frame_width
00022         self.frame_height = frame_height
00023         self.center_width = center_width
00024         self.center_height = center_height
00025 
00026         def crop( y, x, rect ):
00027             crop_img = pil_img.crop( rect )
00028             self.img[y][x] = cterm.Image.fromString( crop_img.size, crop_img.tostring(), (0,0,0) )
00029             self.plane[y][x] = cterm.Plane( window, (0,0), (1,1), priority )
00030             self.plane[y][x].setImage(self.img[y][x])
00031             #print y,x, self.plane[y][x]
00032 
00033         crop( 0, 0, ( 0,                        0,                          frame_width,                frame_height ) )
00034         crop( 0, 1, ( frame_width,              0,                          frame_width+center_width,   frame_height ) )
00035         crop( 0, 2, ( frame_width+center_width, 0,                          frame_width*2+center_width, frame_height ) )
00036 
00037         crop( 1, 0, ( 0,                        frame_height,               frame_width,                frame_height+center_height ) )
00038         crop( 1, 1, ( frame_width,              frame_height,               frame_width+center_width,   frame_height+center_height ) )
00039         crop( 1, 2, ( frame_width+center_width, frame_height,               frame_width*2+center_width, frame_height+center_height ) )
00040 
00041         crop( 2, 0, ( 0,                        frame_height+center_height, frame_width,                frame_height*2+center_height ) )
00042         crop( 2, 1, ( frame_width,              frame_height+center_height, frame_width+center_width,   frame_height*2+center_height ) )
00043         crop( 2, 2, ( frame_width+center_width, frame_height+center_height, frame_width*2+center_width, frame_height*2+center_height ) )
00044 
00045         #print self.plane
00046 
00047     def destroy(self):
00048         self.plane[0][0].destroy()
00049         self.plane[0][1].destroy()
00050         self.plane[0][2].destroy()
00051         self.plane[1][0].destroy()
00052         self.plane[1][1].destroy()
00053         self.plane[1][2].destroy()
00054         self.plane[2][0].destroy()
00055         self.plane[2][1].destroy()
00056         self.plane[2][2].destroy()
00057 
00058     def adjust( self, rect ):
00059 
00060         if (rect[2]-rect[0]) > self.frame_width*2+self.center_width:
00061             plane_frame_width = self.frame_width
00062         else:
00063             plane_frame_width = (rect[2]-rect[0])/3
00064         plane_center_width = (rect[2]-rect[0])-plane_frame_width*2
00065 
00066         if (rect[3]-rect[1]) > self.frame_height*2+self.center_height:
00067             plane_frame_height = self.frame_height
00068         else:
00069             plane_frame_height = (rect[3]-rect[1])/3
00070         plane_center_height = (rect[3]-rect[1])-plane_frame_height*2
00071 
00072 
00073         self.plane[0][0].setPos( (rect[0],rect[1]) )
00074         self.plane[0][0].setSize( (plane_frame_width,plane_frame_height) )
00075 
00076         self.plane[0][1].setPos( (rect[0]+plane_frame_width,rect[1]) )
00077         self.plane[0][1].setSize( (plane_center_width,plane_frame_height) )
00078 
00079         self.plane[0][2].setPos( (rect[0]+plane_frame_width+plane_center_width,rect[1]) )
00080         self.plane[0][2].setSize( (plane_frame_width,plane_frame_height) )
00081 
00082 
00083         self.plane[1][0].setPos( (rect[0],rect[1]+plane_frame_height) )
00084         self.plane[1][0].setSize( (plane_frame_width,plane_center_height) )
00085 
00086         self.plane[1][1].setPos( (rect[0]+plane_frame_width,rect[1]+plane_frame_height) )
00087         self.plane[1][1].setSize( (plane_center_width,plane_center_height) )
00088 
00089         self.plane[1][2].setPos( (rect[0]+plane_frame_width+plane_center_width,rect[1]+plane_frame_height) )
00090         self.plane[1][2].setSize( (plane_frame_width,plane_center_height) )
00091 
00092 
00093         self.plane[2][0].setPos( (rect[0],rect[1]+plane_frame_height+plane_center_height) )
00094         self.plane[2][0].setSize( (plane_frame_width,plane_frame_height) )
00095 
00096         self.plane[2][1].setPos( (rect[0]+plane_frame_width,rect[1]+plane_frame_height+plane_center_height) )
00097         self.plane[2][1].setSize( (plane_center_width,plane_frame_height) )
00098 
00099         self.plane[2][2].setPos( (rect[0]+plane_frame_width+plane_center_width,rect[1]+plane_frame_height+plane_center_height) )
00100         self.plane[2][2].setSize( (plane_frame_width,plane_frame_height) )
00101 
00102     def show( self, _show ):
00103         self.plane[0][0].show( _show )
00104         self.plane[0][1].show( _show )
00105         self.plane[0][2].show( _show )
00106         self.plane[1][0].show( _show )
00107         self.plane[1][1].show( _show )
00108         self.plane[1][2].show( _show )
00109         self.plane[2][0].show( _show )
00110         self.plane[2][1].show( _show )
00111         self.plane[2][2].show( _show )

Copyright © 2009 craftware. All rights reserved.