Esempio n. 1
1
def my_slideshow(new_img, img, screen, file, num_imgs, rect):
    if not gl.TOGGLE_FULLSCREEN_SET:
        screen = set_mode(screen.get_size())
    set_caption("Slideshow Options - imgv")
    speed = get_speed(screen, new_img, rect, gl.files[file], file, num_imgs)
    if not speed == -1: # didn't hit Esc from get_speed:
        gl.SLIDE_SHOW_RUNNING = 1
        disable_screensaver()
        dont_call = 0
        pygame.event.set_blocked(MOUSEMOTION)
        while 1:
            event = pygame.event.poll()
            pygame.time.wait(1)
            check_quit(event)
            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))
                file = file - 1
                break
            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 dont_call == 1:
                break
            if not gl.WRAP_SLIDESHOW:
                if file < num_imgs:
                    (new_img, file, rect, dont_call) = show_slideshow_img(screen, new_img, file, num_imgs, speed)
            if gl.WRAP_SLIDESHOW:
                if file >= num_imgs:
                    file = 0
                (new_img, file, rect, dont_call) = show_slideshow_img(screen, new_img, file, num_imgs, speed)
            pygame.time.delay(5) # don't hog CPU
    if not gl.TOGGLE_FULLSCREEN_SET:
        screen = set_mode(screen.get_size(), RESIZABLE)
    return (new_img, new_img, new_img, file, rect)
Esempio n. 2
0
def do_view_tagged(screen, num_imgs, file):
    "show all tagged dir names"
    paint_screen(screen, gl.BLACK)
    (esc_rect, close_font) = close_button(screen)
    line = 5
    if len(gl.MULT_DIRS) == 0:
        show_message(screen, "[No directories are currently tagged]", "bottom", 12)
    for d in gl.MULT_DIRS:
        font = pygame.font.Font(gl.FONT_NAME, 9)
        ren = font.render(d, 1, (255, 255, 255), (0, 0, 0))
        ren_rect = ren.get_rect()
        ren_rect[0] = 5
        ren_rect[1] = line
        screen.blit(ren, ren_rect)
        line = line + 12
        update(ren_rect)
    pygame.event.set_allowed(MOUSEMOTION)
    while 1:
        ev = pygame.event.wait()
        check_quit(ev)
        hover_cursor(pygame.mouse.get_pos(), (esc_rect,))
        if ev.type == KEYDOWN and ev.key not in (K_LALT, K_RALT, K_TAB, K_LCTRL, K_RCTRL) or ev.type == MOUSEBUTTONDOWN:
            gl.ADDED_DIR_NUMS = 0
            (num_imgs, file) = show_dirs(screen, num_imgs, file)
            break # break event loop
Esempio n. 3
0
def view_filter(screen):
    paint_screen(screen, gl.BLACK)
    show_message(screen, "Current filter", "top", 20, ("underline", "bold"))
    show_message(screen, "Imgv will only display files whose filenames:", (5, 30), 15, ("bold"))
    line = 60
    for k in gl.FILTER_COMMAND.keys():
        font = pygame.font.Font(gl.FONT_NAME, 12)
        if k == "startwith":
            ren = font.render("Start with: %s" % gl.FILTER_COMMAND["startwith"], 1, (255, 255, 255), (0, 0, 0))
        if k == "notstartwith":
            ren = font.render("Do not start with:  %s" % gl.FILTER_COMMAND["notstartwith"], 1, (255, 255, 255), (0, 0, 0))
        if k == "endwith":
            ren = font.render("End with:  %s" % gl.FILTER_COMMAND["endwith"], 1, (255, 255, 255), (0, 0, 0))
        if k == "notendwith":
            ren = font.render("Do not end with:  %s" % gl.FILTER_COMMAND["notendwith"], 1, (255, 255, 255), (0, 0, 0))
        if k == "contain":
            ren = font.render("Contain:  %s" % gl.FILTER_COMMAND["contain"], 1, (255, 255, 255), (0, 0, 0))
        if k == "notcontain":
            ren = font.render("Do not contain:  %s" % gl.FILTER_COMMAND["notcontain"], 1, (255, 255, 255), (0, 0, 0))
        ren_rect = ren.get_rect()
        ren_rect[0] = 5
        ren_rect[1] = line
        screen.blit(ren, ren_rect)
        line = line + 30
        update(ren_rect)
    while 1:
        ev = pygame.event.wait()
        check_quit(ev)
        if ev.type == KEYDOWN or ev.type == MOUSEBUTTONDOWN:
            return
Esempio n. 4
0
def save_remote_img(screen, file):
    save_path = gl.DATA_DIR + "downloads" + sep
    filename = gl.files[file]
    paint_screen(screen, gl.BLACK)
    try:
        im = Image.open(gl.REMOTE_IMG_DATA)

        show_message(screen, "Saving: %s" % basename(gl.files[file]), (20, 50), 12, ("bold"))
        show_message(screen, "From: %s" % filename[:filename.rindex('/')] + '/', (20, 70), 12, ("bold"))
        show_message(screen, "To: %s" % save_path, (20, 90), 12, ("bold"))

        im.save(save_path + basename(filename))

        show_message(screen, "Done", (20, 120), 12, ("bold", "underline"))
        show_message(screen, "[Press any key]", "bottom", 15)
        gl.ALREADY_DOWNLOADED = 1
        normal_cursor()
    except:
        return
    
    while 1:
        event = pygame.event.wait()
        check_quit(event)
        #if event.type == KEYDOWN or event.type == MOUSEBUTTONDOWN:
        if event.type == KEYDOWN and event.key not in (K_LALT, K_RALT):
            return
Esempio n. 5
0
def print_version(screen, screen_height):
    imgvlogo = load_img(gl.IMGV_LOGO_SMALL, screen, False)
    imgvlogo_rect = imgvlogo.get_rect()
    imgvlogo_rect[0] = 5
    imgvlogo_rect[1] = screen_height - 50
    screen.blit(imgvlogo, imgvlogo_rect)
    update(imgvlogo_rect)

    msg = "Version      %s" % gl.IMGV_VERSION
    msg_font = pygame.font.Font(gl.FONT_NAME, 11)
    msg_font.set_bold(1)
    char = 0
    i = 0
    pygame.event.set_blocked(MOUSEMOTION)
    while 1:
        event = pygame.event.poll()
        pygame.time.wait(1)
        check_quit(event)
        if char < len(msg):
            if msg[char] != ' ': # don't delay on spaces
                pygame.time.delay(75)
            ren = msg_font.render(msg[char], 1, gl.RED) # one char at a time
            ren_rect = ren.get_rect()
            # center it
            ren_rect[0] += (i + 7)
            ren_rect[1] = screen_height - 15
            screen.blit(ren, ren_rect)
            i += ren.get_width() # make letters space evenly
            char += 1
            update(ren_rect)
        else:
            break
Esempio n. 6
0
def get_confirmation(screen, confirm_msg):
    paint_screen(screen, gl.IMGV_COLOR)
    pygame.display.update()
    normal_cursor()
    show_message(screen, confirm_msg, "top", 12, ("bold"))
    yes_rect = imgv_button(screen, " YES ", 0, 30, "midtop")
    no_rect = imgv_button(screen, " NO ", 0, 60, "midtop")
    pygame.event.set_blocked(MOUSEMOTION)
    while 1:
        event = pygame.event.poll()
        pygame.time.wait(1)
        cursor = pygame.mouse.get_pos()
        hover_button(yes_rect, cursor, screen, " YES ", 0, 30, "midtop")
        hover_button(no_rect, cursor, screen, " NO ", 0, 60, "midtop")
        hover_cursor(cursor, (yes_rect, no_rect))
        check_quit(event)
        if hit_key(event, K_ESCAPE):
            return 
        if hit_key(event, K_y):
            return "yes"
        if hit_key(event, K_n):
            return "no"
        if event.type == MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:
            if yes_rect.collidepoint(cursor):
                return "yes"
            if no_rect.collidepoint(cursor):
                return "no"
Esempio n. 7
0
def error_screen(screen, msg):
   paint_screen(gl.BLACK)
   while 1:
        event = pygame.event.wait()
        show_message(msg, "top", 12)
        check_quit(event)
        if (event.type == KEYDOWN and event.key not in (K_LALT, K_RALT, K_LCTRL, K_RCTRL)) or event.type == MOUSEBUTTONDOWN:
            return
