Ejemplo n.º 1
0
def errorbox(title, msg):
    "display a pygame error box"
    clean_screen()
    init_screen()
    screen = set_mode((450, 150))
    normal_cursor()
    set_caption(title)
    show_message(msg, (10, 10), 12, ("bold"))
    ok_rect = imgv_button(screen, " OK ", 20, screen.get_height() - 40, "midtop")
    while 1:
        event = wait()
        cursor = get_pos()
        check_quit(event)
        hover_button(ok_rect, cursor, screen, " OK ", 20, screen.get_height() - 40, "midtop")
        hover_cursor(cursor, [ok_rect])
        if left_click(event):
            if ok_rect.collidepoint(cursor):
                clean_screen()
                raise SystemExit
        if hit_key(event, K_SPACE):
            clean_screen()
            raise SystemExit
Ejemplo n.º 2
0
def load_movie(screen, movie_file, *options):
    vol = 0.5 # volume starting half way. min is 0.0 max is 1.0
    paused = 0
    skipped = 0
    image = pygame.image.load(gl.MOVIE_FILE).convert()
    paint_screen(screen, gl.BLACK)

    pygame.mixer.quit() # so sound in the movie works
    print movie_file#
    set_caption("imgv - %s" % movie_file)#
    movie = pygame.movie.Movie(movie_file) 
    screen_center = ((screen.get_width() / 2) - (movie.get_size()[0] / 2), ((screen.get_height() / 2)) -\
                     (movie.get_size()[1] / 2)) # where to center the movie
    if len(options) > 0:
        if options[0] == "fitwindow":
            movie.set_display(screen, (0, 0, screen.get_width(), screen.get_height()))
    else:
        movie.set_display(screen, screen_center)

    if len(movie_file) > 70: 
        movie_name = movie_file[:70] + '...'
    else:
        movie_name = movie_file
    movie.play()
    movie.set_volume(vol)
    normal_cursor()
    mute_rect = show_message(screen, "Mute", (20, 0), 12)
    lower_rect = show_message(screen, "Lower", (80, 0), 12)
    louder_rect = show_message(screen, "Louder", (140, 0), 12)
    pause_rect = show_message(screen, "Pause", (200, 0), 12)
    stop_rect = show_message(screen, "Stop", (260, 0), 12)
    skip_rect = show_message(screen, "Skip-Half", (320, 0), 12)
    fw_rect = show_message(screen, "Fit-Window", (400, 0), 12)
    show_message(screen, "(%d:%02.f)" % (movie.get_length() / 60, movie.get_length() % 60), (480, 0), 12)
    if gl.TOGGLE_STATUS_BAR:
        show_message(screen, "%s/%s, %s" % (gl.files.index(movie_file) + 1, len(gl.files),\
        os.path.basename(movie_name)), "bottom", 12)
    flip()#
    while movie:
        if not movie.get_busy() and not paused and gl.SLIDE_SHOW_RUNNING:
            break
        for event in pygame.event.get():
            cursor = pygame.mouse.get_pos()
            if event.type == KEYDOWN and event.key == K_q or event.type == QUIT:
                wait_cursor()
                movie.stop()
                movie = None
                clean_screen()
                raise SystemExit
            if event.type == KEYDOWN and event.key not in (K_LALT, K_RALT, K_LCTRL, K_RCTRL, K_p, K_TAB):
                movie.stop()
                movie = None
                return image
            if left_click(event):
                if mute_rect.collidepoint(cursor):
                    movie.set_volume(0)
                    break
                if lower_rect.collidepoint(cursor):
                    if vol >= 0.0:
                        vol = vol - 0.2
                        movie.set_volume(vol)
                        break
                if louder_rect.collidepoint(cursor):
                    if vol <= 1.0:
                        vol = vol + 0.2
                        movie.set_volume(vol)
                        break
                if pause_rect.collidepoint(cursor):
                    if paused:
                        paused = 0
                    else:
                        paused = 1
                    movie.pause()
                    break
                if stop_rect.collidepoint(cursor):
                    movie.stop()
                    movie = None
                    return image
                if skip_rect.collidepoint(cursor):
                    if not skipped:
                        movie.skip(movie.get_length() / 2)
                    break
                if fw_rect.collidepoint(cursor):
                    movie.stop()
                    movie = None
                    image = load_movie(screen, movie_file, "fitwindow")
                    break
    movie = None
    return image
