Exemplo n.º 1
0
    def __init__(self, file_name, title="Set Title!"):
        wx.Dialog.__init__(self, None, -1, title)
        if (paths.get_platform() != "mac"):
            co = wx.ColourDatabase().Find("light grey")
            #print co
            #self.SetBackgroundColour(co)
            self.SetBackgroundColour("lightgrey")
        #print self.GetBackgroundColour()

        self.progress_prompt = wx.StaticText(self, -1, "Download progress:")
        if (USE_WINSOUND):
            self.gauge = wx.StaticText(self, -1, "")
        else:
            self.gauge = wx.Gauge(self, -1, range=100)
            self.gauge.SetMinSize((500, -1))

        self.start = wx.Button(self, -1, "Start Download")
        self.cancel = wx.Button(self, -1, "Cancel Download")
        self.help_text = wx.StaticText(self, -1, "")

        grid = wx.FlexGridSizer(3, 1, 5, 5)
        grid.Add(self.progress_prompt)
        grid.Add(self.gauge, flag=wx.EXPAND)
        grid.Add(self.help_text, flag=wx.EXPAND)

        buttons = wx.BoxSizer(wx.HORIZONTAL)
        buttons.AddStretchSpacer()
        buttons.Add(self.cancel)
        buttons.Add(self.start, flag=wx.LEFT, border=10)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(grid, 1, flag=wx.ALL, border=10)
        sizer.Add(buttons, 0, wx.EXPAND | wx.ALL, border=10)
        self.SetSizer(sizer)
        sizer.Fit(self)
        self.Layout()

        self.start.SetDefault()

        self.Bind(wx.EVT_BUTTON, self.on_start, self.start)
        self.Bind(wx.EVT_BUTTON, self.on_cancel, self.cancel)

        self.download_bytes, self.dtype, self.version = get_bytes(file_name)

        self.byte_count = len(self.download_bytes)

        if (USE_WINSOUND):
            self.gauge.SetLabel("")
        else:
            self.gauge.SetRange(self.byte_count)
            self.gauge.SetValue(0)

        self.help_text.SetLabel("Download size is %d bytes" %
                                (self.byte_count, ))

        # convert to wav file
        WAV_FILE = os.path.join(paths.get_store_dir(), "program.wav")
        convertWithPause(self.download_bytes, WAV_FILE, DOWNLOAD_PAUSE_MSECS,
                         DOWNLOAD_BYTES_BETWEEN_PAUSES)
Exemplo n.º 2
0
    def __init__(self, file_name, title="Set Title!"):
        wx.Dialog.__init__(self, None, -1, title)
        if (paths.get_platform() != "mac"):
            self.SetBackgroundColour("light grey")

        self.progress_prompt = wx.StaticText(self, -1, "Download progress:")
        if any([USE_WINSOUND, USE_WAVER]):
            self.gauge = wx.StaticText(self, -1, "")
        else:
            self.gauge = wx.Gauge(self, -1, range=100)
            self.gauge.SetMinSize((500, -1))

        self.start = wx.Button(self, -1, "Start Download")
        self.cancel = wx.Button(self, -1, "Cancel Download")
        self.help_text = wx.StaticText(self, -1, AUDIO_STRING)
        self.file_browse = fbb.FileBrowseButton(
            self,
            -1,
            labelText="Firmware File:",
            dialogTitle="Find a Firmware File",
            fileMode=wx.OPEN)
        if (paths.get_platform() != "mac"):
            self.file_browse.SetBackgroundColour("light grey")

        grid = wx.FlexGridSizer(4, 1, 5, 5)
        grid.Add(self.file_browse, flag=wx.EXPAND)
        grid.Add(self.progress_prompt)
        grid.Add(self.gauge, flag=wx.EXPAND)
        grid.Add(self.help_text, flag=wx.EXPAND)

        buttons = wx.BoxSizer(wx.HORIZONTAL)
        buttons.AddStretchSpacer()
        buttons.Add(self.cancel)
        buttons.Add(self.start, flag=wx.LEFT, border=10)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(grid, 1, flag=wx.ALL, border=10)
        sizer.Add(buttons, 0, wx.EXPAND | wx.ALL, border=10)
        self.SetSizer(sizer)
        sizer.Fit(self)
        self.Layout()

        self.start.SetDefault()

        self.Bind(wx.EVT_BUTTON, self.on_start, self.start)
        self.Bind(wx.EVT_BUTTON, self.on_cancel, self.cancel)
