File size: 3,901 Bytes
fd5da23
7711652
 
fd5da23
 
7711652
 
 
 
 
 
 
fd5da23
7711652
 
 
 
 
 
fd5da23
7711652
 
 
 
 
 
 
fd5da23
 
 
7711652
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd5da23
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import gradio as gr
import github_manager


def update(text):
    file_dir_path = ''
    file_name = 'main.py'
    response = github_manager.push(text, file_dir_path, file_name)
    if response.status_code != 200:
        return response.text
    else:
        print(f"{file_name} pushed")

    workflow_name = 'pygbag.yml'
    response = github_manager.trigger_workflow(workflow_name)
    if response.status_code != 204:
        return response.text
    else:
        print(f"{workflow_name} workflow started")

    workflow_name = 'pages-build-deployment'
    response = github_manager.trigger_workflow(workflow_name)
    if response.status_code != 204:
        return response.text
    else:
        print(f"{workflow_name} workflow started")
    return "update successful"


with gr.Blocks() as demo:
    inp = gr.Textbox(value="""
import pygame
import sys
import asyncio
  
  
# pygame.init() will initialize all
# imported module
pygame.init()
  
clock = pygame.time.Clock()
  
# it will display on screen
screen = pygame.display.set_mode([600, 500])
  
# basic font for user typed
base_font = pygame.font.Font(None, 32)
  
# create rectangle
input_rect = pygame.Rect(200, 200, 140, 32)
  
# color_active stores color(lightskyblue3) which
# gets active when input box is clicked by user
color_active = pygame.Color('lightskyblue3')
  
# color_passive store color(chartreuse4) which is
# color of input box.
color_passive = pygame.Color('chartreuse4')
color = color_passive
  


async def main():
    user_text = ''
    active = False
    while True:
        for event in pygame.event.get():
      
          # if user types QUIT then the screen will close
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
      
            if event.type == pygame.MOUSEBUTTONDOWN:

                if input_rect.collidepoint(event.pos):
                    active = True
                else:
                    active = False
      
            if event.type == pygame.KEYDOWN:
                print(event.key)
                # Check for backspace
                if event.key == pygame.K_BACKSPACE:
      
                    # get text input from 0 to -1 i.e. end.
                    user_text = user_text[:-1]
                elif event.key == 13 or event.key == 1073741912:
                    if user_text == "ciao":
                        user_text = "Ciao anche a te"
      
                # Unicode standard is used for string
                # formation
                else:
                    user_text += event.unicode
          
        # it will set background color of screen
        screen.fill((255, 255, 255))
      
        if active:
            color = color_active
        else:
            color = color_passive
              
        # draw rectangle and argument passed which should
        # be on screen
        pygame.draw.rect(screen, color, input_rect)
      
        text_surface = base_font.render(user_text, True, (255, 255, 255))
          
        # render at position stated in arguments
        screen.blit(text_surface, (input_rect.x+5, input_rect.y+5))
          
        # set width of textfield so that text cannot get
        # outside of user's text input
        input_rect.w = max(100, text_surface.get_width()+10)
          
        # display.flip() will update only a portion of the
        # screen to updated, not full area
        pygame.display.flip()
          
        # clock.tick(60) means that for every second at most
        # 60 frames should be passed.
        clock.tick(60)
        await asyncio.sleep(0)

asyncio.run(main())
""")
    out = gr.Textbox(placeholder="Result")
    btn = gr.Button(value="Push")
    btn.click(update, inputs=[inp], outputs=[out])
    gr.Markdown("""[Play the game!](https://pjavanrooyen.github.io/text-to-game/)""")


if __name__ == "__main__":
    demo.launch()