Exemplo n.º 1
0
 def attributesByName(self, node, attrpath, ABSOLUTE_ATTR_NAME):
     val = node.attributesByName(attrpath, ABSOLUTE_ATTR_NAME)
     if len(val) == 1:
         if val[0].type() == typeId.VTime:
             vtime = val[0].value()
             if vtime:
                 return vtime.get_time()
         else:
             return val[0].value()
Exemplo n.º 2
0
 def attributesByName(self, node, attrpath, ABSOLUTE_ATTR_NAME):
     val = node.attributesByName(attrpath, ABSOLUTE_ATTR_NAME)
     if len(val) == 1:
       if val[0].type() == typeId.VTime:
           vtime = val[0].value()
           if vtime:
             return vtime.get_time()
       else:
           return val[0].value()
Exemplo n.º 3
0
    def data(self, index, role):
        attributes = self.availableAttributes()
        if not index.isValid():
            return QVariant()
        if index.row() > len(self.__list) or index.row() < 0:
            return QVariant()
        try:
            node = self.__rows[index.row()]
        except:
            return QVariant()
        if role == Qt.DisplayRole:
            attrpath = str(unicode(attributes[index.column()]).encode('utf-8'))
            if attrpath == "name":
                return QVariant(QString.fromUtf8(node.name()))
            elif attrpath == "size":
                return QVariant(node.size())
            elif attrpath == "extension":
                return QVariant(QString.fromUtf8(node.extension()))
            elif attrpath == "path":
                if isinstance(node, VLink):
                    return QVariant(QString.fromUtf8(node.linkPath()))
                else:
                    return QVariant(QString.fromUtf8(node.path()))
            elif attrpath == "absolute":
                if isinstance(node, VLink):
                    return QVariant(QString.fromUtf8(node.linkAbsolute()))
                else:
                    return QVariant(QString.fromUtf8(node.absolute()))
            elif attrpath == "module":
                if node.fsobj():
                    return QVariant(QString.fromUtf8(node.fsobj().name))
                return QVariant()
            elif attrpath == "has children":
                if isinstance(node, VLink):
                    return QVariant(node.linkHasChildren())
                else:
                    return QVariant(node.hasChildren())
            elif attrpath == "child count":
                if isinstance(node, VLink):
                    return QVariant(node.linkChildCount())
                else:
                    return QVariant(node.childCount())
            elif attrpath == "is deleted":
                return QVariant(node.isDeleted())

            else:
                try:
                    val = node.attributesByName(attrpath, ABSOLUTE_ATTR_NAME)
                except Exception as e:
                    print "NodeListModel data can't get attribute " + attrpath + " by name " + str(
                        e)
                    return QVariant()
                if len(val) == 1:
                    if val[0].type() == typeId.VTime:
                        vtime = val[0].value()
                        if vtime:
                            return QVariant(str(vtime.get_time()))
                    elif val[0].type() == typeId.String:
                        return QVariant(QString.fromUtf8(val[0].value()))
                    else:
                        return QVariant(val[0].value())

        if role == Qt.ToolTipRole:
            return QVariant(QString.fromUtf8(node.name()))

        # Display icons
        if (role == Qt.DecorationRole) and (attributes[index.column()]
                                            == "name"):
            pixmap = None
            if self.__thumb:
                if self.thumbnailer.isThumbnailable(node):
                    pixmap = self.thumbnailer.generate(node)
                    if not pixmap:
                        pixmap = QPixmap(":file_temporary.png")
            if not pixmap:
                pixmap = self.getIconPixmap(node)
                if not pixmap:
                    pixmap = QPixmap(node.icon())

                if isinstance(node, VLink):
                    pixmap = pixmap.scaled(QSize(128, 128), Qt.KeepAspectRatio)
                    painter = QPainter(pixmap)
                    linkPixmap = QPixmap(":vlink")
                    painter.drawPixmap(0, 0, linkPixmap)
                    painter.end()

                elif node.hasChildren():
                    try:
                        pfsobj = node.children()[0].fsobj().this
                    except AttributeError:
                        pfsobj = None
                    try:
                        nfsobj = node.fsobj().this
                    except AttributeError:
                        nfsobj = None
                    if pfsobj != nfsobj:
                        pixmap = pixmap.scaled(QSize(128, 128),
                                               Qt.KeepAspectRatio)
                        painter = QPainter(pixmap)
                        rootPixmap = QPixmap(":root")
                        painter.drawPixmap(0, 0, rootPixmap)
                        painter.end()

            return QVariant(QIcon(pixmap))

        if role == Qt.BackgroundRole:
            if index.row() == self.activeSelection():
                palette = QPalette().color(QPalette.Highlight)
                return QVariant(QColor(palette))
        if role == Qt.ForegroundRole:
            if index.row() == self.activeSelection():
                palette = QPalette().color(QPalette.HighlightedText)
                return QVariant(QColor(palette))
            if node.isDeleted():
                return QVariant(QColor(Qt.red))

        if (role == Qt.CheckStateRole) and (attributes[index.column()]
                                            == "name"):
            if long(node.this) in self.selection.get():
                return Qt.Checked
            else:
                return Qt.Unchecked
        return QVariant()
