Miglioria a Menu Rapido

This commit is contained in:
Alhaziel01
2021-01-07 19:56:13 +01:00
parent 59c1e66b28
commit 1a61aa5c1b
3 changed files with 242 additions and 258 deletions

View File

@@ -1,16 +1,21 @@
# -*- coding: utf-8 -*-
from builtins import map
import sys, xbmc, xbmcaddon, xbmcgui, base64, json, os
PY3 = False
if sys.version_info[0] >= 3: PY3 = True; unicode = str; unichr = chr; long = int
import sys, xbmc, xbmcaddon, xbmcgui, base64, json, os, re
from threading import Timer
from channelselector import get_thumb
from platformcode import config, logger
from platformcode import config, logger, platformtools, launcher
from core.item import Item
import channelselector
addon_icon = os.path.join( config.__settings__.getAddonInfo( "path" ),'resources', 'media', 'logo.png' )
background = 'FF232323'
text = 'FFFFFFFF'
select = 'FF0082C2'
if config.get_setting('icon_set') == 'dark':
background = 'FFDCDCDC'
text = 'FF232323'
select = '880082C2'
class KeyListener(xbmcgui.WindowXMLDialog):
TIMEOUT = 10
@@ -89,89 +94,113 @@ def delete_key():
config.set_setting("shortcut_key", '')
xbmc.executebuiltin('Action(reloadkeymaps)')
LEFT = 1
RIGHT = 2
UP = 3
DOWN = 4
EXIT = 10
BACKSPACE = 92
RIGHTCLICK = 101
class Main(xbmcgui.WindowXMLDialog):
def __init__(self, *args, **kwargs):
self.items = []
def onInit(self):
self.MENU = self.getControl(1)
self.SUBMENU = self.getControl(2)
#### Compatibility with Kodi 18 ####
if config.get_platform(True)['num_version'] < 18:
self.setCoordinateResolution(2)
for menuentry in menu:
if not menuentry.channel: menuentry.channel = prevchannel
item = xbmcgui.ListItem(menuentry.title)
if not submenu and menuentry.channel in ['news', 'channelselector', 'search', 'videolibrary']:
item.setProperty('sub', 'Shortcut/sub.png')
if menuentry.title != 'Redirect':
for key , value in json.loads(menuentry.tojson()).items():
item.setProperty(key, str(value))
item.setProperty('run', menuentry.tojson())
self.items.append(item)
itemlist = self.menulist(channelselector.getmainlist())
self.getControl(32500).addItems(self.items)
self.setFocusId(32500)
self.MENU.addItems(itemlist)
self.setFocusId(1)
self.submenu()
def menulist(self, menu):
itemlist = []
for menuentry in menu:
# if not menuentry.channel: menuentry.channel = 'news'
item = xbmcgui.ListItem(menuentry.title)
item.setProperty('background', background)
item.setProperty('text', text)
item.setProperty('select', select)
item.setProperty('channel', menuentry.channel)
item.setProperty('focus', '0')
item.setProperty('thumbnail', menuentry.thumbnail)
if menuentry.channel in ['news', 'channelselector', 'search', 'videolibrary', 'favorites']:
item.setProperty('sub', 'true')
item.setProperty('run', menuentry.tourl())
itemlist.append(item)
return itemlist
def onClick(self, control_id):
if control_id == 32500:
action = self.getControl(32500).getSelectedItem().getProperty('run')
if control_id in [1, 2]:
action = self.getControl(control_id).getSelectedItem().getProperty('run')
self.close()
if self.getControl(32500).getSelectedItem().getProperty('folder') == 'False':
xbmc.executebuiltin('RunPlugin("plugin://plugin.video.kod/?' + base64.b64encode(action) + '")')
if self.getControl(control_id).getSelectedItem().getProperty('folder') == 'False':
xbmc.executebuiltin('RunPlugin("plugin://plugin.video.kod/?' + action + '")')
else:
xbmc.executebuiltin('ActivateWindow(10025, "plugin://plugin.video.kod/?' + base64.b64encode(action) + '")')
xbmc.executebuiltin('ActivateWindow(10025, "plugin://plugin.video.kod/?' + action + '")')
elif control_id in [101]:
logger.debug('DOWN')
self.setFocusId(2)
elif control_id in [102]:
logger.debug('UP')
self.setFocusId(1)
def onAction(self, action):
action = action.getId()
# exit
if action in [xbmcgui.ACTION_PREVIOUS_MENU, xbmcgui.ACTION_NAV_BACK]:
if action.getButtonCode() == config.get_setting('shortcut_key'):
self.close()
if submenu: open_shortcut_menu(self=True)
if action == xbmcgui.ACTION_CONTEXT_MENU:
config.open_settings()
action = action.getId()
if action in [EXIT, BACKSPACE, RIGHTCLICK]:
self.close()
focus = self.getFocusId()
if action == 3:
if focus == 61:
self.setFocusId(32500)
elif submenu:
self.close()
open_shortcut_menu(self=True)
elif self.getControl(32500).getSelectedItem().getProperty('channel') in ['news', 'channelselector', 'search', 'videolibrary']:
channel_name = self.getControl(32500).getSelectedItem().getProperty('channel')
if channel_name == 'channelselector':
import channelselector
self.close()
open_shortcut_menu(channelselector.getchanneltypes(), channel_name, self=True)
else:
from core.item import Item
channel = __import__('specials.%s' % channel_name, fromlist=["specials.%s" % channel_name])
self.close()
open_shortcut_menu(channel.mainlist(Item()), channel_name, self=True)
if action in [LEFT, RIGHT]:
if focus in [1]:
self.submenu()
else:
itfocus = str(self.SUBMENU.getSelectedPosition())
self.MENU.getSelectedItem().setProperty('focus', itfocus)
def open_shortcut_menu(newmenu='', channel='', self=False):
if not self: xbmc.executebuiltin('Dialog.Close(all,true)')
global menu
global submenu
global prevchannel
prevchannel = channel
if newmenu:
menu = newmenu
submenu = True
else:
menu = channelselector.getmainlist()
submenu = False
XML = 'ShortCutMenu.xml'
if config.get_setting('icon_set') == 'dark':
XML = 'Dark' + XML
main = Main(XML, config.get_runtime_path())
main.doModal()
del main
def submenu(self):
channel_name = self.MENU.getSelectedItem().getProperty('channel')
focus = int(self.MENU.getSelectedItem().getProperty('focus'))
if channel_name == 'channelselector':
import channelselector
itemlist = self.menulist(channelselector.getchanneltypes())
elif channel_name in ['news', 'channelselector', 'search', 'videolibrary', 'favorites']:
channel = __import__('specials.%s' % channel_name, fromlist=["specials.%s" % channel_name])
itemlist = self.menulist(channel.mainlist(Item().fromurl(self.MENU.getSelectedItem().getProperty('run'))))
self.SUBMENU.reset()
self.SUBMENU.addItems(itemlist)
self.SUBMENU.selectItem(focus)
def context(self):
focus = self.getFocusId()
item_url = self.MENU.getSelectedItem().getProperty('run')
item = Item().fromurl(item_url)
logger.debug(item)
commands = platformtools.set_context_commands(item, item_url, Item())
context = [c[0] for c in commands]
context_commands = [c[1].replace('Container.Refresh', 'RunPlugin').replace('Container.Update', 'RunPlugin') for c in commands]
index = xbmcgui.Dialog().contextmenu(context)
if index > 0: xbmc.executebuiltin(context_commands[index])
def open_shortcut_menu():
logger.debug('WID',xbmcgui.getCurrentWindowDialogId())
if xbmcgui.getCurrentWindowDialogId() == 9999:
main = Main('ShortCutMenu.xml', config.get_runtime_path())
main.doModal()

