def deleteStack(self,cual):
        Application.putOnDeleteList(self.stacks[cual])
        del self.stacks[cual]
        self.i-= 1

        x=cual
        while( x< len(self.stacks)):
            self.stacks[x].Reposition(x)
            x+=1
    def BotonPlayStop(self):
        self.playingStepByStep = False
        image = sf.Image()
        if self.playing:
            self.working_area.DetenerEjecucion()
            self.working_area.ResetConfigs()
            self.function_set.ResetConfigs()
            Application.putOnDeleteList(self.message)
            self.message = None

            image.LoadFromFile(self.DIRECTORIO + "gameplay/play_1.png")
            self.botonPlayStop.SetImage(image)
        else:
            self.working_area.Ejecutar(self.function_set)
            image.LoadFromFile(self.DIRECTORIO + "gameplay/stop_1.png")
            self.botonPlayStop.SetImage(image)

        self.playing = not self.playing
    def Update(self):
        self.temp = None
        input = self.window.GetInput()
        self.DefinirFondo()
        self.DefinirBotones()
        q = False
        while not q:
            x = input.GetMouseX()
            y = input.GetMouseY()
            boton = self.BotonHovered(x, y)
            frameTime = self.window.GetFrameTime()

            while self.window.GetEvent(self.Evento):
                if self.slider.Update(frameTime, self.Evento, x, y) == True:
                    self.working_area.SetVelocity(self.slider.GetVelocity())

                if self.Evento.Type == sf.Event.Closed:
                    q = True
                    if self.sonidos != None:
                        self.sonidos.StopMenuMusic()
                    self.window.Close()

                if self.Evento.Type == sf.Event.MouseButtonPressed:
                    print(str(x) + "," + str(y))
                    self.instruction_name = self.toolbox.InstructionToolboxClicked(x, y)
                    ins = self.instruction_name
                    if ins != None and (not self.playing):
                        if ins != "INS_CLEAR":
                            if self.temp == None:
                                self.temp = self.DuplicateInstruction(ins)
                            else:
                                self.temp.SetImage(self.GetImage(ins))

                            self.dragging_instruction = True
                        else:
                            self.function_set.Clear()
                            self.toolbox.DisableClear()
                    else:
                        if not self.playing:
                            t = self.function_set.InstructionClicked(x, y, self)
                            if self.function_set.GetCount() == 0:
                                self.toolbox.DisableClear()
                        else:
                            t = False
                        if not t:
                            if boton == "BACK":
                                self.BotonBack()
                            elif boton == "HOME":
                                self.BotonHome()
                            elif boton == "PLAY_STOP":
                                self.BotonPlayStop()
                            elif boton == "STEP":
                                self.BotonNextStep()
                            elif boton == "TEST":
                                self.window.GetView().Zoom(1.01)
                            elif boton == "FADE":
                                Application.putOnDeleteList(self.message)
                                self.message = None
                if self.Evento.Type == sf.Event.MouseButtonReleased:
                    if self.dragging_instruction:
                        res = self.function_set.PlaceInstruction(x, y)
                        if res[0]:
                            if self.function_set.InsertInstruction(res[1], res[2], self.temp, self.instruction_name):
                                self.toolbox.EnableClear()
                                self.temp = None

                        self.dragging_instruction = False
            if self.playing or self.playingStepByStep:
                resuelto = self.working_area.Update(frameTime)
                if resuelto == True:
                    self.EndPuzzle()
            self.window.Clear(sf.Color(255, 255, 255))
            self.Pintar(boton)
            self.goal.Pintar(self.window)
            self.working_area.Pintar(self.window)
            self.window.Draw(self.delimiter)

            self.toolbox.Pintar(self.window)
            self.slider.Pintar(self.window)
            self.function_set.Pintar(self.window)
            if self.dragging_instruction:
                self.temp.SetPosition(x - 22, y - 22)
                self.window.Draw(self.temp)
            if self.message != None:
                self.message.Pintar(self.window)
            self.window.Display()
 def ResetConfigs(self):
     self.cable_height = self.base_cable_size[1]
     self.cable.Resize(self.base_cable_size[0], self.base_cable_size[1])
     if self.attachedBox != None:
         Application.putOnDeleteList(self.attachedBox)
         self.attachedBox = None
 def ResetConfigs(self):
     while len(self.stack)>0:
         Application.putOnDeleteList(self.stack.pop())
     self.setInitialState(self.stack_id, self.level_name, self.puzzle_number, self.scale, self.scenario_boundaries, self.final, self.stack_desp)
 def RemoveInstruction(self, pos):
     Application.putOnDeleteList(self.instructions[pos])
     self.instructions[pos] = None
    def Update(self):
        input = self.window.GetInput()
        self.DefinirFondo()
        self.DefinirdeleteStackBoton()
        self.DefiniraddStackBoton()
        self.DefinirSaveBoton()
        
        q = False
        
        while not q:
            x = input.GetMouseX()
            y = input.GetMouseY()
            boton = self.BotonHovered(x, y)
            frameTime = self.window.GetFrameTime()        
            while self.window.GetEvent(self.Evento):
                print self.Evento.Type
                if self.Evento.Type == sf.Event.Closed:
                    self.window.Close()

                if self.Evento.Type == sf.Event.MouseButtonPressed:
                    self.box_name = self.tools.InstructionToolboxClicked(x, y)
                    
                    ins = self.box_name
                    print(str(x))
                    print(str(y))
                    
                    if ins != None:
                        if ins != "INS_CLEAR":
                            if self.temp == None:
                                print("entro aqui y no debe")
                                self.temp = self.DuplicateBox(ins)
                            else:
                                self.temp.SetImage(self.GetImage(ins))
                                

                            self.dragging_box = True
                    
                        else:
                            self.goal.Clear()
                            self.scenario.Clear()
                        
                       
                    else:
                    #    cual = self.BotonHovered(x,y)
                       
                                    
                        if boton == "ADDSTACK":
                            self.scenario.addStack()
                            self.goal.addStack()
                        if boton == "DELETESTACK":
                            
                            self.deleteicon = True
                            clickstack = False
                            print("por aki 1 .....")
                        if boton == "SAVE":
                            self.xml.Generar(self.scenario,self.goal)
                        if self.deleteicon == True:
                            print("por aki 2 .....")

                            if boton != None:
                                print("por aki3 .....")
                                if boton != "ADDSTACK" and boton != "DELETESTACK" and boton !="SAVE":
                                    clickstack = True
                                #    print(cual)
                                
                            if clickstack == True:
                                print("por aki 4 .....")
                                self.scenario.deleteStack(boton[1])
                                self.goal.deleteStack(boton[1])
                                self.deleteicon = False
                        else:
                            if boton is not None:
                                if boton != "ADDSTACK" and boton != "DELETESTACK" and boton != "SAVE":
                                    if boton[0] == "scene":
                                        ift=self.scenario.BoxClicked(x,y,boton[1])
                                    if boton[0] == "goal":
                                        ift=self.goal.BoxClicked(x,y,boton[1])
                                    #self.temp = self.goal.BoxClicked(x,y,boton[1])[0]
                                    self.temp = ift[0]
                                    #ins = self.goal.BoxClicked(x,y,boton[1])[1]
                                    ins = ift[1]
                                    self.dragging_box = True
                           
                                    

                                
                if self.Evento.Type == sf.Event.MouseButtonReleased:

                    
                    
                    if boton is not None:
                        print("aqui")
                        if boton[0] == "goal":
                            if ins is not None:
                               
                                self.goal.PlaceBox(boton[1],ins)
                                #self.idbox+=1
                                         
                        if boton[0] == "scene":
                            if ins is not None:
                                self.scenario.PlaceBox(boton[1],ins)
                    Application.putOnDeleteList(self.temp)            
                    self.temp = None
                    self.dragging_box = False            
                    
                
                    

            self.scenario.Update(frameTime)
            #self.goal.Update(frameTime)              
            self.window.Clear(self.blanco)
            
            self.Pintar()
            self.tools.Pintar(self.window)
            self.scenario.Pintar(self.window)
            self.goal.Pintar(self.window)
            
            if self.dragging_box:
                self.temp.SetPosition(x - 22, y - 22)
                self.window.Draw(self.temp)
                
            if self.deleteicon:
                if self.di != None:
                    Application.putOnDeleteList(self.di)
                self.di = self.DefinirX()
                self.di.SetPosition(x-22,y-22)
               
                self.window.Draw(self.di)
               # 
           # else:
              #  self.DefinirdeleteStackBoton()
                #self.window.Draw(self.deletestack)
            self.window.Display()