Misko_2083
Member
- Joined
- Mar 15, 2015
- Messages
- 306
- Reaction score
- 18
Pokreće Gtk3 meni pomoću koga mogu da se izvršavaju komande ili programi nad fajlovima koji se prosleđuju iz Thunar-a.
Pretpostavljam da će pojedine varijacije ovog skripta biti i više nego korisne.
Sa malim izmenama u kodu mogu da se naprave vrlo korisni meniji, ne samo za Thunar već i za pokretanje aplikacija, skriptova web pregledača…
Čudi me da se niko nije do sada setio da napravi ovako nešto.
Zapravo bila je to ideja ToZ-a iz Xfce-a. Video je moj drugi skript za Thunar koji pokreće prozor u kome grupiše ikone pomoću kojih mogu da se pokrenu Thunar Custom Actions i pitao me da li može da se napravi meni. Pre je bilo nekog plugina koji je dodavao podmenije ali on se ne održava već dosta i više se ne builduje.
class Menu:
[/CODE]
Pretpostavljam da će pojedine varijacije ovog skripta biti i više nego korisne.
Sa malim izmenama u kodu mogu da se naprave vrlo korisni meniji, ne samo za Thunar već i za pokretanje aplikacija, skriptova web pregledača…
Čudi me da se niko nije do sada setio da napravi ovako nešto.
Zapravo bila je to ideja ToZ-a iz Xfce-a. Video je moj drugi skript za Thunar koji pokreće prozor u kome grupiše ikone pomoću kojih mogu da se pokrenu Thunar Custom Actions i pitao me da li može da se napravi meni. Pre je bilo nekog plugina koji je dodavao podmenije ali on se ne održava već dosta i više se ne builduje.
Code:
# Thunar custom actions launcher for the audio files
[HEADING=1]Milos Pavlovic 2015 [email protected][/HEADING]
[HEADING=1]Save this file to /usr/local/bin/zoose.py[/HEADING]
[HEADING=1]Setting thunar custom action:[/HEADING]
[HEADING=1]Name: Audio options[/HEADING]
[HEADING=1]Description : Manipulate Audio Files[/HEADING]
[HEADING=1]Command: python3 /usr/local/bin/zoose.py “%F”[/HEADING]
[HEADING=1]File Pattern: *[/HEADING]
[HEADING=1]Appearance: Directories, Audio files[/HEADING]
[HEADING=1]This program is free software; you can redistribute it and/or modify[/HEADING]
[HEADING=1]it under the terms of the GNU General Public License as published by[/HEADING]
[HEADING=1]the Free Software Foundation; either version 2 of the License, or[/HEADING]
[HEADING=1](at your option) any later version.[/HEADING]
[HEADING=1]This program is distributed in the hope that it will be useful,[/HEADING]
[HEADING=1]but WITHOUT ANY WARRANTY; without even the implied warranty of[/HEADING]
[HEADING=1]MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the[/HEADING]
[HEADING=1]GNU General Public License for more details.[/HEADING]
[HEADING=1]You should have received a copy of the GNU General Public License[/HEADING]
[HEADING=1]along with this program; if not, write to the Free Software[/HEADING]
[HEADING=1]Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,[/HEADING]
[HEADING=1]MA 02110-1301, USA.[/HEADING]
zoose_icons=[
[“name”,“icon”,“command”],
[“Audacious”,“audacious”,‘audacious’],
[“Enqueue in Audacious”,“audacious”,‘audacious -e’],
[“Clementine”,“clementine”,‘clementine -l’],
[“Enqueue in Clementine”,“clementine”,‘clementine -a’],
[“SMPlayer”,“smplayer”,‘smplayer’],
[“Enqueue in SMPlayer”,“smplayer”,‘smplayer -add-to-playlist’],
[“VLC”,“vlc”,‘vlc’],
[“Qmmp”,“qmmp”,‘qmmp’],
[“Enqueue in Qmmp”,“qmmp”,‘qmmp -e’],
[“Convert”,“soundconverter”,’/usr/bin/soundconverter’],
[“Bulk Rename (Thunar)”,“file-manager”,’/usr/bin/thunar --bulk-rename’],
]
import os
import sys
import string
import subprocess
import shlex
from gi.repository import Gtk as Gtk
from gi.repository.GdkPixbuf import Pixbuf
[HEADING=1]Which[/HEADING]
def which(program):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
[CODE] fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
Code:
def destroy(self, widget, data=None):
# zoose mode
Gtk.main_quit()
def action(self, widget, event, x, data=None):
if len(sys.argv) > 1 and x != '':
comm=" {0}".format(str(sys.argv[1]))
command="{0}{1}". format(x, comm)
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 zoose_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)
namen=(line[0])
execc=line[2]
chk = execc.split(' ')[0]
if chk == "gksudo":
chk = execc.split(' ')[1]
elif chk == "gksu":
chk = execc.split(' ')[1]
elif chk == "kdesu":
chk = execc.split(' ')[1]
x=execc
checking = which(chk)
if checking != None:
box = Gtk.Box()
box.set_spacing(10)
img = Gtk.Image()
img.set_from_pixbuf(pixbuf)
label = Gtk.Label(namen)
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(180, height) # Workaround for height
self.menu.popup(None, None, None, None, 0, Gtk.get_current_event_time())
self.menu.show_all()
print(height)
def main(self):
# Cliche init
Gtk.main()
I swear zoose this better work
if name == “main”:
Code:
app = Menu()
app.main()
Last edited: