Ejemplo n.º 1
0
    def onImportDB(self, evt):

        # Create the dialog. In this case the current directory is forced as the starting
        # directory for the dialog, and no default file name is forced. This can easilly
        # be changed in your program. This is an 'open' dialog, and allows multitple
        # file selections as well.
        #
        # Finally, if the directory is changed in the process of getting files, this
        # dialog is set up to change the current working directory to the path chosen.
        dlg = wx.FileDialog(
            self, message="Choose a file",
            defaultDir=os.getcwd(), 
            defaultFile="",
            wildcard='*.xml',
            style=wx.OPEN | wx.CHANGE_DIR
            )

        # Show the dialog and retrieve the user response. If it is the OK response, 
        # process the data.
        if dlg.ShowModal() == wx.ID_OK:
            # This returns a Python list of files that were selected.
            path = dlg.GetPath()
            import_db(path)
            
            session.close_all()
            song_list = [s.name for s in Song.get_songs()]
            for s in song_list:
                self.lb1.Append(s)
            
        dlg.Destroy()
Ejemplo n.º 2
0
 def __init__(self, parent):
     wx.Panel.__init__(self, parent, -1)
     
 
     full_sizer = wx.BoxSizer(wx.HORIZONTAL)
     sizer = wx.BoxSizer(wx.HORIZONTAL)
     
     text = "Songs List"
     text = wx.StaticText(self, -1, text, (20, 20))
     font = wx.Font(18, wx.SWISS, wx.NORMAL, wx.NORMAL, underline=True)
     text.SetFont(font)
     
     song_list = [s.name for s in Song.get_songs()]
     
     self.lb1 = wx.ListBox(self, 60, (50, 100), (150, 200), song_list, wx.LB_SINGLE)
     self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.lb1)
     if len(self.lb1.Items) > 0:
         self.lb1.SetSelection(0)
         
     text = wx.StaticText(self, -1, "Song Writer", (250, 120))    
     self.song_writer_text = wx.TextCtrl(self, -1, "", (250, 150), style=wx.TE_READONLY)
     
     text = wx.StaticText(self, -1, "Song Performer", (250, 220))
     self.song_performer_text = wx.TextCtrl(self, -1, "", (250, 250), style=wx.TE_READONLY)
     
     btn1 = wx.Button(self, -1, "Import song", (400, 150))
     self.Bind(wx.EVT_BUTTON, self.OnAddSong, btn1) 
     
     btn2 = wx.Button(self, -1, "Remove song", (400, 210))
     self.Bind(wx.EVT_BUTTON, self.OnRemoveSong, btn2)
     
     btn3 = wx.Button(self, -1, "Show song", (400, 270))
     self.Bind(wx.EVT_BUTTON, self.showSong, btn3)  
      
     sizer.Add(self.lb1, 0)
     sizer.Add(btn1, 1)
     sizer.Add(btn2, 2)
     sizer.Add(btn3, 3)
     
     btn4 = wx.Button(self, -1, "Export DB", (50, 400))
     self.Bind(wx.EVT_BUTTON, self.onExportDB, btn4)
     
     btn5 = wx.Button(self, -1, "Import DB", (150, 400))
     self.Bind(wx.EVT_BUTTON, self.onImportDB, btn5)    
     
     self.song_text_headline = wx.StaticText(self, -1, "The Song", (600, 50))
     font = wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL)
     self.song_text_headline.SetFont(font)
     self.t3 = wx.TextCtrl(self, -1, "", (600, 100), size=(500, 400), style=wx.TE_MULTILINE|wx.TE_READONLY)
     full_sizer.Add(sizer,0, wx.ALIGN_LEFT)
     full_sizer.Add(self.song_text_headline,1, wx.ALIGN_RIGHT)
Ejemplo n.º 3
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)
        self.words = Word.get_words()
        self.songs = []
        
        song_text = wx.StaticText(self, -1, "Select Song", (100, 30))
        songList = [s.name for s in Song.get_songs()]
        self.lb1 = wx.ListBox(self, 60, (100, 50), (200, 200), songList, wx.LB_EXTENDED)
        self.lb1.SetSelection(0)
        
