我正在设置一个支持白色标签的Android项目。作为此设置的一部分,我需要将品牌信息(原色等)写入文件。为了将此集成到构建过程中,我试图编写一个Gradle任务来自动执行此操作。在import pyqtgraph as pg
class MyBarGraphItem(pg.BarGraphItem):
def __init__(self):
super().__init__()
def setAttr(self, **opts):
if 'x' in opts:
self.x = opts['x']
if 'height' in opts:
self.height = opts['height']
if 'width' in opts:
self.width = opts['width']
if 'brushes' in opts:
self.brushes = opts['brushes']
super().setOpts(**opts)
class MyPlot(pg.PlotWidget):
def __init__(self):
super().__init__()
self.bars = None
def mousePressEvent(self, ev):
pos = self.getPlotItem().vb.mapSceneToView(ev.pos())
if self.bars is not None:
for i,_ in enumerate(self.bars.x):
if self.bars.x[i]-self.bars.width/2 < pos.x() < self.bars.x[i]+self.bars.width/2\
and 0 < pos.y() < self.bars.height[i]:
b = self.bars.brushes
b[i] = pg.QtGui.QColor(255,255,255)
self.bars.setAttr(brushes=b)
print('clicked on bar '+str(i))
ev.accept()
super().mousePressEvent(ev)
def addBars(self, bars):
self.bars = bars
self.addItem(bars)
if __name__ == '__main__':
app = pg.mkQApp()
plot = MyPlot()
bars = MyBarGraphItem()
bars.setAttr(brushes=[pg.hsvColor(float(x) / 5) for x in range(5)], x=[i for i in range(5)], height=[1,5,2,4,3], width=0.5)
plot.addBars(bars)
plot.show()
app.exec()
文件中,我为每种产品指定了产品口味和特定值:
app.gradle
然后我有一个Gradle任务来写入文件:
productFlavors {
flavorA {
dimension 'default'
applicationId "com.myapp.flavora"
resValue "string", "app_name", "Flavor A"
resValue "string", "primary_color", "#363636"
}
...
}
我的问题是:如何加载task copyGlobals {
println "COPY GLOBALS"
project.file('../globals.js') << 'hello world'
}
值并将其写入任务中的primary_color
文件?
答案 0 :(得分:1)
要访问产品口味,您需要迭代所有applicationVariant:
onActiveUserChange