Misko_2083
Member
- Joined
- Mar 15, 2015
- Messages
- 306
- Reaction score
- 18
Ovo je samo moj eksperiment za skladištenje Thunar custom akcija u jednu aplikaciju.
Ovo koristim za reprodukciju audio fajlova. Postavio sam još nekoliko komandi, pa u slučaju da je instaliran Clementine, Qmmp, SMPlayer i Soundconverter, ikone će se pojaviti. Slajder služi za podešavanje jačine zvuka (amixer sset Master).
Komanda za thunar je
Uputstvo je u samom fajlu.
I na kraju nemam pojma zašto sam ovo nazvao zoose.
zoose-audio.py
class Startup:
[/CODE]
Ovo koristim za reprodukciju audio fajlova. Postavio sam još nekoliko komandi, pa u slučaju da je instaliran Clementine, Qmmp, SMPlayer i Soundconverter, ikone će se pojaviti. Slajder služi za podešavanje jačine zvuka (amixer sset Master).
Komanda za thunar je
python3 /putanja/do/zoose-audio.py "%F"
Uputstvo je u samom fajlu.
I na kraju nemam pojma zašto sam ovo nazvao zoose.
zoose-audio.py
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-audio.py or at your whish just remember to change the path in command[/HEADING]
[HEADING=1]Setting thunar custom action:[/HEADING]
[HEADING=1]Name: Audio options[/HEADING]
[HEADING=1]Description : Play Audio Files[/HEADING]
[HEADING=1]Command: python3 /usr/local/bin/zoose-audio.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”],
[“Play with Audacious”,“audacious”,‘audacious’],
[“Enqueue in Audacious”,“audacious”,‘audacious -e’],
[“Play with Clementine”,“clementine”,‘clementine -l’],
[“Enqueue in Clementine”,“clementine”,‘clementine -a’],
[“Play with SMPlayer”,“smplayer”,‘smplayer’],
[“Enqueue in SMPlayer”,“smplayer”,‘smplayer -add-to-playlist’],
[“Play with VLC”,“vlc”,‘vlc’],
[“Play with Qmmp”,“qmmp”,‘qmmp’],
[“Enqueue in Qmmp”,“qmmp”,‘qmmp -e’],
[“Convert”,“soundconverter”,‘/usr/bin/soundconverter’],
[“Bulk Rename (Thunar)”,“thunar”,‘/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 to identify wheather the program exists[/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, data=None):
if event.button==1:
pathinfo=widget.get_path_at_pos(int(event.x),int(event.y))
if pathinfo==None: return False
pathnr=pathinfo[0]
comm=" %s" % str(sys.argv[1])
execc="%s" % self.liststore[pathnr][2]
command=self.liststore[pathnr][2] + comm
if command=='':
gtk.main_quit()
subprocess.Popen(shlex.split(command), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
gtk.main_quit()
return True
return False
def create_label(self):
label = gtk.Label()
label.set_markup("Select the action you whish to perform")
label.set_line_wrap(True)
label.set_size_request(740, -1)
self.grid.attach(label, 0, 0, 2, 1)
def create_icons(self):
# we make the icons
self.liststore=gtk.ListStore(Pixbuf,str,str)
self.iv=gtk.IconView(self.liststore)
self.iv.set_pixbuf_column(0)
self.iv.set_text_column(1)
#self.iv.set_columns(3)
self.iv.set_events(self.iv.get_events())
self.iv.connect("button-press-event", self.action)
sw = gtk.ScrolledWindow()
sw.set_size_request(-1, 250)
sw.add(self.iv)
self.grid.attach(sw, 0, 1, 2, 1)
it=gtk.IconTheme.get_default()
first=True
for line in zoose_icons:
if first:
first=False
continue
try:
if '/' in line[1]:
pixbuf=Pixbuf.new_from_file(line[1]) # if the icon is a path load it from file
else:
pixbuf=it.load_icon(line[1],48,0)
except:
pixbuf=it.load_icon('gtk-stop',48,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]
checking = which(chk)
chk = execc.split(' ')[0]
if chk == "gksudo":
chk = execc.split(' ')[1]
elif chk == "gksu":
chk = execc.split(' ')[1]
checking = which(chk)
if checking != None:
self.liststore.append([ pixbuf,namen,line[2] ])
def create_label_two(self):
# adjustment (initial value, min value, max value,
# step increment - press cursor keys to see!,
# page increment - click around the handle to see!,
# page size - not used here)
ad1 = gtk.Adjustment(0, 0, 100, 5, 10, 0)
cmd = "/usr/bin/amixer sget Master | grep '\[' "
result = os.popen(cmd)
result = result.readline()
find_start = result.find('[') + 1
find_end = result.find('%]', find_start)
audio_level = int(result[find_start])
ad1. set_value(audio_level)
# an horizontal scale
self.h_scale = gtk.Scale(
orientation=gtk.Orientation.HORIZONTAL, adjustment=ad1)
# of integers (no digits)
self.h_scale.set_digits(0)
# that can expand horizontally if there is space in the grid (see
# below)
self.h_scale.set_hexpand(True)
# that is aligned at the top of the space allowed in the grid (see
# below)
self.h_scale.set_valign(gtk.Align.START)
# we connect the signal "value-changed" emitted by the scale with the callback
# function scale_moved
self.h_scale.connect("value-changed", self.scale_moved)
self.grid.attach(self.h_scale, 1, 2, 1, 2)
# any signal from the scales is signaled to the label the text of which is
# changed
def scale_moved(self, event):
val = "{0}".format(int(self.h_scale.get_value()))
proc = subprocess.Popen('/usr/bin/amixer sset Master ' + str(val) + '% 2>&1 >/dev/null', shell=True, stdout=subprocess.PIPE)
proc.wait()
def __init__(self):
# create the window
window = gtk.Window()
self.window=window
window.set_border_width(10)
window.set_title('Audio File Actions')
window.connect("destroy", self.destroy)
window.set_border_width(5)
window.set_position(1)
window.set_resizable(False)
self.grid = gtk.Grid()
window.add(self.grid)
window.set_size_request(740, 300)
self.create_label()
self.create_icons()
self.create_label_two()
it=gtk.IconTheme.get_default()
try:
window.set_icon(it.load_icon(gtk.STOCK_HOME, 64, 0))
except:
pass
window.show_all()
def main(self):
# Cliche init
gtk.main()
I swear zoose this better work
if name == “main”:
Code:
app = Startup()
app.main()
Last edited: