def sound(soundtype=None, filespec=None):
    """Play selected sound"""

    # debugging
    # makes debug apply only to the current thread
    #try:
    #import wingdbstub
    #if wingdbstub.debugger != None:
    #import time
    #wingdbstub.debugger.StopDebug()
    #time.sleep(2)
    #wingdbstub.debugger.StartDebug()
    #import thread
    #wingdbstub.debugger.SetDebugThreads({thread.get_ident(): 1}, default_policy=0)
    ## for V19 use
    #SpssClient._heartBeat(False)
    #except:
    #pass

    # imported within function so that localization and error handling are enabled
    try:
        import winsound
    except:
        raise SystemError(_("""This command is only available on Windows"""))

    sounds = {
        None: winsound.MB_OK,
        "default": winsound.MB_OK,
        "exclamation": winsound.MB_ICONEXCLAMATION,
        "asterisk": winsound.MB_ICONASTERISK,
        "hand": winsound.MB_ICONHAND,
        "question": winsound.MB_ICONQUESTION
    }

    if filespec:
        fh = FileHandles()
        filespec = fh.resolve(filespec)
        winsound.PlaySound(filespec, winsound.SND_FILENAME)
        if soundtype is None:
            return

    winsound.MessageBeep(sounds[soundtype])
def sound(soundtype=None, filespec=None):
    """Play selected sound"""
    
        # debugging
    # makes debug apply only to the current thread
    #try:
        #import wingdbstub
        #if wingdbstub.debugger != None:
            #import time
            #wingdbstub.debugger.StopDebug()
            #time.sleep(2)
            #wingdbstub.debugger.StartDebug()
        #import thread
        #wingdbstub.debugger.SetDebugThreads({thread.get_ident(): 1}, default_policy=0)
        ## for V19 use
        #SpssClient._heartBeat(False)
    #except:
        #pass
    
    # imported within function so that localization and error handling are enabled
    try:
        import winsound
    except:
        raise SystemError(_("""This command is only available on Windows"""))
    
    sounds = {None:winsound.MB_OK, "default":winsound.MB_OK, "exclamation":winsound.MB_ICONEXCLAMATION,
        "asterisk": winsound.MB_ICONASTERISK, "hand":winsound.MB_ICONHAND,
        "question":winsound.MB_ICONQUESTION}
    
    if filespec:
        fh = FileHandles()
        filespec = fh.resolve(filespec)
        winsound.PlaySound(filespec, winsound.SND_FILENAME)
        if soundtype is None:
            return

    winsound.MessageBeep(sounds[soundtype])
Ejemplo n.º 3
0
def dopmml(files):
    """Display pmml files"""

    # debugging
    #makes debug apply only to the current thread
    # The global namespace qualifier depends on the PMML and is set per file
    global ns
    #try:
    #import wingdbstub
    #if wingdbstub.debugger != None:
    #import time
    #wingdbstub.debugger.StopDebug()
    #time.sleep(2)
    #wingdbstub.debugger.StartDebug()
    #import thread
    #wingdbstub.debugger.SetDebugThreads({thread.get_ident(): 1}, default_policy=0)
    ## for V19 use
    #SpssClient._heartBeat(False)
    #except:
    #pass
    fh = FileHandles()
    files = fh.resolve(
        files)  # note that files might be a wildcard file expression
    spss.StartProcedure("STATS PMML DISPLAY", "STATSPMMLINFO")
    didone = False
    try:
        for fnumber, f in enumerate(glob.glob(files)):
            text = Text("""STATS_PMML_DISPLAY-""" + str(fnumber))
            didone = True
            try:
                try:
                    tree = ElementTree.parse(f)
                    root = tree.getroot()
                    first = True
                except:
                    raise ValueError(
                        _("""Invalid xml.  Error: %s File: %s""") %
                        (sys.exc_info()[1].message, f))
                # Discriminant xml is not tagged as pmml
                if not (root.tag.endswith("PMML")
                        or root.tag.endswith("spss-ml")):
                    text.addtext("""%f is not a PMML file""" % f)
                    continue

                ftime = time.ctime(os.stat(f).st_mtime)
                text.title = _("""Summary Information: %s""") % f
                text.addtext(
                    _("""Summary Model Information for File: %s\nmodified: %s\n"""
                      ) % (f, ftime))
                for ch in root.getchildren():
                    if first:
                        first = False
                        # find the namespace - there ought to be a better way :-)
                        thetag = re.match(r"\{.*\}", ch.tag)
                        if thetag:
                            ns = thetag.group()
                        else:
                            ns = ""
                    chtag = re.sub(r"""\{.*\}""", "", ch.tag)
                    if chtag == "Header":
                        doHeader(chtag, ch)
                    elif chtag == "TransformationDictionary":
                        displayTransformations(ch, text)
                    elif chtag == "MiningModel":
                        displayMining(ch, text)
                    elif chtag in [
                            'DataDictionary', 'Extension', 'dictionary'
                    ]:
                        continue
                    elif chtag == "model" and ch.find(
                            "./" + ns + 'discriminant-model') is not None:
                        disc = ch.find("./" + ns + 'discriminant-model')
                        prints['discriminant-model'](disc, text)
                    elif chtag not in prints:
                        text.addtext(
                            _("""Cannot display element: %s""") % chtag)
                    else:
                        prints[chtag](ch, text)
            finally:
                text.printit()
                del (text)  # should not be necessary
    finally:
        spss.EndProcedure()
    if not didone:
        raise ValueError(
            _("""No files were found to process.  File Specification: %s""") %
            files)