Exemplo n.º 3
0
    def __init__(self, file_name, title="Set Title!"):
        wx.Dialog.__init__(self, None, -1, title)
        if (paths.get_platform() != "mac"):
            co = wx.ColourDatabase().Find("light grey")
            #print co
            #self.SetBackgroundColour(co)
            self.SetBackgroundColour("lightgrey")
        #print self.GetBackgroundColour()

        self.progress_prompt = wx.StaticText(self, -1, "Download progress:")
        if (USE_WINSOUND):
            self.gauge = wx.StaticText(self, -1, "")
        else:
            self.gauge = wx.Gauge(self, -1, range=100)
            self.gauge.SetMinSize((500, -1))

        self.start = wx.Button(self, -1, "Start Download")
        self.cancel = wx.Button(self, -1, "Cancel Download")
        self.help_text = wx.StaticText(self, -1, "")

        grid = wx.FlexGridSizer(3 ,1, 5, 5)
        grid.Add(self.progress_prompt)
        grid.Add(self.gauge, flag=wx.EXPAND)
        grid.Add(self.help_text, flag=wx.EXPAND)

        buttons = wx.BoxSizer(wx.HORIZONTAL)
        buttons.AddStretchSpacer()
        buttons.Add(self.cancel)
        buttons.Add(self.start, flag=wx.LEFT, border=10)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(grid, 1, flag=wx.ALL, border=10)
        sizer.Add(buttons, 0, wx.EXPAND | wx.ALL, border=10)
        self.SetSizer(sizer)
        sizer.Fit(self)
        self.Layout()

        self.start.SetDefault()

        self.Bind(wx.EVT_BUTTON, self.on_start, self.start)
        self.Bind(wx.EVT_BUTTON, self.on_cancel, self.cancel)

        self.download_bytes, self.dtype, self.version = get_bytes(file_name)

        self.byte_count = len(self.download_bytes)

        if (USE_WINSOUND):
            self.gauge.SetLabel("")
        else:
            self.gauge.SetRange(self.byte_count)
            self.gauge.SetValue(0)

        self.help_text.SetLabel("Download size is %d bytes" % (self.byte_count,))

        # convert to wav file
        WAV_FILE = os.path.join(paths.get_store_dir(), "program.wav")
        convertWithPause(self.download_bytes, WAV_FILE,
                         DOWNLOAD_PAUSE_MSECS, DOWNLOAD_BYTES_BETWEEN_PAUSES);
Exemplo n.º 4
0
    def __init__(self, file_name, title="Set Title!"):
        wx.Dialog.__init__(self, None, -1, title)
        if (paths.get_platform() != "mac"):
            self.SetBackgroundColour("light grey")

        self.progress_prompt = wx.StaticText(self, -1, "Download progress:")
        if any([USE_WINSOUND, USE_WAVER]):
            self.gauge = wx.StaticText(self, -1, "")
        else:
            self.gauge = wx.Gauge(self, -1, range=100)
            self.gauge.SetMinSize((500, -1))

        self.start = wx.Button(self, -1, "Start Download")
        self.cancel = wx.Button(self, -1, "Cancel Download")
        self.help_text = wx.StaticText(self, -1, AUDIO_STRING)
        self.file_browse = fbb.FileBrowseButton(self, -1, labelText="Firmware File:",
                                                dialogTitle="Find a Firmware File",
                                                fileMode=wx.OPEN)
        if (paths.get_platform() != "mac"):
            self.file_browse.SetBackgroundColour("light grey")

        grid = wx.FlexGridSizer(4 ,1, 5, 5)
        grid.Add(self.file_browse, flag=wx.EXPAND)
        grid.Add(self.progress_prompt)
        grid.Add(self.gauge, flag=wx.EXPAND)
        grid.Add(self.help_text, flag=wx.EXPAND)

        buttons = wx.BoxSizer(wx.HORIZONTAL)
        buttons.AddStretchSpacer()
        buttons.Add(self.cancel)
        buttons.Add(self.start, flag=wx.LEFT, border=10)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(grid, 1, flag=wx.ALL, border=10)
        sizer.Add(buttons, 0, wx.EXPAND | wx.ALL, border=10)
        self.SetSizer(sizer)
        sizer.Fit(self)
        self.Layout()

        self.start.SetDefault()

        self.Bind(wx.EVT_BUTTON, self.on_start, self.start)
        self.Bind(wx.EVT_BUTTON, self.on_cancel, self.cancel)
