Exemplo n.º 1
0
 def processKeyDown(self, key):
     if key == pygame.K_SPACE:
         display.toggle_fullscreen()
     elif key == pygame.K_ESCAPE:
         self.quit()
     else:
         self.activeState.processKeyDown(key)
Exemplo n.º 2
0
Arquivo: res.py Projeto: rkulla/imgv
def command_fullscreen():
    "Toggle between full screen and last screen resolution"
    screen = get_surface()
    wait_cursor()
    if not toggle_fullscreen():
        try:
            if gl.FULLSCREEN_SPECIAL:
                screen_res = screen.get_size()
            else:
                screen_res = screen.get_size()
                gl.MAX_SCREEN_FILES = gl.MAX_SF["%sx%s" % (
                    screen_res[0], screen_res[1])]

            if not gl.TOGGLE_FULLSCREEN_SET:  # go into fullscreen mode
                gl.BEFORE_WINSIZE = screen.get_size()
                screen = set_mode(screen_res, screen.get_flags(
                ) ^ FULLSCREEN, screen.get_bitsize())
            else:  # returning from fullscreen. Go back to last screen size:
                set_mode(gl.BEFORE_WINSIZE, screen.get_flags(
                ) ^ FULLSCREEN, screen.get_bitsize())
                screen = set_mode(
                    gl.BEFORE_WINSIZE, RESIZABLE)  # make resizeable
            my_toggle_fullscreen()
        except:
            print "Couldn't toggle fullscreen. Resolution probably not supported by your video card."
    return screen
Exemplo n.º 3
0
                              callback=input_callback,
                              bouncetime=200)

print "Setting up output pins"
for pins in output_pins:
    if (pins[1].upper() == 'HIGH'):
        GPIO.setup(pins[0], GPIO.OUT, initial=GPIO.HIGH)
    else:
        GPIO.setup(pins[0], GPIO.OUT, initial=GPIO.LOW)

#==============================================================================
#our infinite loop to run everything
print "Starting infinite loop"
#we have to change the working directory or
#it defaults to wherever called the script
os.chdir("/boot/images")
print "{}: {}".format("Current Directory", os.getcwd())

d_surf.blit(i_surf, (0, 0))
disp.toggle_fullscreen()
disp.update()

while True:
    try:
        #button presses are threaded so not handled in main loop
        #same with image and updates
        sleep(.01)
    except KeyboardInterrupt:
        GPIO.cleanup()
        disp.quit()
        exit()
    def get(self):
        t = time.get_ticks()
        events = []
        for ev in event.get(KEYDOWN):
            try:
                events.append(Event(PLAYER,
                                    key = self.events[ev.key],
                                    player = self.players[ev.key]))
            except KeyError:
                if ev.key == K_F11 or ev.key == K_f:
                    display.toggle_fullscreen()
                elif ev.key == K_p:
                    events.append(Event(PAUSE))
                elif ev.key == K_ESCAPE:
                    events.append(Event(QUIT))

        # Joysticks are translated to either 0 or 1, and any button
        # below 4 is also translated to 0 or 1. Thus, e.g. button 3
        # on js 1 and button 1 on js 3 will generate the same event.

        # Button numbers over 15 swap the joystick value and have
        # 16 subtracted from them. This makes the EMSUSB2 adapter work
        # in Linux (where it appears as a single 32 button joystick,
        # rather than two 16 button ones).

        # Button patterns testing on Playstation controllers and also
        # a Gravis gamepad.
        for ev in event.get(JOYBUTTONDOWN):
            if ev.button > 15: button, joy = ev.button - 16, ev.joy + 1
            else: button, joy = ev.button, ev.joy
            player = joy % 2
            if button == CONFIRM_BUTTON:
                events.append(Event(PLAYER, key = CONFIRM, player = player))
            elif button == PAUSE_BUTTON:
                events.append(Event(PAUSE))
            elif button < 4:
                if button & 1: key = ROT_CW
                else: key = ROT_CC
                self._last_press[player] = key
                self._last_press_start[player] = t
                events.append(Event(PLAYER, key = key, player = player))

        for ev in event.get(JOYBUTTONUP):
            if ev.button > 15: button, joy = ev.button - 16, ev.joy + 1
            else: button, joy = ev.button, ev.joy
            player = joy % 2
            if button < 4:
                if button & 1: key = ROT_CW
                else: key = ROT_CC
                if self._last_press[player] == key:
                    self._last_press[player] = None

        # Axis stuff; again for the EMSUSB2 axes 3 and 4 are actually on
        # the second joystick.
        for ev in event.get(JOYAXISMOTION):
            if ev.axis == 3: axis, joy = 0, ev.joy + 1
            elif ev.axis == 4: axis, joy = 1, ev.joy + 1
            else: axis, joy = ev.axis, ev.joy
            player = joy % 2
            key = None
            if axis == 0:
                if ev.value < -TOLERANCE: key = LEFT
                elif ev.value > TOLERANCE: key = RIGHT
            elif axis == 1:
                if ev.value > TOLERANCE: key = DOWN
                elif ev.value < -TOLERANCE: key = UP

            if key is not None and self._last_press[player] != key:
                self._last_press[player] = key
                self._last_press_start[player] = t
                events.append(Event(PLAYER, key = key, player = player))
            elif key is None and axis <= 1:
                self._last_press[player] = None

        # Check for repeated events -- if any player has a pending
        # repeat event that hasn't fired in the given interval put it
        # on the queue again.
        for player in range(len(self._last_press)):
            if (self._last_press[player] is not None and
                (t - self._last_press_start[player]) > DELAY and
                (t - self._last_press_times[player]) > RATE):
                self._last_press_times[player] = t
                events.append(Event(PLAYER, key = self._last_press[player],
                                    player = player))

        # Don't actually post events here; the loop that gets them
        # knows what to do. However, if PLAYER events are posted, grab them
        # and use them.
        events.extend(event.get([PLAYER, QUIT]))
        return events