Skip to content

Add vertical round robining for dialogs where it fits #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion lib/windows/dropdown.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import kodigui

import xbmcgui
from lib import util

SEPARATOR = None
Expand All @@ -20,6 +20,8 @@ def __init__(self, *args, **kwargs):
kodigui.BaseDialog.__init__(self, *args, **kwargs)
self.options = kwargs.get('options')
self.pos = kwargs.get('pos')
self.lastSelectedItem = 0
self.roundRobin = kwargs.get('round_robin', True)
self.posIsBottom = kwargs.get('pos_is_bottom')
self.closeDirection = kwargs.get('close_direction')
self.setDropdownProp = kwargs.get('set_dropdown_prop', False)
Expand Down Expand Up @@ -67,6 +69,26 @@ def onAction(self, action):
except:
util.ERROR()

if self.roundRobin and action in (xbmcgui.ACTION_MOVE_UP, xbmcgui.ACTION_MOVE_DOWN) and \
self.getFocusId() == self.OPTIONS_LIST_ID:
to_pos = None
last_index = self.optionsList.size() - 1

if last_index > 0:
if action == xbmcgui.ACTION_MOVE_UP and self.lastSelectedItem == 0 and self.optionsList.topHasFocus():
to_pos = last_index

elif action == xbmcgui.ACTION_MOVE_DOWN and self.lastSelectedItem == last_index \
and self.optionsList.bottomHasFocus():
to_pos = 0

if to_pos is not None:
self.optionsList.setSelectedItemByPos(to_pos)
self.lastSelectedItem = to_pos
return

self.lastSelectedItem = self.optionsList.control.getSelectedPosition()

kodigui.BaseDialog.onAction(self, action)

def onClick(self, controlID):
Expand Down
2 changes: 1 addition & 1 deletion lib/windows/episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ def optionsButtonClicked(self, from_item=False):
pos = (1490, 167 + (viewPos * 100))
bottom = False
setDropdownProp = True
choice = dropdown.showDropdown(options, pos, pos_is_bottom=bottom, close_direction='top', set_dropdown_prop=setDropdownProp)
choice = dropdown.showDropdown(options, pos, pos_is_bottom=bottom, close_direction='left', set_dropdown_prop=setDropdownProp)
if not choice:
return

Expand Down
4 changes: 4 additions & 0 deletions lib/windows/kodigui.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,10 @@ def getSelectedItem(self):
return None
return self.getListItem(pos)

def setSelectedItemByPos(self, pos):
if self.positionIsValid(pos):
self.control.selectItem(pos)

def removeItem(self, index):
old = self.items.pop(index)
old.onDestroy()
Expand Down
43 changes: 43 additions & 0 deletions lib/windows/playersettings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import xbmc
import xbmcgui
import kodigui

from lib import util
Expand All @@ -23,6 +24,8 @@ def __init__(self, *args, **kwargs):
self.video = kwargs.get('video')
self.viaOSD = kwargs.get('via_osd')
self.nonPlayback = kwargs.get('non_playback')
self.roundRobin = kwargs.get('round_robin', True)
self.lastSelectedItem = 0

if not self.video.mediaChoice:
playerObject = plexnet.plexplayer.PlexPlayer(self.video)
Expand All @@ -44,6 +47,24 @@ def onAction(self, action):
except:
util.ERROR()

if self.roundRobin and action in (xbmcgui.ACTION_MOVE_UP, xbmcgui.ACTION_MOVE_DOWN) and \
self.getFocusId() == self.SETTINGS_LIST_ID:
to_pos = None
last_index = self.settingsList.size() - 1
if action == xbmcgui.ACTION_MOVE_UP and self.lastSelectedItem == 0 and self.settingsList.topHasFocus():
to_pos = last_index

elif action == xbmcgui.ACTION_MOVE_DOWN and self.lastSelectedItem == last_index \
and self.settingsList.bottomHasFocus():
to_pos = 0

if to_pos is not None:
self.settingsList.setSelectedItemByPos(to_pos)
self.lastSelectedItem = to_pos
return

self.lastSelectedItem = self.settingsList.control.getSelectedPosition()

kodigui.BaseDialog.onAction(self, action)

def onClick(self, controlID):
Expand Down Expand Up @@ -159,6 +180,8 @@ def __init__(self, *args, **kwargs):
self.selectedIdx = kwargs.get('selected_idx')
self.choice = None
self.nonPlayback = kwargs.get('non_playback')
self.lastSelectedItem = self.selectedIdx if self.selectedIdx is not None else 0
self.roundRobin = kwargs.get('round_robin', True)

def onFirstInit(self):
self.optionsList = kodigui.ManagedControlList(self, self.OPTIONS_LIST_ID, 8)
Expand All @@ -174,6 +197,26 @@ def onAction(self, action):
except:
util.ERROR()

if self.roundRobin and action in (xbmcgui.ACTION_MOVE_UP, xbmcgui.ACTION_MOVE_DOWN) and \
self.getFocusId() == self.OPTIONS_LIST_ID:
to_pos = None
last_index = self.optionsList.size() - 1

if last_index > 0:
if action == xbmcgui.ACTION_MOVE_UP and self.lastSelectedItem == 0 and self.optionsList.topHasFocus():
to_pos = last_index

elif action == xbmcgui.ACTION_MOVE_DOWN and self.lastSelectedItem == last_index \
and self.optionsList.bottomHasFocus():
to_pos = 0

if to_pos is not None:
self.optionsList.setSelectedItemByPos(to_pos)
self.lastSelectedItem = to_pos
return

self.lastSelectedItem = self.optionsList.control.getSelectedPosition()

kodigui.BaseDialog.onAction(self, action)

def onClick(self, controlID):
Expand Down