-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog.py
219 lines (178 loc) · 6.52 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
from PyQt6.QtWidgets import QDialog, QLabel, QVBoxLayout
from PyQt6.QtCore import QThread, pyqtSignal
from PyQt6.QtCore import Qt
import requests
from GPT import gpt_gen_img, gpt_talk
from googletrans import Translator
from PyQt6.QtGui import QCursor
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QLabel, QSlider, QPushButton
from PyQt6.QtWidgets import *
from PyQt6.QtGui import *
from PyQt6.QtCore import *
from PyQt6.QtWebEngineWidgets import *
from PyQt6.QtNetwork import QNetworkProxy
class CustomDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
# Set dialog title
self.setWindowTitle("Loading....")
self.setWindowModality(Qt.WindowModality.NonModal)
# Create a layout for the dialog
layout = QVBoxLayout()
self.setFixedWidth(500)
# Create a label to display the text
self.label = QLabel("Loading....")
self.label.setWordWrap(True)
# Add the label to the layout
layout.addWidget(self.label)
# Set the dialog layout
self.setLayout(layout)
def show(self):
pixmap = QPixmap()
super().show()
mouse_pos = QCursor.pos()
self.label.setPixmap(pixmap)
self.updateLabel("Loading....")
self.move(mouse_pos)
def updateLabel(self, message):
self.label.setText(message)
self.adjustSize()
def showImageToLabel(self, pixmap):
self.label.setPixmap(pixmap)
self.adjustSize()
def translate(self, text):
self.setWindowTitle("Dịch")
self.thread = RequestTranslateThread(text)
self.thread.response_received.connect(self.handle_trans_response)
self.thread.start()
def handle_trans_response(self, text):
self.updateLabel(text)
def gpt_ask(self, message):
self.setWindowTitle(message)
self.thread = RequestThread(message)
self.thread.response_received.connect(self.handle_response)
self.thread.start()
def handle_response(self, response_text):
self.updateLabel(response_text)
def gpt_gen_img(self, text):
self.updateLabel("Loading....")
self.setWindowTitle(text)
self.thread = RequestImgThread(text)
self.thread.response_received.connect(self.handle_image_result)
self.thread.start()
def handle_image_result(self, response):
response = requests.get(response)
image_data = response.content
pixmap = QPixmap()
pixmap.loadFromData(image_data)
self.showImageToLabel(pixmap)
class RequestImgThread(QThread):
response_received = pyqtSignal(str)
def __init__(self, message):
super().__init__()
self.message = message
def run(self):
# Perform the HTTP request in the background
result = gpt_gen_img(self.message)
# Emit the signal with the response data
self.response_received.emit(result)
class RequestThread(QThread):
response_received = pyqtSignal(str)
def __init__(self, message):
super().__init__()
self.message = message
def run(self):
# Perform the HTTP request in the background
result = gpt_talk(self.message)
# Emit the signal with the response data
self.response_received.emit(result)
class RequestTranslateThread(QThread):
response_received = pyqtSignal(str)
def __init__(self, text):
super().__init__()
self.text = text
self.translator = Translator()
def run(self):
# Perform the HTTP request in the background
result = self.translator.translate(self.text, dest='vi')
# Emit the signal with the response data
self.response_received.emit(result.text)
class ProxyDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
# Set dialog title
self.setWindowTitle("VPN")
self.setWindowModality(Qt.WindowModality.NonModal)
self.proxyStatus = False
# Create a QWidget as the parent widget
widget = QWidget()
# Create a QVBoxLayout for the layout
layout = QVBoxLayout(widget)
layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
# Create a QLabel for the text
label = ClickableLabel("Disabled")
label.setAlignment(Qt.AlignmentFlag.AlignCenter)
label.setStyleSheet("""
QLabel {
background-color: rgb(171, 171, 171);
color: #FFFFFF;
border-radius: 50px;
font-size: 24px;
font-weight: bold;
padding: 40px;
}
""")
label.clicked.connect(self.vpnClicked)
self.label = label
layout.addWidget(label)
self.setFixedSize(200,300)
self.setLayout(layout)
def vpnClicked(self):
if self.proxyStatus:
print(f"Proxy status {self.proxyStatus} => Turn off")
self.disable()
else:
print(f"Proxy status {self.proxyStatus} => Turn on")
self.enable()
def enable(self):
proxy = QNetworkProxy()
proxy.setType(QNetworkProxy.ProxyType.HttpProxy)
proxy.setHostName("194.233.83.119")
proxy.setPort(3128)
proxy.setPassword("trung")
proxy.setUser("trungbmt")
QNetworkProxy.setApplicationProxy(proxy)
self.proxyStatus = True
self.label.setText("Enabled")
self.label.setStyleSheet("""
QLabel {
background-color: rgb(53, 204, 37);
color: #FFFFFF;
border-radius: 50px;
font-size: 24px;
font-weight: bold;
padding: 40px;
}
""")
def disable(self):
QNetworkProxy.setApplicationProxy(QNetworkProxy(QNetworkProxy.ProxyType.DefaultProxy))
self.proxyStatus = False
self.label.setText("Disabled")
self.label.setStyleSheet("""
QLabel {
background-color: rgb(171, 171, 171);
color: #FFFFFF;
border-radius: 50px;
font-size: 24px;
font-weight: bold;
padding: 40px;
}
""")
def show(self, position):
# Move the dialog to the calculated position
self.move(position.x(), position.y())
super().show()
class ClickableLabel(QLabel):
clicked = pyqtSignal()
def mousePressEvent(self, event):
self.clicked.emit()