示例#1
0
文件: error_box.py 项目: rkulla/imgv
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
示例#2
0
文件: imgv.py 项目: rkulla/imgv
 def __init__(self):
     init_screen()
     wait_cursor()
     self.gfx = {}
     self.gfx['screen'] = pygame.display.set_mode(gl.DEFAULT_RES, RESIZABLE)
     set_caption(gl.TITLE)
     if gl.REMOTE == 1:
         show_message("Loading image. Please wait..", 34, 42)
     self.gfx['file'] = 0
     if len(gl.files) < 1:
         gl.files = [gl.IMGV_LOGO]
     self.gfx['img'] = load_img(gl.files[self.gfx['file']])
     wait_cursor()
     self.gfx['refresh_img'] = self.gfx['img']
     self.gfx['new_img'] = self.gfx['img']
     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'])
     normal_cursor()
     if gl.START_FULLSCREEN:
         command_fullscreen()
         my_update_screen(self.gfx['new_img'], self.gfx['rect'], self.gfx['file'])
     self.minus1 = 0
     self.minus2 = 0
     self.last_rect = Rect(self.gfx['rect'])
示例#3
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()