-
Notifications
You must be signed in to change notification settings - Fork 0
/
management.py
221 lines (190 loc) · 7.63 KB
/
management.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
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
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import pandas as pd
import webbrowser as wb
import tkinter as tk
from tkinter import messagebox
from tkinter import Frame
import os
from pandastable.core import Table
from pandastable.data import TableModel
from configparser import ConfigParser
script_dir = os.path.dirname(__file__)
config = ConfigParser()
config.read(os.path.join(script_dir, 'config.ini'))
wb.register('chrome', None, wb.BackgroundBrowser(config.get('Dir', 'Chrome_Dir')))
excel_dir = config.get('Dir', 'Excel_Dir')
data = pd.read_excel(excel_dir, sheet_name = 'Sheet1')
track17 = 'https://t.17track.net/en#nums='
fields = 'Names', 'Address', 'Tracking Number', 'Wechat Number', 'Note'
class MyTable(Table):
def __init__(self, parent=None, **kwargs):
Table.__init__(self, parent, **kwargs)
return
def make_table(frame, **kwds):
df = data
pt = MyTable(frame, dataframe=df, **kwds )
pt.show()
return pt
def test1():
t = tk.Toplevel()
fr = Frame(t)
fr.pack(fill=tk.BOTH,expand=1)
pt = make_table(fr)
return
def main_menu():
menu_window.mainloop()
def add_customer_window():
root = tk.Tk()
ents = makeform(root, fields)
root.after(1, lambda: root.focus_force())
ents[0][1].focus_set()
root.bind('<Return>', (lambda event, e=ents: add_customer(root, e)))
root.bind('<Escape>', (lambda event : root.destroy()))
b1 = tk.Button(root, text='Save',
command=(lambda e=ents: add_customer(root, e)))
b1.pack(side=tk.LEFT, padx=5, pady=5)
b2 = tk.Button(root, text='Quit', command=root.destroy)
b2.pack(side=tk.LEFT, padx=5, pady=5)
root.mainloop()
return
def add_customer(root, entries):
dict_ = {}
for entry in entries:
field = entry[0]
text = entry[1].get()
dict_.update({field : text})
data.loc[data.index.max()+1] = dict_
data.to_excel(excel_dir, sheet_name = 'Sheet1', index=False)
messagebox.showinfo('Info', 'Saved!')
root.destroy()
def makeform(root, fields):
entries = []
for field in fields:
row = tk.Frame(root)
lab = tk.Label(row, width=15, text=field, anchor='w')
ent = tk.Entry(row, width=35)
row.pack(side=tk.TOP, fill=tk.X, padx=5, pady=5)
lab.pack(side=tk.LEFT)
ent.pack(side=tk.RIGHT, expand=tk.YES, fill=tk.X)
entries.append((field, ent))
return entries
def remove_customer_window():
root = tk.Tk()
ents = makeform(root, ['Name'])
root.after(1, lambda: root.focus_force())
ents[0][1].focus_set()
root.bind('<Return>', (lambda event, e=ents: remove_customer(root, e)))
root.bind('<Escape>', (lambda event : root.destroy()))
b1 = tk.Button(root, text='Remove',
command=(lambda e=ents: remove_customer(root, e)))
b1.pack(side=tk.LEFT, padx=5, pady=5)
b2 = tk.Button(root, text='Quit', command=root.destroy)
b2.pack(side=tk.LEFT, padx=5, pady=5)
root.mainloop()
return
def remove_customer(root, e):
data.drop(data.index[data['Names'] == e[0][1].get()], inplace=True)
data.to_excel(excel_dir, sheet_name = 'Sheet1', index=False)
messagebox.showinfo('Info', 'Removed!')
root.destroy()
def track_package_window():
root = tk.Tk()
ents = makeform(root, ['Name'])
root.after(1, lambda: root.focus_force())
ents[0][1].focus_set()
root.bind('<Return>', (lambda event, e=ents: track_package(root, e)))
root.bind('<Escape>', (lambda event : root.destroy()))
b1 = tk.Button(root, text='Track',
command=(lambda e=ents: track_package(root, e)))
b1.pack(side=tk.LEFT, padx=5, pady=5)
b2 = tk.Button(root, text='Quit', command=root.destroy)
b2.pack(side=tk.LEFT, padx=5, pady=5)
root.mainloop()
return
def track_package(root, e):
user_index = data.index[data['Names'] == e[0][1].get()].tolist()
tracking_num = data.loc[user_index[0]]['Tracking Number']
wb.get('chrome').open(track17 + tracking_num)
root.destroy()
def display_data():
root = tk.Tk()
f = Frame(root)
root.geometry('1000x600+200+100')
root.bind('<Escape>', (lambda event : root.destroy()))
f.pack(fill=tk.BOTH,expand=1)
pt = make_table(f)
bp = Frame(root)
bp.pack(side=tk.TOP)
def setting_window():
root = tk.Tk()
root.geometry('600x100')
ents = makeform(root, ['Chomre Path', 'Data Sheet Path'])
ents[0][1].insert(0, config.get('Dir', 'Chrome_Dir'))
ents[1][1].insert(0, excel_dir)
root.after(1, lambda: root.focus_force())
ents[0][1].focus_set()
root.bind('<Return>', (lambda event, e=ents: reset_dir(root, e)))
root.bind('<Escape>', (lambda event : root.destroy()))
b1 = tk.Button(root, text='Set',
command=(lambda e=ents: reset_dir(root, e)))
b1.pack(side=tk.LEFT, padx=5, pady=5)
b2 = tk.Button(root, text='Quit', command=root.destroy)
b2.pack(side=tk.LEFT, padx=5, pady=5)
root.mainloop()
return
def reset_dir(root, e):
config.set('Dir', 'Chrome_Dir', e[0][1].get())
config.set('Dir', 'Excel_Dir', e[1][1].get())
chrome = wb.register('chrome', None, wb.BackgroundBrowser(e[0][1].get()))
excel_dir = e[1][1].get()
with open(os.path.join(script_dir, 'config.ini'), 'w') as configfile:
config.write(configfile)
messagebox.showinfo('Info', 'Saved!')
root.destroy()
def edit_customer_window():
root = tk.Tk()
ents = makeform(root, fields)
root.after(1, lambda: root.focus_force())
ents[0][1].focus_set()
root.bind('<Return>', (lambda event, e=ents: edit_customer(root, e)))
root.bind('<Escape>', (lambda event : root.destroy()))
b1 = tk.Button(root, text='Save',
command=(lambda e=ents: edit_customer(root, e)))
b1.pack(side=tk.LEFT, padx=5, pady=5)
b2 = tk.Button(root, text='Quit', command=root.destroy)
b2.pack(side=tk.LEFT, padx=5, pady=5)
root.mainloop()
return
def edit_customer(root, entries):
dict_ = {}
user_index = data.index[data['Names'] == entries[0][1].get()].tolist()
for entry in entries:
field = entry[0]
text = entry[1].get()
dict_.update({field : text})
for k, v in dict_.items():
if v == '':
dict_[k] = data.loc[user_index[0]][k]
data.loc[user_index[0]] = list(dict_.values())
data.to_excel(excel_dir, sheet_name = 'Sheet1', index=False)
messagebox.showinfo('Info', 'Saved!')
root.destroy()
menu_window = tk.Tk()
menu_window.geometry('250x280')
ac_button = tk.Button(menu_window, text = 'Add Customer', command = add_customer_window)
ed_button = tk.Button(menu_window, text = 'Edit Customer', command = edit_customer_window)
rm_button = tk.Button(menu_window, text = 'Remove Customer', command = remove_customer_window)
tr_button = tk.Button(menu_window, text = 'Track Package', command = track_package_window)
dis_button = tk.Button(menu_window, text = 'Display Data', command = display_data)
set_button = tk.Button(menu_window, text = 'Setting', command = setting_window)
ac_button.pack(side=tk.TOP, fill=tk.X, expand=tk.NO, padx=10, pady=10)
ed_button.pack(side=tk.TOP, fill=tk.X, expand=tk.NO, padx=10, pady=10)
rm_button.pack(side=tk.TOP, fill=tk.X, expand=tk.NO, padx=10, pady=10)
tr_button.pack(side=tk.TOP, fill=tk.X, expand=tk.NO, padx=10, pady=10)
dis_button.pack(side=tk.TOP, fill=tk.X, expand=tk.NO, padx=10, pady=10)
set_button.pack(side=tk.TOP, fill=tk.X, expand=tk.NO, padx=10, pady=10)
main_menu()