コード例 #1
0
ファイル: MimeInfo.py プロジェクト: babytux/PyCamimg
 def getIcon(self, path):
     """
     @summary: Gets an icon from path, matching with its mime.
     @param path: Path to get icon.
     @return: Icon of the path. None if it is not gnome or windows platform.
     """
     if (GNOME):
         return FactoryControls.getPixbufFromStock(self.getIconName(path))
     elif (WINDOWS):
         return FactoryControls.getPixbufFromStock(self.getIconName(path))
         
     
     return None
コード例 #2
0
ファイル: TreeExplorer.py プロジェクト: babytux/PyCamimg
 def __initializeExplorer__(self):
     """
     @summary: Initialize TreeView explorer. Add drives of OS.
     """
     # Make a model for TreeView explorer
     self.__model__ = gtk.TreeStore(gtk.gdk.Pixbuf,
                                    gobject.TYPE_STRING,
                                    gobject.TYPE_STRING)
     
     __log__.debug("Created model for TreeExplorer.")
     # Gets home icon
     iconHome = FactoryControls.getPixbufFromStock(gtk.STOCK_HOME)
     
     # Gets drive icon
     icon = FactoryControls.getPixbufFromStock(gtk.STOCK_HARDDISK)
 
     self.__explorer__.set_model(None)
 
     # Apply look to TreeView
     self.__explorer__.set_headers_visible(False)
     self.__explorer__.set_show_expanders(True)
     self.__explorer__.get_selection().set_mode(gtk.SELECTION_SINGLE)
 
     column = FactoryControls.getTreeColumnTextAndPixbuf(_("Explorer"),
                                                         self.__NAME_COLUMN__,
                                                         self.__IMG_COLUMN__)
     self.__explorer__.append_column(column)
 
     __log__.debug("Added columns to TreeExplorer")
     
     # Add home node
     self.addDirectory(self.__HOME_NODE__, os.path.expanduser("~"), iconHome, glock=False)
     
     # Gets drives from the OS
     for sDrive in self.__ioUtils__.getDrives():
         if (sDrive != None) and (sDrive != ""):
             self.addDirectory (sDrive, sDrive, icon, glock=False)
     
     __log__.debug("Drives added.")
     
     # Set model to explorer TreeView
     self.__explorer__.set_model(self.__model__)
コード例 #3
0
ファイル: TreeExplorer.py プロジェクト: babytux/PyCamimg
 def __handlerDirectoryMonitorEvents__(self, path, operation, type):
     """
     @summary: Handle events from directory monitors.
     @param path: Path of the event.
     @param operation: Operation that occurred.
     @param type: Type of path. Directory or File. 
     """
     if (type == DirectoryMonitor.DIRECTORY):
         if (operation == DirectoryMonitor.ADD):
             head, dirname = os.path.split(path)
             iter = self.__getIterFromPath__(head)
             if (iter != None):
                 icon = FactoryControls.getPixbufFromStock(gtk.STOCK_DIRECTORY)
                 self.addDirectory(dirname, path, icon, iter)
         elif (operation == DirectoryMonitor.DELETE):
             iter = self.__getIterFromPath__(path)
             if (iter != None):
                 self.deleteNode(iter)
コード例 #4
0
ファイル: TreeExplorer.py プロジェクト: babytux/PyCamimg
 def __prepareDirectory__(self, directory, iter, glock=True):
     """
     @summary: Checks if a directory has some directory. 
         In truth case, add a temporal subitem.
     @param directory: Directory to prepare.
     @param iter: TreeIter of the directory.
     @param glock: True to lock gtk-loop.  
     """
     sSubDirs = self.__ioUtils__.getDirectories(directory)
     if (sSubDirs != None) and (len(sSubDirs) > 0):
             UIUtils.addIter(self.__model__,
                             iter,
                             (FactoryControls.getPixbufFromStock(gtk.STOCK_EXECUTE) ,
                              _("Loading..."),
                              self.__TEMP_NODE__
                             ),
                             glock
                         )
