Пример #1
0
class Writer(wx.Frame):
    def __init__(self, parent, title):
        super(Writer, self).__init__(parent, title=title, size=(800, 600))
        self.sourcedir = 'data/rawtranscripts'

        self.doc_list = self.set_doc_list(number_sources=3, ngram_size=3)

        self.log = Log(self)
        self.log.AppendText('i ')

        # TODO: this must change to receive the processed ngram data about the corpus
        #self.channel_list = [(doc, Corpus(doc.name, doc.text)) for doc in self.doc_list]

        self.active_channel = 0

        self.InitUI()
        self.Centre()
        self.Show()

    def InitUI(self):
        menubar = wx.MenuBar()
        fileMenu = wx.Menu()
        menubar.Append(fileMenu, '&File')
        self.SetMenuBar(menubar)

        doc_grid = wx.BoxSizer(wx.VERTICAL)

        #self.Bind(wx.EVT_CHAR, self.onKey) # NB: this is how to bind events to the whole window

        gs = wx.GridSizer(1, 4, 3, 3)

        # add a new channel for each document in the list
        for doc in self.doc_list:
            score = str(doc.term_count('each'))
            newchannel = Channel(self, doc, self.log)
            gs.Add(newchannel, flag=wx.EXPAND)

        doc_grid.Add(self.log, flag=wx.EXPAND | wx.TOP | wx.BOTTOM, border=4)
        doc_grid.Add(gs, proportion=1, flag=wx.EXPAND)
        """
        testing = wx.GridSizer(4, 1, 3, 3)
        testing.Add(wx.Button(self, label = 'test'))
        doc_grid.Add(testing, proportion=1,flag=wx.EXPAND)
        """

        self.SetSizer(doc_grid)

    def set_doc_list(self, number_sources, ngram_size):
        doc_list = []
        for filename in os.listdir('data/rawtranscripts')[0:number_sources]:
            path = 'data/rawtranscripts/' + filename
            with open(path, 'r') as f:
                text = f.read()
                doc = Document(filename, text, ngram_size)
            doc_list.append(doc)
        return doc_list
Пример #2
0
class MyPanel(wx.Panel):
    """"""
 
    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)

        self.number_of_buttons = 0
        self.frame = parent
        self.log = Log(self)
        self.log.AppendText('it ')

        self.log.Bind(wx.EVT_CHAR_HOOK, self.onKey)
 
        self.mainSizer = wx.BoxSizer(wx.VERTICAL)
        controlSizer = wx.BoxSizer(wx.HORIZONTAL)
        self.widgetSizer = wx.GridSizer(2,2,3,3)
 
        self.addButton = wx.Button(self, label="Add")
        self.addButton.Bind(wx.EVT_BUTTON, self.onAddWidget)
        controlSizer.Add(self.addButton, 0, wx.CENTER|wx.ALL, 5)
 
        self.removeButton = wx.Button(self, label="Remove")
        self.removeButton.Bind(wx.EVT_BUTTON, self.onRemoveWidget)
        controlSizer.Add(self.removeButton, 0, wx.CENTER|wx.ALL, 5)
 
        self.mainSizer.Add(self.log)
        self.mainSizer.Add(controlSizer, 0, wx.CENTER)
        self.mainSizer.Add(self.widgetSizer, 0, wx.CENTER|wx.ALL, 10)
 
        self.SetSizer(self.mainSizer)
 
    #----------------------------------------------------------------------
    def onKey(self, event):
        keycode = event.GetKeyCode()
        if chr(keycode).isdigit():
            self.log.AppendText(" it's " + chr(keycode))
        event.Skip()


    #----------------------------------------------------------------------
    def onAddWidget(self, event):
        """"""
        self.number_of_buttons += 1
        label = "Button %s" %  self.number_of_buttons
        name = "button%s" % self.number_of_buttons
        d = Document('test', 'it was the best of times it was the worst of times')
        c = Channel(self, d, self.log)
        #new_button = wx.Button(self, label=label, name=name)
        self.widgetSizer.Add(c, 0, wx.ALL, 5)
        self.frame.fSizer.Layout()
        self.frame.Fit()
 
    #----------------------------------------------------------------------
    def onRemoveWidget(self, event):
        """"""
        if self.widgetSizer.GetChildren():
            self.widgetSizer.Hide(self.number_of_buttons-1)
            self.widgetSizer.Remove(self.number_of_buttons-1)
            self.number_of_buttons -= 1
            self.frame.fSizer.Layout()
            self.frame.Fit()