comparison tools/rect_drawer.py @ 509:616334ea5e8c

Add mode label
author Neil Muller <neil@dip.sun.ac.za>
date Fri, 03 Sep 2010 16:41:25 +0200
parents 91ee6107a216
children d274cc414178
comparison
equal deleted inserted replaced
508:91ee6107a216 509:616334ea5e8c
8 sys.path.append(script_path) 8 sys.path.append(script_path)
9 9
10 from albow.root import RootWidget 10 from albow.root import RootWidget
11 from albow.utils import frame_rect 11 from albow.utils import frame_rect
12 from albow.widget import Widget 12 from albow.widget import Widget
13 from albow.controls import Button, Image 13 from albow.controls import Button, Image, Label
14 from albow.palette_view import PaletteView 14 from albow.palette_view import PaletteView
15 from albow.file_dialogs import request_old_filename 15 from albow.file_dialogs import request_old_filename
16 from albow.resource import get_font 16 from albow.resource import get_font
17 from pygame.locals import SWSURFACE, K_LEFT, K_RIGHT, K_UP, K_DOWN, \ 17 from pygame.locals import SWSURFACE, K_LEFT, K_RIGHT, K_UP, K_DOWN, \
18 K_t, K_d, K_i, K_r, K_o, K_b, K_z, \ 18 K_t, K_d, K_i, K_r, K_o, K_b, K_z, \
458 def mouse_drag(self, e): 458 def mouse_drag(self, e):
459 if self.mode == 'draw': 459 if self.mode == 'draw':
460 self.end_pos = self._conv_pos(e.pos) 460 self.end_pos = self._conv_pos(e.pos)
461 self.invalidate() 461 self.invalidate()
462 462
463
464 class ModeLabel(BoomLabel):
465
466 def __init__(self, app_image):
467 self.app_image = app_image
468 super(ModeLabel, self).__init__('Mode : ', 200,
469 font=get_font(15, 'VeraBd.ttf'),
470 fg_color = pygame.color.Color(128, 0, 255))
471 self.rect.move_ip(805, 0)
472
473 def draw_all(self, surface):
474 self.set_text('Mode : %s' % self.app_image.mode)
475 super(ModeLabel, self).draw_all(surface)
476
477
463 def make_button(text, action, ypos): 478 def make_button(text, action, ypos):
464 button = Button(text, action=action, font=get_font(15, 'VeraBd.ttf')) 479 button = Button(text, action=action, font=get_font(15, 'VeraBd.ttf'))
465 button.align = 'l' 480 button.align = 'l'
466 button.rect = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT) 481 button.rect = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT)
467 button.rect.move_ip(805, ypos) 482 button.rect.move_ip(805, ypos)
468 return button 483 return button
469 484
485
470 class RectApp(RootWidget): 486 class RectApp(RootWidget):
471 """Handle the app stuff for the rect drawer""" 487 """Handle the app stuff for the rect drawer"""
472 488
473 def __init__(self, display): 489 def __init__(self, display):
474 super(RectApp, self).__init__(display) 490 super(RectApp, self).__init__(display)
475 self.image = AppImage(state) 491 self.image = AppImage(state)
476 self.add(self.image) 492 self.add(self.image)
477 y = 0 493 mode_label = ModeLabel(self.image)
494 self.add(mode_label)
495 y = mode_label.get_rect().h
478 draw = make_button('Draw Rect', self.image.draw_mode, y) 496 draw = make_button('Draw Rect', self.image.draw_mode, y)
479 self.add(draw) 497 self.add(draw)
480 y += draw.get_rect().h 498 y += draw.get_rect().h
481 load_image = make_button("Load image", self.image.image_load, y) 499 load_image = make_button("Load image", self.image.image_load, y)
482 self.add(load_image) 500 self.add(load_image)