Setup initial DnD source for grids
This commit is contained in:
		@@ -29,7 +29,6 @@ class Path:
 | 
			
		||||
 | 
			
		||||
        self.load_directory()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def set_path(self, path):
 | 
			
		||||
        if path == self.get_path():
 | 
			
		||||
            return
 | 
			
		||||
@@ -38,17 +37,19 @@ class Path:
 | 
			
		||||
            self.path = list( filter(None, path.replace("\\", "/").split('/')) )
 | 
			
		||||
            self.load_directory()
 | 
			
		||||
            return True
 | 
			
		||||
 | 
			
		||||
        return False
 | 
			
		||||
 | 
			
		||||
    def set_path_with_sub_path(self, sub_path):
 | 
			
		||||
        path = os.path.join(self.get_home(), sub_path)
 | 
			
		||||
        if path == self.get_path():
 | 
			
		||||
            return
 | 
			
		||||
            return False
 | 
			
		||||
 | 
			
		||||
        if os.path.isdir(path):
 | 
			
		||||
            self.path = list( filter(None, path.replace("\\", "/").split('/')) )
 | 
			
		||||
            self.load_directory()
 | 
			
		||||
            return True
 | 
			
		||||
 | 
			
		||||
        return False
 | 
			
		||||
 | 
			
		||||
    def set_to_home(self):
 | 
			
		||||
 
 | 
			
		||||
@@ -11,12 +11,12 @@ from random import randint
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Application imports
 | 
			
		||||
from .utils import Settings, Launcher
 | 
			
		||||
from .utils import Settings, Launcher, FileHandler
 | 
			
		||||
from .icons import Icon
 | 
			
		||||
from . import Path
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class View(Settings, Launcher, Icon, Path):
 | 
			
		||||
class View(Settings, FileHandler, Launcher, Icon, Path):
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        self. logger   = None
 | 
			
		||||
        self.id_length = 10
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,65 @@
 | 
			
		||||
 | 
			
		||||
import os, shutil, subprocess, threading
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class FileHandler:
 | 
			
		||||
    def create_file(self, nFile):
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
    def update_file(self, oFile, nFile):
 | 
			
		||||
        try:
 | 
			
		||||
            print(f"Renaming:  {oFile}  -->  {nFile}")
 | 
			
		||||
            os.rename(oFile, nFile)
 | 
			
		||||
            return True
 | 
			
		||||
        except Exception as e:
 | 
			
		||||
            print("An error occured renaming the file:")
 | 
			
		||||
            print(e)
 | 
			
		||||
            return False
 | 
			
		||||
 | 
			
		||||
    def delete_file(self, toDeleteFile):
 | 
			
		||||
        try:
 | 
			
		||||
            print(f"Deleting:  {toDeleteFile}")
 | 
			
		||||
            if os.path.exists(toDeleteFile):
 | 
			
		||||
                if os.path.isfile(toDeleteFile):
 | 
			
		||||
                    os.remove(toDeleteFile)
 | 
			
		||||
                elif os.path.isdir(toDeleteFile):
 | 
			
		||||
                    shutil.rmtree(toDeleteFile)
 | 
			
		||||
                else:
 | 
			
		||||
                    print("An error occured deleting the file:")
 | 
			
		||||
                    return False
 | 
			
		||||
            else:
 | 
			
		||||
                print("The folder/file does not exist")
 | 
			
		||||
                return False
 | 
			
		||||
        except Exception as e:
 | 
			
		||||
            print("An error occured deleting the file:")
 | 
			
		||||
            print(e)
 | 
			
		||||
            return False
 | 
			
		||||
 | 
			
		||||
        return True
 | 
			
		||||
 | 
			
		||||
    def move_file(self, fFile, tFile):
 | 
			
		||||
        try:
 | 
			
		||||
            print(f"Moving:  {fFile}  -->  {tFile}")
 | 
			
		||||
            if os.path.exists(fFile) and os.path.exists(tFile):
 | 
			
		||||
                if not tFile.endswith("/"):
 | 
			
		||||
                    tFile += "/"
 | 
			
		||||
 | 
			
		||||
                shutil.move(fFile, tFile)
 | 
			
		||||
            else:
 | 
			
		||||
                print("The folder/file does not exist")
 | 
			
		||||
                return False
 | 
			
		||||
        except Exception as e:
 | 
			
		||||
            print("An error occured moving the file:")
 | 
			
		||||
            print(e)
 | 
			
		||||
            return False
 | 
			
		||||
 | 
			
		||||
        return True
 | 
			
		||||
 | 
			
		||||
    def copy_file(self):
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
    def cut_file(self):
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
    def paste_file(self):
 | 
			
		||||
        pass
 | 
			
		||||