#        btn1 = wx.Button(self, -1, "Show words", (330, 120))
#        self.Bind(wx.EVT_BUTTON, self.songChosen, btn1) 
        
        words_text = wx.StaticText(self, -1, "Select Word", (450, 30))
        self.lb2 = wx.ListBox(self, 70, (450, 50), (90, 200), [], wx.LB_SINGLE)
        
        words = self.words
        for word in words:
            self.lb2.Append(word.word)
        
        btn2 = wx.Button(self, -1, "Search Word", (450, 280))
        self.Bind(wx.EVT_BUTTON, self.wordChosen, btn2) 
        
        occurrences_text = wx.StaticText(self, -1, "Occurrences", (750, 30))
        self.t3 = wx.TextCtrl(self, -1,
                        "", (750, 50),
                       size=(400, 400), style=wx.TE_MULTILINE|wx.TE_RICH2)
        
        group_text = wx.StaticText(self, -1, "Select Group", (100, 380))
        self.groups_list = [g.name for g in Group.get_groups(type='group')]
        
        self.select_group = wx.ComboBox(self, 500, "", (100, 400), 
                                        (160, -1), self.groups_list, wx.CB_DROPDOWN)
        
        btn4 = wx.Button(self, -1, "Search Group", (100, 500))
        self.Bind(wx.EVT_BUTTON, self.groupChosen, btn4)
        
        btn2 = wx.Button(self, -1, "Search Phrase", (750, 500))
        self.Bind(wx.EVT_BUTTON, self.phraseChosen, btn2)
        
        expression_text = wx.StaticText(self, -1, "Select Expression", (450, 380))
        
        expression_list = [e.name for e in Expression.get_expressions()]
        self.lb3 = wx.ListBox(self, 70, (450, 410), (90, 50), expression_list, wx.LB_SINGLE)
        
        btn3 = wx.Button(self, -1, "Search Expression", (450, 500))
        self.Bind(wx.EVT_BUTTON, self.expressionChosen, btn3)
Ejemplo n.º 4
0
    def onSearch(self, evt):
        from text_indexer.orm.base import session

        name = None
        writer = None
        performer = None
        word = None
        if self.radio0.IsChecked():
            name = self.text0.Value
        if self.radio1.IsChecked():
            writer = self.text1.Value
        if self.radio2.IsChecked():
            performer = self.text2.Value
        if self.radio3.IsChecked():
            word = self.text3.Value
        songs = [s.name for s in Song.get_songs(name, writer, performer, word)]
        self.song_list.Clear()
        self.song_list.AppendItems(songs)
Ejemplo n.º 5
0
    def onSearch(self, evt):
        try:
            from text_indexer.orm.base import session

            song_name = self.lb1.Items[self.lb1.GetSelection()]
            song = Song.get_songs(name=song_name)[0]
            query = session.query(WordPosition).filter_by(song_id=song.id)
            if self.radio_selected == self.radio1:
                query = query.filter_by(number_in_song=self.text1.Value)
                wp = query.first()
                self.word_text.Value = wp.word.word
            elif self.radio_selected == self.radio2:
                query = query.filter_by(line_number=self.text2_1.Value, row_word_number=self.text2_2.Value)
                wp = query.first()
                self.word_text.Value = wp.word.word
            elif self.radio_selected == self.radio3:
                stanza = song.get_stanza(int(self.text3_1.Value) - 1)
                self.word_text.Value = stanza.split(" ")[int(self.text3_2.Value) - 1]
            if not self.word_text.Value:
                self.word_text.Value = "No word found"
        except Exception, e:
            self.word_text.Value = "No word found"
Ejemplo n.º 6
0
 def showSong(self, evt):
     selection = self.lb1.GetSelection()
     if selection != -1:
         song = Song.get_songs(name=self.lb1.Items[selection])[0]
         self.t3.SetValue(song.get_text())
         self.t3.SetScrollPos(1,1)
