diff --git a/README.md b/README.md index 4c97c6e..883d86e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,19 @@ # Eye -A simple command line image viewer, written in SDL. +`/lib/eye.py` A simple command line image viewer, written in SDL. + +Usage: `./eye.py image_directory` + + +# Commands + +| Key | Command | +| ------------------ | ---------------------- | +| up / scroll up | Zoom In | +| down / scroll down | Zoom Out | +| left | Previous Image | +| right | Next Image | +| h | Move Left | +| j | Move Up | +| k | Move Down | +| l | Move Right | \ No newline at end of file diff --git a/lib/viewer.py b/lib/viewer.py index d181530..484efc9 100644 --- a/lib/viewer.py +++ b/lib/viewer.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python """Simple viewer for images in a directory.""" import os import os.path @@ -211,6 +212,17 @@ def run(self): running = True event = SDL_Event() while running: + + keystate = SDL_GetKeyboardState(None) + if keystate[sdl2.SDL_SCANCODE_L]: + self.move_right() + if keystate[sdl2.SDL_SCANCODE_H]: + self.move_left() + if keystate[sdl2.SDL_SCANCODE_K]: + self.move_up() + if keystate[sdl2.SDL_SCANCODE_J]: + self.move_down() + while SDL_PollEvent(ctypes.byref(event)) != 0: if event.type == SDL_QUIT: running = False @@ -224,22 +236,21 @@ def run(self): self.zoom_in() if event.key.keysym.sym == sdl2.SDLK_DOWN: self.zoom_out() - if event.key.keysym.sym == sdl2.SDLK_l: - self.move_right() - if event.key.keysym.sym == sdl2.SDLK_h: - self.move_left() - if event.key.keysym.sym == sdl2.SDLK_k: - self.move_up() - if event.key.keysym.sym == sdl2.SDLK_j: - self.move_down() + + if event.type == SDL_MOUSEWHEEL: + if event.wheel.y > 0: + self.zoom_in() + if event.wheel.y < 0: + self.zoom_out() + if event.type == SDL_MOUSEBUTTONDOWN: if event.button.button == SDL_BUTTON_LEFT: ix, iy = self._view.image_coordinate(event.button.x, event.button.y) - print("x: {}, y: {}".format(ix, iy)) + print "x: %i, y: %i"%(ix, iy) - SDL_DestroyWindow(window) - SDL_Quit() + SDL_DestroyWindow(self.window) + sdl2.ext.quit() return 0 if __name__ == "__main__":