View File

@@ -1,114 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<window>
<depth>0.52</depth>
<coordinates>
<left>0</left>
<top>0</top>
</coordinates>
<controls>
<!-- CLOSE BUTTON / BACKGROUND -->
<control type="button">
<left>0</left>
<top>0</top>
<width>100%</width>
<height>100%</height>
<texturefocus colordiffuse="80DCDCDC">white.png</texturefocus>
<texturenofocus colordiffuse="80DCDCDC">white.png</texturenofocus>
<animation effect="fade" time="200">WindowOpen</animation>
<animation effect="fade" time="200">WindowClose</animation>
<onclick>Action(close)</onclick>
</control>
<!-- GROUP CONTROLS -->
<control type="group">
<left>100</left>
<top>250</top>
<animation type="WindowOpen" reversible="false">
<effect type="slide" start="0,100" end="0,0" delay="160" time="160" />
<effect type="fade" delay="160" end="100" time="100" />
</animation>
<animation type="WindowClose" reversible="false">
<effect type="slide" start="0,0" end="0,100" delay="160" time="160" />
<effect type="fade" delay="160" start="100" end="0" time="100" />
</animation>
<!-- SCROLLBAR -->
<control type="scrollbar" id="61">
<visible allowhiddenfocus="true">Control.HasFocus(61)</visible>
<animation effect="slide" start="0,0" end="0,-9" time="100">Unfocus</animation>
<animation effect="slide" start="0,-9" end="0,0" time="100">Focus</animation>
<left>0</left>
<top>219</top>
<width>1100</width>
<height>10</height>
<texturesliderbackground colordiffuse="FFDCDCDC">white.png</texturesliderbackground>
<texturesliderbar colordiffuse="FF1f1f1f">white.png</texturesliderbar>
<texturesliderbarfocus colordiffuse="FF0082C2">white.png</texturesliderbarfocus>
<showonepage>false</showonepage>
<orientation>horizontal</orientation>
<ondown>32500</ondown>
</control>
<!-- BACKGROUND -->
<control type="image">
<width>1100</width>
<height>218</height>
<texture colordiffuse="FFDCDCDC">white.png</texture>
</control>
<control type="list" id="32500">
<left>-130</left>
<top>-1</top>
<width>1100</width>
<height>220</height>
<onup>32501</onup>
<ondown>61</ondown>
<orientation>horizontal</orientation>
<scrolltime>200</scrolltime>
<pagecontrol>61</pagecontrol>
<animation effect="slide" start="0,0" end="10,0" time="0" condition="true">Conditional</animation>
<animation effect="slide" end="120,0" time="0" condition="!Control.IsVisible(5)">Conditional</animation>
<itemlayout height="220" width="220">
<control type="image">
<width>220</width>
<height>220</height>
<texture>$INFO[ListItem.Property(thumbnail)]</texture>
<aspectratio>keep</aspectratio>
<align>center</align>
</control>
</itemlayout>
<focusedlayout height="220" width="220">
<control type="image">
<top>1</top>
<width>220</width>
<height>218</height>
<texture colordiffuse="550082C2">white.png</texture>
</control>
<control type="image">
<width>220</width>
<height>220</height>
<texture>$INFO[ListItem.Property(thumbnail)]</texture>
<aspectratio>keep</aspectratio>
<align>center</align>
</control>
<control type="textbox">
<left>0</left>
<top>160</top>
<width>220</width>
<height>74</height>
<font>font13</font>
<textcolor>FF232323</textcolor>
<label>$INFO[ListItem.Label]</label>
<align>center</align>
<aligny>center</aligny>
</control>
<control type="image">
<left>90</left>
<top>0</top>
<width>40</width>
<height>40</height>
<texture colordiffuse="FF232323">$INFO[ListItem.Property(sub)]</texture>
<aspectratio>keep</aspectratio>
<align>center</align>
</control>
</focusedlayout>
</control>
</control> <!-- GROUP CONTROLS END -->
</controls>
</window>

