2011年5月27日更新:用ubuntu 10.04以上版本的同学可以通过添加ppa:doctormo/efl源来安装最新的python-ecore和python-evas包:
https://launchpad.net/~doctormo/+archive/efl
(在10.04LTS上测试了一下似乎不好用,原因不明)
专门针对我的无穷老机写的,因为所有基于gtk或者qt的程序在这上面都启动巨慢(参见viewtopic.php?f=103&t=258661),原生的x程序display功能强大,但是打开大图片时效率奇低(比如一个2.7MB的图片需要狂读硬盘半分钟左右)。2010年4月6日更新:8楼提供了一些有用的相关开发文档
参考网上极其匮乏的python-etk文档和例子写成,基本上算是学习python和etk编程的一个作业。由于对python和etk都是初学,代码也写得很烂(以后也不打算新增功能,所以无所谓了),不过在我的无穷老机上启动迅速且运行良好,配合rox-filer之类的轻量级文件管理器或者e17默认的文件管理模块efm使用,功能也差不多够了。得益于etk强大而高效的图形库,打开上面提到的那个2.7MB的图片只需要3秒钟左右,而且显示原始尺寸并用鼠标拖动的时候非常流畅。
运行环境要求:安装python-ecore和python-evas(应该用不到python-edje和python-etk,虽然我这里都装了)。用ubuntu 8.04和8.10的可以通过添加opengeu的源(参见viewtopic.php?f=103&t=199823),用ubuntu 9.04和9.10或者其它linux发行版的可以通过添加
http://packages.enlightenment.org/
上面的源,用ubuntu 10.04的可以通过添加ppa:canola/ppa源:
代码: 全选
sudo add-apt-repository ppa:canola/ppa
热键说明:
代码: 全选
f或F——切换全屏
空格键——切换原始大小
Esc键——退出
代码: 全选
程序启动时默认打开640*480的窗口,并自动将图片调整至最适合的大小。用空格键切换到原始大小以后可以通过鼠标拖曳图片。
代码: 全选
#!/usr/bin/python
import ecore.evas
import ecore # Ecore is required to get main loop
import sys
def resize_cb(ee):
global rescaled, off_x, off_y, c_x, c_y, iw, ih
bg = ee.data["bg"]
obj = ee.data["obj"]
canvas = ee.evas
bg.size = canvas.size
if not rescaled:
x, y = canvas.rect.center
obj.center = (x+off_x, y+off_y)
else:
w, h = canvas.size
if iw*1.0/w > ih*1.0/h:
sw = w
sh = (ih*w+iw/2)/iw
else:
sw = (iw*h+ih/2)/ih
sh = h
obj.size = (sw, sh)
obj.fill = (0, 0, sw, sh)
obj.center = canvas.rect.center
off_x, off_y = (0,0)
c_x, c_y = obj.center
def key_down_cb(bg, event, ee):
global rescaled, c_x, c_y, off_x, off_y, iw, ih
k = event.key
if k in ("f", "F"):
ee.fullscreen_set(not ee.fullscreen_get())
elif k == "space":
obj = ee.data["obj"]
canvas = ee.evas
if rescaled:
rescaled = False
obj.size = (iw, ih)
obj.fill = (0, 0, iw, ih)
else:
rescaled = True
w, h = canvas.size
if iw*1.0/w > ih*1.0/h:
sw = w
sh = (ih*w+iw/2)/iw
else:
sw = (iw*h+ih/2)/ih
sh = h
obj.size = (sw, sh)
obj.fill = (0, 0, sw, sh)
c_x, c_y = canvas.rect.center
obj.center = c_x, c_y
off_x, off_y = (0,0)
elif k == "Escape":
ecore.main_loop_quit()
def mouse_down_cb(bg, event, ee):
global mouse_down, last_x, last_y
mouse_down = True
ee.x_window_cursor_shape_set(52)
canvas = ee.evas
last_x, last_y = canvas.pointer_canvas_xy
def mouse_move_cb(bg, event, ee):
global rescaled, mouse_down, last_x, last_y, c_x, c_y
if mouse_down and not rescaled:
obj = ee.data["obj"]
canvas = ee.evas
x, y = canvas.pointer_canvas_xy
obj.center = (c_x+x-last_x, c_y+y-last_y)
def mouse_up_cb(bg, event, ee):
global mouse_down, off_x, off_y, c_x, c_y
mouse_down = False
ee.x_window_cursor_shape_set(2)
obj = ee.data["obj"]
canvas = ee.evas
c_x, c_y = obj.center
off_x, off_y = canvas.rect.center
off_x, off_y = (c_x-off_x, c_y-off_y)
if len(sys.argv)<2:
print "Show 0.1 by photor with Python-ETK"
print "Usage: show filename"
print ""
print "Control keys:"
print " f or F toggle full-screen"
print " Space toggle original-size"
print " Escape quit"
print ""
elif __name__ == "__main__":
mouse_down = False
# original size of the canvas
w, h = (640, 480)
ee = ecore.evas.SoftwareX11(w=w, h=h)
ee.x_window_cursor_shape_set(2)
canvas = ee.evas # get drawing area created by SoftwareX11
bg = canvas.Rectangle(color=(255, 255, 255, 255))
# resize object to cover the whole canvas:
bg.size = canvas.size
# show object
bg.show()
filename = sys.argv[1]
obj = canvas.Image(file=filename) # open the image file
iw, ih = obj.image_size
# rescale the image to fit the canvas
if iw*1.0/w > ih*1.0/h:
sw = w
sh = (ih*w+iw/2)/iw
else:
sw = (iw*h+ih/2)/ih
sh = h
obj.size = (sw, sh)
# set visual object to fill whole object area with image, no "tiling"
obj.fill = (0, 0, sw, sh)
# center object on the canvas
obj.center = canvas.rect.center
c_x, c_y = obj.center
# show object
obj.show()
rescaled = True
# remember objects "bg" and "obj" for later use
ee.data["bg"] = bg
ee.data["obj"] = obj
# call function resize_cb() when window is resized so we resize "bg"
ee.callback_resize = resize_cb
ee.title = filename # set the window's name
# show X11 window created by SoftwareX11
ee.show()
obj.on_key_down_add(key_down_cb, ee) # receive keys
# receive mouse actions
obj.on_mouse_down_add(mouse_down_cb, ee)
obj.on_mouse_move_add(mouse_move_cb, ee)
obj.on_mouse_up_add(mouse_up_cb, ee)
obj.focus = True # focus on object
# enter main loop and wait until window is closed
ecore.main_loop_begin()