class MinWii(object):
def __init__(self) :
class MinWii(object):
def __init__(self) :
- app = Desktop()
- synth = Synth()
+ #app = Desktop()
+ #synth = Synth()
- home = Home(songPath=SONG_FILE_PATH)
- home.connect(QUIT, app.quit)
- app.run(home)
- app.close(home)
+ #home = Home(songPath=SONG_FILE_PATH)
+ #home.connect(QUIT, app.quit)
+ #app.run(home)
+ #app.close(home)
selector = InstrumentSelector()
selector.run()
selector.stop()
pygame.event.clear()
EventDispatcher.reset()
selector = InstrumentSelector()
selector.run()
selector.stop()
pygame.event.clear()
EventDispatcher.reset()
song = musicXml2Song(home.songFile, printNotes=True)
synth.program_select(0, 0, 0)
song = musicXml2Song(home.songFile, printNotes=True)
synth.program_select(0, 0, 0)
#self._initRects()
self._initTiles()
self._initCursor()
#self._initRects()
self._initTiles()
self._initCursor()
+ self._inflatedTile = None
def _initTiles(self) :
screen = pygame.display.get_surface()
def _initTiles(self) :
screen = pygame.display.get_surface()
if event.key == pygame.K_q:
self.stop()
if event.key == pygame.K_q:
self.stop()
- #@event_handler(pygame.MOUSEMOTION)
- @event_handler(pygame.MOUSEBUTTONDOWN)
+ @event_handler(pygame.MOUSEMOTION)
+ #@event_handler(pygame.MOUSEBUTTONDOWN)
def onMouseMove(self, event) :
for tile in reversed(self.sprites()[:-1]) :
if tile.rect.collidepoint(*event.pos) :
def onMouseMove(self, event) :
for tile in reversed(self.sprites()[:-1]) :
if tile.rect.collidepoint(*event.pos) :
break
def raiseTileOver(self, tile) :
break
def raiseTileOver(self, tile) :
- self.change_layer(tile, FOREGROUND_LAYER)
- tile.inflate(tile.coords)
+ if not tile.inflated :
+ self.change_layer(tile, FOREGROUND_LAYER)
+ tile.inflate(tile.coords)
+
+ if self._inflatedTile :
+ self._inflatedTile.deflate()
+ self.change_layer(self._inflatedTile, BACKGROUND_LAYER)
+
+ self._inflatedTile = tile
+
return os.path.sep.join(imagePath)
BORDER = 10
return os.path.sep.join(imagePath)
BORDER = 10
def __init__(self, name, group, rect, coords) :
pygame.sprite.DirtySprite.__init__(self, group)
def __init__(self, name, group, rect, coords) :
pygame.sprite.DirtySprite.__init__(self, group)
self.name = name
self.rect = rect
self.name = name
self.rect = rect
+ self._baseRect = rect.copy()
+ imagePath = InstrumentTile._get_instrument_image(name)
+ self._img = pygame.image.load(imagePath)
+ self.update()
+
+
+ def update(self) :
innerWidth, innerHeight = [l-self.BORDER*2 for l in self.rect.size]
innerWidth, innerHeight = [l-self.BORDER*2 for l in self.rect.size]
+ innerSize = innerWidth, innerHeight
- imagePath = InstrumentTile._get_instrument_image(name)
- img = pygame.image.load(imagePath)
+ border = pygame.Surface(self.rect.size)
+ border.fill((0,0,0,255))
+
+ bg = pygame.Surface(innerSize)
+ bg.fill((255,255,255,255))
+ bgRect = pygame.Rect((self.BORDER, self.BORDER), innerSize)
+
+ img = self._img
iWidth, iHeight = img.get_size()
imgRatio = float(iWidth) / iHeight
iWidth, iHeight = img.get_size()
imgRatio = float(iWidth) / iHeight
ih = innerHeight
iw = int(round(innerHeight * imgRatio))
ih = innerHeight
iw = int(round(innerHeight * imgRatio))
- position = ((innerWidth - iw) / 2 + self.BORDER, (innerHeight - ih) / 2 + self.BORDER)
-
+ imgPosition = ((innerWidth - iw) / 2, (innerHeight - ih) / 2)
+ imgRect = pygame.Rect(imgPosition, (iw, ih))
img = pygame.transform.smoothscale(img, (iw, ih))
img = pygame.transform.smoothscale(img, (iw, ih))
- bg = pygame.Surface(self.rect.size)
- bg.fill((255,255,255,255))
- bg.blit(img, pygame.Rect(position, (iw, ih)))
-
- self.image = bg
+ bg.blit(img, imgRect)
+ border.blit(bg, bgRect)
+ self.image = border
def inflate(self, refPoint) :
def inflate(self, refPoint) :
keep = {}
for name in REF_POINTS[refPoint] :
keep[name] = getattr(self.rect, name)
self.rect.inflate_ip(*[l*self.INFLATE_ZOOM for l in self.rect.size])
keep = {}
for name in REF_POINTS[refPoint] :
keep[name] = getattr(self.rect, name)
self.rect.inflate_ip(*[l*self.INFLATE_ZOOM for l in self.rect.size])
- img = pygame.transform.smoothscale(self.image, self.rect.size)
- self.image = img
-
for k, v in keep.items() :
setattr(self.rect, k, v)
for k, v in keep.items() :
setattr(self.rect, k, v)
+
+
+ def deflate(self) :
+ self.inflated = False
+ self.rect = self._baseRect.copy()
+ self.update()
+ self.dirty = 1
+