def toggle_fullscreen(self): """ Swith between fullscreen or windowed mode. @return: if available and successfull, will return True, else return False. @rtype: Boolean """ pygame.display.toggle_fullscreen() debugger.info("toggling fullscreen mode")
def __update(self): for list_pos, x in enumerate(self.__dragging): if self.__dragging[list_pos]: if ( self.clock.time - self.__dragging[list_pos] ) >= self.mouse.drag_time: event_dict = { "type":DRAG_START, "btn":"NotImplementedError", "obj":self._get_picked(), "pos":self.mouse.position } debugger.info("DRAG_START event launched %s" % event_dict) self.room.on_event( event_dict ) self.__dragging[list_pos] = 0
def close(self): """ Close que display window. @return None """ if not self._opened: return pygame.display.quit() debugger.info("display closed")
def __process_mouse_button_up(self, event): if self.__dragging[event.button-1]: event_dict = { "type":SINGLE_CLICK, "btn":event.button, "obj":self._get_picked(), "pos":self.mouse.position } debugger.info("SINGLE_CLICK event launched %s" % event_dict) self.room.on_event( event_dict ) self.__dragging[event.button-1] = 0 else: event_dict = { "type":DRAG_END, "btn":event.button, "obj":self._get_picked(), "pos":self.mouse.position } debugger.info("DRAG_END event launched %s" % event_dict) self.room.on_event( event_dict )
def open(self): """ Open the display window with the setted size. @return: None """ self._opened = True pygame.init() pygame.mouse.set_visible(False) pygame.display.init() self._set_title(self._title) self._set_size(self._size) debugger.info("display openned")
def _set_size(self, size): """ Set a new display size. @param size: The new size of the display (X,Y,*). @type size: pygame.base.Vector3D @return: None """ self._size = size if not self._opened: return screen = pygame.display.set_mode(self._size, pygame.HWSURFACE) screen.set_clip(pygame.Rect((0, 0), self._size)) debugger.info("display size setted [%s]" % (str(self._size)))
def __process_mouse_button_down(self, event): if event.button not in [1,2,3]: return # Check if DOUBLE_CLICK if self.clock.time - self.__button_time[event.button-1] < self.mouse.doubleclick_time: event_dict = { "type":DOUBLE_CLICK, "btn":event.button, "obj":self._get_picked(), "pos":self.mouse.position } debugger.info("DOUBLE_CLICK event launched %s" % event_dict) self.room.on_event(event_dict) self.__dragging[event.button-1] = 0 else: self.__button_time[event.button-1] = self.clock.time # Prepare a possible a DRAG_START self.__dragging[event.button-1] = self.clock.time
def __update(self): for list_pos, x in enumerate(self.__dragging): if self.__dragging[list_pos]: if (self.clock.time - self.__dragging[list_pos]) >= self.mouse.drag_time: event_dict = { "type": DRAG_START, "btn": "NotImplementedError", "obj": self._get_picked(), "pos": self.mouse.position } debugger.info("DRAG_START event launched %s" % event_dict) self.room.on_event(event_dict) self.__dragging[list_pos] = 0
def __process_mouse_button_down(self, event): if event.button not in [1, 2, 3]: return # Check if DOUBLE_CLICK if self.clock.time - self.__button_time[ event.button - 1] < self.mouse.doubleclick_time: event_dict = { "type": DOUBLE_CLICK, "btn": event.button, "obj": self._get_picked(), "pos": self.mouse.position } debugger.info("DOUBLE_CLICK event launched %s" % event_dict) self.room.on_event(event_dict) self.__dragging[event.button - 1] = 0 else: self.__button_time[event.button - 1] = self.clock.time # Prepare a possible a DRAG_START self.__dragging[event.button - 1] = self.clock.time
def __process_mouse_button_up(self, event): if self.__dragging[event.button - 1]: event_dict = { "type": SINGLE_CLICK, "btn": event.button, "obj": self._get_picked(), "pos": self.mouse.position } debugger.info("SINGLE_CLICK event launched %s" % event_dict) self.room.on_event(event_dict) self.__dragging[event.button - 1] = 0 else: event_dict = { "type": DRAG_END, "btn": event.button, "obj": self._get_picked(), "pos": self.mouse.position } debugger.info("DRAG_END event launched %s" % event_dict) self.room.on_event(event_dict)
def run(self, room): pygame.init() debugger.info("turning ON engine...") try: import psyco psyco.full() debugger.info("python-psyco module found, performance acelerarion enabled") except ImportError: debugger.warn("python-psyco module not found, performance aceleration unavaliable") self.display.open() self.room = room() leave = False while not leave: try: self.clock.tick() for event in pygame.event.get(): if event.type == pygame.QUIT: raise StopEngine() elif event.type == pygame.MOUSEMOTION: event_dict = { "type":MOUSE_MOTION, "pos":self.mouse.position, "obj":self._get_picked() } debugger.info("MOUSE_MOTION event launched %s" % event_dict) self.room.on_event(event_dict) elif event.type == pygame.MOUSEBUTTONDOWN: self.__process_mouse_button_down( event ) elif event.type == pygame.MOUSEBUTTONUP: self.__process_mouse_button_up( event ) #self.room.on_event(event) elif event.type == pygame.KEYDOWN: event_dict = { "type":KEY_DOWN, "key":event.key, "mod":"NotImplemented" } debugger.info("KEY_DOWN event launched %s" % event_dict) self.room.on_event(event_dict) elif event.type == pygame.KEYUP: event_dict = { "type":KEY_UP, "key":event.key, "mod":"NotImplemented" } debugger.info("KEY_UP event launched %s" % event_dict) self.room.on_event(event_dict) self.__update() # Sort the container list by Z axis. #self.room.container.sort(key=lambda d: d.position.z) # Call update the room self.room.update() self.room.draw() self.mouse.update() self.mouse.draw() self.display.flip() except ChangeRoom, e: debugger.info("ChangeRoom exception raised, changing room to %s" % e.__class__.__name__) self.room = e except StopEngine: debugger.info("stopping Engine...") leave = True
def run(self, room): pygame.init() debugger.info("turning ON engine...") try: import psyco psyco.full() debugger.info( "python-psyco module found, performance acelerarion enabled") except ImportError: debugger.warn( "python-psyco module not found, performance aceleration unavaliable" ) self.display.open() self.room = room() leave = False while not leave: try: self.clock.tick() for event in pygame.event.get(): if event.type == pygame.QUIT: raise StopEngine() elif event.type == pygame.MOUSEMOTION: event_dict = { "type": MOUSE_MOTION, "pos": self.mouse.position, "obj": self._get_picked() } debugger.info("MOUSE_MOTION event launched %s" % event_dict) self.room.on_event(event_dict) elif event.type == pygame.MOUSEBUTTONDOWN: self.__process_mouse_button_down(event) elif event.type == pygame.MOUSEBUTTONUP: self.__process_mouse_button_up(event) #self.room.on_event(event) elif event.type == pygame.KEYDOWN: event_dict = { "type": KEY_DOWN, "key": event.key, "mod": "NotImplemented" } debugger.info("KEY_DOWN event launched %s" % event_dict) self.room.on_event(event_dict) elif event.type == pygame.KEYUP: event_dict = { "type": KEY_UP, "key": event.key, "mod": "NotImplemented" } debugger.info("KEY_UP event launched %s" % event_dict) self.room.on_event(event_dict) self.__update() # Sort the container list by Z axis. #self.room.container.sort(key=lambda d: d.position.z) # Call update the room self.room.update() self.room.draw() self.mouse.update() self.mouse.draw() self.display.flip() except ChangeRoom, e: debugger.info( "ChangeRoom exception raised, changing room to %s" % e.__class__.__name__) self.room = e except StopEngine: debugger.info("stopping Engine...") leave = True
# Sort the container list by Z axis. #self.room.container.sort(key=lambda d: d.position.z) # Call update the room self.room.update() self.room.draw() self.mouse.update() self.mouse.draw() self.display.flip() except ChangeRoom, e: debugger.info("ChangeRoom exception raised, changing room to %s" % e.__class__.__name__) self.room = e except StopEngine: debugger.info("stopping Engine...") leave = True self.display.close() debugger.info("engine totally stopped, exiting") def __process_mouse_button_down(self, event): if event.button not in [1,2,3]: return # Check if DOUBLE_CLICK if self.clock.time - self.__button_time[event.button-1] < self.mouse.doubleclick_time: event_dict = { "type":DOUBLE_CLICK, "btn":event.button, "obj":self._get_picked(), "pos":self.mouse.position } debugger.info("DOUBLE_CLICK event launched %s" % event_dict) self.room.on_event(event_dict) self.__dragging[event.button-1] = 0 else: self.__button_time[event.button-1] = self.clock.time # Prepare a possible a DRAG_START self.__dragging[event.button-1] = self.clock.time
# Call update the room self.room.update() self.room.draw() self.mouse.update() self.mouse.draw() self.display.flip() except ChangeRoom, e: debugger.info( "ChangeRoom exception raised, changing room to %s" % e.__class__.__name__) self.room = e except StopEngine: debugger.info("stopping Engine...") leave = True self.display.close() debugger.info("engine totally stopped, exiting") def __process_mouse_button_down(self, event): if event.button not in [1, 2, 3]: return # Check if DOUBLE_CLICK if self.clock.time - self.__button_time[ event.button - 1] < self.mouse.doubleclick_time: event_dict = { "type": DOUBLE_CLICK, "btn": event.button, "obj": self._get_picked(), "pos": self.mouse.position } debugger.info("DOUBLE_CLICK event launched %s" % event_dict) self.room.on_event(event_dict)