fix
This commit is contained in:
parent
8e049ab033
commit
a01c16982a
|
@ -86,7 +86,7 @@ class SnPost:
|
||||||
return
|
return
|
||||||
|
|
||||||
menu = (MenuItem('退出', self.close), MenuItem('查看日志', self.log))
|
menu = (MenuItem('退出', self.close), MenuItem('查看日志', self.log))
|
||||||
image = Image.open("favicon.ico")
|
image = Image.open("001.ico")
|
||||||
title = "打印机"
|
title = "打印机"
|
||||||
self.icon = pystray.Icon(title, image, "打印机", menu)
|
self.icon = pystray.Icon(title, image, "打印机", menu)
|
||||||
threading.Thread(target=self.icon.run, daemon=True).start()
|
threading.Thread(target=self.icon.run, daemon=True).start()
|
||||||
|
@ -96,12 +96,11 @@ class SnPost:
|
||||||
def pdf_printer():
|
def pdf_printer():
|
||||||
if request.method == 'OPTIONS': # 跨域请求预检
|
if request.method == 'OPTIONS': # 跨域请求预检
|
||||||
return jsonify({"message": "OK"}), 200
|
return jsonify({"message": "OK"}), 200
|
||||||
# if 'file' not in request.files:
|
|
||||||
# return jsonify({"error_message": "No file part", "error_code": 400}), 400
|
|
||||||
file = request.files['file']
|
file = request.files['file']
|
||||||
printer_name = request.form.get('printer_name', None)
|
printer_name = request.form.get('printer_name', None)
|
||||||
# Save the file temporarily
|
# Save the file temporarily
|
||||||
temp_pdf_path = os.path.join(os.path.dirname(__file__), 'temp_pdf.pdf')
|
temp_pdf_path = os.path.join(os.path.dirname(__file__), 'temp_pdf.pdf')
|
||||||
|
logger.info(f"Saving file to {temp_pdf_path}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Read the PDF binary
|
# Read the PDF binary
|
||||||
|
@ -109,7 +108,8 @@ def pdf_printer():
|
||||||
if printer_name:
|
if printer_name:
|
||||||
win32print.OpenPrinter(printer_name)
|
win32print.OpenPrinter(printer_name)
|
||||||
win32print.SetDefaultPrinter(printer_name)
|
win32print.SetDefaultPrinter(printer_name)
|
||||||
win32print.GetDefaultPrinter()
|
else:
|
||||||
|
return jsonify({"error_message": "打印机名称不正确","error_code": "printer_name_error"}), 400
|
||||||
|
|
||||||
win32api.ShellExecute(
|
win32api.ShellExecute(
|
||||||
0,
|
0,
|
||||||
|
@ -121,6 +121,7 @@ def pdf_printer():
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import traceback
|
import traceback
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
return jsonify({"error_message": str(e), "error_code": "print_failed"}), 500
|
return jsonify({"error_message": str(e), "error_code": "print_failed"}), 500
|
||||||
finally:
|
finally:
|
||||||
|
@ -145,16 +146,17 @@ def save_pdf_from_binary(pdf_binary, file_path):
|
||||||
def str_printer():
|
def str_printer():
|
||||||
if request.method == 'OPTIONS': # 跨域请求预检
|
if request.method == 'OPTIONS': # 跨域请求预检
|
||||||
return jsonify({"message": "OK"}), 200
|
return jsonify({"message": "OK"}), 200
|
||||||
print_commands = request.json.get('print_commands', None)
|
print_commands = request.json.get('printer_commands', None)
|
||||||
print_name = request.json.get('print_name', None)
|
print_name = request.json.get('printer_name', None)
|
||||||
print(print_commands)
|
|
||||||
tsclibrary = ctypes.WinDLL(".//TSCLIB.dll")
|
tsclibrary = ctypes.WinDLL(".//TSCLIB.dll")
|
||||||
if print_name:
|
if print_name:
|
||||||
|
logger.info("打印机名称: %s", print_name)
|
||||||
tsclibrary.openportW(print_name)
|
tsclibrary.openportW(print_name)
|
||||||
else:
|
else:
|
||||||
print_name = win32print.GetDefaultPrinter()
|
logger.error("打印机名称无效")
|
||||||
tsclibrary.openportW(print_name)
|
return jsonify({"error_message": "打印机名称无线","error_code": "printer_name_error"}), 400
|
||||||
tsclibrary.clearbuffer()
|
tsclibrary.clearbuffer()
|
||||||
|
try:
|
||||||
for item in print_commands:
|
for item in print_commands:
|
||||||
if 'WINTEXT' in item:
|
if 'WINTEXT' in item:
|
||||||
item_list = item.replace('WINTEXT ', '').split(',')
|
item_list = item.replace('WINTEXT ', '').split(',')
|
||||||
|
@ -169,8 +171,10 @@ def str_printer():
|
||||||
item_list[7])
|
item_list[7])
|
||||||
else:
|
else:
|
||||||
tsclibrary.sendcommandW(item)
|
tsclibrary.sendcommandW(item)
|
||||||
print(item, "33333")
|
|
||||||
tsclibrary.closeport()
|
tsclibrary.closeport()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
logger.error("打印错误: %s", str(e))
|
||||||
|
|
||||||
return jsonify({}), 200
|
return jsonify({}), 200
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ exe = EXE(
|
||||||
upx=True,
|
upx=True,
|
||||||
upx_exclude=[],
|
upx_exclude=[],
|
||||||
runtime_tmpdir=None,
|
runtime_tmpdir=None,
|
||||||
console=True,
|
console=False,
|
||||||
disable_windowed_traceback=False,
|
disable_windowed_traceback=False,
|
||||||
argv_emulation=False,
|
argv_emulation=False,
|
||||||
target_arch=None,
|
target_arch=None,
|
||||||
|
|
BIN
favicon.ico
BIN
favicon.ico
Binary file not shown.
Before Width: | Height: | Size: 17 KiB |
|
@ -0,0 +1,9 @@
|
||||||
|
[2024-07-23 14:22:33,040] [PrintAgent.py:157] [ERROR]- 打印机名称无效
|
||||||
|
[2024-07-23 14:22:41,597] [PrintAgent.py:157] [ERROR]- 打印机名称无效
|
||||||
|
[2024-07-23 14:23:38,476] [PrintAgent.py:157] [ERROR]- 打印机名称无效
|
||||||
|
[2024-07-23 14:26:43,987] [PrintAgent.py:157] [ERROR]- 打印机名称无效
|
||||||
|
[2024-07-23 14:26:49,117] [PrintAgent.py:157] [ERROR]- 打印机名称无效
|
||||||
|
[2024-07-23 14:44:09,522] [PrintAgent.py:156] [ERROR]- 打印机名称无效
|
||||||
|
[2024-07-23 14:45:04,932] [PrintAgent.py:157] [ERROR]- 打印机名称无效
|
||||||
|
[2024-07-23 14:46:16,085] [PrintAgent.py:154] [INFO]- 打印机名称: GP-3150TN
|
||||||
|
[2024-07-23 14:47:39,217] [PrintAgent.py:153] [INFO]- 打印机名称: GP-3150TN
|
Loading…
Reference in New Issue