def test_event_dispatch(self): decoy1 = Button() button = Button() decoy2 = Button() xs = [] button.callback = (lambda: xs.append(1)) gui = GUI(decoy1, button, decoy2) gui.dispatch_event(Click(target_id=button.id)) self.assertEqual([1], xs)
def songMenuBtn(self): def callback(): # RBs.write_json() # Songs.write_json() self.guisonglist() return Button(text="Songlist", callback=callback)
def guiRasplist(self): # if len(self.body) > 1: # self.body.remove(self.songgrid) self.GuiMain_BtnGrid() self.raspgrid = Grid(n_rows=len(RBs.Rasplist), n_columns=7) rasplist = RBs.Rasplist[:] for num, rasp in enumerate(rasplist): # print(f"song {song} song.name {song.name} num {num}") n = Text(str(num)) t = Text(rasp.name) ip = Text(rasp.IP) redit = self.raspEditBtn(rasp) rdelete = self.raspDeleteBtn(rasp) rshutdown = self.raspshutdownBtn(rasp) rreboot = self.raspsrebootBtn(rasp) self.raspgrid[num, 0] = n self.raspgrid[num, 1] = t self.raspgrid[num, 2] = ip self.raspgrid[num, 3] = redit self.raspgrid[num, 4] = rdelete self.raspgrid[num, 5] = rshutdown self.raspgrid[num, 6] = rreboot self.newRaspBtn = Button(text="New Rasp", callback=self.newrasp) # self.songmenubtn = self.songMenuBtn() self.body.append(self.raspgrid) self.body.append(self.newRaspBtn)
def songeditsaveBtn(self, song): def callback(): # when the name changes name of song in rasp.songliste will be changed Rasplist = RBs.Rasplist.copy() for rasp in Rasplist: songs = rasp.songs.copy() print(f"rasp.songs {songs} for rasp {rasp.name}") for sng in songs: print( f"song found in rrasps songs: {sng} song.name {song.name}" ) if sng == song.name: # remove song from list rasp.addSong(self.ns1.value, rasp.songs[song.name]) # rasp.songs.pop(song.name) # add new instance with new name song.name = self.ns1.value song.description = self.ns3.value RBs.write_json() Songs.write_json() # self.cleanUI() self.guisonglist() return Button(text="Save", callback=callback)
def sngPlayBtn(self, song): def callback(): COM.play_song(song) # song.playRasps() # song.playVideo() return Button(text="Play", callback=callback)
def __init__(self, name="My ToggleableButton", pressed=False, callback=lambda: None): self.name = name self.button = Button(name) self.pressed = pressed PRESSED = {'background-color': 'lightgray', 'border-style': 'inset'} UNPRESSED = {'background-color': 'white', 'border-style': 'outset'} def style_me(self): # UGH, DANGEROUS? HOW TO BETTER? if self.pressed: self.button.css.update(PRESSED) else: self.button.css.update(UNPRESSED) def onClick(): print('Button ' + self.button.text + ' clicked!') self.pressed = not (self.pressed) style_me(self) callback() self.button.callback = onClick style_me(self)
def newsongBtn(self, nametf): def callback(): sng = Song(name=nametf.value, parent=Songs, pis={}) # RBs.write_json() Songs.write_json() self.guisonglist() return Button(text="New Song", callback=callback)
def plsngupdateBtn(self, pl, sng, pausetime): def callback(): ptime = pausetime.value pl.used_songs[sng.name] = ptime PLs.write_json() self.guiEditPlaylist(pl) return Button(text="Update", callback=callback)
def newplBtn(self): def callback(): # PLs.add() pl = Playlist(name=self.nfNewpl.value, parent=PLs) PLs.write_json() self.guiPlaylists() return Button(text="New Playlist", callback=callback)
def test_def_callback(self): xs = [] b = Button() @b.def_callback def _(): xs.append(1) b.handle_event(Click(target_id=b.id)) self.assertEqual([1], xs)
def sng_raspDeleteBtn(self, song, rasp): def callback(): song.removeRasp(rasp) for ras in RBs.Rasplist: if ras.name == rasp: ras.removeSong(song.name) self.EditSong(song) return Button(text="Delete", callback=callback)
def rsngdeleteBtn(self, songs, song, rasp): def callback(): rasp.removeSong(song) Songlist = Songs.Songlist[:] for so in Songlist: if song == so.name: so.removeRasp(rasp.name) break self.editRaspMenu(rasp) return Button(text="Delete", callback=callback)
def raspDeleteBtn(self, rasp): def callback(): print(f"Deleted {rasp.name}") rasp.removeRasp() for song in Songs.Songlist: for pi in song.used_pis: if pi == rasp.name: song.removeRasp(pi) return Button(text="Delete", callback=callback)
def plsngnewBtn(self, pl, songdd, pausefield, songlength, video): def callback(): pause = pausefield.value songleng = float(songlength.value) vid = video.value pl.add_song(Songs.get_song(songdd.value), pause, songleng, vid) self.guiEditPlaylist(pl) return Button(text="New Song", callback=callback)
def sng_raspUpdateBtn(self, rasps, rasp, song, dropdown): def callback(): rasps[rasp] = dropdown.value for ras in RBs.Rasplist: print(f"ras.name {ras.name} == rasp as string {rasp}") if ras.name == rasp: ras.songs[song.name] = dropdown.value self.EditSong(song) return Button(text="Update", callback=callback)
def sngDeleteBtn(self, song): def callback(): song.remove() Rasplist = RBs.Rasplist[:] for pi in Rasplist: songs = pi.songs.copy() for sng in songs: if song.name == sng: pi.songs.pop(sng) self.guisonglist() return Button(text="Delete", callback=callback)
def rsnguploadBtn(self, rasp, filedd, scriptdd): def callback(): # print(f"enum des knopfes ist {enum}") filename = filedd.value scriptname = scriptdd.value # tell file manager to upload COM.upload_light(rasp, filename) COM.upload_script(rasp, scriptname) # self.editRaspMenu(rasp) return Button(text="Upload", callback=callback)
def test_callback_is_settable(self): xs = [] b = Button(callback=(lambda: xs.append(1))) b.handle_event(Click(target_id=b.id)) self.assertEqual([1], xs) xs = [] b.callback = (lambda: xs.append(2)) b.handle_event(Click(target_id=b.id)) self.assertEqual([2], xs) xs = [] b.callback = None b.handle_event(Click(target_id=b.id)) self.assertEqual([], xs)
def rsngupdateBtn(self, songs, song, rasp, dropdown, scriptdropdown): def callback(): # print(f"enum des knopfes ist {enum}") filename = dropdown.value scriptname = scriptdropdown.value files = songs[song] files[0] = filename # self.sngFiletextfield.value files[1] = scriptname # change song in mainsonglist for so in Songs.Songlist: if song == so.name: # self.sngFiletextfield.value so.addRasp(rasp.name, filename) break self.editRaspMenu(rasp) return Button(text="Update", callback=callback)
def appendRasptoSongBtn(self, song, raspsdrop, filedropdown): def callback(): song.addRasp(raspsdrop.value, filedropdown.value) for rasp in RBs.Rasplist: print(f"rasps vorhanden {rasp.name}") if raspsdrop.value == rasp.name: # print( # f"rasps richtig {rasp.name} drop value {self.raspsdrop.value}") rasp.addSong(song.name, filedropdown.value) # tester for rasp in RBs.Rasplist: for sng in rasp.songs: print(f"in rasp {rasp.name} song {sng}") # break self.EditSong(song) return Button(text="Add", callback=callback)
def appendsongtoraspbtn(self, rasp): def callback(): songstr = self.rsongdrop.value filename = self.newsongfile.value scriptname = self.newsongscript.value if songstr == " " or filename == " " or scriptname == " ": self.editRaspMenu(rasp) return "Canceled" rasp.addSong(songstr, filename, scriptname) self.saveEditdata(rasp) for song in Songs.Songlist: if song.name == self.rsongdrop.value: song.addRasp(rasp.name, filename) break self.editRaspMenu(rasp) return Button(text="Add", callback=callback)
def playMenuBtn(self): def callback(): pass # self.guiEditPlaylist(pl) return Button(text="Play Mode", callback=callback)
def plsngdownBtn(self, pl, song): def callback(): pl.down(song) self.guiEditPlaylist(pl) return Button(text="Down", callback=callback)
def plsngupBtn(self, pl, song): def callback(): pl.up(song) self.guiEditPlaylist(pl) return Button(text="Up", callback=callback)
def raspshutdownBtn(self, rasp): def callback(): COM.shutdown_rasp(rasp) return Button(text="Shutdown", callback=callback)
def plsngdeleteBtn(self, pl, song): def callback(): pl.remove_song(song) self.guiEditPlaylist(pl) return Button(text="Delete", callback=callback)
def plDeleteBtn(self, pl): def callback(): pl.remove() self.guiPlaylists() return Button(text="Delete", callback=callback)
def raspsrebootBtn(self, rasp): def callback(): COM.reboot_rasp(rasp) return Button(text="Reboot", callback=callback)
def plEditBtn(self, pl): def callback(): self.guiEditPlaylist(pl) return Button(text="Edit", callback=callback)
def PLMenuBtn(self): def callback(): self.guiPlaylists() return Button(text="Playlist Manager", callback=callback)