Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Adds caching of items, fixes layout in admin item view
  • Loading branch information
psde committed Nov 21, 2012
1 parent b060c8a commit c93742a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 41 deletions.
18 changes: 12 additions & 6 deletions adminItemWindow.py
Expand Up @@ -46,30 +46,36 @@ def rebuildItems(self):
self.items = CoffeeClient().getItems()

font = QtGui.QFont()
font.setPointSize(12)
font.setWeight(75)
font.setPointSize(10)
font.setWeight(50)
font.setBold(True)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)


itemPerRow = 2
itemIndex = 0
for item in self.items:
label = QtGui.QLabel(self)
label.setFont(font)
label.setText(item.desc + "\n" + str(item.price))
label.setSizePolicy(sizePolicy)
label.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignHCenter)
label.setStyleSheet("image: url(resource/items/" + str(item.id) + ".png);")
self.ui.itemLayout.addWidget(label, 0, item.id)
self.ui.itemLayout.addWidget(label, (itemIndex / itemPerRow) * 3 + 0, itemIndex % itemPerRow)

enabledCheckbox = QtGui.QCheckBox(self)
enabledCheckbox.setText("Enabled")
enabledCheckbox.setFont(font)
enabledCheckbox.setChecked(item.enabled)
self.ui.itemLayout.addWidget(enabledCheckbox, 1, item.id)
self.ui.itemLayout.addWidget(enabledCheckbox, (itemIndex / itemPerRow) * 3 + 1, itemIndex % itemPerRow)
item.enabledCheckbox = enabledCheckbox

soldoutCheckbox = QtGui.QCheckBox(self)
soldoutCheckbox.setText("Sold out")
soldoutCheckbox.setFont(font)
soldoutCheckbox.setChecked(item.sold_out)
self.ui.itemLayout.addWidget(soldoutCheckbox, 2, item.id)
self.ui.itemLayout.addWidget(soldoutCheckbox, (itemIndex / itemPerRow) * 3 + 2, itemIndex % itemPerRow)
item.soldoutCheckbox = soldoutCheckbox

itemIndex += 1
60 changes: 25 additions & 35 deletions mainWindow.py
Expand Up @@ -34,8 +34,6 @@ def __init__(self, cfg):

# Message Window
self.messageWindow = MessageWindow(self)
self.messageWindow.show("Just a moment...", 999999)
QtCore.QCoreApplication.processEvents()

# Windows
self.codeWindow = CodeWindow(self.messageWindow, self.redeemCode, self)
Expand All @@ -61,9 +59,6 @@ def __init__(self, cfg):
self.buttons = {}
self.items = {}

# Close message window, we are done
self.messageWindow.close()

# Timer for screensaver timeouts
self.screensaverTimer = QtCore.QTimer()
QtCore.QObject.connect(self.screensaverTimer, QtCore.SIGNAL("timeout()"), self.screensaverTimeout)
Expand Down Expand Up @@ -91,9 +86,9 @@ def rebuildItemTimeout(self):
self.rebuildItems()

def rebuildItems(self):
self.messageWindow.show("Items werden geupdated ...", 999999)
print "Rebuilding items...",

QtCore.QCoreApplication.processEvents()
self.messageWindow.show("Items werden geupdated ...", 60)
print "Rebuilding items..."
QtCore.QCoreApplication.processEvents()

# Remove all buttons
Expand All @@ -114,32 +109,31 @@ def rebuildItems(self):

items = sorted(self.client.getItems(), cmp=Item_Sort)

noItems = 0

for item in items:
if item.enabled == True:
noItems += 1

# Three items per row
noRows = math.ceil(float(noItems) / 3.0)

print noRows
print noItems

if items is None:
items = []

self.items = {}

columnIndex = 0
rowIndex = 0
itemPerRow = 2
itemIndex = 0
for item in items:
self.items[item.id] = item

print "Image for '" + str(item.id) + "...",
serverLastModified = float(self.client.getRequest("resource/item/lastModified/" + str(item.id)))
clientLastModified = 0
try:
clientLastModified = os.path.getctime("resource/items/" + str(item.id) + ".png")
except:
pass

# Download the item icon
f = open("resource/items/" + str(item.id) + ".png", "w+")
f.write(self.client.getRequest("resource/item/" + str(item.id)))
f.close()
if serverLastModified > clientLastModified:
f = open("resource/items/" + str(item.id) + ".png", "w+")
f.write(self.client.getRequest("resource/item/image/" + str(item.id)))
f.close()
print "downloaded."
else:
print "cached."

if item.enabled != True:
continue
Expand All @@ -158,16 +152,12 @@ def rebuildItems(self):
button.setText(item.desc + " / " + str(item.price) + " Bits")
button.setEnabled(True)

self.ui.dynamicButtonLayout.addWidget(button, rowIndex, columnIndex)
columnIndex += 1

if columnIndex >= noItems / noRows:
columnIndex = 0
rowIndex += 1
self.ui.dynamicButtonLayout.addWidget(button, itemIndex / itemPerRow, itemIndex % itemPerRow)
itemIndex += 1

button.clicked.connect(partial(self.pushItemClicked, item.id))
self.buttons[item.id] = button
QtCore.QCoreApplication.processEvents()
# QtCore.QCoreApplication.processEvents()

# Charge button...
self.chargeButton = QtGui.QPushButton(self.ui.centralwidget)
Expand All @@ -176,7 +166,7 @@ def rebuildItems(self):
self.chargeButton.setStyleSheet("image: url(resource/gold.png);")
self.chargeButton.setObjectName("Aufladen")
self.chargeButton.setText("Aufladen")
self.ui.dynamicButtonLayout.addWidget(self.chargeButton, 0, 1337, noRows, 1)
self.ui.dynamicButtonLayout.addWidget(self.chargeButton, 0, 1337, itemIndex / itemPerRow, 1)
self.chargeButton.clicked.connect(self.pushChargeClicked)

self.adminButton = QtGui.QPushButton(self.ui.centralwidget)
Expand All @@ -186,7 +176,7 @@ def rebuildItems(self):
self.adminButton.setObjectName("Admin")
self.adminButton.setText("Admin")
self.adminButton.setVisible(False)
self.ui.dynamicButtonLayout.addWidget(self.adminButton, 0, 1338, noRows, 1)
self.ui.dynamicButtonLayout.addWidget(self.adminButton, 0, 1338, itemIndex / itemPerRow, 1)
self.adminButton.clicked.connect(self.pushAdminClicked)

print "done"
Expand Down

0 comments on commit c93742a

Please sign in to comment.