Esempio n. 8
0
def verbose_info(screen, new_img, file, num_imgs):
    # main engine
    wait_cursor()
    paint_screen(screen, gl.BLACK)
    try:
        (uniquecolors_rect, total_colors, row, font, im, verb) = print_verbose_info(screen, new_img, file, num_imgs)
    except:
        print 'print verbose'
        #(uniquecolors_rect, total_colors, row, font, im, verb) = junk_rect()#
       # uniquecolors_rect = junk_rect()#
       # total_colors = ""#
        verb = verbose(screen, file)#
        (uniquecolors_rect, total_colors, row, font, im) = verb.colors()
        #return
    if gl.SHOW_EXIFBUTTON:
        exif_rect = imgv_button(screen, " Exif Data ", 5, gl.ROW_SEP + 435, None)
    (esc_rect, close_font) = close_button(screen)
    normal_cursor()
    transparency = 0
    while 1:
        event = pygame.event.poll()
        pygame.time.wait(1)
        check_quit(event)
        cursor = pygame.mouse.get_pos()
        hover_cursor(cursor, (esc_rect, exif_rect, uniquecolors_rect))
        if gl.SHOW_EXIFBUTTON:
            hover_button(exif_rect, cursor, screen, " Exif Data ", 5, gl.ROW_SEP + 435, None)
        if gl.UNIQUE_COLORS == None and gl.SHOW_EXIFBUTTON and total_colors != "":
            hover_button(uniquecolors_rect, cursor, screen, " Unique colors ", (font.size(total_colors)[0] + 230), row, None)

        show_message(screen, convert_times(ctime(), 0), "bottom", 15, ("transparent"))

        if event.type == MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:
            if uniquecolors_rect != junk_rect():
                if uniquecolors_rect.collidepoint(cursor):
                    wait_cursor()
                    gl.UNIQUE_COLORS = comma_it(len(dict.fromkeys(im.getdata()))) # determine unique colors
                    before_color = gl.MSG_COLOR
                    if gl.MSG_COLOR == gl.SILVER:
                        gl.MSG_COLOR = (142, 142, 142)
                    else:
                        gl.MSG_COLOR = gl.SILVER
                    show_message(screen,  "Unique colors: %s%s" % (gl.UNIQUE_COLORS, ' ' * 12), ((font.size(total_colors)[0] + 235), row), 12, (""), (14, before_color))
                    gl.MSG_COLOR = before_color
                    normal_cursor()
            if exif_rect.collidepoint(cursor):
                wait_cursor()
                try:
                    verb.exif_data(file)
                except:
                    break
                normal_cursor()
            if esc_rect.collidepoint(cursor):
                before_exit()
                break
        if event.type == KEYDOWN and event.key not in (K_LALT, K_RALT, K_LCTRL, K_RCTRL, K_TAB):
            before_exit()
            break
Esempio n. 9
0
def remote_img_details(screen, new_img, rect, file):
    # show no details if image is on a web server
    paint_screen(gl.BLACK)
    while 1:
        event = pygame.event.wait()
        show_message(gl.REMOTE_IMG, (0, 30, 0, 0), 12)
        check_quit(event)
        if event.type == KEYDOWN or event.type == MOUSEBUTTONDOWN:
            return
Esempio n. 10
0
def pause(screen):
    while 1:
        set_caption("[Slideshow Paused] - imgv")
        ren_rect = show_message(screen, "Paused", 30, 23, ("bold"))
        event = pygame.event.wait()
        check_quit(event)
        if event.type == KEYDOWN and event.key not in(K_LALT, K_RALT, K_LCTRL, K_RCTRL, K_TAB):
            set_caption("Slideshow = imgv")
            paint_screen(screen, gl.BLACK, ren_rect)
            break
Esempio n. 11
0
def play_list_options_msg(screen, msg):
    paint_screen(gl.BLACK)
    show_message(msg, 100, 10)
    normal_cursor()
    while 1:
        event = pygame.event.wait()
        check_quit(event)
        if event.type == KEYDOWN or event.type == MOUSEBUTTONDOWN:
            wait_cursor()
            break
Esempio n. 12
0
File: imgv.py Progetto: rkulla/imgv
    def start(self):
        # start with menu open
        self.gfx = command_main_menu(self.gfx)

        # main loop
        while 1:
            self.event = pygame.event.poll()
            pygame.time.wait(1)  # so pygame doesn't use 100% CPU
            cursor = pygame.mouse.get_pos()
            self.last_rect = Rect(self.gfx['rect'])

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

            if self.event.type == VIDEORESIZE:
                self.gfx['screen'] = pygame.display.set_mode(self.event.dict['size'], RESIZABLE)
                self.gfx['rect'] = get_center(self.gfx['screen'], self.gfx['new_img'])
                my_update_screen(self.gfx['new_img'], self.gfx['rect'], self.gfx['file'])
            if self.event.type == KEYDOWN:
                gl.HAND_TOOL = 0
                if self.event.key not in (K_DOWN, K_UP, K_RIGHT, K_LEFT):
                    normal_cursor()  # stop displaying hand tool
                (self.gfx, self.last_rect) = handle_keyboard(self.event, self.gfx, self.last_rect)
            if self.event.type == KEYUP:
                self.stop_auto_repeat()
            check_quit(self.event)

            if self.event.type == MOUSEBUTTONDOWN and right_click(self.event):
                self.open_main_menu()

            # Re-open the purposely closed window that frees up RAM
            if (gl.KEEP_MENU_OPEN == "1" and gl.COUNT_CLICKS == 1) or gl.JUST_RESIZED:
                gl.COUNT_CLICKS = 0
                gl.JUST_RESIZED = 0
                self.gfx = command_main_menu(self.gfx)

            self.start_auto_repeat()
Esempio n. 13
0
def get_dirnum(screen, key_type):
    BACKSPACED = 0
    keyz = {K_1:1, K_2:2, K_3:3, K_4:4, K_5:5, K_6:6, K_7:7, K_8:8, K_9:9, K_0:0, K_KP1:1, K_KP2:2, K_KP3:3, K_KP4:4,\
            K_KP5:5, K_KP6:6, K_KP7:7, K_KP8:8, K_KP9:9, K_KP0:0}
    dirnum = ['0']
    dirnum.append(str(keyz[key_type]))
    show_message(screen, " " * screen.get_width(), (0, screen.get_height() - 15), 11, ("bold"))
    if not gl.BEEN_THERE_DONE_THAT:
        msg1 = "You can type in a directory number or shortcut (L/T/A/D/C/V/S/Q) instead of clicking: _"
        msg2 = "You can type in a directory number or shortcut (L/T/A/D/C/V/S/Q) instead of clicking: %s" % dirnum[1]
    else:
        msg1 = "Directory number or shortcut: _"
        msg2 = "Directory number or shortcut: %s" % dirnum[1] # start with num showing
    show_message(screen, msg2, "bottom", 11)
    my_digits = [] # keypad number list.

    for num in range(10):
        my_digits.append('[%d]' % num) # [0],[1],..[9]
        
    # pass control to input gathering
    while 1:
        event = pygame.event.wait()
        check_quit(event)
        if event.type == KEYDOWN:
            dirnum_input = pygame.key.name(event.key)
            try:
                if dirnum_input in my_digits or dirnum_input in digits:
                    # only echo digits (0-9)
                    for i in dirnum_input:
                        # extract n from brackets, [n]
                        if i in digits:
                            dirnum_input = i
                    dirnum.append(dirnum_input)
                    if BACKSPACED:
                        show_message(screen, msg2 + ''.join(dirnum[1:]), "bottom", 11)
                    else:
                        show_message(screen, msg2 + ''.join(dirnum[2:]), "bottom", 11)
            except TypeError:
                pass
    
        if hit_key(event, K_RETURN) or hit_key(event, K_KP_ENTER) or hit_key(event, K_SPACE) or hit_key(event, K_l):
            break
        if hit_key(event, K_ESCAPE):
            return
        if hit_key(event, K_BACKSPACE) or hit_key(event, K_DELETE) or hit_key(event, K_KP_PERIOD):
            # erase whatever text was inputed"
            BACKSPACED = 1
            dirnum = ['0']
            msg2 = msg1
            show_message(screen, " " * screen.get_width(), (0, screen.get_height() - 15), 11)
            show_message(screen, msg1, "bottom", 11)
            return 'backspaced' # get control back so you can click directories

    dirnum = int(''.join(dirnum)) # convert to valid number
    return dirnum
Esempio n. 14
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
Esempio n. 15
0
def my_fourslideshow(screen, new_img, rect, filename, file, num_imgs, img_one_file, img_two_file, img_three_file, img_four_file, ns):
    if not gl.TOGGLE_FULLSCREEN_SET:
        screen = set_mode(screen.get_size())
    set_caption("Slideshow Options - imgv")
    speed = get_speed(screen, new_img, rect, filename, file, num_imgs)
    if not speed == -1:  # didn't hit Esc from get_speed:
        gl.SLIDE_SHOW_RUNNING = 1
        disable_screensaver()
        dont_call = 0
        while 1:
            event = pygame.event.poll()
            pygame.time.wait(1)
            check_quit(event)
            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)
                file = file - 1
                (file, new_img, start) = four(screen, file, new_img, ns) # needed to repaint
                break
            if hit_key(event, K_p) or hit_key(event, K_PAUSE):
                pause(screen)
            if dont_call == 1:
                break
            if not gl.WRAP_SLIDESHOW:
                if file < num_imgs:
                    (file, dont_call, img_one_file, img_two_file, img_three_file, img_four_file) =\
                    show_fourslideshow_imgs(screen, file, speed)
            if gl.WRAP_SLIDESHOW:
                if file >= num_imgs:
                    file = 0
                (file, dont_call, img_one_file, img_two_file, img_three_file, img_four_file) =\
                show_fourslideshow_imgs(screen, file, speed)
            pygame.time.delay(5) 
    else: # escaped
        file = file + 4
        return (file, img_one_file, img_two_file, img_three_file, img_four_file)
    if not gl.TOGGLE_FULLSCREEN_SET:
        screen = set_mode(screen.get_size(), RESIZABLE)
    return (file, img_one_file, img_two_file, img_three_file, img_four_file)
