Example #1
0
    def __init__(self, win, font, frameRate, version):
        self.win = win
        self.font = font
        self.frameRate = frameRate
        self.version = version

        self.width = int(self.win.get_width() * 0.8)
        self.height = int(self.win.get_height() * 0.8)

        self.x = (self.win.get_width() - self.width) / 2.0
        self.y = (self.win.get_height() - self.height) / 2.0

        self.backgroundFade = pygame.Surface(
            (self.win.get_width(), self.win.get_height()), pygame.SRCALPHA)
        self.backgroundFade.fill((255, 255, 255, 156))

        self.aboutBackground = pygame.Rect(
            0 + (self.win.get_width() - self.width) / 2.0,
            0 + (self.win.get_height() - self.height) / 2.0, self.width,
            self.height)

        self.button_back = Button("Back",
                                  (self.x + 20, self.height + self.y - 20),
                                  font=self.font)
        self.button_back.rect.y -= self.button_back.rect.h
        self.buttons = [self.button_back]

        self.aboutTitleText = TextBox('About:', (self.x + 20, self.y + 20),
                                      width=self.width - 40,
                                      backgroundColour=(150, 150, 150),
                                      font=self.font,
                                      fontSize='large')
        self.aboutText_1 = TextBox(
            "ReBel version {}".format(self.version[1:]),
            (self.x + 20, self.aboutTitleText.y + self.aboutTitleText.h + 7),
            width=self.width - 40,
            font=self.font,
            fontSize='small')
        self.aboutText_2 = TextBox("ReBel is a client-server-based multiuser online ringing software. Developed by Samuel M. Senior and " + \
                                   "open-sourced using the BSD-3-Clause license.",
                                   (self.x+20, self.aboutText_1.y+self.aboutText_1.h+10), width=self.width-40, font=self.font, fontSize='tiny')
        self.aboutText_3 = TextBox(
            "Source code can be downloaded from 'https://github.com/samuelsenior/ReBel'.",
            (self.x + 20, self.aboutText_2.y + self.aboutText_2.h + 10),
            width=self.width - 40,
            font=self.font,
            fontSize='tiny')
        self.aboutText_4 = TextBox(
            "The latest release can be downloaded from 'https://github.com/samuelsenior/ReBel/releases'.",
            (self.x + 20, self.aboutText_3.y + self.aboutText_3.h + 10),
            width=self.width - 40,
            font=self.font,
            fontSize='tiny')
        self.aboutText = [
            self.aboutTitleText, self.aboutText_1, self.aboutText_2,
            self.aboutText_3, self.aboutText_4
        ]
    def __init__(self,screen,cursor, clock, padre):
        resource.set_images_path(os.path.join("imagenes", "compartir"))
        self.background = resource.get_image("fondoCompartir.png")
        
        imgBtnEnviar = resource.get_image("botonEnviar.png")
        imgBtnEnviarSelec = resource.get_image("BotonesEnviar_selec.png")
        
        self.btnEnviar = Boton.Boton(imgBtnEnviar, imgBtnEnviarSelec, 700,550)
        
        
        
        self.screen = screen
        self.clock = clock
        self.tablero = padre

        self.mouse = mouse.Mouse()
        self.cursor = cursor
  
        self.inicio = True
        self.juego = False
        self.terminar = False
        self.envio = False
        self.letreroEnvio = False
        self.letreroNoEnvio = False
        self.CamposVacios = False
        

        self.tb1 = TextBox(position=(460,250),size=(400,25),textsize=22,editable=False)
        self.tb2 = TextBox(position=(460,300),size=(400,25),textsize=22,editable=False)
        self.contendora = textBox2.Contenedora()
        rutaFuente = os.path.join("fuentes", "PatrickHand-Regular.ttf")
        self.font = pygame.font.Font(rutaFuente, 22) 
        self.img=self.font.render("Nombre: ",1,(0,0,0))
        self.img2=self.font.render("Colegio: ",1,(0,0,0))
        self.img3=self.font.render("Mensaje: ",1,(0,0,0))
        
        
        resource.set_images_path(os.path.join("imagenes"))
        imgBtnRegresar = resource.get_image("boton_regresar.png")
        imgBtnRegresarSelec = resource.get_image("boton_regresar_selec.png")
        
        self.background2 = resource.get_image("Fondo.jpg", False)
        
        
        
        self.btnRegresar = Boton.Boton(imgBtnRegresar, imgBtnRegresarSelec, (1200 - 214 - 10), 10)
        
        self.msjInicio = MensajeEmergente.MensajeInicial(30, "Compartir")
        self.msjVacios = MensajeEmergente.MensajeInicial(30, "Compartir2")
        self.msjNoEnvio = MensajeEmergente.MensajeInicial(30, "Compartir3")
        self.msjEnvio = MensajeEmergente.MensajeInicial(30, "Compartir4")
