From 43a1424d188bdceaa0a313a5c3eb0ba481878f24 Mon Sep 17 00:00:00 2001 From: zhaoyafan Date: Thu, 28 Nov 2024 14:34:13 +0800 Subject: [PATCH] 20241128143300 --- index.html | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 54 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 112 insertions(+), 7 deletions(-) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 0000000..d75ba30 --- /dev/null +++ b/index.html @@ -0,0 +1,65 @@ + + + + + + 接口文档 + + + + + + +
+ + + + + diff --git a/main.py b/main.py index 340bc64..1d85923 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ import clr import time import json import queue +import ctypes import shutil import sqlite3 import logging @@ -18,17 +19,17 @@ import win32print from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QLabel, QComboBox, QCheckBox, QLineEdit, QAction, QMenu, \ QMessageBox, QPushButton, QVBoxLayout, QHBoxLayout, QFileDialog, QDialog from PyQt5.QtCore import Qt, QCoreApplication, QTimer, QPropertyAnimation -from PyQt5.QtGui import QPixmap, QIntValidator +from PyQt5.QtGui import QPixmap, QIntValidator, QFocusEvent from threading import RLock -from flask import Flask, request +from flask import Flask, request, send_from_directory flask_app = Flask(__name__) def _flask_thread(): try: - flask_app.run(host='0.0.0.0', port=7746) + flask_app.run(host='127.0.0.1', port=7746) except: pass @@ -535,6 +536,17 @@ class CustomLineEdit(QLineEdit): action_p.triggered.connect(self.paste) menu.popup(self.mapToGlobal(event.pos())) + def focusInEvent(self, event: QFocusEvent): + super().focusInEvent(event) + self.focusChanged(event) + + def focusOutEvent(self, event: QFocusEvent): + super().focusOutEvent(event) + self.focusChanged(event) + + def focusChanged(self, event: QFocusEvent): + pass + class CustomLineEditNoPopup(QLineEdit): def __init__(self, *args, **kwargs): @@ -558,6 +570,13 @@ class CustomLabel(QLabel): 'font-size: 12px; font-family: \'Microsoft YaHei\'; color: #0C0C0C; border: 1px solid #0C0C0C;') +class CustomText(QLabel): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.setStyleSheet( + 'font-size: 12px; font-family: \'Microsoft YaHei\'; color: #F00000;') + + class CustomComboBox(QComboBox): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -586,7 +605,7 @@ class MainWindow(QMainWindow): def __init__(self, logger: Logger): super().__init__() self.app_name = '标签打印' - self.app_version = ('1.0.5', '20241022', 'zhaoyafan', 'zhaoyafan@foxmail.com', 'https://www.fanscloud.net/') + self.app_version = ('1.0.6', '20241128', 'zhaoyafan', 'zhaoyafan@foxmail.com', 'https://www.fanscloud.net/') self.logger = logger self.toast = ToastNotification() self.setting = Setting( @@ -604,9 +623,10 @@ class MainWindow(QMainWindow): self.task_timer = QTimer(self) self.task_timer.timeout.connect(self.task_execute) self.task_timer.start(100) + self.capslock_state_timer = QTimer(self) + self.capslock_state_timer.timeout.connect(self.update_capslock_state) self.setWindowTitle(self.app_name) self.setGeometry(0, 0, 600, 400) - self.statusBar() self.menubar = self.menuBar() filemenu = self.menubar.addMenu('设置') self.blockRepeatAction = QAction('禁止重复打印', self, checkable=True) @@ -713,16 +733,21 @@ class MainWindow(QMainWindow): # Scan self.edtSCN = CustomLineEdit('') self.edtSCN.setStyleSheet( - 'QLineEdit {font-size: 28px; font-family: \'Microsoft YaHei\'; color: #000000; background-color: #FFFFCC;}') + 'QLineEdit {font-size: 28px; font-family: \'Roboto Mono\',Consolas,\'Microsoft YaHei\'; color: #000000; background-color: #FFFFCC;}') self.edtSCN.setFixedSize(455, 45) + self.edtSCN.focusChanged = self.on_print_scan_focus_change r_layout_3.addWidget(self.edtSCN) # Print button self.butSPT = CustomPushButton('打印') + self.butSPT.setStyleSheet('font-size: 18px; font-family: \'Microsoft YaHei\'; color: #0C0C0C;') self.butSPT.setFixedSize(455, 45) self.butSPT.clicked.connect(self.on_start_printing) self.edtSCN.returnPressed.connect(self.on_print_scan_enter) r_layout_3.addWidget(self.butSPT) - + # CapsLock State + self.TxtCAP = CustomText('') + self.TxtCAP.setFixedSize(205, 15) + r_layout_3.addWidget(self.TxtCAP) # 显示界面 central_widget = QWidget() central_widget.setLayout(m_layout_0) @@ -756,6 +781,12 @@ class MainWindow(QMainWindow): else: break + def update_capslock_state(self): + if (ctypes.windll.user32.GetKeyState(0x14) != 0) == 1: + self.TxtCAP.setText('大写锁定已开启') + else: + self.TxtCAP.setText('') + def load_setting(self): # load blockRepeat self.blockRepeatAction.setChecked(bool(self.setting['blockRepeat'])) @@ -988,6 +1019,12 @@ class MainWindow(QMainWindow): def on_print_scan_enter(self): self.input_scan_prohibited_enter or self.on_start_printing() + def on_print_scan_focus_change(self, event: QFocusEvent): + if (event.gotFocus()) == 1: + self.capslock_state_timer.start(250) + else: + self.capslock_state_timer.stop() + def on_start_printing(self, content=None): edit = self.edtSCN if (self.input_convert_letter == 1) == 1: @@ -1111,6 +1148,9 @@ if __name__ == '__main__': else: return 'Error' + @flask_app.route('/', methods=['GET']) + def index(): + return send_from_directory(os.path.dirname(__file__), 'index.html') flask_thread.start() sys.exit(app.exec_())