예제 #1
0
    def contextMenuEvent(self, event):
        popup_menu = self.createStandardContextMenu()
        pal = QApplication.instance().palette()
        # This fixes Issue 20
        menu_style = """ * { background-color: %s;
                                      color: %s;}
                                  """ % (
            unicode(pal.color(QPalette.Button).name()),
            unicode(pal.color(QPalette.WindowText).name()))
        popup_menu.setStyleSheet(menu_style)

        # Select the word under the cursor.
        cursor = self.textCursor()
        cursor.select(QTextCursor.WordUnderCursor)
        self.setTextCursor(cursor)

        # Check if the selected word is misspelled and offer spelling
        # suggestions if it is.
        if enchant and self.dict:
            if self.textCursor().hasSelection():
                text = unicode(self.textCursor().selectedText())
                if not self.dict.check(text):
                    spell_menu = QMenu(
                        QtCore.QCoreApplication.translate(
                            'app', 'Spelling Suggestions'), self)
                    spell_menu.setStyleSheet(menu_style)
                    for word in self.dict.suggest(text):
                        action = SpellAction(word, spell_menu)
                        action.correct.connect(self.correctWord)
                        spell_menu.addAction(action)
                    # Only add the spelling suggests to the menu if there are
                    # suggestions.
                    if len(spell_menu.actions()) != 0:
                        popup_menu.insertSeparator(popup_menu.actions()[0])
                        popup_menu.insertMenu(popup_menu.actions()[0],
                                              spell_menu)

        # FIXME: add change dict and disable spellcheck options

        popup_menu.exec_(event.globalPos())
예제 #2
0
    def contextMenuEvent(self, event):
        popup_menu = self.createStandardContextMenu()
        RightToLeft = 1;
        # Select the word under the cursor.
        cursor = self.textCursor()
        cursor.select(QTextCursor.WordUnderCursor)
        self.setTextCursor(cursor)
 
        # Check if the selected word is misspelled and offer spelling
        # suggestions if it is.
        if self.textCursor().hasSelection():
            #this is a workaround for QT bug when double click selects Arabic punctuation marks
        	# plus the word in the text editor see https://bugreports.qt-project.org/browse/QTBUG-42397
            orginaltext = unicode(self.textCursor().selectedText())
            arabicmarks = [u'؟',u'،',u'؛',u'“',u'”',u'‘',u'’']
            holder = orginaltext[-1]
            if holder in arabicmarks:
            	self.pretxt = holder
            else:
            	self.pretxt=''
            text = orginaltext.strip(u'؟،؛“”‘’')
            if not self.dict.check(text):
                spell_menu = QMenu(u'اقتراحات التشكيل')
                spell_menu.setLayoutDirection(RightToLeft)
                for word in self.dict.suggest(text):
                    action = SpellAction(word, spell_menu)
                    action.correct.connect(self.correctWord)
                    spell_menu.addAction(action)
                spell_menu.setStyleSheet("QMenu {font: 24px;  margin: 2px;}")						
                # Only add the spelling suggests to the menu if there are
                # suggestions.
                if len(spell_menu.actions()) != 0:
                    popup_menu.insertSeparator(popup_menu.actions()[0])
                    popup_menu.insertMenu(popup_menu.actions()[0], spell_menu)
 
        popup_menu.exec_(event.globalPos())
예제 #3
0
    def contextMenuEvent(self, event):
        popup_menu = self.createStandardContextMenu()
        pal=QApplication.instance().palette()
        # This fixes Issue 20
        menu_style=""" * { background-color: %s;
                                      color: %s;}
                                  """%(unicode(pal.color(QPalette.Button).name()),
                                        unicode(pal.color(QPalette.WindowText).name()))
        popup_menu.setStyleSheet(menu_style)
 
        # Select the word under the cursor.
        cursor = self.textCursor()
        cursor.select(QTextCursor.WordUnderCursor)
        self.setTextCursor(cursor)
 
        # Check if the selected word is misspelled and offer spelling
        # suggestions if it is.
        if enchant and self.dict:
            if self.textCursor().hasSelection():
                text = unicode(self.textCursor().selectedText())
                if not self.dict.check(text):
                    spell_menu = QMenu(QtCore.QCoreApplication.translate('app','Spelling Suggestions'), self)
                    spell_menu.setStyleSheet(menu_style)
                    for word in self.dict.suggest(text):
                        action = SpellAction(word, spell_menu)
                        action.correct.connect(self.correctWord)
                        spell_menu.addAction(action)
                    # Only add the spelling suggests to the menu if there are
                    # suggestions.
                    if len(spell_menu.actions()) != 0:
                        popup_menu.insertSeparator(popup_menu.actions()[0])
                        popup_menu.insertMenu(popup_menu.actions()[0], spell_menu)
                        
        # FIXME: add change dict and disable spellcheck options
 
        popup_menu.exec_(event.globalPos())
