Esempio n. 1
0
def show_slideshow_img(screen, new_img, file, num_imgs, speed):
    start = start_timer()
    wait_cursor()
    new_img = next_img(file, new_img, screen)
    rect = get_center(screen, new_img)
    ns = check_timer(start)
    my_update_screen(new_img, screen, rect, file, num_imgs, ns)
    normal_cursor()
    if speed > 0:
        for i in range(speed):
            # trick delay into letting you escape anytime
            event = pygame.event.poll()
            pygame.time.wait(1)
            if event.type == KEYDOWN and event.key not in (K_LALT, K_RALT, K_LCTRL, K_RCTRL,\
                K_p, K_PAUSE, K_TAB, K_SPACE, K_BACKSPACE):
                stopped_msg(screen)
                my_update_screen(new_img, screen, rect, file, len(gl.files))
                return (new_img, file, rect, 1)
            if hit_key(event, K_p) or hit_key(event, K_PAUSE):
                pause(screen)
                my_update_screen(new_img, screen, rect, file, len(gl.files))
            if hit_key(event, K_SPACE):
                # skip forward an image immediately
                file = file + 1
                return (new_img, file, rect, 0)
            if hit_key(event, K_BACKSPACE):
                # skip backward an image immediately
                file = file - 1
                return (new_img, file, rect, 0)
            pygame.time.delay(1000) # check every second
    file = file + 1
    return (new_img, file, rect, 0)
Esempio n. 2
0
def command_refresh(refresh_img, screen, files, file, num_imgs):
    "reset image to its original state"
    wait_cursor()
    start = start_timer()
    new_img = refresh_img
    rect = get_center(screen, new_img)
    cur_filename = ""
    if len(gl.files) > 1:
        cur_filename = gl.files[file]
    else:
        normal_cursor()
        return (new_img, new_img, get_center(screen, new_img), file)
    if gl.SHRUNK and len(gl.files) > 1:
        # reload shrunk images to their true size
        gl.SKIP_FIT = 1
        refresh_img = load_img(gl.files[file], screen)
        rect = get_center(screen, refresh_img)
        ns = check_timer(start)
        adjust_files(gl.SUBDIRS)
        num_imgs = len(gl.files)
        if cur_filename in gl.files:
            file = gl.files.index(cur_filename) # go back if new images were loaded
        my_update_screen(refresh_img, screen, rect, file, num_imgs, ns)
        normal_cursor()
        return (refresh_img, new_img, rect, file)
    adjust_files(gl.SUBDIRS)
    num_imgs = len(gl.files)
    if cur_filename in gl.files and len(gl.files) > 1:
        file = gl.files.index(cur_filename) # go back if new images were loaded
    ns = check_timer(start)
    my_update_screen(refresh_img, screen, rect, file, num_imgs, ns)
    normal_cursor()
    return (new_img, new_img, get_center(screen, new_img), file)
Esempio n. 3
0
def command_vert(new_img, screen, file, num_imgs, rect):
    "flip vertically"
    wait_cursor()
    start = start_timer()
    new_img = flip(new_img, 90, 90)
    my_update_screen(new_img, screen, rect, file, num_imgs, check_timer(start))
    normal_cursor()
    return (new_img, new_img, rect)
Esempio n. 4
0
def command_horiz(new_img, screen, file, num_imgs, rect):
    "flip horizontally (mirror)"
    wait_cursor()
    start = start_timer()
    new_img = flip(new_img, 90, 0)
    my_update_screen(new_img, screen, rect, file, num_imgs, check_timer(start))
    normal_cursor()
    return (new_img, new_img, rect)
Esempio n. 5
0
def command_rotate_left(new_img, screen, file, num_imgs, rect):
    "rotate counter clockwise"
    wait_cursor()
    start = start_timer()
    new_img = rotate(new_img, 90)
    rect = get_center(screen, new_img)
    my_update_screen(new_img, screen, rect, file, num_imgs, check_timer(start))
    normal_cursor()
    return (new_img, new_img, rect)
Esempio n. 6
0
def command_shuffle(new_img, img, screen, rect, file, num_imgs):
    "randomize the images"
    wait_cursor()
    start = start_timer()
    shuffle(gl.files)
    new_img = load_img(gl.files[file], screen)
    rect = get_center(screen, new_img)
    ns = check_timer(start)
    my_update_screen(new_img, screen, rect, file, num_imgs, ns)
    normal_cursor()
    return (new_img, new_img, new_img, rect)
