def data(self, index, role): if not index.isValid(): return to_qvariant() item = index.internalPointer() # Text if (role == qt.QtCore.Qt.DisplayRole): # Add size info lenstr = '' try: l = item.nb_public_values() if (l): lenstr = " ( %i )" % (l, ) except: pass return to_qvariant(str(item.get_id()) + lenstr) # Tool Tip elif (role == qt.QtCore.Qt.ToolTipRole): return to_qvariant(str(item.get_tip())) # Icon elif (role == qt.QtCore.Qt.DecorationRole): return get_icon(item) else: return to_qvariant()
def data(self, index, role): if not index.isValid(): return to_qvariant() item = index.internalPointer() # Text if (role == qt.QtCore.Qt.DisplayRole): # Add size info lenstr='' try: l = item.nb_public_values() if(l) : lenstr = " ( %i )"%(l,) except: pass return to_qvariant(str(item.get_id()) + lenstr) # Tool Tip elif( role == qt.QtCore.Qt.ToolTipRole ): return to_qvariant(str(item.get_tip())) # Icon elif(role == qt.QtCore.Qt.DecorationRole): return get_icon(item) else: return to_qvariant()
def bind_action(self, action, fName, kwargs=None): func, argcount = self.__get_wrapped(fName, kwargs) #self.unbind_action(action, fName) action.triggered.connect(func) data = to_qvariant(func) action.setData(data) return action
def decorate_element(self, elt, name, newItem, parent=None): icon = get_icon2(elt) newItem.setIcon(icon) newItem.setToolTip(elt.get_tip()) newItem.setData(to_qvariant(elt), self.pkgmodelRole) if parent: parent.appendRow(newItem) return newItem
def data(self, index, role): if (not index.isValid()): return to_qvariant() if (index.row() >= len(self.searchresult)): return to_qvariant() item = self.searchresult[index.row()] if (role == qt.QtCore.Qt.DisplayRole): if(index.column() == 1): return to_qvariant(str(item.package.get_id())) return to_qvariant(str(item.name+ " ("+item.package.name+")")) # Icon elif( role == qt.QtCore.Qt.DecorationRole ): if(index.column()>0) : return to_qvariant() return get_icon(item) # Tool Tip elif( role == qt.QtCore.Qt.ToolTipRole ): return to_qvariant(str(item.get_tip())) else: return to_qvariant()
def data(self, index, role): if (not index.isValid()): return to_qvariant() if (index.row() >= len(self.searchresult)): return to_qvariant() item = self.searchresult[index.row()] if (role == qt.QtCore.Qt.DisplayRole): if (index.column() == 1): return to_qvariant(str(item.package.get_id())) return to_qvariant(str(item.name + " (" + item.package.name + ")")) # Icon elif (role == qt.QtCore.Qt.DecorationRole): if (index.column() > 0): return to_qvariant() return get_icon(item) # Tool Tip elif (role == qt.QtCore.Qt.ToolTipRole): return to_qvariant(str(item.get_tip())) else: return to_qvariant()
def __on_data_added(self, proj, doc): newItem = QtGui.QStandardItem(doc.name) newItem.setData(to_qvariant(doc), self.dataRole) icon = doc.icon newItem.setIcon(icon) newItem.setDragEnabled(True) parItem = self.__activeProjItem parItem.appendRow(newItem) self.__docItemMap[doc] = newItem
def set_active_project(self, proj, old=None): # -- clear the view (maybe be less radical) -- self.__clear(old) # -- now set active project and reconnect slots to this one -- if proj: self.__activeProj = proj self.__activeProjItem = QtGui.QStandardItem(proj.name) self.__activeProjItem.setData(to_qvariant(proj), self.projectRole) self.appendRow(self.__activeProjItem) self.connect_project(proj) for k, v in proj: self.__on_data_added(proj, v)
def get_icon(item): """ Return Icon object depending of the type of item """ global icon_dict if (not icon_dict): # dict to do a switch icon_dict = { PseudoGroup: to_qvariant(qt.QtGui.QPixmap(":/icons/category.png")), CompositeNodeFactory: to_qvariant(qt.QtGui.QPixmap(":/icons/diagram.png")), NodeFactory: to_qvariant(qt.QtGui.QPixmap(":/icons/node.png")), DataFactory: to_qvariant(qt.QtGui.QPixmap(":/icons/data.png")), UserPackage: to_qvariant(qt.QtGui.QPixmap(":/icons/usrpkg.png")), Package: to_qvariant(qt.QtGui.QPixmap(":/icons/pkg.png")), } # Get icon from dictionary if (type(item) in icon_dict): return icon_dict[type(item)] elif (isinstance(item, PseudoPackage)): if (item.is_real_package()): # Try to load package specific icon icon = item.item.metainfo.get("icon", None) if (icon): icon = os.path.join(item.item.path, icon) pix = qt.QtGui.QPixmap(icon) if (not pix.isNull()): return to_qvariant(pix) # Standard icon return icon_dict[type(item.item)] return to_qvariant(qt.QtGui.QPixmap(":/icons/pseudopkg.png")) else: return to_qvariant()
def update_combo_list(self): proj = self.__project self.__browseDataBut.blockSignals(True) currentText = self.__browseDataBut.currentText() self.__browseDataBut.clear() if not self.__restrictedToApplet: mimetypes = [f.created_mimetype for f in \ DataFactoryManager().gather_items().itervalues()] else: mimetypes = self.__applet.get_mimetypes() data = [(datum,proj) for k, datum in proj if datum.mimetype in mimetypes] for dp in data: if dp[0].hidden: continue self.__browseDataBut.addItem(dp[0].icon, dp[0].name, to_qvariant(dp)) self.__browseDataBut.insertSeparator(self.__browseDataBut.count()) globalProj = GlobalDataManager() globalData = [(datum, globalProj) for k, datum in globalProj \ if datum.mimetype in mimetypes] for dp in globalData: if dp[0].hidden: continue self.__browseDataBut.addItem(dp[0].icon, dp[0].name, to_qvariant(dp)) index = self.__browseDataBut.findText(currentText) self.__browseDataBut.setCurrentIndex(index) self.__browseDataBut.blockSignals(False) return data
def __onLayoutListChanged(self, layoutNames): self._layoutMode.blockSignals(True) oldDataMap = {} current = self._layoutMode.currentText() for index in range(self._layoutMode.count()): oldDataMap[str(self._layoutMode.itemText(index))] = self._layoutMode.itemData(index) self._layoutMode.clear() layoutNames.sort() for ln in layoutNames: self._layoutMode.addItem(ln, oldDataMap.get(ln, to_qvariant())) self._layoutMode.adjustSize() ind = self._layoutMode.findText(current) self._layoutMode.setCurrentIndex(ind) self._layoutMode.blockSignals(False)
def get_icon(item): """ Return Icon object depending of the type of item """ global icon_dict if(not icon_dict): # dict to do a switch icon_dict = { PseudoGroup : to_qvariant(qt.QtGui.QPixmap(":/icons/category.png")), CompositeNodeFactory : to_qvariant(qt.QtGui.QPixmap(":/icons/diagram.png")), NodeFactory : to_qvariant(qt.QtGui.QPixmap(":/icons/node.png")), DataFactory : to_qvariant(qt.QtGui.QPixmap(":/icons/data.png")), UserPackage : to_qvariant(qt.QtGui.QPixmap(":/icons/usrpkg.png")), Package : to_qvariant(qt.QtGui.QPixmap(":/icons/pkg.png")), } # Get icon from dictionary if(type(item) in icon_dict): return icon_dict[type(item)] elif(isinstance(item, PseudoPackage)): if(item.is_real_package()): # Try to load package specific icon icon = item.item.metainfo.get("icon", None) if(icon): icon = os.path.join(item.item.path, icon) pix = qt.QtGui.QPixmap(icon) if(not pix.isNull()): return to_qvariant(pix) # Standard icon return icon_dict[type(item.item)] return to_qvariant(qt.QtGui.QPixmap(":/icons/pseudopkg.png")) else: return to_qvariant()
def data(self, index, role): if (not index.isValid()): return to_qvariant() if (index.row() >= len(list(self.datapool.keys()))): return to_qvariant() if (role == qt.QtCore.Qt.DisplayRole): l = list(self.datapool.keys()) l.sort() name = l[index.row()] #classname = self.datapool[name].__class__ value = repr(self.datapool[name]) if(len(value) > 30): value = value[:30] + "..." return to_qvariant("%s ( %s )" % (name, value)) # Icon elif(role == qt.QtCore.Qt.DecorationRole): return to_qvariant(qt.QtGui.QPixmap(":/icons/ccmime.png")) # Tool Tip elif(role == qt.QtCore.Qt.ToolTipRole): l = list(self.datapool.keys()) l.sort() name = l[index.row()] tips = [name] tips.append("%s\n" % (str(self.datapool[name]),)) tips.append("Dir :") temp = "" for i, n in enumerate(dir(self.datapool[name])): s = str(n) if(len(s) > 20): s = s[:20] temp += s + "\t\t" # 2 column view if(i % 2): tips.append(temp) temp = "" if(temp): tips.append(temp) tipstr = '\n'.join(tips) return to_qvariant(str(tipstr)) else: return to_qvariant()
def data(self, index, role): if (not index.isValid()): return to_qvariant() if (index.row() >= len(list(self.datapool.keys()))): return to_qvariant() if (role == qt.QtCore.Qt.DisplayRole): l = list(self.datapool.keys()) l.sort() name = l[index.row()] #classname = self.datapool[name].__class__ value = repr(self.datapool[name]) if (len(value) > 30): value = value[:30] + "..." return to_qvariant("%s ( %s )" % (name, value)) # Icon elif (role == qt.QtCore.Qt.DecorationRole): return to_qvariant(qt.QtGui.QPixmap(":/icons/ccmime.png")) # Tool Tip elif (role == qt.QtCore.Qt.ToolTipRole): l = list(self.datapool.keys()) l.sort() name = l[index.row()] tips = [name] tips.append("%s\n" % (str(self.datapool[name]), )) tips.append("Dir :") temp = "" for i, n in enumerate(dir(self.datapool[name])): s = str(n) if (len(s) > 20): s = s[:20] temp += s + "\t\t" # 2 column view if (i % 2): tips.append(temp) temp = "" if (temp): tips.append(temp) tipstr = '\n'.join(tips) return to_qvariant(str(tipstr)) else: return to_qvariant()
def __onLayoutChosen(self, index): """Called when a user chooses a layout. Fetches the corresponding layout from the registered applications and installs a new splitter in the central window.""" proj = self.__projMan.get_active_project() layoutName = str(self._layoutMode.itemText(index)) if layoutName is None or layoutName == "": return data = self._layoutMode.itemData(index)#.toPyObject() if data and isinstance(data, CustomSplittable): index = self.__centralStack.indexOf(data) if index == -1: self.__centralStack.addWidget(data) self.__centralStack.setCurrentWidget(data) else: # layoutNames encodes the application # name and the layout name: # they are seperated by a period. layout = LayoutManager().get(layoutName) if not layout: return # -- FILL THE LAYOUT WITH WIDGETS DESCRIBED BY THE APPLET MAP -- # create new splittable and retreive objects from previous newSplit, taken = self.__new_splittable(layout.skeleton) contentmap = layout.contentmap afm = AppletFactoryManager() gdm = GlobalDataManager() for paneId in newSplit.leaves(): contentDesc = contentmap.get(paneId) if not contentDesc: space = AppletSpace(proj=proj) else: resName, resType = contentDesc if resType == "g": dataName = resName data = gdm.get_data_by_name(dataName) appFac = DataEditorSelector.mime_type_handler([data.mimetype], applet=True) elif resType == "a": appletName = resName appFac = afm.get(appletName) if appFac is None: self.logger.error("__onLayoutChosen has None factory for "+ resName) continue try: space = appFac(proj) if resType == "g": space.show_data(data) except Exception, e: self.logger.error("__onLayoutChosen cannot display "+ \ resName+":"+\ e.message) traceback.print_exc() continue if space: self.__setSpaceAt(newSplit, paneId, space) self.__centralStack.addWidget(newSplit) self.__centralStack.setCurrentWidget(newSplit) self._layoutMode.setItemData(index, to_qvariant(newSplit))
def headerData(self, section, orientation, role): return to_qvariant()