# -*- coding: utf8 -*-
import wx


def words_in_string(list, string1):
    return set(list).intersection(string1.split())

list = ['python', 'java', 'ruby', 'c++']



class MyFrame(wx.Frame):

    def __init__(self, parent, id, title):

        wx.Frame.__init__(self, parent, id, title)

        # add panel
        panel = wx.Panel(self, -1)
        # now add the needed widgets

        self.label1 = wx.StaticText(panel, -1, 'Write Your Text :')
        self.entry1 = wx.TextCtrl(panel, -1, '', size=(300, 20))
        self.button1 = wx.Button(panel, -1, 'Check ')
        self.button1.SetBackgroundColour('white')
        self.button1.Bind(wx.EVT_BUTTON, self.onChange)
        info = "Check the change the keywords color in text"
        self.display = wx.TextCtrl(panel, -1, info, size=(450, 200),
                                   style=wx.TE_MULTILINE)

        sizer = wx.GridBagSizer(vgap=10, hgap=20)
        sizer.Add(self.label1, pos=(0, 0))  # pos(row,column)
        sizer.Add(self.entry1, pos=(0, 1))  # row 0, column 1
        # span=(1, 2) --> allow to span over 2 columns
        sizer.Add(self.button1, pos=(1, 0), span=(1, 2))
        sizer.Add(self.display, pos=(2, 0), span=(1, 2))

        # use boxsizer to add border around sizer
        border = wx.BoxSizer()
        border.Add(sizer, 0, wx.ALL, 10)
        panel.SetSizerAndFit(border)
        self.Fit()



    def onChange(self, event):

        string1 = self.entry1.GetValue()
        string2 = ''
        words = string1.split()
        for j in range(len(words)):
            was = False
            for i in range(len(list)):
                if words[j] == list[i]:
                    #string2 += ' ' + (words[j])
                    string2 += ' ' + (words[j].SetForegroundColour(wx.Color(255, 0, 0)))
                    was = True
            if was == False:
                string2 += ' ' + words[j]
        self.display.SetValue(string2)

app = wx.App(redirect=False)
frame = MyFrame(None, -1, "App")
frame.Show()
app.MainLoop()