From 827987fe7d8b687c4ec3b4b50920f483650d65f8 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Mon, 20 May 2019 20:46:00 +0100 Subject: [PATCH] [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. --- deluge/ui/gtk3/files_tab.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deluge/ui/gtk3/files_tab.py b/deluge/ui/gtk3/files_tab.py index fad74bf03..a80418ce2 100644 --- a/deluge/ui/gtk3/files_tab.py +++ b/deluge/ui/gtk3/files_tab.py @@ -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)