Created
May 14, 2016 11:52
-
-
Save mhanoglu/00fcdbf07c60dd80016240f09766ccfc to your computer and use it in GitHub Desktop.
imagecrop for symbianOS 2nd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf8 -*- | |
''' Project Name : Image_Crop v1.0 | |
Copyright : www.python-s60.com | |
Author: MaRZoCHi (Mehmet Hanoğlu) | |
License : GNU Lisans | |
Date : 27.04.2011 | |
Description : Açık Kaynaklı Proje.İsteyenler Geliştirebilir. | |
''' | |
from appuifw import app,Canvas | |
from e32 import Ao_lock,ao_sleep,ao_yield | |
from graphics import Image | |
from time import clock | |
from TopWindow import TopWindow | |
from sysinfo import display_pixels | |
def tr(t) : return t.decode('utf-8') | |
path = app.full_name()[0]+":\\System\\Apps\\Image_Crop\\" | |
fonts = [u'dense',u'legend',u'mini'] | |
lock = Ao_lock() | |
_DEBUG = "off" | |
w,h = display_pixels() | |
del display_pixels | |
w_time,quality = 2.0, 'L' | |
window = TopWindow() | |
window.corner_type = 'corner2' | |
class Animation: | |
def __init__(s,body,image_number,delay,pos,spin,image_path,tpos,ttext,tcol): | |
body.text(tpos, ttext, tcol, font = u'title') | |
image = Image.open(image_path) | |
size = image.size;simg = (size[0]/image_number,size[1]) | |
anim = Image.new(simg) | |
for a in range(spin): | |
for x in range(simg[0]): | |
anim.blit(image, target = (0,0),source =((x*simg[0],0),(simg[0]*(1+x),simg[1]))) | |
body.blit(anim,target=pos) | |
ao_sleep(delay) | |
del anim,simg,image,size,tpos,ttext,tcol | |
class Key_Control(object): | |
def __init__(self,):pass | |
def c_quality(self,): | |
global quality | |
if quality == 'L' : quality = 'H' | |
elif quality == 'H' : quality = 'L' | |
def c_color(self,): | |
global col,colors | |
if col == colors[0] : col = colors[1] | |
elif col == colors[1] : col = colors[0] | |
def sense_sqr(self,type): | |
global sens_sqr | |
if type == 'mins' and sens_sqr >= 2 : sens_sqr -= 1 | |
elif type == 'pluss' : sens_sqr += 1 | |
def sense_scale(self,type): | |
global sens_save | |
if type == 'minq' and sens_save >= 2 : sens_save -= 1 | |
elif type == 'plusq' : sens_save += 1 | |
def scale_sqr(self,type): | |
global sx,sy,bx,by,size_sqr,sens_save,rszd_img | |
if type == 'largex' : | |
if (size_sqr[0] + sens_save) + sx <= rszd_img.size[0] : | |
size_sqr = ((size_sqr[0] + sens_save), size_sqr[1]) | |
else : | |
size_sqr = (rszd_img.size[0]-sx+bx, size_sqr[1]) | |
elif type == 'smallx' : | |
if size_sqr[0] > sens_save : | |
size_sqr = ((size_sqr[0] - sens_save), size_sqr[1]) | |
elif type == 'largey' : | |
if (size_sqr[1] + sens_save + sy) <= rszd_img.size[1] + by: | |
size_sqr = (size_sqr[0], (sens_save + size_sqr[1])) | |
else : | |
size_sqr = (size_sqr[0],rszd_img.size[1]-sy+by) | |
elif type == 'smally' : | |
if size_sqr[1] > sens_save : | |
size_sqr = (size_sqr[0], (size_sqr[1] - sens_save)) | |
def move_sqr(self,type): | |
global sx,sy,bx,by,sens_sqr,w,h | |
if type == 'up' : | |
if (sy - sens_sqr) >= by : | |
sy -= sens_sqr | |
else : | |
sy = by | |
pass | |
elif type == 'down' : | |
if (sy + size_sqr[1] + sens_sqr) <= (h - by) : | |
sy += sens_sqr | |
else : | |
sy = (((h - by) - size_sqr[1])) | |
pass | |
elif type == 'right' : | |
if (sx + size_sqr[0] + sens_sqr) <= (w - bx) : | |
sx += sens_sqr | |
else : | |
sx = ((w - bx) - size_sqr[0]) | |
pass | |
elif type == 'left' : | |
if (sx - sens_sqr) >= bx : | |
sx -= sens_sqr | |
else : | |
sx = bx | |
def get_pic(self,) : | |
pbimg = Image.new((size_sqr[0], size_sqr[1])) | |
ao_yield() | |
canvas.text((62, 13), tr('Kaydediliyor'), colors[1],font=u'dense') | |
pbimg.blit(rszd_img, target = (0, 0), source = (sx-bx, sy-by, size_sqr[0]+sx-bx, size_sqr[1]+sy-by)) | |
window.size = size_sqr | |
window.position = (((w - size_sqr[0]) / 2), ((h - size_sqr[1]) / 2)) | |
window.add_image(pbimg, (0, 0)) | |
window.show() | |
if quality == 'L' : | |
pbimg.save((((('d:\\(' + str(sx) + ',') + str((sy - by)) + ',') + str(size_sqr[0] + sx) + ',') + str((size_sqr[1] + sy - by))+')'+quality+'.png')) | |
else : | |
rbimg = Image.new((size_sqr[0]/k, size_sqr[1]/k)) | |
rbimg.blit(org_img, target = (0, 0), source = ((sx-bx)/k, (sy-by)/k, (size_sqr[0]+sx-bx)/k, (size_sqr[1]+sy-by)/k)) | |
rbimg.save((((('d:\\(' + str(sx) + ',') + str((sy - by)) + ',') + str(size_sqr[0] + sx) + ',') + str((size_sqr[1] + sy - by))+')'+quality+'.png')) | |
canvas.rectangle((60, 0, 150, 15), colors[0], fill = colors[0]) | |
ao_sleep(w_time) | |
window.hide() | |
key = Key_Control() | |
class Control(object): | |
__module__ = __name__ | |
def __init__(self): | |
self.key_tbuff = 0 | |
self.keys_active = 1 | |
self.delay = 0.05 | |
self.keys = { 14:['left',1,self.key_left], | |
15:['right',1,self.key_right], | |
16:['up',3,self.key_up], | |
17:['down',3,self.key_down], | |
127:['sharp',3,self.key_sharp], | |
42:['star',3,self.key_star], | |
54:['left-mkey',3,self.key_lkey], | |
167:['select',3,self.key_select], | |
165:['right-mkey',3,self.key_rkey], | |
48:['0',3,self.key_0], | |
49:['1',3,self.key_1], | |
50:['2',3,self.key_2], | |
51:['3',3,self.key_3], | |
52:['4',3,self.key_4], | |
54:['6',3,self.key_6], | |
55:['7',3,self.key_7], | |
56:['8',3,self.key_8], | |
57:['9',3,self.key_9], | |
1:['clear-key',3,self.key_ckey],} | |
def key(self,keycode): | |
if (keycode['scancode'] in self.keys.keys()) and (keycode['type'] == self.keys[keycode['scancode']][1]) and self.keys_active : | |
if _DEBUG == "on" : print self.keys[keycode['scancode']][0] | |
self.keys[keycode['scancode']][2]() | |
if keycode['scancode'] not in [1,165] : ReDraw_Utils() | |
else : pass | |
else : pass | |
def redraw(self,x) : pass | |
def key_left(self,) : key.move_sqr('left') | |
def key_right(self,) : key.move_sqr('right') | |
def key_up(self,) : key.move_sqr('up') | |
def key_down(self,) : key.move_sqr('down') | |
def key_lkey(self,) : pass | |
def key_ckey(self,) : Del_Body() | |
def key_select(self,) : key.get_pic() | |
def key_rkey(self,) : lock.signal() | |
def key_0(self,) : key.c_color() | |
def key_1(self,) : key.scale_sqr('smallx') | |
def key_2(self,) : key.sense_sqr('pluss') | |
def key_3(self,) : key.scale_sqr('largex') | |
def key_4(self,) : key.sense_scale('minq') | |
def key_6(self,) : key.sense_scale('plusq') | |
def key_7(self,) : key.scale_sqr('smally') | |
def key_8(self,) : key.sense_sqr('mins') | |
def key_9(self,) : key.scale_sqr('largey') | |
def key_star(self,) : key.c_quality() | |
def key_sharp(self,) : pass | |
control = Control() | |
def main(): | |
from fy_manager import Manager | |
global org_img,rszd_img,colors,bx,by,col,sens_sqr,sens_save,size_sqr,sx,sy,k | |
_file = Manager().AskUser('e:\\', ext = ['.png', '.jpg', '.bmp']) | |
if _file : | |
img = Image.open(_file) | |
_tcolor = img.getpixel([(0,0),(1,1),(2,2),(3,3),(4,4),(5,5)]) | |
_tcnum = 0 | |
for j in _tcolor : | |
if j < (128,128,128) : _tcnum += 1 | |
if len(_tcolor)/2 >= _tcnum : colors = [0x0,0xffffff] | |
else : colors = [0xffffff,0x0] | |
canvas.clear(colors[0]) | |
col = colors[0] | |
Animation( | |
canvas,12,0.03,(36,89),3,path+str(colors[0])+".png", | |
(54, 100), tr('Yükleniyor...'),colors[1]) | |
sens_sqr, sens_save, size_sqr = 10, 10, (50, 50) | |
del Manager,_file,_tcolor,_tcnum | |
org_img = img | |
rszd_img = img.resize((w, h), keepaspect = 1) | |
bx, by = ((w - rszd_img.size[0])/2, (h - rszd_img.size[1])/2) | |
sx, sy = (bx, by) | |
k = min([(w/(org_img.size[0]/1.0)),(h/(org_img.size[1]/1.0))]) | |
control.keys_active = 1 | |
Set_Body(rszd_img) | |
Draw_Utils() | |
else : No_Image() | |
def Set_Body(img) : | |
canvas.blit(img,target=(bx,by)) | |
def Draw_Utils() : | |
canvas.clear(colors[0]) | |
canvas.blit(rszd_img, target = (bx, by)) | |
canvas.text((5, 13), ((str(sens_sqr).decode('u8') + tr('-')) + str(sens_save).decode('u8')), colors[1]) | |
canvas.text((162, 13), tr(quality), colors[1]) | |
canvas.rectangle((sx, sy, (size_sqr[0] + sx), (size_sqr[1] + sy)), outline = colors[0]) | |
def ReDraw_Utils() : | |
ao_yield() | |
canvas.blit(rszd_img, target = (bx, by)) | |
canvas.rectangle((0, 0, w, 15), colors[0], fill = colors[0]) | |
canvas.text((5, 13), ((str(sens_sqr).decode('u8') + tr('-')) + str(sens_save).decode('u8')), colors[1]) | |
canvas.text((162, 13), tr(quality), colors[1]) | |
canvas.rectangle((sx, sy, (size_sqr[0] + sx), (size_sqr[1] + sy)), outline = col) | |
canvas.blit(rszd_img, target = (bx, by)) | |
canvas.rectangle((0, 0, w, 15), colors[0], fill = colors[0]) | |
canvas.text((5, 13), ((str(sens_sqr).decode('u8') + tr('-')) + str(sens_save).decode('u8')), colors[1]) | |
canvas.text((162, 13), tr(quality), colors[1]) | |
canvas.rectangle((sx, sy, (size_sqr[0] + sx), (size_sqr[1] + sy)), outline = col) | |
ao_yield() | |
def Del_Body() : | |
global org_img,rszd_img,colors,bx,by,col,sens_sqr,sens_save,size_sqr,sx,sy,k | |
canvas.clear(colors[0]) | |
Animation( | |
canvas,12,0.03,(16,19),4,path+str(colors[0])+".png", | |
(34, 30), tr('Veriler Siliniyor...'),colors[1]) | |
control.keys_active = 0 | |
del org_img,rszd_img,bx,by,col,sens_sqr,sens_save,size_sqr,sx,sy,k | |
canvas.clear(colors[0]) | |
del colors | |
main() | |
def No_Image() : | |
canvas.clear(0x0) | |
canvas.text((15,86),tr('Resim Seçilmedi !'),0xFF0000) | |
canvas.text((150,200),tr('Çıkış'),0xDD0000) | |
control.keys_active = 0 | |
def exit(): | |
lock.signal() | |
app.set_exit() | |
app.screen='full' | |
app.body = canvas = Canvas(redraw_callback = control.redraw, event_callback = control.key) | |
app.exit_key_handler = exit | |
main() | |
lock.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment