counter_screen.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # -*- coding: utf-8 -*-
  2. import pygame
  3. import gobject
  4. import commands
  5. ## local package import
  6. from constants import Width,Height,RUNSYS
  7. from label import Label
  8. from fonts import fonts
  9. from full_screen import FullScreen
  10. from skin_manager import MySkinManager
  11. import config
  12. class CounterScreen(FullScreen):
  13. _CounterFont = fonts["varela120"]
  14. _TextFont1 = fonts["varela15"]
  15. _TextFont2 = fonts["varela12"]
  16. _TopLabel = None
  17. _BottomLabel = None
  18. _NumberLabel = None
  19. _BGColor = MySkinManager.GiveColor('Black')
  20. _FGColor = MySkinManager.GiveColor('White')
  21. _Counting = False
  22. _Number = 10
  23. _GobjectIntervalId = -1
  24. _inter_counter = 0
  25. def GObjectInterval(self):
  26. self._inter_counter+=1
  27. if self._Number == 0:
  28. self._Counting = False
  29. print("do the real shutdown")
  30. if config.CurKeySet != "PC":
  31. cmdpath = "feh --bg-center gameshell/wallpaper/seeyou.png;"
  32. cmdpath += "sleep 3;"
  33. cmdpath += "sudo halt -p"
  34. pygame.event.post( pygame.event.Event(RUNSYS, message=cmdpath))\
  35. return False
  36. if self._inter_counter >=2:
  37. self._Number -= 1
  38. if self._Number < 0:
  39. self._Number = 0
  40. print("sub Number %d " % self._Number)
  41. self._inter_counter = 0
  42. self.Draw()
  43. self.SwapAndShow()
  44. return self._Counting
  45. def StartCounter(self):
  46. if self._Counting == True:
  47. return
  48. self._Number = 10
  49. self._Counting = True
  50. self._GobjectIntervalId = gobject.timeout_add(500,self.GObjectInterval)
  51. def StopCounter(self):
  52. if self._Counting == False:
  53. return
  54. self._Counting = False
  55. self._Number = 10
  56. if self._GobjectIntervalId != -1:
  57. gobject.source_remove(self._GobjectIntervalId)
  58. self._GobjectIntervalId = -1
  59. return
  60. def Init(self):
  61. self._CanvasHWND = pygame.Surface((self._Width,self._Height))
  62. self._TopLabel = Label()
  63. self._TopLabel.SetCanvasHWND(self._CanvasHWND)
  64. self._TopLabel.Init("System shutdown in", self._TextFont1, self._FGColor)
  65. self._BottomLabel = Label()
  66. self._BottomLabel.SetCanvasHWND(self._CanvasHWND)
  67. self._BottomLabel.Init("Press any key to stop countdown", self._TextFont2, self._FGColor)
  68. self._NumberLabel = Label()
  69. self._NumberLabel.SetCanvasHWND(self._CanvasHWND)
  70. self._NumberLabel.Init(str(self._Number), self._CounterFont, self._FGColor)
  71. def Draw(self):
  72. self._CanvasHWND.fill( self._BGColor )
  73. self._TopLabel.NewCoord(Width/2, 15)
  74. self._TopLabel.DrawCenter()
  75. self._BottomLabel.NewCoord(Width/2, Height-15)
  76. self._BottomLabel.DrawCenter()
  77. self._NumberLabel.NewCoord(Width/2,Height/2)
  78. self._NumberLabel.SetText(str(self._Number))
  79. self._NumberLabel.DrawCenter()