Example #3
0
 def generate_textBoxs(self):
     group = []
     posx = self.posx + self.s_left + self.s_text_inter + self.text_sizex
     for i in range(0, 2):
         posy = self.posy + self.s_top + (self.items_sizey +
                                          self.s_between) * i
         group.append(
             TextBox(posx,
                     posy,
                     self.items_sizex,
                     self.items_sizey,
                     color=(176, 184, 196),
                     font_size=self.font_size))
     return group[:]
Example #4
0
    def generate_textBoxs(self):
        """
    Genera el arreglo de TextBoxes
    """
        group = []
        posx = self.posx + self.s_left + self.s_text_inter + self.menu_items_sizex
        for i in range(0, 2):
            group.append(
                TextBox(posx,
                        self.posy + self.s_top +
                        (self.items_sizey + self.s_between) * i,
                        self.items_sizex,
                        self.items_sizey,
                        color=(176, 184, 196),
                        font_size=self.font_size))

        return group[:]
Example #5
0
FPS = 50
fpsClock=pygame.time.Clock()

gameTable = (0, 10, 100, 100)

fontObj = pygame.font.Font(None, 32)                  # 현재 디렉토리로부터 myfont.ttf 폰트 파일을 로딩한다. 텍스트 크기를 32로 한다
dieSurface = fontObj.render('YOU DIED', True, RED)

grass = pygame.image.load("youwin.png")
dictimg = pygame.image.load("book.png")
gameover = pygame.image.load("heart.png")
dictimg = pygame.transform.scale(dictimg, (80, 30))
heartimg = pygame.image.load("heart.png")
heartimg = pygame.transform.scale(heartimg, (30, 30))

textBox = TextBox()
shiftDown = False
textBox.rect.center = [310, 400]


def main_window(speed, difficulty):
    word = Word('E')
    width, height = 640, 480
    screen = pygame.display.set_mode((width, height))
    pygame.display.set_caption("Mole Game")
    screen.fill(GREEN)

    running = True

    wordsLst = []  # [word || block_index || timer]
    mainTimer = 100 - speed
