diff --git a/app/gui.py b/app/gui.py index 74b9a71..177f4e1 100644 --- a/app/gui.py +++ b/app/gui.py @@ -1,32 +1,226 @@ +# -*- coding: utf-8 -*- import wx +from plot import * from database import * +import flask as fla class MainWindow(wx.Frame): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) - self.init_ui() def init_ui(self): self.SetSize((480, 320)) self.SetTitle('Baroness Control') - panel = wx.Panel(self, -1) + + self.panelStart = PanelStart(self) + self.panelUser = Panel1(self) + self.panelList = Panel2(self) + self.panelThanks = PanelThanks(self) + + self.active = 0 + self.user = User() + + self.switchPanels() + + self.Show() + + def onStart(self, e): + self.active = 2 + self.switchPanels() + + def delayExit(self, e=None): + wx.CallLater(5000, self.onExit) + + def getUser(self): + return self.user.id + # return self.user + + def onExit(self, e=None): + self.active = 0 + self.switchPanels() + + def onUser(self, e): + self.active = 1 + longn = e.GetEventObject().GetLabelText() + for user in get_users(): + if user.longname == longn: + self.user = user + print self.user.id + print self.user.email + self.switchPanels() + + def onProduct(self, e): + self.active = 3 + print self.user.longname + ' consumes' + buttonl = e.GetEventObject().GetLabelText() + drink = buttonl.split('\n')[0] + with app.app_context(): + for i in range(0, int(self.panelUser.GetAmount())): + add_consume(self.user.name, get_product_by_name(drink).id) + plot_total(self.user) + plot_total() + plot_list(4) + self.switchPanels() + + def switchPanels(self): + if self.active == 0: + self.panelStart.Show() + self.panelUser.Hide() + self.panelList.Hide() + self.panelThanks.Hide() + elif self.active == 1: + self.panelStart.Hide() + self.panelUser.Show() + self.panelList.Hide() + self.panelThanks.Hide() + elif self.active == 2: + self.panelStart.Hide() + self.panelUser.Hide() + self.panelList.Show() + self.panelThanks.Hide() + elif self.active == 3: + self.panelStart.Hide() + self.panelUser.Hide() + self.panelList.Hide() + self.panelThanks.Show() + self.panelThanks.label_1.SetLabel(self.user.longname) + self.delayExit() + +class PanelStart (wx.Panel): + + def __init__(self, parent): + wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos = wx.DefaultPosition, size=(480, 320)) + #panel = wx.Panel(self, -1) + self.bitmap_1 = wx.StaticBitmap(self, wx.ID_ANY, wx.Bitmap("./app/static/start.png", wx.BITMAP_TYPE_ANY)) + self.Bind(wx.EVT_LEFT_UP, parent.onStart) + self.bitmap_1.Bind(wx.EVT_LEFT_UP, parent.onStart) + + def on_quit(self, e): + print "close" + self.Destroy() + +class PanelThanks (wx.Panel): + + def __init__(self, parent): + wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos = wx.DefaultPosition, size=(480, 320)) + #panel = wx.Panel(self, -1) + self.bitmap_1 = wx.StaticBitmap(self, wx.ID_ANY, wx.Bitmap("./app/static/thanks.png", wx.BITMAP_TYPE_ANY)) + self.Bind(wx.EVT_LEFT_UP, parent.onStart) + self.label_1 = wx.StaticText(self, wx.ID_ANY, 'bla blub', pos=(100,100)) + self.label_1.SetFont(wx.Font(30, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans")) + + def on_quit(self, e): + print "close" + self.Destroy() + +class Panel1 (wx.Panel): + + def __init__(self, parent): + wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos = wx.DefaultPosition, size=(480, 320)) + + self.bitmap_1 = wx.StaticBitmap(self, wx.ID_ANY, wx.Bitmap("./app/static/products.png", wx.BITMAP_TYPE_ANY)) products = get_products() buttonids = [] i = 0 for product in products: - but = wx.Button(panel, label=product.name, pos=(50+i*150, 50), size=(100, 100)) + #480x320 + but = wx.Button(self, id=wx.ID_ANY, label=product.name + u"\n" + "%0.2f" % product.price, pos=(0+i*120, 0), size=(120, 120)) + but.SetFont(wx.Font(23, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans")) print "Button %s created" % product.name - self.Bind(wx.EVT_BUTTON, self.on_button_press, id=but.Id) + self.Bind(wx.EVT_BUTTON, parent.onProduct, id=but.Id) i = i+1 + self.b_less = wx.Button(self, id = wx.ID_ANY, label=u"-", pos=(0,240), size=(120, 80)) + self.b_less.SetFont(wx.Font(60, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans")) + self.Bind(wx.EVT_BUTTON, self.onLess, id=self.b_less.Id) + + self.l_amount = wx.StaticText(self, wx.ID_ANY, "1", pos=(145,245), style=wx.ALIGN_CENTER) + self.l_amount.SetFont(wx.Font(50, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Sans")) + + self.b_more = wx.Button(self, id = wx.ID_ANY, label=u"+", pos=(240,240), size=(120, 80)) + self.b_more.SetFont(wx.Font(60, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans")) + self.Bind(wx.EVT_BUTTON, self.onMore, id=self.b_more.Id) + + self.b_exit = wx.Button(self, id = wx.ID_ANY, label=u"x", pos=(360,240), size=(120, 80)) + self.b_exit.SetFont(wx.Font(30, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans")) + self.Bind(wx.EVT_BUTTON, parent.onExit, id=self.b_exit.Id) + self.Bind(wx.EVT_CLOSE, self.on_quit) - self.Show(True) + #self.Show(True) + + def onMore(self,e, id=-1): + self.amount = int(self.l_amount.GetLabelText()) + 1 + self.l_amount.SetLabel(str(self.amount)) + self.Layout() + + def onLess(self,e, id=-1): + self.amount = int(self.l_amount.GetLabelText()) - 1 + if self.amount > 0: + self.l_amount.SetLabel(str(self.amount)) + self.Layout() + + def GetAmount(self): + return int(self.l_amount.GetLabelText()) + + def on_quit(self, e): + print "close" + self.Destroy() + + +class Panel2 (wx.Panel): + + def __init__(self, parent): + wx.Panel.__init__(self, parent, id=wx.ID_ANY, size=(480, 320)) + + self.bitmap_1 = wx.StaticBitmap(self, wx.ID_ANY, wx.Bitmap("./app/static/users.png", wx.BITMAP_TYPE_ANY)) + + users = get_users() + names = list() + for user in users: + names.append(user.longname) + + i = 0 + + self.but_names = list() + for user in users: + #480x320 + but = wx.Button(self, id=wx.ID_ANY, label=names[i], pos=(0,0+i*40), size=(400, 40)) + but.SetFont(wx.Font(20, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans")) + self.Bind(wx.EVT_BUTTON, parent.onUser, id=but.Id) + self.but_names.append(but) + i = i+1 + + b_up = wx.Button(self, id=wx.ID_ANY, label=u"\u25B2", pos=(400,0), size=(80, 80)) + b_up.SetFont(wx.Font(20, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans")) + self.Bind(wx.EVT_BUTTON, self.on_up, id=b_up.Id) + + self.b_down = wx.Button(self, id=wx.ID_ANY, label=u"\u25BC", pos=(400,240), size=(80, 80)) + self.b_down.SetFont(wx.Font(20, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans")) + self.Bind(wx.EVT_BUTTON, self.on_down, id=self.b_down.Id) + + b_exit = wx.Button(self, id=wx.ID_ANY, label="X", pos=(400,120), size=(80, 80)) + b_exit.SetFont(wx.Font(20, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans")) + b_exit.Bind(wx.EVT_BUTTON, parent.onExit, id=b_exit.Id) + + self.Bind(wx.EVT_CLOSE, self.on_quit) + #self.Show(True) + + #This is bad programming :) + def on_down(self,e , id=-1): + for button in self.but_names: + button.SetPosition((button.GetPosition()[0],button.GetPosition()[1]-320)) + + def on_up(self,e , id=-1): + for button in self.but_names: + button.SetPosition((button.GetPosition()[0],button.GetPosition()[1]+320)) def on_button_press(self,e, id=-1): - print e + print e.Id + print id + #if id == self.b_down.Id: def on_quit(self, e): print "close" diff --git a/app/plot.py b/app/plot.py index 1502aca..bfa2152 100644 --- a/app/plot.py +++ b/app/plot.py @@ -114,7 +114,7 @@ def plot_list(duration): i=0 for consumptions in allconsumptions: - ax.barh(np.arange(len(consumptions)), consumptions, label=get_product_by_id(i+1).name, align='center', height=0.5, color=colors[i]) + ax.barh(np.arange(len(consumptions)), consumptions, label=get_product_by_id(i+1).name, align='center', height=(0.5), color=colors[i]) i+=1 names = list() @@ -148,5 +148,5 @@ def plot_list(duration): fig.set_size_inches(10.24, 7.68) plt.savefig('app/static/bierliste.png', dpi=100) #800x600 - fig.set_size_inches(12, 8) + fig.set_size_inches(15, 10) plt.savefig('app/static/bierliste_small.png', dpi=72) diff --git a/app/static/products.png b/app/static/products.png new file mode 100644 index 0000000..9f00217 Binary files /dev/null and b/app/static/products.png differ diff --git a/app/static/start.png b/app/static/start.png new file mode 100644 index 0000000..1d0668e Binary files /dev/null and b/app/static/start.png differ diff --git a/app/static/thanks.png b/app/static/thanks.png new file mode 100644 index 0000000..268a3f7 Binary files /dev/null and b/app/static/thanks.png differ diff --git a/app/static/users.png b/app/static/users.png new file mode 100644 index 0000000..89a4220 Binary files /dev/null and b/app/static/users.png differ diff --git a/app/views.py b/app/views.py index dc9d3f3..6d3e1fe 100644 --- a/app/views.py +++ b/app/views.py @@ -18,8 +18,8 @@ def static_proxy(path): @app.route('/index') def index(): consumed = get_consumed() - plot_total() - plot_list(4) + #plot_total() + #plot_list(4) #generate_test_users() #generate_test_consumptions() return render_template("index.html", consumed=consumed, user=get_user_by_name(session.get('name'))) @@ -213,6 +213,7 @@ def consume(): message = "Du hast gerade ein %s konsumiert." % prod.name plot_total(get_user_by_name(session.get('name'))) plot_total() + plot_list(4) return render_template('consume.html', products=products, message=message, user=get_user_by_name(session.get('name'))) @app.route('/billing') diff --git a/font/install b/font/install new file mode 100644 index 0000000..6bb4424 --- /dev/null +++ b/font/install @@ -0,0 +1,5 @@ +install the font + +https://github.com/shreyankg/xkcd-desktop/blob/master/Humor-Sans.ttf + +in ~/.local/share/fonts/truetype \ No newline at end of file diff --git a/gui/products.xcf b/gui/products.xcf new file mode 100644 index 0000000..21111c6 Binary files /dev/null and b/gui/products.xcf differ diff --git a/gui/start.xcf b/gui/start.xcf new file mode 100644 index 0000000..533de59 Binary files /dev/null and b/gui/start.xcf differ diff --git a/run.py b/run.py index 03a4b08..b469f61 100755 --- a/run.py +++ b/run.py @@ -7,10 +7,9 @@ import thread if __name__ == '__main__': #start gui - #wx = wx.App() - #gui.MainWindow(None) - - #thread.start_new_thread(wx.MainLoop,()) + wx = wx.App() + gui.MainWindow(None) + thread.start_new_thread(wx.MainLoop,()) # start flask app.secret_key = urandom(24)