這個爛攤子工作得很好,但如果有人有任何想法讓它看起來/表現更好,它將不勝感激!這個爛攤子怎麼樣?想更好地重寫它?
def OnButtonClick(b, e, f="none"):
if b == Gui["goleft"] and e == viz.UP: do_Cam([1.475, 7.862, 10.293])
if b == Gui["gocenter"] and e == viz.UP: do_Cam([0, 1, 52])
if b == Gui["goright"] and e == viz.UP: do_Cam([0, 11, 5])
if b == Gui["godown"] and e == viz.UP: do_Cam([0, 16, 53])
def OnSliders(POS, S):
if S == 1:
Gui["bars_alpha"].message(str('%.2f'%(POS)))
CFG["BAR_alpha"] = POS
for i in BAR_Items: BAR_Items[i].alpha(POS)
elif S == 2:
Gui["shps_alpha"].message(str('%.2f'%(POS)))
CFG["SHP_alpha"] = POS
for i in ISOS.keys(): SHAPE[i+"_SHP"].alpha(POS)
elif S == 3:
Gui["bars_sizes"].message(str('%.2f'%(POS)))
CFG["BAR_scale"] = [POS, 0.15, POS]
for i in BAR_Items: BAR_Items[i].scale(POS, BAR_Items[i].getScale()[1], POS)
elif S == 4:
Gui["label_alpha"].message(str('%.2f'%(POS)))
CFG["BARTXT_alpha"] = POS
for i in BAR_Label: BAR_Label[i].alpha(POS)
elif S == 5:
Gui["label_size"].message(str('%.2f'%(POS)))
CFG["BARTXT_scale"] = [POS, POS, POS]
for i in BAR_Label: BAR_Label[i].scale(POS, POS, POS)
elif S == 6:
Gui["grid_alpha"].message(str('%.2f'%(POS)))
CFG["grid_alpha"] = POS
[Griditema[i].alpha(POS) for i in Griditema]
[Griditemb[i].alpha(POS) for i in Griditemb]
以下一些我收到的初步建議後,我現在有:
def OnButtonClick(b, e, f="none"):
if e != viz.UP: return
if b == Gui["goleft"] : do_Cam([1.475, 7.862, 10.293])
elif b == Gui["gocenter"] : do_Cam([0, 1, 5])
elif b == Gui["goright"] : do_Cam([0, 1, 5])
elif b == Gui["godown"] : do_Cam([0, 1, 5])
def OnSliders(POS, S):
if S == 1:
CFG["BAR_alpha"] = POS
for i in BAR_Items: BAR_Items[i].alpha(POS)
elif S == 2:
CFG["SHP_alpha"] = POS
for i in ISOS.keys(): SHAPE[i+"_SHP"].alpha(POS)
elif S == 3:
CFG["BAR_scale"] = [POS, 0.15, POS]
for i in BAR_Items: BAR_Items[i].scale(POS, BAR_Items[i].getScale()[1], POS)
elif S == 4:
CFG["BARTXT_alpha"] = POS
for i in BAR_Label: BAR_Label[i].alpha(POS)
elif S == 5:
CFG["BARTXT_scale"] = [POS, POS, POS]
for i in BAR_Label: BAR_Label[i].scale(POS, POS, POS)
elif S == 6:
CFG["grid_alpha"] = POS
for i in Griditema: Griditema[i].alpha(POS)
for i in Griditemb: Griditemb[i].alpha(POS)
mydict = {1:"bars_alpha", 2:"shps_alpha", 3:"bars_sizes", 4:"label_alpha", 5:"label_size", 6:"grid_alpha"}
Gui[mydict[S]].message('%.2f' % POS)
這是怎麼結束:
def OnButtonClick(b, e, f="none"):
if e != viz.UP: return
if b == Gui["goleft"] : do_Cam([1.475, 7.862, 10.293])
elif b == Gui["gocenter"]: do_Cam([0, 1, 5])
elif b == Gui["goright"] : do_Cam([0, 1, 5])
elif b == Gui["godown"] : do_Cam([0, 1, 5])
def OnSliders(POS, S):
D = {1:"BAR_alpha", 2:"SHP_alpha", 3:"BAR_scale", 4:"TXT_alpha", 5:"TXT_scale", 6:"grid_alpha"}
if S == 1: CFG[D[S]] = POS; [BAR_Items[i].alpha(POS) for i in BAR_Items]
elif S == 2: CFG[D[S]] = POS; [SHAPE[i+"_SHP"].alpha(POS) for i in ISOS.keys()]
elif S == 3: CFG[D[S]] = [POS, 0.15, POS]; [BAR_Items[i].scale(POS, BAR_Items[i].getScale()[1], POS) for i in BAR_Items]
elif S == 4: CFG[D[S]] = POS; [BAR_Label[i].alpha(POS) for i in BAR_Label]
elif S == 5: CFG[D[S]] = [POS, POS, POS]; [BAR_Label[i].scale(POS, POS, POS) for i in BAR_Label]
elif S == 6: CFG[D[S]] = POS; [Griditema[i].alpha(POS) for i in Griditema]; [Griditemb[i].alpha(POS) for i in Griditemb]
Gui[D[S]].message('%.2f' % POS)
感謝您的幫助!
我的猜測是'Griditema'是某種類型的字典。因此,它將簡化爲'在Griditema.values()中的項目:item.alpha(POS)' – aaronasterling 2010-10-28 23:42:34
@arronasterling,好點,編輯 – mikerobi 2010-10-28 23:44:55