confirm_page.py 3.9 KB

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