Kodi Community Forum
Release PyXBMCt: a Python framework for simple creating UI for XBMC addons - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: Release PyXBMCt: a Python framework for simple creating UI for XBMC addons (/showthread.php?tid=174859)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27


RE: PyXBMCt: a Python framework for simple creating UI for XBMC addons - Roman_V_M - 2023-05-10

It's hard to tell without seeing the code but the issue but indeed you need to close your window first before starting video. As for why it stops, you need to show your code.


RE: PyXBMCt: a Python framework for simple creating UI for XBMC addons - carlog - 2023-05-11

Here's the important parts....

class MyAddon(pyxbmct.AddonDialogWindow):

    def __init__(self, title=''):
        super(MyAddon, self).__init__(title)
        self.setGeometry(1200, 450, 9, 5)
        self.set_info_controls()
        self.set_active_controls()
        self.set_navigation()
        # Connect a key action (Backspace) to close the window.
        self.connect(pyxbmct.ACTION_NAV_BACK, self.close)
        

    def set_info_controls(self):
        global gameInfoArr
        # Demo for PyXBMCt UI controls.
.
.
.
        #
        self.list_item_label = pyxbmct.Label('', textColor='0xFF808080')
        self.placeControl(self.list_item_label, 4, 3)
        # List
        self.list = pyxbmct.List()
        self.placeControl(self.list, 3, 4, 3, 1)
        # Add items to the list
        for mlink in gameInfoArr['linkitems']:
         self.list.addItem(mlink['title'])
        self.connect(self.list, lambda: self._play_video(gameInfoArr['linkitems'][self.list.getSelectedPosition()]['url']))
        
        # Connect key and mouse events for list navigation feedback.
        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)
.
.
.
        # Button
        self.button = pyxbmct.Button('Close')
        self.placeControl(self.button, 8, 4)
        # Connect control to close the window.
        self.connect(self.button, self.close)

    def set_navigation(self):
        # Set navigation between controls
        self.button.controlUp(self.slider)
        self.button.controlDown(self.radiobutton)
        self.radiobutton.controlUp(self.button)
        self.radiobutton.controlDown(self.edit)
        self.edit.controlUp(self.radiobutton)
        self.edit.controlDown(self.list)
        self.list.controlUp(self.edit)
        self.list.controlDown(self.slider)
        self.slider.controlUp(self.list)
        self.slider.controlDown(self.button)
        # Set initial focus
        self.setFocus(self.radiobutton)

    def list_update(self):
        # Update list_item label when navigating through the list.
        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):
        # Set fade animation for all add-on window controls
        control.setAnimations([('WindowOpen', 'effect=fade start=0 end=100 time=500',),
                                ('WindowClose', 'effect=fade start=100 end=0 time=500',)])

    def _play_video(self, url):
        xbmc.Player().play(url)
        xbmc.sleep(9000)
        self.close()

.
.
.


def open_window(gameInfo):
.
.
.
    window = MyAddon('Game Information')
    window.doModal()

When I click on the list item, it will load the video and start playing behind the window, then about 9 seconds later the window closes and the video stops.  If I don't put in the 9 second sleep, the window just closes and the video never starts.  If I change it from AddonDialogWindow to AddonFullWindow, I get the error I mentioned earlier.


Thank you in advance for taking a look.  Much appreciated!


RE: PyXBMCt: a Python framework for simple creating UI for XBMC addons - carlog - 2023-05-11

In the code above, after the 9 second sleep, as soon as the window closes and video stops, this is what's in the log:

2023-05-10 18:03:13.906 T:16248    info <general>: CVideoPlayer::CloseFile()
2023-05-10 18:03:13.907 T:8856     info <general>: CVideoPlayer::OnExit()
2023-05-10 18:03:13.907 T:8856     info <general>: Closing stream player 1
2023-05-10 18:03:13.907 T:8856     info <general>: Waiting for audio thread to exit
2023-05-10 18:03:13.911 T:16248    info <general>: VideoPlayer: waiting for threads to exit
2023-05-10 18:03:13.919 T:9768     info <general>: thread end: CVideoPlayerAudio::OnExit()


RE: PyXBMCt: a Python framework for simple creating UI for XBMC addons - carlog - 2023-05-11

I think I got it.  I had set something to isPlayable to true when it should have been false.  Thanks!


RE: PyXBMCt: a Python framework for simple creating UI for XBMC addons - Roman_V_M - 2023-05-11

I'm not sure what isPlayable has to do with it but as I suspected the problem is in object lifetime. Your Player instance lives in the instance method scope and is garbage-collected as soon as your _play_video() method returns that causes your entire script to exit. You should re-organize your code in such way that a Player instance lives as long as your video is played. Another possible way is to try to use "PlayMedia" built-in function: https://kodi.wiki/view/List_of_built-in_functions#Player_built-in's It should start playback in the background if I remember correctly.


RE: PyXBMCt: a Python framework for simple creating UI for XBMC addons - carlog - 2023-05-16

My ItemList was set for each item as isPlayable=true, but instead it actually launched a window, and in that window, a listitem would play a video.  No that I set that to false, it works the way I want it to.  In fact, I changed it to AddonFullWindow so that the window is still up when you exit the video.  This works the way I want if I'm using it in Addons, my addon, and go through the items.  If I add it to a widget in Actic Horizon 2 on the home screen, it hangs when I try to launch the window because apparently AH2 is considered a modal window.  If I change it back to AddonDialogWindow, then the window loads, but launching the video hangs.  I tried closing the window, sleeping for a number of seconds, then launching the video, but it still hangs because of 2 modal windows.


RE: PyXBMCt: a Python framework for simple creating UI for XBMC addons - Gavlarrrrr - 2023-08-13