Esempio n. 7
0
def command_first_img(new_img, screen, file, num_imgs, rect):
    "jump to the first image"
    wait_cursor()
    start = start_timer()
    file = 0
    new_img = load_img(gl.files[file], screen)
    rect = get_center(screen, new_img)
    ns = check_timer(start)
    my_update_screen(new_img, screen, rect, file, num_imgs, ns)
    normal_cursor()
    return (new_img, new_img, new_img, file, rect)
Esempio n. 8
0
def command_prev_img(new_img, screen, file, num_imgs, rect):
    "jump to previous image"
    wait_cursor()
    start = start_timer()
    if file > 0:
        file = file - 1
        new_img = previous_img(file, new_img, screen)
        rect = get_center(screen, new_img)
        ns = check_timer(start)
        my_update_screen(new_img, screen, rect, file, num_imgs, ns)
    normal_cursor()
    return (new_img, new_img, new_img, file, rect)
Esempio n. 9
0
def command_unshuffle(new_img, img, screen, rect, file, num_imgs):
    "un-randomize the images"
    was_on = gl.files[file]
    wait_cursor()
    start = start_timer()
    gl.files.sort(lambda x, y: cmp(x.lower(), y.lower()))
    file = gl.files.index(was_on)
    new_img = load_img(gl.files[file], screen)
    rect = get_center(screen, new_img)
    ns = check_timer(start)
    my_update_screen(new_img, screen, rect, file, num_imgs, ns)
    normal_cursor()
    return (new_img, new_img, new_img, rect, file)
Esempio n. 10
0
def command_zoom_out(new_img, new_img_width, new_img_height, img, screen, file, num_imgs, rect, zoom_type):
    wait_cursor()
    start = start_timer()
    if new_img.get_width() >= gl.MIN_WIDTH and new_img.get_height() >= gl.MIN_HEIGHT:
        gl.ZOOM_EXP -= 1
        if zoom_type == "normal":
            gl.ZOOM_DOUBLE = 0
            new_img = scale(img, (new_img.get_width() / 1.1, new_img.get_height() / 1.1))
        else:
            gl.ZOOM_DOUBLE = 1
            new_img = scale(img, (new_img.get_width() / 2, new_img.get_height() / 2))
        rect = get_center(screen, new_img)
        my_update_screen(new_img, screen, rect, file, num_imgs, check_timer(start))
    normal_cursor()
    return (new_img, img, rect)
Esempio n. 11
0
def command_zoom_in(new_img, new_img_width, new_img_height, img, screen, files, file, num_imgs, rect, zoom_type):
    wait_cursor()
    start = start_timer()
    gl.ZOOM_EXP += 1
    if zoom_type == "normal":
        gl.ZOOM_DOULBE = 0
        new_img = scale(img, (new_img.get_width() * 1.1, new_img.get_height() * 1.1))
    if zoom_type == "double":
        gl.ZOOM_DOUBLE = 1
        new_img = scale(img, (new_img.get_width() * 2, new_img.get_height() * 2))
    if zoom_type == "scale2x":
        gl.ZOOM_DOUBLE = 1
        new_img = scale2x(img) # don't alias simple solid color images (ie., black & white GIFs)
    rect = get_center(screen, new_img)
    my_update_screen(new_img, screen, rect, file, num_imgs, check_timer(start))
    normal_cursor()
    return (new_img, img, rect)
Esempio n. 12
0
def command_next_img(new_img, screen, file, num_imgs, rect):
    "jump to next image"
    wait_cursor()
    start = start_timer()
    if not gl.WRAP:
        if file < (num_imgs - 1):
            file = file + 1
            new_img = next_img(file, new_img, screen)
            rect = get_center(screen, new_img)
            ns = check_timer(start)
            my_update_screen(new_img, screen, rect, file, num_imgs, ns)
    else:
        file = file + 1
        if file > (num_imgs - 1):
            file = 0
        if num_imgs > 1:
            new_img = next_img(file, new_img, screen)
            rect = get_center(screen, new_img)
            ns = check_timer(start)
            my_update_screen(new_img, screen, rect, file, num_imgs, ns)    
    normal_cursor()
    return (new_img, new_img, new_img, file, rect)
Esempio n. 13
0
def command_remove_img(new_img, screen, file, rect):
    "Don't display the image anymore during the session"
    wait_cursor()
    start = start_timer()
    num_imgs = len(gl.files)
    # only remove file if its not the only one:
    if not num_imgs < 2:
        gl.files.remove(gl.files[file])
        # go to the next image if there is one
        if file < (num_imgs - 1):
            new_img = next_img(file, new_img, screen)
        # if not go to the previous image
        else:
            if file > 0:
                file = file - 1
                new_img = previous_img(file, new_img, screen)
        num_imgs = len(gl.files) # re-adjust
        rect = get_center(screen, new_img)
        ns = check_timer(start)
        my_update_screen(new_img, screen, rect, file, num_imgs, ns)
    normal_cursor()
    return (new_img, new_img, new_img, file, num_imgs, rect)
