예제 #1
0
 def __init__(self):
     """
     Initialize plugin.
     """
     self.__waitAction__ = None
     self.__targetAlbum__ = None
     self.__blockWindow__ = None
 
     # Menu action
     self.__gtkAction__ = gtk.Action("PicasaProjectAction", self.__trans__("Picasa Project"), self.__trans__("Create new picasa project"), None)
     self.__gtkAction__.set_menu_item_type(gtk.ImageMenuItem)
     
     # Execution window actions
     self.__gtkActionLogin__ = gtk.Action("LoginAction", self.__trans__("Sign In"), self.__trans__("Sign in on Picasa"), gtk.STOCK_CONNECT)
     self.__gtkActionLogin__.set_menu_item_type(gtk.ImageMenuItem)
     self.__gtkActionLogin__.set_tool_item_type(gtk.ToolButton)
     self.__gtkActionLogin__.connect("activate", self.__loginEvent__)
     
     self.__gtkActionAlbum__ = gtk.Action("SelectTargetAction", self.__trans__("Target Album"), self.__trans__("Select a target album"), gtk.STOCK_DIRECTORY)
     self.__gtkActionAlbum__.set_menu_item_type(gtk.ImageMenuItem)
     self.__gtkActionAlbum__.set_tool_item_type(gtk.ToolButton)
     self.__gtkActionAlbum__.connect("activate", self.__selectAlbumEvent__)
     
     self.__gdata__ = Session()
예제 #2
0
class CamimgPlugin(IProjectType.Project):
    """
    @summary: Defines picasa project structure.
    """
    
    def __init__(self):
        """
        Initialize plugin.
        """
        self.__waitAction__ = None
        self.__targetAlbum__ = None
        self.__blockWindow__ = None
    
        # Menu action
        self.__gtkAction__ = gtk.Action("PicasaProjectAction", self.__trans__("Picasa Project"), self.__trans__("Create new picasa project"), None)
        self.__gtkAction__.set_menu_item_type(gtk.ImageMenuItem)
        
        # Execution window actions
        self.__gtkActionLogin__ = gtk.Action("LoginAction", self.__trans__("Sign In"), self.__trans__("Sign in on Picasa"), gtk.STOCK_CONNECT)
        self.__gtkActionLogin__.set_menu_item_type(gtk.ImageMenuItem)
        self.__gtkActionLogin__.set_tool_item_type(gtk.ToolButton)
        self.__gtkActionLogin__.connect("activate", self.__loginEvent__)
        
        self.__gtkActionAlbum__ = gtk.Action("SelectTargetAction", self.__trans__("Target Album"), self.__trans__("Select a target album"), gtk.STOCK_DIRECTORY)
        self.__gtkActionAlbum__.set_menu_item_type(gtk.ImageMenuItem)
        self.__gtkActionAlbum__.set_tool_item_type(gtk.ToolButton)
        self.__gtkActionAlbum__.connect("activate", self.__selectAlbumEvent__)
        
        self.__gdata__ = Session()
    
    def __trans__(self, msg):
        """
        @summary: Translate msg.
        @param msg: str within message. 
        @return: str translated.
        """
        return gettext.translation(picasaproject.camimgplugin.camimgpluginName, __LOCALE_FOLDER__,
                                   languages=[__LANGKEY__], fallback=True).gettext(msg)
    
    def __loginEvent__(self, b):
        """
        @summary: Process login event.
        @param b: Action associated with event.
        """
        doLogin = True
        if (self.__gdata__.isLogged()):
            doLogin = FactoryControls.getConfirmMessage(self.__trans__("You are signed in picasa\nDo you like sign in with another user in picasa?"),
                                                          title=self.__trans__("Picasa Sign In"), parent=self.__blockWindow__, gtkLock=False,
                                                          returnBoolean=True)
        self.__gdata__.login(parent=self, forceLogin=doLogin, store=False)
        
        
    def __selectAlbumEvent__(self, b):
        """
        @summary: Process select album event.
        @param b: Action associated with event. 
        """
        self.__selectAlbumOption__()
    
    def setBlockWindow(self, window):
        """
        @summary: Sets window as parent window.
        """
        self.__blockWindow__ = window
    
    def getIconName(self):
        """
        @summary: Gets name of icon that represents this project type.
        @return: String with icon filename.
        """
        return "picasa.png"
    
    def getXmlLocation(self):
        """
        @summary: Gets xml file that contains XmlMenu and its options.
        @return: String with path 
        """
        return "picasaproject.xml"
    
    def getGtkAction(self):
        """
        Gets gtk.Action of project
        """
        return self.__gtkAction__
            
    def getTypeName(self):
        """
        @summary: Gets name of this project type.
        @return: String with type project name. 
        """
        return "PicasaProject"
    
    def hasOptions(self):
        """
        @summary: Gets if the type of project has any option.
        @return: True when it has any option.
        """
        return True
    
    def getStringUIManager(self):
        """
        @summary: Gets string to add to UIManager.
        @return: str with menus.
        """
        return '<ui><toolbar name="ToolsExecute"><placeholder name="ExecuteToolItems"> \
                <toolitem name="Login" action="LoginAction" /> \
                <toolitem name="SelectTarget" action="SelectTargetAction" /> \
                </placeholder></toolbar></ui>'
    
    def getOptions(self):
        """
        @summary: Gets options of the project.
        @return: List of gtk.Actin. None if there are not options 
        """
        return [self.__gtkActionAlbum__, self.__gtkActionLogin__]
    
    def getIconsOptions(self):
        """
        @summary: Gets dictionary with icon of each action.
        @return: Dictionary of icons.
        """
        return {}
    
    def PreDoProject(self, core, blockWindow=None):
        """
        @summary: Execute before operations.
        @param core: CamCore to execute.
        @param blockWindow: GtkWindow to block by any dialog.
        @return: True if all is right.
        """
        bReturn = True
        self.__blockWindow__ = blockWindow
        
        if (self.__targetAlbum__ == None):
            bReturn = self.__selectAlbumOption__(gtkLock=False)
        
        if (self.__targetAlbum__ != None):
            albumId = None
            if (self.__targetAlbum__[1] != None):
                albumId = self.__targetAlbum__[1]
            else:
                try:
                    albumName = self.__targetAlbum__[0]
                    newAlbum = self.__gdata__.getGdataAccess().InsertAlbum(title=albumName, summary=albumName)
                    albumId = newAlbum.gphoto_id.text
                    __log__.info("Album %s created. Id: %s" % (albumName, albumId))
                    self.__targetAlbum__ = (albumName, albumId)
                except Exception, ex:
                    __log__.error("An error was occurred when it was creating new album %s. %s" % (self.__targetAlbum__[0], ex))
                    return False
            __log__.info("Album selected. Name: %s , Id: %s" % (self.__targetAlbum__[0], albumId))
        
        return bReturn