コード例 #5
0
ファイル: TabProject.py プロジェクト: babytux/PyCamimg
 def __loadCore__(self, core):
     """
     @summary: Load core information in treeview. It will be called by a thread.
     @param core: Core that will be loaded into tab project.
     """
     self.__doPreviewList__ = Configuration().getConfiguration().getboolean("TABPROJECT", "show_image_list")
     self.__maxHeight__ = Configuration().getConfiguration().getint("TABPROJECT", "max_height_list")
     self.__rescalePercent__ = Configuration().getConfiguration().getfloat("TABPROJECT", "resize_percent_list")
     self.__maxHeightImageIconView__ = Configuration().getConfiguration().getint("TABPROJECT", "max_height_imagelist")
     self.__numberOfColumns__ = Configuration().getConfiguration().getint("TABPROJECT", "number_of_columns_iconview")
     
     gtk.gdk.threads_enter()
     try:
         self.__iconview__.set_columns(self.__numberOfColumns__)
     finally:
         gtk.gdk.threads_leave()
     
     UIUtils.clearModelTreeview(self.__model__)
     
     # Gets pixbuf file 
     icon = FactoryControls.getPixbufFromStock(gtk.STOCK_FILE)
     
     for key, item in core.getItems().iteritems():
         item.refreshThumbnail()
         
         # Handler to extract metadata
         metaData = item.getMetadata()
         
         # Create a new row
         newRowData = [icon,
                       item.getPath(),
                       metaData.getDateTimeDigitized(),
                       item.getTarget() ,
                       item.getDescription(),
                       icon,
                       False]
         
         iterAdd = UIUtils.insertIterAtPathPosition(self.__model__, newRowData,
                                                     None, position=gtk.TREE_VIEW_DROP_AFTER)
         __log__.info("File inserted into target treeview. %s" % file)
         
         self.updateItemImage(iterAdd, item)
         
     self.__core__ = core
コード例 #6
0
ファイル: TabProject.py プロジェクト: babytux/PyCamimg
    def addTargetFiles(self,
                       files,
                       iter=None,
                       position=gtk.TREE_VIEW_DROP_AFTER,
                       gtkLock=True):
        """
        @summary: Add a file list into target view.
        @param files:  A list of files to add.
        @param iter: Iter that it will use as reference to insert new files.
        @param position: Position over iter.    
        @param gtkLock: True to do a lock on gtk loop.    
        """
        if (self.__core__ == None):
            __log__.debug("There is not a project in tabproject")
            return
        
        if (files != None):
            iNImages = len(files)
            __log__.debug("Adding new %d images" % iNImages)
            
            operations = RegOperations()
            iterOp = None
            if (operations != None):
                opData = operations.getDataOperation("AddImg",
                                                     _("Adding images..."),
                                                     iNImages)
                # Add new operation to operation treeview
                iterOp = operations.addOperation(opData)
                
            # Gets pixbuf file 
            icon = FactoryControls.getPixbufFromStock(gtk.STOCK_FILE)

            self.__addTargetFiles__(files, icon, iterOp,
                                    iter=iter, position=position,
                                    gtkLock=gtkLock)

            if (iterOp != None):
                operations.removeOperation(iterOp)
        else:
            __log__.debug("There are not files to insert")
