page.py 22 KB

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