Advertisement
Guest User

Untitled

a guest
Jul 9th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.40 KB | None | 0 0
  1. #import threading
  2. import os
  3. from gtts import gTTS
  4. from playsound import playsound
  5. import pygame
  6.  
  7. print("Alive")
  8.  
  9. #agrments x,y,w,h,text
  10. class InputBox:
  11.  
  12.     pygame.font.init()
  13.     COLOR_INACTIVE = pygame.Color('lightskyblue3')
  14.     COLOR_ACTIVE = pygame.Color('dodgerblue2')
  15.     FONT = pygame.font.SysFont('DejaVu Serif.ttf', 32)
  16.  
  17.  
  18.     def __init__(self, x, y, w, h, text=''):
  19.         self.rect = pygame.Rect(x, y, w, h)
  20.         self.color = self.COLOR_INACTIVE
  21.         self.text = text
  22.         self.txt_surface = self.FONT.render(text, True, self.color)
  23.         self.active = False
  24.  
  25.     def handle_event(self, event):
  26.         if event.type == pygame.MOUSEBUTTONDOWN:
  27.             # If the user clicked on the input_box rect.
  28.             if self.rect.collidepoint(event.pos):
  29.                 # Toggle the active variable.
  30.                 self.active = not self.active
  31.             else:
  32.                 self.active = False
  33.             # Change the current color of the input box.
  34.             self.color = self.COLOR_ACTIVE if self.active else self.COLOR_INACTIVE
  35.         if event.type == pygame.KEYDOWN:
  36.             if self.active:
  37.                 if event.key == pygame.K_BACKSPACE:
  38.                     self.text = self.text[:-1]
  39.                 else:
  40.                     self.text += event.unicode
  41.                 # Re-render the text.
  42.                 self.txt_surface = self.FONT.render(self.text, True, self.color)
  43.  
  44.     def update(self):
  45.         # Resize the box if the text is too long.
  46.         width = max(200, self.txt_surface.get_width()+10)
  47.         self.rect.w = width
  48.  
  49.     def draw(self, screen):
  50.         # Blit the text.
  51.         screen.blit(self.txt_surface, (self.rect.x+5, self.rect.y+5))
  52.         # Blit the rect.
  53.         pygame.draw.rect(screen, self.color, self.rect, 2)
  54.  
  55. print("WhatAboutNow?")
  56.  
  57. class pygameSTD:
  58.  
  59.     pygame.font.init()
  60.     pygame.init
  61.  
  62.     configUdater = None
  63.  
  64.     Bigfont = pygame.font.SysFont('DejaVu Serif.ttf', 154)
  65.     smallFont = pygame.font.SysFont('DejaVu Serif.ttf', 55)
  66.     smallerFont = pygame.font.SysFont('DejaVu Serif.ttf', 33)
  67.     screenState = 'start'
  68.     ligtGray = (128,128,128)
  69.     ligherGray = (150, 150, 150)
  70.     white = (255,255,255)
  71.     wasExitClicked = False
  72.  
  73.     def createOptionBoxes(self, configList):
  74.         self.screenResBox = InputBox(590,110,400,50,configList[0][1])
  75.         self.textToSpeechBox = InputBox(590,210,400,50,configList[1][1])
  76.         self.languageBox = InputBox(590,310,400,50,configList[2][1])
  77.         self.readAttackNameBox = InputBox(590,410,400,50,configList[3][1])
  78.         self.box = [self.screenResBox, self.textToSpeechBox, self.languageBox, self.readAttackNameBox]
  79.  
  80.     def didPressExit(self):
  81.         if self.wasExitClicked == True:
  82.             return True
  83.         for event in pygame.event.get():
  84.             if event.type == pygame.QUIT:
  85.                 return True
  86.             for box in self.box:
  87.                 box.handle_event(event)
  88.         return False
  89.  
  90.     def changeGameSence(self):
  91.         print("scene changed")
  92.  
  93.     def changeGameSenceToOption(self):
  94.         self.screenState = 'options'
  95.     def changeGameSenceToStart(self):
  96.         self.screenState = 'start'
  97.     def exitWasClicked(self):
  98.         self.wasExitClicked = True
  99.     def updateConfig(self):
  100.         content = []
  101.         for box in self.box:
  102.             content.append(box.text)
  103.         self.configUdater.configUpdate(content)
  104.         self.changeGameSenceToStart()
  105.  
  106.     def text_objects(self, text, font):
  107.         textSurface = font.render(text, True, self.white)
  108.         return textSurface, textSurface.get_rect()
  109.  
  110.     def button(self,screen, msg,x,y,w,h,action=None):
  111.         mouse = pygame.mouse.get_pos()
  112.         click = pygame.mouse.get_pressed()
  113.         if x+w > mouse[0] > x and y+h > mouse[1] > y:
  114.             pygame.draw.rect(screen, self.ligherGray,(x,y,w,h))
  115.  
  116.             if click[0] == 1 and action != None:
  117.                 action()
  118.         else:
  119.             pygame.draw.rect(screen, self.ligtGray,(x,y,w,h))
  120.  
  121.         textSurf, textRect = self.text_objects(msg, self.smallFont)
  122.         textRect.center = ( (x+(w/2)), (y+(h/2)) )
  123.         screen.blit(textSurf, textRect)
  124.  
  125.     def startScreen(self, screen):
  126.         name = self.Bigfont.render("MMO Rotation Tool", 1, self.white)
  127.         run = self.smallFont.render
  128.         screen.blit(name, (60, 60))
  129.         self.button(screen, "Run a Template", 340, 210, 400, 50, self.changeGameSence)
  130.         self.button(screen, "Create a Template", 340, 310, 400, 50, self.changeGameSence)
  131.         self.button(screen, "Options", 340,410,400,50, self.changeGameSenceToOption)
  132.         self.button(screen,"Exit",340,510,400,50, self.exitWasClicked)
  133.  
  134.     def OptionsScreen(self, screen):
  135.         for box in self.box:
  136.             box.update()
  137.             box.draw(screen)
  138.         self.button(screen, "Back",440,610,200,50, self.updateConfig)
  139.         screenResModeText = self.smallerFont.render("Screen Res Mode: ", 1, self.white)
  140.         textToSpeechText = self.smallerFont.render("Use Text To Speech:", 1, self.white)
  141.         languageText = self.smallerFont.render("Language For TTS:", 1, self.white)
  142.         readAttackNameText = self.smallerFont.render("Attack name read with TTS:", 1, self.white)
  143.         screen.blit(screenResModeText,(290,120))
  144.         screen.blit(textToSpeechText, (290, 220))
  145.         screen.blit(languageText, (290, 320))
  146.         screen.blit(readAttackNameText, (290, 420))
  147.  
  148.     def updateScreen(self, screen):
  149.         if self.screenState == 'start':
  150.             self.startScreen(screen)
  151.         elif self.screenState == 'options':
  152.             self.OptionsScreen(screen)
  153.  
  154. print("check for life")
  155.  
  156. class config:
  157.  
  158.     file_path = ".\data"
  159.     directory = os.path.dirname(file_path)
  160.  
  161.     def checkFolder(self):
  162.         try:
  163.             if not os.path.exists(self.file_path):
  164.                 os.mkdir(self.file_path)
  165.         except OSError:
  166.             print ('Error: Creating directory. ' + self.file_path)
  167.  
  168.     def createConfig(self):
  169.         self.checkFolder()
  170.         file = open("data/config.txt", "w+")
  171.         file.write("ScreenRes: 1\n")
  172.         file.write("TextToSpeach: True\n")
  173.         file.write("language: en\n")
  174.         file.write("ReadAttackName: True\n")
  175.  
  176.     def readConfig(self):
  177.         while True:
  178.             try:
  179.                 configFile = open("data/config.txt", "r")
  180.                 break
  181.             except FileNotFoundError:
  182.                 self.createConfig()
  183.             except Exception as e:
  184.                 print("Unknown error: " + str(e))
  185.  
  186.         configList = []
  187.         for line in configFile:
  188.             configLine = line.strip().split()
  189.             configList.append(configLine)
  190.         configFile.close()
  191.         return configList
  192.  
  193.     def configUpdate(self, content):
  194.         self.checkFolder()
  195.         file = open("data/config.txt", "w+")
  196.         file.write("ScreenRes: " + str(content[0]) + "\n")
  197.         file.write("TextToSpeach: " + str(content[1]) + "\n" )
  198.         file.write("language: " + str(content[2]) + "\n")
  199.         file.write("ReadAttackName: " +str(content[3]) + "\n")
  200. print("Mayhap if im lucky")
  201. class TexttoSpeech:
  202.     language = 'fn'
  203.  
  204.     def testTTS(self):
  205.         mytext = 'This is a test function to see if Text to speech is working!'
  206.         myobj = gTTS(text=mytext, lang=self.language)
  207.         myobj.save("data/test.mp3")
  208.         playsound("data/test.mp3")
  209. print("Still alive?")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement