Release - PyXBMCt: a Python framework for simple creating UI for XBMC addons

  Thread Rating:
  • 2 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
petewilson Offline
Junior Member
Posts: 6
Joined: Jan 2015
Reputation: 0
Post: #151
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.getSelectedPo​sition()).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..?
(This post was last modified: 2015-01-13 05:10 by petewilson.)
find quote
Roman_V_M Online
Fan
Posts: 624
Joined: Jun 2011
Reputation: 15
Location: Kyiv, Ukraine
Post: #152
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.

AMD A4-3300 + AsRock A75M-ITX
XBMC 13.2 (custom build) on Windows 7
find quote
petewilson Offline
Junior Member
Posts: 6
Joined: Jan 2015
Reputation: 0
Post: #153
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. .
find quote
Roman_V_M Online
Fan
Posts: 624
Joined: Jun 2011
Reputation: 15
Location: Kyiv, Ukraine
Post: #154
(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.

AMD A4-3300 + AsRock A75M-ITX
XBMC 13.2 (custom build) on Windows 7
find quote
petewilson Offline
Junior Member
Posts: 6
Joined: Jan 2015
Reputation: 0
Post: #155
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
(This post was last modified: 2015-01-14 14:53 by petewilson.)
find quote
petewilson Offline
Junior Member
Posts: 6
Joined: Jan 2015
Reputation: 0
Post: #156
I've tried but still no further forward.. can someone just spell it out for me.. please..
find quote
petewilson Offline
Junior Member
Posts: 6
Joined: Jan 2015
Reputation: 0
Post: #157
anyone?
(This post was last modified: 2015-01-17 16:18 by petewilson.)
find quote
nickr Offline
Donor
Posts: 10,920
Joined: May 2009
Reputation: 196
Location: Christchurch NZ
Post: #158
Have you taken a look at the hello world sample thread?

If I have helped you or increased your knowledge, click the plus button and increase my reputation :)
find quote
Post Reply