Newer
Older
CubeSolver / Code Stuff / old / mainV2.py
  1. import twophase.solver as sv
  2. import kociemba
  3. import pygame
  4. import sys
  5. # cubestring = 'LLBUUFFFLBDDDRBFFRDLURFLRBRBLUUDUDRBURLRLBRBDLUFDBDUFF'
  6. # solution = sv.solve(cubestring, 0, 2)
  7. # print(solution)
  8. # solution2 = kociemba.solve(cubestring)
  9. # print(solution2, len(solution2))
  10. #
  11. # final_solution = []
  12.  
  13.  
  14. # Initialize pygame
  15. pygame.init()
  16.  
  17. # Define colors
  18. WHITE = (255, 255, 255)
  19. BLACK = (0, 0, 0)
  20. GRAY = (150, 150, 150)
  21.  
  22. # Set up the screen
  23. screen_width, screen_height = 400, 300
  24. screen = pygame.display.set_mode((screen_width, screen_height))
  25. pygame.display.set_caption("Simple GUI with Pygame")
  26.  
  27. # Create a font
  28. font = pygame.font.SysFont(None, 40)
  29.  
  30.  
  31. # Function to display text on the screen
  32. def draw_text(text, x, y, color):
  33. text_surface = font.render(text, True, color)
  34. screen.blit(text_surface, (x, y))
  35.  
  36.  
  37. # Function to check if a point is inside a rectangle
  38. def is_mouse_over(pos, rect):
  39. return rect.left < pos[0] < rect.right and rect.top < pos[1] < rect.bottom
  40.  
  41.  
  42. # Function to create a button
  43. def draw_button(rect, color, text):
  44. pygame.draw.rect(screen, color, rect)
  45. draw_text(text, rect.x + 10, rect.y + 10, BLACK)
  46.  
  47.  
  48. class Button:
  49. rect = pygame.Rect
  50. isPressed = False
  51. name = "1"
  52.  
  53. def draw(self, screen):
  54. if self.isPressed:
  55. pygame.draw.rect(screen, (0, 255, 0), self.rect)
  56. else:
  57. pygame.draw.rect(screen, (0, 0, 0), self.rect)
  58. draw_text(self.name, self.rect.x + 10, self.rect.y + 10, (255, 255, 255))
  59.  
  60.  
  61.  
  62. # Main function for GUI
  63. def main():
  64. # Initialize variables
  65. number_input = ""
  66.  
  67. # setup gui
  68. buttons = []
  69. buttonPoss = [
  70. (130, 10, 50, 50),
  71. (130, 70, 50, 50),
  72. (130, 190, 50, 50),
  73. (130, 250, 50, 50),
  74. (10, 130, 50, 50),
  75. (70, 130, 50, 50),
  76. (190, 130, 50, 50),
  77. (250, 130, 50, 50),
  78.  
  79. ]
  80. for i, pos in enumerate(buttonPoss):
  81. buttons.append(Button())
  82. buttons[i].rect = pygame.Rect(pos)
  83. buttons[i].name = str(i)
  84.  
  85. while True:
  86. for event in pygame.event.get():
  87. if event.type == pygame.QUIT:
  88. pygame.quit()
  89. sys.exit()
  90. elif event.type == pygame.KEYDOWN:
  91. if event.key == pygame.K_RETURN:
  92. print("Entered number:", number_input)
  93. number_input = ""
  94. elif event.key == pygame.K_BACKSPACE:
  95. number_input = number_input[:-1]
  96. else:
  97. number_input += event.unicode
  98. elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
  99. mouse_pos = pygame.mouse.get_pos()
  100. for button in buttons:
  101. button.isPressed = False
  102. if is_mouse_over(mouse_pos, button.rect):
  103. button.isPressed = True
  104. # # Check if the left mouse button is clicked on the buttons
  105. # if is_mouse_over(mouse_pos, pygame.Rect(150, 150, 100, 50)):
  106. # print("Button 1 clicked!")
  107. # elif is_mouse_over(mouse_pos, pygame.Rect(150, 220, 100, 50)):
  108. # print("Button 2 clicked!")
  109.  
  110. # Clear the screen
  111. screen.fill(WHITE)
  112.  
  113. # Draw the input field
  114. pygame.draw.rect(screen, GRAY, pygame.Rect(100, 50, 200, 40))
  115. draw_text(number_input, 110, 60, BLACK)
  116.  
  117. # Draw buttons
  118. for button in buttons:
  119. button.draw(screen)
  120. # draw_button(pygame.Rect(150, 150, 100, 50), BLACK, "Button 1")
  121. # draw_button(pygame.Rect(150, 220, 100, 50), BLACK, "Button 2")
  122.  
  123. # Update the display
  124. pygame.display.flip()
  125.  
  126.  
  127. if __name__ == "__main__":
  128. main()
  129.  
  130. # i = 0
  131. # while True:
  132. # # woo if statement spam
  133. # if solution[i] == "1":
  134. # final_solution[-1] += "n"
  135. # i += 2
  136. # elif solution[i] == "3":
  137. # final_solution[-1] += "p"
  138. # i += 2
  139. # elif solution[i] == "2":
  140. # final_solution[-1] += "n"
  141. # final_solution.append(final_solution[-1])
  142. # i += 2
  143. # elif solution[i] == "(":
  144. # break
  145. # else:
  146. # final_solution.append(solution[i])
  147. # i += 1
  148. #
  149. # print(final_solution)
  150.