本文整理汇总了Python中Button.Button.button_pressed方法的典型用法代码示例。如果您正苦于以下问题:Python Button.button_pressed方法的具体用法?Python Button.button_pressed怎么用?Python Button.button_pressed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Button.Button
的用法示例。
在下文中一共展示了Button.button_pressed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: App
# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import button_pressed [as 别名]
#.........这里部分代码省略.........
#if the color has a note assigned to it and has not already been
#seen add it to the newChordDict with the color as the key
if ((color in self.noteDict) and (color not in newChordDict)):
newChordDict[color] = (self.noteDict[color])
for note in self.noteDict.iterkeys():
#if the note was playing but is no longer present stop playing it
if ((note in self.chordDict) and (note not in newChordDict)):
self.noteDict[note].stop()
#if the note was not playing but is now present, begin playing it.
if ((note in newChordDict) and (note not in self.chordDict)):
self.noteDict[note].play()
self.chordDict = newChordDict
#sleep for 1 ms to get a more uniform scan speed
time.sleep(.01)
def mouse_event_handler(self, event):
'''
Handles mouse events
'''
if event.type == MOUSEBUTTONDOWN:
self.mouse_button_down_handler(event)
elif event.type == MOUSEMOTION:
self.mouse_motion_handler(event)
elif event.type == MOUSEBUTTONUP:
self.mouse_button_up_handler(event)
else: return
def mouse_button_down_handler(self, event):
'''
Handles mousebuttondown events
'''
if event.button == 1:
#if the play button is pressed begin scanning
if (self.playButton.button_pressed(event.pos, 0, 0)):
if (self.playback == False):
self.chordDict = dict()
self.scannerLeft = 0
self.playback = True
self.scanSprite = Scanner(self.paintScreen)
self.scanGroup.add(self.scanSprite)
self.canvas = self.paintScreen.copy()
if (self.stopButton.button_pressed(event.pos, 0, 0)):
if (self.playback == False):
return
else:
#clear scanSprites from the screen and stop playing notes
self.playback = False
self.scanGroup.clear(self.paintScreen, self.canvas)
self.scanGroup.empty()
for note in self.noteDict.itervalues():
note.stop()
#play all colors currently present on screen
if (self.chordButton.button_pressed(event.pos, 0, 0)):
#get all unique elements in canvasChordArray
canvasChordSet = set(self.canvasChordArray)
#play all notes in canvasChordSet
for sound in canvasChordSet:
sound.play(0, 1000, 0)
#load demo1 or demo2 to the screen with their correct respective
#canvasChordArrays
if (self.demo1Button.button_pressed(event.pos, 0, 0)):
self.paintScreen.blit(self.demo1, (0,0))
self.canvasChordArray = [pygame.mixer.Sound("data/C.ogg"),
pygame.mixer.Sound("data/E.ogg"),
pygame.mixer.Sound("data/D#.ogg"),
pygame.mixer.Sound("data/G.ogg")]