possible to modify listitem context menu?
#1
Question 
Hi, novice add-on developer here...

I'm working on a python script that updates a ListItem's database value.

I can, of course, call the script from a skin XML with RunScript(myscript, params), however I want this script to be called from the context menu, e.g. the user:
  • enters VideoLibrary list
  • highlights an item
  • enters the context menu (press "c" for eg.)
  • a new button exists for him to choose this new functionality I'm developing
  • clicking this button will run the script, referencing the highlighted ListItem
Is it possible to modify or add an item to the context menu? And if so, under which conditions/events should this be hooked into?
Also, if this is not possible - what would you suggest is the best place/way to add functionality that should be available for list-items?

Thanks Smile
Reply
#2
The following will create a listitem with a single context menu item:

Code:
listItem = xbmcgui.ListItem(name, iconImage='DefaultFolder.png', thumbnailImage=iconimage)
listItem.setInfo(type="Video", infoLabels={'Title': name })

contextMenuItems = []
contextMenuItems.append(('Your context button', 'XBMC.RunScript(%s,%s)' % (myscript, params))

listItem.addContextMenuItems(contextMenuItems, replaceItems=True)

xbmcplugin.addDirectoryItem...

Notice that a contextMenuItem is a 2-tuple, that takes 2 strings: name of the button and the button action.
Also notice replaceItems in addContextMenuItems, this is whether the items should be appended to the current context menu or simply just replace them and show only the new ones.
Reply
#3
(2013-11-16, 08:44)mikaelec Wrote: Notice that a contextMenuItem is a 2-tuple, that takes 2 strings: name of the button and the button action.
Also notice replaceItems in addContextMenuItems, this is whether the items should be appended to the current context menu or simply just replace them and show only the new ones.

@mikaelec
Thank you so much for your response! these contextMenu functions will definitely get me on my way to scripting this new contentMenuItem.
However, I'm still missing one thing - how do I hook into XBMC to fire the script?

Meaning: the goal here is to make this script fire automatically whenever a list is being created my XBMC, so that I could iterate the media items in that list and add my context menu item to each of them. Basically:
  • user click "Movies", for example
  • XBMC goes to "Movies" page, generating a list of movies to be displayed to the user
  • during pageload, after the list has been generated, my script is fired
  • I go through the listItems, adding my contextMenuItem to each of them
Currently, I can only fire my script by manually running RunScript(...)

Is there a hook or event that XBMC uses while creating media lists, that I can use to tell it to fire my script whenever a list is being created? Maybe through my script's addon.xml definition?
Reply
#4
Hi there!

I have exactly the same problem. Any progress on this?
Reply
#5
Currently, you can only change the context menu for list items that you create, when you create them. You cannot edit the global context menu.

The "exception" to this if you edit the skin to include the item when displaying the context menu.

Also, there is a PR in the works, but since Gotham is in Feature Freeze, it won't make it into Gotham
Reply
#6
Found the answer, a bit disappointing (not yet merged), but at least something:

https://github.com/xbmc/xbmc/pull/1654

Also discussed somewhere else:

http://forum.xbmc.org/showthread.php?tid=180451
Reply
#7
The only way is to manually add your button in DialogContextMenu.xml. Copy the contents of the button template with id=1000 and put it in your button to give it the same appearance.
Reply
#8
(2014-01-15, 12:49)torenvalk Wrote: The only way is to manually add your button in DialogContextMenu.xml. Copy the contents of the button template with id=1000 and put it in your button to give it the same appearance.

Hi @torenvalk,

Thanks for your answer, I've been meaning to implement a new button for quite some time now Smile
I tried adding a button according to your suggestion, but without success.

For example, I changed DialogContextMenu.xml in skin.confluence:
PHP Code:
        <control type="button" id="1000"><!-- this is from the original skin -->
            <
description>button template</description>
            <
posx>-</posx>
            <
posy>-</posy>
            <
width>300</width>
            <
height>38</height>
            <
font>fontContextMenu</font>
            <
align>center</align>
            <
textcolor>grey2</textcolor>
            <
focusedcolor>white</focusedcolor>
            <
texturefocus border="5">button-focus.png</texturefocus>
        </
control>
        <
control type="button"><!-- my addition -->
          <
posx>-</posx>
            <
posy>-</posy>
            <
width>300</width>
            <
height>38</height>
            <
font>fontContextMenu</font>
            <
align>center</align>
            <
textcolor>grey2</textcolor>
            <
focusedcolor>white</focusedcolor>
            <
texturefocus border="5">button-focus.png</texturefocus>
            <
label>test</label>
        </
control

...but the button did not work according to plan.
  1. The button is not places correctly, not aligned like all the other buttons
  2. You canot navigate to the button - up-down cycles through the core's buttons and the new one is unreachable
Here's a pic to demonstrate:
Image

Am I doing something wrong?
Reply
#9
(2014-01-16, 19:58)EtgarDizz Wrote: Am I doing something wrong?

You'll want to make sure it looks something like this:

Code:
<control type="grouplist" id="996">
    
        <!--Your manually added button-->
    <control type="button" id="2001">
            
           </control>
                
    <control type="button" id="1000">
                
        <description>Buttons</description>
        <include>Common_ContextMenu_Button</include>
                
    </control>
                
</control>

The button you're trying to add should have an id. Whether or not that button needs to be before / after button 1000 someone else will have to chime in.
Reply
#10
(2014-01-17, 16:28)Sranshaft Wrote: The button you're trying to add should have an id. Whether or not that button needs to be before / after button 1000 someone else will have to chime in.

Hi @Sranshaft, thanks for the reply.
Unfortunately, your suggestion made no difference. I tried with/without an ID, before/after button 1000, no change.
Any ideas?
Reply
#11
(2014-01-18, 23:48)EtgarDizz Wrote:
(2014-01-17, 16:28)Sranshaft Wrote: The button you're trying to add should have an id. Whether or not that button needs to be before / after button 1000 someone else will have to chime in.

Hi @Sranshaft, thanks for the reply.
Unfortunately, your suggestion made no difference. I tried with/without an ID, before/after button 1000, no change.
Any ideas?

No clue. This is the code I used to add a context menu item for Meta-data Actors script support in Immersive and works as one would expect. Maybe if we had a look at the full DialogContextMenu.xml file someone might be able to point out the issue.
Reply
#12
(2014-01-21, 17:11)Sranshaft Wrote: No clue. This is the code I used to add a context menu item for Meta-data Actors script support in Immersive and works as one would expect. Maybe if we had a look at the full DialogContextMenu.xml file someone might be able to point out the issue.

Where can I find Immersive code?

Here's a pastebin: http://pastebin.com/ReDbh7jZ
(it's basically the code form Quartz which I'm trying to mod a bit)
Reply
#13
The issue you're having in that you need to put the button you're adding within the 996 grouplist control. Do that and it should work.

Here's the link to Immersive's DialogContextMenu.xml for comparison: https://github.com/Sranshaft/skin.immers...xtMenu.xml
Reply
#14
I myself solved the problem by hacking xbmc itself.

See xbmc/windowsGUIMediaWindow.cpp :
functions:
GetContextButtons
OnContextButton

I just added my own buttons to the end of the CONTEXT_BUTTON enum in xbmc/dialogs/GUIDialogContextMenu.h.

Then I just called buttons.Add(CONTEXT_BUTTON_MYCOOLBUTTON, "Label text");

and handled the click in OnContextButton.

It works like a charm.

If you need to get the real filesystem path for an item, this worked for me:

m_pathCItem = item->HasVideoInfoTag() ? item->GetVideoInfoTag()->GetPath() : item->GetBaseMoviePath(true);

item-> GetPath() itself does not return the filesystem path, if you browse your videos via the library, but instead some virtual path something like: recentlyadded:://vidoes/1

Good luck.
Reply
#15
This should work: http://pastebin.com/QwdpDNe1
Reply

Logout Mark Read Team Forum Stats Members Help
possible to modify listitem context menu?0