Esempio n. 14
0
def command_img_names(screen, new_img, img, file, num_imgs, rect):
    (screen, before_winsize, not_accepted) = adjust_screen(screen)
    paint_screen(screen, gl.BLACK)
    normal_cursor()
    gl.SORT_HIT = 0
    (list_names, filename, x, my_string) = command_file_master(screen, gl.files,\
    "(%d Images)" % len(gl.files), 15, 0, 1, 0)
    wait_cursor()
    start = start_timer()
    screen = restore_screen(screen, before_winsize, not_accepted, new_img, file, num_imgs, rect)
    if not filename == None:
        if num_imgs > 1:
            file = gl.files.index(filename)
        new_img = load_img(gl.files[file], screen)
        rect = get_center(screen, new_img)
        ns = check_timer(start)
        my_update_screen(new_img, screen, rect, file, num_imgs, ns)
    normal_cursor()
    rect = get_center(screen, new_img)
    num_imgs = len(gl.files)
    my_update_screen(new_img, screen, rect, file, num_imgs)
    return (new_img, new_img, new_img, file, rect)
Esempio n. 15
0
def command_show_dirs(new_img, img, screen, rect, file, num_imgs):
    (screen, before_winsize, not_accepted) = adjust_screen(screen)
    set_caption("Directory Browser - imgv")
    paint_screen(screen, gl.BLACK)
    (num_imgs, file) = show_dirs(screen, num_imgs, file)
    wait_cursor()
    if gl.ESCAPED != 1:
        start = start_timer()
        if num_imgs < 1 or len(gl.files) == 0:
            gl.files = [gl.IMGV_LOGO]
            num_imgs = 0
            new_img = img = load_img(gl.files[file], screen)
        else:
            new_img = load_img(gl.files[file], screen)
    screen = restore_screen(screen, before_winsize, not_accepted, new_img, file, num_imgs, rect)
    rect = get_center(screen, new_img)
    if gl.ESCAPED != 1:
        ns = check_timer(start)
        my_update_screen(new_img, screen, rect, file, num_imgs, ns)
    else:
        my_update_screen(new_img, screen, rect, file, num_imgs)
    normal_cursor()
    return (new_img, new_img, new_img, num_imgs, file, rect)
