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