Пример #1
0
    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)
Пример #2
0
  def test_callbacks_produce_commands(self):
    button_with_predefined_callback = Button(callback=(lambda: None))
    button_with_later_callback = Button()
    gui = GUI(button_with_predefined_callback, button_with_later_callback)
    stream = gui.command_stream()

    self.assertIn(button_with_predefined_callback.id, stream.get(block=False))
    self.assertTrue(stream.empty())

    button_with_later_callback.set_callback(lambda: None)
    self.assertIn(button_with_later_callback.id, stream.get(block=False))
    self.assertTrue(stream.empty())
Пример #3
0
  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)
Пример #4
0
    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)
Пример #5
0
  def test_event_dispatch(self):
    decoy1 = Button()
    button = Button()
    decoy2 = Button()

    xs = []
    button.set_callback(lambda: xs.append(1))

    gui = GUI(decoy1, button, decoy2)

    event = {'type': CLICK, 'id': button.id}
    gui.dispatch_event({'type': CLICK, 'id': button.id})
    self.assertEqual([1], xs)
Пример #6
0
    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)
Пример #7
0
    def sngPlayBtn(self, song):
        def callback():
            COM.play_song(song)
            # song.playRasps()
            # song.playVideo()

        return Button(text="Play", callback=callback)
Пример #8
0
    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)
Пример #9
0
    def songMenuBtn(self):
        def callback():
            # RBs.write_json()
            # Songs.write_json()
            self.guisonglist()

        return Button(text="Songlist", callback=callback)
Пример #10
0
    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)
Пример #11
0
    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)
Пример #12
0
    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)
Пример #13
0
    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)
Пример #14
0
    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)
Пример #15
0
    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)
Пример #16
0
    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)
Пример #17
0
    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)
Пример #18
0
    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)
Пример #19
0
    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)
Пример #20
0
  def test_set_callback(self):
    xs = []
    b = Button(callback=(lambda: xs.append(1)))
    b.handle_event({'type': CLICK, 'id': b.id})
    self.assertEqual([1], xs)

    xs = []
    b.set_callback(lambda: xs.append(2))
    b.handle_event({'type': CLICK, 'id': b.id})
    self.assertEqual([2], xs)
Пример #21
0
    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)
Пример #22
0
    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)
Пример #23
0
    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)
Пример #24
0
    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)
Пример #25
0
    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)
Пример #26
0
    def playMenuBtn(self):
        def callback():
            pass
            # self.guiEditPlaylist(pl)

        return Button(text="Play Mode", callback=callback)
Пример #27
0
    def plsngdownBtn(self, pl, song):
        def callback():
            pl.down(song)
            self.guiEditPlaylist(pl)

        return Button(text="Down", callback=callback)
Пример #28
0
    def plsngupBtn(self, pl, song):
        def callback():
            pl.up(song)
            self.guiEditPlaylist(pl)

        return Button(text="Up", callback=callback)
Пример #29
0
    def plsngdeleteBtn(self, pl, song):
        def callback():
            pl.remove_song(song)
            self.guiEditPlaylist(pl)

        return Button(text="Delete", callback=callback)
Пример #30
0
    def plDeleteBtn(self, pl):
        def callback():
            pl.remove()
            self.guiPlaylists()

        return Button(text="Delete", callback=callback)
Пример #31
0
    def plEditBtn(self, pl):
        def callback():
            self.guiEditPlaylist(pl)

        return Button(text="Edit", callback=callback)
Пример #32
0
    def PLMenuBtn(self):
        def callback():
            self.guiPlaylists()

        return Button(text="Playlist Manager", callback=callback)
Пример #33
0
    def raspsrebootBtn(self, rasp):
        def callback():
            COM.reboot_rasp(rasp)

        return Button(text="Reboot", callback=callback)
Пример #34
0
    def raspshutdownBtn(self, rasp):
        def callback():
            COM.shutdown_rasp(rasp)

        return Button(text="Shutdown", callback=callback)