-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotepad_support.py
159 lines (124 loc) · 3.63 KB
/
notepad_support.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
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
#! /usr/bin/env python
#
# Support module generated by PAGE version 4.10
# In conjunction with Tcl version 8.6
# Jan 29, 2018 03:25:00 PM
import sys
import sqlite3
try:
from Tkinter import *
except ImportError:
from tkinter import *
try:
import ttk
py3 = 0
except ImportError:
import tkinter.ttk as ttk
py3 = 1
# connect with database 'data.db'
connection = sqlite3.connect("data.db")
# creates a cursor (pointer) to the data base
cursor = connection.cursor()
search = False
results = []
index = 0
def delete_button(p1):
global index
global results
global cursor
# fetch id of the current note
id = results[index][0]
sql_command = """ DELETE FROM notes WHERE id = {0}; """
sql_command = sql_command.format(id)
cursor.execute(sql_command)
connection.commit()
def create_button(p1):
"""
for creating a new database
"""
global cursor
sql_command = """
CREATE TABLE notes (
id INTEGER PRIMARY KEY,
title TEXT,
note TEXT);"""
try:
cursor.execute(sql_command)
w.errorOutput.configure(text="")
except:
w.errorOutput.configure(text="The database already exists")
def add_button(p1):
# for manipulating the data base
global cursor
global connection
if (len(w.inputTitle.get()) > 0 and len(w.inputNotice.get(1.0,END)) > 0):
w.errorOutput.configure(text="")
title = w.inputTitle.get()
note = w.inputNotice.get(1.0,END)
sql_command = """INSERT INTO notes (title,note) VALUES ("{0}","{1}"); """
sql_command = sql_command.format(title,note)
cursor.execute(sql_command)
connection.commit()
else:
w.errorOutput.configure(text="Please fill the fields. ")
def back_button(p1):
global search
global results
global index
w.errorOutput.configure(text="")
index -= 1
if (index >= 0 and index < len(results)):
w.outputNotice.delete(1.0,END)
w.outputNotice.insert(1.0,results[index][2])
def clear_button(p1):
"""
This function is for the clear button.
This will clear the notice-input field
"""
w.inputNotice.delete(1.0, END)
def exit_button(p1):
"""
function for the exit button.
this will exit the application.
"""
sys.exit(0)
def search_button(p1):
global cursor
global results
global index
w.errorOutput.configure(text="")
sql_command = """ SELECT * FROM notes WHERE title LIKE "%{0}%";"""
sql_command = sql_command.format(w.inputSearchTitle.get())
try:
cursor.execute(sql_command)
results = cursor.fetchall()
w.errorOutput.configure(text=str(len(results)) + " results")
index = 0
if (index >= 0 and index < len(results)):
w.outputNotice.delete(1.0,END)
w.outputNotice.insert(1.0,results[index][2])
except:
w.errorOutput.configure(text ="Please create at first a database.")
def next_button(p1):
global results
global index
index += 1
if (len(w.inputSearchTitle.get()) > 0):
if (index >= 0 and index < len(results)):
w.outputNotice.delete(1.0,END)
w.outputNotice.insert(1.0,results[index][2])
else:
w.errorOutput.configure(text="Please fill the search field. ")
def init(top, gui, *args, **kwargs):
global w, top_level, root
w = gui
top_level = top
root = top
def destroy_window():
# Function which closes the window.
global top_level
top_level.destroy()
top_level = None
if __name__ == '__main__':
import notepad
notepad.vp_start_gui()