Skip to content
Snippets Groups Projects
Commit 6260ef1e authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Added two images missing in repo.

Fixed portability issue with image paths.
parent 8c1ec58d
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# ~*~ coding: utf-8 ~*~
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyKDE4.plasma import Plasma
from PyKDE4 import plasmascript
from datetime import datetime
from PyQt4 import uic
import pickle
import os
class Koala():
def __init__(self):
......@@ -13,9 +15,10 @@ class Koala():
self.hunger = 10
self.exhaustion = 10
self.brushed = datetime.now()
self.brushtime = "22:15"
def get_mood(self):
if datetime.now() > datetime.strptime("22:15", "%H:%M") and self.brushed < datetime.strptime("22:15", "%H:%M"):
if datetime.now() > datetime.strptime(datetime.now().strftime("%d.%m.%Y") + " " + self.brushtime, "%d.%m.%Y %H:%M") and self.brushed < datetime.strptime(datetime.now().strftime("%d.%m.%Y") + " " + self.brushtime, "%d.%m.%Y %H:%M"):
return "dirty-teeth"
if self.hunger < 0:
......@@ -34,12 +37,9 @@ class Koala():
self.happiness -= 1
self.hunger += 1
try:
f = open(os.path.join("~", ".deskoala", "koala.dat"), "wb")
pickle.dump(self, f)
f.close()
except:
pass
f = open(os.path.expanduser(os.path.join("~", ".deskoala", "koala.dat")), "wb")
pickle.dump(self, f)
f.close()
def feed(self):
self.hunger -= 2
......@@ -47,6 +47,9 @@ class Koala():
def turn(self):
self.happiness += 3
def brush(self):
self.brushed = datetime.now()
def excercise(self):
self.hunger += 2
self.happiness += 1
......@@ -57,14 +60,14 @@ class Deskoala(plasmascript.Applet):
plasmascript.Applet.__init__(self,parent)
try:
f = open(os.path.join("~", ".deskoala", "koala.dat"), "rb")
f = open(os.path.expanduser(os.path.join("~", ".deskoala", "koala.dat")), "rb")
self.koala = pickle.load(f)
f.close()
except:
self.koala = Koala()
def init(self):
self.setHasConfigurationInterface(False)
self.setHasConfigurationInterface(True)
self.resize(280, 240)
self.setAspectRatioMode(Plasma.Square)
self.layout = QGraphicsLinearLayout(Qt.Horizontal,self.applet)
......@@ -73,17 +76,31 @@ class Deskoala(plasmascript.Applet):
self.show_mood()
self.buttons = QGraphicsLinearLayout(Qt.Vertical, self.layout)
for b in [("feed", self.feed), ("turn", self.turn)]:
for b in [("feed", self.feed), ("turn", self.turn), ("excercise", self.excercise), ("brush", self.brush)]:
button = Plasma.PushButton(self.applet)
button.setImage("/home/mitroman/Python/desKoala/contents/images/button_" + b[0] + ".gif")
button.setImage(self.package().filePath('images', 'button_' + b[0] + '.gif'))
self.connect(button, SIGNAL("clicked()"), b[1])
self.buttons.addItem(button)
self.layout.addItem(self.buttons)
self.startTimer(5000)
def createConfigurationInterface(self, parent):
self.widget = QWidget(parent)
self.connect(self.widget, SIGNAL('destroyed(QObject*)'), self.configWidgetDestroyed)
self.ui = uic.loadUi(self.package().filePath('ui', 'config.ui'), self.widget)
return self.widget
def save(self, config):
pass
def configWidgetDestroyed(self):
self.widget = None
self.ui = None
def show_mood(self):
self.label.setImage("/home/mitroman/Python/desKoala/contents/images/koala_" + self.koala.get_mood() + ".gif")
self.label.setImage(self.package().filePath('images', 'koala_' + self.koala.get_mood() + '.gif'))
self.update()
def timerEvent(self, event):
......@@ -98,5 +115,13 @@ class Deskoala(plasmascript.Applet):
self.koala.turn()
self.show_mood()
def excercise(self):
self.koala.excercise()
self.show_mood()
def brush(self):
self.koala.brush()
self.show_mood()
def CreateApplet(parent):
return Deskoala(parent)
contents/images/button_brush.gif

113 B

contents/images/button_excercise.gif

945 B

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment