def OnEnterText(self, evt):
     print "text entered!"
     testo_risposta = self.answer.GetValue()
     try:
         self.soluzioni = zip(*self.righe)[2]
         testo_soluzione = self.soluzioni[self.indice_lines]
         if testo_risposta == testo_soluzione:
             if wx.Platform != '__WXGTK__':
                 self.player = wx.Sound('tada.wav')
                 self.player.Play()
                 print "esatto!"
             else:
                 mixer.init()
                 self.s = mixer.Sound('tada.wav')
                 self.s.play()
                 print "esatto su linux!"
         else:
             if wx.Platform != '__WXGTK__':
                 self.player = wx.Sound('Windows_Hardware_Fail.wav')
                 self.player.Play()
                 print "errore!"
             else:
                 mixer.init()
                 self.s = mixer.Sound('Windows_Hardware_Fail.wav')
                 self.s.play()
                 print "errore su linux!"
     except:
         pass
Esempio n. 2
0
 def ChangeButCur(self, event):
     if self.Group == 0:
         self.ButtonIndex = (self.ButtonIndex + 1) % 2
         self.Mx1, self.My1 = self.butList[self.ButtonIndex *
                                           10].GetPosition()
         self.wdt, self.ht = self.butList[0].GetSize(
         )  #for getting ht alone..
         self.Mx1, self.My1 = self.Mx1 - 5, self.My1 - 5
         twd, tht = wx.GetDisplaySize()
         self.wdt, self.ht = twd - 70, self.ht + 10
     else:
         if self.Group == 1:
             self.ButtonIndex = (self.ButtonIndex + 1) % 10
         else:
             self.ButtonIndex = (self.ButtonIndex + 1 -
                                 10) % (len(self.butList) - 10) + 10
         #Voice Playing...
         if self.butList[self.ButtonIndex].GetLabel() == "-->":
             snd = wx.Sound('files/voice/MoveRight.wav')
         elif self.butList[self.ButtonIndex].GetLabel() == "<--":
             snd = wx.Sound('files/voice/MoveLeft.wav')
         else:
             snd = wx.Sound('files/voice/' +
                            self.butList[self.ButtonIndex].GetLabel() +
                            '.wav')
         snd.Play()
         #Voice ends..
         self.Mx1, self.My1 = self.butList[self.ButtonIndex].GetPosition()
         self.wdt, self.ht = self.butList[self.ButtonIndex].GetSize()
         self.Mx1, self.My1 = self.Mx1 - 5, self.My1 - 5
         self.wdt, self.ht = self.wdt + 10, self.ht + 10
     self.Refresh()
     self.MenuTimer.Start(self.speed)
Esempio n. 3
0
 def __init__(self):
     wx.Frame.__init__(self, None, -1,"My Frame", size=(SCREEN_LONG+18,SCREEN_HIGH+97))
     self.Bind(wx.EVT_PAINT,self.OnPaint)
     self.Bind(wx.EVT_KEY_DOWN,self.Calculate)
     self.SetBackgroundColour("#CEB69A")
     self.status_list=[[0]*SQUARE_LEVEL for i in xrange(SQUARE_LEVEL)]
     self.score=0
     self.sound1 = wx.Sound(u'success.wav')
     self.sound2 = wx.Sound(u'failed.wav')
     self.CreateStatusBar()
     self.menubar=wx.MenuBar()
     menu_game=wx.Menu()
     menu_1=menu_game.Append(wx.NewId(),u"&新游戏<enter>",u"开始一个新游戏")
     menu_2=menu_game.Append(wx.NewId(),u"设置<s>",u"对游戏内容进行配置")
     menu_3=menu_game.Append(wx.NewId(),u"排行榜<p>",u"查看游戏的历史战绩")
     menu_4=menu_game.Append(wx.NewId(),u"退出<alt+f4>",u"退出游戏")
     
     self.menubar.Append(menu_game,u"&游戏")
     menu_help=wx.Menu()
     menu_5=menu_help.Append(wx.NewId(),u"游戏规则",u"点击查看游戏规则")
     self.menubar.Append(menu_help,u"&帮助")
     self.SetMenuBar(self.menubar)
     self.ranking_obj=RankingList()
     self.rank_message=wx.MessageDialog(self,u"第一名:{0[0]}:{0[1]}\n第二名:{1[0]}:{1[1]}\n第三名:{2[0]}:{2[1]}".format(*self.ranking_obj.ranking_list),u"排行榜",wx.OK)
     self.set_dialog=SettingDialog()
     self.Bind(wx.EVT_MENU,self.NewGame,menu_1)
     self.Bind(wx.EVT_MENU,self.Settings,menu_2)
     self.Bind(wx.EVT_MENU,self.ShowRankMessage,menu_3)
     self.Bind(wx.EVT_MENU,self.ExitGame,menu_4)
     self.Bind(wx.EVT_MENU,self.ShowHelp,menu_5)
     self.Centre()
 def onPlaySound(self, event):
     sound_file, ext = os.path.splitext(self.image_file)
     sound_file = os.path.join(SOUND_DIR, sound_file + '.mp3')
     print(sound_file)
     sound = wx.Sound(sound_file)
     # sound.IsOk(wx.SOUND_ASYNC)
     sound.Play(wx.SOUND_ASYNC)