コード例 #7
0
ファイル: TabProject.py プロジェクト: babytux/PyCamimg
    def __initializeUI__(self, numberColumns):
        """
        @summary: Initialize TreeView Target.
        """
        iconview = gtk.IconView()
        treeview = gtk.TreeView()

        model = gtk.ListStore(gtk.gdk.Pixbuf,
                              gobject.TYPE_STRING,
                              gobject.TYPE_STRING,
                              gobject.TYPE_STRING,
                              gobject.TYPE_STRING,
                              gtk.gdk.Pixbuf,
                              gobject.TYPE_BOOLEAN,
                              gobject.TYPE_BOOLEAN)

        model.set_default_sort_func(lambda *args:-1)
        
        __log__.debug("Created model for new project")
    
        treeview.set_model(model)
        treeview.set_headers_visible(True)
        treeview.set_headers_clickable(True)
        treeview.set_rules_hint(True)
        treeview.set_enable_search(False)
        treeview.set_fixed_height_mode(False)
        treeview.set_tooltip_column(self.COLUMN_SOURCE)
        treeview.set_show_expanders(False)
        treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
        treeview.set_reorderable(True)
    
        iconview.set_model(model)
        iconview.set_text_column(self.COLUMN_TARGET)
        iconview.set_pixbuf_column(self.COLUMN_PREVIEW)
        iconview.set_tooltip_column(self.COLUMN_SOURCE)
        iconview.set_columns(numberColumns)
        iconview.set_selection_mode(gtk.SELECTION_MULTIPLE)
        iconview.set_reorderable(True)
    
        __log__.debug("Applied settings")
    
        # Creates columns of the TreeView of target files
        column = FactoryControls.getTreeColumnTextAndPixbuf(_("Name"), self.COLUMN_SOURCE, self.COLUMN_IMAGE)
        treeview.append_column(column)
        columnDate = FactoryControls.getTreeColumnText(_("Photo Date"), self.COLUMN_DATE)
        treeview.append_column(columnDate)
        columnTarget = FactoryControls.getTreeColumnText(_("Target Name"), self.COLUMN_TARGET)
        treeview.append_column(columnTarget)
        columnOps = FactoryControls.getTreeColumnText(_("Operations"), self.COLUMN_OPERATIONS)
        treeview.append_column(columnOps)
    
        __log__.debug("Columns added")
    
        # Enabled as drag source
        treeview.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
                                          self.FROM_ITSELF,
                                          gtk.gdk.ACTION_MOVE)
    
        iconview.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
                                          self.FROM_ITSELF,
                                          gtk.gdk.ACTION_MOVE)
            
        # Enabled as drop target
        treeview.enable_model_drag_dest(self.TO_TEXT,
                                        gtk.gdk.ACTION_DEFAULT
                                        | gtk.gdk.ACTION_COPY
                                        | gtk.gdk.ACTION_MOVE)
        
        iconview.enable_model_drag_dest(self.TO_TEXT,
                                        gtk.gdk.ACTION_DEFAULT
                                        | gtk.gdk.ACTION_COPY
                                        | gtk.gdk.ACTION_MOVE)
        
        treeview.connect("drag-data-get", self.__dragTarget__)
        treeview.connect("drag-data-received", self.__dropTarget__)
        treeview.connect("key-press-event", self.__keyPressEvent__)
        
        iconview.connect("drag-data-get", self.__dragTarget__)
        iconview.connect("drag-data-received", self.__dropTarget__)
        iconview.connect("key-press-event", self.__keyPressEvent__)
        
        __log__.debug("Drag & Drop enabled")
        
        scroll = gtk.ScrolledWindow()
        scroll.add(treeview)
        
        size = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)
        if ((self.__iconName__ != None) and (self.__iconName__ != "")):
            pbProject = gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(self.__iconsPath__, self.__iconName__),
                                                             size[0], size[1])
        else:
            pbProject = FactoryControls.getPixbufFromStock(gtk.STOCK_MISSING_IMAGE, gtk.ICON_SIZE_MENU)
            
        imageProject = gtk.Image()
        imageProject.set_from_pixbuf(pbProject)
        
        bClose = gtk.Button(label=None, stock=None, use_underline=False)
        image = gtk.Image()
        image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
        bClose.set_relief(gtk.RELIEF_NONE)
        bClose.set_border_width(0)
        bClose.set_image(image)
        bClose.connect("clicked", self.__buttonActivateSignal__)
        
        lTitle = gtk.Label(str=self.__name__)
        hbTab = gtk.HBox()
        
        hbTab.pack_start(imageProject, expand=False, fill=False, padding=1)
        hbTab.pack_start(lTitle, expand=False, fill=False, padding=2)
        hbTab.pack_start(bClose, expand=False, fill=False)
        
        __log__.debug("Scroll created")
        
        self.__label__ = lTitle
        self.__button__ = bClose
        self.__tabWidget__ = hbTab
        
        self.__treeview__ = treeview
        self.__iconview__ = iconview
        self.__model__ = model
        self.__scroll__ = scroll