Exemplo n.º 5
0
    def __init__(self, usb_device, file_name, title="Set Title!", size=(200, 200)):
        wx.Dialog.__init__(self, None, -1, title, size=(500, 300))
        if (paths.get_platform() != "mac"):
            self.SetBackgroundColour("lightgray")

        # self.ports = get_possible_ports()
        # if (usb_device not in self.ports):
        #     if (len(self.ports) > 0):
        #         usb_device = self.ports[0]
        #     else:
        #         usb_device = ""
        usb_device = ""
        
        self.usb_ctrl = wx.ComboBox(self, -1, value=usb_device, choices=self.ports, size=(150,-1))

        
        self.grid = wx.GridBagSizer(5,5)
        self.usb_prompt = wx.StaticText(self, -1, "USB Device:")
        self.progress_prompt = wx.StaticText(self, -1, "Download progress:")
        self.gauge = wx.Gauge(self, -1, range=100)
        self.start = wx.Button(self, -1, "Start Download")
        self.cancel = wx.Button(self, -1, "Cancel Download")
        self.help_text = wx.StaticText(self, -1, "")
        
        self.grid.Add(self.usb_prompt, (1,1),
                 flag=wx.ALIGN_RIGHT|wx.ALIGN_CENTRE_VERTICAL)
        self.grid.Add(self.usb_ctrl, (1,2), flag=wx.ALIGN_LEFT|wx.ALIGN_CENTRE_VERTICAL)


        self.grid.Add(self.progress_prompt, (3,1), span=(1,2), flag=wx.EXPAND)
        self.grid.Add(self.gauge, (4,1), span=(1,3), flag=wx.EXPAND)
        
        self.grid.Add(self.help_text, (6,1), span=(2,2), flag=wx.EXPAND)

        self.grid.AddGrowableRow(7)
        self.grid.Add(self.cancel, (8,2), flag=wx.ALIGN_RIGHT | wx.BOTTOM)
        self.grid.Add(self.start, (8,3), flag=wx.ALIGN_LEFT | wx.BOTTOM)
        self.grid.Add((1,1), (9,2))

        self.SetSizer(self.grid)
        self.Layout()

        self.start.SetDefault()

        self.Bind(wx.EVT_BUTTON, self.on_start, self.start)
        self.Bind(wx.EVT_BUTTON, self.on_cancel, self.cancel)

        self.download_bytes, self.dtype, self.version = get_bytes(file_name)
        self.byte_count = len(self.download_bytes)
        self.gauge.SetRange(self.byte_count)
        self.gauge.SetValue(0)

        self.help_text.SetLabel("Download size is %d bytes." % (len(self.download_bytes),))
