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])
def excelexport(obj, custom): """Export selected output items to Excel parameters: file - filespec for output (required) sheet - sheetname. Default is "Sheet" action - "CreateWorkbook" | "Create Worksheet" | "ModifyWorksheet" location - "OverwriteAtCellRef" | "AddColumns" | "AddRows" startingCell - starting cell if location is overwrite. Default is "A1" image - image format - "jpg" | "png" | "tiff" | "eps" | "emf" | "bmp" See OUTPUT EXPORT help for information on these options Use # in the file or sheet string to insert a sequential number on each save operation to avoid overwriting. The first value listed is the default if there is one. If an item would overwrite another item in the same command, an error is raised""" if custom["_first"]: custom["_first"] = False custom["number"] = 0 # set defaults custom["sheet"] = custom.get("sheet", "Sheet") custom["action"] = custom.get("action", "CreateWorkbook") custom["location"] = custom.get("location", "OverwriteAtCellRef") custom["startingCell"] = custom.get("startingCell", "A1") image = custom.get("image", "jpg") if not image in imagekwds.keys(): raise ValueError(_("""Invalid image format: %s""" % image)) custom["image"] = imagekwds[image] if not "file" in custom: raise ValueError(_("""file parameter must be specified""")) # user might have too old a version for file handle support try: custom["file"] = FileHandles().resolve(custom["file"]) except: pass count = custom["file"].count("#") + custom["sheet"].count("#") if count > 1: raise ValueError( _("""Only one "#" may appear in file and sheet parameters together""" )) custom["wouldoverwrite"] = (count == 0 and custom["location"] == "OverwriteAtCellRef") or \ (custom["file"].count("#") == 0 and custom["action"] == "CreateWorkbook") # desout is the designated output window desout = custom["_designatedOutput"] # error checking is left to the apis desout.SetOutputOptions( SpssClient.DocExportOption.ExcelOperationOptions, custom["action"]) desout.SetOutputOptions(SpssClient.DocExportOption.ExcelStartingCell, custom["startingCell"]) desout.SetOutputOptions( SpssClient.DocExportOption.ExcelLocationOptions, custom["location"]) # Process the current object # check for overwrite if custom["wouldoverwrite"] and custom["number"] > 0: raise ValueError( _("""Exporting stopped: multiple items would overwrite each other""" )) filename = custom["file"].replace("#", str(custom["number"])) sheetname = custom["sheet"].replace("#", str(custom["number"])) desout = custom["_designatedOutput"] desout.SetOutputOptions(SpssClient.DocExportOption.ExcelSheetNames, sheetname) # Write graphics objects to separate files named by file and sheet name # since ExportToDocument api can't do images if obj.GetType() in [ SpssClient.OutputItemType.CHART, SpssClient.OutputItemType.TREEMODEL, SpssClient.OutputItemType.MODEL ]: name = os.path.splitext(filename)[0] + "_" + sheetname obj.ExportToImage(name, custom["image"]) else: obj.ExportToDocument(filename, SpssClient.DocExportFormat.SpssFormatXls) custom["number"] = custom["number"] + 1
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)