Esempio n. 5
0
 def playsound(self):
     settings = self.getSettings()
     if (settings["PLAYSOUND"] == "1"):
         #os.system("playsound "+Variables.playonlinux_env+"/etc/snd/snd.wav & 2> /dev/null > /dev/null")
         sound = wx.Sound(Variables.playonlinux_env +
                          "/resources/sounds/irc.wav")
         sound.Play(wx.SOUND_SYNC)
Esempio n. 6
0
 def OnPlaySound(self, evt):
     filename = self.fbb.GetValue()
     self.sound = wx.Sound(filename)
     if self.sound.IsOk():
         self.sound.Play(wx.SOUND_ASYNC)
     else:
         wx.MessageBox("Invalid sound file", "Error")
Esempio n. 7
0
 def __init__(self, filename, loop=False):
     self._filename = filename
     self._is_playing = False
     self._lib = _lib
     self._lib_version = _lib_version
     self._loop = loop
     self._play_timestamp = 0
     self._play_count = 0
     self._thread = -1
     if not _initialized:
         self._server = init()
     else:
         self._server = _server
     if _initialized and not isinstance(_initialized, Exception):
         if not self._lib and _lib:
             self._lib = _lib
             self._lib_version = _lib_version
         if not self._snd and self._filename:
             if self._lib == "pyo":
                 self._snd = pyo.SfPlayer(safe_str(self._filename),
                                          loop=self._loop)
             elif self._lib == "pyglet":
                 snd = pyglet.media.load(self._filename, streaming=False)
                 self._ch = pyglet.media.Player()
                 self._snd = snd
             elif self._lib == "SDL":
                 rw = sdl.SDL_RWFromFile(safe_str(self._filename, "UTF-8"),
                                         "rb")
                 self._snd = self._server.Mix_LoadWAV_RW(rw, 1)
             elif self._lib == "wx":
                 self._snd = wx.Sound(self._filename)
Esempio n. 8
0
    def __init__(self, parent):
        self.win = parent
        #self.image = wx.Image(os.path.join(HOME,'target.png'), wx.BITMAP_TYPE_PNG)
        self.image = images.gettargetImage()
        #self.mask = wx.Image(os.path.join(HOME,'mask.png'), wx.BITMAP_TYPE_PNG)
        self.mask = images.getmaskImage()
        self.aspect = self.image.GetWidth() / float(self.image.GetHeight())
        self.color = "RED"
        self.click = 0
        self.score = 0
        self.time = 0
        self.lastPos = None
        self.shoots = []

        wx.Window.__init__(self,
                           parent,
                           -1,
                           size=(200, 200),
                           style=wx.SIMPLE_BORDER)
        wx.EVT_SIZE(self, self.OnSize)
        wx.EVT_PAINT(self, self.OnPaint)
        wx.EVT_LEFT_DOWN(self, self.OnLeftClick)
        wx.EVT_LEFT_UP(self, self.OnLeftClickEnd)
        wx.EVT_MOTION(self, self.OnMotion)
        try:
            self.shoot = wx.Sound(os.path.join(HOME, "shoot.wav"))
        except:
            self.shoot = None
