#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# generated by wxGlade 0.9.3 on Sat Jun 22 23:12:22 2019
#

import wx
import actions
import time

#for testing
from coinbase.wallet.client import Client



# begin wxGlade: dependencies
# end wxGlade

# begin wxGlade: extracode
# end wxGlade


class PriceCheck(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: PriceCheck.__init__
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.SetSize((400, 300))
        self.check_button = wx.ToggleButton(self, wx.ID_ANY, "start")
        self.check_button.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle)
        
        # #Imma putting in an off button
        # self.off_button = wx.ToggleButton(self, wx.ID_ANY, "Stop")
        # self.off_button.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggleOff)
        # # Menu Bar
        self.frame_menubar = wx.MenuBar()
        self.SetMenuBar(self.frame_menubar)
        # Menu Bar end

        self.__set_properties()
        self.__do_layout()
        # end wxGlade
        
        #state variable
        self.state = 0
    def __set_properties(self):
        # begin wxGlade: PriceCheck.__set_properties
        self.SetTitle("Price Check")
        _icon = wx.NullIcon
        _icon.CopyFromBitmap(wx.Bitmap("C:\\Users\\rickd\\Downloads\\wxGlade-0.9.3\\icons\\toolbar.xpm", wx.BITMAP_TYPE_ANY))
        self.SetIcon(_icon)
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: PriceCheck.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_1.Add(self.check_button, 0, wx.ALIGN_CENTER, 0)
        #sizer_1.Add(self.off_button, 0, wx.ALIGN_CENTER, 0)
        self.priceText = wx.StaticText(self, wx.ID_ANY, "Click the button dummy", style=wx.ALIGN_CENTER)
        sizer_1.Add(self.priceText, 0, wx.ALIGN_CENTER, 0)
        self.SetSizer(sizer_1)
        
        
        # end wxGlade
        
    #what the button does
    def OnToggle(self, event):
        client = Client("WNCJ3l6KlXgGDmqq", "Il6nr9t43HFinjYzIyKPF4eAMtNf1c67") #update this to take values later
        state = event.GetEventObject().GetValue()
        #print(self.state)
        #rint("onnnd")
        #print(event.GetEventObject().GetValue())
        if state == True:
            #print(self.state)
            self.state = 1
            event.GetEventObject().SetLabel("Stop") #change button text
            self.check_button.Bind(wx.EVT_TOGGLEBUTTON,self.OnToggleOff)
            while self.state == 1:
                time.sleep(1)
                price = float(client.get_buy_price(currency_pair = 'BTC-USD')['amount'])
                #print(price)
                self.priceText.SetLabel(str(price)) #gotta turn it to a strong
                wx.Yield()
                
            else:
                event.GetEventObject().SetLabel("Start")
        
    def OnToggleOff(self, event):
        self.state = 0
        #print("offed")
        #print(self.state)
        # print(event.GetEventObject().GetValue())
        # event.GetEventObject().SetLabel("Start")
    
        
        
        #price = actions.getcurprice('BTC-USD')
        
        
        

# end of class PriceCheck

class MyApp(wx.App):
    def OnInit(self):
        self.frame = PriceCheck(None, wx.ID_ANY, "")
        self.SetTopWindow(self.frame)
        self.frame.Show()
        return True

# end of class MyApp

if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()
