LINUX LITE 7.2 FINAL RELEASED - SEE RELEASE ANNOUNCEMENTS SECTION FOR DETAILS


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Linux Lite 3.0 Suggestion Thread
#44
(02-17-2016, 04:47 PM)avj link Wrote:If possible I would like to have a "Send to" right click menu item for the desktop that allows me to send items from the desktop to my home, documents, music, pictures, and other relevant folders.
Yep.
This is a quick hack of shaggytwodopes's control center code. Will copy just one file but the general idea is that Thunar calls a py script Smile
Code:
# Thunar custom actions launcher for Send to operations
#  Milos Pavlovic 2016 <[email protected]>
#
#  Save this file to /usr/local/bin/menu.py
#  Setting thunar custom action:
#  Name: Send to
#  Description : Copy file to...
#  Command: python3 /usr/local/bin/menu.py "%F"

#  File Pattern: *
#  Appearance: *
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.

#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.

#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.


# $@ - file input

icons=[
["name","icon","command"],
["Send to Home","folder-home",'cp $@ $HOME/'],
["Send to Desktop","desktop",'cp $@ $HOME/Desktop/'],
["Send to Documents","folder-documents",'cp $@ $HOME/Documents/'],
["Send to Downloads","folder-downloads",'cp $@ $HOME/Downloads'],
["Send to Music","folder-music",'cp $@ $HOME/Music'],
["Send to Pictures","folder-pictures",'cp $@ $HOME/Pictures'],
["Send to Videos","folder-videos",'cp $@ $HOME/Videos'],
]


import os
import sys
import string
import subprocess
import shlex
from gi.repository import Gtk as Gtk
from gi.repository.GdkPixbuf import Pixbuf


class Menu:

    def destroy(self, widget, data=None):
        Gtk.main_quit()

    def action(self, widget, event, x, data=None):
        if len(sys.argv) > 1 and  x != '':
           files = "{0}".format(sys.argv[1])
           home = os.path.expanduser("~/")
           command = x.replace("$@", files)
           command = command.replace("$HOME", home)
           subprocess.Popen(shlex.split(command), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        else:
           print("No file(s) passed. Exiting.")
        Gtk.main_quit()

    def __init__(self):
        self.menu = Gtk.Menu()
        self.menu.connect("hide", self.destroy)
        it=Gtk.IconTheme.get_default()
        j=0
        first=True
        for line in icons:
            if first:
               first=False
               continue 
            try:
               if '/' in line[1]:
                  pixbuf = pixbuf_new_from_file(line[1])
               else:
                  pixbuf = it.load_icon(line[1],24,0)
            except:
               pixbuf = it.load_icon('gtk-stop',24,0)
            name = (line[0])
            execc = line[2]


            x=execc

            box = Gtk.Box()
            box.set_spacing(10)
            img = Gtk.Image()
            img.set_from_pixbuf(pixbuf)
            label = Gtk.Label(name)
            box.add(img)
            box.add(label)
            menuitem = Gtk.MenuItem()
            menuitem.add(box)
            menuitem.connect("button-press-event", self.action, x)
            self.menu.append(menuitem)
            j +=1
        height = j*30
        self.menu.set_size_request(150, height) # Workaround for height
        self.menu.popup(None, None, None, None, 0, Gtk.get_current_event_time())
        self.menu.show_all()
    def main(self):
        # Cliche init
        Gtk.main()

if __name__ == "__main__":

     app = Menu()
     app.main()
Just throwing in some ideas for now.
Would need to be reworked to use shutil to copy files and folders. And passing file and folder names from Thunar like this is not a very good idea. I guess writing to temp file would be preferable so file and folder names are read line by line in a script. Then Thunar custom action would be something like: "for file in %F; do echo $file >> tmp.txt; done; python3 /souce/ destination tmp.txt;rm -r tmp.txt".
There is also a case when filename exists. In that case script could offer to overwrite / change destination filename / skip coping that file or folder. To display error when it cant copy and finally a progress bar. Smile


Messages In This Thread
Linux Lite 3.0 Suggestion Thread - by Valtam - 02-08-2016, 03:08 AM
Re: Linux Lite 3.0 Suggestion Thread - by bfb - 02-08-2016, 07:10 AM
Re: Linux Lite 3.0 Suggestion Thread - by Glenn - 02-08-2016, 06:05 PM
Re: Linux Lite 3.0 Suggestion Thread - by ZoA - 02-08-2016, 08:57 PM
Re: Linux Lite 3.0 Suggestion Thread - by nomko - 02-08-2016, 09:18 PM
Re: Linux Lite 3.0 Suggestion Thread - by nomko - 02-10-2016, 06:23 AM
Re: Linux Lite 3.0 Suggestion Thread - by nomko - 02-10-2016, 06:26 PM
Re: Linux Lite 3.0 Suggestion Thread - by N4RPS - 02-11-2016, 10:22 AM
Re: Linux Lite 3.0 Suggestion Thread - by nomko - 02-11-2016, 11:08 AM
Re: Linux Lite 3.0 Suggestion Thread - by avj - 02-11-2016, 11:49 PM
Re: Linux Lite 3.0 Suggestion Thread - by nomko - 02-12-2016, 06:10 AM
Re: Linux Lite 3.0 Suggestion Thread - by bfb - 04-26-2016, 09:38 AM
Re: Linux Lite 3.0 Suggestion Thread - by avj - 02-17-2016, 04:47 PM
Re: Linux Lite 3.0 Suggestion Thread - by misko_2083 - 02-18-2016, 01:39 AM
Re: Linux Lite 3.0 Suggestion Thread - by nomko - 02-18-2016, 09:32 AM

Forum Jump:


Users browsing this thread: 31 Guest(s)