Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Init_Window_v104.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'Init_Window.ui'
# Form implementation generated from reading ui file 'E:\CLONE\QC-Formula/Init_Window_v104.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
Expand Down Expand Up @@ -50,6 +50,9 @@ def setupUi(self, MainWindow):
self.DOCPage_ImageLabel.setScaledContents(False)
self.DOCPage_ImageLabel.setAlignment(QtCore.Qt.AlignCenter)
self.DOCPage_ImageLabel.setObjectName("DOCPage_ImageLabel")
self.DOCPage_LoadButton_clipboard = QtWidgets.QPushButton(self.tab_2)
self.DOCPage_LoadButton_clipboard.setGeometry(QtCore.QRect(470, 90, 100, 32))
self.DOCPage_LoadButton_clipboard.setObjectName("DOCPage_LoadButton_clipboard")
self.TopTabWidget.addTab(self.tab_2, "")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
Expand Down Expand Up @@ -158,7 +161,7 @@ def setupUi(self, MainWindow):
self.Copy_Status_Label.setObjectName("Copy_Status_Label")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 650, 22))
self.menubar.setGeometry(QtCore.QRect(0, 0, 650, 23))
self.menubar.setObjectName("menubar")
self.menu = QtWidgets.QMenu(self.menubar)
self.menu.setObjectName("menu")
Expand All @@ -178,7 +181,7 @@ def setupUi(self, MainWindow):
self.menubar.addAction(self.menu.menuAction())

self.retranslateUi(MainWindow)
self.TopTabWidget.setCurrentIndex(2)
self.TopTabWidget.setCurrentIndex(0)
self.DOCPage_LoadButton.clicked.connect(MainWindow.img_Load_From_Doc)
self.DOCPage_LoadButton.clicked.connect(MainWindow.img_Display_In_Doc_Label)
self.Setting_ConfirmButton.clicked.connect(MainWindow.Setting_API_Values)
Expand All @@ -199,6 +202,7 @@ def retranslateUi(self, MainWindow):
self.DOCPage_InfoButton.setText(_translate("MainWindow", "图片信息"))
self.DOCPage_ConfirmButton.setText(_translate("MainWindow", "识别公式"))
self.DOCPage_ImageLabel.setText(_translate("MainWindow", "公式预览"))
self.DOCPage_LoadButton_clipboard.setText(_translate("MainWindow", "读取粘贴板"))
self.TopTabWidget.setTabText(self.TopTabWidget.indexOf(self.tab_2), _translate("MainWindow", "从文件导入"))
self.URLPage_label_1.setText(_translate("MainWindow", "图片网址:"))
self.URLPage_ConfirmButton.setText(_translate("MainWindow", "识别公式"))
Expand Down
30 changes: 28 additions & 2 deletions main_v104.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
# 从根目录下文件中调用的类
from Init_Window_v104 import Ui_MainWindow ### PyQt 界面样式
from OCR_iFLY_v104 import get_result ### 讯飞接口

import numpy as np
### 注意:使用 PyInstaller 进行打包时,配置文件路径的定义,与调试时不同。
### 使用 Python IDE 调试时,需要注释掉第二行,使第一行命令生效;而使用 PyInstaller 进行打包时,需要注释掉第一行,使第二行命令生效。
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) ### 用于读写配置文件的全局路径
print(BASE_DIR)
#BASE_DIR = os.path.dirname(sys.executable) ### 用于读写配置文件的全局路径

class MainWindow(QMainWindow):
Expand All @@ -38,6 +39,7 @@ def __init__(self, parent=None):
self.ui.Input_APISecret.setText(self.conf.get('API_iFLY', 'APISecret'))
self.ui.Input_APIKey.setText(self.conf.get('API_iFLY', 'APIKey'))
self.ui.Copy_Status_Label.setText("")
self.ui.DOCPage_LoadButton_clipboard.clicked.connect(self.img_Load_From_Clipboard)


# 定义槽函数:从本地请求图片地址
Expand All @@ -64,7 +66,31 @@ def img_Load_From_Doc(self):
self.conf.write(f)
print("IMG LOAD SUCCESS")

# 定义槽函数:从互联网请求图片地址
def img_Load_From_Clipboard(self):
clipboard = QApplication.clipboard()
image = clipboard.image()
self.img_Display_In_Doc_Label_Clipboard(image)

def img_Display_In_Doc_Label_Clipboard(self,image):
# 在 QLabel 中绘制图片
image = QPixmap.fromImage(image)
self.ui.DOCPage_ImageLabel.setPixmap(image)
self.ui.DOCPage_ImageLabel.setScaledContents(True) # 自适应QLabel大小
# 保存照片
image_path = os.path.join(BASE_DIR,'Examples','temp.png')
image.save(image_path)
self.conf = configparser.ConfigParser() # 加载现有配置文件
self.conf.read(os.path.join(BASE_DIR, 'config.ini'), encoding="utf-8-sig") # 从全局路径读取配置文件
try:
self.conf.set('img_Location', 'DOC', image_path)
### 确定写入配置文件
with open("config.ini", "w+") as f:
self.conf.write(f)
print("IMG LOAD SUCCESS")
except:
pass

# 定义槽函数:从互联网请求图片地址
def img_Load_From_Internet(self):
return 0 ### 等待后续开发...

Expand Down