Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling pgi.clib.glib.GSListPtr #43

Open
jim-easterbrook opened this issue Feb 26, 2018 · 4 comments
Open

Handling pgi.clib.glib.GSListPtr #43

jim-easterbrook opened this issue Feb 26, 2018 · 4 comments

Comments

@jim-easterbrook
Copy link

jim-easterbrook commented Feb 26, 2018

I've been experimenting with using the Gspell spell checking library from Python. The only difficulty I've encountered is with the value returned by Gspell.Checker.get_suggestions. When using PyGObject I get a Python list of strings, as expected. With pgi I get an object of type pgi.clib.glib.GSListPtr.

I've found a workaround as follows:

suggestions = checker.get_suggestions(word, -1)
result = []
for i in range(suggestions.length):
    c_str = ctypes.c_char_p(suggestions.nth_data(i))
    result.append(c_str.value.decode('utf_8'))
return result
@stuaxo
Copy link
Contributor

stuaxo commented Nov 2, 2018

Can you check if this is an issue for anything that would return a list of strings ?

(ie go, find some other APIs that would normally return lists of strings and see if they return GSListPtr instead) ?

Maybe some code like yours could be added to the right place in PGI if so.

@stuaxo
Copy link
Contributor

stuaxo commented Nov 2, 2018

@jim-easterbrook can you post a more complete example? I installed the GSpell gir bindings, but I'm not sure how to create the checker instance you have.

@jim-easterbrook
Copy link
Author

Here's a short script.

try:
    import pgi
    pgi.install_as_gi()
except ImportError:
    pass
import gi
gi.require_version('Gspell', '1')
from gi.repository import Gspell

check = Gspell.Checker.new(Gspell.Language.lookup('en'))
suggestions = check.get_suggestions('foo', -1)
print(type(suggestions))
print(suggestions)

Without pgi installed I get the following:

(process:11865): gspell-CRITICAL **: gspell_checker_add_word_to_session: assertion 'word != NULL' failed
<class 'list'>
['foo', 'goo', 'fop', 'foot', 'fool', 'food', 'foe', 'for', 'fro', 'too', 'fol', 'loo', 'coo', 'fog', 'moo']

With pgi I get this:

<class 'pgi.clib.glib.GSListPtr'>
<pgi.clib.glib.GSListPtr object at 0x7f554067a9d8>

I'm not familiar with many GObject APIs, I've only used Gspell and GExiv2 so far. I'm not sure how easy it'll be to find another that returns a list of strings.

@stuaxo
Copy link
Contributor

stuaxo commented Nov 3, 2018

That one is fine, I spent a bit of time trying to understand the pgi code generation the other day but am not really there.

Is plain gobject not an option under the environment you are running under?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants