-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProjects-Tasks.py
More file actions
351 lines (253 loc) · 10.5 KB
/
Copy pathProjects-Tasks.py
File metadata and controls
351 lines (253 loc) · 10.5 KB
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
from tkinter import *
import sqlite3
import tkinter.scrolledtext as tkst
t_name_editor = NONE
t_start_date_editor = NONE
t_type_editor = NONE
editor = NONE
var = NONE
conn = sqlite3.connect('db1.py')
c = conn.cursor()
c.execute("""CREATE TABLE projects (
name text,
start_date real,
type text
)""")
c.execute("""CREATE TABLE tasks (
instruction text,
due_date real,
to_project integer
)""")
class Page(Frame):
def __init__(self, *args, **kwargs):
Frame.__init__(self, *args, **kwargs)
def show(self):
self.lift()
class Page1(Page):
def __init__(self, *args, **kwargs):
Page.__init__(self, *args, **kwargs)
# create Text boxes
self.t_name = Entry(self, width=30)
self.t_name.grid(row=0, column=1, padx=20, pady=(35, 0))
self.t_start_date = Entry(self, width=30)
self.t_start_date.grid(row=1, column=1, padx=20)
self.t_type = Entry(self, width=30)
self.t_type.grid(row=2, column=1, padx=20)
self.delete_box = Entry(self, width=30)
self.delete_box.grid(row=9, column=1, pady=5)
# create Lables for text boxes
self.t_name_lable = Label(self, text="Name of the Project").grid(
row=0, column=0, pady=(35, 0))
self.t_start_date_lable = Label(
self, text="Start date").grid(row=1, column=0)
self.t_type_lable = Label(self, text="Type").grid(row=2, column=0)
self.delete_box_lable = Label(self, text=" Choose Project ID").grid(
row=9, column=0, pady=5)
# create Buttons
self.add_btn = Button(self, text="Add Project",
command=self.create_project)
self.add_btn.grid(row=6, column=0, columnspan=2,
pady=10, padx=10, ipadx=139)
self.show_db_btn = Button(
self, text="Show Project Database", command=self.query)
self.show_db_btn.grid(row=13, column=0, columnspan=2,
pady=10, padx=10, ipadx=112)
self.delete_btn = Button(self, text="Delete Project",
command=self.remove_project)
self.delete_btn.grid(row=10, column=0, columnspan=2,
pady=10, padx=10, ipadx=135)
self.edit_btn = Button(self, text="Update Project",
command=self.update_project)
self.edit_btn.grid(row=11, column=0, columnspan=2,
pady=10, padx=10, ipadx=133)
def create_project(self):
conn = sqlite3.connect('db1.py')
c = conn.cursor()
c.execute("INSERT INTO projects VALUES (:name, :start_date,:type)",
{
'name': self.t_name.get(),
'start_date': self.t_start_date.get(),
'type': self.t_type.get()
})
conn.commit()
conn.close()
self.t_name.delete(0, END)
self.t_start_date.delete(0, END)
self.t_type.delete(0, END)
def query(self):
query = Tk()
query.geometry("375x180")
conn = sqlite3.connect('db1.py')
c = conn.cursor()
c.execute("SELECT *,oid FROM projects")
records = c.fetchall()
print_records = ''
for record in records:
print_records += str(record) + "\n"
query_lable = Label(query, text=print_records)
query_lable.grid(row=0, column=0, padx=95, pady=10)
conn.commit()
conn.close()
def remove_project(self):
conn = sqlite3.connect('db1.py')
c = conn.cursor()
c.execute("DELETE from projects WHERE oid = " + self.delete_box.get())
self.delete_box.delete(0, END)
conn.commit()
conn.close()
def update_project(self):
global t_name_editor
global t_start_date_editor
global t_type_editor
global editor
editor = Tk()
editor.geometry("375x180")
conn = sqlite3.connect('db1.py')
c = conn.cursor()
project_id = self.delete_box.get()
c.execute("SELECT * FROM projects WHERE oid = " + project_id)
records = c.fetchall()
# create Text boxes
t_name_editor = Entry(editor, width=30)
t_name_editor.grid(row=0, column=1, padx=20, pady=(10, 0))
t_start_date_editor = Entry(editor, width=30)
t_start_date_editor.grid(row=1, column=1, padx=20)
t_type_editor = Entry(editor, width=30)
t_type_editor.grid(row=2, column=1, padx=20)
# create Lables for text boxes
t_name_lable_editor = Label(editor, text="Name of the Project").grid(
row=0, column=0, pady=(10, 0))
t_start_date_lable_editor = Label(
editor, text="Start date").grid(row=1, column=0)
t_type_lable_editor = Label(editor, text="Type").grid(row=2, column=0)
for record in records:
t_name_editor.insert(0, record[0])
t_start_date_editor.insert(0, record[1])
t_type_editor.insert(0, record[2])
save_btn = Button(editor, text="Save Record",
command=self.edit_project)
save_btn.grid(row=4, column=0, columnspan=2,
pady=10, padx=10, ipadx=133)
def edit_project(self):
conn = sqlite3.connect('db1.py')
c = conn.cursor()
project_id = self.delete_box.get()
c.execute("""UPDATE projects SET
name = :name,
start_date = :start_date,
type = :type
WHERE oid = :oid""",
{
'name': t_name_editor.get(),
'start_date': t_start_date_editor.get(),
'type': t_type_editor.get(),
'oid': project_id
})
conn.commit()
conn.close()
editor.destroy()
class Page2(Page):
def __init__(self, *args, **kwargs):
Page.__init__(self, *args, **kwargs)
conn = sqlite3.connect('db1.py')
c = conn.cursor()
c.execute("SELECT name FROM projects")
list1 = c.fetchall()
if not list1:
list1.append("No Projects yet")
global var
# create Text boxes
self.t_instruction = tkst.ScrolledText(self, height=5, width=22)
self.t_instruction.grid(row=0, column=1, padx=0, pady=(15, 0))
self.t_due_date = Entry(self, width=32)
self.t_due_date.grid(row=1, column=1, padx=20)
self.delete_box = Entry(self, width=32)
self.delete_box.grid(row=4, column=1, pady=5)
var = StringVar()
var.set("Project Name")
self.which_project = OptionMenu(self, var, *list1)
self.which_project.grid(row=2, column=1, padx=20,)
# create Lables for text boxes
self.t_instruction_lable = Label(self, text="Task Instructions").grid(
row=0, column=0, padx=20, pady=(15, 0))
self.t_due_date_lable = Label(
self, text="Due date").grid(row=1, column=0, pady=10)
self.t_which_project_lable = Label(
self, text="Chose Project").grid(row=2, column=0, pady=10)
self.delete_box_lable = Label(self, text=" Choose Task ID").grid(
row=4, column=0, pady=5)
# create Buttons
self.add_btn = Button(self, text="Add Task",
command=self.add_task)
self.add_btn.grid(row=3, column=0, columnspan=2,
pady=10, padx=10, ipadx=136)
self.show_db_btn = Button(
self, text="Show Task Database", command=self.query2)
self.show_db_btn.grid(row=6, column=0, columnspan=2,
pady=10, padx=10, ipadx=112)
self.delete_btn = Button(self, text="Delete Task",
command=self.remove_task)
self.delete_btn.grid(row=5, column=0, columnspan=2,
pady=10, padx=10, ipadx=135)
conn.commit()
conn.close()
def add_task(self):
conn = sqlite3.connect('db1.py')
c = conn.cursor()
c.execute("INSERT INTO tasks VALUES (:instruction, :due_date,:to_project)",
{
'instruction': self.t_instruction.get(1.0, END),
'due_date': self.t_due_date.get(),
'to_project': var.get()
})
conn.commit()
conn.close()
self.t_instruction.delete(1.0, END)
self.t_due_date.delete(0, END)
def query2(self):
query2 = Tk()
query2.geometry("375x180")
conn = sqlite3.connect('db1.py')
c = conn.cursor()
c.execute("SELECT *,oid FROM tasks")
records = c.fetchall()
print_records = ''
for record in records:
print_records += str(record) + "\n"
query_lable = Label(query2, text=print_records)
query_lable.grid(row=0, column=0, padx=60, pady=10)
conn.commit()
conn.close()
def remove_task(self):
conn = sqlite3.connect('db1.py')
c = conn.cursor()
c.execute("DELETE from tasks WHERE oid = " + self.delete_box.get())
self.delete_box.delete(0, END)
conn.commit()
conn.close()
class MainView(Frame):
def __init__(self, *args, **kwargs):
Frame.__init__(self, *args, **kwargs)
p1 = Page1(self)
p2 = Page2(self)
buttonframe = Frame(self)
container = Frame(self)
buttonframe.pack(side="top", fill="x", expand=False)
container.pack(side="top", fill="both", expand=True)
p1.place(in_=container, x=0, y=0, relwidth=1, relheight=1)
p2.place(in_=container, x=0, y=0, relwidth=1, relheight=1)
b1 = Button(buttonframe, text="Projects", command=p1.lift)
b2 = Button(buttonframe, text="Tasks", command=p2.lift)
b1.pack(side="left")
b2.pack(side="left")
p1.show()
if __name__ == "__main__":
root = Tk()
main = MainView(root)
main.pack(side="top", fill="both", expand=True)
root.wm_geometry("375x500")
root.mainloop()
# commit changes
conn.commit()
# close connection
conn.close()