Esempio n. 16
0
def handle_keyboard(event, screen, rect, new_img, img, refresh_img, file, num_imgs, screen_width, screen_height, new_img_width, new_img_height, last_rect, ns):
    if hit_key(event, K_d):
        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:
            gl.ADDED_DIR_NUMS = 0
            (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
    if hit_key(event, K_i):
        (new_img, img, refresh_img, file, rect) = command_img_names(screen, new_img,\
         img, file, num_imgs, rect)
#    if event.type == VIDEORESIZE:
#        "let user resize window"
#        rect = resize_it(event, screen, new_img, file, num_imgs)
    if hit_key(event, K_F1):
        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
    if hit_key(event, K_F2):
        rect = command_640x480(new_img, file, num_imgs, rect)
        normal_cursor()
    if hit_key(event, K_F3):
        rect = command_800x600(new_img, file, num_imgs, rect)
        normal_cursor()
    if hit_key(event, K_F4):
        rect = command_1024x768(new_img, file, num_imgs, rect)
        normal_cursor()
    if hit_key(event, K_F5):
        rect = command_1280x1024(new_img, file, num_imgs, rect)
        normal_cursor()
    if hit_key(event, K_F6):
        screen = command_fullscreen(screen, new_img, file, num_imgs, rect)
        rect = get_center(screen, new_img)
        my_update_screen(new_img, screen, rect, file, num_imgs)
        normal_cursor()
    if event.type == KEYDOWN: # alt+enter code
        mods = pygame.key.get_mods()
        if ((event.key == K_RETURN and mods & KMOD_ALT)):
            screen = command_fullscreen(screen, new_img, file, num_imgs, rect)
            rect = get_center(screen, new_img)
            my_update_screen(new_img, screen, rect, file, num_imgs)
    if hit_key(event, K_F7):
        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
        my_update_screen(new_img, screen, rect, file, num_imgs)
        normal_cursor()
    if hit_key(event, K_s):
        (new_img, img, refresh_img, rect) = command_shuffle(new_img, img, screen, rect, file, num_imgs)
    if hit_key(event, K_u):
        (new_img, img, refresh_img, rect, file) = command_unshuffle(new_img, img, screen, rect, file, num_imgs)
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if event.key == K_r and mods & KMOD_CTRL == 0:
            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."
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if event.key == K_r and mods & KMOD_CTRL:    
            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."
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if event.key == K_p and mods & KMOD_CTRL == 0:
            command_add_to_play_list(screen, gl.files[file])
            gl.SORT_HIT = 0
            my_update_screen(new_img, screen, rect, file, num_imgs)
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if event.key == K_p and mods & KMOD_CTRL:
            (new_img, new_img, new_img, file, rect, num_imgs) = command_play_list_options(screen, file)
            gl.SORT_HIT = 0
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if event.key == K_x and mods & KMOD_CTRL == 0:
            command_hide(screen, new_img, rect, file, num_imgs)
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if event.key == K_x and mods & KMOD_CTRL:
            if get_config_val("ON_THE_FLY_EXIF_STATUS_BAR") == 1:
                gl.ON_FLY_EXIF_STATUS_BAR ^= 1
            gl.TOGGLE_STATUS_BAR ^= 1
            my_update_screen(new_img, screen, rect, file, num_imgs)
            normal_cursor()
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if (event.key == K_MINUS or event.key == K_KP_MINUS) and mods & KMOD_CTRL == 0:
            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" 
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if (event.key == K_MINUS or event.key == K_KP_MINUS) and mods & KMOD_CTRL:
            try:
                (new_img, img, rect) = command_zoom_out(new_img, new_img_width, new_img_height,\
                 img, screen, file, num_imgs, rect, "double")
            except:
                print 'Out of memory.'
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if (event.key == K_EQUALS or event.key == K_KP_PLUS) and mods & KMOD_CTRL == 0:
            # Zoom in only if there seems to be enough memory
            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.'
    if event.type == KEYDOWN: # ctrl+'+' code
        mods = pygame.key.get_mods()
        if (event.key == K_EQUALS or event.key == K_KP_PLUS) and (mods & KMOD_CTRL and mods & KMOD_ALT == 0):
            if int(gl.N_MILLISECONDS) < gl.DBL_ZOOM_MAX_MS and gl.CURRENT_ZOOM_PERCENT < gl.ZOOM_PERCENT_MAX:
                try: 
                    (new_img, img, rect) = command_zoom_in(new_img, new_img_width, new_img_height, img,\
                    screen, gl.files, file, num_imgs, rect, "double")
                except:
                    print 'Zoom max reached.'
            else:
                print 'Zoom max reached.'
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if (event.key == K_EQUALS or event.key == K_KP_PLUS) and (mods & KMOD_CTRL and mods & KMOD_ALT):
            try:
                (new_img, img, rect) = command_zoom_in(new_img, new_img_width, new_img_height, new_img,\
                screen, gl.files, file, num_imgs, rect, "scale2x")
            except:
                print 'Zoom max. Out of memory.'
    if hit_key(event, K_DOWN):
        pygame.event.set_allowed(MOUSEMOTION)
        gl.MY_KEYDOWN = 1
        gl.HAND_TOOL = 1
    if hit_key(event, K_UP):
        pygame.event.set_allowed(MOUSEMOTION)
        gl.MY_KEYUP = 1
        gl.HAND_TOOL = 1
    if hit_key(event, K_RIGHT):
        pygame.event.set_allowed(MOUSEMOTION)
        gl.MY_KEYRIGHT = 1
        gl.HAND_TOOL = 1
    if hit_key(event, K_LEFT):
        pygame.event.set_allowed(MOUSEMOTION)
        gl.MY_KEYLEFT = 1
        gl.HAND_TOOL = 1
    if hit_key(event, K_HOME):
        pygame.event.set_allowed(MOUSEMOTION)
        command_full_right(rect, last_rect, new_img, screen, file, num_imgs)
        if gl.IMG_BORDER:
            img_border(screen, new_img.get_width(), new_img.get_height(), rect[0], rect[1])
    if hit_key(event, K_END):
        pygame.event.set_allowed(MOUSEMOTION)
        command_full_left(rect, last_rect, new_img, screen, file, num_imgs, screen.get_width())
        if gl.IMG_BORDER:
            img_border(screen, new_img.get_width(), new_img.get_height(), rect[0], rect[1])
    if hit_key(event, K_PAGEDOWN):
        pygame.event.set_allowed(MOUSEMOTION)
        command_full_up(rect, last_rect, new_img, screen, file, num_imgs, screen.get_height())
        if gl.IMG_BORDER:
            img_border(screen, new_img.get_width(), new_img.get_height(), rect[0], rect[1])
    if hit_key(event, K_PAGEUP):
        pygame.event.set_allowed(MOUSEMOTION)
        command_full_down(rect, last_rect, new_img, screen, file, num_imgs)
        if gl.IMG_BORDER:
            img_border(screen, new_img.get_width(), new_img.get_height(), rect[0], rect[1])
    if hit_key(event, K_m):
        (new_img, img, rect) = command_horiz(new_img, screen, file, num_imgs, rect)
    if hit_key(event, K_v):
        (new_img, img, rect) = command_vert(new_img, screen, file, num_imgs, rect)
    if event.type == KEYDOWN: 
        mods = pygame.key.get_mods()
        if (event.key == K_TAB and mods & KMOD_CTRL) or hit_key(event, K_SPACE) or\
            hit_key(event, K_n):
            (new_img, img, refresh_img, file, rect) = command_next_img(new_img, screen, file, len(gl.files), rect)
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if (hit_key(event, K_BACKSPACE) or hit_key(event, K_b)) and mods & KMOD_CTRL == 0:
            (new_img, img, refresh_img, file, rect) = command_prev_img(new_img, screen, file, len(gl.files), rect)
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if event.key == K_b and mods & KMOD_CTRL:
            gl.IMG_BORDER ^= 1
            my_update_screen(new_img, screen, rect, file, num_imgs)
            normal_cursor()
    if hit_key(event, K_o):
        (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, num_imgs)
        normal_cursor()
    if hit_key(event, K_ESCAPE):
        (new_img, img, rect, file) = command_refresh(refresh_img, screen, gl.files, file, num_imgs)
        my_update_screen(new_img, screen, rect, file, num_imgs)
    if event.type == KEYDOWN: # Ctrl+0 (Fit to Window) code
        mods = pygame.key.get_mods()
        if event.key == K_0 and mods & KMOD_CTRL:
            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()
    if event.type == KEYDOWN: # Alt+0 (Actual Size) code
        mods = pygame.key.get_mods()
        if ((event.key == K_0 and mods & KMOD_ALT)):
            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()
    if hit_key(event, K_1) or hit_key(event, K_KP1):
        #gl.SCALE_UP = 1
        if gl.FIT_IMAGE_VAL:
            gl.FIT_IMAGE_VAL = 0
            gl.RESET_FIT = 1
        else:
            gl.SKIP_FIT = 0
            gl.FIT_IMAGE_VAL = 1
            gl.RESET_FIT = 0
        start = start_timer()
        wait_cursor()
        if new_img.get_width() > screen.get_width() or new_img.get_height() > screen.get_height() or gl.RESET_FIT:
            new_img = load_img(gl.files[file], screen)
            img = refresh_img = new_img
            rect = get_center(screen, new_img)
        if gl.RESET_FIT:
            gl.FIT_IMAGE_VAL = 0
        my_update_screen(new_img, screen, rect, file, num_imgs, check_timer(start))
        normal_cursor()
    if hit_key(event, K_f):
        (new_img, img, refresh_img, file, rect) = command_first_img(new_img, screen, file, len(gl.files), rect)
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if (event.key == K_l and mods & KMOD_CTRL == 0):
            (new_img, img, refresh_img, file, rect) = command_last_img(new_img, screen, file, len(gl.files), rect)
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if (event.key == K_l and mods & KMOD_CTRL):
            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)
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if (event.key == K_DELETE and mods & KMOD_CTRL == 0) or\
                (event.key == K_KP_PERIOD and mods & KMOD_CTRL == 0) or\
                (event.key == K_w and mods & KMOD_CTRL):
            (new_img, img, refresh_img, file, num_imgs, rect) = command_remove_img(new_img, screen, file, rect)
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if (event.key == K_DELETE and mods & KMOD_CTRL) or\
           (event.key == K_KP_PERIOD and mods & KMOD_CTRL):
            fn = gl.files[file]
            answer = get_confirmation(screen, "Delete %s? [y/n]" % basename(fn))
            if answer == "yes":
                (new_img, img, refresh_img, file, num_imgs, rect) = command_delete_img(fn, new_img, screen, file, rect)
            my_update_screen(new_img, screen, rect, file, num_imgs)
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if (event.key == K_w and mods & KMOD_CTRL == 0) and hit_key(event, K_w):
           (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, num_imgs)
    if hit_key(event, K_e):
        (screen, before_winsize, not_accepted) = adjust_screen(screen)
        gl.USING_SCROLL_MENU = 1
        zoom_percent = gl.CURRENT_ZOOM_PERCENT
        real_width = gl.REAL_WIDTH
        (new_img, img, refresh_img, file, num_imgs, rect) = command_edit_menu(screen, file, new_img, num_imgs, rect)
        if gl.ESCAPED:
            gl.CURRENT_ZOOM_PERCENT = zoom_percent
            gl.REAL_WIDTH = real_width
        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.ESCAPED = 0
        gl.USING_SCROLL_MENU = 0
    if hit_key(event, K_z):
        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)
    if hit_key(event, K_4):
        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()
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if (event.key == K_t and mods & KMOD_CTRL):
            gl.TOGGLE_TRANSPARENT ^= 1
            my_update_screen(new_img, screen, rect, file, len(gl.files))
    if event.type == KEYDOWN:
        mods = pygame.key.get_mods()
        if (event.key == K_t and mods & KMOD_CTRL == 0) and hit_key(event, K_t):
            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)
    if hit_key(event, K_h):
        pygame.event.set_allowed(MOUSEMOTION)
        gl.HAND_TOOL = 1
        drag_hand_cursor()
    if gl.REMOTE and not gl.ALREADY_DOWNLOADED:
        if hit_key(event, K_a):
            save_remote_img(screen, file)

    return (screen, rect, new_img, img, refresh_img, file, num_imgs, screen_width, screen_height, new_img_width, new_img_height, last_rect)
