Update of /cvsroot/freevo/freevo/src/plugins
In directory sc8-pr-cvs1:/tmp/cvs-serv14734

Added Files:
        shoppingcart.py 
Log Message:
make it a little easier to move multiple files around

--- NEW FILE: shoppingcart.py ---
#if 0 /*
# -----------------------------------------------------------------------
# shoppingcart.py - Example item plugin
# -----------------------------------------------------------------------
# $Id: shoppingcart.py,v 1.1 2003/12/09 23:29:46 mikeruelle Exp $
#
# Notes: This is a plugin to move and copy files
#
# Activate: 
#   plugin.activate('shoppingcart')
#
# Todo:        
#
# -----------------------------------------------------------------------
# $Log: shoppingcart.py,v $
# Revision 1.1  2003/12/09 23:29:46  mikeruelle
# make it a little easier to move multiple files around
#
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al. 
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# 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 MER-
# CHANTABILITY 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.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------- */
#endif


import os
import plugin
import config
import shutil
import util
from gui.PopupBox import PopupBox
import rc
import event as em

class PluginInterface(plugin.ItemPlugin):
    """
    This plugin copies or moves files to directories. Go to a file hit
    enter pick 'add to cart' and then go to a directory. Press enter
    and pick what you want to do.

    plugin.activate('shoppingcart')

    """
    def __init__(self):
        plugin.ItemPlugin.__init__(self)
        self.item = None
        self.pfile = os.path.join(config.FREEVO_CACHEDIR, 'cart')

    def moveHere(self, arg=None, menuw=None):
        cartfiles = util.read_pickle(self.pfile)
        popup = PopupBox(text=_('Moving files...'))
        popup.show()
        for cartfile in cartfiles:
            shutil.move(cartfile, self.item.dir)
        os.unlink(self.pfile)
        popup.destroy()
        rc.post_event(em.MENU_BACK_ONE_MENU)

    def copyHere(self, arg=None, menuw=None):
        cartfiles = util.read_pickle(self.pfile)
        popup = PopupBox(text=_('Copying files...'))
        popup.show()
        for cartfile in cartfiles:
            shutil.copy(cartfile, self.item.dir)
        os.unlink(self.pfile)
        popup.destroy()
        rc.post_event(em.MENU_BACK_ONE_MENU)

    def addToCart(self, arg=None, menuw=None):
        if (os.path.isfile(self.pfile) == 0):
            cartfiles = []
        else:
            cartfiles = util.read_pickle(self.pfile)
        cartfiles.append(self.item.filename)
        util.save_pickle(cartfiles, self.pfile)
        rc.post_event(em.MENU_BACK_ONE_MENU)

    def deleteCart(self, arg=None, menuw=None):
        if (os.path.isfile(self.pfile) != 0):
            os.unlink(self.pfile)
        rc.post_event(em.MENU_BACK_ONE_MENU)

    def actions(self, item):
        self.item = item
        myactions = []
        if (os.path.isfile(self.pfile) == 0):
            cartfiles = []
        else:
            cartfiles = util.read_pickle(self.pfile)
        if item.type == 'dir' and len(cartfiles) > 0:
            myactions.append((self.moveHere, _('Move Files Here')))
            myactions.append((self.copyHere, _('Copy Files Here')))
        elif hasattr(item, 'filename'):
            myactions.append((self.addToCart, _('Add File to Cart')))
        if (os.path.isfile(self.pfile) != 0):
            myactions.append((self.deleteCart, _('Delete Cart')))
        return myactions





-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to