Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import threading
- import os
- from gtts import gTTS
- from playsound import playsound
- import pygame
- print("Alive")
- #agrments x,y,w,h,text
- class InputBox:
- pygame.font.init()
- COLOR_INACTIVE = pygame.Color('lightskyblue3')
- COLOR_ACTIVE = pygame.Color('dodgerblue2')
- FONT = pygame.font.SysFont('DejaVu Serif.ttf', 32)
- def __init__(self, x, y, w, h, text=''):
- self.rect = pygame.Rect(x, y, w, h)
- self.color = self.COLOR_INACTIVE
- self.text = text
- self.txt_surface = self.FONT.render(text, True, self.color)
- self.active = False
- def handle_event(self, event):
- if event.type == pygame.MOUSEBUTTONDOWN:
- # If the user clicked on the input_box rect.
- if self.rect.collidepoint(event.pos):
- # Toggle the active variable.
- self.active = not self.active
- else:
- self.active = False
- # Change the current color of the input box.
- self.color = self.COLOR_ACTIVE if self.active else self.COLOR_INACTIVE
- if event.type == pygame.KEYDOWN:
- if self.active:
- if event.key == pygame.K_BACKSPACE:
- self.text = self.text[:-1]
- else:
- self.text += event.unicode
- # Re-render the text.
- self.txt_surface = self.FONT.render(self.text, True, self.color)
- def update(self):
- # Resize the box if the text is too long.
- width = max(200, self.txt_surface.get_width()+10)
- self.rect.w = width
- def draw(self, screen):
- # Blit the text.
- screen.blit(self.txt_surface, (self.rect.x+5, self.rect.y+5))
- # Blit the rect.
- pygame.draw.rect(screen, self.color, self.rect, 2)
- print("WhatAboutNow?")
- class pygameSTD:
- pygame.font.init()
- pygame.init
- configUdater = None
- Bigfont = pygame.font.SysFont('DejaVu Serif.ttf', 154)
- smallFont = pygame.font.SysFont('DejaVu Serif.ttf', 55)
- smallerFont = pygame.font.SysFont('DejaVu Serif.ttf', 33)
- screenState = 'start'
- ligtGray = (128,128,128)
- ligherGray = (150, 150, 150)
- white = (255,255,255)
- wasExitClicked = False
- def createOptionBoxes(self, configList):
- self.screenResBox = InputBox(590,110,400,50,configList[0][1])
- self.textToSpeechBox = InputBox(590,210,400,50,configList[1][1])
- self.languageBox = InputBox(590,310,400,50,configList[2][1])
- self.readAttackNameBox = InputBox(590,410,400,50,configList[3][1])
- self.box = [self.screenResBox, self.textToSpeechBox, self.languageBox, self.readAttackNameBox]
- def didPressExit(self):
- if self.wasExitClicked == True:
- return True
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- return True
- for box in self.box:
- box.handle_event(event)
- return False
- def changeGameSence(self):
- print("scene changed")
- def changeGameSenceToOption(self):
- self.screenState = 'options'
- def changeGameSenceToStart(self):
- self.screenState = 'start'
- def exitWasClicked(self):
- self.wasExitClicked = True
- def updateConfig(self):
- content = []
- for box in self.box:
- content.append(box.text)
- self.configUdater.configUpdate(content)
- self.changeGameSenceToStart()
- def text_objects(self, text, font):
- textSurface = font.render(text, True, self.white)
- return textSurface, textSurface.get_rect()
- def button(self,screen, msg,x,y,w,h,action=None):
- mouse = pygame.mouse.get_pos()
- click = pygame.mouse.get_pressed()
- if x+w > mouse[0] > x and y+h > mouse[1] > y:
- pygame.draw.rect(screen, self.ligherGray,(x,y,w,h))
- if click[0] == 1 and action != None:
- action()
- else:
- pygame.draw.rect(screen, self.ligtGray,(x,y,w,h))
- textSurf, textRect = self.text_objects(msg, self.smallFont)
- textRect.center = ( (x+(w/2)), (y+(h/2)) )
- screen.blit(textSurf, textRect)
- def startScreen(self, screen):
- name = self.Bigfont.render("MMO Rotation Tool", 1, self.white)
- run = self.smallFont.render
- screen.blit(name, (60, 60))
- self.button(screen, "Run a Template", 340, 210, 400, 50, self.changeGameSence)
- self.button(screen, "Create a Template", 340, 310, 400, 50, self.changeGameSence)
- self.button(screen, "Options", 340,410,400,50, self.changeGameSenceToOption)
- self.button(screen,"Exit",340,510,400,50, self.exitWasClicked)
- def OptionsScreen(self, screen):
- for box in self.box:
- box.update()
- box.draw(screen)
- self.button(screen, "Back",440,610,200,50, self.updateConfig)
- screenResModeText = self.smallerFont.render("Screen Res Mode: ", 1, self.white)
- textToSpeechText = self.smallerFont.render("Use Text To Speech:", 1, self.white)
- languageText = self.smallerFont.render("Language For TTS:", 1, self.white)
- readAttackNameText = self.smallerFont.render("Attack name read with TTS:", 1, self.white)
- screen.blit(screenResModeText,(290,120))
- screen.blit(textToSpeechText, (290, 220))
- screen.blit(languageText, (290, 320))
- screen.blit(readAttackNameText, (290, 420))
- def updateScreen(self, screen):
- if self.screenState == 'start':
- self.startScreen(screen)
- elif self.screenState == 'options':
- self.OptionsScreen(screen)
- print("check for life")
- class config:
- file_path = ".\data"
- directory = os.path.dirname(file_path)
- def checkFolder(self):
- try:
- if not os.path.exists(self.file_path):
- os.mkdir(self.file_path)
- except OSError:
- print ('Error: Creating directory. ' + self.file_path)
- def createConfig(self):
- self.checkFolder()
- file = open("data/config.txt", "w+")
- file.write("ScreenRes: 1\n")
- file.write("TextToSpeach: True\n")
- file.write("language: en\n")
- file.write("ReadAttackName: True\n")
- def readConfig(self):
- while True:
- try:
- configFile = open("data/config.txt", "r")
- break
- except FileNotFoundError:
- self.createConfig()
- except Exception as e:
- print("Unknown error: " + str(e))
- configList = []
- for line in configFile:
- configLine = line.strip().split()
- configList.append(configLine)
- configFile.close()
- return configList
- def configUpdate(self, content):
- self.checkFolder()
- file = open("data/config.txt", "w+")
- file.write("ScreenRes: " + str(content[0]) + "\n")
- file.write("TextToSpeach: " + str(content[1]) + "\n" )
- file.write("language: " + str(content[2]) + "\n")
- file.write("ReadAttackName: " +str(content[3]) + "\n")
- print("Mayhap if im lucky")
- class TexttoSpeech:
- language = 'fn'
- def testTTS(self):
- mytext = 'This is a test function to see if Text to speech is working!'
- myobj = gTTS(text=mytext, lang=self.language)
- myobj.save("data/test.mp3")
- playsound("data/test.mp3")
- print("Still alive?")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement