本文整理汇总了Python中filter.Filter.apply方法的典型用法代码示例。如果您正苦于以下问题:Python Filter.apply方法的具体用法?Python Filter.apply怎么用?Python Filter.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类filter.Filter
的用法示例。
在下文中一共展示了Filter.apply方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filter
# 需要导入模块: from filter import Filter [as 别名]
# 或者: from filter.Filter import apply [as 别名]
def filter(self, q):
"""
q is the query.
"""
if not isinstance(q, str):
s = "filter: invalid query argument. You must use a string."
self.logger.error(s)
raise TypeError(s)
f = Filter(self.sites, q)
f.apply()
示例2: getmeansfromboard
# 需要导入模块: from filter import Filter [as 别名]
# 或者: from filter.Filter import apply [as 别名]
def getmeansfromboard(self, board):
# Split the board into pieces
mean = [[0 for _ in range(self.boardsize)] for _ in range(self.boardsize)]
#mean = [[0] * self.boardsize] * self.boardsize
print mean
means = []
for i in range(self.boardsize):
row = board[(i*50):((i+1)*50)]
for j in range(self.boardsize):
tile = row[0:50, (j*50):((j+1)*50)]
means.append(cv2.mean(tile)[0])
filter = Filter(self.boardsize)
filter.apply(means)
return means
示例3: test_filter_apply
# 需要导入模块: from filter import Filter [as 别名]
# 或者: from filter.Filter import apply [as 别名]
def test_filter_apply(self):
input = QEInput(config=fixtures.textMain)
# Filter that adds parameters to input
fp = Filter("fPlus")
fp.setParam("control", "prefix", "'ni'")
fp.setParam("control", "pseudo_dir", "''")
fp.setParam("control", "outdir", "''")
fp.setCard({"name": "occupations", "lines": ("New line",)}) # Add new card
fp.setNamelist({"name": "cell", "params": {"hello": "world"}}) # Add new namelist
fp.setNamelist({"name": "phonon"})
fp.apply(input, "plus")
self.assertEqual(input.toString(), fixtures.assertPlus)
# Filter that removes parameters from input
fm = Filter("fMinus")
fm.setCard({"name": "atomic_species"})
fm.setNamelist({"name": "phonon"}) # Remove namelist
fm.setParam("cell", "hello") # Remove parameter that makes namelist empty
fm.setParam("control", "prefix") # Remove parameter
fm.apply(input, "minus")
self.assertEqual(input.toString(), fixtures.assertMinus)
示例4: Carousel
# 需要导入模块: from filter import Filter [as 别名]
# 或者: from filter.Filter import apply [as 别名]
class Carousel(object):
def __init__(self, aggregatedData):
self.__aData = aggregatedData
self.__currentType = CUSTOMIZATION_TYPE.CAMOUFLAGE
self.__currentSlotIdx = 0
self.__currentDuration = 0
self.__carouselItems = []
self.filter = Filter(self.__aData.availableGroupNames)
self.filter.changed += self.__updateCarouselData
self.slots = Slots(self.__aData)
self.slots.selected += self.__onSlotSelected
self.slots.updated += self.__onSlotUpdated
self.updated = Event()
def fini(self):
self.slots.selected -= self.__onSlotSelected
self.slots.updated -= self.__onSlotUpdated
self.filter.changed -= self.__updateCarouselData
self.__carouselItems = None
self.__aData = None
self.slots.fini()
self.filter.fini()
return
@property
def items(self):
return self.__carouselItems
@property
def currentType(self):
return self.__currentType
@property
def currentSlotIdx(self):
return self.__currentSlotIdx
def applyItem(self, carouselItemIdx):
self.slots.updateSlot(self.__carouselItems[carouselItemIdx], duration=self.__currentDuration)
def previewItem(self, carouselItemIdx):
previewItemID = self.__carouselItems[carouselItemIdx]['id']
if self.__currentType == CUSTOMIZATION_TYPE.CAMOUFLAGE:
g_hangarSpace.space.updateVehicleCamouflage(camouflageID=previewItemID)
else:
self.__updateItemOnTank3DModel(previewItemID)
def changeDuration(self, duration):
self.__currentDuration = duration
self.__updateCarouselData()
def __updateItemOnTank3DModel(self, previewItemID):
cType = self.__currentType
slotIdx = self.__currentSlotIdx
slotItem = self.slots.getData()['data'][cType]['data'][slotIdx]
changedPreviewModel = copy.deepcopy(self.__aData.viewModel[1:3])
rawInstalledItem = [previewItemID, time.time(), 0]
if cType == CUSTOMIZATION_TYPE.INSCRIPTION:
rawInstalledItem.append(0)
changedPreviewModel[cType - 1][slotItem['spot'] + self.slots.calculateVehicleIndex(slotIdx, cType)] = rawInstalledItem
g_hangarSpace.space.updateVehicleSticker(changedPreviewModel)
def __onSlotSelected(self, newType, newSlotIdx):
self.__currentType = newType
self.__currentSlotIdx = newSlotIdx
self.filter.setTypeAndIdx(newType, newSlotIdx)
if newType == CUSTOMIZATION_TYPE.CAMOUFLAGE:
self.filter.set(FILTER_TYPE.GROUP, CAMOUFLAGE_GROUP_MAPPING[newSlotIdx])
self.filter.apply()
def __getBtnTooltip(self, installedInSlot):
if installedInSlot:
params = (TOOLTIPS.CUSTOMIZATION_CAROUSEL_SLOT_REMOVE_HEADER, TOOLTIPS.CUSTOMIZATION_CAROUSEL_SLOT_REMOVE_BODY)
else:
params = (TOOLTIPS.CUSTOMIZATION_CAROUSEL_SLOT_SELECT_HEADER, TOOLTIPS.CUSTOMIZATION_CAROUSEL_SLOT_SELECT_BODY)
return makeTooltip(*params)
def __onSlotUpdated(self, newSlotData):
self.__updateCarouselData()
def __updateCarouselData(self):
oldItemsCount = len(self.__carouselItems)
del self.__carouselItems[:]
appliedItems = []
purchasedItems = []
otherItems = []
currentSlotItem = None
installedItemID = self.slots.getInstalledItem(self.__currentSlotIdx, self.__currentType).getID()
if self.__currentType == CUSTOMIZATION_TYPE.CAMOUFLAGE:
displayedItems = {}
for itemID, item in self.__aData.displayed[self.__currentType].iteritems():
if item.getGroup() == CAMOUFLAGE_GROUP_MAPPING[self.__currentSlotIdx]:
displayedItems[itemID] = item
else:
displayedItems = self.__aData.displayed[self.__currentType]
for itemID, item in displayedItems.iteritems():
if not self.filter.check(item):
continue
appliedToCurrentSlot = itemID == self.slots.getSelectedSlotItemID()
#.........这里部分代码省略.........
示例5: Carousel
# 需要导入模块: from filter import Filter [as 别名]
# 或者: from filter.Filter import apply [as 别名]
class Carousel(object):
def __init__(self, aggregatedData):
self.__aData = aggregatedData
self.__currentType = CUSTOMIZATION_TYPE.CAMOUFLAGE
self.__currentSlotIdx = 0
self.__currentDuration = 0
self.__carouselItems = []
self.filter = Filter(self.__aData.availableGroupNames)
self.filter.changed += self.__updateCarouselData
self.slots = Slots(self.__aData)
self.slots.selected += self.__onSlotSelected
self.slots.updated += self.__onSlotUpdated
self.updated = Event()
def fini(self):
self.slots.selected -= self.__onSlotSelected
self.slots.updated -= self.__onSlotUpdated
self.filter.changed -= self.__updateCarouselData
self.__carouselItems = None
self.__aData = None
self.slots.fini()
self.filter.fini()
return
@property
def items(self):
return self.__carouselItems
@property
def currentType(self):
return self.__currentType
@property
def currentSlotIdx(self):
return self.__currentSlotIdx
def applyItem(self, carouselItemIdx):
carouselItem = self.__carouselItems[carouselItemIdx]
self.slots.applyItem(carouselItem, duration=self.__currentDuration)
def changeDuration(self, duration):
self.__currentDuration = duration
self.__updateCarouselData()
def __onSlotSelected(self, newType, newSlotIdx):
self.__currentType = newType
self.__currentSlotIdx = newSlotIdx
self.filter.setTypeAndIdx(newType, newSlotIdx)
if newType == CUSTOMIZATION_TYPE.CAMOUFLAGE:
self.filter.set(FILTER_TYPE.GROUP, CAMOUFLAGE_GROUP_MAPPING[newSlotIdx])
self.filter.apply()
def __onSlotUpdated(self, newSlotData):
if self.__currentType == newSlotData['type'] and self.__currentSlotIdx == newSlotData['idx']:
self.filter.setTypeAndIdx(newSlotData['type'], newSlotData['idx'])
self.__updateCarouselData()
def __updateCarouselData(self):
oldItemsCount = len(self.__carouselItems)
del self.__carouselItems[:]
appliedItems = defaultdict(list)
purchasedItems = defaultdict(list)
otherItems = defaultdict(list)
allItems = [appliedItems, purchasedItems, otherItems]
currentSlotItem = None
installedItemID = self.slots.getInstalledItem(self.__currentSlotIdx, self.__currentType).getID()
if self.__currentType == CUSTOMIZATION_TYPE.CAMOUFLAGE:
displayedItems = {}
for itemID, item in self.__aData.displayed[self.__currentType].iteritems():
if item.getGroup() == CAMOUFLAGE_GROUP_MAPPING[self.__currentSlotIdx]:
displayedItems[itemID] = item
else:
displayedItems = self.__aData.displayed[self.__currentType]
filterExceptions = {FILTER_TYPE.SHOW_IN_DOSSIER: self.__aData.installed[self.__currentType]}
for itemID, item in displayedItems.iteritems():
if self.filter.check(item, filterExceptions):
appliedToCurrentSlot = itemID == self.slots.getSelectedSlotItemID()
installedInSlot = itemID == installedItemID
isInQuests = item.isInQuests and not item.isInDossier and self.filter.purchaseType == PURCHASE_TYPE.QUEST
carouselItem = {'id': itemID,
'object': item,
'appliedToCurrentSlot': appliedToCurrentSlot,
'price': item.getPrice(self.__currentDuration),
'priceIsGold': item.priceIsGold(self.__currentDuration),
'isInDossier': item.isInDossier,
'isInQuests': isInQuests,
'duration': self.__currentDuration,
'installedInSlot': installedInSlot}
if appliedToCurrentSlot:
currentSlotItem = carouselItem
if installedInSlot:
group = appliedItems[item.getGroup()]
elif item.isInDossier:
group = purchasedItems[item.getGroup()]
else:
group = otherItems[item.getGroup()]
if item.isFeatured:
group.insert(0, carouselItem)
#.........这里部分代码省略.........