Esempio n. 9
0
 def OnButton1(self, evt):
     try:
         sound = wx.Sound(opj('data/anykey.wav'))
         self.log.write("before Play...\n")
         sound.Play(wx.SOUND_SYNC)
         self.log.write("...after Play\n")
     except NotImplementedError, v:
         wx.MessageBox(str(v), "Exception Message")
Esempio n. 10
0
    def OnBeepSetting(self, event):
        dlg = wx.FileDialog(self,
                            u"聲音檔案路徑",
                            wildcard="Wav files (*.wav)|*.wav")
        if dlg.ShowModal() == wx.ID_OK:
            self.Sound = wx.Sound(dlg.Path)

        dlg.Destroy()
Esempio n. 11
0
 def loadSensors(self):
     # open file and read sensor info
     S=open(rootdir+'/Trebos/SensorSpec.txt')
     for line in S:
         name, posx, posy, type=line.split()
         self.controller.place(name, label="Sensor", location=(float(posx),float(posy)), type=type, status=0)
     S.close()
     self.SensorDetect=wx.Sound(rootdir+'/sounds/online.wav')
Esempio n. 12
0
 def onPlay(self, evt):
     filename = self.fbb.GetValue()
     self.sound = wx.Sound(filename)
     # error handling ...
     if self.sound.IsOk():
         self.sound.Play(wx.SOUND_ASYNC)
     else:
         wx.MessageBox("Missing or invalid sound file", "Error")
Esempio n. 13
0
    def presentFeedback(self, FB_Type, FB):
        '''
          Function for giving proper feedback
        '''
        if self.debug: print "E_UI.presentFeedback"

        FB_Type = FB_Type.lower()
        FB = FB.lower()
        ### set-up for negative visual feedback type
        negVisualFBType = "solid_color:red"
        if exptApp.settings.has_key("NEG_VISUAL_FB_TYPE"):
            negVisualFBType = exptApp.settings["NEG_VISUAL_FB_TYPE"].lower()

        if FB_Type == 'positive':
            sound = wx.Sound(
                os.path.join(exptApp.input_path, exptApp.file_AudFB_Pos))
            if FB == 'visual': pass
            elif FB == 'auditory': sound.Play(wx.SOUND_ASYNC)
            elif FB == 'both': sound.Play(wx.SOUND_ASYNC)
            if exptApp.settings[
                    "COMM_ARDUINO"]:  # feedback through Arduino is True.
                self.commArduino()  # sending signals to Arduino
        elif FB_Type == 'negative':
            sound = wx.Sound(
                os.path.join(exptApp.input_path, exptApp.file_AudFB_Neg))
            if FB == 'visual':
                if negVisualFBType.startswith('flicker'):
                    self.flickerWindow(10, negVisualFBType.split(":")[1])
                elif negVisualFBType.startswith('solid_color'):
                    self.negColorWindow(negVisualFBType.split(":")[1])
            elif FB == 'auditory':
                sound.Play(wx.SOUND_ASYNC)
            elif FB == 'both':
                sound.Play(wx.SOUND_ASYNC)
                if negVisualFBType.startswith('flicker'):
                    self.flickerWindow(10, negVisualFBType.split(":")[1])
                elif negVisualFBType.startswith('solid_color'):
                    self.negColorWindow(negVisualFBType.split(":")[1])
        if FB_Type == 'negative':
            if FB == 'both' or FB == 'visual':
                return 'delay'  # pause for 1.5 sec. for showing negative color screen
            else:
                return None
        else:
            return None
Esempio n. 14
0
def playSound(wav_path):
	""" Play sound from wav_path
	"""

	if wav_path != os.devnull:
		sound = wx.Sound(wav_path)
		if sound.IsOk():
			sound.Play(wx.SOUND_ASYNC)
			wx.YieldIfNeeded()
Esempio n. 15
0
 def playGameSound(self, file):
     '''Play a sound.'''
     ##        print 'before play...'
     if (self.gameSound):
         try:
             sound = wx.Sound(gamerc.get_sound_path(file))
             sound.Play(wx.SOUND_ASYNC)
         except NotImplementedError, v:
             wx.MessageBox(str(v), "Exception Message")
