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"
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
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
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)
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)
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)