Esempio n. 16
0
def hide(screen):
    paint_screen(screen, gl.BLACK)
    set_icon(pygame.image.load(gl.DATA_DIR + "imgv-icon-blank.png"))
    normal_cursor()
    while 1:
        event = pygame.event.poll()
        pygame.time.wait(150)
        check_quit(event)
        if event.type == KEYDOWN and event.key not in (K_LALT, K_RALT, K_LCTRL, K_RCTRL, K_TAB):
            if gl.CORRECT_PASSWORD.lower() not in ("none", None):
                pw = ask(screen, "Password")
                if pw == gl.CORRECT_PASSWORD:
                    break
                else:
                    show_message(screen, "Incorrect Password", (150), 24, ("bold", "transparent"))
                    show_message(screen, "Press any key to try again", (175), 12, ("bold", "transparent"))
                    f = open(gl.DATA_DIR + "security.log", "a")
                    f.write("Password failure: %s\n" % ctime())
                    f.close()
                    continue
            else:
                break
    set_icon(pygame.image.load(gl.DATA_DIR + "imgv-icon.png"))
Esempio n. 17
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()
Esempio n. 18
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. 19
0
def help(screen):
    paint_screen(screen, gl.BLACK)
    (screen_width, screen_height) = (screen.get_width(), screen.get_height())
    (esc_rect, font) = close_button(screen)
    show_message(screen, "Main Keyboard Commands", "top", 11, ("bold", "underline", "transparent"))
    key_list = [" Space/N/Ctrl+Tab=Next image, Backspace/B=Previous Image. Ctrl+B=Toggle Image Border ", 
                " D=Change Directory ", 
                " I=Image Browser ", 
                " T=Thumbnails (Space/N/Right-Click=Next. Backspace/B/Middle-Click=Prev. P/Pause=Pause), Ctrl+T=Transparent font ", 
                " 4=View four images at a time (Space/N/Right-Click=Next. Backspace/B/Middle-Click=Previous. W=Slideshow) ", 
                " W=Slideshow (Space=Skip forward. Backspace=Skip backward. P/Pause=Pause) ", 
                " P=Add to Playlist, Ctrl+P=Playlist Options ", 
                " C=Close Menu ",
                " F=First Image (Jump to the first image), L=Last Image (Jump to the last image), Ctrl+L=Lock Zoom ", 
                " '+'=Zoom In. '-'=Zoom Out. Ctrl+'+'=Zoom In (Double). Ctrl+'-'=Zoom Out (Double). Ctrl+Alt+'+'=Zoom In (Scale2X) ", 
                " R=Rotate Right. Ctrl+R=Rotate Left ",
                " Escape=Refresh (Reverts images to original state or reloads after directory changes) ",
                " M=Flip Horizontal (Mirror), V=Flip Vertical ", 
                " S=Shuffle, U=Unshuffle ", 
                " A=Download Image (Saves remote images to your imgv download directory) ", 
                " Delete/Ctrl+W=Close Image, Ctrl+Delete=Permanently delete image from harddisk", 
                " X=Hide Image, Ctrl+X=Toggle displaying the main and on-the-fly-Exif status bars ", 
                " O=Open URL to extract images from a Website ",
                " F1=Help, F2=640x480, F3=800x600, F4=1024x768, F5=1280x1024, F6/Alt+Enter=Fullscreen, F7=Resize Options ", 
                " H=Hand Tool (Allows you to pan/move images on the screen) ", 
                " Q=Exit imgv at any time (except when prompted for input) ", 
                " Arrow keys=Scroll the image left/right/up/down. PgUp/PgDown/Home/End=full up/full down/full left/full right, (Mouse Wheel=up/down) ", 
                " E=Edit ", 
                " Z=Image Properties ",
                " 1=Toggle scaling large images to fit the window ",
                " Ctrl+Zero=Fit image to the window, Alt+Zero=Actual Size (Show image at its real size) "]
    key_list.sort()
    if screen_width == 640:
        linesep = 13 
        font_size = 9
    else:
        linesep =15
        font_size = 11
    pos = linesep
    for line in key_list:
        show_message(screen, line, (2, pos), font_size, ("transparent"))
        pos += linesep 
 
    mouse_msg = "Main Mouse Commands"
    show_message(screen, mouse_msg, ((screen_width / 2) - (font.size(mouse_msg)[0] / 2), pos, 0, 0), 11, ("bold", "underline", "transparent"))
    mouse_list = [" Left-Click=Select menu options/Load images in Four at a Time, Thumbnail and Image browser/Click buttons and links/Change directories ", " Right-Click=Open or move the main menu/Go forward a page in Four at a Time, Thumbnail and Image Browser/Tag directories ", " Middle-Click=Close the main menu/Go back a page in Four at a Time, Thumbnail and Image Browser ", " Mouse Scroll Wheel=Scroll images that are larger than the screen up or down/Activate the Hand Tool "]
    pos += linesep
    for line in mouse_list:
        show_message(screen, line, (2, pos), font_size, ("transparent"))
        pos += linesep

    gl.MSG_COLOR = gl.BLUE
    doc_msg = "View imgv's online documentation"
    doc_rect = show_message(screen, doc_msg, ((screen_width / 2) - (font.size(doc_msg)[0] / 2), screen_height - 20, 0, 0), 12, ("underline", "bold"))

    donate_msg = "Donate!"
    donate_rect = show_message(screen, donate_msg, ((screen_width) - (font.size(donate_msg)[0] + 70), screen_height - 35, 0, 0), 12, ("bold", "underline"))

    gl.MSG_COLOR = gl.SILVER
    author_msg = "Author: Ryan Kulla"
    show_message(screen, author_msg, ((screen_width) - (font.size(author_msg)[0] - 10), screen_height - 15, 0, 0), 9, ("bold", "transparent"), (7, gl.WHITE))

    normal_cursor()
    print_version(screen, screen_height)
    pygame.event.set_blocked(MOUSEMOTION)
    while 1:
        event = pygame.event.poll()
        pygame.time.wait(1)
        cursor = pygame.mouse.get_pos()
        check_quit(event)
        hover_cursor(cursor, (doc_rect, esc_rect, donate_rect))
        if hit_key(event, K_ESCAPE) or hit_key(event, K_SPACE):
           gl.ESCAPED = 1
           gl.MSG_COLOR = gl.MENU_COLOR
           break
        if left_click(event):
            wait_cursor()
            if doc_rect.collidepoint(cursor):
                webbrowser.open("http://imgv.sourceforge.net/doc/", 1, 1)
            if donate_rect.collidepoint(cursor):
                webbrowser.open("http://imgv.sourceforge.net/donate.html", 1, 1)
            elif esc_rect.collidepoint(cursor):
                gl.ESCAPED = 1
                gl.MSG_COLOR = gl.MENU_COLOR
                break
Esempio n. 20
0
def command_file_master(screen, file_names, msg, down, button_op, disable_right_click, again):
    set_caption("Image Browser - imgv")
    screen_pause = place = marker = 0
    menu_items = []
    edit_rect = back_rect = forward_rect = sort_rect = junk_rect()
    (esc_rect, font) = close_button(screen)
    create_rect = imgv_button(screen, " Create New List ", 0, 18, "midtop")
    if len(file_names) < 1:
        my_string = ask(screen, "Create playlist first (Enter a name)")
        if my_string == None or my_string == []:
            return ([], [], [], []) # don't create a list
        if my_string != []: # create list
            if (len(my_string) > 0) and my_string != "\n":
                return (file_names, None, None, my_string)
    pygame.event.set_blocked(MOUSEMOTION)
    while 1:
        event = pygame.event.poll()
        pygame.time.wait(1)
        if screen_pause == 1:
            while 1:
                event = pygame.event.poll()
                pygame.time.wait(1)
                cursor = pygame.mouse.get_pos()
                hover_fx(screen, menu_items, cursor)
                hover_cursor(cursor, [esc_rect, edit_rect, sort_rect, back_rect, forward_rect, create_rect] + [x[0] for x in menu_items])
                if button_op:
                    hover_button(create_rect, cursor, screen, " Create New List ", 0, 18, "midtop")
                if (place + 1) < len(file_names):
                    hover_button(forward_rect, cursor, screen, " Next ", 10, 18, "topright")
                if (((place + 1) - gl.MAX_SCREEN_FILES) > 1):
                    hover_button(back_rect, cursor, screen, " Previous ", 10, 18, "topleft")
                if not gl.SORT_HIT:
                    hover_button(sort_rect, cursor, screen, " Sort ", 13, 42, "midtop")
                check_quit(event)
                if hit_key(event, K_ESCAPE):
                    return (None, None, None, None)
                if left_click(event):
                    if esc_rect.collidepoint(cursor):
                        return (None, None, None, None)
                if left_click(event):
                    for item in menu_items:
                        if item[0].collidepoint(cursor):
                            if pygame.mouse.get_pressed()[0] and (pygame.key.get_pressed()[K_LCTRL] or\
                               pygame.key.get_pressed()[K_RCTRL]):
                                return (file_names, item[1], "deleteit", None)
                            if again == "do again":
                                return (file_names, item[1], "do again", None)
                            return (file_names, item[1], menu_items, None)
                if right_click(event):
                    if not disable_right_click:
                        for item in menu_items:
                            if item[0].collidepoint(cursor):
                                if not os.path.isfile(gl.DATA_DIR + item[1]):
                                    if edit_rect != junk_rect():
                                        paint_screen(gl.BLACK)
                                    edit_rect = show_message(
                                    "%s doesn't exist in %s" % (item[1], gl.DATA_DIR), "top", 9, ("bold", "transparent"))
                                else:
                                    return (None, item[1], "rclicked", None)
                if hit_key(event, K_SPACE) or right_click(event):
                    if not place >= len(file_names):
                        screen_pause = 0
                        marker = 0
                        menu_items = []
                        break
                if left_click(event):
                    if forward_rect.collidepoint(cursor):
                        if not place >= len(file_names):
                            screen_pause = 0
                            marker = 0
                            menu_items = []
                            break
                if hit_key(event, K_BACKSPACE) or middle_click(event):
                    if ((place - marker) > 0):
                        paint_screen(gl.BLACK)
                        screen_pause = 0
                        place = place - (gl.MAX_SCREEN_FILES + marker)
                        marker = 0
                        menu_items = []
                        break
                if left_click(event):
                    if back_rect.collidepoint(cursor):
                        if ((place - marker) > 0):
                            paint_screen(gl.BLACK)
                            screen_pause = 0
                            place = place - (gl.MAX_SCREEN_FILES + marker)
                            marker = 0
                            menu_items = []
                            break
                if left_click(event):
                    if sort_rect.collidepoint(cursor):
                        gl.SORT_HIT = 1
                        file_names = basename_sort(file_names)
                        (file_names, menu_items, screen_pause, place, marker, forward_rect, back_rect, sort_rect) = file_master(screen, file_names, place, marker, menu_items, msg, down, button_op)
                        screen_pause = place = marker = 0
                        menu_items = []
                        break
                if left_click(event):
                    if create_rect.collidepoint(cursor):
                        my_string = ask(screen, "Enter name of list")
                        if my_string != None:
                            if (len(my_string) > 0) and my_string != "\n":
                                return (file_names, None, menu_items, my_string)
        (file_names, menu_items, screen_pause, place, marker, forward_rect, back_rect, sort_rect) =\
            file_master(screen, file_names, place, marker, menu_items, msg, down, button_op)
        pygame.time.delay(5)
