daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest Nov 20th, 2017 157 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2. # Thunar custom actions launcher for Send to operations
  3. #  Milos Pavlovic 2016 <mpsrbija@gmail.com>
  4. #
  5. #  Save this file to /usr/local/bin/menu.py
  6. #  Setting thunar custom action:
  7. #  Name: Send to
  8. #  Description : Copy file(s) and folder(s) to...
  9. #  Command: tempfile=$(mktemp /tmp/XXXXX); for file in %F; do echo "${file##*/}" >> $tempfile; done; python3 /usr/local/bin/menu.py %d/ $tempfile | python3 /usr/local/bin/docp.py; rm -f $tempfile
  10. #  
  11. #  File Pattern: *
  12. #  Appearance: *
  13. #
  14. #  This program is free software; you can redistribute it and/or modify
  15. #  it under the terms of the GNU General Public License as published by
  16. #  the Free Software Foundation; either version 3 of the License, or
  17. #  (at your option) any later version.
  18. #  
  19. #  This program is distributed in the hope that it will be useful,
  20. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. #  GNU General Public License for more details.
  23. #  
  24. #  You should have received a copy of the GNU General Public License
  25. #  along with this program; if not, write to the Free Software
  26. #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  27. #  MA 02110-1301, USA.
  28. #  
  29.  
  30.  
  31. icons=[
  32. ["name","icon","command"],
  33. ["Send to Home","folder-home",'$HOME/'],
  34. ["Send to Desktop","desktop",'$HOME/Desktop/'],
  35. ["Send to Documents","folder-documents",'$HOME/Documents/'],
  36. ["Send to Downloads","folder-downloads",'$HOME/Downloads/'],
  37. ["Send to Music","folder-music",'$HOME/Music/'],
  38. ["Send to Pictures","folder-pictures",'$HOME/Pictures/'],
  39. ["Send to Videos","folder-videos",'$HOME/Videos/'],
  40. ]
  41.  
  42.  
  43. import os
  44. import sys
  45. import string
  46. from gi import require_version
  47. require_version('Gtk', '3.0')
  48. from gi.repository import Gtk
  49. from gi.repository.GdkPixbuf import Pixbuf
  50.  
  51.  
  52. class Menu:
  53.  
  54.     def destroy(self, widget, data=None):
  55.         Gtk.main_quit()
  56.  
  57.  
  58.     def action(self, button, event, path, data=None):
  59.         if len(sys.argv) > 1 and  path != '':
  60.            files = "{0}".format(sys.argv[1])
  61.            home = os.path.expanduser("~")
  62.            if "$HOME" in path:
  63.                path = path.replace("$HOME", home)
  64.            src = sys.argv[1]
  65.            file_with_list = sys.argv[2]
  66.            print(src)
  67.            print(path)
  68.            print(file_with_list)
  69.            sys.stdout.flush()
  70.         else:
  71.            print("No file(s) passed. Exiting.")
  72.         Gtk.main_quit()
  73.  
  74.     def __init__(self):
  75.         self.menu = Gtk.Menu()
  76.         self.menu.connect("hide", self.destroy)
  77.         it=Gtk.IconTheme.get_default()
  78.         j=0
  79.         first=True
  80.         for line in icons:
  81.             if first:
  82.                first=False
  83.                continue  
  84.             try:
  85.                if '/' in line[1]:
  86.                   pixbuf = pixbuf_new_from_file(line[1])
  87.                else:
  88.                   pixbuf = it.load_icon(line[1],24,0)
  89.             except:
  90.                pixbuf = it.load_icon('gtk-stop',24,0)
  91.             name = (line[0])
  92.             path = line[2]
  93.  
  94.             box = Gtk.Box()
  95.             box.set_spacing(5)
  96.             img = Gtk.Image()
  97.             img.set_from_pixbuf(pixbuf)
  98.             label = Gtk.Label(name)
  99.             box.add(img)
  100.             box.add(label)
  101.             menuitem = Gtk.MenuItem()
  102.             menuitem.add(box)
  103.             menuitem.connect("button-release-event", self.action, path)
  104.             self.menu.append(menuitem)
  105.             j +=1
  106.         height = j*30
  107.         self.menu.set_size_request(0, height)
  108.         self.menu.popup(None, None, None, None, 0, Gtk.get_current_event_time())
  109.         self.menu.show_all()
  110.  
  111.     def main(self):
  112.         # Cliche init
  113.         Gtk.main()
  114.  
  115. if __name__ == "__main__":
  116.  
  117.      app = Menu()
  118.      app.main()
RAW Paste Data
Top