View File

@@ -6,22 +6,29 @@
<top>0</top>
</coordinates>
<controls>
<!-- CLOSE BUTTON / BACKGROUND -->
<control type="button">
<description>Close Button</description>
<left>0</left>
<top>0</top>
<width>100%</width>
<height>100%</height>
<texturefocus colordiffuse="80232323">white.png</texturefocus>
<texturenofocus colordiffuse="80232323">white.png</texturenofocus>
<texturefocus colordiffuse="77232323">white.png</texturefocus>
<texturenofocus colordiffuse="77232323">white.png</texturenofocus>
<animation effect="fade" time="200">WindowOpen</animation>
<animation effect="fade" time="200">WindowClose</animation>
<onclick>Action(close)</onclick>
<onup>100</onup>
<ondown>100</ondown>
<onleft>100</onleft>
<onright>100</onright>
</control>
<!-- GROUP CONTROLS -->
<control type="group">
<description>Group Controls</description>
<left>100</left>
<top>250</top>
<width>1100</width>
<height>220</height>
<animation type="WindowOpen" reversible="false">
<effect type="slide" start="0,100" end="0,0" delay="160" time="160" />
<effect type="fade" delay="160" end="100" time="100" />
@@ -30,84 +37,146 @@
<effect type="slide" start="0,0" end="0,100" delay="160" time="160" />
<effect type="fade" delay="160" start="100" end="0" time="100" />
</animation>
<!-- SCROLLBAR -->
<control type="scrollbar" id="61">
<visible allowhiddenfocus="true">Control.HasFocus(61)</visible>
<animation effect="slide" start="0,0" end="0,-9" time="100">Unfocus</animation>
<animation effect="slide" start="0,-9" end="0,0" time="100">Focus</animation>
<left>0</left>
<top>219</top>
<width>1100</width>
<height>10</height>
<texturesliderbackground colordiffuse="FF232323">white.png</texturesliderbackground>
<texturesliderbar colordiffuse="FF1f1f1f">white.png</texturesliderbar>
<texturesliderbarfocus colordiffuse="FF0082C2">white.png</texturesliderbarfocus>
<showonepage>false</showonepage>
<orientation>horizontal</orientation>
<ondown>32500</ondown>
</control>
<!-- BACKGROUND -->
<control type="image">
<width>1100</width>
<height>218</height>
<texture colordiffuse="FF232323">white.png</texture>
<description>Background</description>
<top>0</top>
<left>0</left>
<width>100%</width>
<height>100%</height>
<texture colordiffuse="Container(1).ListItem.Property(background)">white.png</texture>
</control>
<control type="list" id="32500">
<left>-130</left>
<top>-1</top>
<width>1100</width>
<control type="grouplist">
<description>Group List</description>
<top>0</top>
<left>0</left>
<width>100%</width>
<height>220</height>
<onup>32501</onup>
<ondown>61</ondown>
<orientation>horizontal</orientation>
<scrolltime>200</scrolltime>
<pagecontrol>61</pagecontrol>
<animation effect="slide" start="0,0" end="10,0" time="0" condition="true">Conditional</animation>
<animation effect="slide" end="120,0" time="0" condition="!Control.IsVisible(5)">Conditional</animation>
<itemlayout height="220" width="220">
<control type="image">
<width>220</width>
<height>220</height>
<texture>$INFO[ListItem.Property(thumbnail)]</texture>
<aspectratio>keep</aspectratio>
<align>center</align>
</control>
</itemlayout>
<focusedlayout height="220" width="220">
<control type="image">
<top>1</top>
<width>220</width>
<height>218</height>
<texture colordiffuse="FF0082C2">white.png</texture>
</control>
<control type="image">
<width>220</width>
<height>220</height>
<texture>$INFO[ListItem.Property(thumbnail)]</texture>
<aspectratio>keep</aspectratio>
<align>center</align>
</control>
<control type="textbox">
<left>0</left>
<top>160</top>
<width>220</width>
<height>74</height>
<font>font13</font>
<textcolor>FFFFFFFF</textcolor>
<label>$INFO[ListItem.Label]</label>
<align>center</align>
<aligny>center</aligny>
</control>
<control type="image">
<left>90</left>
<top>0</top>
<width>40</width>
<height>40</height>
<texture>$INFO[ListItem.Property(sub)]</texture>
<aspectratio>keep</aspectratio>
<align>center</align>
</control>
</focusedlayout>
<orientation>vertical</orientation>
<control type="list" id="1">
<description>Menu</description>
<left>0</left>
<top>0</top>
<width>100%</width>
<height>220</height>
<onup>32501</onup>
<ondown>61</ondown>
<orientation>horizontal</orientation>
<scrolltime>200</scrolltime>
<pagecontrol>61</pagecontrol>
<itemlayout height="220" width="220">
<control type="image">
<width>220</width>
<height>220</height>
<texture>$INFO[ListItem.Property(thumbnail)]</texture>
<aspectratio>keep</aspectratio>
<align>center</align>
</control>
</itemlayout>
<focusedlayout height="220" width="220">
<control type="image">
<top>1</top>
<width>220</width>
<height>218</height>
<texture colordiffuse="Container(1).ListItem.Property(select)">white.png</texture>
</control>
<control type="image">
<width>220</width>
<height>220</height>
<texture>$INFO[ListItem.Property(thumbnail)]</texture>
<aspectratio>keep</aspectratio>
<align>center</align>
</control>
</focusedlayout>
</control>
<control type="list" id="2">
<description>Submenu</description>
<left>0</left>
<top>0</top>
<width>100%</width>
<height>220</height>
<onup>32501</onup>
<ondown>61</ondown>
<orientation>horizontal</orientation>
<scrolltime>200</scrolltime>
<pagecontrol>61</pagecontrol>
<itemlayout height="220" width="220">
<control type="image">
<width>220</width>
<height>220</height>
<texture>$INFO[ListItem.Property(thumbnail)]</texture>
<aspectratio>keep</aspectratio>
<align>center</align>
</control>
</itemlayout>
<focusedlayout height="220" width="220">
<control type="image">
<top>1</top>
<width>220</width>
<height>218</height>
<texture colordiffuse="Container(1).ListItem.Property(select)">white.png</texture>
</control>
<control type="image">
<width>220</width>
<height>220</height>
<texture>$INFO[ListItem.Property(thumbnail)]</texture>
<aspectratio>keep</aspectratio>
<align>center</align>
</control>
</focusedlayout>
</control>
</control>
<control type="textbox">
<description>Selected Item</description>
<left>0</left>
<top>280</top>
<width>100%</width>
<height>40</height>
<font>font13</font>
<textcolor>FFFFFFFF</textcolor>
<label>$INFO[ListItem.Label]</label>
<align>center</align>
<aligny>center</aligny>
</control>
<control type="button" id='101'>
<visible>!String.IsEmpty(Container(1).ListItem.Property(sub)) + !Control.HasFocus(2) + !Control.HasFocus(102)</visible>
<animation effect="fade" start="0" end="100" time="200" reversible="true" condition="Control.IsVisible(101)">Conditional</animation>
<animation effect="slide" end="220,0" condition="Integer.IsGreater(Container(1).Position,0)">Conditional</animation>
<animation effect="slide" end="220,0" condition="Integer.IsGreater(Container(1).Position,1)">Conditional</animation>
<animation effect="slide" end="220,0" condition="Integer.IsGreater(Container(1).Position,2)">Conditional</animation>
<animation effect="slide" end="220,0" condition="Integer.IsGreater(Container(1).Position,3)">Conditional</animation>
<animation effect="slide" end="220,0" condition="Integer.IsGreater(Container(1).Position,4)">Conditional</animation>
<animation effect="slide" end="220,0" condition="Integer.IsGreater(Container(1).Position,5)">Conditional</animation>
<left>90</left>
<top>180</top>
<width>40</width>
<height>40</height>
<texturefocus colordiffuse="Container(1).ListItem.Property(text)">down.png</texturefocus>
<texturenofocus colordiffuse="Container(1).ListItem.Property(text)">down.png</texturenofocus>
<aspectratio>keep</aspectratio>
</control>
<control type="button" id='102'>
<visible>!Control.HasFocus(1) + !Control.HasFocus(101)</visible>
<animation effect="fade" start="0" end="100" time="200" reversible="true" condition="Control.IsVisible(102)">Conditional</animation>
<animation effect="slide" end="220,0" condition="Integer.IsGreater(Container(2).Position,0)">Conditional</animation>
<animation effect="slide" end="220,0" condition="Integer.IsGreater(Container(2).Position,1)">Conditional</animation>
<animation effect="slide" end="220,0" condition="Integer.IsGreater(Container(2).Position,2)">Conditional</animation>
<animation effect="slide" end="220,0" condition="Integer.IsGreater(Container(2).Position,3)">Conditional</animation>
<animation effect="slide" end="220,0" condition="Integer.IsGreater(Container(2).Position,4)">Conditional</animation>
<animation effect="slide" end="220,0" condition="Integer.IsGreater(Container(2).Position,5)">Conditional</animation>
<left>90</left>
<top>0</top>
<width>40</width>
<height>40</height>
<texturefocus colordiffuse="Container(1).ListItem.Property(text)">up.png</texturefocus>
<texturenofocus colordiffuse="Container(1).ListItem.Property(text)">up.png</texturenofocus>
<aspectratio>keep</aspectratio>
</control>
</control> <!-- GROUP CONTROLS END -->
</controls>