@@ -1,2 +1,3 @@
 | 
			
		||||
from .Settings import Settings
 | 
			
		||||
from .Launcher import Launcher
 | 
			
		||||
from .FileHandler import FileHandler
 | 
			
		||||
 
 | 
			
		||||
@@ -35,7 +35,6 @@ class TabMixin(WidgetMixin):
 | 
			
		||||
        notebook.show_all()
 | 
			
		||||
        notebook.set_current_page(index)
 | 
			
		||||
 | 
			
		||||
        # FIXME: set_tab_reorderable doesn't seem to work...
 | 
			
		||||
        notebook.set_tab_reorderable(scroll, True)
 | 
			
		||||
        self.load_store(view, store, save_state)
 | 
			
		||||
 | 
			
		||||
@@ -50,7 +49,7 @@ class TabMixin(WidgetMixin):
 | 
			
		||||
        notebook.remove_page(page)
 | 
			
		||||
        self.window_controller.save_state()
 | 
			
		||||
 | 
			
		||||
    def icon_double_left_click(self, widget, item):
 | 
			
		||||
    def grid_icon_double_left_click(self, widget, item):
 | 
			
		||||
        try:
 | 
			
		||||
            wid, tid   = self.window_controller.get_active_data()
 | 
			
		||||
            notebook   = self.builder.get_object(f"window_{wid}")
 | 
			
		||||
@@ -82,7 +81,8 @@ class TabMixin(WidgetMixin):
 | 
			
		||||
        except Exception as e:
 | 
			
		||||
            print(repr(e))
 | 
			
		||||
 | 
			
		||||
    def icon_single_click(self, widget, eve):
 | 
			
		||||
 | 
			
		||||
    def grid_icon_single_click(self, widget, eve):
 | 
			
		||||
        try:
 | 
			
		||||
            wid, tid = widget.get_name().split("|")
 | 
			
		||||
            self.window_controller.set_active_data(wid, tid)
 | 
			
		||||
@@ -123,9 +123,48 @@ class TabMixin(WidgetMixin):
 | 
			
		||||
        except Exception as e:
 | 
			
		||||
            print(repr(e))
 | 
			
		||||
 | 
			
		||||
    def update_path(self, widget, eve=None):
 | 
			
		||||
        print(widget)
 | 
			
		||||
 | 
			
		||||
    def grid_on_drag_set(self, widget, drag_context, data, info, time):
 | 
			
		||||
        action    = widget.get_name()
 | 
			
		||||
        store     = widget.get_model()
 | 
			
		||||
        treePaths = widget.get_selected_items()
 | 
			
		||||
        wid, tid  = action.split("|")
 | 
			
		||||
        view      = self.get_fm_window(wid).get_view_by_id(tid)
 | 
			
		||||
        dir       = view.get_current_directory()
 | 
			
		||||
        uris      = []
 | 
			
		||||
 | 
			
		||||
        for path in treePaths:
 | 
			
		||||
            itr   = store.get_iter(path)
 | 
			
		||||
            file  = store.get(itr, 1)[0]
 | 
			
		||||
            fpath = f"file://{dir}/{file}"
 | 
			
		||||
            uris.append(fpath)
 | 
			
		||||
 | 
			
		||||
        data.set_uris(uris)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def grid_on_drag_motion(self, widget, drag_context, x, y, data):
 | 
			
		||||
        wid, tid = widget.get_name().split("|")
 | 
			
		||||
        self.window_controller.set_active_data(wid, tid)
 | 
			
		||||
 | 
			
		||||
    def grid_on_drag_data_received(self, widget, drag_context, x, y, data, info, time):
 | 
			
		||||
        if info == 80:
 | 
			
		||||
            wid, tid  = self.window_controller.get_active_data()
 | 
			
		||||
            notebook  = self.builder.get_object(f"window_{wid}")
 | 
			
		||||
            icon_view, tab_label = self.get_icon_view_and_label_from_notebook(notebook, f"{wid}|{tid}")
 | 
			
		||||
 | 
			
		||||
            view  = self.get_fm_window(wid).get_view_by_id(tid)
 | 
			
		||||
            store = icon_view.get_model()
 | 
			
		||||
            uris  = data.get_uris()
 | 
			
		||||
            dest  = view.get_current_directory()
 | 
			
		||||
 | 
			
		||||
            print(f"Target Move Path:  {dest}")
 | 
			
		||||
            if len(uris) > 0:
 | 
			
		||||
                for uri in uris:
 | 
			
		||||
                    print(f"URI:  {uri}")
 | 
			
		||||
                    self.move_file(view, uri, dest)
 | 
			
		||||
 | 
			
		||||
                view.load_directory()
 | 
			
		||||
                self.load_store(view, store, False)
 | 
			
		||||
 | 
			
		||||
    def do_action_from_bar_controls(self, widget, eve=None):
 | 
			
		||||
        action    = widget.get_name()
 | 
			
		||||
