raelgc / scudcloud

ScudCloud - Slack for Linux
https://launchpad.net/~rael-gc/+archive/ubuntu/scudcloud
MIT License
1.22k stars 99 forks source link

Mis-spelled word right-click action crashes ScudCloud in python 3.4 #537

Closed rsyring closed 7 years ago

rsyring commented 7 years ago

ScudCloud Version

Paste the output for scudcloud --version below:

ScudCloud 1.47
Python 3.4.3
Qt 4.8.6
PyQt 4.10.4
SIP 4.15.5

Distro and Desktop info

Expected behavior

Right click on mis-spelled word and get menu of correction options.

Actual behavior

Right click on mis-spelled word causes message from Ubuntu that Scudcloud has crashed. But, scudcloud itself doesn't actually crash, it continues to work, but spellchecking no longer works.

Steps to reproduce

  1. Right click on a misspelled word

Other

raelgc commented 7 years ago

Hi @rsyring and thanks for raising this.

The code for misspelling has not changed since several months ago.

Anyway, the difference in our environment is python version (I'm using 3.5).

Hope you find a consistent way to reproduce this. Wondering if it happens when you type a word that has no suggestions.

rsyring commented 7 years ago

Wondering if it happens when you type a word that has no suggestions.

Trying to find one...so frustrating. I'm typing gibberish and it still has ideas. :/

rsyring commented 7 years ago

Another interesting tidbit...I have three teams and two of them the spell checker work suggestions work. On the third one (level12 team), right-clicking on a mis-spelled word no longer brings up a menu. Nothing at all happens.

The console has some errors that the other team consoles don't have, not sure if it's related:

image

Oh, here you go, there is a traceback in the console:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/scudcloud/wrapper.py", line 69, in contextMenuEvent
    self.window.speller.populateContextMenu(menu, element)
  File "/usr/lib/python3/dist-packages/scudcloud/speller.py", line 77, in populateContextMenu
    word = self.getWord(element)
  File "/usr/lib/python3/dist-packages/scudcloud/speller.py", line 70, in getWord
    pos = int(int(element.evaluateJavaScript("this.selectionStart")) + int(1))
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
raelgc commented 7 years ago

The console errors are just Slack internal stuff, not related to this issue.

And this appears to happen only in python 3.4

Can you, please, replace the getWord method in speller.py

    def getWord(self, element):
        text = str(element.evaluateJavaScript("this.value"))
        pos = int(int(element.evaluateJavaScript("this.selectionStart")) + int(1))
        finder =  QTextBoundaryFinder(QTextBoundaryFinder.Word, text)
        finder.setPosition(pos)
        self.startPos = finder.toPreviousBoundary()
        return text[self.startPos:finder.toNextBoundary()].strip()

by below one?

    def getWord(self, element):
        text = str(element.evaluateJavaScript("this.value"))
        pos = 1
        jsPos = element.evaluateJavaScript("this.selectionStart")
        if jsPos is not None:
            pos = int(int(jsPos) + int(1))
        finder = QTextBoundaryFinder(QTextBoundaryFinder.Word, text)
        finder.setPosition(pos)
        self.startPos = finder.toPreviousBoundary()
        return text[self.startPos:finder.toNextBoundary()].strip()
rsyring commented 7 years ago

By replacing getWord() I now get a right-click menu, but it is the standard right click menu, but there are no suggestions. My other team still works fine. Examples below:

Working team:

image

Broken team:

image

I'm not sure if it matters, but I noticed that the broken team has a Fonts option in the right-click menu while the working team does not.

raelgc commented 7 years ago

For some reason, Python 3.4 is not returning the correct position of the mispelled word. Do you mind to try to install python 3.6 using the deadsnake PPA?

cajogos commented 7 years ago

Hey @raelgc I am getting the same, here's my scudcloud --version:

ScudCloud 1.52
Python 3.5.2
Qt 5.5.1
PyQt 5.5.1
SIP 4.17

I get the exact same Traceback when right clicking the text box.

raelgc commented 7 years ago

I'm working on a fix.

raelgc commented 7 years ago

Published for Ubuntu. Let me know if it's working now.

cajogos commented 7 years ago

@raelgc yep, right-click working again, thanks for the quick fix!

raelgc commented 7 years ago

I've made another fix to get the spell corrector working again. Let me know if after upgrade, this is still an issue.

cajogos commented 7 years ago

@raelgc Just to let you know the spellchecker works now as well. Thanks for the fix! :smile:

rsyring commented 7 years ago

This is still broken for me. The red squiggly does not show, but if I right-click on a word that I know is mis-spelled, I get an exception.

$ scudcloud --version
ScudCloud 1.56
Python 3.4.3
Qt 5.2.1
PyQt 5.2.1
SIP 4.15.5

Traceback:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/scudcloud/wrapper.py", line 71, in contextMenuEvent
    self.window.speller.populateContextMenu(menu, element)
  File "/usr/lib/python3/dist-packages/scudcloud/speller.py", line 91, in populateContextMenu
    word = self.getWord(element)
  File "/usr/lib/python3/dist-packages/scudcloud/speller.py", line 86, in getWord
    finder.setPosition(self._getSelectionStart(element) + 1)
  File "/usr/lib/python3/dist-packages/scudcloud/speller.py", line 81, in _getSelectionStart
    return int(element.evaluateJavaScript("document.getSelection().anchorOffset")) or 0
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

I've tried running it in Python 3.5 instead, but I get this message:

$ python3.5 /usr/lib/python3/dist-packages/scudcloud
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3/dist-packages/scudcloud/__main__.py", line 15, in <module>
    from scudcloud.resources import Resources
  File "/usr/lib/python3/dist-packages/scudcloud/scudcloud.py", line 1, in <module>
    from scudcloud.cookiejar import PersistentCookieJar
ImportError: No module named 'scudcloud.cookiejar'; 'scudcloud' is not a package
raelgc commented 7 years ago

@rsyring the package setup with Python 3.5 is not properly configured, according the error message. Maybe you should try, using python 3.5, run the setup again.