Exemplo n.º 6
0
    def __init__(self, usb_device, file_name, title="Set Title!", size=(200, 200)):
        wx.Dialog.__init__(self, None, -1, title, size=(500, 300))
        if (paths.get_platform() != "mac"):
            self.SetBackgroundColour("light grey")

        # self.ports = get_possible_ports()
        # if (usb_device not in self.ports):
        #     if (len(self.ports) > 0):
        #         usb_device = self.ports[0]
        #     else:
        #         usb_device = ""
        usb_device = ""

        self.usb_ctrl = wx.ComboBox(self, -1, value=usb_device, choices=self.ports, size=(150,-1))


        self.grid = wx.GridBagSizer(5,5)
        self.usb_prompt = wx.StaticText(self, -1, "USB Device:")
        self.progress_prompt = wx.StaticText(self, -1, "Download progress:")
        self.gauge = wx.Gauge(self, -1, range=100)
        self.start = wx.Button(self, -1, "Start Download")
        self.cancel = wx.Button(self, -1, "Cancel Download")
        self.help_text = wx.StaticText(self, -1, "")

        self.grid.Add(self.usb_prompt, (1,1),
                 flag=wx.ALIGN_RIGHT|wx.ALIGN_CENTRE_VERTICAL)
        self.grid.Add(self.usb_ctrl, (1,2), flag=wx.ALIGN_LEFT|wx.ALIGN_CENTRE_VERTICAL)


        self.grid.Add(self.progress_prompt, (3,1), span=(1,2), flag=wx.EXPAND)
        self.grid.Add(self.gauge, (4,1), span=(1,3), flag=wx.EXPAND)

        self.grid.Add(self.help_text, (6,1), span=(2,2), flag=wx.EXPAND)

        self.grid.AddGrowableRow(7)
        self.grid.Add(self.cancel, (8,2), flag=wx.ALIGN_RIGHT | wx.BOTTOM)
        self.grid.Add(self.start, (8,3), flag=wx.ALIGN_LEFT | wx.BOTTOM)
        self.grid.Add((1,1), (9,2))

        self.SetSizer(self.grid)
        self.Layout()

        self.start.SetDefault()

        self.Bind(wx.EVT_BUTTON, self.on_start, self.start)
        self.Bind(wx.EVT_BUTTON, self.on_cancel, self.cancel)

        self.download_bytes, self.dtype, self.version = get_bytes(file_name)
        self.byte_count = len(self.download_bytes)
        self.gauge.SetRange(self.byte_count)
        self.gauge.SetValue(0)

        self.help_text.SetLabel("Download size is %d bytes." % (len(self.download_bytes),))
Exemplo n.º 7
0
def set_audio_output(choice):
    global USE_PORTAUDIO
    global USE_PYGAME
    global USE_WINSOUND
    global USE_WAVER
    global AUDIO_STRING

    choice = choice.lower()
    installed = "unknown"
    using = "unknown"

    WAVER_PRESENT = False
    # if sys.platform.startswith("win"):
    #     waver_path = os.path.join(paths.get_run_dir(), "waver", "waver.exe")
    #     if os.path.isfile(waver_path):
    #         WAVER_PRESENT = True

    installedList = []
    installed = ""
    if (PORTAUDIO_PRESENT):
        installedList.append("portaudio")
    if (PYGAME_PRESENT):
        installedList.append("pygame")
    if (WAVER_PRESENT):
        installedList.append("waver")

    if (len(installedList) > 0):
        for i in range(len(installedList) - 1):
            installed += installedList[i] + ", "
        installed += installedList[-1]
    else:
        installed = "no extra audio backends"

    AUDIO_STRING = "(Audio installed: %s" % (installed)

    if (choice == "any"):
        if WAVER_PRESENT:
            USE_WAVER = True
            using = "waver"
        elif (PORTAUDIO_PRESENT):
            USE_PORTAUDIO = True
            using = "portaudio"
        elif (PYGAME_PRESENT):
            USE_PYGAME = True
            using = "pygame"
        else:
            USE_WINSOUND = True
            # must be windows built-in
            using = "built-in winsound"

    elif (choice == "waver"):
        if (not WAVER_PRESENT):
            print "\nERROR - selected audio 'waver' is not installed!"
            sys.exit(1)
        else:
            USE_WAVER = True
            using = choice

    elif (choice == "portaudio"):
        if (not PORTAUDIO_PRESENT):
            print "\nERROR - selected audio 'portaudio' is not installed!"
            sys.exit(1)
        else:
            USE_PORTAUDIO = True
            using = choice

    elif (choice == "pygame"):
        if (not PYGAME_PRESENT):
            print "\nERROR - selected audio 'pygame' is not installed!"
            sys.exit(1)
        else:
            USE_PYGAME = True
            using = choice

    elif (choice == "winsound"):
        if (paths.get_platform() != "win"):
            print "\nERROR - selected audio 'winsound' is not available on non-window systems"
            sys.exit(1)
        else:
            USE_WINSOUND = True
            using = "built-in winsound"

    else:
        print "\nERROR - selected audio '%s' is unknown!" % (choice)
        sys.exit(2)

    AUDIO_STRING += " -  Audio to be used: %s)" % (using)

    # print AUDIO_STRING
    return AUDIO_STRING
