-
Notifications
You must be signed in to change notification settings - Fork 4
/
InterfaceGTKGlade.py
229 lines (191 loc) · 11.6 KB
/
InterfaceGTKGlade.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
222
223
224
225
226
227
228
229
#!/usr/bin/env python
import sys, string
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
import gtk.glade
except:
sys.exit(1)
try:
import machine
except:
sys.exit(1)
class VendingMachineGTK:
MODEL_NAME = 0
MODEL_PRICE = 1
MODEL_AVAILABLE = 2
MODEL_QUANTITY = 3
MODEL_INVENTORY = 4
MODEL_LOC = 5
def __init__(self):
self.filename = "InterfaceGTKGlade.glade"
self.builder = gtk.Builder()
self.builder.add_from_file(self.filename)
self.window = self.builder.get_object("MainWindow")
#self.window.fullscreen()
dic = {
#"on_quantity_spinner_edited" : self.quantitySpinnerEdited,
"on_start_button_clicked" : self.startButtonClicked,
"on_page2_fwd_clicked" : self.page2FwdClicked,
"on_page2_back_clicked" : self.page2BackClicked,
"on_page3_back_clicked" : self.page3BackClicked,
"on_MainWindow_destroy" : self.quit,
"on_increment_button_clicked" : self.incrementButtonClicked,
"on_decrement_button_clicked" : self.decrementButtonClicked,
"on_quit_button_clicked" : self.quitButtonClicked,
"on_page3_quit_clicked" : self.purchaseClicked,
"on_purchase_button_clicked" : self.purchaseClicked
}
self.builder.connect_signals(dic)
# We just init on applicaiton start - and maybe when the user wants to totally empty the cart
self.initItemsView()
def wait_for_tag_to_start(self, widget):
'''
This function polls the RFID reader continuously until a uid is
obtained. If the uid is a verified EHC member then the user may
proceed. Otherwise, an error screen should be displayed.
'''
reader = machine.TagReader()
uid = reader.get()
user = User(uid) # also called User._verify()
if user.verified==1:
# go to the next screen
notebook1 = self.builder.get_object("notebook1")
notebook1.set_current_page(1)
else:
# go to an error screen
self.initItemsView()
notebook1.set_current_page(0) # todo: set the right page (not 0)
return
def purchaseClicked(self, widget):
'''
This function is called when the user clicks the 'complete purchase'
button. It uses the public methods from machine.py to instantiate a
Store.Purchase() object, populate its cart, and then complete all the
database, object, and hardware calls associated with vending the items.
'''
# Interface magic
notebook1 = self.builder.get_object("notebook1")
#notebook1.set_current_page(0)
# Initialize interface
purch = machine.Purchase(us.uid)
# Build the cart
for list_item in self.itemsListStore:
if list_item[self.MODEL_QUANTITY]!=0:
purch.add_to_cart(list_item[self.MODEL_LOC],
list_item[self.MODEL_QUANTITY])
# Vend the Purchase
purch.vend()
self.initItemsView()
notebook1.set_current_page(0)
return
def incrementButtonClicked(self, widget):
treeView = self.builder.get_object("items_tree_view")
(model, path) = treeView.get_selection().get_selected()
if self.itemsListStore[path][self.MODEL_AVAILABLE] > 0:
self.itemsListStore[path][self.MODEL_QUANTITY] = self.itemsListStore[path][self.MODEL_QUANTITY] + 1
self.itemsListStore[path][self.MODEL_AVAILABLE] = self.itemsListStore[path][self.MODEL_INVENTORY] - self.itemsListStore[path][self.MODEL_QUANTITY]
self.currentCostLabel = self.builder.get_object("current_cost_label")
#print self.currentCostLabel.get_label()
self.mytext = ('Current Cost: $%0.00f' % self.currentCost())
#print self.mytext
self.currentCostLabel.set_label(('Current Cost: $%0.2f' % self.currentCost()))
def decrementButtonClicked(self, widget):
treeView = self.builder.get_object("items_tree_view")
(model, path) = treeView.get_selection().get_selected()
if self.itemsListStore[path][self.MODEL_QUANTITY] > 0:
self.itemsListStore[path][self.MODEL_QUANTITY] = self.itemsListStore[path][self.MODEL_QUANTITY] - 1
self.itemsListStore[path][self.MODEL_AVAILABLE] = self.itemsListStore[path][self.MODEL_INVENTORY] - self.itemsListStore[path][self.MODEL_QUANTITY]
self.currentCostLabel = self.builder.get_object("current_cost_label")
#print self.currentCostLabel.get_label()
self.mytext = ('Current Cost: $%0.00f' % self.currentCost())
#print self.mytext
self.currentCostLabel.set_label(('Current Cost: $%0.2f' % self.currentCost()))
def startButtonClicked(self, widget):
notebook1 = self.builder.get_object("notebook1")
notebook1.set_current_page(1)
def page2FwdClicked(self, widget):
notebook1 = self.builder.get_object("notebook1")
self.initCheckoutView()
notebook1.set_current_page(2)
def page2BackClicked(self, widget):
notebook1 = self.builder.get_object("notebook1")
self.initItemsView()
notebook1.set_current_page(0)
def page3BackClicked(self, widget):
notebook1 = self.builder.get_object("notebook1")
notebook1.set_current_page(1)
def quitButtonClicked(self, widget):
notebook1 = self.builder.get_object("notebook1")
## for listItem in self.itemsListStore:
## if listItem[MODEL_QUANTITY] > 0:
## #print (listItem[0],listItem[1],listItem[2],listItem[3],listItem[4])
## listItem[MODEL_QUANTITY] = 0
## listItem[MODEL_AVAILABLE] = listItem[MODEL_INVENTORY]
self.initItemsView()
notebook1.set_current_page(0)
def quit(self, widget):
print 'QUIT'
sys.exit(0)
def currentCost(self):
cost = 0.00
for listItem in self.itemsListStore:
cost = cost + (listItem[self.MODEL_PRICE] * listItem[self.MODEL_QUANTITY])
return cost
def initCheckoutView(self):
#print (self.itemsListStore)
checkoutView = self.builder.get_object("checkoutView")
self.currentCostLabel2 = self.builder.get_object("current_cost_label2")
self.currentCostLabel2.set_label(('Current Cost: $%0.2f' % self.currentCost()))
finalString = ''
for listItem in self.itemsListStore:
if listItem[3] != 0:
#print (listItem[0],listItem[1],listItem[2],listItem[3])
#print ('Item:', listItem[0], 'PPU:', listItem[1], 'Quantity:', listItem[3])
outputString = 'Item:\t', str(listItem[0]), '\t PPU:\t', str(listItem[1]), '\tQuantity:\t', str(listItem[3])
finalString = finalString + ''.join( outputString )
finalString = finalString + ''.join('\n')
checkoutView.get_buffer().set_text(finalString)
def initItemsView(self):
self.itemsTreeView = self.builder.get_object("items_tree_view")
self.itemsListStore = self.builder.get_object("items_list_store")
self.currentCostLabel = self.builder.get_object("current_cost_label")
self.store = machine.Store()
items = machine.Item.listItems(self.store);
self.itemsListStore.clear()
for item in items:
#print item.info.values()
itemValues = item.info.values()
itemInfo = itemValues[5]
itemLoc = itemInfo[0]
itemCost = itemInfo[1]
itemQty = itemInfo[2]
itemName = itemInfo[3]
itemLongName = itemInfo[4]
itemDesc = itemInfo[5]
self.itemsListStore.append([itemName, itemCost, itemQty, 0, itemQty, itemLoc])
self.itemsTreeView.get_selection().select_path(0)
self.currentCostLabel.set_label(('Current Cost: $%0.2f' % 0))
if __name__ == "__main__":
## it = cli.Item(10, 5.00, 99, 'test10', 'long name', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam porttitor faucibus tempus. Nullam neque leo, ultricies sit amet rutrum quis, interdum et metus. In ac risus sapien, sed vestibulum felis. Maecenas luctus semper rutrum. In eget adipiscing mauris. Pellentesque ultricies mattis nunc eu luctus. In eget nisi neque. Ut sit amet dapibus mauris. Donec vel nulla nunc, non lacinia lacus. Pellentesque ac sapien lacinia arcu cursus dignissim. Suspendisse ut sapien sit amet.')
## it.save()
## it = cli.Item(11, 5.00, 99, 'test11', 'long name', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam porttitor faucibus tempus. Nullam neque leo, ultricies sit amet rutrum quis, interdum et metus. In ac risus sapien, sed vestibulum felis. Maecenas luctus semper rutrum. In eget adipiscing mauris. Pellentesque ultricies mattis nunc eu luctus. In eget nisi neque. Ut sit amet dapibus mauris. Donec vel nulla nunc, non lacinia lacus. Pellentesque ac sapien lacinia arcu cursus dignissim. Suspendisse ut sapien sit amet.')
## it.save()
## it = cli.Item(12, 5.00, 99, 'test12', 'long name', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam porttitor faucibus tempus. Nullam neque leo, ultricies sit amet rutrum quis, interdum et metus. In ac risus sapien, sed vestibulum felis. Maecenas luctus semper rutrum. In eget adipiscing mauris. Pellentesque ultricies mattis nunc eu luctus. In eget nisi neque. Ut sit amet dapibus mauris. Donec vel nulla nunc, non lacinia lacus. Pellentesque ac sapien lacinia arcu cursus dignissim. Suspendisse ut sapien sit amet.')
## it.save()
## it = cli.Item(13, 5.00, 99, 'test13', 'long name', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam porttitor faucibus tempus. Nullam neque leo, ultricies sit amet rutrum quis, interdum et metus. In ac risus sapien, sed vestibulum felis. Maecenas luctus semper rutrum. In eget adipiscing mauris. Pellentesque ultricies mattis nunc eu luctus. In eget nisi neque. Ut sit amet dapibus mauris. Donec vel nulla nunc, non lacinia lacus. Pellentesque ac sapien lacinia arcu cursus dignissim. Suspendisse ut sapien sit amet.')
## it.save()
## it = cli.Item(14, 5.00, 99, 'test14', 'long name', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam porttitor faucibus tempus. Nullam neque leo, ultricies sit amet rutrum quis, interdum et metus. In ac risus sapien, sed vestibulum felis. Maecenas luctus semper rutrum. In eget adipiscing mauris. Pellentesque ultricies mattis nunc eu luctus. In eget nisi neque. Ut sit amet dapibus mauris. Donec vel nulla nunc, non lacinia lacus. Pellentesque ac sapien lacinia arcu cursus dignissim. Suspendisse ut sapien sit amet.')
## it.save()
## it = cli.Item(15, 5.00, 99, 'test15', 'long name', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam porttitor faucibus tempus. Nullam neque leo, ultricies sit amet rutrum quis, interdum et metus. In ac risus sapien, sed vestibulum felis. Maecenas luctus semper rutrum. In eget adipiscing mauris. Pellentesque ultricies mattis nunc eu luctus. In eget nisi neque. Ut sit amet dapibus mauris. Donec vel nulla nunc, non lacinia lacus. Pellentesque ac sapien lacinia arcu cursus dignissim. Suspendisse ut sapien sit amet.')
## it.save()
us = machine.User(123456789, 'Zachary')
## us.save()
## us.verify()
hwg = VendingMachineGTK()
hwg.window.show()
gtk.main()