-
Notifications
You must be signed in to change notification settings - Fork 0
/
Speedy Shopper with GUI.py
145 lines (116 loc) · 5.01 KB
/
Speedy Shopper with GUI.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
import time
import os
import wx
grocery_list = []
time_completed = 0
requested_aisles = []
requested_aisles_dict = {}
aisles = {}
aisles_full = {}
def initialize(file):
global aisles
global aisles_full
data = open(file).read().splitlines()
aisle_designator = 0
for line in data:
if line == '':
aisle_designator += 1
elif line == 'hbc':
aisle_designator = 'hbc'
elif line == 'front':
aisle_designator = 'front'
elif line == 'back':
aisle_designator = 'back'
elif line == 'pharmacy':
aisle_designator = 'pharmacy'
else:
aisles[line.lower()] = 'aisle ' + str(aisle_designator)
aisles_full = aisles
class Output(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, id=wx.ID_ANY, title=u'Output Frame', pos=wx.DefaultPosition, size=wx.Size(500, 300), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
bSizer1 = wx.BoxSizer(wx.VERTICAL)
bSizer2 = wx.BoxSizer(wx.VERTICAL)
self.wait_pls = wx.StaticText(self, wx.ID_ANY, u"Gathering Information", wx.DefaultPosition, wx.DefaultSize, 0)
self.wait_pls.Wrap(-1)
bSizer2.Add(self.wait_pls, 0, wx.ALIGN_CENTER | wx.ALL, 5)
self.gauge = wx.Gauge(self, wx.ID_ANY, 100, wx.DefaultPosition, wx.DefaultSize, wx.GA_HORIZONTAL)
self.gauge.SetValue(0)
bSizer2.Add(self.gauge, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 5)
bSizer1.Add(bSizer2, 1, wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, 5)
self.SetSizer(bSizer1)
self.Layout()
self.Centre(wx.BOTH)
class Home(wx.Frame):
global grocery_list
def __init__(self):
wx.Frame.__init__(self, None, id=wx.ID_ANY, title=u'speedy shop', pos=wx.DefaultPosition, size=wx.Size(500, 300), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
bSizer1 = wx.BoxSizer(wx.VERTICAL)
bSizer2 = wx.BoxSizer(wx.VERTICAL)
self.welcome = wx.StaticText(self, wx.ID_ANY, u"Welcome to speedy shopper program", wx.DefaultPosition, wx.DefaultSize, 0)
self.welcome.Wrap(-1)
bSizer2.Add(self.welcome, 0, wx.ALIGN_CENTER | wx.ALL, 5)
bSizer3 = wx.BoxSizer(wx.VERTICAL)
self.instructions = wx.StaticText(self, wx.ID_ANY, u"Add Items to Grocery List", wx.DefaultPosition, wx.DefaultSize, 0)
self.instructions.Wrap(-1)
bSizer3.Add(self.instructions, 0, wx.ALIGN_CENTER | wx.ALL, 5)
self.text_box = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0)
bSizer3.Add(self.text_box, 0, wx.ALIGN_CENTER | wx.ALL, 5)
self.append_button = wx.Button(self, wx.ID_ANY, u"Add To List", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer3.Add(self.append_button, 0, wx.ALIGN_CENTER | wx.ALL, 5)
self.search_button = wx.Button(self, wx.ID_ANY, u"Search Grocery List", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer3.Add(self.search_button, 0, wx.ALIGN_CENTER | wx.ALL, 5)
bSizer2.Add(bSizer3, 1, wx.ALIGN_CENTER | wx.EXPAND, 5)
bSizer1.Add(bSizer2, 1, wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, 5)
self.SetSizer(bSizer1)
self.Layout()
self.Centre(wx.BOTH)
# Connect Events
self.append_button.Bind(wx.EVT_BUTTON, self.append_grocery)
self.text_box.Bind(wx.EVT_TEXT_ENTER, self.append_grocery)
self.search_button.Bind(wx.EVT_BUTTON, self.search)
# Connect Events
def __del__(self):
pass
# Virtual event handlers, override them in your derived class
def load_outFrame(self):
wx.Frame.Close(self)
def append_grocery(self, event):
item = self.text_box.GetLineText(0)
grocery_list.append(item.lower())
self.text_box.Clear()
def search(self, event):
# self.frame.Show()
search(grocery_list)
wx.Exit()
def onClose(self, event):
self.Close()
def scan_reg(item):
print("Running: " + "[PID: " + str(os.getpid()) + "]")
for grocery in aisles_full:
if grocery == item:
print(grocery)
print(aisles_full[grocery] + " From [reg]")
if aisles_full[grocery] not in requested_aisles_dict: # take this out for multiple items in aisle
requested_aisles_dict[aisles_full[grocery]] = []
(requested_aisles_dict[aisles_full[grocery]]).append(item)
print("Finished: " + "[PID: " + str(os.getpid()) + "]")
def search(items):
time.sleep(0.5)
output = Output()
global time_completed
start_time = time.time()
for i in items:
scan_reg(i)
time_completed = time.time() - start_time
if __name__ == '__main__':
initialize('item_locations.txt')
app = wx.App()
frame1 = Home()
frame1.Show()
# frame2 = Output().Show()
app.MainLoop()
print(requested_aisles_dict) # Print what item from grocery list is in the aisle
print("Time Completed: " + str(time_completed))