Example #6
0
def main():
    pygame.init()
    screen = pygame.display.set_mode((640, 480),pygame.SWSURFACE)
    pygame.key.set_repeat(100, 100)
    '''TEST'''
    g=Gui()
    #g.enableDirtyRect()
    g.optimizeDraw()
    i=PygameInput()
    Image.mImageLoader=PygameImageLoader()
    gr=PygameGraphics()
    gr.setTarget(screen)
    f=ImageFont("C:\Python25\Projects\Guichan\consolefont.bmp")
    #f=ImageFont("consolefont.bmp")
    f.setColorkey( Color(255,0,255) )
    f.setGlyphSpacing(2)
    f2=PygameFont("C:\Python25\Projects\Guichan\LiberationMono-Regular.ttf",14,Color(0,0,0,255))
    #f2=PygameFont("C:\Python25\Projects\Guichan\Caracteres L1.ttf",13,Color(0,0,0,255))
    f2.setGlyphSpacing(1)
    Widget.setGlobalFont(f2)
    
    c=Container()
    c.setOpaque(False)
    c.setPosition(0,0)
    c.setSize(640,480)
    c.setBaseColor( Color(255,0,0,255) )
    
    a=ActionListener()
    a.action=action
    b, b2=Button("YEY!"), Button("WHa?")
    b.setPosition(0,50)
    b.setActionEventId("Button 1")
    b.addActionListener(a)
    b2.setPosition(100,100)
    b2.setActionEventId("Button 2")
    b2.addActionListener(a)
    b2.setBaseColor( Color(200,200,200) )
    b2.setCaption("ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()")
    w,w2=Window("Hey over here!"), Window("Trapped in a window!")
    wColor=w.getBaseColor()
    wColor.a=200
    w.setBaseColor(wColor)
    w.setTextColor(Color(255,0,255))
    xyz=Button("XYZ")
    xyz.setTextColor(Color(0,255,255))
    pb=ProgressBar(100.0)
    pb.setBaseColor( Color(255,255,0) )
    pb.setForegroundColor( Color(0,255,255) )
    pb.setSize(100, 20)
    pb.setPosition(300, 300)
    pb.setValue(50.0)
    c.add(w,0,100)
    c.add(b)
    c.add(b2)
    c.add(xyz,10,10)
    c.add(pb)
    
    check=Checkbox("Ye what? GET BACK HERE BOY!")
    check.setActionEventId("Checkbox")
    check.addActionListener(a)
    text=TextField("Hey Hey Hey Hey Hey Hey Hey Hey")
    text.setBackgroundColor( Color(255,255,255,255) )
    text.setMaxSize(150)
    text2=TextBox("Hey, HeyTrapped in a window!\nWhat's goin' onTrapped in a window!\ntodays???Trapped in a window!")
    text2.setTabSize(10)
    sc=ScrollArea(text2)
    sc.setSize(200,100)
    rBox=Container()
    r1=RadioButton("1984","Dystopia")
    r2=RadioButton("Fahrenheit 451","Dystopia")
    r3=RadioButton("Brave New World","Dystopia")
    rBox.add(r1,0,0)
    rBox.add(r2,0,r1.getY()+r1.getHeight())
    rBox.add(r3,0,r2.getY()+r2.getHeight())
    label=Label("WE AIN'T GOT IT")
    ico_image=Image.load("C:\Python25\Projects\Guichan\May.bmp")
    ico=Icon(ico_image)
    lb=ListBox( List_ListModel(["Bollocks!","Never!","Cuppa tea, mate?","Hello!","Goodbye!","OK Computer!","Oh Inverted World!","How To Disappear Completely!","Hold Still!","It Takes A Train To Cry!","A","B","C","D","E","F","G","H","I",]) )
    sc2=ScrollArea(lb)
    sc2.setSize(125,100)
    lb.setWidth(110)
    slider=Slider(0,100)
    slider.setOrientation(Slider.Orientation.VERTICAL)
    slider.setSize(15,100)
    slider.setActionEventId("Slider")
    #slider.addActionListener(a)
    ib=ImageButton(ico_image)
    ta=TabbedArea()
    c.add(w2)
    ta.addTab("Text",[ (text,0,0), (sc,0,50) ])
    ta.addTab("Check",check)
    ta.addTab("Radio",rBox)
    ta.addTab("List",[ (sc2,0,0) ])
    ta.addTab("Label",label)
    ta.addTab("Icon",[ (ico,0,0), (ib,100,0) ])
    ta.addTab("Slider",slider)
    ta.setSize(300,300)
    w2.add(ta,0,0)
    g.setGraphics(gr)
    w2.resizeToContent()
    w.setSize(300,300)
    g.setInput(i)
    g.setTop(c)
    clock=pygame.time.Clock()
    
    g.mDirtyRect.addRect( Rectangle(0,0,640,480) )
    done=False
    while done == False:
        clock.tick(0)

        for event in pygame.event.get():
            if event.type==KEYDOWN:
                if event.key == K_ESCAPE:
                    c.remove(b)
                    c.remove(b2)
                    done=True
                
                elif event.key == K_RETURN:
                    w=Window("It'a window!")
                    w.add(Checkbox("Kool thing"))
                    w.resizeToContent()
                    c.add(w, 10, 10)
                    
                elif event.key == K_LEFT:
                    pb.setValue( pb.getValue()-1.0 )
                elif event.key == K_RIGHT:
                    pb.setValue( pb.getValue()+1.0 )                
                    
            if event.type == ACTIVEEVENT:
                if event.gain == 1:
                    g.mDirtyRect.addRect( Rectangle(0,0,640,480) )
                    
            i.pushInput(event)
            g.logic()
            
        b2.setCaption( str( int(clock.get_fps()) ) )
        fRect=GuichanToPygameDirtyRect(g.mDirtyRect.getList())
        #for ix in fRect: screen.fill((255,0,0),ix)
        
        screen.fill((255,0,0))    
        g.draw()
        #pygame.display.update( GuichanToPygameDirtyRect(g.mDirtyRect.getList()) )
        pygame.display.update()
        
        g.mDirtyRect.clearList()
