[GTK] Fix drag and drop files in files_tab
Encoutered an error reordering files by dragging in the files tab: TypeError: can't pickle TreePath objects The issue was get_selected_row now returns a list of TreePath objects which cannot be pickled. Also the set_text method only accept unicode text to pickled bytes cannot be used. The fix is to convert the TreePaths to strings and use json to encode the list of strings for set_text.
This commit is contained in:
parent
1357ca7582
commit
827987fe7d
|
@ -9,10 +9,10 @@
|
|||
|
||||
from __future__ import division, unicode_literals
|
||||
|
||||
import json
|
||||
import logging
|
||||
import os.path
|
||||
|
||||
import six.moves.cPickle as pickle # noqa: N813
|
||||
from gi.repository import Gio, Gtk
|
||||
from gi.repository.Gdk import DragAction, ModifierType, keyval_name
|
||||
from gi.repository.GObject import TYPE_UINT64
|
||||
|
@ -813,14 +813,14 @@ class FilesTab(Tab):
|
|||
|
||||
def _on_drag_data_get_data(self, treeview, context, selection, target_id, etime):
|
||||
paths = self.listview.get_selection().get_selected_rows()[1]
|
||||
selection.set_text(pickle.dumps(paths, protocol=2))
|
||||
selection.set_text(json.dumps([str(path) for path in paths]), -1)
|
||||
|
||||
def _on_drag_data_received_data(
|
||||
self, treeview, context, x, y, selection, info, etime
|
||||
):
|
||||
try:
|
||||
selected = pickle.loads(selection.get_data())
|
||||
except pickle.UnpicklingError:
|
||||
selected = json.loads(selection.get_data())
|
||||
except TypeError:
|
||||
log.debug('Invalid selection data: %s', selection.get_data())
|
||||
return
|
||||
log.debug('selection.data: %s', selected)
|
||||
|
|
Loading…
Reference in New Issue