Exemplo n.º 4
0
  def data(self, index, role):
    attributes = self.availableAttributes()
    if not index.isValid():
      return QVariant()
    if index.row() > len(self.__list) or index.row() < 0:
      return QVariant()
    try:
      node = self.__rows[index.row()]
    except:
      return QVariant()
    if role == Qt.DisplayRole :
      attrpath = str(unicode(attributes[index.column()]).encode('utf-8'))
      if attrpath == "name":
          return QVariant(QString.fromUtf8(node.name()))
      elif attrpath == "size":
          return QVariant(node.size())
      elif attrpath == "extension":
          return QVariant(QString.fromUtf8(node.extension()))
      elif attrpath == "path":
          if isinstance(node, VLink):
            return QVariant(QString.fromUtf8(node.linkPath()))
          else:
            return QVariant(QString.fromUtf8(node.path()))
      elif attrpath == "absolute":
          if isinstance(node, VLink):
            return QVariant(QString.fromUtf8(node.linkAbsolute()))
          else:
           return QVariant(QString.fromUtf8(node.absolute()))
      elif attrpath == "module":
	  if node.fsobj():
            return QVariant(QString.fromUtf8(node.fsobj().name))
          return QVariant()
      elif attrpath == "has children":
          if isinstance(node, VLink):
            return QVariant(node.linkHasChildren())
          else:
            return QVariant(node.hasChildren())
      elif attrpath == "child count":
          if isinstance(node, VLink):
            return QVariant(node.linkChildCount())
          else:
            return QVariant(node.childCount())
      elif attrpath == "is deleted":
          return QVariant(node.isDeleted())
	
      else:
	try :
          val = node.attributesByName(attrpath, ABSOLUTE_ATTR_NAME)
	except Exception as e:
	   print "NodeListModel data can't get attribute " + attrpath + " by name " + str(e)
	   return QVariant()
        if len(val) == 1:
          if val[0].type() == typeId.VTime:
            vtime = val[0].value()
            if vtime:
              return QVariant(str(vtime.get_time()))
          elif val[0].type() == typeId.String:
            return QVariant(QString.fromUtf8(val[0].value()))
          else:
            return QVariant(val[0].value())

    if role == Qt.ToolTipRole :
      return QVariant(QString.fromUtf8(node.name()))

    # Display icons
    if (role == Qt.DecorationRole) and (attributes[index.column()] == "name"):
      pixmap = None
      if self.__thumb:
	if self.thumbnailer.isThumbnailable(node):
	  pixmap = self.thumbnailer.generate(node)
          if not pixmap:
	    pixmap = QPixmap(":file_temporary.png")
      if not pixmap:
        pixmap = self.getIconPixmap(node)
        if not pixmap:
          pixmap = QPixmap(node.icon())
        
        if isinstance(node, VLink):
          pixmap = pixmap.scaled(QSize(128, 128), Qt.KeepAspectRatio)
          painter = QPainter(pixmap)
          linkPixmap = QPixmap(":vlink") 
          painter.drawPixmap(0, 0, linkPixmap)
          painter.end()

	elif node.hasChildren():
          try:
            pfsobj = node.children()[0].fsobj().this
          except AttributeError:
  	    pfsobj = None
          try:
            nfsobj = node.fsobj().this
          except AttributeError:
	    nfsobj = None
          if pfsobj != nfsobj:
            pixmap = pixmap.scaled(QSize(128, 128), Qt.KeepAspectRatio)
            painter = QPainter(pixmap)
            rootPixmap = QPixmap(":root")
            painter.drawPixmap(0, 0, rootPixmap)
            painter.end()

      return QVariant(QIcon(pixmap))
	
    if role == Qt.BackgroundRole:
      if index.row() == self.activeSelection():
        palette = QPalette().color(QPalette.Highlight)
        return QVariant(QColor(palette))
    if role == Qt.ForegroundRole:
      if index.row() == self.activeSelection():
        palette = QPalette().color(QPalette.HighlightedText)
        return QVariant(QColor(palette))
      if node.isDeleted():
        return  QVariant(QColor(Qt.red))

    if (role == Qt.CheckStateRole) and (attributes[index.column()] == "name"):
      if long(node.this) in self.selection.get():
        return Qt.Checked
      else:
        return Qt.Unchecked
    return QVariant()