12
12
13
13
from PyQt5 .QtCore import Qt
14
14
15
+ from application .common import toolbox
15
16
from application .common .constants import FileModes
16
17
from application .common .decorators import timeit
17
18
from application .gui .widgets .file_select_widget import FileSelectWidget
@@ -33,22 +34,24 @@ def __init__(self, client: Operator, parent: QWidget = None) -> None:
33
34
34
35
self ._arg_name_edit : QLineEdit = None
35
36
self ._arg_value_edit : QWidget = None
36
- self ._arg_required : QCheckBox = None
37
37
self ._arg_file_mode_edit : QComboBox = None
38
38
self ._arg_equals_edit : QCheckBox = None
39
39
self ._arg_quotes_edit : QCheckBox = None
40
40
41
41
self ._submit_btn : QPushButton = QPushButton ("Submit" )
42
42
self ._reset_btn : QPushButton = QPushButton ("Reset" )
43
43
44
+ def closeEvent (self , event ):
45
+ if self ._parent :
46
+ self ._parent .start_timer ()
47
+
44
48
def init_ui (self , game_name : str ):
45
49
self ._layout .setAlignment (Qt .AlignTop )
46
50
47
51
self ._layout .addWidget (QLabel ("Add Argument:" ), 0 , 0 )
48
52
49
53
self ._arg_name_edit = QLineEdit ()
50
54
self ._arg_value_edit = QLineEdit ()
51
- self ._arg_required = QCheckBox ()
52
55
self ._arg_file_mode_edit = QComboBox ()
53
56
self ._arg_equals_edit = QCheckBox ()
54
57
self ._arg_quotes_edit = QCheckBox ()
@@ -64,9 +67,6 @@ def init_ui(self, game_name: str):
64
67
self ._layout .addWidget (QLabel ("Argument Value: " ), 2 , 0 )
65
68
self ._layout .addWidget (self ._arg_value_edit , 2 , 1 )
66
69
67
- self ._layout .addWidget (QLabel ("Required? " ), 3 , 0 )
68
- self ._layout .addWidget (self ._arg_required , 3 , 1 )
69
-
70
70
self ._layout .addWidget (QLabel ("File Mode Select: " ), 4 , 0 )
71
71
self ._layout .addWidget (self ._arg_file_mode_edit , 4 , 1 )
72
72
@@ -89,6 +89,19 @@ def init_ui(self, game_name: str):
89
89
90
90
self ._initialized = True
91
91
92
+ self .clear ()
93
+
94
+ def clear (self ):
95
+ self ._arg_name_edit .setText ("" )
96
+
97
+ if isinstance (self ._arg_value_edit , FileSelectWidget ):
98
+ self ._arg_value_edit .get_line_edit ().setText ("" )
99
+ else :
100
+ self ._arg_value_edit .setText ("" )
101
+ self ._arg_file_mode_edit .setCurrentIndex (0 )
102
+ self ._arg_equals_edit .setChecked (False )
103
+ self ._arg_quotes_edit .setChecked (False )
104
+
92
105
def update (self , game_name : str ):
93
106
self ._game_name = game_name
94
107
@@ -110,13 +123,16 @@ def _update_value_edit(self, file_mode_string: str) -> None:
110
123
self .adjustSize ()
111
124
112
125
def _submit_argument (self , game_name : str ) -> None :
126
+ # For error messages
127
+ message = QMessageBox ()
128
+
113
129
# Line edit
114
130
arg_name = self ._arg_name_edit .text ()
115
131
116
132
# combo
117
133
file_mode = self ._arg_file_mode_edit .currentIndex ()
118
134
119
- arg_required = self . _arg_required . isChecked ()
135
+ arg_required = False # User may never add a new required argument.
120
136
arg_equals = self ._arg_equals_edit .isChecked ()
121
137
arg_quotes = self ._arg_quotes_edit .isChecked ()
122
138
@@ -126,6 +142,15 @@ def _submit_argument(self, game_name: str) -> None:
126
142
file_mode == FileModes .FILE .value or file_mode == FileModes .DIRECTORY .value
127
143
):
128
144
arg_value = self ._arg_value_edit .get_line_edit ().text ()
145
+ arg_value = toolbox ._correct_path (arg_value )
146
+
147
+ # Check if all args are empty.
148
+ if arg_value == "" or arg_name == "" :
149
+ message .setText ("Error: Cannot create an empty argument!" )
150
+ message .exec ()
151
+ self .clear ()
152
+ self ._parent .start_timer ()
153
+ return
129
154
130
155
argument_id = self ._client .game .create_argument (
131
156
game_name ,
@@ -138,11 +163,13 @@ def _submit_argument(self, game_name: str) -> None:
138
163
use_quotes = arg_quotes ,
139
164
)
140
165
141
- message = QMessageBox ()
142
166
if argument_id == - 1 :
143
167
message .setText ("New Arg: There was an error creating the argument." )
144
168
else :
145
- message .setText ("Success!" )
169
+ message .setText ("Success! Please wait for user interface to update. " )
146
170
self .hide ()
171
+ self ._parent ._refresh_on_timer ()
172
+ self ._parent .start_timer ()
173
+ self .clear ()
147
174
148
175
message .exec ()
0 commit comments