Esempio n. 17
0
def four(screen, file, new_img, ns):
    paint_screen(screen, gl.IMGV_COLOR) # so transparent status bars don't mess up on VIDEOEXPOSE repaints
    old_file = file
    (img_one_rect, img_two_rect, img_three_rect, img_four_rect) = (0, 0, 0, 0)
    (img_one_name, img_two_name, img_three_name, img_four_name) = (0, 0, 0, 0)
    (show_img_one, show_img_two, show_img_three, show_img_four) = (0, 0, 0, 0)

    rect = show_message(screen, "", "bottom", 9, ("bold")) # needed to not paint on esc_rect first time
    (file, img_one_rect, img_one_name, img_one_file) = square_one(screen, file)
    (file, img_two_rect, img_two_name, img_two_file) = square_two(screen, file)
    (file, img_three_rect, img_three_name, img_three_file) = square_three(screen, file)
    (file, img_four_rect, img_four_name, img_four_file) = square_four(screen, file)

    (esc_rect, close_font) = close_button(screen)
    start = ns
    while 1:
        flag = 0
        event = pygame.event.poll()
        pygame.time.wait(1)
        cursor = pygame.mouse.get_pos()

        if event.type == VIDEORESIZE:
            pygame.event.set_blocked(VIDEOEXPOSE)
            screen = pygame.display.set_mode(event.dict['size'], RESIZABLE)
            file = file - 4
            pygame.event.set_allowed(VIDEOEXPOSE)
            (file, new_img, start) = four(screen, file, new_img, ns)
            flag = 1
            break

        if hit_key(event, K_ESCAPE):
            gl.ESCAPED = 1
            file = old_file
            break
        check_quit(event)
        if hit_key(event, K_SPACE) or hit_key(event, K_n) or hit_key(event, K_4) or right_click(event): # show next 4 images
            paint_screen(screen, gl.IMGV_COLOR)
            flag = 1
        if hit_key(event, K_BACKSPACE) or hit_key(event, K_b) or middle_click(event): # show previous 4 images
            paint_screen(screen, gl.IMGV_COLOR)
            file = file - 8
            flag = 1

        if flag == 1:
            (file, img_one_rect, img_one_name, img_one_file) = square_one(screen, file)
        if flag == 1:
            (file, img_two_rect, img_two_name, img_two_file) = square_two(screen, file)
        if flag == 1:
            (file, img_three_rect, img_three_name, img_three_file) = square_three(screen,\
            file)
        if flag == 1:
            (file, img_four_rect, img_four_name, img_four_file) = square_four(screen, file)
        (show_img_one, show_img_two, show_img_three, show_img_four, rect) = hover_square(\
         screen, show_img_one, show_img_two, show_img_three, show_img_four, img_one_rect,\
        img_two_rect, img_three_rect, img_four_rect, img_one_name, img_two_name, img_three_name,\
        img_four_name, img_one_file, img_two_file, img_three_file, img_four_file, rect, event)

        hover_fx(screen, img_one_name, img_two_name, img_three_name, img_four_name, img_one_rect, img_two_rect, img_three_rect, img_four_rect, cursor)

        if show_img_one == None:
            file = old_file
            break
        if hit_key(event, K_w): 
            if len(gl.files) <= 1: # nothin to slideshow
                file = old_file
                break # kick 'em out
            (file, img_one_file, img_two_file, img_three_file, img_four_file) =\
            my_fourslideshow(screen, new_img, rect, gl.files[file], file - 4,\
            len(gl.files), img_one_file, img_two_file, img_three_file, img_four_file, ns)
            paint_screen(screen, gl.IMGV_COLOR)
            (file, new_img, start) = four(screen, file - 4, new_img, ns)
            flag = 1
            break
        if left_click(event):
            start = start_timer()
            if img_one_rect.collidepoint(cursor):
                wait_cursor()
                new_img = load_img(gl.files[img_one_file], screen)
                return (img_one_file, new_img, start)
            if img_two_rect.collidepoint(cursor):
                wait_cursor()
                new_img = load_img(gl.files[img_two_file], screen)
                return (img_two_file, new_img, start)
            if img_three_rect.collidepoint(cursor):
                wait_cursor()
                new_img = load_img(gl.files[img_three_file], screen)
                return (img_three_file, new_img, start)
            if img_four_rect.collidepoint(cursor):
                wait_cursor()
                new_img = load_img(gl.files[img_four_file], screen)
                return (img_four_file, new_img, start)
            if esc_rect.collidepoint(cursor):
                file = old_file
                gl.ESCAPED = 1
                break
        if event.type == VIDEOEXPOSE:
       # if event.type == VIDEOEXPOSE and not pygame.mouse.get_focused():#
            # repaint the screen in case other windows painted over it:
            file = file - 4
            (file, new_img, start) = four(screen, file, new_img, ns)
            flag = 1
            break
    return (file, new_img, start)
