[Sugar-devel] Cannot write a function definition for a copy button.

Sebastian Silva sebastian at fuentelibre.org
Sun Apr 19 10:31:06 EDT 2015


On 19/04/15 05:10, Iain Brown Douglas wrote:
> Following a month of Learn Python the Hard Way, I cannot get an Edit
> Toolbar to behave fully correctly, in Activity Help, as modified for
> SoaS Loader.
Keep it up! This is exactly the way to learn and have fun.
It might be a good idea to also keep in mind that you are learning two
things at the same time: Python and GTK.
> I have tried (in various permutations) to make use of code borrowed from
> Terminal, Pippy, Develop, Browse, ReadETexts, and Write. I get stuck
> just writing a "vanilla" function definition for
>
> `__copy_cb`
>
> as in: `edit_toolbar.copy.connect('clicked', self.__copy_cb)` .
>
> What am I missing?
>
> This "fresh start" approach seems to demonstrate a "most naive" form of
> my error.
>
> I take Help-19 as my base (working with sugar-runner, on Fedora 20).
>
> I edit helpactivity.py adding 5 segments [1] of code I borrowed from
> Terminal and Pippy.
The third segment has a commented line in [2] (line 192), but not in [1].
This is the line where the object /text_buffer/ is created in the
original code.
Since in line 194, the code tries to access a method of this object, it
will fail because at this point in the code, /text_buffer /is None.
This will stop execution of the code and thus the hotkey does nothing.
>
> The resulting modified helpactivity.py is [2].
>
> For this example, no further debugging or "improvements".
>
> The Activity runs, and looks ok, the copy button works to the extent
> that the selected text can be pasted with the centre mouse button, but
> not with a Sugar Paste button (or Ctrl+Shift+V). When I press the "new"
> Copy button, no clipping shows in the Frame.
>
> The Debug error is:
>
> File "~/Activities/SugarTutorial.activity/helpactivity.py", line 194, in
> __copy_cb
>     text_buffer.copy_clipboard(clipboard)
> AttributeError: 'NoneType' object has no attribute 'copy_clipboard'
You need to find out what /text_buffer /is supposed to be.
My guess is that you need to ask your Webkit.WebView object
(instantiated as self._web_view in your code), what text is selected
(and put /that/ into text_buffer).
It is always good to have docs at hand, and also Q&A websites are good
for these kinds of details.
Here's a relevant question answered, and it seems Webkit is a little quirky:
http://stackoverflow.com/questions/14823892/whats-the-method-to-get-the-webkit-webviews-currently-selected-text
>
> I guess I am missing something very obvious, grateful if anyone could
> throw me a clue.
>
> With thanks,
Good luck!
> Iain
>
> [1] http://fpaste.org/212778/
> [2] http://ur1.ca/k7fir
>
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel

-- 
I+D SomosAzucar.Org
"icarito" #somosazucar en Freenode IRC
"Nadie libera a nadie, nadie se libera solo. Los seres humanos se liberan en comunión" - P. Freire

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20150419/9e016455/attachment.html>


More information about the Sugar-devel mailing list