confirm_page.py 3.9 KB

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