import wx
import os
from framegrid import FrameGrid
from framebuilddict import FrameBuildDictionary
import dictionary
import Global

class FrameDictionary(wx.Frame):
           
    WILDCARD = "Memorize Word File (*.mwd)|*.mwd"

    def __init__(self, parent):
        BUTTON_SIZE=(200,-1)
        FRAME_SIZE_WIDTH = 800
        FRAME_SIZE_HEIGHT = 300
        FRAME_POS_X = 200
        FRAME_POS_Y = 200

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


        self.frame = parent
        
        button_build_dict = wx.Button(self, -1, Global.BUILD_DICT_BUTTON, BUTTON_SIZE)
        button_show_dict = wx.Button(self, -1, Global.SHOW_DICT_BUTTON, BUTTON_SIZE)


        
        # Add Items to Sizer
        mainSizer = wx.GridBagSizer(3, 3)
        mainSizer.Add(button_build_dict, pos=(1, 0), flag=wx.ALL, border=5)
        mainSizer.Add(button_show_dict, pos=(2, 0), flag=wx.ALL, border=5)
        mainSizer.Layout()

      
        # Bind item events
        self.Bind(wx.EVT_BUTTON, self.build_dict, button_build_dict)
        self.Bind(wx.EVT_BUTTON, self.show_dict, button_show_dict)
        self.SetSizer(mainSizer)
        self.Fit()
        self.Center()
        self.Show()

    def build_dict(self, evt):
        win = FrameBuildDictionary(self)
        win.Show(True)
        


    def show_dict(self,evt):
        dlg = wx.FileDialog(
            self, message=Global.FILE_BROWS_SHOW_DICT_TITLE,
            defaultDir=os.getcwd(), 
            defaultFile="",
            wildcard=self.WILDCARD,
            style=wx.OPEN | wx.CHANGE_DIR
            )

        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.GetPath()
            win = FrameGrid(self, dictionary.get_entry_list_by_group(path,"defaultGroup"))
            win.Show()