Ejemplo n.º 3
0
def command_main_menu(refresh_img, screen, file, num_imgs, rect, new_img, img, new_img_width, new_img_height, ns):
    menu_items = []
    i = 23
    cursor = pygame.mouse.get_pos()
    screen_width = screen.get_width()
    screen_height = screen.get_height()
    if screen_height < 600:
        font_size = 10
        gl.MENU_DIVIDER_AMOUNT = 12
    else:
        gl.MENU_DIVIDER_AMOUNT = 14
        font_size = 11
    font = pygame.font.Font(gl.FONT_NAME, font_size)
    font.set_bold(1)
    if gl.MENU_POS == -1:
        gl.MENU_POS = cursor[0]
    main_menu_fg(screen, font, i, menu_items)
    normal_cursor()
    last_rect = Rect(rect)
    new_img_width = new_img.get_width()
    new_img_height = new_img.get_height()
    if gl.REMOTE and not gl.ALREADY_DOWNLOADED:
        download_rect = imgv_button(screen, " Downlo(a)d Image ", None, None, "topright")
    while 1:
        event = pygame.event.poll()
        pygame.time.wait(1)
        check_quit(event)
        cursor2 = pygame.mouse.get_pos()

        if event.type == VIDEORESIZE:#
            gl.JUST_RESIZED = 1
            screen = pygame.display.set_mode(event.dict['size'], RESIZABLE)
            rect = get_center(screen, new_img)
            my_update_screen(new_img, screen, rect, file, len(gl.files))
            return (refresh_img, screen, file, num_imgs, new_img, img, new_img_width, new_img_height, rect)
        if gl.REMOTE and not gl.ALREADY_DOWNLOADED:
            hover_button(download_rect, cursor2, screen, " Downlo(a)d Image ", None, None, "topright")

        if event.type == KEYDOWN:
            if event.key in (K_c, K_h, K_UP, K_DOWN, K_RIGHT, K_LEFT):
                if event.key != K_c:
                    pygame.event.set_allowed(MOUSEMOTION)
                    gl.HAND_TOOL = 1
                    drag_hand_cursor()
                # close the menu
                gl.MENU_POS = -1
                my_update_screen(new_img, screen, rect, file, len(gl.files))
                if event.key == K_c:
                    normal_cursor()
                return (refresh_img, screen, file, num_imgs, new_img, img, new_img_width, new_img_height, rect)
            
            (screen, rect, new_img, img, refresh_img, file, num_imgs,\
            screen_width, screen_height, new_img_width, new_img_height, last_rect) =\
            handle_keyboard(event, screen, rect, new_img, img, refresh_img, file, len(gl.files),\
            screen_width, screen_height, new_img_width, new_img_height, last_rect, ns)
            break
        hover_cursor(cursor2, [x[0] for x in menu_items])
        if left_click(event):
            if gl.REMOTE and not gl.ALREADY_DOWNLOADED:
                if download_rect.collidepoint(cursor2):
                    wait_cursor()
                    save_remote_img(screen, file)
                    break
            for it in menu_items:
                if it[0].collidepoint(cursor2):
                    if it[1] == " Next Image ": 
                        (new_img, img, refresh_img, file, rect) = command_next_img(new_img, screen, file, len(gl.files), rect)
                    elif it[1] == " Previous Image ":
                        (new_img, img, refresh_img, file, rect) = command_prev_img(new_img, screen, file, len(gl.files), rect)        
                    elif it[1] == " Directory Browser ":
                        gl.USING_SCROLL_MENU = 1
                        # save current things in case the user ESCAPES out of show_dirs()
                        gl.LAST_DIR = getcwd()
                        last_files = gl.files
                        (last_new_img, last_img, last_refresh_img, last_num_imgs, last_file, last_rect) =\
                        (new_img, img, refresh_img, num_imgs, file, rect)
                        (new_img, img, refresh_img, num_imgs, file, rect) = command_show_dirs(new_img, img, screen, rect,\
                        file, num_imgs)
                        # user ESCAPED from show_dirs, reset last values
                        if gl.ESCAPED:
                            (new_img, img, refresh_img, num_imgs, file, rect) =\
                            (last_new_img, last_img, last_refresh_img, last_num_imgs, last_file, last_rect)
                            chdir(gl.LAST_DIR)
                            gl.files = last_files
                            gl.USING_SCROLL_MENU = 0
                            my_update_screen(new_img, screen, rect, file, num_imgs)
                        else:
                            gl.REFRESH_IMG_COUNT = 0
                        gl.ESCAPED = 0
                        gl.USING_SCROLL_MENU = 0
                    elif it[1] == " Image Browser ":
                        (new_img, img, refresh_img, file, rect) = command_img_names(screen, new_img, img, file,\
                        num_imgs, rect)
                    elif it[1] == " Thumbnails ":
                        gl.THUMBING = 1
                        gl.CALC_ZOOM = 0
                        zoom_percent = gl.CURRENT_ZOOM_PERCENT
                        real_width = gl.REAL_WIDTH
                        (new_img, img, refresh_img, file, rect) = command_thumbs(screen, new_img, file, ns)
                        if gl.ESCAPED:
                            gl.CURRENT_ZOOM_PERCENT = zoom_percent
                            gl.REAL_WIDTH = real_width
                        gl.ESCAPED = 0
                        gl.THUMBING = 0
                        my_update_screen(new_img, screen, rect, file, num_imgs)
                    elif it[1] == " Image Properties ":
                        transparency = 0
                        if not gl.TOGGLE_TRANSPARENT:
                            gl.TOGGLE_TRANSPARENT = 1
                            transparency = 1
                        command_verbose_info(screen, new_img, rect, file, num_imgs)
                        if transparency:
                            gl.TOGGLE_TRANSPARENT = 0
                        my_update_screen(new_img, screen, rect, file, num_imgs)
                    elif it[1] == " Zoom Out ":
                        if int(gl.N_MILLISECONDS) < gl.MAX_ZOOM_MAX_MS and gl.CURRENT_ZOOM_PERCENT< gl.ZOOM_PERCENT_MAX:
                            try:
                                (new_img, img, rect) = command_zoom_out(new_img, new_img_width, new_img_height, img, screen, file, num_imgs, rect, "normal")
                            except:
                                print 'Out of memory.'
                        else:
                            print "Can't zoom out. Out of memory. Resetting the image."
                            gl.SKIP_FIT = 1
                            gl.ZOOM_EXP = 0
                            start = start_timer()
                            wait_cursor()
                            new_img = load_img(gl.files[file], screen)
                            img = refresh_img = new_img
                            rect = get_center(screen, new_img)
                            ns = check_timer(start)
                            my_update_screen(new_img, screen, rect, file, num_imgs, ns)
                            normal_cursor()
                            gl.N_MILLISECONDS = "0" 
                    elif it[1] == " Zoom In ":
                        if int(gl.N_MILLISECONDS) < gl.MAX_ZOOM_MAX_MS and gl.CURRENT_ZOOM_PERCENT < gl.ZOOM_PERCENT_MAX:
                            try: # triple zoom crash protection
                                (new_img, img, rect) = command_zoom_in(new_img, new_img_width, new_img_height, img, screen, gl.files, file, num_imgs, rect, "normal")
                            except:
                                print 'Zoom max reached.'
                        else:
                            print 'Zoom max reached.'
                    elif it[1] == " Fit to Window ":
                        gl.RESET_FIT = 0
                        gl.SCALE_UP = 1
                        if gl.FIT_IMAGE_VAL:
                            gl.RESET_FIT = 0
                        else:
                            gl.RESET_FIT = 1
                            gl.FIT_IMAGE_VAL = 1
                        start = start_timer()
                        wait_cursor()
                        new_img = load_img(gl.files[file], screen)
                        img = refresh_img = new_img
                        rect = get_center(screen, new_img)
                        ns = check_timer(start)
                        my_update_screen(new_img, screen, rect, file, num_imgs, ns)
                        if gl.RESET_FIT == 1:
                            gl.FIT_IMAGE_VAL = 0
                        normal_cursor()
                    elif it[1] == " Lock Zoom ":
                        gl.PERSISTENT_ZOOM_VAL ^= 1
                        if not gl.PERSISTENT_ZOOM_VAL:
                            gl.ZOOM_EXP = 0
                        my_update_screen(new_img, screen, rect, file, num_imgs, ns)
                    elif it[1] == " Actual Size ":
                        gl.SKIP_FIT = 1
                        gl.ZOOM_EXP = 0
                        start = start_timer()
                        wait_cursor()
                        new_img = load_img(gl.files[file], screen)
                        img = refresh_img = new_img
                        rect = get_center(screen, new_img)
                        ns = check_timer(start)
                        my_update_screen(new_img, screen, rect, file, num_imgs, ns)
                        normal_cursor()
                    elif it[1] == " Close Image ":
                        (new_img, img, refresh_img, file, num_imgs, rect) = command_remove_img(new_img, screen, file, rect)
                    elif it[1] == " Rotate Right ":
                        if int(gl.N_MILLISECONDS) < gl.MAX_ZOOM_MAX_MS and gl.CURRENT_ZOOM_PERCENT < gl.ZOOM_PERCENT_MAX:
                            gl.CALC_ZOOM = 0
                            (new_img, img, rect) = command_rotate_right(new_img, screen, file, num_imgs, rect)
                        else:
                            print "Can't rotate. Out of memory."
                    elif it[1] == " Rotate Left ":
                        if int(gl.N_MILLISECONDS) < gl.MAX_ZOOM_MAX_MS and gl.CURRENT_ZOOM_PERCENT < gl.ZOOM_PERCENT_MAX:
                            gl.CALC_ZOOM = 0
                            (new_img, img, rect) = command_rotate_left(new_img, screen, file, num_imgs, rect)
                        else:
                            print "Can't rotate. Out of memory."
                    elif it[1] == " Four at a Time ":
                        gl.CALC_ZOOM = 0
                        zoom_percent = gl.CURRENT_ZOOM_PERCENT
                        real_width = gl.REAL_WIDTH
                        (file, new_img, img, refresh_img, rect) = command_four(screen, file, new_img, ns)
                        if gl.ESCAPED:
                            gl.CURRENT_ZOOM_PERCENT = zoom_percent
                            gl.REAL_WIDTH = real_width
                        gl.ESCAPED = 0
                        my_update_screen(new_img, screen, rect, file, num_imgs)
                        normal_cursor()
 #                   elif it[1] == " Resize Options ":##
 #                       gl.USING_SCROLL_MENU = 1
 #                       gl.CALC_ZOOM = 0
 #                       zoom_percent = gl.CURRENT_ZOOM_PERCENT
 #                       real_width = gl.REAL_WIDTH
 #                       rect = command_show_res_modes(screen, new_img, file, num_imgs, rect)
 #                       gl.CURRENT_ZOOM_PERCENT = zoom_percent
 #                       gl.REAL_WIDTH = real_width
 #                       gl.USING_SCROLL_MENU = 0
                    elif it[1] == " Refresh ":
                        (new_img, img, rect, file) = command_refresh(refresh_img, screen, gl.files, file, num_imgs)
                    elif it[1] == " First Image ":
                        (new_img, img, refresh_img, file, rect) = command_first_img(new_img, screen, file, len(gl.files), rect)
                    elif it[1] == " Last Image ":
                        (new_img, img, refresh_img, file, rect) = command_last_img(new_img, screen, file, len(gl.files), rect)
                    elif it[1] == " Shuffle ":
                        (new_img, img, refresh_img, rect) = command_shuffle(new_img, img, screen, rect, file, num_imgs)
                    elif it[1] == " Unshuffle ":
                        (new_img, img, refresh_img, rect, file) = command_unshuffle(new_img, img, screen, rect, file, num_imgs)
                    elif it[1] == " Flip Horizontal ":
                        (new_img, img, rect) = command_horiz(new_img, screen, file, num_imgs, rect)
                    elif it[1] == " Flip Vertical ":
                        (new_img, img, rect) = command_vert(new_img, screen, file, num_imgs, rect)
                    elif it[1] == " Slideshow ":
                        (new_img, img, refresh_img, file, rect) = my_slideshow(new_img, img, screen, file, num_imgs, rect)
                        my_update_screen(new_img, screen, rect, file, len(gl.files))
                    elif it[1] == " Playlists ":
                        (new_img, new_img, new_img, file, rect, num_imgs) = command_play_list_options(screen, file)
                        gl.SORT_HIT = 0
                    elif it[1] == " Add to Playlist ":
                        command_add_to_play_list(screen, gl.files[file])
                        gl.SORT_HIT = 0
                        my_update_screen(new_img, screen, rect, file, len(gl.files))
                    elif it[1] == " Edit ":
                        (screen, before_winsize, not_accepted) = adjust_screen(screen)
                        gl.USING_SCROLL_MENU = 1
                        (new_img, img, refresh_img, file, num_imgs, rect) = command_edit_menu(screen, file, new_img, num_imgs, rect)
                        screen = restore_screen(screen, before_winsize, not_accepted, new_img, file, num_imgs, rect)
                        my_update_screen(new_img, screen, rect, file, num_imgs)
                        gl.USING_SCROLL_MENU = 0
                    elif it[1] == " Hide Image ":
                        command_hide(screen, new_img, rect, file, num_imgs)
                    elif it[1] == " Extract from Web ":
                        (screen, before_winsize, not_accepted) = adjust_screen(screen)
                        (new_img, num_imgs) = open_url(screen, img)
                        gl.URL_ERROR = False
                        file = 0
                        img = refresh_img = new_img
                        screen = restore_screen(screen, before_winsize, not_accepted, new_img, file, num_imgs, rect)
                        rect = get_center(screen, new_img)
                        my_update_screen(new_img, screen, rect, file, len(gl.files))
                        normal_cursor()
                    elif it[1] == " Help ":
                        gl.CALC_ZOOM = 0
                        zoom_percent = gl.CURRENT_ZOOM_PERCENT
                        real_width = gl.REAL_WIDTH
                        command_help(screen, new_img, file, rect, num_imgs)
                        if gl.ESCAPED:
                            gl.CURRENT_ZOOM_PERCENT = zoom_percent
                            gl.REAL_WIDTH = real_width
                        gl.ESCAPED = 0
                    elif it[1] == " Close Menu " or it[1] == " Hand Tool ":
                        if it[1] == " Hand Tool ":
                            pygame.event.set_allowed(MOUSEMOTION)
                            gl.HAND_TOOL = 1
                            drag_hand_cursor()
                        gl.MENU_POS = -1
                        my_update_screen(new_img, screen, rect, file, len(gl.files))
                        normal_cursor()
                        return (refresh_img, screen, file, num_imgs, new_img, img, new_img_width, new_img_height, rect)
                    elif it[1] == " Exit ":
                        clean_screen()
                        raise SystemExit
            break
        if event.type == KEYDOWN and event.key not in (K_LALT, K_RALT, K_LCTRL, K_RCTRL, K_TAB):
            return (refresh_img, screen, file, num_imgs, new_img, img, new_img_width, new_img_height, rect)
        if middle_click(event):
            "close the menu upon middle click"
            gl.MENU_POS = -1
            my_update_screen(new_img, screen, rect, file, len(gl.files))
            normal_cursor()
            return (refresh_img, screen, file, num_imgs, new_img, img, new_img_width, new_img_height, rect)
        if right_click(event):
            wait_cursor()
            gl.MENU_POS = -1
            my_update_screen(new_img, screen, rect, file, len(gl.files))
            (refresh_img, screen, file, num_imgs, new_img, img, new_img_width, new_img_height, rect) =\
            command_main_menu(refresh_img, screen, file, num_imgs, rect, new_img, img, new_img_width, new_img_height, ns)
            return (refresh_img, screen, file, num_imgs, new_img, img, new_img_width, new_img_height, rect)

        if event.type == MOUSEBUTTONDOWN: # this needs to be down here to work
            if event.dict['button'] in (4, 5): # scroll wheel activated
                # allow for mouse dragging:
                pygame.event.set_allowed(MOUSEMOTION) 
                gl.HAND_TOOL = 1
                drag_hand_cursor()
                # close menu:
                gl.MENU_POS = -1 
                my_update_screen(new_img, screen, rect, file, len(gl.files))
                return (refresh_img, screen, file, num_imgs, new_img, img, new_img_width, new_img_height, rect)
 

    if gl.KEEP_MENU_OPEN == "1":
        # this code purposely closes the main menu by breaking the recursion to free up RAM memory
        gl.COUNT_CLICKS += 1
        if gl.COUNT_CLICKS == 1: # free up ram every click
            return (refresh_img, screen, file, num_imgs, new_img, img, new_img_width, new_img_height, rect)
        (refresh_img, screen, file, num_imgs, new_img, img, new_img_width, new_img_height, rect) =\
        command_main_menu(refresh_img, screen, file, num_imgs, rect, new_img, img, new_img_width, new_img_height, ns)
    normal_cursor()
    return (refresh_img, screen, file, num_imgs, new_img, img, new_img_width, new_img_height, rect)
Ejemplo n.º 4
0
def check_quit(event):
    "quit the program if the close window icon or the 'q' key is hit"
    if event.type == KEYDOWN and event.key == K_q or event.type == QUIT:
        wait_cursor()
        clean_screen()
        raise SystemExit