Ejemplo n.º 7
0
 def OnRemoveSong(self, evt):
     selection = self.lb1.GetSelection()
     if selection != -1:
         song = Song.get_songs(name=self.lb1.Items[selection])[0]
         self.lb1.Delete(selection)
         delete_song(song)
Ejemplo n.º 8
0
 def EvtListBox(self, event):
     name = event.GetString()
     song = Song.get_songs(name=name)[0]
     self.song_writer_text.SetValue(song.writer)
     
     self.song_performer_text.SetValue(song.performer)
Ejemplo n.º 9
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)
        
        text = "Statistics"
        text = wx.StaticText(self, -1, text, (600, 50))
        font = wx.Font(24, wx.SWISS, wx.NORMAL, wx.NORMAL, underline=True)
        text.SetFont(font)
        
        self.grid = wx.grid.Grid(self, -1, (200, 150), (900, 140))
        
        self.grid.CreateGrid(2, 4)
        
        self.grid.SetColSize(0, 200)
        self.grid.SetColSize(1, 200)
        self.grid.SetColSize(2, 200)
        self.grid.SetColSize(3, 200)

        
        self.grid.SetColLabelValue(0, "Word")
        self.grid.SetColLabelValue(1, "Line")
        self.grid.SetColLabelValue(2, "Paragraph")
        self.grid.SetColLabelValue(3, "Song")
        
        self.grid.SetRowSize(0, 50)
        self.grid.SetRowSize(1, 50)
        
        self.grid.SetRowLabelValue(0, "Chars")
        self.grid.SetRowLabelValue(1, "Words")
        
        from text_indexer.orm.base import session
        
        number_of_words = 0
        number_of_chars = 0
        number_of_lines = 0
        number_of_paragraphs = 0
        line=0
        stanza=0
        song_id=0
        for wp in session.query(WordPosition).order_by(WordPosition.song_id, WordPosition.line_number).all():
            number_of_words+=1
            number_of_chars+=len(wp.word.word)
            if wp.song_id != song_id:
                line = wp.line_number
                stanza = wp.stanza_number
                song_id = wp.song_id
                number_of_lines+=1
                number_of_paragraphs+=1
            elif wp.stanza_number != stanza:
                stanza = wp.stanza_number
                line= wp.line_number
                number_of_lines+=1
                number_of_paragraphs+=1
            elif wp.line_number != line:
                number_of_lines+=1
        
        chars_per_word = float(number_of_chars)/number_of_words
        self.grid.SetCellValue(0, 0, str(chars_per_word))
        self.grid.SetCellValue(0, 1, str(chars_per_word*number_of_words/number_of_lines))
        self.grid.SetCellValue(0, 2, str(chars_per_word*number_of_words/number_of_paragraphs))
        self.grid.SetCellValue(0, 3, str(number_of_words * chars_per_word/len(Song.get_songs())))
        self.grid.SetCellValue(1, 0, '1')
        self.grid.SetCellValue(1, 1, str(float(number_of_words)/number_of_lines))
        self.grid.SetCellValue(1, 2, str(float(number_of_words)/number_of_paragraphs))
        self.grid.SetCellValue(1, 3, str(float(number_of_words)/len(Song.get_songs())))
        