class Compartir(object):
    
    
    def __init__(self,screen,cursor, clock, padre):
        resource.set_images_path(os.path.join("imagenes", "compartir"))
        self.background = resource.get_image("fondoCompartir.png")
        
        imgBtnEnviar = resource.get_image("botonEnviar.png")
        imgBtnEnviarSelec = resource.get_image("BotonesEnviar_selec.png")
        
        self.btnEnviar = Boton.Boton(imgBtnEnviar, imgBtnEnviarSelec, 700,550)
        
        
        
        self.screen = screen
        self.clock = clock
        self.tablero = padre

        self.mouse = mouse.Mouse()
        self.cursor = cursor
  
        self.inicio = True
        self.juego = False
        self.terminar = False
        self.envio = False
        self.letreroEnvio = False
        self.letreroNoEnvio = False
        self.CamposVacios = False
        

        self.tb1 = TextBox(position=(460,250),size=(400,25),textsize=22,editable=False)
        self.tb2 = TextBox(position=(460,300),size=(400,25),textsize=22,editable=False)
        self.contendora = textBox2.Contenedora()
        rutaFuente = os.path.join("fuentes", "PatrickHand-Regular.ttf")
        self.font = pygame.font.Font(rutaFuente, 22) 
        self.img=self.font.render("Nombre: ",1,(0,0,0))
        self.img2=self.font.render("Colegio: ",1,(0,0,0))
        self.img3=self.font.render("Mensaje: ",1,(0,0,0))
        
        
        resource.set_images_path(os.path.join("imagenes"))
        imgBtnRegresar = resource.get_image("boton_regresar.png")
        imgBtnRegresarSelec = resource.get_image("boton_regresar_selec.png")
        
        self.background2 = resource.get_image("Fondo.jpg", False)
        
        
        
        self.btnRegresar = Boton.Boton(imgBtnRegresar, imgBtnRegresarSelec, (1200 - 214 - 10), 10)
        
        self.msjInicio = MensajeEmergente.MensajeInicial(30, "Compartir")
        self.msjVacios = MensajeEmergente.MensajeInicial(30, "Compartir2")
        self.msjNoEnvio = MensajeEmergente.MensajeInicial(30, "Compartir3")
        self.msjEnvio = MensajeEmergente.MensajeInicial(30, "Compartir4")
    
    def enviarDatos(self):
        
        if(self.tb1.text=="-" or self.tb1.text=="|" or self.tb1.text=="" or self.tb2.text=="-" or self.tb2.text=="|" or self.tb2.text==""):
            pass
        else:

            try:
                url = 'http://valorar.somee.com/api/Servicio'
                
                payload = {'Nombre':self.tb1.text, 'Msg':self.contendora.texto(), 'Valor':self.valor, 'Colegio':self.tb2.text, 'Actividad':self.actividad, 'Fecha':datetime.datetime.now().strftime("%Y-%m-%d %H:%M")}
                headers = {'content-type': 'application/json'}
                r = requests.post(url, data = json.dumps(payload), headers = headers)
                self.envio = True
                
            except Exception as e:
                    # Se alista todo para una nueva conexion
                    self.envio = False
        
    def reiniciar(self):
        self.inicio = True
        self.juego = False
        self.terminar = False
        self.envio = False
        self.letreroEnvio = False
        self.letreroNoEnvio = False
        self.CamposVacios = False
        
        self.tb1.reiniciar()
        self.tb2.reiniciar()
        self.contendora.reiniciar()
        
    def run(self,valor,actividad):
        
        
        self.valor = valor
        self.actividad = actividad
        self.reiniciar()
        self.tb1.text = self.tablero.personaje.nombre
        self.tb2.text = self.tablero.personaje.colegio
        
        while not self.terminar:
            for event in pygame.event.get():
                if self.juego:
                    self.tb1.Event(event)
                    self.tb2.Event(event)
                self.contendora.Event(event)
                if event.type == pygame.QUIT: 
                    sys.exit()
                   
                if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
                        self.mouse.rect.center = pygame.mouse.get_pos() 
                        
                        if self.cursor.colliderect(self.btnRegresar.rect):
                            self.tablero.sonido2.stop()
                            self.terminar = True
                            self.tablero.sonido.play(-1)
                            self.tablero.run()
                        
                        if self.juego and self.cursor.colliderect(self.btnEnviar.rect):
                            
                            if self.tb1.text.strip() =="" or self.tb2.text.strip() == "" or self.contendora.texto().strip() == "":
                                self.juego = False
                                self.CamposVacios = True
                            else:
                                self.juego = False
                                self.enviarDatos()
                                if self.envio:
                                    self.letreroEnvio = True
                                else:
                                    self.letreroNoEnvio = True
      
                        if self.cursor.colliderect(self.msjInicio.btn.rect) and self.inicio:
                            self.msjInicio.visible = False
                            self.inicio = False
                            self.juego = True
                            
                        elif (self.letreroEnvio and self.cursor.colliderect(self.msjEnvio.btn.rect)) or (self.letreroNoEnvio and self.cursor.colliderect(self.msjNoEnvio.btn.rect)):
                            self.terminar = True
                            self.tablero.sonido2.stop()
                            self.tablero.sonido.play(-1)
                            self.tablero.run()
                            
                        elif self.CamposVacios and self.cursor.colliderect(self.msjVacios.btn.rect):
                            self.msjVacios.visible = False
                            self.juego = True
                            self.CamposVacios = False
                            
                            
                        
                        
                            
                            
            self.screen.fill((0,0,0)) 
            self.screen.blit(self.background2,(0,0))                   
            self.screen.blit(self.background,(0,0))
            
            
            self.screen.blit(self.img,(380,245))   
            self.screen.blit(self.img2,(380,295))      
            self.screen.blit(self.img3,(380,340))   
            self.tb1.Draw(self.screen)
            self.tb2.Draw(self.screen)
            self.contendora.draw(self.screen)
            self.cursor.update()
            
            if self.inicio:
                self.msjInicio.visible = True
                self.btnRegresar.update(self.screen, self.cursor)
                self.msjInicio.update(self.screen, self.cursor)
                
            elif self.juego:
                self.btnRegresar.update(self.screen, self.cursor)
                self.btnEnviar.update(self.screen, self.cursor)
            
            elif self.letreroEnvio:
                self.msjEnvio.update(self.screen, self.cursor)      
                self.msjEnvio.visible = True
                self.btnRegresar.update(self.screen, self.cursor)
            
            elif self.letreroNoEnvio:
                self.msjNoEnvio.update(self.screen, self.cursor)      
                self.msjNoEnvio.visible = True
                self.btnRegresar.update(self.screen, self.cursor)
            
            elif self.CamposVacios:
                self.msjVacios.update(self.screen, self.cursor)      
                self.msjVacios.visible = True
                self.btnRegresar.update(self.screen, self.cursor)
            
            self.clock.tick(60)
            
            
            pygame.display.update() 
            