Esempio n. 21
0
def command_get_filter_info(screen):
    paint_screen(screen, gl.BLACK)
    set_caption("imgv")
    menu_items = []
    (esc_rect, font) = close_button(screen)
    
    show_message(screen, 'To build a search filter click as many options below as you need and then click "Done"', (21, 15), 12, ("bold"))
    show_message(screen, 'Example: If you don\'t want to view movies then just choose "Do not end with" and input:  .mpg, .mpeg', (21, 45), 12)
    show_message(screen, "Option number: _", "bottom", 12)
    (menu_items, filt_ops) = get_filter_info(screen, menu_items)
    pygame.event.set_blocked(MOUSEMOTION)
    while 1:
        event = pygame.event.poll()
        pygame.time.wait(1)
        check_quit(event)
        if hit_key(event, K_ESCAPE):
            gl.ADDED_DIR_NUMS = 0
            return
        if event.type == KEYDOWN and event.key in (K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9, K_KP1, K_KP2, K_KP3, K_KP4, K_KP5, K_KP6, K_KP7, K_KP8, K_KP9):
            if hit_key(event, K_1) or hit_key(event, K_KP1):
                do_startwith(screen)
            if hit_key(event, K_2) or hit_key(event, K_KP2):
                do_donot_startwith(screen)
            if hit_key(event, K_3) or hit_key(event, K_KP3):
                do_endwith(screen)
            if hit_key(event, K_4) or hit_key(event, K_KP4):
                do_donot_endwith(screen)
            if hit_key(event, K_5) or hit_key(event, K_KP5):
                do_contain(screen)
            if hit_key(event, K_6) or hit_key(event, K_KP6):
                do_donot_contain(screen)
            if hit_key(event, K_7) or hit_key(event, K_KP7):
                do_view_filter(screen)
            if hit_key(event, K_8) or hit_key(event, K_KP8):
                do_erase_filter(screen)
            if hit_key(event, K_9) or hit_key(event, K_KP9):
                gl.ADDED_DIR_NUMS = 0
                return
            break
        
        cursor = pygame.mouse.get_pos()

        if left_click(event):
            if esc_rect.collidepoint(cursor):
                gl.ADDED_DIR_NUMS = 0
                return 
        
        hover_fx(screen, menu_items, cursor, font)
        hover_cursor(cursor, [esc_rect] + [x[0] for x in menu_items])
        if gl.NOT_HOVERED:
            show_message(screen, "%sOption number: _%s" % (" " * 100, " " * 100), "bottom", 12)
            blank_fx(screen, 0)
        if event.type == MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:
            for it in menu_items:
                if it[0].collidepoint(cursor) and it[1] in filt_ops:
                    if it[1] == "1) Start with":
                        do_startwith(screen)
                    if it[1] == "2) Do not start with":
                        do_donot_startwith(screen)
                    if it[1] == "3) End with":
                        do_endwith(screen)
                    if it[1] == "4) Do not end with":
                        do_donot_endwith(screen)
                    if it[1] == "5) Contain":
                        do_contain(screen)
                    if it[1] == "6) Do not contain":
                        do_donot_contain(screen)
                    if it[1] == "7) View filter":
                        do_view_filter(screen)
                    if it[1] == "8) Erase filter":
                        do_erase_filter(screen)
                    if it[1] == "9) Done":
                        gl.ADDED_DIR_NUMS = 0
                        return
                    break
            else:
                continue
            break
        gl.NOT_HOVERED = 1
