Add function to add a top-level directory
This commit is contained in:
parent
12a4f1c671
commit
1d9321501a
@ -128,7 +128,8 @@ class display_selection(display):
|
||||
#self.img.paste(self.img_pre, (0,0))
|
||||
self.img = self.img_pre
|
||||
|
||||
def set_entries(self, entries):
|
||||
def set_entries(self, entries, left_only = False):
|
||||
self.left_only = left_only
|
||||
self.entries = entries
|
||||
self.set_page(0)
|
||||
|
||||
@ -138,13 +139,14 @@ class display_selection(display):
|
||||
x = 0
|
||||
y = 0
|
||||
self.img_pre = Image.new('1', (self.width, self.height), color = not self.fg)
|
||||
for entry in self.entries[page*6:]:
|
||||
mult = 3 if self.left_only else 6
|
||||
for entry in self.entries[page*mult:]:
|
||||
ImageDraw.Draw(self.img_pre).text((x,y-font_shift), entry, font=self.font_info, fill=self.fg)
|
||||
y += self.height / 3
|
||||
if (y >= self.height):
|
||||
y = 0
|
||||
x += self.width / 2
|
||||
if (x >= self.width):
|
||||
if (x >= self.width) or (self.left_only):
|
||||
break
|
||||
|
||||
def set_page_relative(self, delta):
|
||||
@ -160,7 +162,8 @@ class display_selection(display):
|
||||
if (page == -1):
|
||||
page = self.page
|
||||
try:
|
||||
return self.entries[page * 6 + offset]
|
||||
mult = 3 if self.left_only else 6
|
||||
return self.entries[page * mult + offset]
|
||||
except:
|
||||
return ""
|
||||
|
||||
@ -224,8 +227,20 @@ class radioserv:
|
||||
entries = []
|
||||
for entry in playlists:
|
||||
entries.append(entry['playlist'])
|
||||
self.disp_select.mode = "playlist"
|
||||
self.disp_select.set_entries(entries)
|
||||
#self.disp_select.set_entries(["Test", "Foo", "Bar", "Meow", "Zzzzzz", "Yehaw!", "Trees", "Bees", "Flowers"])
|
||||
self.disp_mgr.set_display(self.disp_select, LIVE_SELECT)
|
||||
|
||||
def open_directory_screen(self):
|
||||
dirs = self.mpd.listfiles("")
|
||||
entries = []
|
||||
for entry in dirs:
|
||||
try:
|
||||
entries.append(entry['directory'])
|
||||
except:
|
||||
pass
|
||||
self.disp_select.mode = "directory"
|
||||
self.disp_select.set_entries(entries, True)
|
||||
self.disp_mgr.set_display(self.disp_select, LIVE_SELECT)
|
||||
|
||||
def handle_rx(self, rdata):
|
||||
@ -241,11 +256,15 @@ class radioserv:
|
||||
# Handle key presses
|
||||
key_id = rdata[0] & 0x0F
|
||||
key_press_short = ((rdata[0] & 0xC0) == 128)
|
||||
key_press_long = ((rdata[0] & 0xC0) == 192)
|
||||
if key_press_short:
|
||||
print("Press key: {}".format(key_id))
|
||||
elif key_press_long:
|
||||
print("Long press key: {}".format(key_id))
|
||||
# Handle rotary input
|
||||
rotary_delta = int(rdata[1] & 0x1F) - 16
|
||||
if (self.disp_mgr.current_display == self.disp_playback):
|
||||
if (key_press_short):
|
||||
print("Press key: {}".format(key_id))
|
||||
if (key_id == 0): # Tune-
|
||||
print(self.status) # TODO: Only for testing purposes. This key is still free!
|
||||
print(self.currentsong)
|
||||
@ -264,6 +283,9 @@ class radioserv:
|
||||
self.mpd.next()
|
||||
elif (key_id == 7): # PRESET
|
||||
self.mpd.random(int(not int(self.status['random'])))
|
||||
if (key_press_long):
|
||||
if (key_id == 5): # Source
|
||||
self.open_directory_screen()
|
||||
self.handle_volume(rotary_delta, bat)
|
||||
|
||||
elif (self.disp_mgr.current_display == self.disp_info):
|
||||
@ -295,9 +317,12 @@ class radioserv:
|
||||
elif (sel == 100):
|
||||
self.disp_mgr.kill_display()
|
||||
else:
|
||||
print("Load playlist {}.".format(self.disp_select.get_entry(sel)))
|
||||
print("Load {} {}.".format(self.disp_select.mode, self.disp_select.get_entry(sel)))
|
||||
self.mpd.clear()
|
||||
if (self.disp_select.mode == "playlist"):
|
||||
self.mpd.load(self.disp_select.get_entry(sel))
|
||||
else:
|
||||
self.mpd.add(self.disp_select.get_entry(sel))
|
||||
self.mpd.play(0)
|
||||
self.disp_mgr.kill_display()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user