Exemplo n.º 8
0
        p.get_default_output_device_info()['defaultSampleRate'])
    p.terminate()

    # print "Pyaudio installed, sample rate:", WAVE_SAMPLE_RATE_HZ
except:
    pass

try:
    import pygame
    PYGAME_PRESENT = True
    #print "Pygame installed"
except:
    pass

if (not (PORTAUDIO_PRESENT
         or PYGAME_PRESENT)) and (paths.get_platform() != "win"):
    print "ERROR - No Audio package (pygame or pyaudio) installed!"
    sys.exit(1)

AUDIO_CHUNK = 1024
AUDIO_STRING = ""

# A quanta is a 1/2 a microsecond. As the sample rate is in
# Hz, we have to divide it by 2000 to get samples per 0.5ms.
SAMPLES_PER_QUANTA = WAVE_SAMPLE_RATE_HZ / 2000


def set_audio_output(choice):
    global USE_PORTAUDIO
    global USE_PYGAME
    global USE_WINSOUND
Exemplo n.º 9
0
    def on_start(self, event):
        # get the device
        #device = self.usb_ctrl.GetValue()
        device = None
##        if (not os.path.exists(device) or not os.access(device, os.R_OK|os.W_OK)):
##            self.help_text.SetLabel("ERROR - device %s doesn't exist or isn't readable and writable." % (device))
##            return
        
        # can't start twice so disable this button
        self.start.Disable()
        self.help_text.SetLabel("Starting download of %d bytes." % (self.byte_count,))
        self.gauge.SetValue(0)
        self.gauge.Update()
        self.Update()

        time.sleep(1)
        WAV_FILE = os.path.join(paths.get_store_dir(), "program.wav")

        if USE_PORTAUDIO:
            wf = wave.open(WAV_FILE, 'rb')
            p = pyaudio.PyAudio()

            totalFrames = wf.getnframes()
            framesRead = 0
            self.gauge.SetRange(totalFrames)
            self.gauge.SetValue(0)
            stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
                            channels=wf.getnchannels(),
                            rate=wf.getframerate(),
                            output=True)

            data = wf.readframes(AUDIO_CHUNK)
            framesRead += AUDIO_CHUNK
            if (framesRead > totalFrames):
                framesRead = totalFrames

            while data != '':
                stream.write(data)
                self.gauge.SetValue(framesRead)
                self.Update()

                data = wf.readframes(AUDIO_CHUNK)
                framesRead += AUDIO_CHUNK
                if (framesRead > totalFrames):
                    framesRead = totalFrames

            self.gauge.SetValue(totalFrames)
            self.Update()

            stream.stop_stream()
            stream.close()
            p.terminate()

        
        elif USE_PYGAME:
            if (pygame.mixer.get_init() == None):
                pygame.mixer.init(frequency=44100, size=8, channels=2, buffer=4096)
                pygame.mixer.init()
            
            s = pygame.mixer.Sound(WAV_FILE)
            seconds = s.get_length()
            #print "Sounds seconds:", seconds
            if (seconds < 1):
                seconds = 1
            self.gauge.SetRange(seconds * 5)
            self.gauge.SetValue(0)
            elapsed = 0
            s.play()
            while ((elapsed < seconds) and pygame.mixer.get_busy()):
                time.sleep(0.2)
                elapsed += 0.2
                if (elapsed < seconds):
                    self.gauge.SetValue(elapsed * 5)
                    self.Update()

            self.gauge.SetValue(seconds * 5)
            self.Update()
            
        elif paths.get_platform() == "win":
            s1 = wx.Sound(WAV_FILE)
            s1.Play(wx.SOUND_SYNC)

            
        #self.gauge.SetValue(self.byte_count)
        self.help_text.SetLabel("Finished downloading")
        self.start.Enable()

        self.Refresh()
Exemplo n.º 10
0
try:
    import pyaudio
    PORTAUDIO_PRESENT = True
    #print "Pyaudio installed"
