[Sugar-devel] [PATCH] Bring back dragging of elements from the activities to the frame clipboard - SL #3819

2013-04-08 Thread Manuel Quiñones
TestCase:

- open an activity like Browse, Read, Log (not Write, is a special case)
- bring up the frame
- drag things to the left side panel of the frame (images, links, or selected 
text)

The elements should be added to the clipboard which is inside the
panel.  They should have the proper icon and they should popup a
palette to act on them.

Note: if the dragged object is a link from Browse, Sugar tries to copy
the html to the disk.  But the current implementation looks wrong.  I
have opened #4477 to track it: http://bugs.sugarlabs.org/ticket/4477

Note: this doesn't solve the inverse operation: drag from the
clipboard to the activity.  This will be done in another patch.

API fixes:

- gtk.SelectionData.type  ->  Gtk.SelectionData.get_data_type() [1]
- gtk.SelectionData.data  ->  Gtk.SelectionData.get_data() [2]
- gtk.SelectionData.target  ->  Gtk.SelectionData.get_target() [3]
- context.targets  ->  context.list_targets() [4]
- context.drop_finish(...)  ->  Gdk.drop_finish(context, ...) [5]
- context.drag_status(...)  ->  Gdk.drag_status(context, ...) [6]
- context.get_source_widget()  ->  Gdk.drag_get_source_widget(context) [7]

[1] 
https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-data-type
[2] 
https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-data
[3] 
https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-target
[4] 
https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drag-context-list-targets
[5] 
https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drop-finish
[6] 
https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drag-status
[7] 
https://developer.gnome.org/gtk3/stable/gtk3-Drag-and-Drop.html#gtk-drag-get-source-widget

Cast the type of the Gtk.SelectionData from Gdk.Atom to str.  Our code
treats it as str in sugar3.mime and asks methods like startswith which
fails if it is not a str-like object.

The data for the type 'text/uri-list' comes with a character '\x00' at
the end now.  But using SelectionData.get_uris() returns a proper list
(thanks to Flavio Danesse for the recommendation).  So we can use that
list instead of doing selection.get_data().split('\n') or
sugar3.mime.split_uri_list (which could be obsolete now).  In fact,
this change was made a while ago in clipboardpanelwindow.py, but not
in clipboardtray.py.  See commit f0d194f3 .

Signed-off-by: Manuel Quiñones 
---
 src/jarabe/frame/clipboardmenu.py|  4 ++--
 src/jarabe/frame/clipboardobject.py  |  4 ++--
 src/jarabe/frame/clipboardpanelwindow.py |  2 +-
 src/jarabe/frame/clipboardtray.py| 41 +++-
 4 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/src/jarabe/frame/clipboardmenu.py 
b/src/jarabe/frame/clipboardmenu.py
index e6766fb..eef3861 100644
--- a/src/jarabe/frame/clipboardmenu.py
+++ b/src/jarabe/frame/clipboardmenu.py
@@ -195,7 +195,7 @@ class ClipboardMenu(Palette):
 
 transfer_ownership = False
 if most_significant_mime_type == 'text/uri-list':
-uris = mime.split_uri_list(format_.get_data())
+uris = format_.get_uris()
 if len(uris) == 1 and uris[0].startswith('file://'):
 parsed_url = urlparse.urlparse(uris[0])
 file_path = parsed_url.path  # pylint: disable=E1101
@@ -207,7 +207,7 @@ class ClipboardMenu(Palette):
 mime_type = 'text/uri-list'
 else:
 if format_.is_on_disk():
-parsed_url = urlparse.urlparse(format_.get_data())
+parsed_url = urlparse.urlparse(format_.get_uris()[0])
 file_path = parsed_url.path  # pylint: disable=E1101
 transfer_ownership = False
 mime_type = mime.get_for_file(file_path)
diff --git a/src/jarabe/frame/clipboardobject.py 
b/src/jarabe/frame/clipboardobject.py
index e79fa46..5a3c9fe 100644
--- a/src/jarabe/frame/clipboardobject.py
+++ b/src/jarabe/frame/clipboardobject.py
@@ -103,8 +103,8 @@ class ClipboardObject(object):
 
 format_ = mime.choose_most_significant(self._formats.keys())
 if format_ == 'text/uri-list':