Esempio n. 18
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)
Esempio n. 19
0
def thumbs_engine(screen, new_img, file, ns):
    screen_pause = 0
    SPACER = 5
    x = []
    place = file # start thumbing from current image position
    marker = 0
    (i, j) = (SPACER, SPACER)
    (esc_rect, close_font) = close_button(screen)
    font_size = 9
    font = pygame.font.Font(gl.FONT_NAME, font_size)
    pygame.event.set_blocked(MOUSEMOTION)
    while 1:
        event = pygame.event.poll()
        pygame.time.wait(1)
        check_quit(event)
        cursor = pygame.mouse.get_pos()
        hover_cursor(cursor, (esc_rect,))
        gl.PAUSED = 0 # critical
        if hit_key(event, K_ESCAPE):
            gl.ESCAPED = 1
            return (new_img, new_img, new_img, file, ns)
        if left_click(event):
            if esc_rect.collidepoint(cursor):
                gl.ESCAPED = 1
                break
        if hit_key(event, K_t) or hit_key(event, K_p) or hit_key(event, K_PAUSE):
            # pause
            set_caption("Thumbnails [Paused]")
            try:
                if place % gl.MAX_THUMBS_SET != 0:
                    # only pause if it's not the last thumbnail on the page
                    gl.PAUSED = 1
                    screen_pause = 1
            except:
                gl.PAUSED = 1
                screen_pause = 1
        if screen_pause == 1:
            normal_cursor()
            while 1:
                event = pygame.event.poll()
                pygame.time.wait(1)
                cursor = pygame.mouse.get_pos()
                (esc_rect, close_font) = close_button(screen)
                hover_fx(screen, x, cursor, marker)
                hover_cursor(cursor, [esc_rect] + [y[0] for y in x])
                if left_click(event):
                    if esc_rect.collidepoint(cursor):
                        gl.ESCAPED = 1
                        return (new_img, new_img, new_img, file, ns)
                    start = start_timer()
                    for item in x: # load clicked image:
                        if item[0].collidepoint(cursor):
                            wait_cursor()
                            new_img = load_img(item[1], screen)
                            file = gl.files.index(item[1])
                            return (new_img, new_img, new_img, file, start)
                check_quit(event)
                if hit_key(event, K_SPACE) or hit_key(event, K_t) or hit_key(event, K_n) or hit_key(event, K_p) or hit_key(event, K_PAUSE) or right_click(event):
                    if not place >= len(gl.files):
                        if not gl.PAUSED: # go to next thumb page:
                            paint_screen(screen, gl.IMGV_COLOR)
                            close_button(screen)
                            set_caption("Thumbnails [Paused]")
                            x = []
                            screen_pause = 0
                            marker = 0
                            break
                        # unpause:
                        gl.PAUSED = 0
                        screen_pause = 0
                        break
                if hit_key(event, K_BACKSPACE) or hit_key(event, K_b) or middle_click(event): 
                    # go back to previous thumb page, even if paused:
                    if ((place - marker) > 0):
                        i = j = SPACER
                        if gl.PAUSED:
                            gl.PAUSED = 0
                        paint_screen(screen, gl.IMGV_COLOR)
                        close_button(screen)
                        screen_pause = 0
                        place = place - (marker + gl.MAX_THUMBS)
                        marker = 0
                        x = []
                        break
                if hit_key(event, K_ESCAPE):
                    gl.ESCAPED = 1
                    return (new_img, new_img, new_img, file, ns)
        else:
            set_caption("Loading Thumbnails [%d] - imgv" % marker)
            (x, i, j, place, screen_pause, marker) = show_thumbs(screen, SPACER, x, i, j, place, marker, font, font_size)
        pygame.time.delay(5)
    return (new_img, new_img, new_img, file, ns)
