Skip to content

Commit c1e69b6

Browse files
committed
New channels navigation
1 parent d5580e7 commit c1e69b6

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

usr/lib/hypnotix/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,14 @@ def __init__(self, provider, info):
9898
self.group_title = None
9999
self.title = None
100100
self.url = None
101+
self.lcn = None
101102
match = EXTINF.fullmatch(info)
102103
if match is not None:
103104
res = match.groupdict()
104105
if 'params' in res:
105106
params = dict(PARAMS.findall(res['params']))
107+
if "tvg-lcn" in params and params['tvg-lcn'].strip() != "":
108+
self.lcn = params['tvg-lcn'].strip()
106109
if "tvg-name" in params and params['tvg-name'].strip() != "":
107110
self.name = params['tvg-name'].strip()
108111
if "tvg-logo" in params and params['tvg-logo'].strip() != "":

usr/lib/hypnotix/hypnotix.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,9 @@ def show_channels(self, channels, favorites=False):
561561
self.download_channel_logos(logos_to_refresh)
562562
else:
563563
self.sidebar.hide()
564+
565+
self.update_hchannels()
566+
self.chan_num_buf = 0
564567

565568
def show_vod(self, items):
566569
logos_to_refresh = []
@@ -732,6 +735,9 @@ def on_search_bar(self, widget):
732735
self.latest_search_bar_text = search_bar_text
733736
self.search_bar.set_sensitive(False)
734737
GLib.timeout_add_seconds(0.1, self.on_search)
738+
739+
def update_hchannels(self):
740+
self.hchannels = [c for c in self.channels_listbox.get_children() if unidecode(self.search_bar.get_text()).lower() in c.channel.name.lower()]
735741

736742
def on_search(self):
737743
self.visible_search_results = 0
@@ -747,6 +753,7 @@ def on_search(self):
747753
self.search_bar.set_sensitive(True)
748754
self.search_bar.grab_focus_without_selecting()
749755
self.navigate_to("channels_page")
756+
self.update_hchannels()
750757

751758
def init_channels_listbox(self):
752759
self.latest_search_bar_text = None
@@ -883,13 +890,23 @@ def on_channel_activated(self, box, widget):
883890

884891
def on_prev_channel(self):
885892
if self.stack.get_visible_child_name() == "channels_page":
886-
self.channels_listbox.do_move_cursor(self.channels_listbox, Gtk.MovementStep.DISPLAY_LINES, -1)
887-
self.channels_listbox.do_activate_cursor_row(self.channels_listbox)
893+
idx = self.channels_listbox_selected_index()
894+
step = -1 if idx != 0 else (len(self.hchannels) - 1)
895+
self.channels_listbox_activate_row(step)
888896

889897
def on_next_channel(self):
890898
if self.stack.get_visible_child_name() == "channels_page":
891-
self.channels_listbox.do_move_cursor(self.channels_listbox, Gtk.MovementStep.DISPLAY_LINES, 1)
892-
self.channels_listbox.do_activate_cursor_row(self.channels_listbox)
899+
idx = self.channels_listbox_selected_index()
900+
step = 1 if idx != (len(self.hchannels) - 1) else (1 - len(self.hchannels))
901+
self.channels_listbox_activate_row(step)
902+
903+
def channels_listbox_selected_index(self):
904+
channel = [c for c in self.hchannels if c.channel.name == self.active_channel.name][0]
905+
return self.hchannels.index(channel)
906+
907+
def channels_listbox_activate_row(self, step):
908+
self.channels_listbox.do_move_cursor(self.channels_listbox, Gtk.MovementStep.DISPLAY_LINES, step)
909+
self.channels_listbox.do_activate_cursor_row(self.channels_listbox)
893910

894911
@async_function
895912
def play_async(self, channel):
@@ -1516,6 +1533,7 @@ def on_menu_quit(self, widget):
15161533
self.application.quit()
15171534

15181535
def on_key_press_event(self, widget, event):
1536+
channel_focused = self.fullscreen or "ChannelWidget" in widget.get_focus().get_name()
15191537
# Get any active, but not pressed modifiers, like CapsLock and NumLock
15201538
persistant_modifiers = Gtk.accelerator_get_default_mod_mask()
15211539

@@ -1548,6 +1566,24 @@ def on_key_press_event(self, widget, event):
15481566
self.on_prev_channel()
15491567
elif event.keyval == Gdk.KEY_Right:
15501568
self.on_next_channel()
1569+
return True
1570+
elif event.keyval == Gdk.KEY_Return:
1571+
if channel_focused:
1572+
try:
1573+
chan = [c for c in self.hchannels if c.channel.lcn == str(self.chan_num_buf)][0]
1574+
idx = self.channels_listbox_selected_index()
1575+
step = self.hchannels.index(chan) - idx
1576+
self.channels_listbox_activate_row(step)
1577+
finally:
1578+
self.chan_num_buf = 0
1579+
return True
1580+
else:
1581+
self.chan_num_buf = 0
1582+
else:
1583+
try:
1584+
self.chan_num_buf = self.chan_num_buf * 10 + int(chr(event.keyval))
1585+
except:
1586+
self.chan_num_buf = 0
15511587
# elif event.keyval == Gdk.KEY_Up:
15521588
# # Up of in the list
15531589
# pass

0 commit comments

Comments
 (0)