예제 #4
0
    def contextMenuEvent(self, event):
        popup_menu = self.createStandardContextMenu()
        RightToLeft = 1
        # Select the word under the cursor.
        cursor = self.textCursor()
        cursor.select(QTextCursor.WordUnderCursor)
        self.setTextCursor(cursor)

        # Check if the selected word is misspelled and offer spelling
        # suggestions if it is.
        if self.textCursor().hasSelection():
            #this is a workaround for QT bug when double click selects Arabic punctuation marks
            # plus the word in the text editor see https://bugreports.qt-project.org/browse/QTBUG-42397
            orginaltext = unicode(self.textCursor().selectedText())
            arabicmarks = [u'؟', u'،', u'؛', u'“', u'”', u'‘', u'’']
            holder = orginaltext[-1]
            if holder in arabicmarks:
                self.pretxt = holder
            else:
                self.pretxt = ''
            text = orginaltext.strip(u'؟،؛“”‘’')
            if not self.dict.check(text):
                spell_menu = QMenu(u'اقتراحات التشكيل')
                spell_menu.setLayoutDirection(RightToLeft)
                for word in self.dict.suggest(text):
                    action = SpellAction(word, spell_menu)
                    action.correct.connect(self.correctWord)
                    spell_menu.addAction(action)
                spell_menu.setStyleSheet("QMenu {font: 24px;  margin: 2px;}")
                # Only add the spelling suggests to the menu if there are
                # suggestions.
                if len(spell_menu.actions()) != 0:
                    popup_menu.insertSeparator(popup_menu.actions()[0])
                    popup_menu.insertMenu(popup_menu.actions()[0], spell_menu)

        popup_menu.exec_(event.globalPos())
