-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdth.py
199 lines (161 loc) · 7.55 KB
/
dth.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import sys
import os
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout, QFrame, QDialog
from PyQt5.QtGui import QPalette, QColor, QIcon, QFont, QPixmap
from PyQt5.QtCore import Qt, QSize, QFile, QTextStream
# Function to convert man days to hours
def man_days_to_hours():
try:
man_days = float(man_days_input.text())
hours = man_days * 8
result_label.setText(f"{man_days} man days = {hours} hours")
except ValueError:
result_label.setText("Please enter a number.")
# Function to convert hours to man days
def hours_to_man_days():
try:
hours = float(man_days_input.text())
man_days = hours / 8
result_label.setText(f"{hours} hours = {man_days} man days")
except ValueError:
result_label.setText("Please enter a number.")
# Function to toggle between man days and hours calculation
def toggle_calculation():
if toggle_button.isChecked():
label_man_days.setText("Enter Hours:")
convert_button.clicked.disconnect()
convert_button.clicked.connect(hours_to_man_days)
window.setStyleSheet("background-color: #2f2045;")
toggle_button.setIcon(QIcon(icon_path("man_to_hours.png")))
toggle_button.setStyleSheet("background-color: transparent; border: none;")
else:
label_man_days.setText("Enter Man Days:")
convert_button.clicked.disconnect()
convert_button.clicked.connect(man_days_to_hours)
window.setStyleSheet("background-color: #20452e;")
toggle_button.setIcon(QIcon(icon_path("hours_to_man.png")))
toggle_button.setStyleSheet("background-color: transparent; border: none;")
# Function to clear the input field
def clear_fields():
man_days_input.clear()
# Function to get the full path for icon and image files
def icon_path(file_name):
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, file_name)
# Create the information window
def open_info_window():
info_dialog = QDialog(window)
info_dialog.setWindowTitle("About")
info_dialog.setFixedSize(300, 150) # Set the size of the information window
# Pass the current background color from the main window to the information window
info_dialog.setStyleSheet(f"background-color: {window.styleSheet().split(':')[1]};")
layout = QVBoxLayout()
version_label = QLabel("Ver 2.0.2")
version_label.setStyleSheet("color: white; font-size: 14px;")
developer_label = QLabel('<a href="https://www.athuljohny.in" style="color: #FFFF00; text-decoration: none; font-size: 16px;">www.athuljohny.in</a>')
developer_label.setOpenExternalLinks(True) # Enable opening links in a web browser
copyright_label = QLabel("Copyright © 2024 Athul Johny")
copyright_label.setStyleSheet("color: white; font-size: 16px;")
close_button = QPushButton("Close")
close_button.setStyleSheet(
"color: white; background-color: #353535; border: 2px solid #FFFFFF; border-radius: 10px; font-size: 16px; padding: 5px;"
)
layout.addWidget(version_label)
layout.addWidget(developer_label)
layout.addWidget(copyright_label)
layout.addWidget(close_button)
info_dialog.setLayout(layout)
# Connect the Close button to close the information window
close_button.clicked.connect(info_dialog.close)
info_dialog.exec_()
# Create the application
app = QApplication(sys.argv)
# Set the application icon
app_icon = QIcon(icon_path("icon.ico"))
app.setWindowIcon(app_icon)
# Set a dark color palette for dark mode
dark_palette = QPalette()
dark_palette.setColor(QPalette.Window, QColor(53, 53, 53))
dark_palette.setColor(QPalette.WindowText, Qt.white)
dark_palette.setColor(QPalette.Button, QColor(53, 53, 53))
dark_palette.setColor(QPalette.ButtonText, Qt.white)
dark_palette.setColor(QPalette.Base, QColor(25, 25, 25))
dark_palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
dark_palette.setColor(QPalette.ToolTipBase, Qt.white)
dark_palette.setColor(QPalette.ToolTipText, Qt.white)
dark_palette.setColor(QPalette.Text, Qt.white)
dark_palette.setColor(QPalette.BrightText, Qt.red)
dark_palette.setColor(QPalette.Link, QColor(42, 130, 218))
dark_palette.setColor(QPalette.Highlight, QColor(42, 130, 218))
dark_palette.setColor(QPalette.HighlightedText, Qt.black)
# Create the main window
window = QWidget()
window.setWindowTitle("Work Time Converter")
window.setPalette(dark_palette)
# Set the fixed size of the window
window.setFixedSize(400, 150)
# Set the initial background color to #20452e
window.setStyleSheet("background-color: #20452e;")
# Create widgets
man_days_input = QLineEdit()
toggle_button = QPushButton()
convert_button = QPushButton("Convert")
clear_button = QPushButton("Clear") # Create the Clear button
# Set widget styles for dark mode
widgets = [man_days_input, convert_button, clear_button] # Include clear_button in the widgets list
for widget in widgets:
widget.setStyleSheet(
"color: white; background-color: #2e2e2e; border: 1px solid #FFFFFF; border-radius: 15px; font-size: 16px; padding: 5px;"
)
# Set the button as a toggle button and use hours_to_man.png initially
toggle_button.setIcon(QIcon(icon_path("hours_to_man.png")))
toggle_button.setCheckable(True)
toggle_button.setIconSize(QSize(40, 40))
toggle_button.setToolTip("Toggle Calculation Mode")
# Remove default style (border and background) from the input title text
label_man_days = QLabel("Enter Man Days:")
label_man_days.setStyleSheet("color: white; background-color: transparent; border: none; font-size: 16px;")
# Remove default style (border and background) from the info button
toggle_button.setStyleSheet("background-color: transparent; border: none;")
# Create the info button
info_button = QPushButton()
info_button.setIcon(QIcon(icon_path("info.png"))) # Replace with the path to your info button icon
info_button.setFixedSize(40, 40) # Set the size of the info button
info_button.setStyleSheet("background-color: transparent; border: none;")
info_button.setToolTip("About")
# Calculate half of the Clear button's current width and set it as the new fixed width
clear_button.setFixedWidth(clear_button.sizeHint().width() // 0.5)
# Connect the button click to toggle calculation mode
toggle_button.clicked.connect(toggle_calculation)
# Connect the info button's click event to open_info_window
info_button.clicked.connect(open_info_window)
# Connect the Enter key press event to the convert_button click event
man_days_input.returnPressed.connect(convert_button.click)
# Connect the Convert button click event to the appropriate function
convert_button.clicked.connect(man_days_to_hours)
# Connect the Clear button click event to clear_fields function
clear_button.clicked.connect(clear_fields)
# Create layout
input_layout = QHBoxLayout()
input_layout.addWidget(label_man_days)
input_layout.addWidget(man_days_input)
input_layout.addWidget(toggle_button)
# Adjust the layout to accommodate the Clear button
button_layout = QHBoxLayout()
button_layout.addWidget(clear_button)
button_layout.addWidget(convert_button)
button_layout.addWidget(info_button)
main_layout = QVBoxLayout()
main_layout.addLayout(input_layout)
main_layout.addLayout(button_layout)
# Create the result label and adjust its font size and style
result_label = QLabel("Please enter a number.")
result_label.setFont(QFont("Arial", 12))
result_label.setStyleSheet("color: white; padding-top: 0px; padding-bottom: 0px;")
main_layout.addWidget(result_label)
# Set the layout for the window
window.setLayout(main_layout)
# Show the window
window.show()
# Run the application
sys.exit(app.exec_())