2010-01-26 5 views
7

में वर्तमान में प्रदर्शित किए गए सूची बॉक्स की सामग्री बदलना मैं urwid का उपयोग कर एक क्ली के साथ, अजगर में एक संगीत प्लेयर लिख रहा हूं। मैं एक सूचीसूची द्वारा लिपटे एक सरल लिस्टवाकर में वर्तमान प्लेलिस्ट रखना चाहता हूं, फिर स्तंभ, एक ढेर, और अंत में एक फ्रेम।urwid/python2.6

मैं इस सूची बॉक्स (या सरल लिस्टवॉकर) की पूरी सामग्री को किसी और चीज़ के साथ कैसे बदलूं?

प्रासंगिक कोड:

class mainDisplay(object): 
... 
    def renderList(self): 
     songList = db.getListOfSongs() 
     songDictList = [item for item in songList if item['location'] in 
     commandSh.currentPlaylists[commandSh.plyr.currentList]] 
     self.currentSongWidgets = self.createList(songDictList) 
     self.mainListContent = urwid.SimpleListWalker([urwid.AttrMap(w, None, 
     'reveal focus') for w in self.currentSongWidgets]) 
    def initFace(self):#this is the init function that creates the interface 
     #on startup 
     ... 
     self.scanPlaylists() 
     self.renderList() 
     self.mainList = urwid.ListBox(self.mainListContent) 
     self.columns = urwid.Columns([self.mainList, self.secondaryList]) 
     self.pile = urwid.Pile([self.columns, 
     ("fixed", 1, self.statusDisplayOne), 
     ("fixed", 1, self.statusDisplayTwo), 
     ("fixed", 1, self.cmdShInterface)], 3) 
     self.topFrame = urwid.Frame(self.pile) 

पर पूर्ण कोड: http://github.com/ripdog/PyPlayer/tree/cli - इंटरफ़ेस कोड के लिए main.py की जाँच करें।

कोड अभी एक बहुत खराब स्थिति में है, और मैं केवल दो महीने के लिए प्रोग्रामिंग कर रहा हूं। कोड शैली, लेआउट, या आपके पास होने वाली किसी भी अन्य युक्तियों पर कोई सुझाव बहुत सराहना की जाती है।

उत्तर

4
self.mainListContent[:] = [new, list, of, widgets] 

को विजेट की पूरी सूची को जगह में बदलना चाहिए।

अगली बार जब आप एक तेज प्रतिक्रिया चाहते हैं तो मेलिंग सूची या आईआरसी चैनल पर अपना प्रश्न पोस्ट करें!

+1

दस्तावेज़ों में यह बहुत अच्छा होगा। – SummerBreeze