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


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thunar custom action: audio files
#1
Here is how this works.
[Image: tyUskEg.png]
You can select multiple audio files or folders.
After that this window will open.
[Image: 7x9ir6k.png]
Instuctions
Save the file to /usr/local/bin/zoose-audio

Setting thunar custom action:
Name: Audio options
Description : Manipulate Audio Files
Command: python3 /usr/local/bin/zoose-audio "%F"
 
File Pattern: *
Appearance: Directories, Audio files

Code:
# Thunar custom actions launcher for the audio files
#  Milos Pavlovic 2015
# (Based on the control panel concept of  Johnathan "ShaggyTwoDope" Jenkins)
#
# Save this file to /usr/local/bin/zoose-audio
# Setting thunar custom action:
# Name: Audio options
# Description : Manipulate Audio Files
# Command: python3 /usr/local/bin/zoose-audio "%F"

# File Pattern: *
# Appearance: Directories, Audio files
#
#  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.

#
#

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)","thunar",'/usr/bin/thunar --bulk-rename'],
]


import os
import sys
import string
try:
    from gi import pygtkcompat
except ImportError:
    pygtkcompat = None

if pygtkcompat is not None:
    pygtkcompat.enable()
    pygtkcompat.enable_gtk(version='3.0')

from gi.repository import Gtk as gtk
from gi.repository.GdkPixbuf import Pixbuf



class Startup:

    def destroy(self, widget, data=None):
        # zoose mode
        gtk.main_quit()


    def valtamaction(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
           # case for audacious, if not found displays dialog
           if (execc=='audacious' or execc=='audacious -e'):
              if not os.path.exists('/usr/bin/audacious'):
                 dialog = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,gtk.MESSAGE_INFO,gtk.BUTTONS_OK, "apt-get install audacious")
                 result = dialog.run()
                 dialog.destroy()
                 command=''
           # case for clementine, if not found displays dialog
           elif (execc=='clementine -a' or execc=='clementine -l'):
              if not os.path.exists('/usr/bin/clementine'):
                 dialog = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,gtk.MESSAGE_INFO,gtk.BUTTONS_OK, "apt-get install clementine")
                 result = dialog.run()
                 dialog.destroy()
                 command=''
           # case for soundconverter, if not found displays dialog
           elif execc=='/usr/bin/soundconverter':
              if not os.path.exists('/usr/bin/soundconverter'):
                 dialog = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,gtk.MESSAGE_INFO,gtk.BUTTONS_OK, "apt-get install soundconverter")
                 result = dialog.run()
                 dialog.destroy()
                 command=''
           # case for smplayer, if not found displays dialog
           elif (execc=='smplayer' or execc=='smplayer -add-to-playlist'):
              if not os.path.exists('/usr/bin/smplayer'):
                 dialog = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,gtk.MESSAGE_INFO,gtk.BUTTONS_OK, "apt-get install smplayer")
                 result = dialog.run()
                 dialog.destroy()
                 command=''
           # case for qmmp, if not found displays dialog
           elif (execc=='qmmp' or execc=='qmmp -e'):
              if not os.path.exists('/usr/bin/qmmp'):
                 dialog = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,gtk.MESSAGE_INFO,gtk.BUTTONS_OK, "apt-get install qmmp")
                 result = dialog.run()
                 dialog.destroy()
                 command=''
           if command=='':
               gtk.main_quit()
           os.system(command+' &')
           gtk.main_quit()
           return True
        return False

    def __init__(self):
        # create the window
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window=window
        window.set_title('File actions')
        window.connect("destroy", self.destroy)
        window.set_border_width(5)
        window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
        # we make the icons
        it=gtk.icon_theme_get_default()
        gtk.window_set_default_icon(it.load_icon("gtk-preferences",48,gtk.ICON_LOOKUP_FORCE_SVG))
        window.resize(740,400)
        self.liststore=gtk.ListStore(gtk.gdk.Pixbuf,str,str)
        self.iv=gtk.IconView(self.liststore)
        self.iv.set_pixbuf_column(0)
        self.iv.set_text_column(1)
        self.iv.set_events(self.iv.get_events() | gtk.gdk.BUTTON_PRESS_MASK)
        self.iv.connect("button-press-event", self.valtamaction)
        sw = gtk.ScrolledWindow()
        sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sw.add(self.iv)
        window.add(sw)
        first=True
        for line in zoose_icons:
            if first:
               first=False
               continue 
            try:
               if '/' in line[1]:
                  pixbuf=gtk.gdk.pixbuf_new_from_file(line[1])
               else:
                  pixbuf=it.load_icon(line[1],48,gtk.ICON_LOOKUP_FORCE_SVG)
            except:
               pixbuf=it.load_icon('audio-speakers',48,gtk.ICON_LOOKUP_FORCE_SVG)
            namen=(line[0])
            self.liststore.append([ pixbuf,namen,line[2] ])
        window.show_all()


    def main(self):
        # Cliche init
        gtk.main()


# I swear zoose this better work
if __name__ == "__main__":

     app = Startup()
     app.main()
Reply


Messages In This Thread
Thunar custom action: audio files - by misko_2083 - 06-18-2015, 03:29 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)