__init__.py

00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 # ----------------------------------------------------------------------------
00005 # pyjama - python jamendo audioplayer
00006 # Copyright (c) 2008 Daniel Nögel
00007 #
00008 # This program is free software: you can redistribute it and/or modify
00009 # it under the terms of the GNU General Public License as published by
00010 # the Free Software Foundation, either version 3 of the License, or
00011 # (at your option) any later version.
00012 #
00013 # This program is distributed in the hope that it will be useful,
00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 # GNU General Public License for more details.
00017 # You should have received a copy of the GNU General Public License
00018 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 # ----------------------------------------------------------------------------
00020 
00021 ## @package clLayouts
00022 # This module manages the different layouts for pyjama
00023 # e.g. AlbumBrowser, AlbumLayout and ArtistLayout
00024 
00025 import gtk
00026 
00027 
00028 ## Handling the Layouts.
00029 # You'll have to register your custon Layout
00030 # here.
00031 class Layouts():
00032     ## The Constructor
00033     def __init__(self, pyjama):
00034         self.__pyjama = pyjama
00035         ## Dictionary filled with layouts later
00036         self.layouts = {}
00037         ## Dictionary filled with the layouts' toolbars later
00038         self.toolbars = {}
00039         ## Holds the currently shown layout
00040         self.current_layout = None
00041 
00042         self.__pyjama.Events.add_event("show_layout")
00043 
00044     ## Registers a layout.
00045     # Each Layout needs a methode draw() and a subclass called ToolBar().
00046     # See \ref layout-draw and \ref layout-toolbar.
00047     # @param self Object Pointer
00048     # @param layout_name The name of the layout to register
00049     # @param layout_class The layout class to call when you want you Layout to be shown
00050     # @return None
00051     def register_layout(self, layout_name, layout_class):
00052         self.layouts[layout_name] = layout_class
00053         self.toolbars[layout_name] = layout_class.ToolBar(self.__pyjama)
00054         self.__pyjama.window.vbMainLayout.pack_start(self.toolbars[layout_name], False, True)        
00055 
00056     ## Show a layout
00057     # This methode is the central layout function.
00058     # When you've registered your layout, you can show it
00059     # calling this function.
00060     # @param self Object Pointer
00061     # @param layout The layout to show (as registered in register_layout() before)
00062     # @param data1 Optional - Data you want to pass to your layout's draw() methode
00063     # @param data2 Optional - Data you want to pass to your layout's draw() methode
00064     # @param data3 Optional - Data you want to pass to your layout's draw() methode
00065     # @param data4 Optional - Data you want to pass to your layout's draw() methode
00066     # @param fromhistory Optional bool - default is False - If set to True the page won't be
00067     # stored in hinstory
00068     # @param who_called Optional - for debugging perpose only - which methode called this?
00069     # @return None
00070     # @todo
00071     # - use *args or **kargs as params instead of data(n)
00072     def show_layout(self, layout, data1=None, data2=None, data3=None, data4=None, fromhistory=False, who_called=""):
00073         if self.__pyjama.debug:
00074             print ("Called by: %s" % who_called)
00075 
00076         # hiding the last layout's toolbar
00077         if self.current_layout != None and layout != self.current_layout:
00078             self.toolbars[self.current_layout].hide()
00079 
00080         # Unset Layout Info
00081         self.__pyjama.window.LayoutInfo.set_text("")
00082         self.__pyjama.window.LayoutInfo.set_image(None)
00083     
00084         #
00085         # History
00086         #
00087         if self.__pyjama.historyCurrent != {} and fromhistory==False:
00088             self.__pyjama.historyBack.append(self.__pyjama.historyCurrent)
00089         if fromhistory == False:
00090             self.__pyjama.historyForward = []
00091         self.__pyjama.historyCurrent = {'layout':layout, 'data1':data1, 'data2':data2, 'data3':data3, 'data4':data4}
00092         self.__pyjama.window.toolbar.bHistoryForward.set_sensitive(len(self.__pyjama.historyForward)>0)
00093         self.__pyjama.window.toolbar.bHistoryBack.set_sensitive(len(self.__pyjama.historyBack)>0)
00094         
00095         #
00096         # insert Layout into scrolledwindow
00097         #        
00098         if self.current_layout != None:
00099             self.__pyjama.window.scrolledwindow.remove(self.__pyjama.window.scrolledwindow.child)
00100             # For non-scrollable widgets - no scrollbars for some reasons
00101             # self.__pyjama.window.scrolledwindow.add_with_viewport(self.layouts[layout])
00102         if isinstance(self.layouts[layout], gtk.Layout):
00103             self.__pyjama.window.scrolledwindow.add(self.layouts[layout])
00104         else:
00105             self.__pyjama.window.scrolledwindow.add_with_viewport(self.layouts[layout])
00106         # Setting Scrollbars
00107         self.__pyjama.window.scrolledwindow.set_vadjustment(gtk.Adjustment(value=0, lower=0, upper=0, step_incr=0, page_incr=0, page_size=0))
00108 
00109         self.current_layout = layout
00110         
00111         # showing the toolbar
00112         self.toolbars[layout].show()
00113         # calling the layout's draw method:,
00114         self.layouts[layout].draw(data1, data2, data3, data4)
00115         self.__pyjama.window.do_events()

Generated on Thu Jun 4 19:08:24 2009 for Pyjama by  doxygen 1.5.8