Esempio n. 16
0
 def menuRefresh(self):
     self.ButtonIndex = 0
     self.Mx1, self.My1 = self.butList[0].GetPosition()
     self.wdt, self.ht = self.butList[0].GetSize()
     self.Mx1, self.My1 = self.Mx1 - 10, self.My1 - 10
     self.wdt, self.ht = self.wdt + 20, self.ht + 20
     snd = wx.Sound('files/voice/' +
                    self.butList[self.ButtonIndex].GetLabel() + '.wav')
     snd.Play()
     self.Refresh()
     self.MenuTimer.Start(9000)
Esempio n. 17
0
def playSound(sound_path):
	""" Play sound from sound_path
	"""

	if sound_path != os.devnull:
		sound = wx.Sound(sound_path)
		if sound.IsOk():
			sound.Play(wx.SOUND_ASYNC)
			wx.YieldIfNeeded()
		else:
			sys.stderr.write(_("No sound\n"))
Esempio n. 18
0
 def OnStop(self, _=None):
     self.timer.Stop()
     if self.sound is not None:
         if guihelper.IsMac():
             # There is no stop method for Mac so we play a one centisecond wav
             # which cancels the existing playing sound
             self.sound=None
             sound=wx.Sound(self.zerolenwav)
             sound.Play(wx.SOUND_ASYNC)
         else:
             self.sound.Stop()
             self.sound=None
Esempio n. 19
0
    def play_pulse(self):
        '''
          play a pulse-sound as a signal
        '''
        if self.debug: print "E_UI.play_pulse"

        self.sound = wx.Sound(
            os.path.join(exptApp.input_path, exptApp.file_pulse_sound))
        self.sound.Play(wx.SOUND_ASYNC)
        commonFunc.writeFile(
            self.expt.exptLogFileName,
            "%s, A pluse sound was played\n" % commonFunc.get_time_stamp())
Esempio n. 20
0
    def __init__(self, **attrs):
        self.deep_construct(WavePlaybackWX,
            {'wave': None}, attrs)
        if self.data:
# AD: Use one or the other depending on version of wx.Python 2.5 used
# trying this for different versions, QH:
            if not wx.Sound is None:
                wave = wx.Sound()
                wave.CreateFromData(self.data)
            else:
                wave = wx.WaveData(self.data)
            if wave.IsOk():
                self.wave = wave
Esempio n. 21
0
def load_sound(wave_file_path):
    '''
      load the sound (wx.Sound) with the given file path
      calculate the length of the sound.
    '''
    wav = wave.open(wave_file_path, "r")
    numFrames = wav.getnframes(
    )  # note that this is accurate whether for stereo or mono
    sRate = float(wav.getframerate())
    soundlength = round(1000 * numFrames / sRate)  # length in msecs
    wav.close()
    sound = wx.Sound(wave_file_path)
    return soundlength, sound
Esempio n. 22
0
 def ChangeButCur(self, event):
     self.ButtonIndex = (self.ButtonIndex + 1) % (len(self.butList))
     self.Mx1, self.My1 = self.butList[self.ButtonIndex].GetPosition()
     self.wdt, self.ht = self.butList[self.ButtonIndex].GetSize()
     self.Mx1, self.My1 = self.Mx1 - 10, self.My1 - 10
     self.wdt, self.ht = self.wdt + 20, self.ht + 20
     #Voice..
     snd = wx.Sound('files/voice/' +
                    self.butList[self.ButtonIndex].GetLabel() + '.wav')
     snd.Play()
     #Ends..
     self.Refresh()
     self.MenuTimer.Start(9000)
 def OnValidateText(self, evt):
     print "reload text pressed"
     testo_risposta = self.answer.GetValue()
     self.soluzioni = zip(*self.righe)[2]
     testo_soluzione = self.soluzioni[self.indice_lines]
     if testo_risposta == testo_soluzione:
         if wx.Platform != '__WXGTK__':
             self.player = wx.Sound('tada.wav')
             self.player.Play()
             self.rispostegiuste += 1
             self.buttonrispostegiuste.SetLabel(
                 label=str(self.rispostegiuste))
             print "esatto!"
         else:
             mixer.init()
             self.s = mixer.Sound('tada.wav')
             self.s.play()
             self.rispostegiuste += 1
             self.buttonrispostegiuste.SetLabel(
                 label=str(self.rispostegiuste))
             print "esatto su linux!"
     else:
         if wx.Platform != '__WXGTK__':
             self.player = wx.Sound('Windows_Hardware_Fail.wav')
             self.player.Play()
             self.rispostesbagliate += 1
             self.buttonrispostesbagliate.SetLabel(
                 label=str(self.rispostesbagliate))
             print "errore!"
         else:
             mixer.init()
             self.s = mixer.Sound('Windows_Hardware_Fail.wav')
             self.s.play()
             self.rispostesbagliate += 1
             self.buttonrispostesbagliate.SetLabel(
                 label=str(self.rispostesbagliate))
             print "errore su linux!"
     self.OnForward(evt)