Esempio n. 22
0
File: edit.py Progetto: rkulla/imgv
def preferences(screen):
    paint_screen(gl.BLACK)
    set_caption("imgv preferences")
    font_size = 12
    font = pygame.font.Font(gl.FONT_NAME, font_size)
    (esc_rect, font) = close_button(screen)
    pref_items = print_preferences(screen)

    (transparent_text_crect, transparent_text_ucrect, main_statusbar_crect, main_statusbar_ucrect, four_statusbars_crect, four_statusbars_ucrect, exif_statusbar_crect, exif_statusbar_ucrect, thumb_statusbars_crect, thumb_statusbars_ucrect, image_border_crect, image_border_ucrect, fit_image_rect, dirnum_colors_crect, dirnum_colors_ucrect, screen_bgcolor_rect, lock_zoom_crect, lock_zoom_ucrect, wrap_crect, wrap_ucrect, wrap_slideshow_crect, wrap_slideshow_ucrect, start_fullscreen_crect, start_fullscreen_ucrect, thumb_border_crect, thumb_border_ucrect, show_movies_crect, show_movies_ucrect, font_color_rect, font_bgcolor_rect, img_border_color_rect, thumb_border_color_rect, thumb_bgcolor_rect, four_divcolor_rect, button_bgcolor_rect, button_hover_color_rect, button_textcolor_rect, button_texthovercolor_rect, close_button_color_rect, gamma_rect, winsize_rect, thumbsize_rect, transeffect_rect, startdir_rect, external_editor_rect, fit_slideshow_rect, passwd_rect) = pref_options(screen)

    while 1:
        event = pygame.event.poll()
        pygame.time.wait(1)
        check_quit(event)
        cursor = pygame.mouse.get_pos()
        prefs_hover_fx(screen, pref_items, cursor, font)

        hover_cursor(cursor, [esc_rect, transparent_text_crect, transparent_text_ucrect, main_statusbar_crect, main_statusbar_ucrect, four_statusbars_crect, four_statusbars_ucrect, exif_statusbar_crect, exif_statusbar_ucrect, thumb_statusbars_crect, thumb_statusbars_ucrect, image_border_crect, image_border_ucrect, fit_image_rect, dirnum_colors_crect, dirnum_colors_ucrect, screen_bgcolor_rect, lock_zoom_crect, lock_zoom_ucrect, wrap_crect, wrap_ucrect, wrap_slideshow_crect, wrap_slideshow_ucrect, start_fullscreen_crect, start_fullscreen_ucrect, thumb_border_crect, thumb_border_ucrect, show_movies_crect, show_movies_ucrect, font_color_rect, font_bgcolor_rect, img_border_color_rect, thumb_border_color_rect, thumb_bgcolor_rect, four_divcolor_rect, button_bgcolor_rect, button_hover_color_rect, button_textcolor_rect, button_texthovercolor_rect, close_button_color_rect, gamma_rect, winsize_rect, thumbsize_rect, transeffect_rect, startdir_rect, external_editor_rect, fit_slideshow_rect, passwd_rect])

        if gl.NOT_HOVERED:
            show_message("%s%s" % (" " * 100, " " * 100), "bottom", 12, ("transparent"))
            prefs_blank_fx(screen, -1)
        if hit_key(event, K_ESCAPE):
            gl.ESCAPED = 1
            paint_screen(gl.BLACK)
            return
        if left_click(event):
            if esc_rect.collidepoint(cursor):
                gl.ESCAPED = 1
                paint_screen(gl.BLACK)
                return
            if transparent_text_ucrect.collidepoint(cursor):
                gl.TOGGLE_TRANSPARENT ^= 1
                write_cfg("TRANSPARENT_TEXT")
            if main_statusbar_ucrect.collidepoint(cursor):
                gl.TOGGLE_STATUS_BAR ^= 1
                write_cfg("MAIN_STATUS_BAR")
            if four_statusbars_ucrect.collidepoint(cursor):
                gl.FOUR_STATUS_BARS ^= 1
                write_cfg("FOUR_AT_A_TIME_STATUS_BARS")
            if exif_statusbar_ucrect.collidepoint(cursor):
                gl.ON_FLY_EXIF_STATUS_BAR ^= 1
                write_cfg("ON_THE_FLY_EXIF_STATUS_BAR")
            if thumb_statusbars_ucrect.collidepoint(cursor):
                gl.THUMB_STATUS_BARS ^= 1
                write_cfg("THUMBNAIL_STATUS_BARS")
            if image_border_ucrect.collidepoint(cursor):
                gl.IMG_BORDER ^= 1
                write_cfg("IMAGE_BORDER")
            if lock_zoom_ucrect.collidepoint(cursor):
                gl.PERSISTENT_ZOOM_VAL ^= 1
                write_cfg("PERSISTENT_ZOOM")
            if wrap_ucrect.collidepoint(cursor):
                gl.WRAP ^= 1
                write_cfg("WRAP")
            if wrap_slideshow_ucrect.collidepoint(cursor):
                gl.WRAP_SLIDESHOW ^= 1
                write_cfg("WRAP_SLIDESHOW")
            if start_fullscreen_ucrect.collidepoint(cursor):
                gl.START_FULLSCREEN ^= 1
                write_cfg("FULLSCREEN")
            if thumb_border_ucrect.collidepoint(cursor):
                gl.THUMB_BORDER_VAL ^= 1
                write_cfg("THUMB_BORDER")
            if show_movies_ucrect.collidepoint(cursor):
                gl.MOVIES_VAL ^= 1
                show_message("(You must restart imgv for this change to take effect)", (375, 204), 10, ("bold", "transparent"))
                write_cfg("MOVIES")
            if fit_image_rect.collidepoint(cursor):
                paint_screen(gl.BLACK)
                show_message("Enter an option letter and press enter", (15, 20), 13, ("bold", "transparent"))
                show_message("A = Fit nothing.", (15, 60), 13, ("bold", "transparent"))
                show_message("B = Fit only large images to the window.", (15, 80), 13, ("bold", "transparent"))
                show_message("C = Fit all images to the window. (both in normal mode and Four-at-a-Time mode)", (15, 100), 13, ("bold", "transparent"))
                show_message("D = Fit the window to images.", (15, 120), 13, ("bold", "transparent"))
                answer = ask(screen, "Option")
                if answer != None and answer in ('a','A', 'b','B', 'c','C', 'd','D'):
                    dmap = {'a':0, 'b':1, 'c':2, 'd':3}
                    gl.FIT_IMAGE_VAL = dmap[answer.lower()]
                    write_cfg("FIT_IMAGE", str(gl.FIT_IMAGE_VAL))
                clean_prefs(screen)
            if fit_slideshow_rect.collidepoint(cursor):
                paint_screen(gl.BLACK)
                show_message("Enter an option letter and press enter", (15, 20), 13, ("bold", "transparent"))
                show_message("A = Fit nothing.", (15, 60), 13, ("bold", "transparent"))
                show_message("B = Fit only large images to the window.", (15, 80), 13, ("bold", "transparent"))
                show_message("C = Fit all images to the window. (both in normal mode and Four-at-a-Time mode)", (15, 100), 13, ("bold", "transparent"))
                show_message("D = Fit the window to images.", (15, 120), 13, ("bold", "transparent"))
                answer = ask(screen, "Option")
                if answer != None and answer in ('a','A', 'b','B', 'c','C', 'd','D'):
                    dmap = {'a':0, 'b':1, 'c':2, 'd':3}
                    gl.FIT_IMAGE_SLIDESHOW_VAL = dmap[answer.lower()]
                    write_cfg("FIT_IMAGE_SLIDESHOW", str(gl.FIT_IMAGE_SLIDESHOW_VAL))
                clean_prefs(screen)
            if gamma_rect.collidepoint(cursor):
                new_gamma = do_gamma(screen)
                if new_gamma != None:
                    try:
                        set_gamma(float(new_gamma))
                    except:
                        print 'invalid gamma value: %s' % new_gamma
                clean_prefs(screen)
            if dirnum_colors_ucrect.collidepoint(cursor):
                gl.DIRNUM_COLORS ^= 1
                write_cfg("COLOR_DIRECTORY_NUMBERS")
            if screen_bgcolor_rect.collidepoint(cursor):
                answer = color_msg(screen, "Set this to the color you want the background in imgv to be. (Default is BLACK)")
                (gl.IMGV_COLOR, cfg_str) = color_change(answer, gl.IMGV_COLOR)
                color_clean(screen, "IMGV_COLOR", cfg_str)
            if font_color_rect.collidepoint(cursor):
                answer = color_msg(screen, "Set this to the font color you want. (Default is WHITE)")
                (gl.MSG_COLOR, cfg_str) = color_change(answer, gl.MSG_COLOR)
                gl.MENU_COLOR = gl.MSG_COLOR
                color_clean(screen, "FONT_COLOR", cfg_str)
            if font_bgcolor_rect.collidepoint(cursor):
                answer = color_msg(screen, "Font background color you want. (Default is BLACK)")
                (gl.FONT_BG, cfg_str) = color_change(answer, gl.FONT_BG)
                gl.MENU_COLOR = gl.MSG_COLOR
                color_clean(screen, "FONT_BGCOLOR", cfg_str)
            if img_border_color_rect.collidepoint(cursor):
                answer = color_msg(screen, "Set this to the color you want the image border to be when it's activated. (Default is LIGHT_GREEN)")
                (gl.IMG_BORDER_COLOR, cfg_str) = color_change(answer, gl.IMG_BORDER_COLOR)
                color_clean(screen, "IMAGE_BORDER_COLOR", cfg_str)
            if thumb_border_color_rect.collidepoint(cursor):
                answer = color_msg(screen, "Set this to the color you want the image divider to be in Four-at-a-Time mode. (Default is WHITE)")
                (gl.THUMB_BORDER_COLOR, cfg_str) = color_change(answer, gl.THUMB_BORDER_COLOR)
                color_clean(screen, "THUMB_BORDER_COLOR", cfg_str)
            if thumb_bgcolor_rect.collidepoint(cursor):
                answer = color_msg(screen, "Set this to the color you want the background of individual thumbnails to be. (Default is BLACK)")
                (gl.THUMB_BG_COLOR_VAL, cfg_str) = color_change(answer, gl.THUMB_BG_COLOR_VAL)
                color_clean(screen, "THUMB_BG_COLOR", cfg_str)
            if four_divcolor_rect.collidepoint(cursor):
                answer = color_msg(screen, "Set this to the color you want the image divider to be in Four-at-a-Time mode. (Default is WHITE)")
                (gl.FOUR_DIV_COLOR, cfg_str) = color_change(answer, gl.FOUR_DIV_COLOR)
                color_clean(screen, "FOUR_AT_A_TIME_DIVIDER_COLOR", cfg_str)
            if button_bgcolor_rect.collidepoint(cursor):
                answer = color_msg(screen, "Background color of buttons. (Default is IMGV_LOGO_BLUE)")
                (gl.BUTTON_BGCOLOR, cfg_str) = color_change(answer, gl.BUTTON_BGCOLOR)
                color_clean(screen, "BUTTON_BGCOLOR", cfg_str)
            if button_hover_color_rect.collidepoint(cursor):
                answer = color_msg(screen, "Color of buttons when your mouse cursor hovers over them. (Default is SKY_BLUE)")
                (gl.BUTTON_HOVERCOLOR, cfg_str) = color_change(answer, gl.BUTTON_HOVERCOLOR)
                color_clean(screen, "BUTTON_HOVERCOLOR", cfg_str)
            if button_textcolor_rect.collidepoint(cursor):
                answer = color_msg(screen, "Color of text on buttons. (Default is BLACK)")
                (gl.BUTTON_TEXTCOLOR, cfg_str) = color_change(answer, gl.BUTTON_TEXTCOLOR)
                color_clean(screen, "BUTTON_TEXTCOLOR", cfg_str)
            if button_texthovercolor_rect.collidepoint(cursor):
                answer = color_msg(screen, "Color of text on buttons when mouse cursor hovers over them. (Default is BLACK)")
                (gl.BUTTON_TEXTHOVERCOLOR, cfg_str) = color_change(answer, gl.BUTTON_TEXTHOVERCOLOR)
                color_clean(screen, "BUTTON_TEXTHOVERCOLOR", cfg_str)
            if close_button_color_rect.collidepoint(cursor):
                answer = color_msg(screen, "Color of the close/cancel buttons, the 'X' in the top/right corner of the screen. (Default is SADDLE_BROWN)")
                (gl.CLOSE_BUTTONCOLOR, cfg_str) = color_change(answer, gl.CLOSE_BUTTONCOLOR)
                color_clean(screen, "CLOSE_BUTTONCOLOR", cfg_str)
            if winsize_rect.collidepoint(cursor):
                paint_screen(gl.BLACK)
                show_message("Default Window Size or resolution of imgv (in the format: width x height. Default is: 800x600)", (15, 80), 13, ("bold", "transparent"))
                answer = ask(screen, "New window size")
                if answer != None:
                    x = None
                    if answer.find('x') != -1:
                        x = 'x'
                    elif answer.find('X') != -1:
                        x = 'X'
                    if x != None:
                        gl.IMGV_RESOLUTION = int(answer.split(x)[0]), int(answer.split(x)[1])
                    write_cfg("IMGV_WINDOW_SIZE", answer)
                clean_prefs(screen)
            if thumbsize_rect.collidepoint(cursor):
                paint_screen(gl.BLACK)
                show_message("The size you set will be used as the size of the thumbnail border/box, not the images themselves.", (15, 60), 13, ("bold", "transparent"))
                show_message("Values are in the format: width x height. Example: 100x100", (15, 100), 13, ("transparent"))
                show_message("To have imgv choose the best thumb size for a given default screen size use the default value of: AUTO", (15, 120), 13, ("transparent"))
                answer = ask(screen, "New thumbnail size")
                if answer != None:
                    gl.THUMB_VAL = answer
                    write_cfg("THUMB_SIZE", answer)
                clean_prefs(screen)
            if transeffect_rect.collidepoint(cursor):
                paint_screen(gl.BLACK)
                show_message("Valid values: NONE (default), MELT, FADE_IN", (15, 60), 13, ("bold", "transparent"))
                show_message("You can also apply multiple effects by separating them with |'s such as: MELT|FADE_IN", (15, 90), 13, ("transparent"))
                answer = ask(screen, "Transitional effect")
                if answer != None:
                    gl.TRANS_FX = answer
                    write_cfg("TRANSITIONAL_EFFECT", answer)
                clean_prefs(screen)
            if startdir_rect.collidepoint(cursor):
                paint_screen(gl.BLACK)
                show_message("Set this to an already existing directory that you want imgv to initially load images from.", (15, 60), 13, ("bold", "transparent"))
                if platform == 'win32':
                    show_message("For example: C:\photos\\", (15, 80), 13, ("transparent"))
                else:
                     show_message("For example: /home/photos/", (15, 80), 13, ("transparent"))
                show_message("Set to / (default) to have imgv load images from the root directory.", (15, 110), 13, ("transparent"))
                show_message("You an also specify a single image name.", (15, 150), 13, ("transparent"))
                show_message("For example: C:\pics\dog.jpg", (15, 170), 13, ("transparent"))
                answer = ask(screen, "Start directory")
                if answer != None:
                    gl.START_DIRECTORY_VAL = answer
                    write_cfg("START_DIRECTORY", answer)
                clean_prefs(screen)
            if external_editor_rect.collidepoint(cursor):
                paint_screen(gl.BLACK)
                show_message("Path to an external image editing application (You must put quotes around the value)", (15, 60), 13, ("bold", "transparent"))
                show_message("For example, if you want to use Adobe Photoshop with imgv you might put:", (15, 80), 13, ("transparent"))
                show_message("\"C:\\Program Files\\Adobe\\Photoshop CS2\\Photoshop.exe\"", (15, 100), 13, ("transparent"))
                show_message("Set to \"None\" (default) if you don't need this feature.", (15, 130), 13, ("transparent"))
                answer = ask(screen, "External editor")
                if answer != None:
                    gl.EXTERNAL_EDITOR = answer
                    write_cfg("EXTERNAL_EDITOR", answer)
                clean_prefs(screen)
            if passwd_rect.collidepoint(cursor):
                paint_screen(gl.BLACK)
                show_message("Set this to the password you want to be used in the 'Hide Image' feature.", (15, 60), 13, ("bold", "transparent"))
                show_message("It's case sensitive and don't use quotes.", (15, 90), 13, ("transparent"))
                show_message("Set to None (default) if you don't want to be prompted for a password.", (15, 110), 13, ("transparent"))
                answer = ask(screen, "New password")
                if answer != None:
                    gl.CORRECT_PASSWORD = answer
                    write_cfg("PASSWORD", answer)
                clean_prefs(screen)
            (transparent_text_crect, transparent_text_ucrect, main_statusbar_crect, main_statusbar_ucrect, four_statusbars_crect, four_statusbars_ucrect, exif_statusbar_crect, exif_statusbar_ucrect, thumb_statusbars_crect, thumb_statusbars_ucrect, image_border_crect, image_border_ucrect, fit_image_rect, dirnum_colors_crect, dirnum_colors_ucrect, screen_bgcolor_rect, lock_zoom_crect, lock_zoom_ucrect, wrap_crect, wrap_ucrect, wrap_slideshow_crect, wrap_slideshow_ucrect, start_fullscreen_crect, start_fullscreen_ucrect, thumb_border_crect, thumb_border_ucrect, show_movies_crect, show_movies_ucrect, font_color_rect, font_bgcolor_rect, img_border_color_rect, thumb_border_color_rect, thumb_bgcolor_rect, four_divcolor_rect, button_bgcolor_rect, button_hover_color_rect, button_textcolor_rect, button_texthovercolor_rect, close_button_color_rect, gamma_rect, winsize_rect, thumbsize_rect, transeffect_rect, startdir_rect, external_editor_rect, fit_slideshow_rect, passwd_rect) = pref_options(screen)
        gl.NOT_HOVERED = 1