except:
    pass

try:
    import pygame
    PYGAME_PRESENT = True
    #print "Pygame installed"
except:
    pass


if (not (PORTAUDIO_PRESENT or PYGAME_PRESENT)) and (paths.get_platform() != "win"):
    print "ERROR - No Audio package (pygame or pyaudio) installed!"
    sys.exit(1)
            
AUDIO_CHUNK = 1024

def set_audio_output(choice):
    global USE_PORTAUDIO
    global USE_PYGAME
    choice = choice.lower()
    installed = "unknown"
    using = "unknown"

    if (PORTAUDIO_PRESENT and PYGAME_PRESENT):
        installed = "portaudio, pygame"
    elif (PORTAUDIO_PRESENT):
Exemplo n.º 11
0
def set_audio_output(choice):
    global USE_PORTAUDIO
    global USE_PYGAME
    global USE_WINSOUND
    global USE_WAVER
    global AUDIO_STRING

    choice = choice.lower()
    installed = "unknown"
    using = "unknown"

    WAVER_PRESENT = False
    # if sys.platform.startswith("win"):
    #     waver_path = os.path.join(paths.get_run_dir(), "waver", "waver.exe")
    #     if os.path.isfile(waver_path):
    #         WAVER_PRESENT = True

    installedList = []
    installed = ""
    if (PORTAUDIO_PRESENT):
        installedList.append("portaudio")
    if (PYGAME_PRESENT):
        installedList.append("pygame")
    if (WAVER_PRESENT):
        installedList.append("waver")

    if (len(installedList) > 0):
        for i in range(len(installedList)-1):
            installed += installedList[i] + ", "
        installed += installedList[-1]
    else:
        installed = "no extra audio backends"

    AUDIO_STRING = "(Audio installed: %s" % (installed)

    if (choice == "any"):
        if WAVER_PRESENT:
            USE_WAVER = True
            using = "waver"
        elif (PORTAUDIO_PRESENT):
            USE_PORTAUDIO = True
            using = "portaudio"
        elif (PYGAME_PRESENT):
            USE_PYGAME = True
            using = "pygame"
        else:
            USE_WINSOUND = True
            # must be windows built-in
            using = "built-in winsound"

    elif (choice == "waver"):
        if (not WAVER_PRESENT):
            print "\nERROR - selected audio 'waver' is not installed!"
            sys.exit(1)
        else:
            USE_WAVER = True
            using = choice

    elif (choice == "portaudio"):
        if (not PORTAUDIO_PRESENT):
            print "\nERROR - selected audio 'portaudio' is not installed!"
            sys.exit(1)
        else:
            USE_PORTAUDIO = True
            using = choice

    elif (choice == "pygame"):
        if (not PYGAME_PRESENT):
            print "\nERROR - selected audio 'pygame' is not installed!"
            sys.exit(1)
        else:
            USE_PYGAME = True
            using = choice

    elif (choice == "winsound"):
        if (paths.get_platform() != "win"):
            print "\nERROR - selected audio 'winsound' is not available on non-window systems"
            sys.exit(1)
        else:
            USE_WINSOUND = True
            using = "built-in winsound"

    else:
        print "\nERROR - selected audio '%s' is unknown!" % (choice)
        sys.exit(2)

    AUDIO_STRING +=" -  Audio to be used: %s)" % (using)

    # print AUDIO_STRING
    return AUDIO_STRING
Exemplo n.º 12
0
    WAVE_SAMPLE_RATE_HZ = int(p.get_default_output_device_info()['defaultSampleRate'])
    p.terminate()

    # print "Pyaudio installed, sample rate:", WAVE_SAMPLE_RATE_HZ
except:
    pass

try:
    import pygame
    PYGAME_PRESENT = True
    #print "Pygame installed"
except:
    pass


if (not (PORTAUDIO_PRESENT or PYGAME_PRESENT)) and (paths.get_platform() != "win"):
    print "ERROR - No Audio package (pygame or pyaudio) installed!"
    sys.exit(1)

AUDIO_CHUNK = 1024
AUDIO_STRING = ""