コード例 #8
0
ファイル: TreeExplorer.py プロジェクト: babytux/PyCamimg
 def __fillDirectory__(self, path):
     """
     @summary: Fills a node with sub-directories.
     @param path: Folder path to fill. 
     """
     newExpand = False
     # Gets current path
     iter = self.__model__.get_iter(path)
     sPath = self.__model__.get_value(iter, self.__PATH_COLUMN__)
     
     monitor = FactoryDirectoryMonitor.getMonitor(sPath)
     
     # Checks if first child y a temporal node. If it is, it must be removed
     itFirstChild = self.__model__.iter_children(iter)
     if (itFirstChild != None):
         if (self.__model__.get_value(itFirstChild, self.__PATH_COLUMN__) == self.__TEMP_NODE__):
             # Gets number of nodes. If nNodes > 1, 
             # there is another thread that is loading the directory 
             nNodes = self.__model__.iter_n_children(iter)
             if (nNodes > 1):
                 return
             newExpand = True
     else:
         __log__.warning("It can not get first child of %s" % sPath)
 
     # Gets directories of the path
     lDirectories = self.__ioUtils__.getDirectories(sPath,
                                                    showhidden=self.__showHiddens__)
 
     if (lDirectories != None):
         icon = FactoryControls.getPixbufFromStock(gtk.STOCK_DIRECTORY)
             
         if (not newExpand):
             __log__.debug("It is not a new expand. Checking directories...")
             
             iterStep = self.__model__.iter_children(iter)
             # Find deleted iters
             while (iterStep != None):
                 doStep = True
                 sDirFind = self.__model__.get_value(iterStep, self.__NAME_COLUMN__)
                 if (sDirFind != None):
                     try:
                         index = lDirectories.index(sDirFind)
                     except ValueError, ve:
                         __log__.debug("It can not get index of %s. %s" % (sDirFind, ve))
                         index = -1
                     if (index == -1):
                         # In case of directory does not exist, it will remove from treeview
                         iterDelete = iterStep
                         iterStep = self.__model__.iter_next(iterStep)
                         self.deleteNode(iterDelete)
                         __log__.debug("Delete node %s" % sDirFind)
                         
                         doStep = False
                     else:
                         # In case of directory just exists, it will remove from list
                         lDirectories.remove(sDirFind)
                         __log__.debug("%s skipped" % sDirFind)
     
                 if (doStep):
                     iterStep = self.__model__.iter_next(iterStep)
             
             # Check directories in the list 
             for sDir in lDirectories:
                 sFullPath = os.path.join(sPath, sDir)
                 checkIter = self.__findDirectoryOnParent__(iter, sDir)
                 if (checkIter == None):
                     self.addDirectory(sDir, sFullPath, icon, iter)
                     __log__.debug("Add %s" % sFullPath)
         
         # Insert directories
         for sDir in lDirectories:
             sFullPath = os.path.join(sPath, sDir)
             self.addDirectory(sDir, sFullPath, icon, iter)
             __log__.debug("Add %s" % sFullPath)
                 
         if ((itFirstChild != None) and newExpand):
             __log__.debug("Remove temporal node.")
             self.deleteNode(itFirstChild)
             
         monitor.addDirectories(lDirectories)
         monitor.addListener(self.__handlerDirectoryMonitorEvents__)
コード例 #9
0
ファイル: ImageArea.py プロジェクト: babytux/PyCamimg
 def set_from_stock(self, stock):
     """
     @summary: Set image from stock image.
     @param Id stock of the image.: 
     """
     self.set_from_pixbuf(FactoryControls.getPixbufFromStock(stock))