Example #8
0
 def openTextBox(self, label):
     self.state = "inTextBox"
     self.imageStorage = self.image
     self.textBox = TextBox(label,(600,600), (15,15), self.theFont, self.imgFolder)
     self.image.fill((0,0,0))
     self.image.blit(self.textBox.getImage(), self.textBox.getRect())
Example #9
0
class RecipeReciever(Sprite):
    def __init__(self, mode, imgdir, ingParser):
        Sprite.__init__(self)

        self.fields = [["Title","Instructions","IngredientList","Description","Rating"],
                  [True,True,True,True,True]]

        self.focus = None
        self.allTextBoxes = []
        self.allButtons = []
        self.recipeDict = {}
        self.belowTextBorder = 50
        self.imgFolder = imgdir

        ## we might need to create this in the main program
        # when we implement the database of keywords
        # so we can pass them to the parser withotu passing them here first
        # but for now this is ok
        self.ingredientParser = ingParser

        # store None so we can know wether to erase it or not
        self.imageCreated = False

        self.state = "awaitingInput"

        if not pygame.font.get_init():
            pygame.font.init()
        #self.theFont = pygame.font.Font(None, 30)
        self.theFont = pygame.font.Font("freesansbold.ttf", 15)
        
        if mode == "addRecipePage":
            self.createImage()

            self.rect = self.image.get_rect()

    def createImage(self):
        if self.imageCreated:
            self.image.fill((0,0,0))

        self.allTextBoxes = []
        self.allButtons = []
            
        totalHeight = 10
        i = 0
        doneCount = 0
        #print "FIELDS:", self.fields[0]
        #print "       ", self.fields[1]
        #tally the height
        for f in self.fields[0]:
            self.allTextBoxes.append(TextBlock(f + ":", f + ":", self.theFont, totalHeight))

            if self.fields[1][i]:
                self.allButtons.append(Button(self.imgFolder, "textButton",
                                (self.allTextBoxes[i].getImage().get_width() + 15, totalHeight),
                                            f, -1))
                self.allButtons[i].addText("Add Data")
            else:
                self.allButtons.append(Button(self.imgFolder, "checkBox",
                                (self.allTextBoxes[i].getImage().get_width() + 15, totalHeight),
                                            "nothing", -1))
                doneCount += 1
            
            totalHeight += self.allTextBoxes[i].getImage().get_height() + self.belowTextBorder
            i+=1

        totalHeight += 120
        self.image = pygame.Surface((400, totalHeight))
                
        for button in self.allButtons:
            self.image.blit(button.getImage(), button.getRect())
        for text in self.allTextBoxes:
            self.image.blit(text.getImage(), text.getRect())

        if doneCount >= 5:
            doneButton = Button(self.imgFolder, "textButton", (150, totalHeight - 100),
                                       "submitRecipe", -1)
            doneButton.addText("Submit Recipe")
            self.allButtons.append(doneButton)
            self.image.blit(doneButton.getImage(), doneButton.getRect())
            
        self.imageCreated = True
            
    def isClicked(self, xy):
        # need to scale the xy value to be relative to the recipeReciever window
        x,y = xy
        x -= self.rect.left
        y -= self.rect.top
        xy = x,y
        
        ## awaitingInput is the main screen with all the various buttons
        if self.state == "awaitingInput":    
            found = False
            for button in self.allButtons:
                if not button.getIdentity() == "nothing":
                    if button.getRect().collidepoint(xy):
                        if not button.getIdentity() == "submitRecipe":
                            self.openTextBox(button.getIdentity())
                        else: ## send the recipe back to the main program
                            return self.recipeDict
                    
        elif self.state == "inTextBox":
            infoReturned = self.textBox.isClicked(xy)
            if not (infoReturned == None):
                if self.textBox.getIdentity() == "IngredientList":
                    ## in case s is one giant string, as it probably will be
                    # we need to break it up into individual lines,
                    # based on the split characters, which seem to be
                    # /n for python but /r for everything else

                    ## need to create some kind of error catching here as well
                    # and everywhere just in case there is illegal input
                    # but we will do that later
                    #print "info Returned: "
                    #print infoReturned                    

                    ## the general format is this:
                    # ingredientParser.passString(infoReturned)
                    #       info returned is a giant block of text
                    #       subdivided by /r/n or /n, into individual lines
                    #       each containing an ingredient

                    ## result = ingredientParser.parse()
                    #       this returns the progress of the ingredientParser
                    #       for example, if the parser is stuck on something
                    #       it will put in its "message" field info regarding
                    #       asking clarification of the user, which can then
                    #       be handled by the GUI
                    #       -- otherwise this will return an "done" which is
                    #       then tells the GUI to get the finishedMessage

                    self.ingredientParser.passString(infoReturned)
                    result = self.ingredientParser.parse()
                    while (not (result == "done")):
                        result = self.ingredientParser.parse()

                    # this data needs to be in the form
                    # name?(, modifiers) amount unitString
                    ## NOT IN INGREDIENT OBJECT FORM!
                    infoReturned = self.ingredientParser.getFinishedIngredientList()
                        
                    #print
                    #print
                    #print "the new info returned:"
                    #print infoReturned

                    fieldName = "IngredientList"
                

                    #ping!!!

                    ## make a GUI Error here (bad InputError) or something
                    # that when they enter ingredients it checks they
                    # are of the right format... or throws an error
                    # and pulls up the AlertBox (which we have yet to make)
                    # that tells the user of their mistake.

                    # this alert box also should be the same class that confirms
                    # deleting recipes and such...


                ##  from now on, we should always clarify in comments what is being
                # returned in complex situations like this
                # recipeDict goes back to the main program, whereupon
                # Main send the dictionary to Recipe.fromDictionary(recipeDict)
                # which then goes to Ingredient.fromString()                
                self.recipeDict[self.textBox.getIdentity()] = infoReturned
                i = self.fields[0].index(self.textBox.getIdentity())
                self.fields[1][i] = False
                self.createImage()
                self.state = "awaitingInput"
                                        

    def recieveClipboardPaste(self, string):
        if self.state == "inTextBox":
            self.textBox.addText(string)
            self.image.blit(self.textBox.getImage(), self.textBox.getRect())

    def openTextBox(self, label):
        self.state = "inTextBox"
        self.imageStorage = self.image
        self.textBox = TextBox(label,(600,600), (15,15), self.theFont, self.imgFolder)
        self.image.fill((0,0,0))
        self.image.blit(self.textBox.getImage(), self.textBox.getRect())

    def scroll(self, dy):
        pass
