import wx
from settings import Settings
import webbrowser


class About(wx.Panel):
    '''About'''
    def __init__(self, parent):
        super(About, self).__init__(parent)

        self.settings = Settings()
        self.init_ui()

    def init_ui(self):
        #------------------------------------
        # 子部件
        title = wx.StaticText(self, label='Title:')
        title_value = wx.StaticText(self)
        title_value.SetLabelText(self.settings.name)

        version = wx.StaticText(self, label='Version:')
        version_value = wx.StaticText(self)
        version_value.SetLabelText(self.settings.version)

        author = wx.StaticText(self, label='Author:')
        author_value = wx.StaticText(self)
        author_value.SetLabelText(self.settings.author)

        btn = wx.Button(self, label='Get source code')
        btn.Bind(wx.EVT_BUTTON, self.get_source_handler)

        #------------------------------------
        # 布局
        gbs = wx.GridBagSizer(0, 0)
        gbs.Add(title, pos=(0, 0), flag=wx.EXPAND | wx.ALL, border=10)
        gbs.Add(title_value, pos=(0, 1), flag=wx.EXPAND | wx.ALL, border=10)
        gbs.Add(version, pos=(1, 0), flag=wx.EXPAND | wx.ALL, border=10)
        gbs.Add(version_value, pos=(1, 1), flag=wx.EXPAND | wx.ALL, border=10)
        gbs.Add(author, pos=(2, 0), flag=wx.EXPAND | wx.ALL, border=10)
        gbs.Add(author_value, pos=(2, 1), flag=wx.EXPAND | wx.ALL, border=10)
        gbs.Add(btn,
                pos=(3, 0),
                span=(0, 2),
                flag=wx.EXPAND | wx.ALL,
                border=10)

        #------------------------------------
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(gbs)
        self.SetSizerAndFit(sizer)

    def get_source_handler(self, e):
        webbrowser.open(self.settings.url)
