• 1
  • 9
  • 10
  • 11(current)
  • 12
  • 13
  • 27
Release PyXBMCt: a Python framework for simple creating UI for XBMC addons
huh, ok, so after a couple of days I've actually found out I can change the menu items by declaring the items at the top and rem'ming out the line which set the menu items up previously:

Code:
import os
import xbmc
import xbmcaddon
import pyxbmct.addonwindow as pyxbmct

_addon = xbmcaddon.Addon()
_addon_path = _addon.getAddonInfo('path')

items = ('Number1','Number2')

class MyAddon(pyxbmct.AddonDialogWindow):

    def __init__(self, title=''):
        super(MyAddon, self).__init__(title)
        self.setGeometry(500, 450, 9, 4)
        self.set_active_controls()
        self.set_navigation()
        self.connect(pyxbmct.ACTION_NAV_BACK, self.close)


    def set_active_controls(self):
        self.list = pyxbmct.List()
        self.placeControl(self.list, 0, 0, 15, 4)
        #items = ['Item {0}'.format(i) for i in range(1, 8)]
        self.list.addItems(items)
        self.connect(self.list, lambda: xbmc.executebuiltin('Notification(Note!,{0} selected.)'.format(
            self.list.getListItem(self.list.getSelectedPosition()).getLabel())))
        self.connectEventList(
            [pyxbmct.ACTION_MOVE_DOWN,
             pyxbmct.ACTION_MOVE_UP,
             pyxbmct.ACTION_MOUSE_WHEEL_DOWN,
             pyxbmct.ACTION_MOUSE_WHEEL_UP,
             pyxbmct.ACTION_MOUSE_MOVE],
            self.list_update)
        self.button = pyxbmct.Button('Close')
        self.placeControl(self.button, 8, 3)
        self.connect(self.button, self.close)


    def set_navigation(self):
        self.setFocus(self.list)

    def list_update(self):
        try:
            if self.getFocus() == self.list:
                self.list_item_label.setLabel(self.list.getListItem(self.list.getSelectedPosition()).getLabel())
            else:
                self.list_item_label.setLabel('')
        except (RuntimeError, SystemError):
            pass

    def setAnimation(self, control):
        control.setAnimations([('WindowOpen', 'effect=fade start=0 end=100 time=500',),
                                ('WindowClose', 'effect=fade start=100 end=0 time=500',)])
    
    
    def Number1()
        xbmc.executebuiltin('Notification(Note!,Number 1 Selected!)')

    def Number2()
        xbmc.executebuiltin('Notification(Note!,Number 2 Selected!)')

if __name__ == '__main__':
    window = MyAddon('Scripts')
    window.doModal()

so that leaves me being able to set the menu options the way I would like, but now how to code the menu to say if number 1 is selected, run this script..?
Reply
2 petewilson

Please read ControlList docs to find out what methods it has. Specifically to find out which List item is currently selected you need this:
Code:
getSelectedPosition(...)
    getSelectedPosition() --Returns the position of the selected item as an integer.
    
    *Note, Returns -1 for empty lists.
    
    example:
        - pos = cList.getSelectedPosition()

BTW, the example add-on does demonstrate how to organize program feedback for a List.
Reply
Hi Roman, thanks for taking the time to help. I've only been writing python for a week or so on and off.. and I have to admit while I totally get the idea of _getselectedposition, it is not immediately obvious where I should add it.. in notepad plus it seemed every time I tried to add my own code/start my own line it came up with dotted lines below.. I assumed this meant some kind of syntax error. .
Reply
(2015-01-14, 02:15)petewilson Wrote: Hi Roman, thanks for taking the time to help. I've only been writing python for a week or so on and off.. and I have to admit while I totally get the idea of _getselectedposition, it is not immediately obvious where I should add it.. in notepad plus it seemed every time I tried to add my own code/start my own line it came up with dotted lines below.. I assumed this meant some kind of syntax error. .

