__init__.py :  » Media-Sound-Audio » Christine-Media-Player » christine-0.6.1 » libchristine » Plugins » trayicon » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Media Sound Audio » Christine Media Player 
Christine Media Player » christine 0.6.1 » libchristine » Plugins » trayicon » __init__.py
#! /usr/bin/env python
## Copyright (c) 2006 Marco Antonio Islas Cruz
## <markuz@islascruz.org>
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

import gtk

from libchristine.Logger import LoggerManager
from libchristine.Share import Share
from libchristine.ui import interface
from libchristine.Plugins.plugin_base import plugin_base,christineConf
from libchristine.Events import christineEvents

__name__ = _('TrayIcon')
__description__  = _('This plugins shows a Try Icon on the notification area')
__author__  = ['Marco Antonio Islas Cruz <markuz@islascruz.org>']
__enabled__ = christineConf.getBool('trayicon/enabled')

class trayicon(plugin_base):
  '''
  This class creates the tray icon for the christine media player.
  '''
  def __init__(self):
    plugin_base.__init__(self)
    self.name = __name__
    self.description = __description__
    self.Events = christineEvents()
    if not self.christineConf.exists('trayicon/enabled'):
      self.christineConf.setValue('trayicon/enabled', True)
    self.christineConf.notifyAdd('trayicon/enabled', 
              lambda *args: self.__create_and_delete())
    self.__Share   = Share()
    self.__Logger = LoggerManager().getLogger('trayIcon')
    self.interface = interface()
    self.__IsHidden =  False
    self.__buildTrayIcon()
    self.Events.addWatcher('gotTags', self.gotTags)
    
    self.interface.TrayIcon = self
  
  def __create_and_delete(self, *args):
    if self.active:
      self.__buildTrayIcon()
    else:
      del self.TrayIcon
      #self.TrayIcon.destroy()
  
  def pause(self, *args):
    self.interface.coreClass.pause(*args)
  
  def goPrev(self, *args):
    self.interface.coreClass.goPrev(*args)
  
  def goNext(self,*args):
    self.interface.coreClass.goNext(*args)
  
  def __buildTrayIcon(self):
    """
    Show the TrayIcon
    """
    if self.active:
      self.TrayIcon = gtk.StatusIcon()
      self.TrayIcon.set_from_pixbuf(self.__Share.getImageFromPix('trayicon'))
      self.TrayIcon.connect('popup-menu', self.__trayIconHandlerEvent)
      self.TrayIcon.connect('activate',   self.__trayIconActivated)
      self.TrayIcon.set_tooltip('Christine Baby!')
      self.TrayIcon.set_visible(True)

  def __trayIconHandlerEvent(self, widget, event, time):
    """
    TrayIcon handler events
    """
    # If the event is a button press event and it was
    # the third button then show a popup menu
    if (event == 3):
      XML = self.__Share.getTemplate('MenuTrayIcon')
      XML.signal_autoconnect(self)

      popup = XML['menu']
      popup.popup(None, None, None, 3, gtk.get_current_event_time())
      popup.show_all()

  def __trayIconActivated(self, status):
    """
    This hide and then show the window,
    intended when you want to show the window
    in your current workspace
    """
    if (self.__IsHidden == True):
      self.interface.coreWindow.show()
    else:
      self.interface.coreWindow.hide()
    self.__IsHidden = not self.__IsHidden

  def trayIconPlay(self,widget = None):
    self.interface.playButton.set_active(True)
  
  def gotTags(self, tags):
    if self.active:
      tooltext = "%s\n" % tags['title']
      if tags['artist']:
        tooltext += "by %s\n" % tags['artist']
      if tags['album']:
        tooltext += " from %s " % tags['album']
      self.TrayIcon.set_tooltip(tooltext)  
      

  def get_active(self):
    return self.christineConf.getBool('trayicon/enabled')
  
  def set_active(self, value):
    __enabled__ = value
    return self.christineConf.setValue('trayicon/enabled', value)

  active = property(get_active, set_active, None,
          'Determine if the plugin is active or inactive')
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.