我们从Python开源项目中,提取了以下19个代码示例,用于说明如何使用PySide.QtGui.QListWidgetItem()。
def populate_type_shot_Widget(self): type_shot_dict = {"ALL": "all_icon.png", "CAM": "cam_icon.png", "LGT": "lgt_icon.png", "ANM": "animation_icon.png", "DMP": "matte_painting_icon.png", "PNT": "pnt_icon.png", "RTO": "Roto_icon.png", "CMP": "cmp_icon.png", "SFX": "sfx_icon.png" } # populating The left widget list part with different types of assets. for n, v in sorted(type_shot_dict.iteritems()): icon_all = os.path.join(os.getenv("CYC_CORE_PATH"), "icons", v) type_wid = Type_widget() type_wid.set_text(n) type_wid.set_icon(icon_all) wid2 = QtWidgets.QListWidgetItem() wid2.setSizeHint(type_wid.sizeHint()) self.shot_type_listWidget.addItem(wid2) self.shot_type_listWidget.setContentsMargins(100, 100, 100, 100) self.shot_type_listWidget.setItemWidget(wid2, type_wid)
def populate_type_asset_Widget(self): type_asset_dict = {"ALL": "all_icon.png", "CPA": "Concept_art_icon.png", "MOD": "modeling_icon.png", "TXT": "texture_icon.png", "RIG": "rigging_icon.png", "LYT": "layout_icon.png", "CRE": "Creature_icon.png", "SHD": "SHD_icon.png" } # populating The left widget list part with different types of assets. for n, v in sorted(type_asset_dict.iteritems()): icon_all = os.path.join(os.getenv("CYC_CORE_PATH"), "icons", v) type_wid = Type_widget() type_wid.set_text(n) type_wid.set_icon(icon_all) wid2 = QtWidgets.QListWidgetItem() wid2.setSizeHint(type_wid.sizeHint()) self.assets_type_listWidget.addItem(wid2) self.assets_type_listWidget.setContentsMargins(100, 100, 100, 100) self.assets_type_listWidget.setItemWidget(wid2, type_wid)
def open(self): ''' load all packages types to list ''' packages = [] for j in FreeCAD.activeDocument().Objects: if hasattr(j, "Proxy") and hasattr(j.Proxy, "Type") and j.Proxy.Type in ["PCBpart", "PCBpart_E"] and not j.Package in packages: a = QtGui.QListWidgetItem(j.Package) a.setData(QtCore.Qt.UserRole, j.Package) a.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsUserCheckable) try: a.setIcon(j.ViewObject.Icon) except AttributeError: pass if self.updateModel: if self.updateModel == j.Package: a.setCheckState(QtCore.Qt.Checked) else: a.setCheckState(QtCore.Qt.Unchecked) else: a.setCheckState(QtCore.Qt.Checked) self.form.listaElementow.addItem(a) packages.append(j.Package)
def drag_to_shortcut(self): print self.drag_file if os.path.exists(self.drag_file): software_name = os.path.basename(self.drag_file).split('.')[0] software_path = self.drag_file if not software_name in self.data: software_icon = pathjoin(self.app_dir, 'resources', 'default_software_icon.png').replace('\\', '/') self.data.update({software_name: {'path': software_path, 'icon': 'default_software_icon.png', 'describe': software_name, 'order': self.software_commands.count()}}) image = QtGui.QIcon(software_icon) layer_item = QtGui.QListWidgetItem(image, software_name) layer_item.setToolTip(u'%s' % software_name) layer_item.setTextAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) self.software_commands.addItem(layer_item) print self.data self.save_profile()
def getTwits(self,keyWord): if len(keyWord) == 0: keyWord =u'"gündem"' self.lineEdit.setText(keyWord) self.alText = u'' try : tList = self.twitter.search(keyWord, start=self.prevId, count=10, cached=False) except: message = "Twitter Aram Limiti Lütfen Biraz Bekleyin" QtGui.QMessageBox.information(self.dialog, "Information", "Python rocks!") for tweet in tList: self.listWidget.addItem(QtGui.QListWidgetItem(cleanTweet(tweet.text))) self.twIds.append(tweet.id) self.listWidget.setCurrentRow(self.listWidget.count()-1) tweet.text = self.filterRT(tweet.text) tweet.text = self.filterLink(tweet.text) self.alText = self.alText + plaintext(tweet.text) + u' ' self.prevId = tweet.id
def setupUi(self, sonosConnect): sonosConnect.setObjectName("sonosConnect") self.gridLayout = QtGui.QGridLayout(sonosConnect) self.connectList = QtGui.QListWidget(sonosConnect) QtGui.QListWidgetItem(self.connectList) self.gridLayout.addWidget(self.connectList, 0, 0, 1, 3) self.checkBox = QtGui.QCheckBox(sonosConnect) self.gridLayout.addWidget(self.checkBox, 2, 0, 1, 1) self.connectButton = QtGui.QPushButton(sonosConnect) self.gridLayout.addWidget(self.connectButton, 2, 2, 1, 1) self.rescanButton = QtGui.QPushButton(sonosConnect) self.gridLayout.addWidget(self.rescanButton, 2, 1, 1, 1) self.retranslateUi(sonosConnect) QtCore.QMetaObject.connectSlotsByName(sonosConnect)
def getSnapshots(self): """ Logic to retrieve the snapshots from the output file """ files = None files = [ f for f in os.listdir(self.directory_path[0]) if os.path.isfile(os.path.join(self.directory_path[0],f)) ] self.screenshot.listFiles.clear() for i,fileName in enumerate(files): item = None item = QtGui.QListWidgetItem(unicode(fileName),self.screenshot.listFiles) self.screenshot.show()
def formatPliku(self): page = QtGui.QWizardPage() page.setSubTitle(u"<span style='font-weight:bold;font-size:13px;'>File format</span>") # self.nazwaProgramu = QtGui.QLabel() self.formatPliku = QtGui.QLabel() self.ikonaProgramu = QtGui.QLabel() self.ikonaProgramu.setFixedSize(120, 120) self.ikonaProgramu.setAlignment(QtCore.Qt.AlignCenter) # self.listaFormatow = QtGui.QListWidget() for i, j in supSoftware.items(): if j['export']: a = QtGui.QListWidgetItem(j['name']) a.setData(QtCore.Qt.UserRole, i) self.listaFormatow.addItem(a) QtCore.QObject.connect(self.listaFormatow, QtCore.SIGNAL("currentRowChanged (int)"), self.zmianaProgramu) # lay = QtGui.QGridLayout(page) lay.addWidget(self.listaFormatow, 0, 0, 4, 1) lay.addWidget(self.ikonaProgramu, 0, 1, 1, 1, QtCore.Qt.AlignCenter) lay.addWidget(self.nazwaProgramu, 1, 1, 1, 1) lay.addWidget(self.formatPliku, 2, 1, 1, 1) lay.setHorizontalSpacing(20) lay.setColumnMinimumWidth(1, 140) return page
def addItem(self, path): item = QtGui.QListWidgetItem(path) #item.setData(QtCore.Qt.UserRole, absolutePath) self.checkPath(item) item.setFlags(QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsUserCheckable) self.pathsList.addItem(item)
def addCamera(self): cameraName = self.cameraName.text().strip() if cameraName == '': return if len(self.camerasList.findItems(cameraName, QtCore.Qt.MatchExactly)) == 0: item = QtGui.QListWidgetItem(cameraName) item.setData(QtCore.Qt.UserRole, self.cameraParam()) self.camerasList.addItem(item) else: FreeCAD.Console.PrintWarning("Camera already exist.\n")
def readObjects(self): for i in FreeCAD.ActiveDocument.Objects: if hasattr(i.ViewObject, "Transparency"): self.transaprency[i] = i.ViewObject.Transparency i.ViewObject.Transparency = 80 if (hasattr(i, "Shape") and i.Shape.Solids != [] and (i.InList == [] or i.InList[0].TypeId == 'App::DocumentObjectGroup')) or hasattr(i, "Proxy") and hasattr(i.Proxy, "Type") and i.Proxy.Type in ["assemblyMain"]: a = QtGui.QListWidgetItem(i.Label) a.setData(QtCore.Qt.UserRole, i.Name) a.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsUserCheckable) try: a.setIcon(i.ViewObject.Icon) except AttributeError: pass a.setCheckState(QtCore.Qt.Unchecked) self.table1.addItem(a) ########### a = QtGui.QListWidgetItem(i.Label) a.setData(QtCore.Qt.UserRole, i.Name) a.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsUserCheckable) try: a.setIcon(i.ViewObject.Icon) except AttributeError: pass a.setCheckState(QtCore.Qt.Unchecked) self.table2.addItem(a)
def _avoid_system_name(self, sys_name): if sys_name: if sys_name not in self.avoidance_list(): QtGui.QListWidgetItem(sys_name, self.listWidget_avoid) self._avoid_message("Added", MainWindow.MSG_OK) else: self._avoid_message("Already in list!", MainWindow.MSG_ERROR) else: self._avoid_message("Invalid system name :(", MainWindow.MSG_ERROR)
def __init__(self, parent = None): super(ParameterTypeList, self).__init__(parent) self.setDragEnabled(True) for t in ['int','float','string']: item = QtGui.QListWidgetItem(t, self)
def search_software(self): self.software_commands.clear() result = [] soft_name = self.search_text.text() pattem = '.*?'.join(soft_name.lower()) regex = re.compile(pattem) Manager.sort_data(self.data) for software_name in self.data.keys(): match = regex.search(software_name.lower()) if match: result.append((len(match.group()), match.start(), software_name)) if result: sorted_result = [x for _, _, x in sorted(result)] for r in sorted_result: icon_name = self.data[r]['icon'] if icon_name: image_path = pathjoin(self.app_dir, 'resources', icon_name) else: image_path = pathjoin(self.app_dir, 'resources', 'default_software_icon.png') if not os.path.isfile(image_path): image_path = pathjoin(self.app_dir, 'resources', 'default_software_icon.png') image = QtGui.QIcon(image_path) layer_item = QtGui.QListWidgetItem(image, r) describe_msg = 'Describe:\n\t{0}\nPath:\n\t{1}'.format(r, self.data[r].get('path')) layer_item.setToolTip(describe_msg) layer_item.setTextAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) self.software_commands.addItem(layer_item)
def setListItems(self, mapped_items, slotType): if slotType is not "C": slot = mapped_items[slotType] listWidget = slot["list"] listWidget.clear() for item in sorted(slot["items"]): QtGui.QListWidgetItem(item, listWidget)
def run(self, text, function, path=None): """ Run the script: create the scene. It can run step-by-step and stop after every part or run every function one after another. The function also measures an execution time of commands and updates the UI elements. :param text: string - Name of the current step that will be displayed in the UI and scores table. :param function: function() - Function that will be run. :param path: string - Additional parameter: path that can be passed to the function as parameter: required by some functions. """ self.target_label.setText(text) # Update the label of UI if path is None: # If no path was passed as argument, then do not pass this variable to target function ts = time.time() # Start measuring time function() # Execute the function passed as an argument else: ts = time.time() function(path) # if path was passed then pass it to the target function te = time.time() # Record the ending time of command score = [text, te - ts] # Measure the interval self.scores_list.append(score) # append the try: self.target_list.addItem(QtGui.QListWidgetItem(str(score))) # Add measured time to scores list in UI except: print("Some problem with UI occurred") pass
def refreshObjectList(self): self.onionObjects_list.clear() for obj in self.mOnionObjectSet: listWidget = OnionListObject() listWidget.object_label.setText(obj.nodeName()) listWidget.object_remove_btn.clicked.connect(lambda b_obj = obj: self.removeOnionObject(b_obj)) listItem = QtGui.QListWidgetItem() listItem.setSizeHint(listWidget.sizeHint()) self.onionObjects_list.addItem(listItem) self.onionObjects_list.setItemWidget(listItem, listWidget) #
def refreshAbsoluteList(self): # remove any entries that don't exist anymore framesInList = [] for i in reversed(xrange(self.absolute_list.count())): frame = self.absolute_list.item(i).data(QtCore.Qt.UserRole) framesInList.append(frame) if frame not in self.mAbsoluteOnionSet: self.absolute_list.takeItem(i) # add any missing entry for frame in self.mAbsoluteOnionSet: if frame not in framesInList: listWidget = OnionListFrame() listWidget.frame_number.setText(str(int(frame))) listWidget.frame_opacity_slider.setValue(onionCore.viewRenderOverrideInstance.getAbsoluteOpacity(int(frame))) listWidget.addRemoveButton() listWidget.frame_visibility_btn.setChecked(onionCore.viewRenderOverrideInstance.absoluteOnionExists(int(frame))) listWidget.frame_remove_btn.clicked.connect(lambda b_frame = frame: self.removeAbsoluteFrame(b_frame)) listWidget.frame_visibility_btn.clicked.connect(self.toggleAbsoluteFrame) listWidget.frame_opacity_slider.sliderMoved.connect(self.setAbsoluteOpacity) listItem = QtGui.QListWidgetItem() listItem.setData(QtCore.Qt.UserRole, int(frame)) listItem.setSizeHint(listWidget.sizeHint()) # insert item at correct position correctRow = 0 for i in xrange(self.absolute_list.count()): if frame < self.absolute_list.item(i).data(QtCore.Qt.UserRole): break correctRow = i+1 self.absolute_list.insertItem(correctRow, listItem) self.absolute_list.setItemWidget(listItem, listWidget) # --------------------------- # CONNECTIONS #
def populate_widget_entities(self, assets): self.asset_listWidget.clear() for asset in assets: asset_widget = Asset_widget() asset_UUID = asset.get("UUID") if self.types_tabWidget.currentIndex() == 0: uuid_obj = utils.UUID(asset_UUID, "asset") if not uuid_obj.task() == 'TXT': asset_widget.frame_range_data.hide() asset_widget.frame_range_label.hide() else: asset_widget.frame_range_label.setText("UDIM") if self.types_tabWidget.currentIndex() == 1: uuid_obj = utils.UUID(asset_UUID, "shot") asset_widget.set_username(asset.get('publisher')) pretty_date = utils.pretty_date(asset.get('pub_date')) asset_widget.set_date(pretty_date) asset_widget.set_task(uuid_obj.task()) asset_widget.set_name(uuid_obj.name()) if asset.get('type') == "2D": UUID_thumbnail = os.path.join(os.getenv("SHOW_PATH"), os.getenv("SHOW"), "tmp", "thumbnails", "{}.jpg".format(asset_UUID)) if os.path.isfile(UUID_thumbnail): asset_widget.set_icon(UUID_thumbnail, 75, (75 / 1.775)) else: asset_widget.set_icon(os.path.join(os.getenv("CYC_ICON"), "cyc_small.png"), 75, 75) first_frame = int(asset.get('first_frame')) last_frame = int(asset.get('last_frame')) asset_widget.set_frameRange(first_frame, last_frame) if asset.get('type') == "script": asset_widget.set_icon(os.path.join(os.getenv("CYC_ICON"), "script_small.png"), 75, 75) asset_widget.frame_range_label.hide() asset_widget.frame_range_data.hide() if uuid_obj.task() == "MOD": asset_widget.set_icon(os.path.join(os.getenv("CYC_ICON"), "mod_256.png"), 75, 75) if uuid_obj.task() == "TXT": asset_widget.set_icon(os.path.join(os.getenv("CYC_ICON"), "txt_256.png"), 75, 75) if uuid_obj.task() == "SHD": asset_widget.set_icon(os.path.join(os.getenv("CYC_ICON"), "shd_256.png"), 75, 75) if uuid_obj.task() == "CRE": asset_widget.set_icon(os.path.join(os.getenv("CYC_ICON"), "cre_256.png"), 75, 75) if uuid_obj.task() == "RIG": asset_widget.set_icon(os.path.join(os.getenv("CYC_ICON"), "rig_256.png"), 75, 75) if uuid_obj.task() == "LYT": asset_widget.set_icon(os.path.join(os.getenv("CYC_ICON"), "lyt_256.png"), 75, 75) asset_widget.set_version(uuid_obj.version()) asset_widget.set_UUID(asset.get('UUID')) asset_widget.set_path(asset.get('path')) asset_widget.UUID_label.hide() asset_widget.path_label.hide() wid2 = QtWidgets.QListWidgetItem() asset_widget.setProperty("asset", True) wid2.setSizeHint(asset_widget.sizeHint()) self.asset_listWidget.addItem(wid2) self.asset_listWidget.setItemWidget(wid2, asset_widget) self.asset_listWidget.setStyleSheet("QListWidget::item {margin-bottom: 4px; background-color: rgb(45,45,45);}") wid2.setBackground(QtGui.QColor(45, 45, 45))