Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SnowballXueQiu committed Jul 20, 2023
1 parent 65d7df9 commit 4c42b99
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self):

# 设置程序标题和图标
self.setWindowTitle("Image to JSON Converter")
self.setWindowIcon(QIcon("assets/Icon.svg"))
self.setWindowIcon(QIcon(self.getPath("assets/Icon.svg")))
self.resize(400, 380)

# 添加标题
Expand All @@ -59,7 +59,6 @@ def __init__(self):
self.image_path_button = QPushButton("选择图片路径", self)
self.image_path_label = NewQLineEdit("", self)
self.image_path_label.setPlaceholderText("请输入图片路径或拖入图片")
self.image_path_button.setIcon(QIcon("assets/arrow.png"))
self.image_path_button.clicked.connect(self.select_image_path)
image_path_layout.addWidget(self.image_path_button)
image_path_layout.addWidget(self.image_path_label)
Expand All @@ -70,7 +69,6 @@ def __init__(self):
self.output_path_button = QPushButton("选择输出路径", self)
self.output_path_label = QLineEdit("", self)
self.output_path_label.setPlaceholderText("请输入输出路径")
self.output_path_button.setIcon(QIcon("assets/arrow.png"))
self.output_path_button.clicked.connect(self.select_output_path)
output_path_layout.addWidget(self.output_path_button)
output_path_layout.addWidget(self.output_path_label)
Expand Down Expand Up @@ -173,12 +171,21 @@ def convert_image_to_json(self):

QMessageBox.information(self, "成功", "图片已成功转换为JSON文件!")

@staticmethod
def getPath(path: str):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")

return os.path.join(base_path, path)


if __name__ == "__main__":
app = QApplication(sys.argv)

# 加载自定义字体文件
font_path = os.path.join("assets", "HarmonyOS_Sans_SC_Regular.ttf")
font_path = MainWindow.getPath("assets/HarmonyOS_Sans_SC_Regular.ttf")
font_id = QFontDatabase.addApplicationFont(font_path)
font_family = QFontDatabase.applicationFontFamilies(font_id)[0]
app.setFont(QFont(font_family, 10))
Expand Down

0 comments on commit 4c42b99

Please sign in to comment.