-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.py
More file actions
131 lines (113 loc) · 4.87 KB
/
main.py
File metadata and controls
131 lines (113 loc) · 4.87 KB
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
import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QSystemTrayIcon, QMenu, QMessageBox
from PySide6.QtCore import Qt, QPoint
from PySide6.QtGui import QCursor, QIcon, QAction
from modules.line_label import LineLabel
from modules.connect_button import ConnectButton
from modules.autostart_checkbox import AutostartWidget
from modules.autoupdate_checkbox import AutoupdateWidget
from modules.window_controls import WindowControls
from modules.config_file_selector import ConfigFileSelector
from modules.clickable_link import ClickableLink
import ctypes
import core.func
import core.update
import configparser
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setFixedSize(355, 510)
self.setStyleSheet("""
MainWindow {
background-color: rgb(40, 40, 40);
border-radius: 17px;
}
""")
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
self.central_widget = QWidget(self)
self.central_widget.setStyleSheet("background-color: rgb(40, 40, 40); border-radius: 17px;")
self.setCentralWidget(self.central_widget)
self.dragPosition = QPoint()
self.line_label = LineLabel(self.central_widget)
self.connect_button = ConnectButton(self.central_widget)
self.autostart_checkbox = AutostartWidget(self.central_widget)
self.autoupdate_checkbox = AutoupdateWidget(self.central_widget)
self.config_file_selector = ConfigFileSelector(self.central_widget)
self.clickable_link = ClickableLink(self.central_widget)
self.window_controls = WindowControls(self)
self.window_controls.setGeometry(self.width() - 65, 2, 60, 30)
self.connect_button.setCursor(QCursor(Qt.PointingHandCursor))
self.autostart_checkbox.setCursor(QCursor(Qt.PointingHandCursor))
self.autoupdate_checkbox.setCursor(QCursor(Qt.PointingHandCursor))
self.config_file_selector.setCursor(QCursor(Qt.PointingHandCursor))
self.window_controls.setCursor(QCursor(Qt.PointingHandCursor))
self.clickable_link.setCursor(QCursor(Qt.PointingHandCursor))
self.background_process = None
self.tray_icon = QSystemTrayIcon(self)
self.tray_icon.setIcon(QIcon('icon.png'))
self.tray_icon.setToolTip('Line')
self.tray_icon.setVisible(True)
self.tray_menu = QMenu()
self.show_action = QAction("Развернуть", self)
self.quit_action = QAction("Закрыть", self)
self.show_action.triggered.connect(self.show)
self.quit_action.triggered.connect(self.quit_application)
self.tray_menu.addAction(self.show_action)
self.tray_menu.addAction(self.quit_action)
self.tray_icon.setContextMenu(self.tray_menu)
self.closing_from_tray = False
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.dragPosition = event.globalPosition().toPoint() - self.frameGeometry().topLeft()
event.accept()
def mouseMoveEvent(self, event):
if event.buttons() == Qt.LeftButton:
self.move(event.globalPosition().toPoint() - self.dragPosition)
event.accept()
def closeEvent(self, event):
if not self.closing_from_tray and self.isVisible():
self.hide()
self.tray_icon.showMessage(
"Line",
"The application continues to run in the background.",
QSystemTrayIcon.Information,
2000
)
event.ignore()
else:
event.accept()
def quit_application(self):
self.closing_from_tray = True
core.func.toggle_connection(False)
QApplication.instance().quit()
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
def run_as_admin():
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
def check_system_bitness():
return sys.maxsize > 2**32
if __name__ == "__main__":
if not is_admin():
run_as_admin()
sys.exit()
app = QApplication(sys.argv)
window = MainWindow()
if not check_system_bitness():
window.tray_icon.showMessage(
"Warning",
"Your system is 32-bit. The application may not work correctly.",
QSystemTrayIcon.Warning,
5000
)
core.func.stop_windivert_service()
config_file_path = 'scr/config.cfg'
config = configparser.ConfigParser()
config.read(config_file_path)
if int(config['Autoupdate']['enabled']) == 1:
core.update.check_and_update()
window.show()
sys.exit(app.exec())