Esempio n. 23
0
def show_dirs(screen, num_imgs, file):
    wait_cursor()
    if platform == 'win32':
        try:
            os.chdir(gl.DRIVE + ":")
        except:
            pass # Probably an OSError from not having a cd in the drive
    slash, get_curdir = os.sep, os.getcwd()
    fg_color = gl.SILVER
    font_size = 10
    font = pygame.font.Font(gl.FONT_NAME, font_size)
    font.set_bold(1) # very important
    line = 55
    name_max = 16 # dir name max
    menu_items = []
    if get_curdir[-1] == slash:
        curdir = get_curdir 
    else:
        curdir = get_curdir + slash
    paint_screen(screen, gl.BLACK)
    screen_height = screen.get_height()

    if not gl.BEEN_THERE_DONE_THAT:
        show_message(screen, "You can type in a directory number or shortcut (L/T/A/D/C/V/S/Q) instead of clicking: _", "bottom", 11)
    else:
        show_message(screen, "Directory number or shortcut: _", "bottom", 11)

    curdir_msg = check_truncate(screen.get_width(), curdir)
    all_files = os.listdir('.')
    all_files.sort()
    n_dirs = len([d for d in all_files if os.path.isdir(d)])
    all_files = [f for f in all_files if not os.path.isdir(f)]
    n_files = len(all_files)
    all_images = get_imgs(os.getcwd(), 0)
    n_images = len(all_images)
    get_movies = lambda x, y: [i.upper().endswith(y) for i in all_images].count(True)
    n_movies = get_movies(all_images, ".MPG") + get_movies(all_images, ".MPEG")
    dirs_text = "Directories"
    files_text = "Files"
    images_text = "Images"
    movies_text = "MPEGs"
    if n_dirs == 1: dirs_text = "Directory" # unplural
    if n_files == 1: files_text = "File"
    if n_images == 1: images_text = "Image"
    if n_movies == 1: movies_text = "MPEG"
    files_msg = "[%d %s. %d %s. %d %s. %d %s]" % (n_dirs, dirs_text, n_files, files_text, n_images - n_movies, images_text, n_movies, movies_text)
    curdir_msg_wpos = (screen.get_width() / 2 - font.size(curdir_msg)[0] / 2) - font.size(files_msg)[0] / 2 + 10
    files_msg_wpos = screen.get_width() / 2 + font.size(curdir_msg)[0] / 2 - font.size(files_msg)[0] / 2 + 20

    if not gl.REFRESH_IMG_COUNT and gl.CACHE_DIR_OK:
        dirs = gl.CACHE_DIRS
        gl.REFRESH_IMG_COUNT = 1
        set_caption(curdir)
        show_message(screen, curdir_msg, (curdir_msg_wpos, 4), 10, ("bold"))
        show_message(screen, files_msg, (files_msg_wpos, 4), 10)
    else:
        show_message(screen, curdir_msg, (curdir_msg_wpos, 4), 10, ("bold"))
        show_message(screen, files_msg, (files_msg_wpos, 4), 10)
        set_caption(curdir)
        dirs = os.listdir(curdir)
        dirs.sort()
        dirs = strip_dirs(dirs)
        # ensure the root dir and last dir items go at top
        dirs.insert(0, "..")
        dirs.insert(0, slash)
        gl.CACHE_DIRS = dirs
    ren_load_rect = imgv_button(screen, " (L)oad ", 0, 18, "topleft")
    ren_load_subdirs_rect = imgv_button(screen, " Subdirs (T)oo ", 62, 18, "topleft")
    if platform == 'win32':
        ren_drive_rect = imgv_button(screen, " Change (D)rive ", 271, 18, "topleft")
    dirpl_rect = imgv_button(screen, " (A)dd To Playlist ", 160, 18, "topleft")
    untag_all_rect = imgv_button(screen, " (C)lear Tags ", 380, 18, "topleft")
    view_tagged_rect = imgv_button(screen, " (V)iew Tags ", 472, 18, "topleft")
    filter_rect = imgv_button(screen, " (S)earch ", 559, 18, "topleft")
    col = 10
    show_message(screen, "Right-Click directories to tag multiple directories to load. Ctrl+Left-Click to untag.", (10, 40), 10)
    if gl.MULT_DIRS != []:
        show_message(screen, "[Dirs tagged: %s]" % len(gl.MULT_DIRS), (440, 40), 10, "bold")

    if gl.FILTER_COMMAND != {}:
        show_message(screen, "[Filter: on]", (560, 40), 10, "bold")

    # add numbers to directory names
    if gl.ADDED_DIR_NUMS == 0 and dirs[0] != '*':
        gl.ADDED_DIR_NUMS = 1
        for i, d in enumerate(dirs):
            dirs[i] = '*' + str(i) + gl.DIRNUMSEP + d
    for d in dirs:
        d = d[1:] # strip out the '*' marker
        if d[3:] == slash:
            if gl.DIRNUM_COLORS:
                dmsg = d
            else:
                ren = font.render(d, 1, gl.MSG_COLOR)
        else:
            if len(d) > name_max:
                if gl.DIRNUM_COLORS:
                    dmsg = truncate_name(d, name_max)
                else:
                    ren = font.render(truncate_name(d, name_max), 1, gl.MSG_COLOR)
            else:
                if gl.DIRNUM_COLORS:
                    dmsg = d + slash
                else:
                    ren = font.render(d + slash, 1, gl.MSG_COLOR)
            
        # print directory names on screen, wrapping if necessary
        font_height = font.size(' '.join(d.split(' ')[1:]))[1]
        if (line + font_height) >= (screen_height - 10):
            line = 55 # reset to beginning of screen
            col = col + (name_max + 130) # go to next column

        if gl.DIRNUM_COLORS:
            before_color = gl.MSG_COLOR
            if gl.MSG_COLOR == gl.SILVER:
                gl.MSG_COLOR = (142, 142, 142)
            else:
                gl.MSG_COLOR = gl.SILVER
            if before_color == gl.WHITE:
                ren_rect = show_message(screen, dmsg, (col, line), font_size, ("bold"), (len(dmsg[:dmsg.index(gl.DIRNUMSEP) + 1]), gl.SILVER))
            else:
                ren_rect = show_message(screen, dmsg, (col, line), font_size, ("bold"), (len(dmsg[:dmsg.index(gl.DIRNUMSEP) + 1]), before_color))
        else:
            ren_rect = ren.get_rect()
            ren_rect[0] = col
            ren_rect[1] = line
            screen.blit(ren, ren_rect)
            update(ren_rect)
        line = line + 12
        menu_items.append((ren_rect, d))
        if gl.DIRNUM_COLORS:
            gl.MSG_COLOR = before_color

    normal_cursor()
    pygame.event.set_blocked(MOUSEMOTION)
    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, curdir, menu_items, cursor)
        if platform == 'win32':#
            hover_cursor(cursor, [ren_load_rect, ren_load_subdirs_rect, ren_drive_rect, dirpl_rect, untag_all_rect, view_tagged_rect, filter_rect, esc_rect] + [x[0] for x in menu_items])
        hover_button(ren_load_rect, cursor, screen, " (L)oad ", 0, 18, "topleft")
        hover_button(ren_load_subdirs_rect, cursor, screen, " Subdirs (T)oo ", 62, 18, "topleft")
        if platform == 'win32':
            hover_button(ren_drive_rect, cursor, screen, " Change (D)rive ", 271, 18, "topleft")
        hover_button(dirpl_rect, cursor, screen, " (A)dd To Playlist ", 160, 18, "topleft")
        hover_button(untag_all_rect, cursor, screen, " (C)lear Tags ", 380, 18, "topleft")
        hover_button(view_tagged_rect, cursor, screen, " (V)iew Tags ", 472, 18, "topleft")
        hover_button(filter_rect, cursor, screen, " (S)earch ", 559, 18, "topleft")
        if left_click(event):
            for item in menu_items:
                if item[0].collidepoint(cursor):
                    if pygame.mouse.get_pressed()[0] and (pygame.key.get_pressed()[K_LCTRL] or\
                       pygame.key.get_pressed()[K_RCTRL]): 
                        try: # untag directory
                            gl.MULT_DIRS.remove(os.getcwd() + slash + ' '.join(item[1].split(' ')[1:]))
                            show_message(screen, " " * 30, (440, 40), 10, ("bold"))
                            show_message(screen, "[Dirs tagged: %s]" % len(gl.MULT_DIRS), (440, 40), 10, "bold")
                        except:
                            pass
                    else: # (normal mode) change to a single directory and load its images
                        (num_imgs, file) = do_change_dir(screen, num_imgs, file, item[1])
                        return (num_imgs, file)
        if right_click(event):
            for item in menu_items:
                if item[0].collidepoint(cursor):
                    # tag directory
                    if os.getcwd()[-1] != slash:
                        gl.MULT_DIRS.append(os.getcwd() + slash + ' '.join(item[1].split(' ')[1:]))
                    else:
                        gl.MULT_DIRS.append(os.getcwd() + ' '.join(item[1].split(' ')[1:]))
                    show_message(screen, " " * 30, (440, 40), 10, ("bold"))
                    show_message(screen, "[Dirs tagged: %s]" % len(gl.MULT_DIRS), (440, 40), 10, "bold")
                    
        # allow number keys to be used to change directories
        dirnum = None
        if event.type == KEYDOWN and event.key in (K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9, K_0, K_KP1, K_KP2, K_KP3, K_KP4, K_KP5, K_KP6, K_KP7, K_KP8, K_KP9, K_KP0):
            dirnum = get_dirnum(screen, event.key)
            if dirnum != 'backspaced':
                for item in menu_items:
                    if item[1].startswith(str(dirnum)):
                        (num_imgs, file) = do_change_dir(screen, num_imgs, file, item[1])
                        return (num_imgs, file)
                break

        if hit_key(event, K_RETURN) or hit_key(event, K_SPACE) or hit_key(event, K_l):
            (num_imgs, file) = do_load_dir()
            break
        if hit_key(event, K_t): # load subdirs on keypress 't'
            (num_imgs, file) = do_subdirs_too()
            break
        if hit_key(event, K_s): # search
           command_get_filter_info(screen)
           (num_imgs, file) = show_dirs(screen, num_imgs, file)
           break
        if hit_key(event, K_d): # change drives
           if platform == 'win32':
               gl.WAS_IN_CHANGE_DRIVES = 1
               (num_imgs, file) = do_change_drive(screen, num_imgs, file)
               gl.WAS_IN_CHANGE_DRIVES = 0
               break
        if hit_key(event, K_c): # clear tag list
            do_untag(screen)
        if hit_key(event, K_v): # view tagged dirs
           do_view_tagged(screen, num_imgs, file)
           break # break main loop to display properly
        if hit_key(event, K_a): # add curdir to playlist
           command_add_to_play_list(screen, curdir)
           return (num_imgs, file) 
        if hit_key(event, K_ESCAPE):
            gl.ESCAPED = 1
            gl.ADDED_DIR_NUMS = 0
            break
        if left_click(event):
            if esc_rect.collidepoint(cursor):
                gl.ESCAPED = 1
                gl.ADDED_DIR_NUMS = 0
                break
            if ren_load_rect.collidepoint(cursor): # load current dir
                (num_imgs, file) = do_load_dir()
                break
            if ren_load_subdirs_rect.collidepoint(cursor): # load subdirs too
                (num_imgs, file) = do_subdirs_too()
                break
            if platform == 'win32':
                if ren_drive_rect.collidepoint(cursor):
                    gl.WAS_IN_CHANGE_DRIVES = 1
                    (num_imgs, file) = do_change_drive(screen, num_imgs, file)
                    gl.WAS_IN_CHANGE_DRIVES = 0
                    break
            if dirpl_rect.collidepoint(cursor):
                command_add_to_play_list(screen, curdir)
                return (num_imgs, file)
            if untag_all_rect.collidepoint(cursor):
                do_untag(screen)
            if view_tagged_rect.collidepoint(cursor): 
                do_view_tagged(screen, num_imgs, file)
                break # break main loop to display properly
            if filter_rect.collidepoint(cursor):
                command_get_filter_info(screen)
                (num_imgs, file) = show_dirs(screen, num_imgs, file)
                break
        check_quit(event)
    gl.CACHE_DIR_OK = 1 
    return (num_imgs, file)
