Esempio n. 1
0
def Main_Win():
    """Genera la ventana principal"""
    bg = pygame.image.load('.\Images\CDBG.png')
    run = True
    # BOTON: color boton, posicion x, posicion y, ancho, altura, tamano de letra, texto, color texto
    createbtn = Button((0, 0, 0), 310, 275, 150, 60, 26, "Create", (0, 191, 255))
    importbtn = Button((0, 0, 0), 310, 375, 150, 60, 26, "Import", (0, 191, 255))

    f_name = EntryBox("Introduce name:", 310, 405, 40, 180)
    read = Button((0,0,0), 310, 460, 120, 50, 24, "Import", (0,191,255))

    Import = False
    while run:
        screen.blit(bg,(0,0))
        createbtn.Draw(screen)
        if Import:
            f_name.Draw(screen)
            read.Draw(screen)
        else:
            importbtn.Draw(screen)
        pygame.display.update()
        for event in pygame.event.get():
            pos = pygame.mouse.get_pos()
            if event.type == pygame.QUIT:
                run = False
                pygame.quit()
                sys.exit()
            if event.type == pygame.MOUSEBUTTONUP:
                if createbtn.Click(pos):
                    run = False
                    DesignWin()
                if importbtn.Click(pos):
                    Import = True

                if read.Click(pos) and Import:
                    if f_name != "":
                        try:
                            with open(f_name.GetText() + '.json') as json_file:
                                pass
                        except(FileNotFoundError):
                            pass
                        else:
                            circuit = Json.Read(f_name.GetText())
                            CircuitDes = Circuit()
                            CircuitDes.ReadComponents(circuit)
                            DesignWin()
                    else:
                        pass

                if f_name.Click(pos) and Import:
                    pass

            if event.type == pygame.KEYDOWN:
                if f_name.CheckSelected():
                    if event.key == pygame.K_BACKSPACE:
                        text = f_name.GetText()
                        new = text[:-1]
                        f_name.SetText(new)
                    elif event.key == pygame.K_RETURN:
                        f_name.SetSelected(False)
                    else:
                        text = f_name.GetText()
                        new = text + event.unicode
                        f_name.SetText(new)
    pygame.display.update()
Esempio n. 2
0
        for event in events:
            # user clicked draw
            if event.type == pygame.MOUSEBUTTONDOWN:
                mouse_pos = pygame.mouse.get_pos()
                if (button.Collide(mouse_pos, button.get_rect())):
                    running = False
            if event.type == pygame.QUIT:
                generate = False
                running = False

        screen.fill(settings.BG_COLOR)
        surface1.fill(settings.BG_COLOR)
        #input_box.Update(events)
        #input_box.Draw(surface1)

        button.Draw(surface1)

        screen.blit(surface1, (0, 0))
        pygame.display.flip()

    # Setup screen is now gone, so reset the screen
    running = True
    surface1.fill(settings.BG_COLOR)

    clock = pygame.time.Clock()

    while (running and generate):

        # checks the events and stops the program from running if the "X" was pressed
        for event in pygame.event.get():
            if event.type == pygame.QUIT: