Guest User

interfacegraphique

a guest
Feb 14th, 2020
102
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #-*- coding: utf-8 -*-
  2.  
  3. import watchdog as wd
  4.  
  5. import random
  6. import pygame
  7. import time
  8. import os
  9.  
  10. from pygame.locals import *
  11.  
  12.  
  13. pygame.init()
  14. pygame.mixer.init()
  15.  
  16. # os.system("sudo su root") # pour le raspberry
  17.  
  18.  
  19. class button :
  20. def __init__(self, x, y, size_x, size_y):
  21. self.NAME = ""
  22.  
  23. self.POSITION_Y = y
  24. self.POSITION_X = x
  25.  
  26. self.SIZE_x = size_x
  27. self.SIZE_y = size_y
  28.  
  29.  
  30. def click(self, position):
  31. posi_mouse = position
  32. print "ok ok"
  33. if posi_mouse[0] > self.POSITION_X and posi_mouse[0] < self.POSITION_X + self.SIZE_x :
  34. print " x OK"
  35.  
  36. if posi_mouse[1] > self.POSITION_Y and posi_mouse[1] < self.POSITION_Y + self.SIZE_y :
  37. print "clicked " + self.NAME
  38. return True
  39. return False
  40. return False
  41.  
  42.  
  43. class window :
  44. def __init__(self):
  45. self.AUTHOR = "Hirel Loick"
  46. self.TITLE = "Kurietatsuru v1.0.0.2.7"
  47.  
  48. self.BUTTON_NAME = ["start", "mesure", "setting", "credit", "exit" ]
  49.  
  50. self.CHRONO = wd.dog(12)
  51.  
  52. self.SIZE_X = 1200
  53. self.SIZE_Y = 700
  54.  
  55. self.PI = 3.141592653 # pour faire un arc de cercle
  56. self.BLACK = pygame.Color(0, 0, 0)
  57. self.WHITE = pygame.Color(255,255,255)
  58.  
  59. self.WINDOW = pygame.display.set_mode((self.SIZE_X, self.SIZE_Y), pygame.FULLSCREEN)
  60. self.FOLDER_LOAD_BAR = "sprite/okdude"
  61.  
  62. self.BACKGROUND = pygame.image.load("sprite/background.png")
  63. self.BACKGROUND_TITLE = pygame.image.load("sprite/background2.png")
  64. self.BACKGROUND_MENU = pygame.image.load("sprite/background3.png")
  65.  
  66. # load_var loading =============================================
  67. self.LOADBAR = []
  68. for x in range(1, 9):
  69. self.LOADBAR.append(pygame.image.load(self.FOLDER_LOAD_BAR + str(x) + ".png"))
  70.  
  71. print "[+] window display !"
  72.  
  73. # button data ===================================================
  74. self.BUTTONS = []
  75.  
  76. def run(self):
  77. status = True
  78. x = 0
  79. # while status == True :
  80. while x < random.randint(3, 6) :
  81. for image in self.LOADBAR :
  82. x_blit = (self.SIZE_X/2)
  83. y = (self.SIZE_Y/2)
  84. self.WINDOW.blit(image, (x_blit, y))
  85. pygame.display.flip()
  86. time.sleep(0.09)
  87. x += 1
  88. print "[+] loading complet"
  89.  
  90. # animation debut ===============================
  91. self.WINDOW.blit(self.BACKGROUND,(0, 0))
  92. pygame.display.flip()
  93. for x in range(1, 450):
  94. pygame.draw.rect(self.WINDOW, self.BLACK, [275, 225, x, 50])
  95. pygame.display.flip()
  96. time.sleep(0.001)
  97. time.sleep(0.5)
  98.  
  99. self.WINDOW.blit(self.BACKGROUND_TITLE, (0, 0))
  100. pygame.draw.rect(self.WINDOW, self.BLACK, [575, 375, 50, 50])
  101. pygame.display.flip()
  102. time.sleep(0.2)
  103. pygame.draw.rect(self.WINDOW, self.WHITE, [575, 375, 50, 50])
  104. pygame.display.flip()
  105. time.sleep(0.8)
  106. pygame.draw.rect(self.WINDOW, self.BLACK, [575, 375, 50, 50])
  107. pygame.display.flip()
  108. time.sleep(0.2)
  109. pygame.draw.rect(self.WINDOW, self.WHITE, [575, 375, 50, 50])
  110. pygame.display.flip()
  111. time.sleep(0.8)
  112. pygame.draw.rect(self.WINDOW, self.BLACK, [575, 375, 50, 50])
  113. pygame.display.flip()
  114. time.sleep(0.2)
  115. pygame.draw.rect(self.WINDOW, self.WHITE, [575, 375, 50, 50])
  116. pygame.display.flip()
  117. time.sleep(1)
  118. # =========================================
  119.  
  120. self.WINDOW.blit(self.BACKGROUND_MENU, (0, 0))
  121.  
  122. # creation des bouttons de commandes ( initialisation )
  123. posi_x = 450
  124. posi_y = 10
  125. for name in self.BUTTON_NAME :
  126. but = button(posi_x, posi_y, 300, 200)
  127. but.NAME = name
  128. self.BUTTONS.append(but)
  129. img = pygame.image.load("sprite/" + name + "_button.png")
  130. self.WINDOW.blit(img, (posi_x, posi_y,))
  131. posi_y += 201
  132.  
  133. pygame.display.flip()
  134. time.sleep(3)
  135.  
  136. status_display = True
  137. # lancement du tactile
  138. self.CHRONO.start()
  139. while status_display == True :
  140. event = pygame.event.poll()
  141. status_display = self.CHRONO.status
  142. if event.type == pygame.MOUSEBUTTONDOWN :
  143. y = pygame.mouse.get_pos()[1]
  144. status = False
  145. for but in self.BUTTONS :
  146. click = but.click(pygame.mouse.get_pos())
  147. if click == True :
  148. status = True
  149. n = but.NAME
  150. if n == "start" :
  151. print "clicked"
  152. return True
  153. # start(self.WINDOW)
  154. elif n == "mesure" :
  155. return True
  156. # mesure(self.WINDOW)
  157. elif n == "setting" :
  158. return True
  159. # setting(self.WINDOW)
  160. elif n == "credit" :
  161. return True
  162. # credit(self.WINDOW)
  163. elif n == "exit" :
  164. return True
  165. # os.system("shutdown -h 00")
  166. posi_x = 450
  167. # self.CHRONO.start()
  168. new_y = pygame.mouse.get_pos()[1]
  169. print y
  170. print new_y
  171. if new_y > 800 :
  172. self.WINDOW.blit(self.BACKGROUND_MENU)
  173. posi_y -= 2
  174. for but in self.BUTTONS :
  175. but.POSITION_Y = posi_y
  176. img = pygame.image.load("sprite/" + str(but.NAME) + "_button.png")
  177. self.WINDOW.blit(img, (but.POSITION_X, but.POSITION_Y,))
  178.  
  179.  
  180. # os.system("shutdown -h 00") # eteindre quand on quitte
  181.  
  182.  
  183. w = window()
  184. w.run()
RAW Paste Data