-data = self._formats['text/uri-list'].get_data()
-uri = urlparse.urlparse(mime.split_uri_list(data)[0], 'file')
+uris = self._formats[format_].get_uris()
+uri = urlparse.urlparse(uris[0], 'file')
 scheme = uri.scheme  # pylint: disable=E1101
 if scheme == 'file':
 path = uri.path  # pylint: disable=E1101
diff --git a/src/jarabe/frame/clipboardpanelwindow.py 
b/src/jarabe/frame/clipboardpanelwindow.py
index ba86775..14b5f5d 100644
--- a/src/jarabe/frame/clipboardpanelwindow.py
+++ b/src/jarabe/frame/clipboardpanelwindow.py
@@ -79,7 +79,7 @@ class ClipboardPanelWindow(FrameWindow):
 cb_selections.append(selection)
 
 if target_is_uri:
-uri = selection.get_data(

Re: [Sugar-devel] [PATCH] Bring back dragging of elements from the activities to the frame clipboard - SL #3819

2013-04-08 Thread Manuel Quiñones
2013/4/4 Manuel Quiñones :
> 2013/4/4 Flavio Danesse :
>> Actually if you for example:
>>
>> selection.get_uris (* args, ** kwargs)
>>
>> will return a list of uris in selection, so if no uris it will return an
>> empty list, then do not even need to know what type of data is in selection.
>
> Excellent Flavio!  I have to try it.  This will simplify the code a
> lot as you say.

I confirmed get_uris() made the trick.  In fact one py file was fixed
a while ago in 2007, but not the others.

--
.. manuq ..
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


Re: [Sugar-devel] [PATCH] Bring back dragging of elements from the activities to the frame clipboard - SL #3819

2013-04-04 Thread Manuel Quiñones
2013/4/4 Flavio Danesse :
> Actually if you for example:
>
> selection.get_uris (* args, ** kwargs)
>
> will return a list of uris in selection, so if no uris it will return an
> empty list, then do not even need to know what type of data is in selection.

Excellent Flavio!  I have to try it.  This will simplify the code a
lot as you say.


--
.. manuq ..
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


Re: [Sugar-devel] [PATCH] Bring back dragging of elements from the activities to the frame clipboard - SL #3819

2013-04-04 Thread Flavio Danesse
Actually if you for example:

selection.get_uris (* args, ** kwargs)

will return a list of uris in selection, so if no uris it will return an
empty list, then do not even need to know what type of data is in selection.


2013/4/4 Flavio Danesse 

> Manuel, I think this code can be improved and greatly simplified if
> instead of using things like:
>
> selection_data.split uris = ('\ n')
>
> use:
>
> uris = selection.get_uris ()
>
> Instead of using:
>
> selection.get_data (* args, ** kwargs)
>
> You can work directly on selection and get the data type with:
>
> selection.get_data_type (* args, ** kwargs)
>
> and get straight to the content:
>
> selection.get_pixbuf (* args, ** kwargs)
> selection.get_text (* args, ** kwargs)
> selection.get_uris (* args, ** kwargs)
>
>
> 2013/4/4 Manuel Quiñones 
>
>> Note I have also applied this as a pull request to the github experiment:
>>
>> https://github.com/sugarlabs/sugar/pull/14
>>
>> 2013/4/4 Manuel Quiñones :
>> > TestCase:
>> >
>> > - open an activity like Browse, Read, Log (not Write, is a special case)
>> > - bring up the frame
>> > - drag things to the left side panel of the frame (images, links, or
>> selected text)
>> >
>> > The elements should be added to the clipboard which is inside the
>> > panel.  They should have the proper icon and they should popup a
>> > palette to act on them.
>> >
>> > Note: if the dragged object is a link from Browse, Sugar tries to copy
>> > the html to the disk.  But the current implementation looks wrong.  I
>> > have opened #4477 to track it: http://bugs.sugarlabs.org/ticket/4477
>> >
>> > Note: this doesn't solve the inverse operation: drag from the
>> > clipboard to the activity.  This will be done in another patch.
>> >
>> > API fixes:
>> >
>> > - gtk.SelectionData.type  ->  Gtk.SelectionData.get_data_type() [1]
>> > - gtk.SelectionData.data  ->  Gtk.SelectionData.get_data() [2]
>> > - gtk.SelectionData.target  ->  Gtk.SelectionData.get_target() [3]
>> > - context.targets  ->  context.list_targets() [4]
>> > - context.drop_finish(...)  ->  Gdk.drop_finish(context, ...) [5]
>> > - context.drag_status(...)  ->  Gdk.drag_status(context, ...) [6]
>> > - context.get_source_widget()  ->  Gdk.drag_get_source_widget(context)
>> [7]
>> >
>> > [1]
>> https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-data-type
>> > [2]
>> https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-data
>> > [3]
>> https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-target
>> > [4]
>> https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drag-context-list-targets
>> > [5]
>> https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drop-finish
>> > [6]
>> https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drag-status
>> > [7]
>> https://developer.gnome.org/gtk3/stable/gtk3-Drag-and-Drop.html#gtk-drag-get-source-widget
>> >
>> > Cast the type of the Gtk.SelectionData from Gdk.Atom to str.  Our code
>> > treats it as str in sugar3.mime and asks methods like startswith which
>> > fails if it is not a str-like object.
>> >
>> > The data for the type 'text/uri-list' comes with a character '\x00' at
>> > the end now.  Remove it so our functions like
>> > sugar3.mime.split_uri_list don't break.
>> >
>> > Signed-off-by: Manuel Quiñones 
>> > ---
>> >  src/jarabe/frame/clipboardtray.py | 46
>> +--
>> >  1 file changed, 30 insertions(+), 16 deletions(-)
>> >
>> > diff --git a/src/jarabe/frame/clipboardtray.py
>> b/src/jarabe/frame/clipboardtray.py
>> > index abc885e..5115d61 100644
>> > --- a/src/jarabe/frame/clipboardtray.py
>> > +++ b/src/jarabe/frame/clipboardtray.py
>> > @@ -76,26 +76,39 @@ class ClipboardTray(tray.VTray):
>> >  return False
>> >
>> >  def _add_selection(self, object_id, selection):
>> > -if not selection.data:
>> > +if not selection.get_data():
>> >  return
>> >
>> > -logging.debug('ClipboardTray: adding type %r', selection.type)
>> > +selection_data = selection.get_data()
>> > +selection_type = selection.get_data_type()
>> > +
>> > +# The type comes as a Gdk.Atom but we need it as str to
>> > +# compare it.
>> > +assert isinstance(selection_type, Gdk.Atom)
>> > +selection_type = str(selection_type)
>> > +
>> > +logging.debug('ClipboardTray: adding type %r', selection_type)
>> >
>> >  cb_service = clipboard.get_instance()
>> > -if selection.type == 'text/uri-list':
>> > -uris = selection.data.split('\n')
>> > +if selection_type == 'text/uri-list':
>> > +# For 'text/uri-list' type, last character is '\x00'.  This
>> > +# wasn't the case in GTK2.
>> > +assert selection_data[-1] == '\x00'
>> > +selection_data = selection_data[:-1]
>> > +
>> > +uris = selection_data.split('\n')
>> > 

Re: [Sugar-devel] [PATCH] Bring back dragging of elements from the activities to the frame clipboard - SL #3819

2013-04-04 Thread Flavio Danesse
Manuel, I think this code can be improved and greatly simplified if instead
of using things like:

selection_data.split uris = ('\ n')

use:

uris = selection.get_uris ()

Instead of using:

selection.get_data (* args, ** kwargs)

You can work directly on selection and get the data type with:

selection.get_data_type (* args, ** kwargs)

and get straight to the content:

selection.get_pixbuf (* args, ** kwargs)
selection.get_text (* args, ** kwargs)
selection.get_uris (* args, ** kwargs)


2013/4/4 Manuel Quiñones 

> Note I have also applied this as a pull request to the github experiment:
>
> https://github.com/sugarlabs/sugar/pull/14
>
> 2013/4/4 Manuel Quiñones :
> > TestCase:
> >
> > - open an activity like Browse, Read, Log (not Write, is a special case)
> > - bring up the frame
> > - drag things to the left side panel of the frame (images, links, or
> selected text)
> >
> > The elements should be added to the clipboard which is inside the
> > panel.  They should have the proper icon and they should popup a
> > palette to act on them.
> >
> > Note: if the dragged object is a link from Browse, Sugar tries to copy
> > the html to the disk.  But the current implementation looks wrong.  I
> > have opened #4477 to track it: http://bugs.sugarlabs.org/ticket/4477
> >
> > Note: this doesn't solve the inverse operation: drag from the
> > clipboard to the activity.  This will be done in another patch.
> >
> > API fixes:
> >
> > - gtk.SelectionData.type  ->  Gtk.SelectionData.get_data_type() [1]
> > - gtk.SelectionData.data  ->  Gtk.SelectionData.get_data() [2]
> > - gtk.SelectionData.target  ->  Gtk.SelectionData.get_target() [3]
> > - context.targets  ->  context.list_targets() [4]
> > - context.drop_finish(...)  ->  Gdk.drop_finish(context, ...) [5]
> > - context.drag_status(...)  ->  Gdk.drag_status(context, ...) [6]
> > - context.get_source_widget()  ->  Gdk.drag_get_source_widget(context)
> [7]
> >
> > [1]
> https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-data-type
> > [2]
> https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-data
> > [3]
> https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-target
> > [4]
> https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drag-context-list-targets
> > [5]
> https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drop-finish
> > [6]
> https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drag-status
> > [7]
> https://developer.gnome.org/gtk3/stable/gtk3-Drag-and-Drop.html#gtk-drag-get-source-widget
> >
> > Cast the type of the Gtk.SelectionData from Gdk.Atom to str.  Our code
> > treats it as str in sugar3.mime and asks methods like startswith which
> > fails if it is not a str-like object.
> >
> > The data for the type 'text/uri-list' comes with a character '\x00' at
> > the end now.  Remove it so our functions like
> > sugar3.mime.split_uri_list don't break.
> >
> > Signed-off-by: Manuel Quiñones 
> > ---
> >  src/jarabe/frame/clipboardtray.py | 46
> +--
> >  1 file changed, 30 insertions(+), 16 deletions(-)
> >
> > diff --git a/src/jarabe/frame/clipboardtray.py
> b/src/jarabe/frame/clipboardtray.py
> > index abc885e..5115d61 100644
> > --- a/src/jarabe/frame/clipboardtray.py
> > +++ b/src/jarabe/frame/clipboardtray.py
> > @@ -76,26 +76,39 @@ class ClipboardTray(tray.VTray):
> >  return False
> >
> >  def _add_selection(self, object_id, selection):
> > -if not selection.data:
> > +if not selection.get_data():
> >  return
> >
> > -logging.debug('ClipboardTray: adding type %r', selection.type)
> > +selection_data = selection.get_data()
> > +selection_type = selection.get_data_type()
> > +
> > +# The type comes as a Gdk.Atom but we need it as str to
> > +# compare it.
> > +assert isinstance(selection_type, Gdk.Atom)
> > +selection_type = str(selection_type)
> > +
> > +logging.debug('ClipboardTray: adding type %r', selection_type)
> >
> >  cb_service = clipboard.get_instance()
> > -if selection.type == 'text/uri-list':
> > -uris = selection.data.split('\n')
> > +if selection_type == 'text/uri-list':
> > +# For 'text/uri-list' type, last character is '\x00'.  This
> > +# wasn't the case in GTK2.
> > +assert selection_data[-1] == '\x00'
> > +selection_data = selection_data[:-1]
> > +
> > +uris = selection_data.split('\n')
> >  if len(uris) > 1:
> >  raise NotImplementedError('Multiple uris in
> text/uri-list' \
> >' still not supported.')
> >
> >  cb_service.add_object_format(object_id,
> > - selection.type,
> > + selection_type,
> >   

Re: [Sugar-devel] [PATCH] Bring back dragging of elements from the activities to the frame clipboard - SL #3819

2013-04-04 Thread Manuel Quiñones
Note I have also applied this as a pull request to the github experiment:

https://github.com/sugarlabs/sugar/pull/14

2013/4/4 Manuel Quiñones :
> TestCase:
>
> - open an activity like Browse, Read, Log (not Write, is a special case)
> - bring up the frame
> - drag things to the left side panel of the frame (images, links, or selected 
> text)
>
> The elements should be added to the clipboard which is inside the
> panel.  They should have the proper icon and they should popup a
> palette to act on them.
>
> Note: if the dragged object is a link from Browse, Sugar tries to copy
> the html to the disk.  But the current implementation looks wrong.  I
> have opened #4477 to track it: http://bugs.sugarlabs.org/ticket/4477
>
> Note: this doesn't solve the inverse operation: drag from the
> clipboard to the activity.  This will be done in another patch.
>
> API fixes:
>
> - gtk.SelectionData.type  ->  Gtk.SelectionData.get_data_type() [1]
> - gtk.SelectionData.data  ->  Gtk.SelectionData.get_data() [2]
> - gtk.SelectionData.target  ->  Gtk.SelectionData.get_target() [3]
> - context.targets  ->  context.list_targets() [4]
> - context.drop_finish(...)  ->  Gdk.drop_finish(context, ...) [5]
> - context.drag_status(...)  ->  Gdk.drag_status(context, ...) [6]
> - context.get_source_widget()  ->  Gdk.drag_get_source_widget(context) [7]
>
> [1] 
> https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-data-type
> [2] 
> https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-data
> [3] 
> https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-target
> [4] 
> https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drag-context-list-targets
> [5] 
> https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drop-finish
> [6] 
> https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drag-status
> [7] 
> https://developer.gnome.org/gtk3/stable/gtk3-Drag-and-Drop.html#gtk-drag-get-source-widget
>
> Cast the type of the Gtk.SelectionData from Gdk.Atom to str.  Our code
> treats it as str in sugar3.mime and asks methods like startswith which
> fails if it is not a str-like object.
>
> The data for the type 'text/uri-list' comes with a character '\x00' at
> the end now.  Remove it so our functions like
> sugar3.mime.split_uri_list don't break.
>
> Signed-off-by: Manuel Quiñones 
> ---
>  src/jarabe/frame/clipboardtray.py | 46 
> +--
>  1 file changed, 30 insertions(+), 16 deletions(-)
>
> diff --git a/src/jarabe/frame/clipboardtray.py 
> b/src/jarabe/frame/clipboardtray.py
> index abc885e..5115d61 100644
> --- a/src/jarabe/frame/clipboardtray.py
> +++ b/src/jarabe/frame/clipboardtray.py
> @@ -76,26 +76,39 @@ class ClipboardTray(tray.VTray):
>  return False
>
>  def _add_selection(self, object_id, selection):
> -if not selection.data:
> +if not selection.get_data():
>  return
>
> -logging.debug('ClipboardTray: adding type %r', selection.type)
> +selection_data = selection.get_data()
> +selection_type = selection.get_data_type()
> +
> +# The type comes as a Gdk.Atom but we need it as str to
> +# compare it.
> +assert isinstance(selection_type, Gdk.Atom)
> +selection_type = str(selection_type)
> +
> +logging.debug('ClipboardTray: adding type %r', selection_type)
>
>  cb_service = clipboard.get_instance()
> -if selection.type == 'text/uri-list':
> -uris = selection.data.split('\n')
> +if selection_type == 'text/uri-list':
> +# For 'text/uri-list' type, last character is '\x00'.  This
> +# wasn't the case in GTK2.
> +assert selection_data[-1] == '\x00'
> +selection_data = selection_data[:-1]
> +
> +uris = selection_data.split('\n')
>  if len(uris) > 1:
>  raise NotImplementedError('Multiple uris in text/uri-list' \
>' still not supported.')
>
>  cb_service.add_object_format(object_id,
> - selection.type,
> + selection_type,
>   uris[0],
>   on_disk=True)
>  else:
>  cb_service.add_object_format(object_id,
> - selection.type,
> - selection.data,
> + selection_type,
> + selection_data,
>   on_disk=False)
>
>  def _object_added_cb(self, cb_service, cb_object):
> @@ -132,9 +145,9 @@ class ClipboardTray(tray.VTray):
>  logging.debug('ClipboardTray._drag_motion_cb')
>
>  if self._internal_drag(context):
> -context.dr

[Sugar-devel] [PATCH] Bring back dragging of elements from the activities to the frame clipboard - SL #3819

2013-04-04 Thread Manuel Quiñones
TestCase:

- open an activity like Browse, Read, Log (not Write, is a special case)
- bring up the frame
- drag things to the left side panel of the frame (images, links, or selected 
text)

The elements should be added to the clipboard which is inside the
panel.  They should have the proper icon and they should popup a
palette to act on them.

Note: if the dragged object is a link from Browse, Sugar tries to copy
the html to the disk.  But the current implementation looks wrong.  I
have opened #4477 to track it: http://bugs.sugarlabs.org/ticket/4477

Note: this doesn't solve the inverse operation: drag from the
clipboard to the activity.  This will be done in another patch.

API fixes:

- gtk.SelectionData.type  ->  Gtk.SelectionData.get_data_type() [1]
- gtk.SelectionData.data  ->  Gtk.SelectionData.get_data() [2]
- gtk.SelectionData.target  ->  Gtk.SelectionData.get_target() [3]
- context.targets  ->  context.list_targets() [4]
- context.drop_finish(...)  ->  Gdk.drop_finish(context, ...) [5]
- context.drag_status(...)  ->  Gdk.drag_status(context, ...) [6]
- context.get_source_widget()  ->  Gdk.drag_get_source_widget(context) [7]

[1] 
https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-data-type
[2] 
https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-data
[3] 
https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-target
[4] 
https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drag-context-list-targets
[5] 
https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drop-finish
[6] 
https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drag-status
[7] 
https://developer.gnome.org/gtk3/stable/gtk3-Drag-and-Drop.html#gtk-drag-get-source-widget

Cast the type of the Gtk.SelectionData from Gdk.Atom to str.  Our code
treats it as str in sugar3.mime and asks methods like startswith which
fails if it is not a str-like object.

The data for the type 'text/uri-list' comes with a character '\x00' at
the end now.  Remove it so our functions like
sugar3.mime.split_uri_list don't break.

Signed-off-by: Manuel Quiñones 
---
 src/jarabe/frame/clipboardtray.py | 46 +--
 1 file changed, 30 insertions(+), 16 deletions(-)

diff --git a/src/jarabe/frame/clipboardtray.py 
b/src/jarabe/frame/clipboardtray.py
index abc885e..5115d61 100644
--- a/src/jarabe/frame/clipboardtray.py
+++ b/src/jarabe/frame/clipboardtray.py
@@ -76,26 +76,39 @@ class ClipboardTray(tray.VTray):
 return False
 
 def _add_selection(self, object_id, selection):
-if not selection.data:
+if not selection.get_data():
 return
 
-logging.debug('ClipboardTray: adding type %r', selection.type)
+selection_data = selection.get_data()
+selection_type = selection.get_data_type()
+
+# The type comes as a Gdk.Atom but we need it as str to
+# compare it.
+assert isinstance(selection_type, Gdk.Atom)
+selection_type = str(selection_type)
+
+logging.debug('ClipboardTray: adding type %r', selection_type)
 
 cb_service = clipboard.get_instance()
-if selection.type == 'text/uri-list':
-uris = selection.data.split('\n')
+if selection_type == 'text/uri-list':
+# For 'text/uri-list' type, last character is '\x00'.  This
+# wasn't the case in GTK2.
+assert selection_data[-1] == '\x00'
+selection_data = selection_data[:-1]
+
+uris = selection_data.split('\n')
 if len(uris) > 1:
 raise NotImplementedError('Multiple uris in text/uri-list' \
   ' still not supported.')
 
 cb_service.add_object_format(object_id,
- selection.type,
+ selection_type,
  uris[0],
  on_disk=True)
 else:
 cb_service.add_object_format(object_id,
- selection.type,
- selection.data,
+ selection_type,
+ selection_data,
  on_disk=False)
 
 def _object_added_cb(self, cb_service, cb_object):
@@ -132,9 +145,9 @@ class ClipboardTray(tray.VTray):
 logging.debug('ClipboardTray._drag_motion_cb')
 
 if self._internal_drag(context):
-context.drag_status(Gdk.DragAction.MOVE, time)
+Gdk.drag_status(context, Gdk.DragAction.MOVE, time)
 else:
-context.drag_status(Gdk.DragAction.COPY, time)
+Gdk.drag_status(context, Gdk.DragAction.COPY, time)
 self.props.drag_active = True
 
 return True
@@ -148,15 +161,16 @@ class ClipboardTray(tr