Пример #1
0
    def updateContent(self):
        
        """Resetting multi-label sentence"""
        if self.grid_layout != ():
            for i in range(0, self.grid_layout.count()):
                    self.grid_layout.itemAt(i).widget().hide()
            self.layout_vertical.removeItem(self.grid_layout)
            self.grid_layout.setParent(None)
            self.update()
        if self.sentence.isHidden():    
            self.sentence.show()
        self.showButtonsQuiz()
        
        """Getting actual content"""
        self.srs.getNextItem()
              
        example = self.srs.getCurrentExample()
        
        # checking for no example case
        if example is None:
            self.manualAddDialog.setProblemKanji(self.srs.getCurrentItemKanji())
            done = self.manualAddDialog.exec_()
            
            if done == 0:
                self.updateContent()
            elif done == 1:
                self.updateContent()
            else:
                pass
        else:
            example = example.replace(self.srs.getWordFromExample(), u"<font color='blue'>" + self.srs.getWordFromExample() + u"</font>")
            
            # checking sentence length
            if len(self.srs.currentExample.sentence) > SENTENCE_MAX: self.sentence.setFont(QFont(self.options.getSentenceFont(), MIN_FONT_SIZE))
            else: self.sentence.setFont(QFont(self.options.getSentenceFont(), self.options.getSentenceFontSize()))
            
            #temporary debug info:
#            print len(example), self.sentence.font()
            
            self.sentence.setText(example)
            
            readings = self.srs.getQuizVariants()

            changeFont = False
            for item in readings:
                if len(item) > BUTTON_KANA_MAX : changeFont = True
                
            try:
                for i in range(0, self.layout_horizontal.count()):
                        if i > 3: break
                        self.layout_horizontal.itemAt(i).widget().setText(u'')
                        
                        if changeFont:
                            self.layout_horizontal.itemAt(i).widget().setStyleSheet('QPushButton { font-family: ' + self.options.getQuizFont() + '; font-size: 11pt; }')
                        else:
                            self.layout_horizontal.itemAt(i).widget().setStyleSheet('QPushButton { font-family: ' + self.options.getQuizFont() + '; font-size: %spt; }' % self.options.getQuizFontSize())
                            
                        self.layout_horizontal.itemAt(i).widget().setText(readings[i])
            except:
                log.debug(u'Not enough quiz variants for ' + self.srs.getCurrentItem())
Пример #2
0
Файл: suzu.py Проект: Xifax/suzu
def main():
    
    app = QApplication(sys.argv)
    app.setWindowIcon(QIcon(PATH_TO_RES + LOGOS + 'suzu.png'))
    
    # application settings #
    options = Options()
    if options.isPlastique():  app.setStyle('plastique')
    
    # main gui module #
    quiz = Quiz(options)
    
    # additional gui components #
    about = About()
    options = OptionsDialog(quiz.srs.db, quiz.options)
    qdict = QuickDictionary(quiz.jmdict, quiz.edict, quiz.kjd, quiz.srs.db, quiz.options)
    
    # background updater #
    updater = BackgroundDownloader(quiz.options.getRepetitionInterval())
    updater.start()
    
    # additional tools #
    tools = Tools()
    web = WebPage()
    statistics = StatsInfo(quiz.srs.db)
    rehash = QuizRehash(quiz.srs.db, quiz.kjd, quiz.edict)
    
    # initializing references and hotkeys #
    quiz.addReferences(about, options, qdict, updater, tools, statistics, web, rehash)
    quiz.initGlobalHotkeys()
    
    try:
        sys.exit(app.exec_())
    except Exception, e:
        log.debug(e)
Пример #3
0
    def parseToWordsFull(text):
        mecab = MeCab.Tagger("")
    
        mnode = mecab.parseToNode(text.encode('utf8'))
        word_array = []
    
        while mnode:
            infos = {}
            infos['word'] = mnode.surface.decode('utf8')
            feature = mnode.feature.decode('utf8')
            array = feature.split(",")
            infos['type'] = array[0]
            infos['dform'] = array[4]
            infos['reading'] = array[5]
            infos['nform'] = array[6]                # non-inflected form (self)
            try:
                infos['pronunciation'] = array[7]
            except IndexError, e:
#                print e, text; log.debug(str(e) +'\t' + text)
                log.debug(str(e) +'\t' + text)
            if not infos['type'] == "BOS/EOS":
                word_array.append(infos)
            mnode = mnode.next
