page.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. # -*- coding: utf-8 -*-
  2. import pygame
  3. from pygame.locals import *
  4. from sys import exit
  5. import os
  6. import sys
  7. import math
  8. import fnmatch
  9. import random
  10. from libs import easing
  11. # import base64
  12. # from beeprint import pp
  13. # local import
  14. from constants import ALIGN, icon_width, icon_height, Width, Height, ICON_TYPES
  15. from util_funcs import midRect,FileExists
  16. from keys_def import CurKeys, IsKeyStartOrA, IsKeyMenuOrB
  17. from icon_pool import MyIconPool
  18. from lang_manager import MyLangManager
  19. from widget import Widget
  20. import config
  21. class PageStack:
  22. def __init__(self):
  23. self.stack = list()
  24. def Push(self, data):
  25. if data not in self.stack:
  26. self.stack.append(data)
  27. return True
  28. return False
  29. def Pop(self):
  30. if len(self.stack) <= 0:
  31. return None, False
  32. return self.stack.pop(), True
  33. def Length(self):
  34. return len(self.stack)
  35. class PageSelector(Widget):
  36. _Parent = None
  37. _Alpha = 0
  38. _OnShow = True
  39. _IconSurf = None
  40. def __init__(self):
  41. pass
  42. def Init(self, x, y, w, h, alpha):
  43. self._PosX = x
  44. self._PosY = y
  45. self._Width = w
  46. self._Height = h
  47. self._Alpha = alpha
  48. def Adjust(self, x, y, w, h, alpha):
  49. self._PosX = x
  50. self._PosY = y
  51. self._Width = w
  52. self._Height = h
  53. self._Alpha = alpha
  54. def Draw(self):
  55. canvas = self._Parent._CanvasHWND
  56. idx = self._Parent._PsIndex
  57. iconidx = self._Parent._IconIndex
  58. if idx < len(self._Parent._Icons):
  59. x = self._Parent._Icons[idx]._PosX+self._Parent._PosX
  60. # only use current icon's PosY
  61. y = self._Parent._Icons[iconidx]._PosY
  62. rect = midRect(x, y, self._Width, self._Height,
  63. self._Parent._Width, self._Parent._Height)
  64. if rect.width <= 0 or rect.height <= 0:
  65. return
  66. # color = (244,197,66,50)
  67. # pygame.draw.rect(canvas,color,rect,1)
  68. if self._IconSurf != None:
  69. self._Parent._CanvasHWND.blit(self._IconSurf, rect)
  70. class Page(Widget):
  71. _Icons = []
  72. _Ps = None
  73. _PsIndex = 0
  74. _IconNumbers = 0
  75. _IconIndex = 0 # shows which icon current selected, the Selector can not move here
  76. _PrevIconIndex = 0 # for remember the Highlighted Icon ,restore it's PosY to average
  77. _Index = 0
  78. _Align = ALIGN["SLeft"]
  79. _CanvasHWND = None
  80. _HWND = None
  81. _OnShow = False
  82. _Name = ""
  83. _Screen = None # Should be the Screen Class
  84. _PageIconMargin = 20
  85. _FootMsg = ["Nav", "", "", "", "Enter"] # Default Page Foot info
  86. _Wallpaper = None
  87. _SelectedIconTopOffset = 20
  88. _EasingDur = 20/config.GlobalScale
  89. _Padding = pygame.Rect(0, 0, 0, 0) # x,y,w,h
  90. _Margin = pygame.Rect(0, 0, 0, 0)
  91. _ScrollStep = 1
  92. def __init__(self):
  93. self._Icons = []
  94. ## so every theme can have a background.png for displaying as the background of the launcher,except the topbar and footbar
  95. ## https://forum.clockworkpi.com/t/give-your-gs-a-custom-wallpaper/3724
  96. bg_img_path = config.SKIN+"/background.png"
  97. if FileExists(bg_img_path):
  98. self._Wallpaper = pygame.transform.scale(pygame.image.load(bg_img_path).convert(), (320,240))
  99. def AdjustHLeftAlign(self): ## adjust coordinator and append the PageSelector
  100. self._PosX = self._Index*self._Screen._Width
  101. self._Width = self._Screen._Width
  102. self._Height = self._Screen._Height
  103. cols = int(Width /icon_width)
  104. rows = int( (self._IconNumbers * icon_width)/Width + 1)
  105. if rows < 1:
  106. rows = 1
  107. cnt = 0
  108. for i in range(0,rows):
  109. for j in range(0,cols):
  110. start_x = icon_width/2 + j*icon_width
  111. start_y = icon_height/2 + i*icon_height
  112. icon = self._Icons[cnt]
  113. icon.Adjust(start_x,start_y,icon_width-4,icon_height-4,0)
  114. icon._Index = cnt
  115. icon._Parent = self
  116. if cnt >= (self._IconNumbers -1):
  117. break
  118. cnt+=1
  119. ps = PageSelector()
  120. ps._IconSurf = MyIconPool.GiveIconSurface("blueselector")
  121. ps._Parent = self
  122. ps.Init(icon_width/2, TitleBar._BarHeight+icon_height/2,92,92,128)
  123. self._Ps = ps
  124. self._PsIndex = 0
  125. self._OnShow = False
  126. def AdjustSLeftAlign(self): ## adjust coordinator and append the PageSelector
  127. self._PosX = self._Index*self._Screen._Width
  128. self._Width = self._Screen._Width
  129. self._Height = self._Screen._Height
  130. start_x = (self._PageIconMargin + icon_width+self._PageIconMargin) /2
  131. start_y = self._Height/2
  132. for i in range(0,self._IconNumbers):
  133. it = self._Icons[i]
  134. it._Parent = self
  135. it._Index = i
  136. it.Adjust(start_x+i*self._PageIconMargin+i*icon_width,start_y,icon_width-6,icon_height-6,0)
  137. it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
  138. ps = PageSelector()
  139. ps._IconSurf = MyIconPool.GiveIconSurface("blueselector")
  140. ps._Parent = self
  141. ps.Init(start_x,start_y,92,92,128)
  142. self._Ps = ps
  143. self._PsIndex = 0
  144. self._OnShow = False
  145. if self._IconNumbers > 1:
  146. self._PsIndex = 1
  147. self._IconIndex = self._PsIndex
  148. self._PrevIconIndex = self._IconIndex
  149. self._Icons[self._IconIndex]._PosY -= self._SelectedIconTopOffset
  150. def AdjustSAutoLeftAlign(self): ## adjust coordinator and append the PageSelector
  151. self._PosX = self._Index*self._Screen._Width
  152. self._Width = self._Screen._Width
  153. self._Height = self._Screen._Height
  154. start_x = (self._PageIconMargin + icon_width+self._PageIconMargin) /2
  155. start_y = self._Height/2
  156. if self._IconNumbers == 1:
  157. start_x = self._Width / 2
  158. start_y = self._Height/2
  159. it = self._Icons[0]
  160. it._Parent = self
  161. it._Index = 0
  162. it.Adjust(start_x,start_y,icon_width,icon_height,0)
  163. # it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
  164. elif self._IconNumbers == 2:
  165. start_x = (self._Width - self._PageIconMargin - self._IconNumbers*icon_width) / 2 + icon_width/2
  166. start_y = self._Height /2
  167. for i in range(0,self._IconNumbers):
  168. it = self._Icons[i]
  169. it._Parent = self
  170. it._Index = i
  171. it.Adjust(start_x+i*self._PageIconMargin + i*icon_width,start_y, icon_width, icon_height,0)
  172. # it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
  173. elif self._IconNumbers > 2:
  174. for i in range(0,self._IconNumbers):
  175. it = self._Icons[i]
  176. it._Parent = self
  177. it._Index = i
  178. it.Adjust(start_x+i*self._PageIconMargin + i*icon_width,start_y,icon_width,icon_height,0)
  179. # it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
  180. ps = PageSelector()
  181. ps._IconSurf = MyIconPool.GiveIconSurface("blueselector")
  182. ps._Parent = self
  183. ps.Init(start_x,start_y,92,92,128)
  184. self._Ps = ps
  185. self._PsIndex = 0
  186. self._OnShow = False
  187. if self._IconNumbers > 1:
  188. self._PsIndex = 1
  189. self._IconIndex = self._PsIndex
  190. self._PrevIconIndex = self._IconIndex
  191. self._Icons[self._IconIndex]._PosY -= self._SelectedIconTopOffset
  192. def InitLeftAlign(self):
  193. self._PosX = self._Index*Width
  194. self._Width = self._Screen._Width
  195. self._Height = self._Screen._Height
  196. cols = int(self._Width /icon_width)
  197. rows = int((self._IconNumbers * icon_width)/self._Width + 1)
  198. if rows < 1:
  199. rows = 1
  200. cnt = 0
  201. for i in range(0,rows):
  202. for j in range(0,cols):
  203. start_x = icon_width/2 + j*icon_width
  204. start_y = TitleBar._BarHeight + icon_height/2 + i*icon_height
  205. icon = IconItem()
  206. icon.Init(start_x,start_y,icon_width-4,icon_height-4,0)
  207. icon._Index = cnt
  208. icon._Parent = self
  209. self._Icons.append(icon)
  210. if cnt >= (self._IconNumbers -1):
  211. break
  212. cnt+=1
  213. ps = PageSelector()
  214. ps._IconSurf = MyIconPool.GiveIconSurface("blueselector")
  215. ps._Parent = self
  216. ps.Init(icon_width/2,icon_height/2,92,92,128)
  217. self._Ps = ps
  218. self._PsIndex = 0
  219. self._OnShow = False
  220. def Adjust(self): ## default init way,
  221. self._PosX = self._Index*self._Screen._Width
  222. self._Width = self._Screen._Width ## equal to screen width
  223. self._Height = self._Screen._Height
  224. if self._Align == ALIGN["HLeft"]:
  225. start_x = (self._Width - self._IconNumbers*icon_width)/2 + icon_width/2
  226. start_y = self._Height/2
  227. for i in range(0,self._IconNumbers):
  228. it = self._Icons[i]
  229. it._Parent = self
  230. it._Index = i
  231. it.Adjust(start_x+i*icon_width,start_y,icon_width,icon_height,0)
  232. ps = PageSelector()
  233. ps._IconSurf = MyIconPool.GiveIconSurface("blueselector")
  234. ps._Parent = self
  235. ps.Init(start_x,start_y,92,92,128)
  236. self._Ps = ps
  237. self._PsIndex = 0
  238. self._OnShow = False
  239. elif self._Align == ALIGN["SLeft"]:
  240. start_x = (self._PageIconMargin + icon_width+self._PageIconMargin) /2
  241. start_y = self._Height/2
  242. for i in range(0,self._IconNumbers):
  243. it = self._Icons[i]
  244. it._Parent = self
  245. it._Index = i
  246. it.Adjust(start_x+i*self._PageIconMargin+i*icon_width,start_y,icon_width,icon_height,0)
  247. ps = PageSelector()
  248. ps._IconSurf = MyIconPool.GiveIconSurface("blueselector")
  249. ps._Parent = self
  250. ps.Init(start_x,start_y-self._SelectedIconTopOffset,92,92,128)
  251. self._Ps = ps
  252. self._PsIndex = 0
  253. self._OnShow = False
  254. if self._IconNumbers > 1:
  255. self._PsIndex = 1
  256. self._IconIndex = self._PsIndex
  257. self._PrevIconIndex = self._IconIndex
  258. self._Icons[self._IconIndex]._PosY -= self._SelectedIconTopOffset
  259. def Init(self): ## default init way,
  260. if self._Screen != None:
  261. if self._Screen._CanvasHWND != None and self._CanvasHWND == None:
  262. self._CanvasHWND = self._Screen._CanvasHWND
  263. self._PosX = self._Index*self._Screen._Width
  264. self._Width = self._Screen._Width ## equal to screen width
  265. self._Height = self._Screen._Height
  266. start_x = (self._Width - self._IconNumbers*icon_width)/2 + icon_width/2
  267. start_y = self._Height/2
  268. for i in range(0,self._IconNumbers):
  269. it = IconItem()
  270. it._Parent = self
  271. it._Index = i
  272. it.Init(start_x+i*icon_width,start_y,icon_width,icon_height,0)
  273. self._Icons.append(it)
  274. if self._IconNumbers > 0:
  275. ps = PageSelector()
  276. ps._IconSurf = MyIconPool.GiveIconSurface("blueselector")
  277. ps._Parent = self
  278. ps.Init(start_x,start_y,icon_width+4,icon_height+4,128)
  279. self._Ps = ps
  280. self._PsIndex = 0
  281. self._OnShow = False
  282. def IconStepMoveData(self,icon_eh,cuts):## no Sine,No curve,plain movement steps data
  283. all_pieces = []
  284. piece = icon_eh / cuts
  285. c = 0.0
  286. prev = 0.0
  287. for i in range(0,cuts):
  288. c+=piece
  289. dx = c-prev
  290. if dx < 0.5:
  291. dx = 1.0
  292. all_pieces.append( math.ceil(dx) )
  293. if c >= icon_eh:
  294. break
  295. c = 0
  296. bidx = 0
  297. for i in all_pieces:
  298. c+=i
  299. bidx+=1
  300. if c >= icon_eh:
  301. break
  302. all_pieces = all_pieces[0:bidx]
  303. if len(all_pieces) < cuts:
  304. dff = cuts - len(all_pieces)
  305. diffa = []
  306. for i in range(0,dff):
  307. diffa.append(0)
  308. all_pieces.extend( diffa)
  309. return all_pieces
  310. def EasingData(self,start,distance):##generate easing steps data
  311. current_time = 0.0
  312. start_posx = 0.0
  313. current_posx = start_posx
  314. final_posx = float(distance)
  315. posx_init = start
  316. dur = self._EasingDur
  317. last_posx = 0.0
  318. all_last_posx = []
  319. for i in range(0,distance*dur):
  320. current_posx = easing.SineIn(current_time,start_posx,final_posx-start_posx,float(dur))
  321. if current_posx >= final_posx:
  322. current_posx = final_posx
  323. dx = current_posx - last_posx
  324. all_last_posx.append(int(dx))
  325. current_time+=1
  326. last_posx = current_posx
  327. if current_posx >= final_posx:
  328. break
  329. c = 0
  330. for i in all_last_posx:
  331. c+=i
  332. if c < final_posx -start_posx:
  333. all_last_posx.append(final_posx - c)
  334. return all_last_posx
  335. def IconSmoothUp(self,icon_ew):
  336. data = self.EasingData(self._PosX,icon_ew)
  337. data2 = self.IconStepMoveData(self._SelectedIconTopOffset,len(data))
  338. for i,v in enumerate(data):
  339. self.ClearCanvas()
  340. self._Icons[self._IconIndex]._PosY -= data2[i]
  341. if self._Icons[self._PrevIconIndex]._PosY < self._Height/2:
  342. self._Icons[self._PrevIconIndex]._PosY+=data2[i]
  343. self.DrawIcons()
  344. self._Screen.SwapAndShow()
  345. def IconsEasingLeft(self,icon_ew):
  346. data = self.EasingData(self._PosX,icon_ew)
  347. data2 = self.IconStepMoveData(self._SelectedIconTopOffset,len(data))
  348. for i,v in enumerate(data):
  349. self.ClearCanvas()
  350. self._PosX -= v
  351. self._Icons[self._IconIndex]._PosY -= data2[i]
  352. if self._Icons[self._PrevIconIndex]._PosY < self._Height/2:
  353. self._Icons[self._PrevIconIndex]._PosY+=data2[i]
  354. self.DrawIcons()
  355. self._Screen.SwapAndShow()
  356. def IconsEasingRight(self,icon_ew):
  357. data = self.EasingData(self._PosX,icon_ew)
  358. data2 = self.IconStepMoveData(self._SelectedIconTopOffset,len(data))
  359. for i,v in enumerate(data):
  360. self.ClearCanvas()
  361. self._PosX += v
  362. self._Icons[self._IconIndex]._PosY-=data2[i]
  363. if self._Icons[self._PrevIconIndex]._PosY < self._Height/2:
  364. self._Icons[self._PrevIconIndex]._PosY+=data2[i]
  365. self.DrawIcons()
  366. self._Screen.SwapAndShow()
  367. def EasingLeft(self,ew): #ew int
  368. data = self.EasingData(self._PosX,ew)
  369. for i in data:
  370. self._PosX -=i
  371. self.Draw()
  372. self._Screen.SwapAndShow()
  373. def EasingRight(self,ew):
  374. data = self.EasingData(self._PosX,ew)
  375. for i in data:
  376. self._PosX += i
  377. self.Draw()
  378. self._Screen.SwapAndShow()
  379. def MoveLeft(self,ew):
  380. self._PosX -= ew
  381. def MoveRight(self,ew):
  382. self._PosX += ew
  383. def ResetPageSelector(self):
  384. self._PsIndex = 0
  385. self._IconIndex = 0
  386. self._Ps._OnShow = True
  387. def DrawPageSelector(self):
  388. if self._Ps._OnShow == True:
  389. self._Ps.Draw()
  390. def MoveIconIndexPrev(self):
  391. self._PrevIconIndex = self._IconIndex
  392. self._IconIndex-=1
  393. if self._IconIndex < 0:
  394. self._IconIndex = max(0, self._IconNumbers - 1) # Wrap Icon Index
  395. return False
  396. return True
  397. def MoveIconIndexNext(self):
  398. self._PrevIconIndex = self._IconIndex
  399. self._IconIndex+=1
  400. if self._IconIndex > (self._IconNumbers - 1):
  401. self._IconIndex = 0 # Wrap Icon Index
  402. return False
  403. return True
  404. def IconClick(self):
  405. if self._IconIndex > (len(self._Icons) -1):
  406. return
  407. cur_icon = self._Icons[self._IconIndex]
  408. if self._Ps._OnShow == False:
  409. return
  410. if cur_icon._MyType == ICON_TYPES["EXE"]:
  411. print("IconClick: %s %d"%(cur_icon._CmdPath,cur_icon._Index))
  412. self._Screen.RunEXE(cur_icon._CmdPath)
  413. elif cur_icon._MyType == ICON_TYPES["DIR"]:
  414. child_page = self._Icons[self._IconIndex]._LinkPage
  415. if child_page != None:
  416. child_page.Draw()
  417. self._Screen._MyPageStack.Push(self._Screen._CurrentPage)
  418. self._Screen._CurrentPage = child_page
  419. elif cur_icon._MyType == ICON_TYPES["FUNC"]:
  420. print("IconClick API: %d"%(cur_icon._Index))
  421. # print("%s"% cur_icon._CmdPath)
  422. api_cb = getattr(cur_icon._CmdPath,"API",None)
  423. if api_cb != None:
  424. if callable(api_cb):
  425. cur_icon._CmdPath.API(self._Screen)
  426. elif cur_icon._MyType == ICON_TYPES["Emulator"] or cur_icon._MyType == ICON_TYPES["Commercial"]:
  427. cur_icon._CmdPath.API(self._Screen)
  428. def ReturnToUpLevelPage(self):
  429. pop_page,ok = self._Screen._MyPageStack.Pop()
  430. if ok == True:
  431. # self._Screen._CurrentPage.ResetPageSelector()
  432. pop_page.Draw()
  433. self._Screen._CurrentPage = pop_page
  434. on_return_back_cb = getattr(self._Screen._CurrentPage,"OnReturnBackCb",None)
  435. if on_return_back_cb != None:
  436. if callable(on_return_back_cb):
  437. self._Screen._CurrentPage.OnReturnBackCb()
  438. else:
  439. if self._Screen._MyPageStack.Length() == 0:
  440. if len(self._Screen._Pages) > 0:
  441. self._Screen._CurrentPage = self._Screen._Pages[self._Screen._PageIndex]
  442. self._Screen._CurrentPage.Draw()
  443. print("OnTopLevel ",self._Screen._PageIndex)
  444. def ClearCanvas(self):
  445. if self._Wallpaper:
  446. self._CanvasHWND.blit(self._Wallpaper,(0,0))
  447. else:
  448. self._CanvasHWND.fill(self._Screen._SkinManager.GiveColor("White"))
  449. def ClearIcons(self):
  450. for i in range(0,self._IconNumbers):
  451. self._Icons[i].Clear()
  452. def DrawIcons(self):
  453. for i in range(0,self._IconNumbers):
  454. self._Icons[i].Draw()
  455. # make sure the Class has the _MyList
  456. def ScrollDown(self):
  457. if len(self._MyList) == 0:
  458. return
  459. self._PsIndex +=1
  460. if self._PsIndex >= len(self._MyList):
  461. self._PsIndex = len(self._MyList) -1
  462. cur_li = self._MyList[self._PsIndex]
  463. if cur_li._PosY +cur_li._Height > self._Height:
  464. for i in range(0,len(self._MyList)):
  465. self._MyList[i]._PosY -= self._MyList[i]._Height
  466. def ScrollUp(self):
  467. if len(self._MyList) == 0:
  468. return
  469. self._PsIndex -= 1
  470. if self._PsIndex < 0:
  471. self._PsIndex = 0
  472. cur_li = self._MyList[self._PsIndex]
  473. if cur_li._PosY < 0:
  474. for i in range(0, len(self._MyList)):
  475. self._MyList[i]._PosY += self._MyList[i]._Height
  476. def FScrollUp(self,Step=1):
  477. if len(self._MyList) == 0:
  478. return
  479. tmp = self._PsIndex
  480. self._PsIndex -= Step
  481. if self._PsIndex < 0:
  482. self._PsIndex = 0
  483. dy = tmp-self._PsIndex
  484. cur_li = self._MyList[self._PsIndex]
  485. if cur_li._PosY < 0:
  486. for i in range(0, len(self._MyList)):
  487. self._MyList[i]._PosY += self._MyList[i]._Height*dy
  488. def RefreshPsIndex(self):
  489. if len(self._MyList) == 0:
  490. self._PsIndex = 0
  491. if self._PsIndex > (len(self._MyList) -1):
  492. self._PsIndex = len(self._MyList) -1
  493. def FScrollDown(self,Step=1):
  494. if len(self._MyList) == 0:
  495. return
  496. tmp = self._PsIndex
  497. self._PsIndex +=Step
  498. if self._PsIndex >= len(self._MyList):
  499. self._PsIndex = len(self._MyList) -1
  500. dy = self._PsIndex - tmp
  501. cur_li = self._MyList[self._PsIndex]
  502. if cur_li._PosY +cur_li._Height > self._Height:
  503. for i in range(0,len(self._MyList)):
  504. self._MyList[i]._PosY -= self._MyList[i]._Height*dy
  505. def KeyDown(self,event):##default keydown,every inherited page class should have it's own KeyDown
  506. if IsKeyMenuOrB(event.key):
  507. self.ReturnToUpLevelPage()
  508. self._Screen.Draw()
  509. self._Screen.SwapAndShow()
  510. if event.key == CurKeys["Right"]:
  511. if self.MoveIconIndexNext() == True:
  512. if self._IconIndex == (self._IconNumbers -1) or self._PrevIconIndex == 0:
  513. self.IconSmoothUp(icon_width + self._PageIconMargin)
  514. else:
  515. self.IconsEasingLeft(icon_width + self._PageIconMargin)
  516. else:
  517. screen_icons = int(math.floor(self._Screen._Width / (icon_width + self._PageIconMargin)))
  518. if self._IconNumbers > screen_icons:
  519. self.IconsEasingRight((icon_width + self._PageIconMargin) * (self._IconNumbers - screen_icons))
  520. elif self._IconNumbers > 0:
  521. self.IconSmoothUp(icon_width+ self._PageIconMargin)
  522. self._PsIndex = self._IconIndex
  523. self._Screen.Draw()
  524. self._Screen.SwapAndShow()
  525. if event.key == CurKeys["Left"]:
  526. if self.MoveIconIndexPrev() == True:
  527. if self._IconIndex == 0 or self._PrevIconIndex == (self._IconNumbers -1):
  528. self.IconSmoothUp(icon_width + self._PageIconMargin)
  529. else:
  530. self.IconsEasingRight(icon_width + self._PageIconMargin)
  531. else:
  532. screen_icons = int(math.floor(self._Screen._Width / (icon_width + self._PageIconMargin)))
  533. if self._IconNumbers > screen_icons:
  534. self.IconsEasingLeft((icon_width + self._PageIconMargin) * (self._IconNumbers - screen_icons))
  535. elif self._IconNumbers > 0:
  536. self.IconSmoothUp(icon_width+ self._PageIconMargin)
  537. self._PsIndex = self._IconIndex
  538. self._Screen.Draw()
  539. self._Screen.SwapAndShow()
  540. if IsKeyStartOrA(event.key):
  541. self.IconClick()
  542. self._Screen.Draw()
  543. self._Screen.SwapAndShow()
  544. def Draw(self):
  545. self.ClearCanvas()
  546. self.DrawIcons()
  547. self.DrawPageSelector()