Ejemplo n.º 10
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)

        sizer = wx.BoxSizer(wx.HORIZONTAL)

        song_sizer = wx.BoxSizer(wx.VERTICAL)
        option_sizer = wx.BoxSizer(wx.VERTICAL)
        result_sizer = wx.BoxSizer(wx.VERTICAL)

        text = "Choose song"
        text = wx.StaticText(self, -1, text, (100, 20))
        font = wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL)
        text.SetFont(font)

        songList = [s.name for s in Song.get_songs()]
        self.lb1 = wx.ListBox(self, 60, wx.DefaultPosition, (200, 400), songList, wx.LB_SINGLE)
        self.lb1.SetSelection(0)

        song_sizer.AddSpacer(20)
        song_sizer.Add(text)
        song_sizer.AddSpacer(20)
        song_sizer.Add(self.lb1)

        box1_title = wx.StaticBox(self, -1, "Search Options")
        box1 = wx.StaticBoxSizer(box1_title, wx.VERTICAL)

        grid1 = wx.FlexGridSizer(0, 2, 30, 10)

        o_sizer1 = wx.BoxSizer(wx.VERTICAL)
        o_sizer2 = wx.BoxSizer(wx.VERTICAL)
        o_sizer3 = wx.BoxSizer(wx.VERTICAL)

        self.group1_ctrls = []
        self.radio1 = wx.RadioButton(self, -1, " Word number  ")
        self.radio2 = wx.RadioButton(self, -1, " Line    ")
        self.radio3 = wx.RadioButton(self, -1, " Paragraph         ")
        self.radio_selected = self.radio1

        l1 = wx.StaticText(self, -1, "Number in song")
        self.text1 = wx.TextCtrl(self, -1, "")
        self.text1.Value = "1"
        o_sizer1.Add(l1)
        o_sizer1.AddSpacer(5)
        o_sizer1.Add(self.text1)

        l2_1 = wx.StaticText(self, -1, "Line number")
        l2_2 = wx.StaticText(self, -1, "Number in line")
        self.text2_1 = wx.TextCtrl(self, -1, "")
        self.text2_2 = wx.TextCtrl(self, -1, "")
        self.text2_1.Value = "1"
        self.text2_2.Value = "1"

        o_sizer2.Add(l2_1)
        o_sizer2.AddSpacer(5)
        o_sizer2.Add(self.text2_1)
        o_sizer2.Add(l2_2)
        o_sizer2.AddSpacer(5)
        o_sizer2.Add(self.text2_2)

        l3_1 = wx.StaticText(self, -1, "Paragraph number")
        l3_2 = wx.StaticText(self, -1, "Number in paragraph")
        self.text3_1 = wx.TextCtrl(self, -1, "")
        self.text3_2 = wx.TextCtrl(self, -1, "")
        self.text3_1.Value = "1"
        self.text3_2.Value = "1"

        o_sizer3.Add(l3_1)
        o_sizer3.AddSpacer(5)
        o_sizer3.Add(self.text3_1)
        o_sizer3.Add(l3_2)
        o_sizer3.AddSpacer(5)
        o_sizer3.Add(self.text3_2)

        self.group1_ctrls.append((self.radio1, [self.text1], o_sizer1))
        self.group1_ctrls.append((self.radio2, [self.text2_1, self.text2_2], o_sizer2))
        self.group1_ctrls.append((self.radio3, [self.text3_1, self.text3_2], o_sizer3))

        for radio, text_group, o_sizer in self.group1_ctrls:
            grid1.Add(radio, 0, wx.ALIGN_LEFT | wx.LEFT | wx.RIGHT | wx.TOP, 5)
            self.Bind(wx.EVT_RADIOBUTTON, self.OnGroupSelect, radio)
            grid1.Add(o_sizer, 0, wx.ALIGN_LEFT | wx.LEFT | wx.RIGHT | wx.TOP, 5)

            for text in text_group:
                text.Enable(False)

        btn1 = wx.Button(self, -1, "Search", (700, 275))
        self.Bind(wx.EVT_BUTTON, self.onSearch, btn1)

        self.text_result = "result"
        self.text_result = wx.StaticText(self, -1, self.text_result, (100, 20))
        font = wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL)
        self.text_result.SetFont(font)

        self.word_text = wx.TextCtrl(self, -1, "", size=(125, -1))

        result_sizer.AddSpacer(250)
        result_sizer.Add(self.text_result)
        result_sizer.AddSpacer(10)
        result_sizer.Add(self.word_text)

        box1.Add(grid1, 0, wx.ALIGN_CENTRE | wx.ALL, 5)
        option_sizer.AddSpacer(120)
        option_sizer.Add(box1)

        sizer.AddSpacer(100)
        sizer.Add(song_sizer)
        sizer.AddSpacer(100)
        sizer.Add(option_sizer)
        sizer.AddSpacer(200)
        sizer.Add(result_sizer)

        self.SetSizer(sizer)