Skip to content

Commit

Permalink
fix auto store skill file to .config directory bug
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonWong08 committed Oct 26, 2023
1 parent 28fdd5b commit 72604af
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
13 changes: 9 additions & 4 deletions pyUI/SkillComposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ def export(self):
print('};')

if file:
print(file.name)
# print(file.name)
x = datetime.datetime.now()
fileData = '# ' + file.name.split('/')[-1].split('.')[0] + '\n'
fileData += 'Note: '+'You may add a short description/instruction here.\n\n'
Expand All @@ -1492,18 +1492,23 @@ def export(self):
fileData += '\n'
fileData += '};'

# the file in the config directory wiill be saved automatically
filePathName = configDir + seperation + file.name.split('/')[-1]
# the file in the config directory will be saved automatically
filePathName = configDir + separation + 'SkillLibrary' + separation + self.model + separation + file.name.split('/')[-1]
logger.debug(f"fileName is: {filePathName}")

filePathList = [file.name, filePathName]
for filePath in filePathList:
if filePath == filePathName:
modelDir = configDir + separation + 'SkillLibrary' + separation + self.model
makeDirectory(modelDir)
try:
with open(filePath, 'w+', encoding="utf-8") as f:
f.write(fileData)
time.sleep(0.1)
logger.info(f"save successfully: {filePath}")
except Exception as e:
return False, 'save failed:{}'.format(e)
logger.info(f"save failed:{e}")
return False

if self.gaitOrBehavior.get() == txt('Behavior'):
skillData.insert(0, [loopStructure[0], loopStructure[-1], int(self.loopRepeat.get())])
Expand Down
26 changes: 16 additions & 10 deletions pyUI/commonVar.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from translate import *
import platform
import sys
sys.path.append('../serialMaster/')
resourcePath = './resources/'
releasePath = './release/'
if platform.system() == "Windows": # for Windows
sys.path.append('..\\serialMaster\\')
resourcePath = '.\\resources\\'
releasePath = '.\\release\\'
else:
sys.path.append('../serialMaster/')
resourcePath = './resources/'
releasePath = './release/'
sys.path.append(resourcePath)

from ardSerial import *
from tkinter import *
from tkinter import messagebox
Expand All @@ -12,7 +19,6 @@
import threading
import random
import datetime
import platform
import os

NyBoard_version = 'NyBoard_V1_2'
Expand Down Expand Up @@ -53,7 +59,7 @@

ports = []

def mkdir(path):
def makeDirectory(path):
# delete spaces in the path string
path = path.strip()
# delete the '\' at the end of path string
Expand All @@ -74,17 +80,17 @@ def mkdir(path):
return False

if platform.system() == "Windows": # for Windows
seperation = '\\'
separation = '\\'
homeDri = os.getenv('HOMEDRIVE')
homePath = os.getenv('HomePath')
configDir = homeDri + homePath
else: # for Linux & macOS
seperation = '/'
separation = '/'
home = os.getenv('HOME')
configDir = home
configDir = configDir + seperation +'.config' + seperation +'Petoi'
mkdir(configDir)
defaultConfPath = configDir + seperation + 'defaultConfig.txt'
configDir = configDir + separation +'.config' + separation +'Petoi'
makeDirectory(configDir)
defaultConfPath = configDir + separation + 'defaultConfig.txt'
print(defaultConfPath)

def createImage(frame, imgFile, imgW):
Expand Down
2 changes: 1 addition & 1 deletion pyUI/translate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
versionNum = '1.1.3'
dateStr = '2023-09-28'
dateStr = '2023-10-26'

textEN = {
'lan':'English',
Expand Down
4 changes: 2 additions & 2 deletions serialMaster/ardSerial.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def txt(key):
The default starting point is INFO,
which means that the logging module will automatically filter out any DEBUG messages.
'''
# logging.basicConfig(level=logging.DEBUG, format=FORMAT)
#logging.basicConfig(level=logging.DEBUG, format=FORMAT)
logging.basicConfig(level=logging.INFO, format=FORMAT)
logger = logging.getLogger(__name__)

Expand All @@ -41,7 +41,7 @@ def printH(head, value):
print(head, end=' ')
print(value)

printH("ardSerial date: ", "Sep 26, 2023")
printH("ardSerial date: ", "Oct 10, 2023")

def encode(in_str, encoding='utf-8'):
if isinstance(in_str, bytes):
Expand Down

0 comments on commit 72604af

Please sign in to comment.