def themesPanel(self, themes=None): themes = None if not themes: themes=['0','1', 'cms', 'pypress'] vPanel = VerticalPanel() vPanel.setID('themes') for i in range(len(themes)): a=Button('theme %s' % themes[i], Index.toTheme, StyleName='link') a.setID(themes[i]) vPanel.add(a) return vPanel
class Application: def __init__(self): #set some vars self.title = "last.fm" #this is where we build the ui self.statusPanel = VerticalPanel() self.statusPanel.setID('status_panel') #make a few Labels to hold station, artist, track, album info self.stationLabel = Label() self.artistLabel = Label() self.trackLabel = Label() self.albumLabel = Label() self.timeLabel = Label() self.infoTable = FlexTable() i=0 self.stationLabel = Label() self.infoTable.setWidget(i,0,Label("Station:") ) self.infoTable.setWidget(i,1,self.stationLabel) i+=1 self.infoTable.setWidget(i,0,Label("Artist:") ) self.infoTable.setWidget(i,1,self.artistLabel) i+=1 self.infoTable.setWidget(i,0,Label("Track:") ) self.infoTable.setWidget(i,1,self.trackLabel) i+=1 self.infoTable.setWidget(i,0,Label("Album:") ) self.infoTable.setWidget(i,1,self.albumLabel) self.statusPanel.add(self.infoTable) self.statusPanel.add(self.timeLabel) #make the time bar timebarWrapperPanel = SimplePanel() timebarWrapperPanel.setID("timebar_wrapper") #timebarWrapperPanel.setStyleName('timebar_wrapper') self.timebarPanel = SimplePanel() self.timebarPanel.setID("timebar") #self.timebarPanel.setStyleName('timebar') timebarWrapperPanel.add(self.timebarPanel) self.statusPanel.add(timebarWrapperPanel) #make some shit for buttons self.buttonHPanel = HorizontalPanel() self.skipButton = Button("Skip", self.clicked_skip ) self.buttonHPanel.add(self.skipButton) loveButton = Button("Love", self.clicked_love ) self.buttonHPanel.add(loveButton) pauseButton = Button("Pause", self.clicked_pause ) self.buttonHPanel.add(pauseButton) banButton = Button("Ban", self.clicked_ban ) self.buttonHPanel.add(banButton) #control the volume self.volumePanel = HorizontalPanel() self.volumeLabel = Label("Volume:") self.volumePanel.add(self.volumeLabel) volupButton = Button("+", self.clicked_volume_up, 5) self.volumePanel.add(volupButton) voldownButton = Button("-", self.clicked_volume_down, 5) self.volumePanel.add(voldownButton) #make buttons and shit to create a new station self.setStationHPanel = HorizontalPanel() self.setStationTypeListBox = ListBox() self.setStationTypeListBox.setVisibleItemCount(0) self.setStationTypeListBox.addItem("Similar Artists", "artist/%s/similarartists") self.setStationTypeListBox.addItem("Top Fans", "artist/%s/fans") self.setStationTypeListBox.addItem("Library", "user/%s/library") self.setStationTypeListBox.addItem("Mix", "user/%s/mix") self.setStationTypeListBox.addItem("Recommended", "user/%s/recommended") self.setStationTypeListBox.addItem("Neighbours", "user/%s/neighbours") self.setStationTypeListBox.addItem("Global Tag", "globaltags/%s") self.setStationHPanel.add(self.setStationTypeListBox) self.setStationTextBox = TextBox() self.setStationTextBox.setVisibleLength(10) self.setStationTextBox.setMaxLength(50) self.setStationHPanel.add(self.setStationTextBox) self.setStationButton = Button("Play", self.clicked_set_station) self.setStationHPanel.add(self.setStationButton) #make an error place to display data self.infoHTML = HTML() RootPanel().add(self.statusPanel) RootPanel().add(self.buttonHPanel) RootPanel().add(self.volumePanel) RootPanel().add(self.setStationHPanel) RootPanel().add(self.infoHTML) def run(self): self.get_track_info() def get_track_info(self): HTTPRequest().asyncGet("/track_info", TrackInfoHandler(self)) Timer(5000,self.get_track_info) def clicked_skip(self): self.skipButton.setEnabled(False) HTTPRequest().asyncGet("/skip",ButtonInfoHandler(self,self.skipButton) ) def clicked_volume_down(self): HTTPRequest().asyncGet("/volume/down",NullInfoHandler(self) ) def clicked_volume_up(self): HTTPRequest().asyncGet("/volume/up",NullInfoHandler(self) ) def clicked_love(self): HTTPRequest().asyncGet("/love",NullInfoHandler(self) ) def clicked_ban(self): result = Window.confirm("Really ban this song?") if result: HTTPRequest().asyncGet("/ban",NullInfoHandler(self) ) def clicked_pause(self): HTTPRequest().asyncGet("/pause",NullInfoHandler(self) ) def clicked_set_station(self): type = self.setStationTypeListBox.getSelectedValues()[0] text = self.setStationTextBox.getText().strip() if len(text) > 0 : #clear the text self.setStationTextBox.setText("") station = type % text HTTPRequest().asyncGet("/station/%s" % station,NullInfoHandler(self) ) def set_error(self, content): self.infoHTML.setHTML("<pre>%s</pre>" % content) def onTimeout(self,text): self.infoHTML.setHTML("timeout: "+text) def onError(self, text, code): self.infoHTML.setHTML(text + "<br />" + str(code)) def process_track_info(self,text): #explode the text at :: #%a::%t::%l::%d::%R::%s::%v::%r data = text.split("::") artist = data[0] track = data[1] album = data[2] duration = data[3] played = int(duration)-int(data[4]) percent = int( played/int(duration)*100 ) self.artistLabel.setText( artist ) self.trackLabel.setText( track ) self.albumLabel.setText( album ) #format time t = "%s : %d %d" % (duration,played,percent) self.timeLabel.setText(data[7]) #update the timebarwidth self.timebarPanel.setWidth("%d%" % (percent) ) #set the station self.stationLabel.setText(data[5]) #display the volume self.volumeLabel.setText("Volume: "+data[6]) Window.setTitle(self.title+": "+artist+" - "+track)