def main(): """ Fonction principale (invoquée au lancement) """ # noinspection PyProtectedMember window = tk._default_root #type: tk.Tk # Affectation du titre window.title("Racer Vroomer") # Affectation de l'icône sous Windows if utils.isWindows(): window.iconbitmap("icon.ico") # Maximisation de la fenêtre if utils.isWindows(): window.state("zoomed") else: window.attributes("-zoomed", True) # Résolution de base de 840x420 lorsque la fenêtre n'est pas maximisée width = 840 height = 420 # Placement de la fenêtre au centre de l'écran (quand non-maximisée) screenWidth = window.winfo_screenwidth() screenHeight = window.winfo_screenheight() window.geometry( str(width) + "x" + str(height) + "+" + str(int((screenWidth - width) / 2)) + "+" + str(int((screenHeight - height) / 2))) # Quand la touche F11 est pressée, la fenêtre passe en mode plein écran (la touche ne peut être modifiée directement dans le jeu) def catch_key_event(event): if window.attributes("-fullscreen"): window.attributes("-fullscreen", False) else: window.attributes("-fullscreen", True) settings.saveSettings() window.bind("<KeyPress-F11>", catch_key_event) # Chargement des paramètres settings.loadSettings() # Chargement des scores scores.loadScores() # Affichage du menu principal MainMenu(window) # Démarrage du processus audio, afin de ne pas interrompre le processus principal audio.AudioPlayer(window).start() # Vérification de l'installation de la police if not "Plantagenet Cherokee" in font.families(): import messages as msgs utils.showMessageDialog(msgs.FONT_ERROR, msgs.FONT_NOT_FOUND) # Affichage de la fenêtre et démarrage de la boucle principale window.mainloop()
def checkPython(context): import distutils.sysconfig context.Message("Checking if python is embeddable... ") include_path = distutils.sysconfig.get_config_var('INCLUDEPY') link_stuff = distutils.sysconfig.get_config_var('LINKFORSHARED') # libs = distutils.sysconfig.get_config_var('LDLIBRARY') libs = distutils.sysconfig.get_config_var('LIBRARY') lib_path = distutils.sysconfig.get_config_var('LIBP') # hacks for windows because distutils is broken if libs == None and utils.isWindows(): libs = ['python26'] if lib_path == None and utils.isWindows(): import os lib_path = os.path.join(os.path.dirname(include_path), 'libs') # hacks for osx because distutils doesn't quote things if utils.isOSX() or utils.isOSX104(): import re f = re.compile( '(-framework System Python.framework/Versions/.*/Python)') link_stuff = re.sub(f, r"'\1'", link_stuff) tmp = context.env.Clone() env = context.env if include_path != None: env.Append(CPPPATH=[include_path]) if link_stuff != None: env.Append(LINKFLAGS=link_stuff.split(' ')) if lib_path != None: env.Append(LIBPATH=[lib_path]) new_libs = [] if libs != None: new_libs = libs old_libs = env['LIBS'] env.Replace(LIBS=[new_libs]) env.Append(CPPDEFINES=['HAVE_PYTHON']) ret = context.TryLink( """ #include <Python.h> int main(int argc, char *argv[]) { Py_Initialize(); return 0; } """, ".c") env.Append(LIBS=old_libs) if not ret: context.sconf.env = tmp context.Result(utils.colorResult(ret)) return ret
def checkPython(context): import distutils.sysconfig context.Message("Checking if python is embeddable... ") include_path = distutils.sysconfig.get_config_var('INCLUDEPY') link_stuff = distutils.sysconfig.get_config_var('LINKFORSHARED') # libs = distutils.sysconfig.get_config_var('LDLIBRARY') libs = distutils.sysconfig.get_config_var('LIBRARY') lib_path = distutils.sysconfig.get_config_var('LIBP') # hacks for windows because distutils is broken if libs == None and utils.isWindows(): libs = ['python26'] if lib_path == None and utils.isWindows(): import os lib_path = os.path.join(os.path.dirname(include_path),'libs') # hacks for osx because distutils doesn't quote things if utils.isOSX() or utils.isOSX104(): import re f = re.compile('(-framework System Python.framework/Versions/.*/Python)') link_stuff = re.sub(f, r"'\1'", link_stuff) tmp = context.env.Clone() env = context.env if include_path != None: env.Append(CPPPATH = [include_path]) if link_stuff != None: env.Append(LINKFLAGS = link_stuff.split(' ')) if lib_path != None: env.Append(LIBPATH = [lib_path]) new_libs = [] if libs != None: new_libs = libs old_libs = env['LIBS'] env.Replace(LIBS = [new_libs]) env.Append(CPPDEFINES = ['HAVE_PYTHON']) ret = context.TryLink(""" #include <Python.h> int main(int argc, char *argv[]) { Py_Initialize(); return 0; } """, ".c"); env.Append(LIBS = old_libs) if not ret: context.sconf.env = tmp context.Result(utils.colorResult(ret)) return ret
def catch_key_event(event): """ Méthode invoquée lorsqu'une touche est pressée Paramètre : informations par rapport à l'évennemment "appuyer sur une touche" """ # event.keycode est le numéro de la touche dans la table ASCII key = event.keycode # La touche 27 est la touche ÉCHAP qui annule alors la modification de contrôle if key == 27: popup.destroy() return # On vérifie si la touche n'est pas déjà assignée et si ce n'est pas la touche F11 (utile pour le plein écran) if event.keysym.upper() in utils.CONTROLS.values() or event.keysym.upper() == "F11": # Si on est sous windows, le son d'erreur est alors déclenché # La variable sound_started permet alors de savoir si ce son a déjà été déclenché if utils.isWindows(): import winsound, threading if not sound_started.get(): def start_sound(): sound_started.set(True) winsound.PlaySound("*", winsound.SND_ALIAS) sound_started.set(False) threading.Thread(target = start_sound).start() return # Changement du texte du bouton avec le nouveau contrôle buttonText.set(event.keysym.upper().replace("_", " ")) # Affectation du nouveau contrôle utils.CONTROLS[index] = event.keysym.upper() # Fermeture de la boîte de dialogue popup.destroy() # Écriture des paramètres saveSettings()
def serialConnect(): global gSerial, gSERIAL_PORTNUMBER ui.debugLog("[ Entering serialConnect() ]", caller='serialConnect()', verbose='DEBUG') if( ut.isWindows() ): gSERIAL_PORTNUMBER = gSERIAL_PORTNUMBER_WINDOWS else: gSERIAL_PORTNUMBER = gSERIAL_PORTNUMBER_LINUX gSerial.baudrate = gSERIAL_BAUDRATE gSerial.port = gSERIAL_PORTNUMBER gSerial.timeout = gSERIAL_TIMEOUT if(gSerial.isOpen()): if(ut.isWindows()): ui.debugLog("Closing serial port %s: ..." % gSerial.makeDeviceName(gSerial.port), caller='serialConnect()', verbose='BASIC') else: ui.debugLog("Closing serial port %s: ..." % gSerial.port, caller='serialConnect()', verbose='BASIC') gSerial.close() if(ut.isWindows()): ui.debugLog("Opening serial port %s: ..." % gSerial.makeDeviceName(gSerial.port), caller='serialConnect()', verbose='BASIC') else: ui.debugLog("Opening serial port %s: ..." % gSerial.port, caller='serialConnect()', verbose='BASIC') try: gSerial.open() except: pass if(gSerial.isOpen()): ui.debugLog("Serial port open, waiting for startup message...", caller='serialConnect()', verbose='BASIC') ui.debugLog("", caller='serialConnect()', verbose='BASIC') response = readSerialResponse(2) if( len(response) == 2 ): ui.debugLog("", caller='serialConnect()', verbose='BASIC') ui.debugLog("Startup message received, machine ready", caller='serialConnect()', verbose='BASIC') ui.debugLog("", caller='serialConnect()', verbose='BASIC') else: ui.debugLog("ERROR: startup message error, exiting program", caller='serialConnect()', verbose='BASIC') quit() else: ui.debugLog("ERROR opening serial port, exiting program", caller='serialConnect()', verbose='BASIC') quit()
def _getPath(): path = None if isWindows(): pass # none yet else: p = subprocess.Popen(["which", "zip"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() path = out.strip() return path
def sanitizeVersionNumber(number): """Removes non-digits to be compatible with pywin32""" if not isWindows(): return number match = re.match(r'(\d+)[^\d](\d+)[^\d](\d+)', number) if match is None: return "0" number = ".".join(match.groups()) try: bits = [int(i) for i in number.split(".")] assert (len(bits)) except (AssertionError, IndexError, TypeError, ValueError): number = "0" # do not set version number in win32 binary return number
def wii(env): bin_path = "%s/bin" % os.environ['DEVKITPPC'] ogc_bin_path = "%s/libogc/bin" % os.environ['DEVKITPRO'] prefix = 'powerpc-eabi-' def setup(x): return '%s%s' % (prefix, x) env['CC'] = setup('gcc') env['LD'] = setup('ld') env['CXX'] = setup('g++') env['AS'] = setup('as') env['AR'] = setup('ar') env['OBJCOPY'] = setup('objcopy') if utils.isWindows(): env.Append(CPPPATH=[ "%s/libogc/include" % os.environ['DEVKITPRO'], "%s/libogc/include/SDL" % os.environ['DEVKITPRO'], "%s/libogc/include/freetype2" % os.environ['DEVKITPRO'] ]) env.Append(LIBPATH=[ "%s/libogc/lib" % os.environ['DEVKITPRO'], "%s/libogc/lib/wii" % os.environ['DEVKITPRO'] ]) env.Append( LIBS=['SDL', 'SDL_image', 'SDL_mixer', 'png', 'freetype', 'z']) else: env.Append(CPPPATH=["%s/libogc/include" % os.environ['DEVKITPRO']]) env.Append(CPPDEFINES=['GEKKO', 'WII']) flags = ['-mrvl', '-mcpu=750', '-meabi', '-mhard-float'] env.Append(CCFLAGS=flags) env.Append(CXXFLAGS=flags) env.Append(LINKFLAGS=flags) # env.Append(CPPPATH = ['#src/wii']) env['LINKCOM'] = '$CXX $LINKFLAGS -Wl,--start-group $ARCHIVES $SOURCES $_LIBDIRFLAGS $_LIBFLAGS -Wl,--end-group -o $TARGET' env.Append( LIBS=['wiiuse', 'wiikeyboard', 'iberty', 'bte', 'fat', 'ogc', 'm']) # os.environ['PATH'] = "%s:%s:%s" % (bin_path, ogc_bin_path, os.environ['PATH']) env.PrependENVPath('PATH', bin_path) env.PrependENVPath('PATH', ogc_bin_path) env.Append(CPPDEFINES=['USE_SDL_MAIN']) utils.safeParseConfig(env, 'sdl-config --cflags --libs') utils.safeParseConfig(env, 'freetype-config --libs --cflags') utils.safeParseConfig(env, 'libpng-config --libs --cflags') return env
def _addFilePathListToUploadManager(self,filePathList,targetItemID,currentTargetDirectoryItem): from os.path import isfile,isdir remoteSession = AppController.getInstance().getRemoteSession() if self._uploadManager is None: self._uploadManager = self.getUploadManagerViewController().getUploadManager() for fp in filePathList: #ignore invalid files if fp == "" or fp is None or len(fp) == 0 or fp == '\0': continue #fix filepaths for windows files, remove '/' from beginning if utils.isWindows() and fp.startswith('/'): fp = fp[1:] #more filepath fixing if fp.endswith('/') or fp.endswith("\\"): fp = fp[:-1] print "DROPPING","["+fp+"]","at",str(targetItemID) if isfile(fp): #Add the file and attempt to map the target directory id to its BloopItem object #MIGHT DO: Put this addFile on a thread for snappier UI response. self._uploadManager.addFile(fp, targetItemID, remoteSession.getUserFiles(targetItemID), persist=False) #self.hireWorker(self._uploadManager.addFile, # fp,#filepath # targetItemID,#remoteid # remoteSession.getUserFiles(targetItemID), #remoteFiles # False) #persist=False self.mapDirIdToDirBloopItem(targetItemID,currentTargetDirectoryItem) elif isdir(fp): self._uploadManager.addFolder(fp, targetItemID) else: raise Exception("Something is wrong with this dropped file path " + str(fp)) self._uploadManager.persistUploadTransactions()
def _getPath(): """Retrieves 7-Zip install path and binary from Windows Registry. This way, we do not rely on PATH containing 7-Zip. """ path = None if isWindows(): import win32api, win32con for key in (win32con.HKEY_LOCAL_MACHINE, win32con.HKEY_CURRENT_USER): try: key = win32api.RegConnectRegistry(None, key) key = win32api.RegOpenKeyEx(key, r"SOFTWARE\7-Zip") path, dtype = win32api.RegQueryValueEx(key, "Path") path = os.path.abspath(os.path.join(path, "7z.exe")) except: pass else: p = subprocess.Popen(["which", "7z"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() path = out.strip() return path
def wii(env): bin_path = "%s/bin" % os.environ['DEVKITPPC'] ogc_bin_path = "%s/libogc/bin" % os.environ['DEVKITPRO'] prefix = 'powerpc-eabi-' def setup(x): return '%s%s' % (prefix, x) env['CC'] = setup('gcc') env['LD'] = setup('ld') env['CXX'] = setup('g++') env['AS'] = setup('as') env['AR'] = setup('ar') env['OBJCOPY'] = setup('objcopy') if utils.isWindows(): env.Append(CPPPATH = ["%s/libogc/include" % os.environ['DEVKITPRO'], "%s/libogc/include/SDL" % os.environ['DEVKITPRO'], "%s/libogc/include/freetype2" % os.environ['DEVKITPRO']]) env.Append(LIBPATH = ["%s/libogc/lib" % os.environ['DEVKITPRO'], "%s/libogc/lib/wii" % os.environ['DEVKITPRO']]) env.Append(LIBS = ['SDL', 'SDL_image', 'SDL_mixer', 'png', 'freetype', 'z']) else: env.Append(CPPPATH = ["%s/libogc/include" % os.environ['DEVKITPRO']]) env.Append(CPPDEFINES = ['GEKKO', 'WII']) flags = ['-mrvl', '-mcpu=750', '-meabi', '-mhard-float'] env.Append(CCFLAGS = flags) env.Append(CXXFLAGS = flags) env.Append(LINKFLAGS = flags) # env.Append(CPPPATH = ['#src/wii']) env['LINKCOM'] = '$CXX $LINKFLAGS -Wl,--start-group $ARCHIVES $SOURCES $_LIBDIRFLAGS $_LIBFLAGS -Wl,--end-group -o $TARGET' env.Append(LIBS = ['wiiuse', 'wiikeyboard', 'iberty', 'bte', 'fat', 'ogc', 'm']) # os.environ['PATH'] = "%s:%s:%s" % (bin_path, ogc_bin_path, os.environ['PATH']) env.PrependENVPath('PATH', bin_path) env.PrependENVPath('PATH', ogc_bin_path) env.Append(CPPDEFINES = ['USE_SDL_MAIN']) utils.safeParseConfig(env, 'sdl-config --cflags --libs') utils.safeParseConfig(env, 'freetype-config --libs --cflags') utils.safeParseConfig(env, 'libpng-config --libs --cflags') return env
def _internal_readKey(): if(ut.isWindows()): return ord(msvcrt.getch()) else: return ord(getch.getch())
""" grblCommander - keyboard ======================== Keyboard management """ #print("***[IMPORTING]*** grblCommander - keyboard") import time import kbhit import utils as ut if(ut.isWindows()): import msvcrt if(not ut.isWindows()): import getch # Keyboard manager gKey = kbhit.KBHit() # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def keyPressed(): return gKey.kbhit() # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def _internal_readKey(): if(ut.isWindows()): return ord(msvcrt.getch()) else: return ord(getch.getch()) def readKey(): return _internal_readKey()
# coding=utf-8 from tkinter import StringVar import locale from guis import settings import utils # Affectation de la langue par défaut si non présente if utils.isWindows(): if locale.getlocale(locale.LC_ALL) == (None, None): locale.setlocale(locale.LC_ALL, locale.getdefaultlocale()[0][:2]) else: if locale.getlocale(locale.LC_CTYPE) == (None, None): locale.setlocale(locale.LC_CTYPE, locale.getdefaultlocale()[0][:2]) # Affectation de la langue d'utilisation en fonction des paramètres ou du système d'exploitation (français ou anglais) LOCALE = StringVar(value=locale.getlocale()[0][:2]) if LOCALE.get() != "fr" and LOCALE.get() != "en": LOCALE.set("en") LOCALE.trace_variable("w", lambda *args: settings.saveSettings()) class MSG(StringVar): def __init__(self, english_message: str, french_message: str): """ Constructeur d'un message localisé Le premier argument est le message en anglais, le second est en français """ super().__init__() self.en = english_message self.fr = french_message
def automaticContactTest(iterations = 3): ui.debugLog("[ Entering automaticContactTest() ]", caller='automaticContactTest()', verbose='DEBUG') if(ut.isWindows()): ui.debugLog("ERROR: Automatic contact test not available under Windows", caller='automaticContactTest()', verbose='BASIC') return False ui.debugLog("Saving original Z", caller='automaticContactTest()', verbose='DETAIL') savedZ = tbl.getZ() downStep = 0.1 upStep = 0.01 touchZList = [] nextStartPoint = 0 touchZ = 0 ui.debugLog("Starting contact test (%d iterations)..." % iterations, caller='automaticContactTest()', verbose='BASIC') for curIteration in range(iterations): # Prepare Z position ui.debugLog("Moving to Z to last known touch point +1 step to start test...", caller='automaticContactTest()', verbose='DETAIL') mch.feedAbsolute(z=nextStartPoint, speed=mch.gDEFAULT_SEEK_SPEED, verbose='NONE') # Step down until contact exit = False testCancelled = False z = tbl.getZ() ui.debugLog("---[Iteration %d]-----------------------" % (curIteration+1,), caller='automaticContactTest()', verbose='BASIC') while(not exit): ui.debugLog("Seeking CONTACT point (Z=%.3f)\r" % (z,), end='', caller='automaticContactTest()', verbose='BASIC') mch.feedAbsolute(z=z, verbose='NONE') if(kb.keyPressed()): key=kb.readKey() if( key == 27 ): # <ESC> exit = True testCancelled = True break if(gpio.isContactActive()): ui.debugLog("", caller='automaticContactTest()', verbose='BASIC') exit = True touchZ = z nextStartPoint = touchZ+downStep break z -= downStep # Step up until contact lost if(testCancelled): break else: exit = False lastZ = z while(not exit): z += upStep ui.debugLog("Seeking RELEASE point (Z=%.3f)\r" % (z,), end='', caller='automaticContactTest()', verbose='BASIC') mch.feedAbsolute(z=z, verbose='NONE') if(kb.keyPressed()): key=kb.readKey() if( key == 27 ): # <ESC> exit = True testCancelled = True break if(not gpio.isContactActive()): ui.debugLog("", caller='automaticContactTest()', verbose='BASIC') ui.debugLog("*** TOUCH POINT at Z=%.3f ***" % (lastZ,), caller='automaticContactTest()', verbose='BASIC') exit = True touchZ = lastZ break lastZ = z touchZList.append(touchZ) ui.debugLog("---------------------------------------", caller='automaticContactTest()', verbose='BASIC') if(testCancelled): ui.debugLog("", caller='automaticContactTest()', verbose='BASIC') ui.debugLog("*"*40, caller='automaticContactTest()', verbose='BASIC') ui.debugLog("POINT CONTACT TEST CANCELLED", caller='automaticContactTest()', verbose='BASIC') ui.debugLog("*"*40, caller='automaticContactTest()', verbose='BASIC') ui.debugLog("Restoring original Z...", caller='automaticContactTest()', verbose='DETAIL') mch.safeRapidAbsolute(z=savedZ, verbose='NONE') averageTouchZ = float(sum(touchZList))/len(touchZList) if len(touchZList) > 0 else 0 minTouchZ = 9999 for tz in touchZList: if( tz < minTouchZ ): minTouchZ = tz maxTouchZ = -9999 for tz in touchZList: if( tz > maxTouchZ ): maxTouchZ = tz maxDevTouchZ = maxTouchZ - minTouchZ ui.debugLog( "RESULTS:", caller='automaticContactTest()', verbose='BASIC') ui.debugLog( "--------", caller='automaticContactTest()', verbose='BASIC') ui.debugLog( "- TOUCH POINTS at Z=%s" % (touchZList,), caller='automaticContactTest()', verbose='BASIC') ui.debugLog( "- Average=%.3f - Min=%.3f - Max=%.3f - MaxDev=%.3f" % ( averageTouchZ , minTouchZ , maxTouchZ , maxDevTouchZ) , caller='automaticContactTest()', verbose='BASIC') if(testCancelled): return False else: return { 'z':averageTouchZ, 'iter':iterations, 'max':maxTouchZ, 'min':minTouchZ, 'dev':maxDevTouchZ }
def gridContactTest(): ui.debugLog("[ Entering gridContactTest() ]", caller='gridContactTest()', verbose='DEBUG') ui.debugLog("Enter number of (inner) lines...", caller='gridContactTest()', verbose='BASIC') userLines=input("[0-n]\n") if(not userLines.isnumeric()): ui.debugLog("Invalid number of lines", caller='gridContactTest()', verbose='BASIC') return gridLines = int(userLines) + 2 result = [[None for i in range(gridLines)] for j in range(gridLines)] ui.debugLog("Saving original XYZ", caller='gridContactTest()', verbose='DETAIL') savedX, savedY, savedZ = tbl.getX(), tbl.getY(), tbl.getZ() if(tbl.getZ() < tbl.gSAFE_HEIGHT): ui.debugLog("Temporarily moving to safe Z...", caller='gridContactTest()', verbose='DETAIL') mch.rapidAbsolute(z=tbl.gSAFE_HEIGHT, verbose='NONE') gridIncrementX = tbl.getMaxX() / (gridLines-1) gridIncrementY = tbl.getMaxY() / (gridLines-1) gridX = [gridIncrementX * pos for pos in range(gridLines)] gridY = [gridIncrementY * pos for pos in range(gridLines)] ui.debugLog("tbl.getMaxX() = [%.3f]" % (tbl.getMaxX(),), caller='gridContactTest()', verbose='DEBUG') ui.debugLog("tbl.getMaxY() = [%.3f]" % (tbl.getMaxY(),), caller='gridContactTest()', verbose='DEBUG') ui.debugLog("gridIncrementX = [%.3f]" % (gridIncrementX,), caller='gridContactTest()', verbose='DEBUG') ui.debugLog("gridIncrementY = [%.3f]" % (gridIncrementY,), caller='gridContactTest()', verbose='DEBUG') ui.debugLog("gridX = [%s]" % (repr(gridX),), caller='gridContactTest()', verbose='DEBUG') ui.debugLog("gridY = [%s]" % (repr(gridY),), caller='gridContactTest()', verbose='DEBUG') ui.debugLog( "Starting test (%d*%d lines / %d points)..." % ( gridLines , gridLines , gridLines*gridLines ) , caller='gridContactTest()', verbose='BASIC') testCancelled = False curGridPoint = 0 rangeY = range(len(gridY)) for indexY in rangeY: if( indexY % 2 == 0 ): rangeX = range(len(gridX)) else: rangeX = range(len(gridX)-1,-1,-1) for indexX in rangeX: ui.debugLog("*"*40, caller='gridContactTest()', verbose='BASIC') ui.debugLog( "Testing[%d][%d] Y=%.3f X=%.3f (%d/%d)..." % ( indexY , indexX , gridY[indexY] , gridX[indexX] , curGridPoint+1 , gridLines*gridLines ) , caller='gridContactTest()', verbose='BASIC') ui.debugLog("*"*40, caller='gridContactTest()', verbose='BASIC') ui.debugLog("mch.rapidAbsolute(Y=%.3f X=%.3f)..." % (gridY[indexY],gridX[indexX],), caller='gridContactTest()', verbose='DEBUG') mch.rapidAbsolute(y=gridY[indexY], x=gridX[indexX], verbose='NONE') if kb.keyPressed(): if(kb.readKey() == 27): # <ESC> testCancelled = True break curGridPoint+=1 # Make a contact test if(ut.isWindows()): testResult = manualContactTest() else: testResult = automaticContactTest() if( testResult is False ): testCancelled = True break result[indexY][indexX] = { 'X':gridX[indexX], 'Y':gridY[indexY], 'Z':testResult['z'], 'Zmaz':testResult['max'], 'Zmin':testResult['min'], 'Zdev':testResult['dev'] } if(testCancelled): break if(testCancelled): ui.debugLog("*"*40, caller='gridContactTest()', verbose='BASIC') ui.debugLog("GRID CONTACT TEST CANCELLED", caller='gridContactTest()', verbose='BASIC') ui.debugLog("*"*40, caller='gridContactTest()', verbose='BASIC') if(tbl.getZ() < tbl.gSAFE_HEIGHT): ui.debugLog("Temporarily moving to safe Z...", caller='gridContactTest()', verbose='DETAIL') mch.rapidAbsolute(z=tbl.gSAFE_HEIGHT, verbose='NONE') ui.debugLog("Restoring original XYZ...", caller='gridContactTest()', verbose='DETAIL') mch.safeRapidAbsolute(x=savedX, y=savedY, verbose='NONE') mch.safeRapidAbsolute(z=savedZ, verbose='NONE') return else: ui.debugLog("*"*40, caller='gridContactTest()', verbose='BASIC') ui.debugLog("Test finished.", caller='gridContactTest()', verbose='BASIC') ui.debugLog("*"*40, caller='gridContactTest()', verbose='BASIC') # Test results - normal ui.debugLog("*"*40, caller='gridContactTest()', verbose='BASIC') ui.debugLog("Test tesults (normalized) = ", caller='gridContactTest()', verbose='BASIC') rangeY = range(len(gridY)) rangeX = range(len(gridX)) for indexY in rangeY: for indexX in rangeX: if(result[indexY][indexX] is None): ui.debugLog( "Y[%02d][%07.3f] X[%02d][%07.3f] Z[ERROR]" % ( indexY , 0.0 , indexX , 0.0 ) , caller='gridContactTest()', verbose='BASIC') else: ui.debugLog( "Y[%02d][%07.3f] X[%02d][%07.3f] Z[%07.3f]-dev[%07.3f]" % ( indexY , result[indexY][indexX]['Y'] , indexX , result[indexY][indexX]['X'] , (result[indexY][indexX]['Z'] - result[0][0]['Z']) , result[indexY][indexX]['Zdev'] ) , caller='gridContactTest()', verbose='BASIC') # Test results - Excel formatted # Create output file t=time.localtime() fileName = "logs/GridContactTest %d%02d%02d%02d%02d%02d.txt" % (t.tm_year,t.tm_mon,t.tm_mday,t.tm_hour,t.tm_min,t.tm_sec) outFile = open(fileName, 'w') outFile.write(" grblCommander Grid Contact Test \n") outFile.write("=================================\n") outFile.write("\n") outFile.write("TimeStamp: %d/%02d/%02d %02d:%02d:%02d\n" % (t.tm_year,t.tm_mon,t.tm_mday,t.tm_hour,t.tm_min,t.tm_sec) ) outFile.write("\n") outFile.write( """ Software config: RapidIncrement_XY = %.2f RapidIncrement_Z = %.2f TableSize%% = %d%% """ % ( tbl.getRI_XY(), tbl.getRI_Z(), tbl.getTableSizePercent() ) ) outFile.write("\n") outFile.write("Test results (real Z):\n") outFile.write("----------------------\n") outFile.write("\n") rangeY = range(len(gridY)-1,-1,-1) rangeX = range(len(gridX)) for indexY in rangeY: line = "%07.3f\t" % result[indexY][0]['Y'] for indexX in rangeX: if(result[indexY][indexX] is None): line += "ERROR\t" else: line += "%07.3f\t" % result[indexY][indexX]['Z'] outFile.write(line.rstrip('\t')+'\n') line = "\t" for indexX in rangeX: line += "%07.3f\t" % result[0][indexX]['X'] outFile.write(line.rstrip('\t')+'\n') outFile.write("\n") outFile.write("Test results (normalized Z):\n") outFile.write("----------------------------\n") outFile.write("\n") rangeY = range(len(gridY)-1,-1,-1) rangeX = range(len(gridX)) for indexY in rangeY: line = "%07.3f\t" % result[indexY][0]['Y'] for indexX in rangeX: if(result[indexY][indexX] is None): line += "ERROR\t" else: line += "%07.3f\t" % (result[indexY][indexX]['Z'] - result[0][0]['Z']) outFile.write(line.rstrip('\t')+'\n') line = "\t" for indexX in rangeX: line += "%07.3f\t" % result[0][indexX]['X'] outFile.write(line.rstrip('\t')+'\n') outFile.write("\n") outFile.write("Test results (Z deviations):\n") outFile.write("----------------------------\n") outFile.write("\n") rangeY = range(len(gridY)-1,-1,-1) rangeX = range(len(gridX)) for indexY in rangeY: line = "%07.3f\t" % result[indexY][0]['Y'] for indexX in rangeX: if(result[indexY][indexX] is None): line += "ERROR\t" else: line += "%07.3f\t" % (result[0][0]['Zdev'],) outFile.write(line.rstrip('\t')+'\n') line = "\t" for indexX in rangeX: line += "%07.3f\t" % result[0][indexX]['X'] outFile.write(line.rstrip('\t')+'\n') outFile.write("\n") outFile.close() ui.debugLog("", caller='gridContactTest()', verbose='BASIC') ui.debugLog("Excel version saved to %s" % fileName, caller='gridContactTest()', verbose='BASIC') ui.debugLog("*"*40, caller='gridContactTest()', verbose='BASIC') ui.debugLog("Restoring original XYZ...", caller='gridContactTest()', verbose='BASIC') mch.safeRapidAbsolute(x=savedX, y=savedY, verbose='NONE') mch.safeRapidAbsolute(z=savedZ, verbose='NONE')
===================== Test code """ #print("***[IMPORTING]*** grblCommander - test") import sys import time import utils as ut import interface as ui import table as tbl import machine as mch import serialport as sp import keyboard as kb if(not ut.isWindows()): import rpigpio as gpio gpio.setup() # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def automaticContactTest(iterations = 3): ui.debugLog("[ Entering automaticContactTest() ]", caller='automaticContactTest()', verbose='DEBUG') if(ut.isWindows()): ui.debugLog("ERROR: Automatic contact test not available under Windows", caller='automaticContactTest()', verbose='BASIC') return False ui.debugLog("Saving original Z", caller='automaticContactTest()', verbose='DETAIL') savedZ = tbl.getZ()
def includeModels(includeFilesLst): modelsDir = FindModels.rootName for path, relFile in FindModels.candidateFiles(): src = os.path.join(path, relFile) dst = os.path.join(modelsDir, relFile) includeFilesLst.append((src, dst)) if __name__ == "__main__": # using zip by default, its preinstalled everywhere archiver = None # TODO: perhaps switch to pythons builtin zip? if isWindows(): archiver = Archiver7z(filetype="zip") else: archiver = ArchiverZip() PACKAGENAME = "{name} {ver}".format(name=version.name(), ver=version.number()) # target (temp) dir for mcsas package sysname = platform.system().title() if "darwin" in sysname.lower(): sysname = "MacOS" TARGETDIR = "{pckg} for {sysname}".format(pckg=PACKAGENAME, sysname=sysname) if isLinux(): bitness, binfmt = platform.architecture() TARGETDIR += " " + bitness