-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdialog.py
142 lines (105 loc) · 4.42 KB
/
dialog.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Copyright(C) 2024 Advanced Micro Devices, Inc. All rights reserved.
import sys
import importlib.metadata
# pylint: disable=no-name-in-module
from PySide6.QtWidgets import (
QPushButton,
QDialog,
QVBoxLayout,
QLabel,
QSizePolicy,
QTextEdit,
QProgressDialog,
)
from PySide6.QtGui import QIcon
from PySide6.QtCore import Qt
class ProgressDialog(QProgressDialog):
"""A pop up window with a progress label that goes from 1 to 100"""
def __init__(self, label: str, num_steps: int = 0, parent=None):
"""
label: the text to be shown in the pop up dialog
num_steps: the total number of events the progress bar will load through
"""
super().__init__(label, "Cancel", 1, num_steps, parent)
self.setWindowModality(Qt.WindowModality.WindowModal)
self.setMinimumDuration(0)
self.setWindowTitle("Digest")
self.setWindowIcon(QIcon(":/assets/images/digest_logo_500.jpg"))
self.setValue(1)
self.step_size = 1
self.current_step = 0
self.num_steps = num_steps
def step(self):
self.current_step += self.step_size
if self.current_step > self.num_steps:
self.current_step = self.num_steps
self.setValue(self.current_step)
class InfoDialog(QDialog):
"""This is a specific dialog class used to display the package information
when a user clicks the info button"""
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Application Information")
self.setMinimumWidth(300)
layout = QVBoxLayout()
# Application Version
layout.addWidget(QLabel("<b>Digest Package Information</b>"))
# Python Packages, if you add a new package please update the
# main.spec file in the root_dir (just follow whats there for these packages)
for package in [
"digestai",
"onnx",
"onnxruntime",
]: # Add relevant packages here
version = importlib.metadata.version(package)
layout.addWidget(QLabel(f"{package}: {version}"))
major, minor, micro, _, _ = sys.version_info
python_version_str = f"{major}.{minor}.{micro}"
layout.addWidget(QLabel(f"Python: {python_version_str}"))
self.setLayout(layout)
class StatusDialog(QDialog):
"""A pop up dialog window indicating some useful info the user"""
def __init__(self, status_message: str, title: str = "", parent=None):
super().__init__(parent)
self.setWindowIcon(QIcon(":/assets/images/digest_logo_500.jpg"))
# Modernization
self.setWindowTitle(
title or "Status Message"
) # Use title if provided, else default
self.setWindowFlags(Qt.WindowType.Dialog)
# Modal Behavior (takes over screen)
self.setWindowModality(Qt.WindowModality.WindowModal)
layout = QVBoxLayout()
message_label = QTextEdit(status_message)
message_label.setReadOnly(True) # Prevent editing
message_label.setTextInteractionFlags(
Qt.TextInteractionFlag.TextSelectableByMouse
)
message_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
message_label.setSizePolicy(
QSizePolicy.Policy.MinimumExpanding, QSizePolicy.Policy.Preferred
) # Allow the label to expand
message_label.setMinimumWidth(300)
message_label.setMaximumHeight(75)
layout.addWidget(message_label)
ok_button = QPushButton("OK")
ok_button.clicked.connect(self.accept) # Close dialog when clicked
layout.addWidget(ok_button)
self.setLayout(layout)
class WarnDialog(QDialog):
"""A pop up dialog window indicating a warning to the user"""
def __init__(self, warning_message: str, parent=None):
super().__init__(parent)
self.setWindowIcon(QIcon(":/assets/images/digest_logo_500.jpg"))
self.setWindowTitle("Warning Message")
self.setWindowFlags(Qt.WindowType.Dialog)
self.setMinimumWidth(300)
self.setWindowModality(Qt.WindowModality.WindowModal)
layout = QVBoxLayout()
# Application Version
layout.addWidget(QLabel("<b>Warning</b>"))
layout.addWidget(QLabel(warning_message))
ok_button = QPushButton("OK")
ok_button.clicked.connect(self.accept) # Close dialog when clicked
layout.addWidget(ok_button)
self.setLayout(layout)