def dopmml(files):
    """Display pmml files"""
    
    # debugging
    #makes debug apply only to the current thread
    # The global namespace qualifier depends on the PMML and is set per file
    global ns
    #try:
        #import wingdbstub
        #if wingdbstub.debugger != None:
            #import time
            #wingdbstub.debugger.StopDebug()
            #time.sleep(2)
            #wingdbstub.debugger.StartDebug()
        #import thread
        #wingdbstub.debugger.SetDebugThreads({thread.get_ident(): 1}, default_policy=0)
        ## for V19 use
        #SpssClient._heartBeat(False)
    #except:
        #pass
    fh = FileHandles()
    files = fh.resolve(files)   # note that files might be a wildcard file expression
    spss.StartProcedure("STATS PMML DISPLAY", "STATSPMMLINFO")
    didone = False
    try:
        for fnumber, f in enumerate(glob.glob(files)):
            text = Text("""STATS_PMML_DISPLAY-""" + str(fnumber) )
            didone = True
            try:
                try:
                    tree = ElementTree.parse(f)
                    root = tree.getroot()
                    first = True
                except:
                    raise ValueError(_("""Invalid xml.  Error: %s File: %s""") % (sys.exc_info()[1].message, f))
                # Discriminant xml is not tagged as pmml
                if not (root.tag.endswith("PMML") or root.tag.endswith("spss-ml")):
                    text.addtext("""%f is not a PMML file""" % f)
                    continue
      
                ftime = time.ctime(os.stat(f).st_mtime)
                text.title = _("""Summary Information: %s""") % f
                text.addtext( _("""Summary Model Information for File: %s\nmodified: %s\n""") % (f, ftime))
                for ch in root.getchildren():
                    if first:
                        first = False
                        # find the namespace - there ought to be a better way :-)
                        thetag = re.match(r"\{.*\}", ch.tag)
                        if thetag:
                            ns = thetag.group()
                        else:
                            ns = ""                    
                    chtag = re.sub(r"""\{.*\}""", "", ch.tag)
                    if chtag == "Header":
                        doHeader(chtag, ch)
                    elif chtag == "TransformationDictionary":
                        displayTransformations(ch, text)
                    elif chtag == "MiningModel":
                        displayMining(ch, text)
                    elif chtag in ['DataDictionary', 'Extension', 'dictionary']:
                        continue
                    elif chtag == "model" and ch.find("./" + ns + 'discriminant-model') is not None:
                        disc = ch.find("./" + ns + 'discriminant-model')
                        prints['discriminant-model'](disc, text)
                    elif chtag not in prints:
                        text.addtext( _("""Cannot display element: %s""") % chtag)
                    else:                
                        prints[chtag](ch, text)
            finally:
                text.printit()
                del(text)   # should not be necessary
    finally:
        spss.EndProcedure()
    if not didone:
        raise ValueError( _("""No files were found to process.  File Specification: %s""") % files)