-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
726 lines (569 loc) · 31.7 KB
/
main.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
import sys
import random
import requests
import webbrowser
import json
from PyQt5.QtWidgets import QFrame, QDialogButtonBox, QApplication, QWidget, QLabel, QPushButton, QHBoxLayout, QVBoxLayout, QLineEdit, QDialog, QTextEdit, QDesktopWidget, QStackedLayout, QCheckBox, QListWidget, QListWidgetItem, QMessageBox
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtCore import Qt, pyqtSlot, QDate
class WedoneOperateApp(QWidget):
def __init__(self):
super().__init__()
self.settings = self.load_settings()
self.initUI()
self.setWindowTitle("Wedone Operate")
self.setWindowIcon(QIcon("icon.png"))
self.setStyleSheet("background-color: white; color: #2b2b2b;")
self.check_obsolete_version()
def load_settings(self):
default_settings = {
"auto_update": True,
"auto_patch": True,
"addition_enabled": True,
"subtraction_enabled": True,
"multiplication_enabled": True,
"division_enabled": True
}
try:
with open("settings.json", "r") as file:
settings = json.load(file)
# Mettre à jour les valeurs par défaut avec les valeurs chargées
default_settings.update(settings)
except FileNotFoundError:
# Si le fichier n'existe pas, créer un nouveau fichier avec les valeurs par défaut
with open("settings.json", "w") as file:
json.dump(default_settings, file)
return default_settings
def initUI(self):
self.layout = QVBoxLayout(self)
self.layout.setContentsMargins(10, 10, 10, 10)
self.label = QLabel("Bienvenue dans Wedone Operate 4.1 ! Bonne aventure !", self)
self.label.setStyleSheet("font-size: 16px; font-weight: bold; color: #2b2b2b;")
self.layout.addWidget(self.label)
self.label = QLabel("Combien d'épreuves souhaitez-vous faire ?", self)
self.label.setStyleSheet("font-size: 14px; color: #0672BC; margin-top: 10px;")
self.layout.addWidget(self.label)
self.input = QLineEdit(self)
self.input.setStyleSheet("font-size: 14px; background-color: #f0f0f0; color: #2b2b2b; border: 1px solid #0672BC; border-radius: 5px;")
self.layout.addWidget(self.input)
self.start_button = QPushButton("Commencer", self)
self.start_button.clicked.connect(self.start_game)
self.start_button.setStyleSheet("font-size: 14px; background-color: #0672BC; color: white; font-weight: bold; border: 1px solid #0672BC; border-radius: 5px;")
self.layout.addWidget(self.start_button)
self.settings_button = QPushButton("Paramètres", self)
self.settings_button.clicked.connect(self.open_settings)
self.settings_button.setStyleSheet("font-size: 14px; background-color: #0672BC; color: white; font-weight: bold; border: 1px solid #0672BC; border-radius: 5px;")
self.layout.addWidget(self.settings_button)
self.setLayout(self.layout)
self.center()
def showEvent(self, event):
super().showEvent(event)
self.center()
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
@pyqtSlot()
def start_game(self):
self.execute_game()
def keyPressEvent(self, event):
if event.key() == Qt.Key_Return or event.key() == Qt.Key_Enter:
self.execute_game()
def execute_game(self):
try:
nombre_epreuves = self.input.text()
if not nombre_epreuves.isdigit() or int(nombre_epreuves) <= 0:
raise ValueError("Veuillez entrer un nombre valide et supérieur à 0 pour le nombre d'épreuves.")
nombre_epreuves = int(nombre_epreuves)
score = 0
for i in range(1, nombre_epreuves + 1):
operation, nombre1, nombre2, operation_str, resultat = self.generate_operation()
dialog = AnswerDialog(f"Épreuve {i}", f"{nombre1} {operation_str} {nombre2} = ?")
user_input = dialog.get_answer()
if user_input is None:
return
if user_input == resultat:
score += 1
message_window = MessageWindow("Bonne réponse", "Bonne réponse !")
message_window.exec_()
else:
message_window = MessageWindow("Mauvaise réponse", f"Mauvaise réponse. La réponse correcte était {resultat}.")
message_window.exec_()
pourcentage = score * 100 / nombre_epreuves
message = f"Vous avez réussi {score} épreuves sur {nombre_epreuves}.\nVotre pourcentage de réussite est de {pourcentage:.2f}%."
result_window = MessageWindow("Résultat", message)
result_window.exec_()
except ValueError as e:
error_window = InputErrorWindow("Erreur", str(e))
error_window.exec_()
def generate_operation(self):
available_operations = []
settings = self.load_settings() # Chargement des paramètres actuels
if settings['addition_enabled']:
available_operations.append(1) # Addition
if settings['subtraction_enabled']:
available_operations.append(2) # Soustraction
if settings['multiplication_enabled']:
available_operations.append(3) # Multiplication
if settings['division_enabled']:
available_operations.append(4) # Division
if not available_operations:
raise ValueError("Aucune opération n'est activée. Veuillez activer au moins un type d'opération dans les paramètres.")
operation = random.choice(available_operations) # Choix aléatoire parmi les opérations activées
nombre1, nombre2, operation_str, resultat = 0, 0, "", 0
if operation == 1: # Addition
nombre1 = random.randint(1, 100)
nombre2 = random.randint(1, 100 - nombre1)
resultat = nombre1 + nombre2
operation_str = "+"
elif operation == 2: # Soustraction
nombre1 = random.randint(1, 100)
nombre2 = random.randint(1, nombre1)
resultat = nombre1 - nombre2
operation_str = "-"
elif operation == 3: # Multiplication
nombre1 = random.randint(1, 10)
nombre2 = random.randint(1, 10)
resultat = nombre1 * nombre2
operation_str = "*"
elif operation == 4: # Division
nombre1 = random.randint(2, 10)
nombre2 = random.randint(2, nombre1)
while nombre1 % nombre2 != 0:
nombre2 = random.randint(2, nombre1)
resultat = nombre1 // nombre2
operation_str = "/"
return operation, nombre1, nombre2, operation_str, resultat
@pyqtSlot()
def open_settings(self):
settings_window = SettingsWindow()
settings_window.load_settings()
settings_window.exec_()
def check_obsolete_version(self):
current_version = "4.1" # Remplacez par la version actuelle de votre logiciel
obsolete_versions_url = "https://wedoneofficiel.github.io/Gestion-Mises-A-Jour/Wedone-Operate/versions-obsoletes-wedone-operate-stable.txt"
try:
response = requests.get(obsolete_versions_url)
if response.status_code == 200:
obsolete_versions = response.text.strip().split('\n')
if current_version in obsolete_versions:
self.show_obsolete_version_alert(current_version)
except requests.exceptions.RequestException:
print("Impossible de vérifier les versions obsolètes.")
def show_obsolete_version_alert(self, version):
alert = ObsoleteVersionAlert(version)
alert.exec_()
class MessageWindow(QDialog):
def __init__(self, title, message):
super().__init__()
self.setWindowTitle(title)
self.setWindowIcon(QIcon("icon.png"))
self.setStyleSheet("background-color: white; color: #2b2b2b;")
layout = QVBoxLayout(self)
label = QLabel(message)
label.setStyleSheet("font-size: 14px;")
layout.addWidget(label)
ok_button = QPushButton("OK")
ok_button.clicked.connect(self.accept)
ok_button.setStyleSheet("font-size: 14px; background-color: #0672BC; color: white; font-weight: bold; border: 1px solid #0672BC; border-radius: 5px;")
layout.addWidget(ok_button)
self.setLayout(layout)
class InputErrorWindow(QDialog):
def __init__(self, title, message):
super().__init__()
self.setWindowTitle(title)
self.setWindowIcon(QIcon("icon.png"))
self.setStyleSheet("background-color: white; color: #2b2b2b;")
layout = QVBoxLayout(self)
label = QLabel(message)
label.setStyleSheet("font-size: 14px;")
layout.addWidget(label)
ok_button = QPushButton("OK")
ok_button.clicked.connect(self.accept)
ok_button.setStyleSheet("font-size: 14px; background-color: #0672BC; color: white; font-weight: bold; border: 1px solid #0672BC; border-radius: 5px;")
layout.addWidget(ok_button)
self.setLayout(layout)
class AnswerDialog(QDialog):
def __init__(self, title, message):
super().__init__()
self.setWindowTitle(title)
self.setWindowIcon(QIcon("icon.png"))
self.setStyleSheet("background-color: white; color: #2b2b2b;")
layout = QVBoxLayout(self)
label = QLabel(message)
label.setStyleSheet("font-size: 14px;")
layout.addWidget(label)
self.answer_input = QLineEdit()
self.answer_input.setStyleSheet("font-size: 14px; background-color: #f0f0f0; color: #2b2b2b; border: 1px solid #0672BC; border-radius: 5px;")
layout.addWidget(self.answer_input)
ok_button = QPushButton("OK")
ok_button.clicked.connect(self.accept)
ok_button.setStyleSheet("font-size: 14px; background-color: #0672BC; color: white; font-weight: bold; border: 1px solid #0672BC; border-radius: 5px;")
layout.addWidget(ok_button)
self.setLayout(layout)
def get_answer(self):
if self.exec_() == QDialog.Accepted:
user_input = self.answer_input.text()
if user_input.strip() == "":
return None
return int(user_input)
return None
class UpdateWindow(QDialog):
def __init__(self, latest_version):
super().__init__()
self.setWindowTitle("Mise à jour disponible")
self.setWindowIcon(QIcon("icon.png"))
self.setStyleSheet("background-color: white; color: #2b2b2b;")
layout = QVBoxLayout(self)
label = QLabel(f"Une nouvelle version de Wedone Operate est disponible (version {latest_version}) !\n\nNous vous recommandons de mettre à jour l'application pour obtenir les dernières fonctionnalités et correctifs de sécurité.")
label.setStyleSheet("font-size: 14px;")
layout.addWidget(label)
buttons_layout = QHBoxLayout()
layout.addLayout(buttons_layout)
# Ajout d'un espace blanc entre les boutons Télécharger et Ignorer
buttons_layout.addStretch()
ignore_button = QPushButton(" Ignorer ")
ignore_button.clicked.connect(self.close)
ignore_button.setStyleSheet("font-size: 14px; background-color: #E7E3E3; color: #2b2b2b; font-weight: none; border: 1px solid #E7E3E3; border-radius: 5px;")
buttons_layout.addWidget(ignore_button)
download_button = QPushButton(" Télécharger ")
download_button.clicked.connect(self.download_update)
download_button.setStyleSheet("font-size: 15px; background-color: #0672BC; color: white; font-weight: bold; border: 1px solid #0672BC; border-radius: 5px;")
buttons_layout.addWidget(download_button)
self.setLayout(layout)
def download_update(self):
webbrowser.open("https://github.com/WedoneOfficiel/Wedone-Operate/releases")
class SettingsWindow(QDialog):
def __init__(self):
super().__init__()
self.setWindowTitle("Paramètres")
self.setWindowIcon(QIcon("icon.png"))
self.setStyleSheet("background-color: white; color: #2b2b2b;")
self.setMinimumSize(400, 200)
self.initUI()
self.load_settings()
def initUI(self):
main_layout = QHBoxLayout(self)
# Liste des sections à gauche
self.sections_layout = QVBoxLayout()
self.sections_layout.setSpacing(10)
self.sections_layout.setAlignment(Qt.AlignTop)
main_layout.addLayout(self.sections_layout)
self.add_section_button(" Epreuves ", self.show_options_section)
self.add_section_button(" Mises à jour ", self.show_updates_section)
self.add_section_button(" À propos ", self.show_about_section)
# Ajoutez d'autres sections ici si nécessaire
# Barre verticale
main_layout.addWidget(QFrame(frameShape=QFrame.VLine, frameShadow=QFrame.Sunken))
# Contenu des sections à droite
self.stacked_layout = QStackedLayout()
main_layout.addLayout(self.stacked_layout)
# Paramètres de la recherche automatique des mises à jour
self.updates_section = QWidget()
self.updates_section.setStyleSheet("background-color: white; font-size: 14px;")
self.create_updates_section()
self.stacked_layout.addWidget(self.updates_section)
# Section "À propos" - Initialisation
self.about_section = QWidget()
self.about_section.setStyleSheet("background-color: white; font-size: 14px;")
self.create_about_section()
self.stacked_layout.addWidget(self.about_section)
# Nouvelle section "Options du logiciel" - Initialisation
self.options_section = QWidget()
self.options_section.setStyleSheet("background-color: white; font-size: 14px;")
self.create_options_section()
self.stacked_layout.addWidget(self.options_section)
self.setLayout(main_layout)
# Sélectionner automatiquement l'onglet "Mises à jour"
self.show_options_section()
def auto_update_changed(self, state):
self.settings["auto_update"] = state == Qt.Checked
print("Auto-update set to:", self.settings["auto_update"])
self.save_settings()
def auto_patch_changed(self, state):
self.settings["auto_patch"] = state == Qt.Checked
print("Auto-patch set to:", self.settings["auto_patch"])
self.save_settings()
def save_settings(self):
with open("settings.json", "w") as file:
json.dump(self.settings, file)
print("Settings saved")
def add_section_button(self, text, callback):
button = QPushButton(text)
button.setStyleSheet("font-size: 14px; background-color: #0672BC; color: white; font-weight: bold; border: 1px solid #0672BC; border-radius: 5px;")
button.clicked.connect(callback)
self.sections_layout.addWidget(button)
def show_updates_section(self):
self.stacked_layout.setCurrentIndex(0)
self.highlight_selected_section(" Mises à jour ")
def show_about_section(self): # Fonction pour afficher la section "À propos"
self.stacked_layout.setCurrentIndex(1)
self.highlight_selected_section(" À propos ")
def show_options_section(self): # Fonction pour afficher la section "Options du logiciel"
self.stacked_layout.setCurrentIndex(2)
self.highlight_selected_section(" Epreuves ")
def highlight_selected_section(self, section_name):
for i in range(self.sections_layout.count()):
button = self.sections_layout.itemAt(i).widget()
if button.text().strip() == section_name.strip():
button.setStyleSheet("font-size: 14px; background-color: #0672BC; color: white; font-weight: bold; border: 1px solid #0672BC; border-radius: 5px;")
else:
button.setStyleSheet("font-size: 14px; background-color: #E7E3E3; color: #2b2b2b; font-weight: bold; border: 1px solid #E7E3E3; border-radius: 5px;")
def create_updates_section(self):
layout = QVBoxLayout(self.updates_section)
self.auto_update_check = QCheckBox("Recherche automatique des mises à jour")
self.auto_update_check.stateChanged.connect(self.auto_update_changed)
self.auto_update_check.setStyleSheet("font-size: 14px; color: black;")
layout.addWidget(self.auto_update_check)
self.auto_patch_check = QCheckBox("Recherche automatique des patchs")
self.auto_patch_check.stateChanged.connect(self.auto_patch_changed)
self.auto_patch_check.setStyleSheet("font-size: 14px; color: black;")
layout.addWidget(self.auto_patch_check)
# Bouton de recherche manuelle des mises à jour
manual_update_button = QPushButton(" Rechercher manuellement les mises à jour ")
manual_update_button.setStyleSheet("font-size: 14px; background-color: #f0f0f0; color: #2b2b2b; border: 2px solid #f0f0f0; border-radius: 5px;")
manual_update_button.clicked.connect(self.manual_update)
layout.addWidget(manual_update_button)
# Bouton de recherche manuelle des patchs
manual_patch_button = QPushButton(" Rechercher manuellement les patchs ")
manual_patch_button.setStyleSheet("font-size: 14px; background-color: #f0f0f0; color: #2b2b2b; border: 2px solid #f0f0f0; border-radius: 5px;")
manual_patch_button.clicked.connect(self.manual_patch)
layout.addWidget(manual_patch_button)
def create_about_section(self): # Fonction pour créer la section "À propos"
layout = QVBoxLayout(self.about_section)
# Chargement de l'icône
icon_label = QLabel()
pixmap = QPixmap("icon.png")
pixmap = pixmap.scaledToWidth(50) # Ajuster la largeur de l'icône à 50 pixels
icon_label.setPixmap(pixmap)
layout.addWidget(icon_label, alignment=Qt.AlignCenter)
# Numéro de version
version_layout = QHBoxLayout()
version_label = QLabel("Wedone Operate | Version : Stable 4.1")
version_label.setStyleSheet("font-size: 14px; color: black;")
version_layout.addWidget(version_label)
layout.addLayout(version_layout)
# Licence
license_label = QLabel('<a href="https://github.com/WedoneOfficiel/Wedone-Operate?tab=Apache-2.0-1-ov-file#readme">Licence Apache 2.0</a>')
license_label.setOpenExternalLinks(True)
license_label.setStyleSheet("font-size: 14px; color: blue;")
layout.addWidget(license_label)
# Copyright
current_year = QDate.currentDate().year()
copyright_label = QLabel(f"Copyright © 2022-{current_year}")
copyright_label.setStyleSheet("font-size: 14px; color: black;")
layout.addWidget(copyright_label)
self.setLayout(layout)
def create_options_section(self): # Fonction pour créer la section "Epreuves"
layout = QVBoxLayout(self.options_section)
version_layout = QHBoxLayout()
version_label = QLabel("Sélectionnez ici les types d'opérations que <br> vous souhaitez que l'on vous propose :")
version_label.setStyleSheet("font-size: 14px; color: black;")
version_layout.addWidget(version_label)
layout.addLayout(version_layout)
self.addition_checkbox = QCheckBox("Additions")
self.addition_checkbox.setChecked(True) # Sélectionnez par défaut
self.addition_checkbox.stateChanged.connect(self.addition_changed)
layout.addWidget(self.addition_checkbox)
self.subtraction_checkbox = QCheckBox("Soustractions")
self.subtraction_checkbox.setChecked(True) # Sélectionnez par défaut
self.subtraction_checkbox.stateChanged.connect(self.subtraction_changed)
layout.addWidget(self.subtraction_checkbox)
self.multiplication_checkbox = QCheckBox("Multiplications")
self.multiplication_checkbox.setChecked(True) # Sélectionnez par défaut
self.multiplication_checkbox.stateChanged.connect(self.multiplication_changed)
layout.addWidget(self.multiplication_checkbox)
self.division_checkbox = QCheckBox("Divisions")
self.division_checkbox.setChecked(True) # Sélectionnez par défaut
self.division_checkbox.stateChanged.connect(self.division_changed)
layout.addWidget(self.division_checkbox)
def auto_update_changed(self, state):
print(f"Recherche automatique des mises à jour : {state == Qt.Checked}")
def auto_patch_changed(self, state):
print(f"Recherche automatique des patchs : {state == Qt.Checked}")
def manual_update(self):
print("Recherche manuelle des mises à jour...")
def manual_patch(self):
print("Recherche manuelle des patchs...")
def addition_changed(self, state):
print(f"Additions activées : {state == Qt.Checked}")
self.save_settings()
def subtraction_changed(self, state):
print(f"Soustractions activées : {state == Qt.Checked}")
self.save_settings()
def multiplication_changed(self, state):
print(f"Multiplications activées : {state == Qt.Checked}")
self.save_settings()
def division_changed(self, state):
print(f"Divisions activées : {state == Qt.Checked}")
self.save_settings()
def load_settings(self):
try:
with open("settings.json", "r") as file:
settings = json.load(file)
self.auto_update_check.setChecked(settings.get("auto_update", True))
self.auto_patch_check.setChecked(settings.get("auto_patch", True))
self.addition_checkbox.setChecked(settings.get("addition_enabled", True))
self.subtraction_checkbox.setChecked(settings.get("subtraction_enabled", True))
self.multiplication_checkbox.setChecked(settings.get("multiplication_enabled", True))
self.division_checkbox.setChecked(settings.get("division_enabled", True))
except FileNotFoundError:
pass
def save_settings(self):
settings = {
"auto_update": self.auto_update_check.isChecked(),
"auto_patch": self.auto_patch_check.isChecked(),
"addition_enabled": self.addition_checkbox.isChecked(),
"subtraction_enabled": self.subtraction_checkbox.isChecked(),
"multiplication_enabled": self.multiplication_checkbox.isChecked(),
"division_enabled": self.division_checkbox.isChecked()
}
with open("settings.json", "w") as file:
json.dump(settings, file)
def closeEvent(self, event):
self.save_settings()
super().closeEvent(event)
def auto_update_changed(self, state):
print(f"Recherche automatique des mises à jour : {'activée' if state == Qt.Checked else 'désactivée'}")
self.save_settings()
def auto_patch_changed(self, state):
if state == Qt.Unchecked:
confirmation = ConfirmationDialog(self)
if confirmation.exec_() == QDialog.Accepted:
print("Recherche automatique des patchs désactivée.")
self.save_settings()
else:
self.auto_patch_check.setChecked(True) # Rétablir l'état précédent
else:
print("Recherche automatique des patchs activée.")
self.save_settings()
def manual_update(self):
check_for_updates(True)
def manual_patch(self):
check_for_security_patches(True)
def closeEvent(self, event):
self.save_settings()
super().closeEvent(event)
class ConfirmationDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Confirmation")
layout = QVBoxLayout(self)
label = QLabel("Êtes-vous sûr de vouloir désactiver la recherche automatique des patchs ?")
label.setStyleSheet("font-size: 14px; color: #0672BC;")
layout.addWidget(label)
explanation_label = QLabel("La recherche automatique des patchs joue un rôle essentiel dans la protection de votre système et du logiciel. <br/>Il est fortement recommandé de la conserver active pour garantir une sécurité optimale.")
explanation_label.setStyleSheet("font-size: 13px; color: black;")
explanation_label.setWordWrap(True)
layout.addWidget(explanation_label)
button_box = QDialogButtonBox(QDialogButtonBox.Cancel | QDialogButtonBox.Ignore, Qt.Horizontal, self)
layout.addWidget(button_box)
cancel_button = button_box.button(QDialogButtonBox.Cancel)
cancel_button.setText(" Annuler ")
ignore_button = button_box.button(QDialogButtonBox.Ignore)
ignore_button.setText(" Continuer ")
cancel_button.setStyleSheet("font-size: 15px; background-color: #0672BC; color: white; font-weight: bold; border: 1px solid #0672BC; border-radius: 5px;")
ignore_button.setStyleSheet("font-size: 14px; background-color: #E7E3E3; color: #2b2b2b; font-weight: none; border: 1px solid #E7E3E3; border-radius: 5px;")
cancel_button.clicked.connect(self.reject)
ignore_button.clicked.connect(self.accept)
def check_for_updates(auto_update):
if auto_update:
version_url = "https://wedoneofficiel.github.io/Gestion-Mises-A-Jour/Wedone-Operate/version-wedone-operate.txt"
obsolete_versions_url = "https://wedoneofficiel.github.io/Gestion-Mises-A-Jour/Wedone-Operate/versions-obsoletes-wedone-operate-stable.txt"
try:
response = requests.get(version_url)
obsolete_response = requests.get(obsolete_versions_url)
if response.status_code == 200 and obsolete_response.status_code == 200:
latest_version = response.text.strip()
obsolete_versions = obsolete_response.text.strip().split('\n')
current_version = "4.1" # Remplacez par la version actuelle de votre logiciel
if current_version in obsolete_versions:
# Ne rien faire si la version est obsolète
return
if float(latest_version) > float(current_version):
update_window = UpdateWindow(latest_version)
update_window.exec_()
except requests.exceptions.RequestException:
print("Impossible de récupérer la version la plus récente ou la liste des versions obsolètes.")
class ObsoleteVersionAlert(QDialog):
def __init__(self, version):
super().__init__()
self.setWindowTitle("Version obsolète")
self.setWindowIcon(QIcon("icon.png"))
self.setStyleSheet("background-color: white; color: #2b2b2b;")
layout = QVBoxLayout(self)
label = QLabel(f"Attention : La version actuelle ({version}) de Wedone Operate est obsolète et ne reçoit plus de support.\n\nCela peut entraîner des problèmes de sécurité et de fonctionnalité. Nous vous recommandons fortement de mettre à jour l'application vers la dernière version disponible.")
label.setStyleSheet("font-size: 14px; color: red; font-weight: bold;")
label.setWordWrap(True)
layout.addWidget(label)
download_button = QPushButton("Télécharger la dernière version")
download_button.clicked.connect(self.download_update)
download_button.setStyleSheet("font-size: 14px; background-color: #0672BC; color: white; font-weight: bold; border: 1px solid #0672BC; border-radius: 5px;")
layout.addWidget(download_button)
self.setLayout(layout)
def download_update(self):
webbrowser.open("https://github.com/WedoneOfficiel/Wedone-Operate/releases")
def check_for_security_patches(auto_patch):
if auto_patch:
patch_url = "https://wedoneofficiel.github.io/Gestion-Mises-A-Jour/Wedone-Operate/Patchs/Stable_4-1.txt"
obsolete_versions_url = "https://wedoneofficiel.github.io/Gestion-Mises-A-Jour/Wedone-Operate/versions-obsoletes-wedone-operate-stable.txt"
try:
response = requests.get(patch_url)
obsolete_response = requests.get(obsolete_versions_url)
if response.status_code == 200 and obsolete_response.status_code == 200:
latest_version = response.text.strip()
obsolete_versions = obsolete_response.text.strip().split('\n')
current_version = "4.1" # Remplacez par la version actuelle de votre logiciel
if current_version in obsolete_versions:
# Ne rien faire si la version est obsolète
return
if float(latest_version) > float(current_version):
update_window = UpdateWindow(latest_version)
update_window.exec_()
except requests.exceptions.RequestException:
print("Impossible de récupérer la version la plus récente ou la liste des versions obsolètes.")
class SecurityPatchWindow(QDialog):
def __init__(self, latest_patch):
super().__init__()
self.setWindowTitle("Mise à jour de sécurité disponible")
self.setWindowIcon(QIcon("icon.png"))
self.setStyleSheet("background-color: white; color: #2b2b2b;")
layout = QVBoxLayout(self)
label = QLabel(f"Un nouveau patch de sécurité est disponible pour Wedone Operate (version {latest_patch}) !\n\nIl est impératif de télécharger et d'installer ce patch pour garantir la sécurité et la stabilité de l'application.")
label.setStyleSheet("font-size: 14px;")
layout.addWidget(label)
buttons_layout = QHBoxLayout()
layout.addLayout(buttons_layout)
# Ajout d'un espace blanc entre les boutons Télécharger et Ignorer
buttons_layout.addStretch()
ignore_button = QPushButton(" Ignorer ")
ignore_button.clicked.connect(self.close)
ignore_button.setStyleSheet("font-size: 14px; background-color: #E7E3E3; color: #2b2b2b; border: 1px solid #E7E3E3; border-radius: 5px;")
buttons_layout.addWidget(ignore_button)
download_button = QPushButton(" Télécharger ")
download_button.clicked.connect(self.download_patch)
download_button.setStyleSheet("font-size: 14px; background-color: #0672BC; color: white; font-weight: bold; border: 1px solid #0672BC; border-radius: 5px;")
buttons_layout.addWidget(download_button)
self.setLayout(layout)
def download_patch(self):
webbrowser.open("https://github.com/WedoneOfficiel/Wedone-Operate/releases")
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setAttribute(Qt.AA_EnableHighDpiScaling)
auto_update = False
auto_patch = False
try:
with open("settings.json", "r") as file:
settings = json.load(file)
auto_update = settings["auto_update"]
auto_patch = settings["auto_patch"]
except FileNotFoundError:
pass
window = WedoneOperateApp()
window.show()
if auto_update:
check_for_updates(True)
if auto_patch:
check_for_security_patches(True)
sys.exit(app.exec_())