Skip to content

Commit b90f414

Browse files
committed
Added Files
0 parents  commit b90f414

File tree

2 files changed

+167
-0
lines changed

2 files changed

+167
-0
lines changed

todolist.py

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import PySimpleGUI as sg
2+
3+
4+
SYMBOL_RIGHT ='►'
5+
SYMBOL_DOWN = '▼'
6+
7+
8+
opened1, opened2 = True, False
9+
10+
menu = [['Add', ['Task', 'Section']],
11+
['Lists', ['View', 'Add']
12+
]]
13+
14+
section_right_click = ['&Right', [['&Add', ['Task', 'Section', ]], 'Rename', 'Delete']]
15+
task_right_click = ['&Right', [['&Rename', 'Delete']]]
16+
17+
programValues = {'List': 'Daily'}
18+
19+
elementKeys = []
20+
21+
SectionsOpen = {}
22+
23+
24+
# data is pretty much everything from the to do lists, sections and tasks
25+
# it is a list of lists that shows each To do list
26+
# The first element of the to do lists is the name of the to do list
27+
# Dictionaries are checkboxes that say whether they are ticked or not.
28+
# lists are sections that contain dicitonaries
29+
# The first dictionary under in a list is the name of the section and whether it is closed or not
30+
31+
data = [
32+
['Daily', {'Methods homework': False, 'Physics': True}, [{'Section 1': True}, {'Learn python': False, 'Buy Furniture': True}], [{'Section 2': False}, {'Workout': False}]],
33+
['Project 1', {'Workout': False}]
34+
]
35+
36+
def collapse(layout, key, isVisible):
37+
"""
38+
Helper function that creates a Column that can be later made hidden, thus appearing "collapsed"
39+
:param layout: The layout for the section
40+
:param key: Key used to make this seciton visible / invisible
41+
:return: A pinned column that can be placed directly into your layout
42+
:rtype: sg.pin
43+
"""
44+
return sg.pin(sg.Column(layout, key=key, visible=isVisible))
45+
46+
def symbol(opened):
47+
if opened is True:
48+
return SYMBOL_DOWN
49+
else:
50+
return SYMBOL_RIGHT
51+
52+
53+
54+
55+
combo = []
56+
57+
def createCombo():
58+
for i in data:
59+
combo.append(i[0])
60+
combo.append(' Add List')
61+
#print(combo)
62+
63+
def createCheckBox(name, checked):
64+
return [sg.Checkbox(name, default=checked)]
65+
66+
def createSection(header, opened, content):
67+
listLayout.append([sg.T(symbol(opened), enable_events=True, k=f'{header} ARROW'), sg.T(header, enable_events=True, k=f'{header}', right_click_menu=section_right_click)])
68+
listLayout.append([collapse(content, f'{header} CONTENT', opened)])
69+
elementKeys.append(f'{header}')
70+
SectionsOpen[f'{header}'] = opened
71+
72+
73+
74+
def createListLayout(theList):
75+
for i in data:
76+
if i[0] is theList:
77+
contents = i
78+
for content in contents:
79+
if type(content) is dict:
80+
for key, value in content.items():
81+
listLayout.append(createCheckBox(key, value))
82+
83+
if type(content) is list:
84+
for key, value in content[0].items():
85+
header = key
86+
opened = value
87+
88+
for contentInSection in content:
89+
sectionContent = []
90+
91+
if type(contentInSection) is dict and content.index(contentInSection) != 0:
92+
for key, value in contentInSection.items():
93+
sectionContent.append(createCheckBox(key, value))
94+
95+
#print(sectionContent)
96+
createSection(header, opened, sectionContent)
97+
#print(listLayout)
98+
#print(dw)
99+
100+
101+
102+
103+
section1 = [
104+
[sg.Checkbox('Learn python')],
105+
[sg.Checkbox('Buy Furniture')]
106+
]
107+
108+
section2 = [[sg.Checkbox('Workout')]
109+
]
110+
111+
# The layout that has all the sections and tasks
112+
listLayout = []
113+
114+
# REFERENCE LAYOUT
115+
dw = [
116+
[sg.Checkbox('Methods homework')],
117+
#### Section 1 part ####
118+
[sg.T(symbol(opened1), enable_events=True, k='-OPEN SEC1-'), sg.T('Section 1', enable_events=True, k='-OPEN SEC1-TEXT', right_click_menu=section_right_click)],
119+
[collapse(section1, '-SEC1-', opened1)],
120+
#### Section 2 part ####
121+
[sg.T(symbol(opened2), enable_events=True, k='-OPEN SEC2-'), sg.T('Section 2', enable_events=True, k='-OPEN SEC2-TEXT', right_click_menu=section_right_click)],
122+
[collapse(section2, '-SEC2-', opened2)]
123+
]
124+
125+
createListLayout(programValues['List'])
126+
createCombo()
127+
128+
layout = [
129+
[sg.Menu(menu)],
130+
[sg.Combo(combo,default_value=combo[0] , size=(100, 1), key='-COMBO-', readonly=True)],
131+
[sg.Column(listLayout,size=(300,400), key='-LB-', scrollable=True, vertical_scroll_only=True, pad=((0,5),(10,10)))],
132+
[sg.Button('Add Task', image_size=(130,40), pad=((5,0),(0,10)), image_filename='white.png', border_width=0, button_color=('black', 'black')), sg.Button('Add Section', image_size=(130,40), pad=((5,0),(0,10)), image_filename='white.png', border_width=0, button_color=('black', 'black'))]
133+
]
134+
135+
window = sg.Window('To Do List', layout, size=(300,500))
136+
print(elementKeys)
137+
138+
while True: # Event Loop
139+
event, values = window.read()
140+
print(event, values)
141+
if event == sg.WIN_CLOSED or event == 'Exit':
142+
break
143+
144+
if 'ARROW' in event:
145+
eventName = event.replace(' ARROW', '')
146+
SectionsOpen[eventName] = not SectionsOpen[eventName]
147+
window[f'{event}'].update(SYMBOL_DOWN if SectionsOpen[eventName] else SYMBOL_RIGHT)
148+
window[f'{eventName} CONTENT'].update(visible=SectionsOpen[eventName])
149+
150+
if event in elementKeys:
151+
SectionsOpen[event] = not SectionsOpen[event]
152+
window[f'{event} ARROW'].update(SYMBOL_DOWN if SectionsOpen[event] else SYMBOL_RIGHT)
153+
window[f'{event} CONTENT'].update(visible=SectionsOpen[event])
154+
155+
if event.startswith('-OPEN SEC1-'):
156+
opened1 = not opened1
157+
window['-OPEN SEC1-'].update(SYMBOL_DOWN if opened1 else SYMBOL_RIGHT)
158+
window['-SEC1-'].update(visible=opened1)
159+
160+
if event.startswith('-OPEN SEC2-'):
161+
opened2 = not opened2
162+
window['-OPEN SEC2-'].update(SYMBOL_DOWN if opened2 else SYMBOL_RIGHT)
163+
window['-SEC2-'].update(visible=opened2)
164+
165+
166+
167+
window.close()

white.png

5.77 KB
Loading

0 commit comments

Comments
 (0)