-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpyqt5_qr_scan.py
57 lines (51 loc) · 1.74 KB
/
pyqt5_qr_scan.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: 'zfb'
# time: 2022-02-20 11:18
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QIcon
from multiprocessing import freeze_support
import sys
import os
import logging
from custom_qwidget import QrDetectDialog, scan_process
from sql_helper import create_files_table, create_status_table
from utils import get_base_path
# 用于把图片资源嵌入到Qt程序里面
# 发布exe时就不需要附该文件了
import resources
def log_init():
try:
# 当前程序的路径
log_dir = os.path.join(get_base_path(), "log")
if not os.path.exists(log_dir):
os.makedirs(log_dir)
logging.info(f"日志文件夹{log_dir}创建成功")
else:
logging.info(f"日志文件夹{log_dir}已存在")
except Exception as e:
logging.warning(f"日志文件{log_dir}创建失败")
logging.warning(repr(e))
if __name__ == '__main__':
# 如果用pyinstaller打包含有多进程的代码,这一行必须要
# 且在最开始执行
freeze_support()
create_files_table()
create_status_table()
app = QApplication(sys.argv)
detectDialog = QrDetectDialog()
detectDialog.set_run_func(scan_process)
detectDialog.setWindowFlags(Qt.WindowMinimizeButtonHint|Qt.WindowCloseButtonHint)
detectDialog.setWindowIcon(QIcon(':/icons/icon.png'))
screen = app.desktop()
detectDialog.resize(screen.height(),screen.height()//2)
fg = detectDialog.frameGeometry()
sc = screen.availableGeometry().center()
fg.moveCenter(sc)
detectDialog.show()
log_init()
code = app.exec_()
if detectDialog._loadThread:
detectDialog._loadThread.quit()
sys.exit(code)