Skip to content

Commit 328f800

Browse files
committed
fixed unable to delete last element from list, added vscode launch.json for debugging
1 parent 5ebe81d commit 328f800

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

.vscode/launch.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
8+
{
9+
"name": "Python: Run TODOlist.py",
10+
"type": "python",
11+
"request": "launch",
12+
"program": "${workspaceFolder}/TODOlist.py",
13+
"console": "integratedTerminal"
14+
}
15+
]
16+
}

model/model.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,25 @@ def write_to_todolist_file(self, **kwargs):
120120
# print(kwargs['action'], kwargs['indices'])
121121
if kwargs['action'] == 'delete_element' and len(kwargs['indices']) == 1:
122122
json_data['data'].pop(kwargs['indices'][0])
123+
print('what???????')
124+
else:
123125

124-
current_element = json_data['data'][kwargs['indices'][-1]]
125-
for i in range(len(kwargs['indices'])-1):
126-
if isinstance(current_element[0], list):
127-
current_element = current_element[1]
126+
current_element = json_data['data'][kwargs['indices'][-1]]
127+
for i in range(len(kwargs['indices'])-1):
128+
if isinstance(current_element[0], list):
129+
current_element = current_element[1]
128130

129-
# print(kwargs['action'], current_element, kwargs['indices'], list(reversed(kwargs['indices'][:-1])), i)
130-
if kwargs['action'] == 'delete_element' and i == len(kwargs['indices']) - 2:
131-
current_element.pop(list(reversed(kwargs['indices'][:-1]))[i])
132-
break
131+
# print(kwargs['action'], current_element, kwargs['indices'], list(reversed(kwargs['indices'][:-1])), i)
132+
if kwargs['action'] == 'delete_element' and i == len(kwargs['indices']) - 2:
133+
current_element.pop(list(reversed(kwargs['indices'][:-1]))[i])
134+
break
133135

134-
current_element = current_element[list(reversed(kwargs['indices'][:-1]))[i]]
136+
current_element = current_element[list(reversed(kwargs['indices'][:-1]))[i]]
135137

136-
if kwargs['action'] == 'toggle_task':
137-
current_element[1] = kwargs['value']
138-
elif kwargs['action'] == 'toggle_section':
139-
current_element[0][1] = kwargs['value']
138+
if kwargs['action'] == 'toggle_task':
139+
current_element[1] = kwargs['value']
140+
elif kwargs['action'] == 'toggle_section':
141+
current_element[0][1] = kwargs['value']
140142

141143

142144

view/widgetObjects.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def create_element(self, **kwargs):
129129

130130
def delete_element(self, action):
131131
parent_widget = action.parentWidget().parentWidget()
132-
print(parent_widget)
132+
print(parent_widget.children())
133133

134134
kwargs = {
135135
'indices': parent_widget.get_index_location(),
@@ -426,6 +426,9 @@ def delete_child_element(self, action):
426426
'indices': parent_widget.get_index_location(),
427427
'action': 'delete_element'
428428
}
429+
if len(kwargs['indices'] == 1):
430+
return
431+
429432
self.root.send_changed_data(kwargs)
430433

431434
self.sectionBody.sectionBodyLayout.removeWidget(parent_widget)

0 commit comments

Comments
 (0)