Пример #4
0
    def eventFilter(self, object, event):

        if event.type() == QEvent.HoverLeave:
            object.setStyleSheet("QLabel { color: rgb(0, 0, 0); }")
            
            object.parent().info.hide()
            object.parent().allInfo.hide()
            object.parent().kanjiInfo.hide()
            object.parent().kanjiGroups.hide()

            desktop = QApplication.desktop().screenGeometry()
            object.parent().info.setGeometry(QRect(desktop.width() - H_INDENT - I_WIDTH - I_INDENT, desktop.height() - V_INDENT, I_WIDTH, I_HEIGHT))
        
        if event.type() == QEvent.HoverEnter:
            object.setStyleSheet("QLabel { color: rgb(0, 5, 255); }")
            
            object.parent().info.item.setText(object.text())
            
            reading = object.parent().srs.getWordPronunciationFromExample(object.text())
            if reading != object.text() :  object.parent().info.reading.setText(reading)
            else:   object.parent().info.reading.setText(u'')
            
            #parsing word
            script = scripts.script_boundaries(object.text())
            components = []

            for cluster in script:
                if scripts.script_type(cluster) == scripts.Script.Kanji:
                    for kanji in cluster:
                        components = components + list(object.parent().rdk[kanji]) + list('\n')
                
            #setting radikals
            if len(components) > 0: components.pop()    #remove last '\n'
            object.parent().info.components.setText(' '.join(components))
            object.parent().info.show()

        if event.type() == QEvent.MouseButtonPress:
            # item context menu #
            if event.button() == Qt.MiddleButton:
                
                object.parent().info.hide()
                object.parent().allInfo.hide()
                object.parent().kanjiInfo.hide()
                
                script = scripts.script_boundaries(object.text())
                resulting_info = u''
#                kanji_groups = {}
                kanji_groups = OrderedDict()
    
                for cluster in script:
                    if scripts.script_type(cluster) == scripts.Script.Kanji:
#                        for kanji in cluster[::-1]:
                        for kanji in cluster:
                            similar = object.parent().groups.findSimilarKanji(kanji)
                            try:
                                kanji_groups[kanji] = similar[:similar.index(kanji)] + similar[similar.index(kanji) + 1:] 
                            except Exception:
                                kanji_groups[kanji] = object.parent().groups.findSimilarKanji(kanji)
                                log.debug(u'Not in group: ' + kanji)
                            
                for kanji in kanji_groups:
#                for kanji in list(reversed(sorted(kanji_groups.keys()))):
                    resulting_info += kanji + u' ~\t'
                    for item in kanji_groups[kanji]:
                        lookup = object.parent().kjd[item]
                        resulting_info += " " + item + " <font style='font-family: Calibri; font-size: 12pt'>(" + lookup.gloss[0] + ")</font> "
                    resulting_info += '<br/>'
                
                if resulting_info == u'': resulting_info = u'No such groups in Kanji.Odyssey!'
                object.parent().kanjiGroups.info.setText(resulting_info)
                
                object.parent().kanjiGroups.show()
                
            # kanji info #
            if event.button() == Qt.RightButton:
                    
                object.parent().info.hide()
                object.parent().allInfo.hide()
                object.parent().kanjiGroups.hide()
                
                object.parent().kanjiInfo.info.setText(u'')
                
                script = scripts.script_boundaries(object.text())
                resulting_info = u''
    
                for cluster in script:
                    if scripts.script_type(cluster) == scripts.Script.Kanji:
                        for kanji in cluster:
                            try:
                                lookup = object.parent().kjd[kanji]
                                kun = lookup.kun_readings; on = lookup.on_readings; gloss = lookup.gloss
                                
                                resulting_info += "<font style='font-family: " + Fonts.HiragiNoMyoutyouProW3 + "; font-size: 16.5pt'>(" + kanji + ")</font>\t"
                            
                                if len(kun) > 0:
                                    resulting_info += '<b>kun: </b>' + ', '.join(kun) + '\t'
                                if len(on) > 0:
                                    resulting_info += '<b>on:</b>' + ', '.join(on) + '<br/>'
                                if len(gloss) > 0:
                                    resulting_info += "<font style='font-family: Calibri; font-size: 12pt'>" + ", ".join(gloss) + "</font><br/>"
                            except:
                                components += kanji + '<br/>'
                
                if resulting_info != '':  
                    if resulting_info.count('<br/>') > 7:  object.parent().kanjiInfo.setStyleSheet('QLabel { font-size: 13pt }')
                    object.parent().kanjiInfo.info.setText(resulting_info.rstrip('<br/>'))
                    
                else: object.parent().kanjiInfo.info.setText(u'No such kanji in kanjidic!')
                object.parent().kanjiInfo.show()
                
            # translation and strokes info #
            if event.button() == Qt.LeftButton:
                
                object.parent().kanjiInfo.hide()
                object.parent().info.hide()
                object.parent().kanjiGroups.hide()
                              
                unfillLayout(object.parent().allInfo.layout)
                object.parent().allInfo.layout.setMargin(1)
                
                kanjiList = []
                script = scripts.script_boundaries(object.text())

                for cluster in script:
                    if scripts.script_type(cluster) == scripts.Script.Kanji:
                        for kanji in cluster:
                            kanjiList.append(kanji)
                
                i=0; j=0;
                # kanji strokes
                if len(kanjiList) > 0:
                    
                    infile = open(PATH_TO_RES + STROKES + KANJI_MANIFEST, 'r')
                    text = infile.read()
                    infile.close()
                    
                    for kanji in kanjiList:
                        
                        if( text.find(kanji.encode('utf-8').encode('hex')) != -1):
                        
                            gif = QLabel()
                            gif.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)        
                            gif.setAlignment(Qt.AlignCenter) 
    
                            movie = QMovie(PATH_TO_RES + STROKES + kanji.encode('utf-8').encode('hex') + '.gif', QByteArray(), self) 
                            movie.setCacheMode(QMovie.CacheAll) 
                            movie.setSpeed(150) 

                            gif.setMovie(movie)
                            object.parent().allInfo.layout.addWidget(gif, i, j);   j = j + 1
                            movie.start()
                              
                    i = i + 1
                
                # words translation
                translations = QLabel(u'')
                translations.setFont(QFont('Calibri', 11))
                translations.setWordWrap(True)
                translations.setAlignment(Qt.AlignCenter)
                try:
                    search = object.parent().edict[object.parent().srs.getWordNonInflectedForm(object.text())]

                    translationText = u''
                    
                    variants = search.senses_by_reading()[object.parent().srs.getWordPronounciation(object.parent().srs.getWordNonInflectedForm(object.text()))][:3]
                    variants = filter (lambda e: e != '(P)', variants)                                                                         
                    
                    translationText += '<b>' + object.parent().srs.getWordPronunciationFromExample(object.text()) + '</b>:\t' + ', '.join(variants)
                    translations.setText(translationText.rstrip('\n'))
                    
                except:
                    ### by reading
                    search = object.parent().jmdict.lookupTranslationByReadingJoin(object.parent().srs.getWordPronounciation(object.parent().srs.getWordNonInflectedForm(object.text())), object.parent().options.getLookupLang())
                    if len(search) > 0:
                        if len(search) > 5: search = search[:5]
                        translations.setText('<b>' + object.parent().srs.getWordPronunciationFromExample(object.text())+ '</b>:\t' + ', '.join(search))
                    ### by kanji
                    else:
                        search = object.parent().jmdict.lookupItemByReading(object.parent().srs.getWordPronounciation(object.parent().srs.getWordNonInflectedForm(object.text())))
                        if len(search) > 0:
                            lookup = object.parent().jmdict.lookupItemTranslationJoin(search[0], object.parent().options.getLookupLang())
                            if len(lookup) > 5: lookup = lookup[:5]
                            translations.setText('<b>' + object.parent().srs.getWordPronunciationFromExample(object.text())+ '</b>:\t' + ', '.join(lookup))
                    ### nothing found
                    if len(search) == 0: translations.setText(u'Alas, no translation in edict or jmdict!')
                
                if i > 0:
                    separator = QFrame()
                    separator.setFrameShape(QFrame.HLine)
                    separator.setFrameShadow(QFrame.Sunken)
                    object.parent().allInfo.layout.addWidget(separator, i, 0, 1, j);   i = i + 1
                
                object.parent().allInfo.layout.addWidget(translations, i, 0, 1, j)
                
                object.parent().allInfo.update()
                object.parent().allInfo.show()
                
            elif object.parent().allInfo.isVisible():

                object.parent().allInfo.hide()   
                object.parent().info.show()
            
        return False
