20241128143300
This commit is contained in:
parent
d54479f42a
commit
43a1424d18
File diff suppressed because one or more lines are too long
54
main.py
54
main.py
|
@ -7,6 +7,7 @@ import clr
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
import queue
|
import queue
|
||||||
|
import ctypes
|
||||||
import shutil
|
import shutil
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import logging
|
import logging
|
||||||
|
@ -18,17 +19,17 @@ import win32print
|
||||||
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QLabel, QComboBox, QCheckBox, QLineEdit, QAction, QMenu, \
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QLabel, QComboBox, QCheckBox, QLineEdit, QAction, QMenu, \
|
||||||
QMessageBox, QPushButton, QVBoxLayout, QHBoxLayout, QFileDialog, QDialog
|
QMessageBox, QPushButton, QVBoxLayout, QHBoxLayout, QFileDialog, QDialog
|
||||||
from PyQt5.QtCore import Qt, QCoreApplication, QTimer, QPropertyAnimation
|
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 threading import RLock
|
||||||
|
|
||||||
from flask import Flask, request
|
from flask import Flask, request, send_from_directory
|
||||||
|
|
||||||
flask_app = Flask(__name__)
|
flask_app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _flask_thread():
|
def _flask_thread():
|
||||||
try:
|
try:
|
||||||
flask_app.run(host='0.0.0.0', port=7746)
|
flask_app.run(host='127.0.0.1', port=7746)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -535,6 +536,17 @@ class CustomLineEdit(QLineEdit):
|
||||||
action_p.triggered.connect(self.paste)
|
action_p.triggered.connect(self.paste)
|
||||||
menu.popup(self.mapToGlobal(event.pos()))
|
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):
|
class CustomLineEditNoPopup(QLineEdit):
|
||||||
def __init__(self, *args, **kwargs):
|
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;')
|
'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):
|
class CustomComboBox(QComboBox):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
@ -586,7 +605,7 @@ class MainWindow(QMainWindow):
|
||||||
def __init__(self, logger: Logger):
|
def __init__(self, logger: Logger):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.app_name = '标签打印'
|
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.logger = logger
|
||||||
self.toast = ToastNotification()
|
self.toast = ToastNotification()
|
||||||
self.setting = Setting(
|
self.setting = Setting(
|
||||||
|
@ -604,9 +623,10 @@ class MainWindow(QMainWindow):
|
||||||
self.task_timer = QTimer(self)
|
self.task_timer = QTimer(self)
|
||||||
self.task_timer.timeout.connect(self.task_execute)
|
self.task_timer.timeout.connect(self.task_execute)
|
||||||
self.task_timer.start(100)
|
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.setWindowTitle(self.app_name)
|
||||||
self.setGeometry(0, 0, 600, 400)
|
self.setGeometry(0, 0, 600, 400)
|
||||||
self.statusBar()
|
|
||||||
self.menubar = self.menuBar()
|
self.menubar = self.menuBar()
|
||||||
filemenu = self.menubar.addMenu('设置')
|
filemenu = self.menubar.addMenu('设置')
|
||||||
self.blockRepeatAction = QAction('禁止重复打印', self, checkable=True)
|
self.blockRepeatAction = QAction('禁止重复打印', self, checkable=True)
|
||||||
|
@ -713,16 +733,21 @@ class MainWindow(QMainWindow):
|
||||||
# Scan
|
# Scan
|
||||||
self.edtSCN = CustomLineEdit('')
|
self.edtSCN = CustomLineEdit('')
|
||||||
self.edtSCN.setStyleSheet(
|
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.setFixedSize(455, 45)
|
||||||
|
self.edtSCN.focusChanged = self.on_print_scan_focus_change
|
||||||
r_layout_3.addWidget(self.edtSCN)
|
r_layout_3.addWidget(self.edtSCN)
|
||||||
# Print button
|
# Print button
|
||||||
self.butSPT = CustomPushButton('打印')
|
self.butSPT = CustomPushButton('打印')
|
||||||
|
self.butSPT.setStyleSheet('font-size: 18px; font-family: \'Microsoft YaHei\'; color: #0C0C0C;')
|
||||||
self.butSPT.setFixedSize(455, 45)
|
self.butSPT.setFixedSize(455, 45)
|
||||||
self.butSPT.clicked.connect(self.on_start_printing)
|
self.butSPT.clicked.connect(self.on_start_printing)
|
||||||
self.edtSCN.returnPressed.connect(self.on_print_scan_enter)
|
self.edtSCN.returnPressed.connect(self.on_print_scan_enter)
|
||||||
r_layout_3.addWidget(self.butSPT)
|
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 = QWidget()
|
||||||
central_widget.setLayout(m_layout_0)
|
central_widget.setLayout(m_layout_0)
|
||||||
|
@ -756,6 +781,12 @@ class MainWindow(QMainWindow):
|
||||||
else:
|
else:
|
||||||
break
|
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):
|
def load_setting(self):
|
||||||
# load blockRepeat
|
# load blockRepeat
|
||||||
self.blockRepeatAction.setChecked(bool(self.setting['blockRepeat']))
|
self.blockRepeatAction.setChecked(bool(self.setting['blockRepeat']))
|
||||||
|
@ -988,6 +1019,12 @@ class MainWindow(QMainWindow):
|
||||||
def on_print_scan_enter(self):
|
def on_print_scan_enter(self):
|
||||||
self.input_scan_prohibited_enter or self.on_start_printing()
|
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):
|
def on_start_printing(self, content=None):
|
||||||
edit = self.edtSCN
|
edit = self.edtSCN
|
||||||
if (self.input_convert_letter == 1) == 1:
|
if (self.input_convert_letter == 1) == 1:
|
||||||
|
@ -1111,6 +1148,9 @@ if __name__ == '__main__':
|
||||||
else:
|
else:
|
||||||
return 'Error'
|
return 'Error'
|
||||||
|
|
||||||
|
@flask_app.route('/', methods=['GET'])
|
||||||
|
def index():
|
||||||
|
return send_from_directory(os.path.dirname(__file__), 'index.html')
|
||||||
|
|
||||||
flask_thread.start()
|
flask_thread.start()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|
Loading…
Reference in New Issue