forked from rgomezjnr/GcodeFilenameFormatPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseFilenameFormat.py
More file actions
executable file
·37 lines (30 loc) · 1.1 KB
/
ParseFilenameFormat.py
File metadata and controls
executable file
·37 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import re
import os.path
# from PyQt6.QtWidgets import QFileDialog, QMessageBox
# Substitute print setting values in filename format
def parseFilenameFormat(print_settings, filename_format):
short = 0
dos = False
# 设置了 8.3 格式 [8.3.2] .2 截取参数的长度
# 截取参数的长度
ma = re.match("^\[8\.3\.?(\d?)\]", filename_format)
if ma != None:
dos = True
# QMessageBox.information(None,'test',ma.group(1))
try:
short = int(ma.group(1))
except:
short = 0
filename_format = filename_format[ma.span()[1]:]
else:
dos = False
for setting, value in print_settings.items():
val = str(value)
if dos:
val = val.replace(" ", "").replace(".", "")
if short > 0:
val = val[0:short]
filename_format = filename_format.replace("[" + setting + "]", val)
filename = re.sub(
'[^A-Za-z0-9.,_\-%°$£€#\[\]\(\)\|\+\'\" ]+', '', filename_format)
return filename