-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog_item_edit.py
83 lines (63 loc) · 3.12 KB
/
dialog_item_edit.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
import os
from PySide6.QtCore import *
from PySide6.QtWidgets import QWidget, QLineEdit, QPushButton, QHBoxLayout, QFormLayout, QFileDialog, QMessageBox
from games_controller import Game
from icons import Icons
class ItemEditDialog(QWidget):
game: Game = None
def __init__(self, parent: QWidget, game: Game = None) -> None:
super().__init__(parent, Qt.WindowType.Dialog)
self.setWindowIcon(Icons.appIcon())
self.setWindowModality(Qt.WindowModality.WindowModal)
self.setMinimumWidth(600)
self.game = game
if game:
self.setWindowTitle(f'Modification du jeu - {game.name}')
else:
self.setWindowTitle('Ajout d\'un nouveau jeu')
self.game_name_editbox = QLineEdit()
if self.game: self.game_name_editbox.setText(self.game.name)
self.game_path_editbox = QLineEdit()
if self.game: self.game_path_editbox.setText(self.game.path)
self.game_path_browse = QPushButton('...')
self.game_path_browse.setFixedWidth(20)
self.game_path_browse.clicked.connect(self._browseClicked)
self.game_path_layout = QHBoxLayout()
self.game_path_layout.addWidget(self.game_path_editbox)
self.game_path_layout.addWidget(self.game_path_browse)
self.game_arguments_editbox = QLineEdit()
if self.game: self.game_arguments_editbox.setText(self.game.args)
self.save_button = QPushButton(Icons.saveIcon(), 'Sauvegarder')
font = self.save_button.font()
font.setBold(True)
self.save_button.setFont(font)
self.save_button.clicked.connect(self._saveClicked)
self.cancel_button = QPushButton(Icons.quitIcon(), 'Annuler')
self.cancel_button.clicked.connect(lambda: self.close())
self.buttons_layout = QHBoxLayout()
self.buttons_layout.addWidget(self.save_button)
self.buttons_layout.addWidget(self.cancel_button)
layout = QFormLayout(self)
layout.setLabelAlignment(Qt.AlignmentFlag.AlignRight)
layout.addRow('Nom du jeu:', self.game_name_editbox)
layout.addRow('Chemin du jeu:', self.game_path_layout)
layout.addRow('Argument(s) supplémentaire(s):', self.game_arguments_editbox)
layout.addRow(self.buttons_layout)
self.setLayout(layout)
def _browseClicked(self):
file = QFileDialog.getOpenFileName(self.parent(), dir=os.path.abspath(self.game_path_editbox.text()), filter='Exécutables (*.exe)')[0]
if file != "": self.game_path_editbox.setText(file.replace('/', '\\'))
def _saveClicked(self):
if self.game_name_editbox.text() != '' and self.game_path_editbox.text() != '':
if os.path.exists(self.game_path_editbox.text()):
if self.game:
self.game.name = self.game_name_editbox.text()
self.game.path = self.game_path_editbox.text()
self.game.args = self.game_arguments_editbox.text()
else:
self.game = Game(self.game_name_editbox.text(), self.game_path_editbox.text(), self.game_arguments_editbox.text())
self.close()
else:
QMessageBox.critical(self, 'ERREUR', 'Le fichier n\'existe pas! Veuillez corriger et réessayer')
else:
QMessageBox.critical(self, 'ERREUR', 'Un nom et un chemin valide doivent être remplis avant de poursuivre.')