confirm_page.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. # -*- coding: utf-8 -*-
  2. import pygame
  3. import os
  4. from libs.roundrects import aa_round_rect
  5. #UI lib
  6. from constants import Width,Height,ICON_TYPES
  7. from page import Page,PageSelector
  8. from label import Label
  9. from fonts import fonts
  10. from util_funcs import midRect
  11. from keys_def import CurKeys
  12. class ListPageSelector(PageSelector):
  13. _BackgroundColor = pygame.Color(131,199,219)
  14. def __init__(self):
  15. self._PosX = 0
  16. self._PosY = 0
  17. self._Height = 0
  18. self._Width = Width
  19. def AnimateDraw(self,x2,y2):
  20. pass
  21. def Draw(self):
  22. idx = self._Parent._PsIndex
  23. if idx > (len(self._Parent._MyList)-1):
  24. idx = len(self._Parent._MyList)
  25. if idx > 0:
  26. idx -=1
  27. elif idx == 0: #Nothing
  28. return
  29. x = self._Parent._MyList[idx]._PosX+2
  30. y = self._Parent._MyList[idx]._PosY+1
  31. h = self._Parent._MyList[idx]._Height -3
  32. self._PosX = x
  33. self._PosY = y
  34. self._Height = h
  35. aa_round_rect(self._Parent._CanvasHWND,
  36. (x,y,self._Width-4,h),self._BackgroundColor,4,0,self._BackgroundColor)
  37. class ConfirmPage(Page):
  38. _Icons = {}
  39. _Selector=None
  40. _FootMsg = ["Nav","","","Cancel","Yes"]
  41. _MyList = []
  42. _ListFont = fonts["veramono20"]
  43. _MyStack = None
  44. _FileName = ""
  45. _TrashDir = ""
  46. _ConfirmText = "Confirm?"
  47. _BGPosX = 0
  48. _BGPosY = 0
  49. _BGWidth = 0
  50. _BGHeight = 0
  51. _Parent = None
  52. def __init__(self):
  53. Page.__init__(self)
  54. self._Icons = {}
  55. self._CanvasHWND = None
  56. self._MyList = []
  57. def Reset(self):
  58. self._MyList[0].SetText(self._ConfirmText)
  59. self._MyList[0]._PosX = (self._Width - self._MyList[0]._Width)/2
  60. self._MyList[0]._PosY = (self._Height - self._MyList[0]._Height)/2
  61. self._BGPosX = self._MyList[0]._PosX-10
  62. self._BGPosY = self._MyList[0]._PosY-10
  63. self._BGWidth = self._MyList[0]._Width+20
  64. self._BGHeight = self._MyList[0]._Height+20
  65. def SnapMsg(self,msg):
  66. self._MyList[0].SetText(msg)
  67. self._MyList[0]._PosX = (self._Width - self._MyList[0]._Width)/2
  68. self._MyList[0]._PosY = (self._Height - self._MyList[0]._Height)/2
  69. self._BGPosX = self._MyList[0]._PosX-10
  70. self._BGPosY = self._MyList[0]._PosY-10
  71. self._BGWidth = self._MyList[0]._Width+20
  72. self._BGHeight = self._MyList[0]._Height+20
  73. def Init(self):
  74. self._PosX = self._Index * self._Screen._Width
  75. self._Width = self._Screen._Width
  76. self._Height = self._Screen._Height
  77. self._CanvasHWND = self._Screen._CanvasHWND
  78. ps = ListPageSelector()
  79. ps._Parent = self
  80. self._Ps = ps
  81. self._PsIndex = 0
  82. li = Label()
  83. li.SetCanvasHWND(self._CanvasHWND)
  84. li.Init(self._ConfirmText,self._ListFont)
  85. li._PosX = (self._Width - li._Width)/2
  86. li._PosY = (self._Height - li._Height)/2
  87. self._BGPosX = li._PosX-10
  88. self._BGPosY = li._PosY-10
  89. self._BGWidth = li._Width+20
  90. self._BGHeight = li._Height+20
  91. self._MyList.append(li)
  92. def KeyDown(self,event):
  93. if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
  94. self.ReturnToUpLevelPage()
  95. self._Screen.Draw()
  96. self._Screen.SwapAndShow()
  97. def DrawBG(self):
  98. _rect = pygame.Rect(self._BGPosX,self._BGPosY,self._BGWidth,self._BGHeight)
  99. pygame.draw.rect(self._CanvasHWND,(255,255,255),_rect,0)
  100. pygame.draw.rect(self._CanvasHWND,(83,83,83),_rect,1)
  101. def Draw(self):
  102. #self.ClearCanvas()
  103. self.DrawBG()
  104. for i in self._MyList:
  105. i.Draw()
  106. self.Reset()