Ejemplo n.º 1
0
def get_icon(index, default=None):
    '''
    Makes the best effort to find an icon for an index.
    Index can be a path, a Qt resource path, an integer.
    @return: QIcon instance or None if no icon could be retrieved
    '''
    #Try icon in db
    path = getResourcePath(index, ["Icons", "External"])
    if path is not None:
        return QtGui.QIcon(path)
    elif isinstance(index, basestring):
        #Try file path
        if os.path.isfile(index):
            return __fileIconProvider.icon(QtCore.QFileInfo(index))
        elif os.path.isdir(index):
            return __fileIconProvider.icon(QtGui.QFileIconProvider.Folder)
        elif QtGui.QIcon.hasThemeIcon(index):
            return QtGui.QIcon._fromTheme(index)
        elif default is not None:
            return default
        else:
            return QtGui.QIcon(getResourcePath("notfound", ["Icons"]))
    elif isinstance(index, int):
        #Try icon by int index in fileicon provider
        return __fileIconProvider.icon(index)
Ejemplo n.º 2
0
class ConfigureTreeNode(TreeNodeBase):
    NAMESPACE = ""
    ICON = QtGui.QIcon()
    TITLE = ""

    def __init__(self, name, parent=None):
        TreeNodeBase.__init__(self, name, parent)
        self.setTitle(self.TITLE)
        self.setIcon(self.ICON)

    def filterString(self):
        return self.nodeName() + self.title() + reduce(
            lambda initial, child: initial + child.filterString(),
            self.childrenNodes, "")

    def title(self):
        return self.__title

    def setTitle(self, title):
        self.__title = title

    def icon(self):
        return self.__icon

    def setIcon(self, icon):
        self.__icon = icon
Ejemplo n.º 3
0
 def tabIcon(self):
     baseIcon = QtGui.QIcon()
     if self.filePath is not None:
         baseIcon = resources.getIcon(self.filePath)
     if self.isModified():
         baseIcon = resources.getIcon("document-save")
     if self.externalAction != None:
         importantIcon = resources.getIcon("emblem-important")
         baseIcon = combine_icons(baseIcon, importantIcon, 0.8)
     return baseIcon
Ejemplo n.º 4
0
def get_std_icon(name, size=None):
    """Get standard platform icon
    Call 'show_std_icons()' for details"""
    if not name.startswith('SP_'):
        name = 'SP_' + name
    icon = QtGui.QWidget().style().standardIcon(getattr(QtGui.QStyle, name))
    if size is None:
        return icon
    else:
        return QtGui.QIcon(icon.pixmap(size, size))
Ejemplo n.º 5
0
 def addPathToFavourites(self, path):
     """
     Adds an entry to the File Manager 
     @param path: Adds parameter to path
     """
     if os.path.isdir(unicode(path)):
         root, dirname_part = path.rsplit(os.sep, 1)
         self.comboFavourites.addItem(dirname_part, {
             'path': path,
             'icon': QtGui.QIcon()
         })
     else:
         self.logger.debug("Not a directory %s" % path)
Ejemplo n.º 6
0
class PMXBaseDock(PMXBaseWidgetComponent):
    SHORTCUT = ""
    ICON = QtGui.QIcon()
    PREFERED_AREA = QtCore.Qt.RightDockWidgetArea

    def __init__(self):
        PMXBaseWidgetComponent.__init__(self)
        self.toggleViewAction().setShortcut(QtGui.QKeySequence(self.SHORTCUT))
        self.toggleViewAction().setIcon(self.ICON)

    def runKeyHelper(self, event):
        runHelper = False
        for helper in self.findHelpers(event.key()):
            runHelper = helper.accept(event)
            if runHelper:
                helper.execute(event)
                break
        return runHelper
Ejemplo n.º 7
0
def combine_icons(icon1, icon2, scale=1):
    newIcon = QtGui.QIcon()
    sizes = icon1.availableSizes()
    if not sizes:
        sizes = [
            QtCore.QSize(16, 16),
            QtCore.QSize(22, 22),
            QtCore.QSize(32, 32),
            QtCore.QSize(48, 48)
        ]
    for size in sizes:
        pixmap1 = icon1.pixmap(size)
        pixmap2 = icon2.pixmap(size)
        pixmap2 = pixmap2.scaled(pixmap1.width() * scale,
                                 pixmap1.height() * scale)
        result = QtGui.QPixmap(size)
        result.fill(QtCore.Qt.transparent)
        painter = QtGui.QPainter(result)
        painter.drawPixmap(0, 0, pixmap1)
        painter.drawPixmap(pixmap1.width() - pixmap2.width(),
                           pixmap1.height() - pixmap2.height(), pixmap2)
        painter.end()
        newIcon.addPixmap(result)
    return newIcon
Ejemplo n.º 8
0
 def getIcon(self, index, default = None):
     if index in self.resources:
         return QtGui.QIcon(self.resources[index])
     return resources.getIcon(index)