Esempio n. 24
0
def get_speed(screen, new_img, rect, filename, file, num_imgs):
    "get input from keyboard (including number pad) and only accept/display digits"
    paint_screen(screen, gl.BLACK)
    normal_cursor()
    DEFAULT_SPEED = 5
    MAX_SPEED = 100000
    speed_msg = " Enter number of seconds to delay between images (Default=5): _ "
    speed = ['0']
    char_space = 0
    screen_midtop = (screen.get_rect().midtop[0], screen.get_rect().midtop[1] + 20)
    font = pygame.font.Font(gl.FONT_NAME, 13)
    ren_speed_msg = font.render(speed_msg, 1, gl.MSG_COLOR)
    ren_speed_msg_rect = ren_speed_msg.get_rect()
    ren_speed_msg_width = ren_speed_msg.get_width()
    ren_speed_msg_rect.midtop = screen_midtop
    screen.blit(ren_speed_msg, ren_speed_msg_rect)
    update(ren_speed_msg_rect)
    (esc_rect, close_font) = close_button(screen)
    my_digits = [] # keypad number list.
    dirty_rects = []
    for num in range(10):
        my_digits.append('[%d]' % num) # [0],[1]...[9]
    pygame.event.set_allowed(MOUSEMOTION)
    while 1:
        event = pygame.event.wait()
        cursor = pygame.mouse.get_pos()
        hover_cursor(cursor, (esc_rect,))
        if event.type == KEYDOWN and not event.key == K_RETURN:
            speed_input = pygame.key.name(event.key)
            try:
                check_quit(event)
                if speed_input in my_digits or speed_input in digits:
                    # only echo digits (0-9)
                    for i in speed_input:
                        # extract n from brackets, [n]
                        if i in digits:
                            speed_input = i
                    speed.append(speed_input)
                    ren_speed = font.render(speed_input, 1, gl.MSG_COLOR, gl.BLACK)
                    ren_speed_rect = ren_speed.get_rect()
                    ren_speed_rect.midtop = screen_midtop
                    # dividing by 2.12 allows to overwrite the "_" fake cursor marker:
                    ren_speed_rect[0] = ren_speed_rect[0] + (char_space + (ren_speed_msg_width / 2.12) + 5)
                    dirty_rects.append(ren_speed_rect)
                    screen.blit(ren_speed, ren_speed_rect)
                    update(ren_speed_rect)
                    char_space = char_space + ren_speed.get_width()
            except TypeError:
                # don't crash if user hits Backspace, Esc, etc.
                pass
        if hit_key(event, K_RETURN) or hit_key(event, K_KP_ENTER):
            break
        if left_click(event):
            if esc_rect.collidepoint(cursor):
                wait_cursor()
                my_update_screen(new_img, screen, rect, file, num_imgs)
                normal_cursor()
                return -1
        if hit_key(event, K_ESCAPE):
            wait_cursor()
            my_update_screen(new_img, screen, rect, file, num_imgs)
            normal_cursor()
            return -1
        if hit_key(event, K_BACKSPACE) or hit_key(event, K_DELETE) or hit_key(event, K_KP_PERIOD):
            # erase whatever text was inputed
            speed = ['0']
            try:
                for rect in dirty_rects:
                    paint_screen(screen, gl.BLACK, rect)
                char_space = ren_speed.get_width()
            except:
                pass
    # convert to a valid speed
    if not len(speed) > 1:
        speed.append(str(DEFAULT_SPEED))
    speed = int(''.join(speed))
    if speed > MAX_SPEED:
        speed = DEFAULT_SPEED
    return speed