Example #10
0
    def __init__(self, win, font, frameRate):
        self.win = win
        self.font = font
        self.frameRate = frameRate

        self.width = int(self.win.get_width() * 0.8)
        self.height = int(self.win.get_height() * 0.8)

        self.x = (self.win.get_width() - self.width) / 2.0
        self.y = (self.win.get_height() - self.height) / 2.0

        self.backgroundFade = pygame.Surface((self.win.get_width(), self.win.get_height()), pygame.SRCALPHA)
        self.backgroundFade.fill((255, 255, 255, 156))

        self.helpBackground = pygame.Rect(0 + (self.win.get_width() - self.width) / 2.0, 0 + (self.win.get_height() - self.height) / 2.0, self.width, self.height)

        self.button_back = Button("Back", (self.x + 20, self.height + self.y - 20), font=self.font)
        self.button_back.rect.y -= self.button_back.rect.h
        #
        self.button_serverPage = Button("Server", (self.x + self.width - 20, self.y + 20), font=self.font)
        self.button_serverPage.rect.x -= self.button_serverPage.rect.w
        #
        self.button_ringingPage = Button("Ringing", (self.button_serverPage.x - self.button_serverPage.rect.w - 10, self.y + 20), font=self.font)
        self.button_ringingPage.rect.x -= self.button_ringingPage.rect.w
        #
        self.buttons = [self.button_back, self.button_ringingPage, self.button_serverPage]

        self.serverTitleText = TextBox('Server Help:',
                                       (self.x+20, self.y+self.button_serverPage.rect.h+20), width=self.width-40, backgroundColour=(150, 150, 150), font=self.font, fontSize='large')
        self.serverSubTitleText = TextBox('Connecting to a server:',
                                          (self.x+20, self.serverTitleText.y+self.serverTitleText.h+10), width=self.width-40, font=self.font, fontSize='small')
        self.serverText_1 = TextBox("In 'Your Name' enter your name.",
                                    (self.x+20, self.serverSubTitleText.y+self.serverSubTitleText.h+7), width=self.width-40, font=self.font, fontSize='tiny')
        self.serverText_2 = TextBox("In 'Server IP' enter the public IP of the server as told by the person running the server, or the local IP of the " + \
                                    "server if on the same network, or leave it blank if you are on the same machine as the one runnning the server.",
                                    (self.x+20, self.serverText_1.y+self.serverText_1.h+10), width=self.width-40, font=self.font, fontSize='tiny')
        self.serverText_3 = TextBox("Leave 'Server Port' as the default value if the person running the server hasn't changed it, " + \
                                    "otherwise change it to the number they give.",
                                    (self.x+20, self.serverText_2.y+self.serverText_2.h+10), width=self.width-40, font=self.font, fontSize='tiny')
        self.serverText_4 = TextBox("Once these details have been entered click 'Connect to Server'. If you are able to connect to the " + \
                                    "server successfully a 'Connected' message will appear, if not a 'Server Offline' message will appear. " +
                                    "If you can't connect make sure to check your internet connection, the server IP, and the server port.",
                                    (self.x+20, self.serverText_3.y+self.serverText_3.h+10), width=self.width-40, font=self.font, fontSize='tiny')
        self.serverText_5 = TextBox("To reconnect to a server or to connect to a new one go back to the home screen, enter in the " + \
                                    "details of the new server (or leave the original details in if reconnecting), then click 'Connect " +
                                    "to Server' and then click 'Start Ringing' like normal.",
                                    (self.x+20, self.serverText_4.y+self.serverText_4.h+10), width=self.width-40, font=self.font, fontSize='tiny')
        self.serverText = [self.serverTitleText, self.serverSubTitleText, self.serverText_1, self.serverText_2, self.serverText_3, self.serverText_4, self.serverText_5]

        self.ringingTitleText = TextBox('Ringing Help:',
                                        (self.x+20, self.y+self.button_serverPage.rect.h+20), width=self.width-40, backgroundColour=(150, 150, 150), font=self.font, fontSize='large')
        self.ringingSubTitleText_1 = TextBox('Ringing Keys:',
                                             (self.x+20, self.ringingTitleText.y+self.ringingTitleText.h+10), width=self.width-40, font=self.font, fontSize='small')
        self.ringingText_1 = TextBox("By default bells 1 and 2 are set as the ringable and are rung with the 'j' and 'f' keys.",
                                     (self.x+20, self.ringingSubTitleText_1.y+self.ringingSubTitleText_1.h+7), width=self.width-40, font=self.font, fontSize='tiny')
        self.ringingText_2 = TextBox("All the bells can be configured to be rung and can be set to use any letter or number key. The key bindings are " + \
                                     "set in the 'Options' menu found in the ringing screen.",
                                     (self.x+20, self.ringingText_1.y+self.ringingText_1.h+10), width=self.width-40, font=self.font, fontSize='tiny')
        self.ringingText_3 = TextBox("The bell you set as your first bell will be placed at the bottom of the ringing circle, just to the right of the " + \
                                     "center.",
                                     (self.x+20, self.ringingText_2.y+self.ringingText_2.h+10), width=self.width-40, font=self.font, fontSize='tiny')
        self.ringingSubTitleText_2 = TextBox('Bell Tunings and Scales:',
                                             (self.x+20, self.ringingText_3.y+self.ringingText_3.h+16), width=self.width-40, font=self.font, fontSize='small')
        self.ringingText_4 = TextBox("By default the bells are in the key of C and are generated from a size 15 handbell in C. The key of the bells can " + \
                                     "changed by shifting them by both an integer number of semitones and an integer number of octaves. Currently this " + \
                                     "can only be done by manually changing the config file.",
                                     (self.x+20, self.ringingSubTitleText_2.y+self.ringingSubTitleText_2.h+10), width=self.width-40, font=self.font, fontSize='tiny')
        self.ringingText_5 = TextBox("The bells are tuned to a major scale by default though they can also be changed to natural, harmonic, and melodic " + \
                                     "minor scales. Currently this can only be done manually changing the config file.",
                                     (self.x+20, self.ringingText_4.y+self.ringingText_4.h+10), width=self.width-40, font=self.font, fontSize='tiny')
        
        self.ringingText = [self.ringingTitleText, self.ringingSubTitleText_1, self.ringingText_1, self.ringingText_2, self.ringingText_3]#,
