[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] video error



Is the entirety of your code in your __init__ class?

I'm not sure if the spacing got mangled in the e-mail but the way it came across when I cut and pasted the class into my editor is that your while loop is in the main Class, not in the __init__ function.  Since the class gets created before the __init__ is called that's what's causing your problem.



On 9/26/07, Eric Hunter <hunter.eric1@xxxxxxxxx> wrote:
can't understand why I'm getting this error. everything looks okay to me. but then again I'm a newbie. thanks in advance.

Traceback (most recent call last):
  File "las.py", line 54, in <module>
    class PygameClass():
  File "las.py", line 78, in PygameClass
    for event in pygame.event.get():
pygame.error: video system not initialized



[code]
class PygameClass():
        # Starts Pygame
        def __init__(self, full_path):
            pygame.init()
            self.window = pygame.display.set_mode((1,1), pygame.RESIZABLE)
            self.image_name = os.path.basename(full_path)
            pygame.display.set_caption(self.image_name)
            self.image = pygame.image.load(full_path)
            self.image = self.image.convert()
            self.image_rect = self.image.get_rect()
            print self.image_rect
            print self.image_rect.width
            print self.image_rect.height
            self.window = pygame.display.set_mode((self.image_rect.width, self.image_rect.height))
            self.window = self.window.convert()

        self.point_draw = 1
        self.numRect = 0
        rect = {}
 
            self.screen.blit(self.image, (0, 0))
            pygame.display.flip()
 
        while True:
                for event in pygame.event.get():
            if self.event.type == QUIT:
                pygame.quit()
                sys.exit()

            elif self.event.type == pygame.KEYDOWN:
                if self.event.key == K_s:
                    self.out_file = open("text.txt", "w")
                    pickle.dump(rect, self.out_file)
                    print "memory dumped."
                    self.out_file.close()
                if self.event.key == K_o:
                    self.in_file = open('text.txt', 'r')
                    rect = pickle.load(self.in_file )
                    print "memory loaded."
                    self.in_file.close()
   
            elif self.event.type == pygame.MOUSEBUTTONDOWN:
                if self.event.button == 1:
                    # If point_draw = 1, get x,y of mouse
                    if self.point_draw == 1:
                        self.mouseX1, self.mouseY1 = pygame.mouse.get_pos()
                        self.point_draw = 2
                    else:
                        # If point_draw = 2, get x,y of mouse, make a rect and throw it in a dictionary
                        self.mouseX2, self.mouseY2 = pygame.mouse.get_pos()
                        self.numRect += 1
                        self.newRect = pygame.Rect(self.mouseX1, self.mouseY1, self.mouseX2 - self.mouseX1, self.mouseY2 - self.mouseY1)
                        rect[self.numRect ] = self.newRect
                        self.point_draw = 1
                elif self.event.button == 3:
                    self.mouseXTEMP, self.mouseYTEMP = pygame.mouse.get_pos()
                    for self.x in rect.keys():
                        if rect[self.x].collidepoint(self.mouseXTEMP, mself.ouseYTEMP):
                            del rect[x]
                            self.numRect -= 1
   
        # draws the rectangles in the rect{}   
        for self.x in rect.keys():
            pygame.draw.rect(window, ((255, 255, 0)), rect[self.x], 1)
       
        pygame.display.flip()

[/code]