Esempio n. 25
0
File: thumb.py Progetto: rkulla/imgv
def thumbs_engine(screen, new_img, file):
    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)
        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)
                    for item in x:  # load clicked image:
                        if item[0].collidepoint(cursor):
                            wait_cursor()
                            new_img = load_img(item[1])
                            file = gl.files.index(item[1])
                            return (new_img, new_img, new_img, file)
                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(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(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)
        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)
Esempio n. 26
0
def command_show_res_modes(screen, new_img, file, num_imgs, rect):
    paint_screen(screen, gl.BLACK)
    set_caption("Resize Options - imgv")
    menu_items = []
    (esc_rect, font) = close_button(screen)
    res_font = pygame.font.Font(gl.FONT_NAME, 18)
    res_font.set_bold(1)
    show_message(screen, "Choose a preset or custom window size for imgv", "top", 12, ("underline", "bold"))
    show_message(screen, "Use current window size as fullscreen resolution?", (170, 192), 10)
    show_message(screen, "No  Yes", (430, 182), 10)
    show_message(screen, "Option: _", "bottom", 12)
    (menu_items, men_ops) = show_res_modes(screen, menu_items, res_font)
    pygame.event.set_blocked(MOUSEMOTION)
    while 1:
       event = pygame.event.poll()
       pygame.time.wait(35) # don't use 100% CPU
       cursor = pygame.mouse.get_pos()
       hover_fx(screen, menu_items, cursor, res_font)
       if gl.NOT_HOVERED:
           show_message(screen, "%sOption: _%s" % (" " * 100, " " * 100), "bottom", 12)
           blank_fx(screen, 0)
       check_quit(event)

       if event.type == VIDEORESIZE:
            screen = pygame.display.set_mode(event.dict['size'], RESIZABLE)
            rect = get_center(screen, new_img)
            command_show_res_modes(screen, new_img, file, num_imgs, rect)
            break

       # draw checked box:
       checked_img = load_img(gl.CHECKED_BOX, screen, False)
       checked_img_rect = checked_img.get_rect()
       if gl.FULLSCREEN_SPECIAL == 0:
           checked_img_rect[0] = 432
       else:
           checked_img_rect[0] = 455
       checked_img_rect[1] = 195
       screen.blit(checked_img, checked_img_rect)
       update(checked_img_rect)

       # draw unchecked box:
       unchecked_img = load_img(gl.UNCHECKED_BOX, screen, False)
       unchecked_img_rect = unchecked_img.get_rect()
       if gl.FULLSCREEN_SPECIAL == 0:
           unchecked_img_rect[0] = 455
       else:
           unchecked_img_rect[0] = 432
       unchecked_img_rect[1] = 195
       screen.blit(unchecked_img, unchecked_img_rect)
       update(unchecked_img_rect)

       hover_cursor(cursor, [esc_rect, checked_img_rect, unchecked_img_rect] + [x[0] for x in menu_items])

       if hit_key(event, K_ESCAPE):
           update_res_screen(screen, file, new_img)
           return rect
       if event.type == KEYDOWN and event.key in (K_F2, K_F3, K_F4, K_F5, K_F6, K_c):
           if hit_key(event, K_F2):
               rect = command_640x480(new_img, file, num_imgs, rect)
           if hit_key(event, K_F3):
               rect = command_800x600(new_img, file, num_imgs, rect)
           if hit_key(event, K_F4):
               rect = command_1024x768(new_img, file, num_imgs, rect)
           if hit_key(event, K_F5):
               rect = command_1280x1024(new_img, file, num_imgs, rect)
           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)
           if hit_key(event, K_c):
               rect = do_custom(screen, new_img, file, num_imgs, rect)
           return rect
       if left_click(event):
           if esc_rect.collidepoint(cursor):
               gl.ESCAPED = 1
               update_res_screen(screen, file, new_img)
               return rect
           if unchecked_img_rect.collidepoint(cursor):
               gl.FULLSCREEN_SPECIAL ^= 1 # toggle
           for it in menu_items:
               if it[0].collidepoint(cursor) and it[1] in men_ops:
                   if it[1] == "F2) 640x480":
                       rect = command_640x480(new_img, file, num_imgs, rect)
                   elif it[1] == "F3) 800x600":
                       rect = command_800x600(new_img, file, num_imgs, rect)
                   elif it[1] == "F4) 1024x768":
                       rect = command_1024x768(new_img, file, num_imgs, rect)
                   elif it[1] == "F5) 1280x1024":
                       rect = command_1280x1024(new_img, file, num_imgs, rect)
                   elif it[1] == "F6) Fullscreen":
                       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)
                   elif it[1] == "C) Custom":
                       rect = do_custom(screen, new_img, file, num_imgs, rect)
                   return rect
       gl.NOT_HOVERED = 1
    return rect
Esempio n. 27
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. 28
0
File: edit.py Progetto: rkulla/imgv
def command_edit_menu(screen, file, new_img, rect):
    menu_items = []
    paint_screen(gl.BLACK)
    (esc_rect, font) = close_button(screen)
    show_message("%s" % os.path.basename(gl.files[file]), "top", 12, "bold")
    show_message("Option number: _", "bottom", 12)
    pygame.event.set_blocked(MOUSEMOTION)
    (menu_items, men_ops) = edit_menu(screen, file, menu_items)
    while 1:
       event = pygame.event.poll()
       pygame.time.wait(1)
       check_quit(event)
       cursor = pygame.mouse.get_pos()
       hover_fx(screen, menu_items, men_ops, cursor, font)
       hover_cursor(cursor, [esc_rect] + [x[0] for x in menu_items])
       if gl.NOT_HOVERED:
           show_message("%sOption number: _%s" % (" " * 100, " " * 100), "bottom", 12)
           blank_fx(screen, -1)

       if hit_key(event, K_ESCAPE):
           gl.USING_SCROLL_MENU = 0
           update_edit_screen(screen, file, new_img)
           return (new_img, new_img, new_img, file, rect)
       if left_click(event):
           if esc_rect.collidepoint(cursor):
               gl.USING_SCROLL_MENU = 0
               update_edit_screen(screen, file, new_img)
               return (new_img, new_img, new_img, file, rect)

       if event.type == KEYDOWN and event.key in (K_1, K_2, K_3, K_4, K_KP1, K_KP2, K_KP3, K_KP4):
           if hit_key(event, K_1) or hit_key(event, K_KP1):
               (new_img, img, refresh_img, file, rect) = do_delete_image(screen, new_img, file, rect)
               paint_screen(gl.BLACK)
               (menu_items, men_ops) = edit_menu(screen, file, menu_items)
           if hit_key(event, K_2) or hit_key(event, K_KP2):
               do_set_wallpaper(screen, file, new_img, rect)
               paint_screen(gl.BLACK)
               (menu_items, men_ops) = edit_menu(screen, file, menu_items)
           if hit_key(event, K_3) or hit_key(event, K_KP3):
                if gl.EXTERNAL_EDITOR not in ('"None"', '"none"', '"NONE"', ''):
                    do_external_viewer(screen, file, new_img)
                paint_screen(gl.BLACK)
                (menu_items, men_ops) = edit_menu(screen, file, menu_items)
           if hit_key(event, K_4) or hit_key(event, K_KP4):
               preferences(screen)
               (menu_items, men_ops) = edit_menu(screen, file, menu_items)

       if event.type == MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:
           for it in menu_items:
               if it[0].collidepoint(cursor) and it[1] in men_ops:
                   if it[1] == "1) Delete image":
                       (new_img, new_img, new_img, file, rect) = do_delete_image(screen, new_img, file, rect)
                       paint_screen(gl.BLACK)
                       (menu_items, men_ops) = edit_menu(screen, file, menu_items)
                       break
                   if it[1] == "2) Set as wallpaper":
                       do_set_wallpaper(screen, file, new_img, rect)
                       paint_screen(gl.BLACK)
                       (menu_items, men_ops) = edit_menu(screen, file, menu_items)
                       break
                   if it[1] == "3) Open in external viewer":
                        do_external_viewer(screen, file, new_img)
                        paint_screen(gl.BLACK)
                        (menu_items, men_ops) = edit_menu(screen, file, menu_items)
                        break
                   if it[1] == "4) Preferences":
                       preferences(screen)
                       (menu_items, men_ops) = edit_menu(screen, file, menu_items)
                       break
                   return (new_img, new_img, new_img, file, rect)
       gl.NOT_HOVERED = 1
    return (new_img, new_img, new_img, file, rect)