import wx
from griddict import GridDictionary
import Global


class FrameFinish(wx.Frame):

    def __init__(self, parent, true_count, false_count, falses):

        FRAME_SIZE_WIDTH = 800
        FRAME_SIZE_HEIGHT = 300
        FRAME_POS_X = 200
        FRAME_POS_Y = 200

        wx.Frame.__init__(self, parent, -1,
                          title=Global.FINISH_TITLE,
                          size=(FRAME_SIZE_WIDTH, FRAME_SIZE_HEIGHT),
                          pos=(FRAME_POS_X, FRAME_POS_Y),
                          style=wx.DEFAULT_FRAME_STYLE)
        self.frame = parent

        # Text Items
        true_count_text = wx.StaticText(self, -1, Global.TRUE_COUNT_TEXT)
        false_count_text = wx.StaticText(self, -1, Global.FALSE_COUNT_TEXT)
        true_count_value = wx.StaticText(self, -1, str(true_count))
        false_count_value = wx.StaticText(self, -1, str(false_count))
        seperator = wx.StaticText(self, -1, "-----------------------------")
        font = wx.Font(16, wx.MODERN, wx.NORMAL, wx.BOLD)
        falses_big_text = wx.StaticText(self, -1, Global.WRONG_ANSWERS_TEXT+":")
        falses_big_text.SetFont(font)

        # Grid
        grid_falses = GridDictionary(self, falses)
        print "false count:", len(falses)
        
        # Sizer Set
        trueCountSizer = wx.GridBagSizer(2,2)
        trueCountSizer.Add(true_count_text,pos=(0,0))
        trueCountSizer.Add(true_count_value,pos=(0,1))
        trueCountSizer.Add(false_count_text,pos=(1,0))
        trueCountSizer.Add(false_count_value,pos=(1,1))
        
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(trueCountSizer, 0, wx.ALL, 5)
        mainSizer.Add(seperator,0, wx.ALL, 5)
        mainSizer.Add(falses_big_text,0, wx.ALL, 5)
        mainSizer.Add(grid_falses, 0, wx.ALL, 5)
        

        # Bind
        self.Bind(wx.EVT_CLOSE, self.close_event)

        # Frame Settings
        self.SetSizer(mainSizer)
        self.Fit()
        self.Show()

    def close_event(self, evt):
        print "closed..."
        self.frame.close()
