Skip to content

Commit d945cf5

Browse files
committed
fix QList<> to list[] convertion
1 parent dc8b4f4 commit d945cf5

File tree

1 file changed

+47
-20
lines changed

1 file changed

+47
-20
lines changed

generate-python-autocomplete-file.py

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
from tkinter.filedialog import askdirectory
1313
#from tkinter.messagebox import askyesno
1414
kritaHomeDir = ""
15-
savedConfig = tempfile.gettempdir()+"/kritaHomeDirSave.py"
15+
savedConfig = os.path.join(tempfile.gettempdir(), 'kritaHomeDirSave.py')
1616
if os.path.isfile(savedConfig):
17-
# isToLoadSavedConfig = askyesno("use previous config", f"Krita source path config was found in {savedConfig}, would you like to use it?")
17+
# isToLoadSavedConfig = askyesno("found previous config", f"Krita source path config was found in {savedConfig}, would you like to use it?")
1818
# if isToLoadSavedConfig:
1919
m = SourceFileLoader("myModule", savedConfig).load_module()
2020
kritaHomeDir = getattr(m, "kritaHomeDir")
@@ -221,8 +221,8 @@
221221
indentspace = indentspace0
222222

223223

224-
225-
exportFile.write(f"{indentspace}\"\"\" " + classCommentsOutput + " \"\"\"" + "\n\n")
224+
exportFile.write(f"{indentspace}\"\"\"<{currentFile.name}>\n")
225+
exportFile.write(f"{indentspace}" + classCommentsOutput + f"{indentspace}\"\"\"" + "\n\n")
226226

227227

228228

@@ -236,7 +236,7 @@
236236
#we save the line of the previous function to get exactly range between signatures of the methods
237237
previousFunctionLineNumber = -1
238238
isInBlockComment = False
239-
fnPattern = re.compile("\(.*\)")
239+
fnPattern = re.compile(r"\(.*\)")
240240
for j, line in enumerate(allFileLines):
241241
if line.__contains__('*/'):
242242
isInBlockComment = False
@@ -252,24 +252,46 @@
252252

253253
line = line.strip() # strip white beginning and trailing white space
254254

255-
def removeCharactersWithinLimiters(input: str, limitBegin: str, limitEnd) -> str:
255+
# def removeCharactersWithinLimiters(input: str, limitBegin: str, limitEnd) -> str:
256+
# output: str = ""
257+
#
258+
# areWeWithinLimiters = False
259+
# i = -1
260+
# for char in input:
261+
# i += 1
262+
# if char == limitBegin:
263+
# areWeWithinLimiters = True
264+
# continue
265+
# if char == limitEnd:
266+
# areWeWithinLimiters = False
267+
#
268+
# if not areWeWithinLimiters:
269+
# output += char
270+
# return output
271+
#
272+
# line = removeCharactersWithinLimiters(line, '<', '>')
273+
def removeSpacesWithinLimiters(input: str, limitBegin: str, limitEnd: str) -> str:
256274
output: str = ""
257-
258-
areWeWithinLimiters = False
275+
isWithinLimiters = False
259276
i = -1
277+
260278
for char in input:
261279
i += 1
262280
if char == limitBegin:
263-
areWeWithinLimiters = True
281+
isWithinLimiters = True
282+
elif char == limitEnd:
283+
isWithinLimiters = False
284+
285+
if isWithinLimiters and char == ' ':
264286
continue
265-
if char == limitEnd:
266-
areWeWithinLimiters = False
267-
268-
if not areWeWithinLimiters:
287+
else:
269288
output += char
289+
270290
return output
271-
272-
line = removeCharactersWithinLimiters(line, '<', '>')
291+
292+
293+
line = removeSpacesWithinLimiters(line, '<', '>')
294+
line = line.replace('<', '[').replace('>', ']')
273295

274296
for match in re.finditer(fnPattern, line):
275297
if line.strip()[0][0] != "*": # this means it is part of a comments
@@ -311,10 +333,14 @@ def removeCharactersWithinLimiters(input: str, limitBegin: str, limitEnd) -> str
311333
returnType = functionList.split(' ')[0]
312334
if returnType == "void":
313335
returnType = "None"
314-
elif returnType == "QString":
315-
returnType = "str"
316-
elif returnType == "QList":
317-
returnType = "list"
336+
#elif returnType == "QString":
337+
# returnType = "str"
338+
elif 'Qstring[' in returnType:
339+
returnType = returnType.replace('QString', 'str')
340+
#elif returnType == "QList":
341+
# returnType = "list"
342+
elif 'QList[' in returnType:
343+
returnType = returnType.replace('QList', 'list')
318344
# elif returnType.__len__()>0:
319345
# returnType = returnType + "()"
320346
functionList = functionList.split(' ')[1]
@@ -433,7 +459,8 @@ def formatParamForDocString(paramName: str, paramType: str) -> str:
433459

434460
functionCommentsOutput = f"{newLine}{indentspace8}{functionCommentsOutput}{newLine}{indentspace8}{parameterPartOfComment}{formatParamForDocString('return', returnType)}{newLine}"
435461

436-
exportFile.write(f"{indentspace8}\"\"\" " + functionCommentsOutput + f"{indentspace8}\"\"\"\n\n" )
462+
exportFile.write(f"{indentspace8}\"\"\"<{currentFile.name}>\n")
463+
exportFile.write(f"{indentspace8}" + functionCommentsOutput + f"{indentspace8}\"\"\"\n\n" )
437464
# exportFile.write(f"{indentspace8}return {returnType}\n\n" )
438465

439466

0 commit comments

Comments
 (0)