# A quanta is a 1/2 a microsecond. As the sample rate is in
# Hz, we have to divide it by 2000 to get samples per 0.5ms.
SAMPLES_PER_QUANTA = WAVE_SAMPLE_RATE_HZ / 2000

def set_audio_output(choice):
    global USE_PORTAUDIO
    global USE_PYGAME
    global USE_WINSOUND
Exemplo n.º 13
0
def set_audio_output(choice):
    global USE_PORTAUDIO
    global USE_PYGAME
    global USE_WINSOUND
    global AUDIO_STRING
    
    choice = choice.lower()
    installed = "unknown"
    using = "unknown"
    

    if (PORTAUDIO_PRESENT and PYGAME_PRESENT):
        installed = "portaudio, pygame"
    elif (PORTAUDIO_PRESENT):
        installed = "portaudio"
    elif (PYGAME_PRESENT):
        installed = "pygame"
    else:
        installed = "no extra audio backends"

    AUDIO_STRING = "(Audio installed: %s" % (installed)
    
    if (choice == "any"):
        if (PORTAUDIO_PRESENT):
            USE_PORTAUDIO = True
            using = "portaudio"
        elif (PYGAME_PRESENT):
            USE_PYGAME = True
            using = "pygame"
        else:
            USE_WINSOUND = True
            # must be windows built-in
            using = "built-in winsound"

    elif (choice == "portaudio"):
        if (not PORTAUDIO_PRESENT):
            print "\nERROR - selected audio 'portaudio' is not installed!"
            sys.exit(1)
        else:
            USE_PORTAUDIO = True
            using = choice

    elif (choice == "pygame"):
        if (not PYGAME_PRESENT):
            print "\nERROR - selected audio 'pygame' is not installed!"
            sys.exit(1)
        else:
            USE_PYGAME = True
            using = choice

    elif (choice == "winsound"):
        if (paths.get_platform() != "win"):
            print "\nERROR - selected audio 'winsound' is not available on non-window systems"
            sys.exit(1)
        else:
            USE_WINSOUND = True
            using = "built-in winsound"
            
    else:
        print "\nERROR - selected audio '%s' is unknown!" % (choice)
        sys.exit(2)

    AUDIO_STRING +=" -  Audio to be used: %s)" % (using)

    #print AUDIO_STRING
    return AUDIO_STRING
Exemplo n.º 14
0
def set_audio_output(choice):
    global USE_PORTAUDIO
    global USE_PYGAME
    global USE_WINSOUND
    global AUDIO_STRING

    choice = choice.lower()
    installed = "unknown"
    using = "unknown"

    if (PORTAUDIO_PRESENT and PYGAME_PRESENT):
        installed = "portaudio, pygame"
    elif (PORTAUDIO_PRESENT):
        installed = "portaudio"
    elif (PYGAME_PRESENT):
        installed = "pygame"
    else:
        installed = "no extra audio backends"

    AUDIO_STRING = "(Audio installed: %s" % (installed)

    if (choice == "any"):
        if (PORTAUDIO_PRESENT):
            USE_PORTAUDIO = True
            using = "portaudio"
        elif (PYGAME_PRESENT):
            USE_PYGAME = True
            using = "pygame"
        else:
            USE_WINSOUND = True
            # must be windows built-in
            using = "built-in winsound"

    elif (choice == "portaudio"):
        if (not PORTAUDIO_PRESENT):
            print "\nERROR - selected audio 'portaudio' is not installed!"
            sys.exit(1)
        else:
            USE_PORTAUDIO = True
            using = choice

    elif (choice == "pygame"):
        if (not PYGAME_PRESENT):
            print "\nERROR - selected audio 'pygame' is not installed!"
            sys.exit(1)
        else:
            USE_PYGAME = True
            using = choice

    elif (choice == "winsound"):
        if (paths.get_platform() != "win"):
            print "\nERROR - selected audio 'winsound' is not available on non-window systems"
            sys.exit(1)
        else:
            USE_WINSOUND = True
            using = "built-in winsound"

    else:
        print "\nERROR - selected audio '%s' is unknown!" % (choice)
        sys.exit(2)

    AUDIO_STRING += " -  Audio to be used: %s)" % (using)

    #print AUDIO_STRING
    return AUDIO_STRING