Evening,

Is it possible in pyxbmct to capture long press? I want to be able to activate a context menu like you would in a standard addon by long press of c or spacebar or hold select on a remote if using an android device.

I've tried the below code as a test but doesn't work. Not sure if within the pyxbmct framework if it is possible to have a context menu even if I created a custom size window to display the options I wish, first I need to be able to capture the long press like within a regular addon.

Thank you
Quote:ACTION_MOUSE_LONG_CLICK = 108
def onAction(self, action):
    if action == ACTION_MOUSE_LONG_CLICK:



RE: PyXBMCt: a Python framework for simple creating UI for XBMC addons - Gavlarrrrr - 2023-08-13

I see you said you found another way, I have also been curious about playing a video within the window, What way did you discover?


RE: PyXBMCt: a Python framework for simple creating UI for XBMC addons - Gavlarrrrr - 2023-08-13

(2019-02-13, 17:02)yannbrrd Wrote: Hi,

I have 3 questions (for now Wink ):
1. How can I preserve picture ratio on display ?
2. Is there a way to play audio in background ?
3. Can we display a video too ?

Thanks.

Yann
What other way did you find for number 3 in the end?


RE: PyXBMCt: a Python framework for simple creating UI for XBMC addons - Roman_V_M - 2023-08-14

(2023-08-13, 22:58)Gavlarrrrr Wrote: Is it possible in pyxbmct to capture long press?

Python API does not work with key presses or mouse clicks or whatever. It woks with UI actions: https://romanvm.github.io/Kodistubs/_modules/xbmcgui.html that are mapped to specific controller events using a keymap file: https://kodi.wiki/view/Keymap.

As for video in a window it is not possible via Python API. Maybe it's possible via XML-based UI but I'm not familiar with skinning and XML-based UIs.


RE: PyXBMCt: a Python framework for simple creating UI for XBMC addons - Gavlarrrrr - 2023-08-14

(2023-08-14, 09:30)Roman_V_M Wrote:
(2023-08-13, 22:58)Gavlarrrrr Wrote: Is it possible in pyxbmct to capture long press?

Python API does not work with key presses or mouse clicks or whatever. It woks with UI actions: https://romanvm.github.io/Kodistubs/_modules/xbmcgui.html that are mapped to specific controller events using a keymap file: https://kodi.wiki/view/Keymap.

As for video in a window it is not possible via Python API. Maybe it's possible via XML-based UI but I'm not familiar with skinning and XML-based UIs.

Yes I have tried keymaps from this as well for example ACTION_SELECT_ITEM = 7 which to my thinking means when they select an item, it should see this and do something so even as a test I had this, but it didn't dialog like it should, I have buttons within the GUI, I wanted it to basically have similar to a context menu like in a standard addon, so I can add some functions into the context menu within the GUI
Quote:ACTION_SELECT_ITEM = 7

def onAction(self, action):
    if action == ACTION_SELECT_ITEM:
         dialog.ok("YOU","CLICKED")



RE: PyXBMCt: a Python framework for simple creating UI for XBMC addons - Gavlarrrrr - 2023-08-14

(2023-08-14, 09:30)Roman_V_M Wrote:
(2023-08-13, 22:58)Gavlarrrrr Wrote: Is it possible in pyxbmct to capture long press?

Python API does not work with key presses or mouse clicks or whatever. It woks with UI actions: https://romanvm.github.io/Kodistubs/_modules/xbmcgui.html that are mapped to specific controller events using a keymap file: https://kodi.wiki/view/Keymap.

As for video in a window it is not possible via Python API. Maybe it's possible via XML-based UI but I'm not familiar with skinning and XML-based UIs.

Maybe to make it easier to understand, in a normal none gui kodi addon, you have lists and if you pushed " C " on your keyboard on an item in a list a context menu appears as you can add the item to Kodi Favs, however if you have a list within GUI and you pushed " C " on an item in the list, no context menu appears so no way of being able to add something to Kodi Favs, so I am asking how can we achieve that within PYXBMCT?

Thanks for your assistance?


RE: PyXBMCt: a Python framework for simple creating UI for XBMC addons - Roman_V_M - 2023-08-15

(2023-08-14, 22:57)Gavlarrrrr Wrote: Maybe to make it easier to understand, in a normal none gui kodi addon, you have lists and if you pushed " C " on your keyboard on an item in a list a context menu appears as you can add the item to Kodi Favs, however if you have a list within GUI and you pushed " C " on an item in the list, no context menu appears so no way of being able to add something to Kodi Favs, so I am asking how can we achieve that within PYXBMCT?

For context menu we have ACTION_CONTEXT_MENU that can be captured and a context menu can be displayed via https://romanvm.github.io/Kodistubs/_autosummary/xbmcgui.html#xbmcgui.Dialog.contextmenu But you'll have to program all the flow for yourself, including context menu items and their respective actions. And you cannot add items from ControlList to Favorites. Favorites can hold only paths to media items, either direct (/home/Videos/... , https://....) or virtual (plugin://...) and ControlList items are neither.

Also for addons that play some media files it's better to use plugin API that is much simpler and Kodi does most of the work for you.

And I want to repeat this again, Python-based addon UI is good for relatively simple things. For complex stuff you should use XML-based UI.


RE: PyXBMCt: a Python framework for simple creating UI for XBMC addons - caperucitaferoz - 2023-12-04

Hello!
First of all I apologize if this has already been explained before, but I've been searching and haven't found it.
My question is simple, is there a multiline Edit control or an editable textbox? And if it does not exist, could this be implemented using Python in some way?
Thank you


RE: PyXBMCt: a Python framework for simple creating UI for XBMC addons - Roman_V_M - 2023-12-04

Kodi does not have such control.