Esempio n. 20
0
def main():
    pygame.time.delay(5) # to make start_timer() work initially
    start = start_timer()
    num_imgs = len(gl.files) 
    pygame.init() # needed for Mac OSX?
    init_screen()
    wait_cursor()
    screen = pygame.display.set_mode(gl.DEFAULT_RES, RESIZABLE)
    set_caption(gl.TITLE)
    if gl.REMOTE == 1:
        show_message(screen, "Loading image. Please wait..", 34, 42)
    file = 0
    if num_imgs < 1:
        gl.files = [gl.IMGV_LOGO]
        num_imgs = 1 
        img = load_img(gl.files[file], screen)
    else:
        img = load_img(gl.files[file], screen)
    wait_cursor()
    img_width = img.get_width()
    img_height = img.get_height()
    refresh_img = img
    new_img = img
    rect = get_center(screen, new_img)
    ns = check_timer(start)
    my_update_screen(new_img, screen, rect, file, num_imgs, ns)
    normal_cursor()
    if gl.START_FULLSCREEN:
        command_fullscreen(screen, new_img, file, num_imgs, rect)
        my_update_screen(new_img, screen, rect, file, num_imgs, ns)
    # start with menu open
    screen_width = screen.get_width()
    screen_height = screen.get_height()
    new_img_width = new_img.get_width()
    new_img_height = new_img.get_height()
    (refresh_img, screen, file, num_imgs, new_img, img,\
    new_img_width, new_img_height, rect) = command_main_menu(refresh_img, screen,\
    file, len(gl.files), rect, new_img, img, new_img_width, new_img_height, ns)
    minus1 = minus2 = 0

    # main loop
    while 1:
        event = pygame.event.poll()
        pygame.time.wait(1) # so pygame doesn't use 100% CPU
        cursor = pygame.mouse.get_pos()
        last_rect = Rect(rect)
        screen_width = screen.get_width()
        screen_height = screen.get_height()
        new_img_width = new_img.get_width()
        new_img_height = new_img.get_height()

        # drag image code:
        if gl.HAND_TOOL:
            if left_click(event): # calculate drag coordinates:
                if gl.IMG_BORDER:
                    border_fix(screen) # erase the current border
                grab_hand_cursor()
                minus1 = cursor[0] - rect[0]
                minus2 = cursor[1] - rect[1]
                gl.DO_DRAG = 1
            if event.type == MOUSEMOTION and gl.DO_DRAG: # move the image when dragged:
                grab_hand_cursor()
                rect[0] = cursor[0] - minus1 
                rect[1] = cursor[1] - minus2
                screen.fill(gl.IMGV_COLOR, last_rect)
                screen.blit(new_img, rect)
                update(rect.union(last_rect))
            if event.type == MOUSEBUTTONUP: # released mouse button, redisplay status bars:
                drag_hand_cursor()
                my_update_screen(new_img, screen, rect, file, num_imgs, ns)
                gl.DO_DRAG = 0

        if event.type == VIDEORESIZE:#
             print 'resize imgv.py'#
             screen = pygame.display.set_mode(event.dict['size'], RESIZABLE)
             rect = get_center(screen, new_img)
             my_update_screen(new_img, screen, rect, file, num_imgs, ns)
        if event.type == KEYDOWN:
            gl.HAND_TOOL = 0
            if event.key not in (K_DOWN, K_UP, K_RIGHT, K_LEFT):
                normal_cursor() # stop displaying hand tool
            (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)
        if event.type == KEYUP:
             stop_auto_repeat()
        check_quit(event)

        if event.type == MOUSEBUTTONDOWN: # open main menu:
            if right_click(event):
                gl.HAND_TOOL = 0
                (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)
        if (gl.KEEP_MENU_OPEN == "1" and gl.COUNT_CLICKS == 1) or gl.JUST_RESIZED: # Re-open the purposely closed window that frees up RAM
            gl.COUNT_CLICKS = 0
            gl.JUST_RESIZED = 0
            (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)
        start_auto_repeat(rect, last_rect, new_img, screen, file, len(gl.files), screen_width, screen_height, event)
    clean_screen()