Notepad++ is a good tool but only if you know what you are doing. First, I strongly recommend to learn at least Python basics, especially syntax rules.
Also for those with little or no previous Python experience I would recommend to use PyCharm Educational Edition to write your code. It is a great tool which will help you avoid at least basic errors.
Reply
to be honest I'm just dipping my toe so to speak, I have a little few scripts which are obviously a lot more basic than what I'm trying to do now (no gui's but they work) all I want now is to have a little menu on the screen so I can pick a script to run - once I have my menu I'm sorted and will only every be doing basic things which I've managed to learn for myself.. I've tried to read docs but I've yet to find one that easily explains how to do what I want to do.. spent so much time on this now, it'd be a shame not to have a little gui - especially since it seems I am so close
Reply
I've tried but still no further forward.. can someone just spell it out for me.. please..
Reply
anyone?
Reply
Have you taken a look at the hello world sample thread?
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply
Hi!
I've managed to store/load current status of a few radiobuttons when start/stop the addon. However, is there a way to simulate a that a radiobutton isSelected? Cause if I read from the file that a radiobutton was On before shutdown I want to set it as On when I open the addon.
The code looks like this:
Code:
try:
            with open("output.txt") as f:
                states = json.load(f)
        except IOError:
            states = [1, 0, 0, 0, 0, 0, 0, 0]
            f = open('output.txt', 'w')
            json.dump(states, f)
        for state in states:
            if state == 1:
                //This button used to be on, lets turn it on! How?

EDIT: Solved using setSelected.
Reply
Hi Roman,

First of all - Thank you very much!

Almost completed my plugin using 'AddonDialogWindow', works great, and now want to try AddonFullWindow.

The problem is I have been trying hard to overcome Kodi showing the spinning 'Working' notification at the bottom right when using AddonFullWindow, even when testing with the minimal non OOP example on your first post.

Basically I swapped 'AddonDialogWindow' for AddonFullWindow in the example to test but still have Kodi showing the 'Working' notification. To get past the notification, I hit 'ESC', then wait about 5 seconds before the window responds.

I have also tried the local pyxbmct version (FYI - Missing the ## Mouse click
ACTION_MOUSE_LEFT_CLICK = 100)

Are there any examples of using AddonFullWindow, in case I may be missing something important?

Using kodi-14.2-Helix

Thanks again.
Reply
2 DEBUG

I've tested the example from the 1-st post with AddonFullWindows on Kodi 14.2, and it works fine for me. Maybe I can help you more if you show me some of your code.
Also, since PyXBMCt is in the official Kodi repo now, local version is depreciated and outdated.
Reply
Hi Roman,

Problem solved!

Thank you for quick reply and confirming PyXBMCt all ok with Kodi 14. This prompted me to look elsewhere.

I found that my "addon.xml" was the issue. I have now changed it to match yours. I had changed the required Python and PyXBMCt versions to match what I saw in the current Kodi. Best I leave it alone!

On with my personal preference add-on for viewing/setting recording schedules for MythTV PVR backend. Smile


Regards,

Debug.
Reply
Hi again Roman ;-)

Another question, but this time it's specific to PyXBMCt, which BTW is extremely helpful and intuitive in setting up my add ons UI.

First question:
Can you set a fadelabel control to have a fixed X axis width with the text wrapping if necessary, and then the text scrolling up and down (if it's too long)?

Currently if I just put in:
Code:
my_fadelabel = pyxbmct.FadeLabel()
window.placeControl(my_fadelabel, 0, 0, columnspan=1, rowspan=1)
my_fadelabel.addLabel('Blah blah blah blah blah  blah blah blah blah  blah blah blah blah  blah blah blah blah ....... ')
The text will scroll left and right. For my purposes, i'd like it to wrap left / right and scroll up and down if necessary.

Second question. Is it possible to play a video in a set grid size within the window? If so, are there examples around that show how this is done?

Thanks very much!
Reply
2 zachmorris
"No" to both of your questions. PyXBMCt can do only as much as underlying xbmcgui Controls. Maybe you should consider XML-based UI which offers more features, but you need to know Kodi skinning as well.
Reply
This framework have worked great for me so far. I am really missing some kind of a scrolling function in each window I open though.
Is there any way to achieve this?

I will resort to a next button if all else fails.
Reply
  • 1
  • 9
  • 10
  • 11(current)
  • 12
  • 13
  • 27

Logout Mark Read Team Forum Stats Members Help
PyXBMCt: a Python framework for simple creating UI for XBMC addons4