Example #11
0
    def __init__(self, win, font, config, frameRate):
        self.win = win
        self.font = font
        self.config = config
        self.frameRate = frameRate

        self.bellKeysUpdated = False

        self.width = int(self.win.get_width() * 0.8)
        self.height = int(self.win.get_height() * 0.8)

        self.x = (self.win.get_width() - self.width) / 2.0
        self.y = (self.win.get_height() - self.height) / 2.0

        self.backgroundFade = pygame.Surface(
            (self.win.get_width(), self.win.get_height()), pygame.SRCALPHA)
        self.backgroundFade.fill((255, 255, 255, 156))

        self.optionsBackground = pygame.Rect(
            0 + (self.win.get_width() - self.width) / 2.0,
            0 + (self.win.get_height() - self.height) / 2.0, self.width,
            self.height)

        self.button_back = Button("Cancel",
                                  (self.x + 20, self.height + self.y - 20),
                                  font=self.font)
        self.button_back.rect.y -= self.button_back.rect.h
        #
        self.button_save = Button(
            "Save", (self.x + self.width - 20, self.height + self.y - 20),
            font=self.font)
        self.button_save.rect.x -= self.button_save.rect.w
        self.button_save.rect.y -= self.button_save.rect.h
        #
        self.button_other = Button("Other",
                                   (self.x + self.width - 20, self.y + 20),
                                   font=self.font)
        self.button_other.rect.x -= self.button_other.rect.w
        #
        self.button_tuning = Button(
            "Tuning",
            (self.button_other.x - self.button_other.rect.w - 10, self.y + 20),
            font=self.font)
        self.button_tuning.rect.x -= self.button_tuning.rect.w
        #
        self.button_keys = Button(
            "keys", (self.button_tuning.x - self.button_tuning.rect.w - 10,
                     self.y + 20),
            font=self.font)
        self.button_keys.rect.x -= self.button_keys.rect.w
        #
        self.buttons = [
            self.button_back, self.button_save
        ]  #, self.button_keys, self.button_tuning, self.button_other]

        self.keysTitleText = TextBox(
            'Keys Options:',
            (self.x + 20, self.y + self.button_keys.rect.h + 20),
            width=self.width - 40,
            backgroundColour=(150, 150, 150),
            font=self.font,
            fontSize='large')
        self.keysSubTitleText_1 = TextBox(
            'Bell Keys:',
            (self.x + 20, self.keysTitleText.y + self.keysTitleText.h + 10),
            width=self.width - 40,
            font=self.font,
            fontSize='small')
        self.keysText_1 = TextBox(
            "In the 'Ringable Bells' row of boxes enter in the bell numbers of the bells that you want to ring.",
            (self.x + 20,
             self.keysSubTitleText_1.y + self.keysSubTitleText_1.h + 7),
            width=self.width - 40,
            font=self.font,
            fontSize='tiny')
        self.keysText_2 = TextBox(
            "In the 'Key Press' row of boxes enter in the keys you want to press to ring each bell.",
            (self.x + 20, self.keysText_1.y + self.keysText_1.h + 10),
            width=self.width - 40,
            font=self.font,
            fontSize='tiny')
        self.keysText_3 = TextBox(
            "Each 'Key Press' box corresponds to the 'Ringable Bell' box above it.",
            (self.x + 20, self.keysText_2.y + self.keysText_2.h + 10),
            width=self.width - 40,
            font=self.font,
            fontSize='tiny')
        self.keysText_4 = TextBox("Only numbers can be entered into the 'Ringable Bell' boxes and only letters and numbers can be entered " + \
                                  "into the 'Key Press' boxes.",
                                  (self.x+20, self.keysText_3.y+self.keysText_3.h+10), width=self.width-40, font=self.font, fontSize='tiny')
        self.keysText = [
            self.keysTitleText, self.keysSubTitleText_1, self.keysText_1,
            self.keysText_2, self.keysText_3, self.keysText_4
        ]

        self.tuningTitleText = TextBox(
            'Tuning Options:',
            (self.x + 20, self.y + self.button_tuning.rect.h + 20),
            width=self.width - 40,
            backgroundColour=(150, 150, 150),
            font=self.font,
            fontSize='large')
        self.tuningSubTitleText_1 = TextBox(
            'Octave and Semitone Shift:',
            (self.x + 20,
             self.tuningTitleText.y + self.tuningTitleText.h + 10),
            width=self.width - 40,
            font=self.font,
            fontSize='small')
        self.tuningText_1 = TextBox("... still to do...",
                                    (self.x + 20, self.tuningSubTitleText_1.y +
                                     self.tuningSubTitleText_1.h + 7),
                                    width=self.width - 40,
                                    font=self.font,
                                    fontSize='tiny')
        self.tuningText = [
            self.tuningTitleText, self.tuningSubTitleText_1, self.tuningText_1
        ]

        self.otherTitleText = TextBox(
            'Other Options:',
            (self.x + 20, self.y + self.button_other.rect.h + 20),
            width=self.width - 40,
            backgroundColour=(150, 150, 150),
            font=self.font,
            fontSize='large')
        self.otherSubTitleText_1 = TextBox(
            '...:',
            (self.x + 20, self.otherTitleText.y + self.otherTitleText.h + 10),
            width=self.width - 40,
            font=self.font,
            fontSize='small')
        self.otherText_1 = TextBox("... still to do...",
                                   (self.x + 20, self.otherSubTitleText_1.y +
                                    self.otherSubTitleText_1.h + 7),
                                   width=self.width - 40,
                                   font=self.font,
                                   fontSize='tiny')
        self.otherText = [
            self.otherTitleText, self.otherSubTitleText_1, self.otherText_1
        ]