PyS60-图库缩略图版本。2

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PyS60-图库缩略图版本。2相关的知识,希望对你有一定的参考价值。

  1. import appuifw
  2. import e32
  3. import graphics
  4. import key_codes
  5. import os
  6.  
  7. class FlickrS60Error(Exception): pass
  8.  
  9. class FlickrS60Thumb:
  10.  
  11. def __init__(self, path):
  12.  
  13. self.path = unicode(path)
  14. self.listFile = []
  15. self.ldivx = 0
  16. self.ldivy = 0
  17. self.lock = e32.Ao_lock()
  18. self.canvas = None
  19. self.img = graphics.Image.new((176, 144))
  20. self.img_tmp = graphics.Image.new((42, 36))
  21. self.x, self.y = 0, 0
  22. self.p = 0
  23. self.pages = 0
  24. self.currpages = 0
  25. self.mpath = 0
  26.  
  27. def OnRun(self):
  28.  
  29. appuifw.app.exit_key_handler = self.lock.signal
  30.  
  31. self._createList()
  32.  
  33. self.canvas = appuifw.Canvas(redraw_callback=self.OnUpdate)
  34. appuifw.app.body = self.canvas
  35.  
  36. self.canvas.bind(key_codes.EKeyRightArrow, lambda: self.move(1, 0))
  37. self.canvas.bind(key_codes.EKeyLeftArrow, lambda: self.move(-1, 0))
  38. self.canvas.bind(key_codes.EKeyUpArrow, lambda: self.move(0, -1))
  39. self.canvas.bind(key_codes.EKeyDownArrow, lambda: self.move(0, 1))
  40. self.canvas.bind(key_codes.EKeySelect, self.IMG)
  41.  
  42. self._drawIMG()
  43.  
  44. self.lock.wait()
  45.  
  46. def OnUpdate(self, rect):
  47.  
  48. self.canvas.blit(self.img)
  49. self.canvas.rectangle([(self.p+(42*self.x), 36*self.y), (self.p+(42*self.x)+42, (36*self.y)+36)], width=2, outline=0x123456)
  50.  
  51. def move(self, x, y):
  52.  
  53. self.x = (self.x+x)%4
  54. self.y = (self.y+y)
  55.  
  56. if x == 1: self.p = (self.p+2)%8
  57. if x == -1: self.p = (self.p-2)%8
  58.  
  59. if self.y == 4:
  60. if self.currpages < self.pages-1:
  61. self.y = 0
  62. self.currpages += 1
  63. self._drawIMG(start=self.currpages)
  64. else:
  65. self.y = 3
  66.  
  67. if self.y == -1:
  68. if self.currpages > 0:
  69. self.y = 3
  70. self.currpages -= 1
  71. self._drawIMG(start=self.currpages)
  72. else:
  73. self.y = 0
  74.  
  75. self.mpath = (4*self.y + self.x)+(16*self.currpages)
  76.  
  77. self.OnUpdate(None)
  78.  
  79. def IMG(self):
  80.  
  81. try:
  82. m = self.listFile[self.mpath].replace('_PalbTN\', '')
  83. appuifw.Content_handler().open(m)
  84. except:
  85. pass
  86.  
  87. def _drawIMG(self, start=0):
  88.  
  89. self.img.clear(0xffffff)
  90. z = 0
  91.  
  92. for id in range(start*16, (start+1)*16):
  93. j, i = divmod(id-(start*16), 4)
  94. try:
  95. self.img_tmp.load(self.listFile[id])
  96. self.img.blit(self.img_tmp, target=(z+(42*i)+(z+1), 36*j))
  97. z = (z+1)%4
  98. except:
  99. break
  100.  
  101. self.OnUpdate(None)
  102.  
  103. def _createList(self):
  104.  
  105. try:
  106. for id in os.listdir(self.path):
  107. self.listFile.append(self.path + id)
  108.  
  109. self.ldivx, self.ldivy = divmod(len(self.listFile), 16)
  110.  
  111. self.pages = self.ldivx
  112. if self.ldivy <> 0: self.pages += 1
  113. except:
  114. raise FlickrS60Error('Errore nella creazione della lista.')
  115.  
  116. if __name__ == '__main__':
  117.  
  118. FlickrS60Thumb('E:\Images\_PalbTN\').OnRun()

以上是关于PyS60-图库缩略图版本。2的主要内容,如果未能解决你的问题,请参考以下文章

从 android 图库中选择缩略图

如何在图库中的缩略图之间留出空间并且在所有浏览器中都相同?

php 在单个产品页面更改图库缩略图大小

有没有办法从手机图库中读取缩略图?

浮动缩略图库,大小不一,如何处理?

使用 Laravel 为社交网站创建缩略图