예제 #5
0
    def contextMenuEvent(self, event):
        popup_menu = self.createStandardContextMenu()
        #~popup_menu = QMenu()
        #~self.setContextMenuPolicy()
        RightToLeft = 1;
        # Select the word under the cursor.
        cursor = self.textCursor()
        cursor.select(QTextCursor.WordUnderCursor)
        self.setTextCursor(cursor)
 
        # Check if the selected word is misspelled and offer spelling
        # suggestions if it is.
        if self.textCursor().hasSelection():
            

            
            #~text = (unicode(self.textCursor().selectedText()))
            #this is a workaround for QT bug when double click selects Arabic punctuation marks
            # plus the word in the text editor see https://bugreports.qt-project.org/browse/QTBUG-42397
            originaltext = unicode(self.textCursor().selectedText())
            
            arabicmarks = [u'؟',u'،',u'؛',u'“',u'”',u'‘',u'’']
            holder = originaltext[-1]
            if holder in arabicmarks:
                self.pretxt = holder
            else:
                self.pretxt=''
            text = originaltext.strip(u'؟،؛“”‘’')   

            # the word is aleady analyzed         
            if self.dict.check(text):
                spell_menu = QMenu(u'المزيد...')
                spell_menu.setLayoutDirection(RightToLeft)
                suggests = self.dict.suggest(text)
                for word in suggests[:10]:
                    action = SpellAction(word, spell_menu)
                    action.correct.connect(self.correctWord)
                    #~spell_menu.addAction(action)
                    popup_menu.addAction(action)

                    
                #~spell_menu.setStyleSheet("QMenu {font: 32px;  margin: 2px;}")
                popup_menu.setStyleSheet("QMenu {font: 24px;}")
                # Only add the spelling suggests to the menu if there are
                # suggestions.
                
                #~if len(spell_menu.actions()) != 0:
                    #~popup_menu.insertSeparator(popup_menu.actions()[0])
                    #~popup_menu.insertMenu(popup_menu.actions()[0], spell_menu)
                if len (suggests)>10:
                    for word in suggests[10:]:
                        action = SpellAction(word, spell_menu)
                        action.correct.connect(self.correctWord)
                        #~spell_menu.addAction(action)
                        spell_menu.addAction(action)                    
                    spell_menu.setStyleSheet("QMenu {font: 24px;}")
                    
                    popup_menu.addSeparator()
                    popup_menu.addMenu(spell_menu)
                
                if len(suggests) == 1 and not araby.is_vocalized(suggests[0]):
                    addtodict_action = popup_menu.addAction(u'أضف للقاموس')
                    #~addtodict_action.triggered.connect( lambda x = x = originaltext: self.add_to_dict(x))
                    addtodict_action.triggered.connect( lambda : self.add_to_dict(originaltext))
                    # if the word hs no suggestions
                    # we lookup for customized vocalization
                    suggests = self.dict.custom_dict.lookup(word)
                    for word in suggests:
                        action = SpellAction(word, spell_menu)
                        action.correct.connect(self.correctWord)
                        #~spell_menu.addAction(action)
                        popup_menu.addAction(action)                    
                    
                    
            else:
                # redo taskeel for this word
                #~pass;
                # if the word hs no suggestions
                # we lookup for customized vocalization
                suggests = self.dict.custom_dict.lookup(text)
                for word in suggests:
                    action = SpellAction(word, spell_menu)
                    action.correct.connect(self.correctWord)
                    #~spell_menu.addAction(action)
                    popup_menu.addAction(action)
        popup_menu.exec_(event.globalPos())
    def contextMenuEvent(self, event):
        popup_menu = self.createStandardContextMenu()
        #~popup_menu = QMenu()
        #~self.setContextMenuPolicy()
        RightToLeft = 1
        # Select the word under the cursor.
        cursor = self.textCursor()
        cursor.select(QTextCursor.WordUnderCursor)
        self.setTextCursor(cursor)

        # Check if the selected word is misspelled and offer spelling
        # suggestions if it is.
        if self.textCursor().hasSelection():

            #~text = (unicode(self.textCursor().selectedText()))
            #this is a workaround for QT bug when double click selects Arabic punctuation marks
            # plus the word in the text editor see https://bugreports.qt-project.org/browse/QTBUG-42397
            originaltext = unicode(self.textCursor().selectedText())

            arabicmarks = [u'؟', u'،', u'؛', u'“', u'”', u'‘', u'’']
            holder = originaltext[-1]
            if holder in arabicmarks:
                self.pretxt = holder
            else:
                self.pretxt = ''
            text = originaltext.strip(u'؟،؛“”‘’')

            # the word is aleady analyzed
            if self.dict.check(text):
                spell_menu = QMenu(u'المزيد...')
                spell_menu.setLayoutDirection(RightToLeft)
                suggests = self.dict.suggest(text)
                for word in suggests[:10]:
                    action = SpellAction(word, spell_menu)
                    action.correct.connect(self.correctWord)
                    #~spell_menu.addAction(action)
                    popup_menu.addAction(action)

                #~spell_menu.setStyleSheet("QMenu {font: 32px;  margin: 2px;}")
                popup_menu.setStyleSheet("QMenu {font: 24px;}")
                # Only add the spelling suggests to the menu if there are
                # suggestions.

                #~if len(spell_menu.actions()) != 0:
                #~popup_menu.insertSeparator(popup_menu.actions()[0])
                #~popup_menu.insertMenu(popup_menu.actions()[0], spell_menu)
                if len(suggests) > 10:
                    for word in suggests[10:]:
                        action = SpellAction(word, spell_menu)
                        action.correct.connect(self.correctWord)
                        #~spell_menu.addAction(action)
                        spell_menu.addAction(action)
                    spell_menu.setStyleSheet("QMenu {font: 24px;}")

                    popup_menu.addSeparator()
                    popup_menu.addMenu(spell_menu)

                if len(suggests) == 1 and not araby.is_vocalized(suggests[0]):
                    addtodict_action = popup_menu.addAction(u'أضف للقاموس')
                    #~addtodict_action.triggered.connect( lambda x = x = originaltext: self.add_to_dict(x))
                    addtodict_action.triggered.connect(
                        lambda: self.add_to_dict(originaltext))
                    # if the word hs no suggestions
                    # we lookup for customized vocalization
                    suggests = self.dict.custom_dict.lookup(word)
                    for word in suggests:
                        action = SpellAction(word, spell_menu)
                        action.correct.connect(self.correctWord)
                        #~spell_menu.addAction(action)
                        popup_menu.addAction(action)

            else:
                # redo taskeel for this word
                #~pass;
                # if the word hs no suggestions
                # we lookup for customized vocalization
                suggests = self.dict.custom_dict.lookup(text)
                for word in suggests:
                    action = SpellAction(word, spell_menu)
                    action.correct.connect(self.correctWord)
                    #~spell_menu.addAction(action)
                    popup_menu.addAction(action)
        popup_menu.exec_(event.globalPos())