def setup(self): self.circle1 = scene.Rect(50, 50, 50, 50) self.circle2 = scene.Rect(150, 50, 50, 50) self.circle1_layer = scene.Layer(self.circle1) circle1 = Image.new('RGBA', (101, 101)) draw1 = ImageDraw.Draw(circle1) draw1.ellipse((0, 0, 100, 100), fill=(0, 255, 0, 255)) self.circle1_layer.image = scene.load_pil_image(circle1) self.circle1_layer.animate('alpha', 0.0, duration=1.0, autoreverse=True, repeat=3) # alpha animation self.add_layer(self.circle1_layer) # touch handling self.circle2_layer = scene.Layer(self.circle2) circle2 = Image.new('RGBA', (101, 101)) draw2 = ImageDraw.Draw(circle2) draw2.ellipse((0, 0, 100, 100), fill=(255, 0, 0, 255)) self.circle2_layer.image = scene.load_pil_image(circle2) self.circle2_layer.animate('scale_x', 2.0, duration=1.0, autoreverse=True, repeat=sys.maxint) # alpha animation self.circle2_layer.animate('scale_y', 2.0, duration=1.0, autoreverse=True, repeat=sys.maxint) # alpha animation
def setup(self): self.button_dict = collections.OrderedDict([ ('+', self.increase_font_size), ('—', self.decrease_font_size), ('Font', self.next_font), ('Color', self.next_color), ('Save', self.save_image), ('Cancel', self.cancel) ]) fgColor = scene.Color(*color('black')) bgColor = scene.Color(*color('grey')) loc = [0, 0] for button_text in self.button_dict: if button_text == '+': button_text = ' + ' # double spaces around '+' else: # single space around others button_text = ' ' + button_text + ' ' theButton = TextButton(self, loc, button_text, fgColor, bgColor) self.btn_height = max(self.btn_height, theButton.frame.h) loc[0] += theButton.frame.w + 4 # 4 pixels between each button self.picratio = self.picsize.w / (self.picsize.h * 1.0) usable_space = self.bounds.h - self.btn_height x = usable_space * self.picratio if x <= self.bounds.w: y = usable_space else: x = self.bounds.w y = self.bounds.w / self.picratio self.position = scene.Size(x / 2, y / 2) # no ...y/2+self.btn_height self.picscale = self.picsize[0] / (x * 1.0) self.layer = scene.Layer(scene.Rect(0, self.btn_height, x, y)) self.layer.image = scene.load_pil_image(self.img) self.add_layer(self.layer)
def makeBgImage(inFillColor = fillColorBlue, inText = 'Blue'): img = Image.new("RGBA", (300, 300)) with drawingContext(img) as draw: draw.ellipse((0,0,200,200), fill=inFillColor) draw.text((65, 85), inText, fill=fillColorLtGrey, font=theFont) return scene.load_pil_image(img)
def setup(self): self.button_dict = collections.OrderedDict([ ('+', self.increase_font_size), ('—', self.decrease_font_size), ('Font', self.next_font), ('Color', self.next_color), ('Save', self.save_image), ('Cancel', self.cancel) ]) fgColor = scene.Color(*color('black')) bgColor = scene.Color(*color('grey')) loc = [0, 0] for button_text in self.button_dict: if button_text == '+': button_text = ' + ' # double spaces around '+' else: # single space around others button_text = ' ' + button_text + ' ' theButton = TextButton(self, loc, button_text, fgColor, bgColor) self.btn_height = max(self.btn_height, theButton.frame.h) loc[0] += theButton.frame.w + 4 # 4 pixels between each button self.picratio = self.picsize.w / (self.picsize.h * 1.0) usable_space = self.bounds.h - self.btn_height x = usable_space * self.picratio if x <= self.bounds.w: y = usable_space else: x = self.bounds.w y = self.bounds.w / self.picratio self.position = scene.Size(x/2, y/2) # no ...y/2+self.btn_height self.picscale = self.picsize[0] / (x * 1.0) self.layer = scene.Layer(scene.Rect(0, self.btn_height, x, y)) self.layer.image = scene.load_pil_image(self.img) self.add_layer(self.layer)
def setup(self): self.button_dict = collections.OrderedDict([ ('+', self.increase_font_size), ('-', self.decrease_font_size), ('Font', self.next_font), ('Color', self.next_color), ('Save', self.save_image), ('Cancel', self.cancel) ]) fgColor = scene.Color(*color('blue')) bgColor = scene.Color(*color('grey')) loc = [0, 0] for button_text in self.button_dict: theButton = TextButton(self, loc, button_text, fgColor, bgColor) self.btn_height = max(self.btn_height, theButton.frame.h) loc[0] += theButton.frame.w + 4 # 4 pixels between each button self.picratio = self.picsize.w / (self.picsize.h * 1.0) x = 668 * self.picratio # where does 668 come from? should it be a constant? if x <= 1024: # where does 1024 come from? should it be a constant? y = 668 self.picborder = scene.Rect(x, self.btn_height, 1024, y) else: x = 1024 y = 1024 / self.picratio self.picborder = scene.Rect(0, y+self.btn_height, x, 668-y) self.position = scene.Size(x/2, y/2+self.btn_height) self.picscale = self.picsize[0] / (x * 1.0) self.layer = scene.Layer(scene.Rect(0, self.btn_height, x, y)) self.layer.image = scene.load_pil_image(self.img) self.add_layer(self.layer)
def __init__(self, path): try: self.__image = PILImage.open(system.getSystemPath(path)) self.__image.save(path + ".png") self.__surface = scene.load_pil_image(self.__image) except IOError: raise error.ImageNotFoundError(path)
def oldMakeBgImage(inFillColor = fillColorBlue, inText = 'Blue'): img = Image.new("RGBA", (300,300)) draw = ImageDraw.Draw(img) draw.ellipse((0,0,200,200), fill=inFillColor) draw.text((65, 85), inText, fill=fillColorLtGrey, font=theFont) del draw return scene.load_pil_image(img)
def slice_image_into_tiles(in_image, img_count_h, img_count_v=1): w, h = in_image.size # get the size of the big image w /= img_count_h # calculate the size of smaller images h /= img_count_v return [ load_pil_image(in_image.crop((x * w, y * h, (x + 1) * w, (y + 1) * h))) for y in range(img_count_v) for x in range(img_count_h) ]
def get_images_from_zip_file(file_name, directory, starts_with): with open(file_name) as in_file: starts_with = directory + '/' + starts_with zip_file = zipfile.ZipFile(in_file) return [ load_pil_image( Image.open(cStringIO.StringIO(zip_file.open(name).read()))) for name in zip_file.namelist() if name.startswith(starts_with) ]
def __init__(self, rect=Rect(), parent=None): cloud_image = self.cloud_maker() new_rect = pil_rect_to_scene_rect(cloud_image.getbbox()) rect.w, rect.h = new_rect.w, new_rect.h super(self.__class__, self).__init__(rect, parent, load_pil_image(cloud_image)) self.velocity.x = random.randint(-1, 4) # give clouds a 2-in-6 chance to be moving if self.velocity.x > 1: self.velocity.x = 0 self.velocity.x *= 50
def setup(self): self.circle1 = scene.Rect(50,50,50,50) self.circle2 = scene.Rect(150,50,50,50) self.circle1_layer = scene.Layer(self.circle1) circle1 = Image.new('RGBA', (101,101)) draw1 = ImageDraw.Draw(circle1) draw1.ellipse((0,0,100,100),fill=(0,255,0,255)) self.circle1_layer.image = scene.load_pil_image(circle1) self.circle1_layer.animate('alpha', 0.0, duration=1.0, autoreverse=True, repeat=3) # alpha animation self.add_layer(self.circle1_layer) # touch handling self.circle2_layer = scene.Layer(self.circle2) circle2 = Image.new('RGBA', (101,101)) draw2 = ImageDraw.Draw(circle2) draw2.ellipse((0,0,100,100),fill=(255,0,0,255)) self.circle2_layer.image = scene.load_pil_image(circle2) self.circle2_layer.animate('scale_x', 2.0, duration=1.0, autoreverse=True, repeat=sys.maxint) # alpha animation self.circle2_layer.animate('scale_y', 2.0, duration=1.0, autoreverse=True, repeat=sys.maxint) # alpha animation
def __init__(self, rect=Rect(), parent=None): cloud_image = self.cloud_maker() new_rect = pil_rect_to_scene_rect(cloud_image.getbbox()) rect.w, rect.h = new_rect.w, new_rect.h super(self.__class__, self).__init__(rect, parent, load_pil_image(cloud_image)) self.velocity.x = random.randint( -1, 4) # give clouds a 2-in-6 chance to be moving if self.velocity.x > 1: self.velocity.x = 0 self.velocity.x *= 50
def on_next(self,button): if(len(self.selected) != 0 and self.answered): # don't advance if answer wasn't displayed dir_index = random.randint(0,len(self.selected)-1) # random chapter dirname = self.chap_list[self.selected[dir_index]] (path, image_list, image_pointer_list, image_pointer_index) = self.chap_dict[dirname] try: imagename = image_list[image_pointer_list[image_pointer_index]] except: image_pointer_index = 0 random.shuffle(image_pointer_list) imagename = image_list[image_pointer_list[0]] image_pointer_index += 1 self.chap_dict[dirname] = (path, image_list, image_pointer_list, image_pointer_index) fullname = os.path.join(path,imagename) (self.basename,ext) = os.path.splitext(imagename) pil_img = Image.open(fullname).convert('RGBA') (W,H) = pil_img.size if W > H: NewW = self.PhotoMaxSize NewH = self.PhotoMaxSize * H / W else: NewH = self.PhotoMaxSize NewW = self.PhotoMaxSize * W / H self.current_image_size = (NewW, NewH) pil_img = pil_img.resize(self.current_image_size) self.image_name = scene.load_pil_image(pil_img) self.currentMode = self.mode if (self.currentMode == "RANDOM"): self.currentMode = ("IMAGE","TEXT")[random.randint(0,1)] if (self.currentMode == "TEXT" or self.currentMode == "BOTH"): self.text_comp.set_text(self.basename) id, size = render_text(self.text_comp._text) self.text_comp.bounds.x = (510 - size[0])/2 self.text_comp.bounds.y = (100 - size[1])/2 else: self.text_comp.set_text(" ") if (self.currentMode == "IMAGE" or self.currentMode == "BOTH"): self.img_comp.set_image(self.image_name,Size(NewW, NewH)) else: self.img_comp.set_image(self.blank_image_name,Size(self.PhotoMaxSize,self.PhotoMaxSize)) if self.currentMode == "BOTH": self.answered = True else: self.answered = False
def __init__(self, screen, w, h): self.size = scene.Size(w, h) w, h = (screen.w / w, screen.h / h) self.cells = {(x, y): Cell(x, y, scene.Rect(x * w, y * h, w, h)) for x in xrange(self.size.w) for y in xrange(self.size.h)} grid_img = Image.new('RGBA', [int(i) for i in screen.as_tuple()]) grid_draw = ImageDraw.Draw(grid_img) for x in xrange(self.size.w): grid_draw.line((x * w, 0, x * w, screen.h)) x = self.size.w grid_draw.line((x * w - 1, 0, x * w - 1, screen.h)) for y in xrange(self.size.h): grid_draw.line((0, y * h, screen.w, y * h)) y = self.size.h grid_draw.line((0, y * h - 1, screen.w, y * h - 1)) self.grid_img = scene.load_pil_image(grid_img) del grid_img, grid_draw
def __init__(self, screen, w, h): self.size = scene.Size(w, h) w, h = (screen.w/w, screen.h/h) self.cells = { (x, y) : Cell(x, y, scene.Rect(x*w, y*h, w, h)) for x in xrange(self.size.w) for y in xrange(self.size.h) } grid_img = Image.new('RGBA', [int(i) for i in screen.as_tuple()]) grid_draw = ImageDraw.Draw(grid_img) for x in xrange(self.size.w): grid_draw.line((x*w, 0, x*w, screen.h)) x = self.size.w grid_draw.line((x*w-1, 0, x*w-1, screen.h)) for y in xrange(self.size.h): grid_draw.line((0, y*h, screen.w, y*h)) y = self.size.h grid_draw.line((0, y*h-1, screen.w, y*h-1)) self.grid_img = scene.load_pil_image(grid_img) del grid_img, grid_draw
def setup(self): self.chap_list = chapter_names_list self.chap_dict = chapter_dir_dict self.selected = [] # which chapters to display self.chapter_switches = [] # all chapter switches (in alpahetical order) self.mode = "IMAGE" # how to display, "IMAGE" is default self.currentMode = "IMAGE" self.mode_switches = [] # allows to manipulate switches as a radio button group self.PhotoMaxSize = 500 # photo size self.img_comp = None # placeholder for global image self.blank_image = Image.new("RGBA", (500, 500), "white") self.blank_image_name = scene.load_pil_image(self.blank_image) # blank image name self.text_comp = None # ditto self.add_local_laf() self.image_window = self.add_image_window() self.label = self.add_label() self.chapter_switch_group = self.add_chapter_switch_group() self.mode_switch_group = self.add_mode_switch_group() self.button_group = self.add_button_group() self.answered = True
def get_images_from_zip_file(file_name, directory, starts_with): with open(file_name) as in_file: starts_with = directory + '/' + starts_with zip_file = zipfile.ZipFile(in_file) return [load_pil_image(Image.open(cStringIO.StringIO(zip_file.open(name).read()))) for name in zip_file.namelist() if name.startswith(starts_with)]
def slice_image_into_tiles(in_image, img_count_h, img_count_v=1): w, h = in_image.size # get the size of the big image w /= img_count_h # calculate the size of smaller images h /= img_count_v return [load_pil_image(in_image.crop((x * w, y * h, (x + 1) * w, (y + 1) * h))) for y in range(img_count_v) for x in range(img_count_h)]
def get_random_photo( ): # returns the name (a string) of a random photo from the camera role return scene.load_pil_image( photos.get_fullscreen_image(random.randint(0, photo_count)))
def setup(self): self.layer = scene.Layer(self.bounds) self.layer.image = scene.load_pil_image(self.img) self.add_layer(self.layer)
def __init__(self): theImage = diagonalLineImage() theRect = scene.Rect(0, 0, *theImage.size) super(self.__class__, self).__init__(theRect) self.image = scene.load_pil_image(theImage)
def __init__(self, parent=None): cloud_image = cloud_maker() super(self.__class__, self).__init__(scene.Rect(*cloud_image.getbbox())) if parent: parent.add_layer(self) self.image = scene.load_pil_image(cloud_image)
def setup(self): w, h = self.picsize self.textPosition = scene.Size(w/2/self.scale, h/2/self.scale) self.layer = scene.Layer(scene.Rect(0, 0, w/2, h/2)) self.layer.image = scene.load_pil_image(self.img) self.add_layer(self.layer)
def get_random_photo(): # returns the name (a string) of a random photo from the camera role return scene.load_pil_image(photos.get_fullscreen_image(random.randint(0, photo_count)))