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