Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
	modified:   .gitignore
		don't ignore png files
	new file:   resource/big.png
	new file:   resource/brush.png
	new file:   resource/pen1.png
	new file:   resource/pen2.png
	new file:   resource/small.png
		add resource files
	modified:   src/painter.py
		query when mouse up
  • Loading branch information
lqhl committed May 11, 2012
1 parent d6f4d83 commit 6f1cd4d
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -3,6 +3,5 @@
*.pkl
*.mat

*.png
*.jpg
test.jpg
data/
Binary file added resource/big.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/brush.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/pen1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/pen2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/small.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 14 additions & 12 deletions src/painter.py
Expand Up @@ -24,7 +24,7 @@ def __init__(self, screen, im):
# if style is False, png brush
self.style = False
# load brush style png
self.brush = pygame.image.load("brush.png").convert_alpha()
self.brush = pygame.image.load("../resource/brush.png").convert_alpha()
# set the current brush depends on size
self.brush_now = self.brush.subsurface((0,0), (1, 1))

Expand Down Expand Up @@ -113,17 +113,17 @@ def __init__(self, screen):
self.colors_rect.append(rect)

self.pens = [
pygame.image.load("pen1.png").convert_alpha(),
pygame.image.load("pen2.png").convert_alpha()
pygame.image.load("../resource/pen1.png").convert_alpha(),
pygame.image.load("../resource/pen2.png").convert_alpha()
]
self.pens_rect = []
for (i, img) in enumerate(self.pens):
rect = pygame.Rect(10, 10 + i * 64, 64, 64)
self.pens_rect.append(rect)

self.sizes = [
pygame.image.load("big.png").convert_alpha(),
pygame.image.load("small.png").convert_alpha()
pygame.image.load("../resource/big.png").convert_alpha(),
pygame.image.load("../resource/small.png").convert_alpha()
]
self.sizes_rect = []
for (i, img) in enumerate(self.sizes):
Expand Down Expand Up @@ -250,7 +250,7 @@ def run(self):
self.screen.fill((255, 255, 255))
self.im.clear()
elif event.key == K_s:
self.update(self.im.convert())
self.update()
elif event.type == MOUSEBUTTONDOWN:
# coarse judge here can save much time
if event.pos[0] < 80:
Expand All @@ -260,27 +260,29 @@ def run(self):
elif event.type == MOUSEMOTION:
if event.pos[0] < 80 or event.pos[0] >= 680:
self.brush.end_draw()
self.update()
else:
self.brush.draw(event.pos)
elif event.type == MOUSEBUTTONUP or event.type == ACTIVEEVENT and event.gain == 0:
self.brush.end_draw()
self.update()

self.menu.draw()
try:
self.board.update(self.queue.get_nowait())
except Empty:
pass
if self.process is not None and not self.process.is_alive():
self.process = None
self.board.draw()
pygame.display.update()

def update(self, d):
def update(self):
d = self.im.convert()
#query.query(self.mData, d)
#thread.start_new_thread(query.query, (self.mData, d))
if self.process is None:
self.process = Process(target = do_query, args = (self.mData, d, self.queue))
self.process.start()
if self.process is not None and self.process.is_alive():
self.process.terminate()
self.process = Process(target = do_query, args = (self.mData, d, self.queue))
self.process.start()

if __name__ == '__main__':
app = Painter()
Expand Down

0 comments on commit 6f1cd4d

Please sign in to comment.