@@ -155,3 +194,33 @@ class TabMixin(WidgetMixin):
 | 
			
		||||
        self.load_store(view, store, True)
 | 
			
		||||
        self.set_path_text(wid, tid)
 | 
			
		||||
        tab_label.set_label(view.get_end_of_path())
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # File control events
 | 
			
		||||
    def create_file(self):
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
    def update_file(self):
 | 
			
		||||
        nFile = widget.get_text().strip()
 | 
			
		||||
        if data and data.keyval == 65293:    # Enter key event
 | 
			
		||||
            view.update_file(nFile)
 | 
			
		||||
        elif data == None:                   # Save button 'event'
 | 
			
		||||
            view.update_file(nFile)
 | 
			
		||||
 | 
			
		||||
    def delete_file(self):
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def move_file(self, view, fFile, tFile):
 | 
			
		||||
        view.move_file(fFile.replace("file://", ""), tFile)
 | 
			
		||||
 | 
			
		||||
    def copy_file(self):
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
    def cut_file(self):
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
    def paste_file(self):
 | 
			
		||||
        pass
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,9 @@ import threading, subprocess
 | 
			
		||||
import gi
 | 
			
		||||
 | 
			
		||||
gi.require_version("Gtk", "3.0")
 | 
			
		||||
gi.require_version('Gdk', '3.0')
 | 
			
		||||
from gi.repository import Gtk
 | 
			
		||||
from gi.repository import Gdk
 | 
			
		||||
from gi.repository import GLib
 | 
			
		||||
from gi.repository import GdkPixbuf
 | 
			
		||||
 | 
			
		||||
@@ -88,8 +90,18 @@ class WidgetMixin:
 | 
			
		||||
        grid.set_spacing(1)
 | 
			
		||||
        grid.set_column_spacing(2)
 | 
			
		||||
 | 
			
		||||
        grid.connect("button_release_event", self.icon_single_click)
 | 
			
		||||
        grid.connect("item-activated", self.icon_double_left_click)
 | 
			
		||||
        grid.connect("button_release_event", self.grid_icon_single_click)
 | 
			
		||||
        grid.connect("item-activated", self.grid_icon_double_left_click)
 | 
			
		||||
        grid.connect("drag-data-get", self.grid_on_drag_set)
 | 
			
		||||
        grid.connect("drag-data-received", self.grid_on_drag_data_received)
 | 
			
		||||
        grid.connect("drag-motion", self.grid_on_drag_motion)
 | 
			
		||||
 | 
			
		||||
        URI_TARGET_TYPE  = 80
 | 
			
		||||
        uri_target       = Gtk.TargetEntry.new('text/uri-list', Gtk.TargetFlags(0), URI_TARGET_TYPE)
 | 
			
		||||
        targets          = [ uri_target ]
 | 
			
		||||
        action           = Gdk.DragAction.COPY
 | 
			
		||||
        grid.enable_model_drag_dest(targets, action)
 | 
			
		||||
        grid.enable_model_drag_source(0, targets, action)
 | 
			
		||||
 | 
			
		||||
        grid.show_all()
 | 
			
		||||
        scroll.add(grid)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user