Esempio n. 24
0
 def give_shot_results(self, result):
     self.Show()
     if result == HIT:
         msg = "HIT!!! Please go again!"
         sound_file = 'hit.wav'
     else:
         msg = "MISS"
         sound_file = 'miss.wav'
     sound = wx.Sound(os.path.join(os.path.dirname(__file__),
                                   'audio', sound_file))
     sound.Play(wx.SOUND_SYNC)
     busy = wx.BusyInfo(msg)
     time.sleep(1)
     self.Hide()
Esempio n. 25
0
 def __init__(self, filename) :
     self._filename = filename
     self._sndType = sndhdr.what(filename)
     if self._sndType:
         self._sndType = self._sndType[0]
     if self._sndType in ['wav']:
         try:
             self._sound = wx.Sound(filename)    # support resources?
         except:
             self._sndType = None
     else:
         self._sndType = None
     if not self._sndType:
         raise SoundFileError, 'This is not a valid sound file'
Esempio n. 26
0
File: real.py Progetto: whuper/Dict
    def Speak(self, wordId, wordReal):
        folder_size = 500
        folder_name = 'within_' + str((int(
            (wordId - 1) / folder_size) + 1) * folder_size)
        save_path = 'iciba/audio_wav/' + folder_name
        mp3_path = save_path + '/' + wordReal + self.fileType
        print mp3_path

        self.sound = wx.Sound(mp3_path)
        # error handling ...
        if self.sound.IsOk():
            self.sound.Play(wx.SOUND_ASYNC)
        else:
            wx.MessageBox("Missing or invalid sound file", "Error")
Esempio n. 27
0
    def OnButton2(self, evt):
        try:
            if True:
                sound = wx.Sound(opj('data/plan.wav'))
            else:
                # sounds can also be loaded from a buffer object
                data = open(opj('data/plan.wav'), 'rb').read()
                sound = wx.SoundFromData(data)

            self.log.write("before Play...\n")
            sound.Play(wx.SOUND_ASYNC)
            self.sound = sound  # save a reference (This shoudln't be needed, but there seems to be a bug...)
            wx.YieldIfNeeded()
            self.log.write("...after Play\n")
        except NotImplementedError, v:
            wx.MessageBox(str(v), "Exception Message")
Esempio n. 28
0
def Play(soundFile):
    global soundCache
    soundFile = os.path.join(getImageFolder(), soundFile)

    if sys.platform.startswith('linux'):
        try:
            subprocess.Popen(['aplay', '-q', soundFile])
        except:
            pass
        return True

    try:
        return soundCache[soundFile].Play()
    except:
        soundCache[soundFile] = wx.Sound(soundFile)
        return soundCache[soundFile].Play()
Esempio n. 29
0
def click_sound():
    global click_wav
    # trying without the click sound
    if (True):
        return
    else:
        if (sys.platform == 'win32' or sys.platform.startswith('linux')
                or sys.platform == 'darwin'):
            try:
                if (not click_wav):
                    click_wav = wx.Sound()
                    click_wav.Create("Click.wav")

                click_wav.Play(flags=wx.SOUND_ASYNC)
            except:
                pass
Esempio n. 30
0
    def _OnRefresh(self,event):

        for i, btn in zip(self.data["item"], self.Group_Btn):

            key = self.rc.get(i[u"Redis Key"]["text"])
            if key:
                btn.Show()
                btn.SetLabel(i[u"服務器名稱"]["text"])
                btnstatus = btn.GetName()
                if "OK" in self.rc.get(i[u"Redis Key"]["text"]):
                    btn.SetBackgroundColour(wx.GREEN)
                else:
                    btn.SetBackgroundColour(i[u'警報等級']["bg"])
                    if not "1" in btnstatus:
                        btn.SetName("1")
                        wx.Sound(r"C:\Windows\Media\tada.wav").Play()