Пример #5
0
    
    about = About()
    options = OptionsDialog(quiz.srs.db, quiz.srs.db.frequency, quiz.options)
    #qdict = QuickDictionary(quiz.jmdict, quiz.edict, quiz.kjd, quiz.srs.db, quiz.options)
        
    #updater = BackgroundDownloader(quiz.options.getRepetitionInterval())
    #updater.start()
    qdict = (); updater = ()
    
    quiz.addReferences(about, options, qdict, updater)
#    quiz.initGlobalHotkeys() 
    
    try:
        sys.exit(app.exec_())
    except Exception, e:
        log.debug(e)
                    
#    test = TatoebaLookup()
#    #test.parseTatoebaExamples()
#    test.loadExamplesFromPickled()
#    results = test.lookupExactWorld('to')
#    pass

#===============================================================================
#    from datetime import datetime
# 
#    start = datetime.now()
#    
#    test = FrequencyLookup()
#    test.parseXLSXSource()
#    
Пример #6
0
    about = About()
    options = OptionsDialog(quiz.srs.db, quiz.srs.db.frequency, quiz.options)
    #qdict = QuickDictionary(quiz.jmdict, quiz.edict, quiz.kjd, quiz.srs.db, quiz.options)

    #updater = BackgroundDownloader(quiz.options.getRepetitionInterval())
    #updater.start()
    qdict = ()
    updater = ()

    quiz.addReferences(about, options, qdict, updater)
    #    quiz.initGlobalHotkeys()

    try:
        sys.exit(app.exec_())
    except Exception, e:
        log.debug(e)

#    test = TatoebaLookup()
#    #test.parseTatoebaExamples()
#    test.loadExamplesFromPickled()
#    results = test.lookupExactWorld('to')
#    pass

#===============================================================================
#    from datetime import datetime
#
#    start = datetime.now()
#
#    test = FrequencyLookup()
#    test.parseXLSXSource()
#