Kodi Community Forum

Full Version: PyXBMCt: a Python framework for simple creating UI for XBMC addons
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
I'm sorry for such a noob question, but how do I install PyXBMCt in Kodi 17? I can't seem to find it in the Kodi official repository.
(2017-03-23, 13:28)anpaza Wrote: [ -> ]I'm sorry for such a noob question, but how do I install PyXBMCt in Kodi 17? I can't seem to find it in the Kodi official repository.

Unfortunately, library addons cannot be installed manuall from a repo. There was such possibility once but it was remove for reasons unknown. PyXBMCt is automatically installed if you install an addon that has it as a dependency, or you can install it manually from ZIP.
I want Kodi to play a video (fullscreen) when I push a button on a PyXBMCt build window. When the video is stopped/finished, I want to return to that PyXBMCt build window.

When I click that button, following code gets run:

Code:
def push_main_test_button(self):
        log("Main test button pushed")
        wid = xbmcgui.getCurrentWindowDialogId()
        log("windialog id = %s" % str(wid))

        
        self.close()
        xbmc.executebuiltin('ActivateWindow(fullscreenvideo)')
        xbmc.Player().play("f:\BIU_Black_Animation.720p_large.mp4")

This works so far OK.
But when the video is done, I can't return to this PyXBMCt build window (window id = wid). This has failed me so far.

Has anyone an idea how to achieve this?

At the moment, I think that the script is even terminated by Kodi (looking at the logs). I tried also to subclass xbmc.player() and call activatewindow(wid) from "onPlayBackEnded" & "onPlayBackStopped", but that also doesn't work (seems to be the same problem, script seems to be terminated by Kodi).

Code:
19:33:26.470 T:3184   DEBUG: Bluray iso utils: Main test button pushed
19:33:26.471 T:3184   DEBUG: Bluray iso utils: windialog id = 13003
19:33:26.483 T:4980   DEBUG: ------ Window Deinit () ------
19:33:26.484 T:3184    INFO: CPythonInvoker(7, C:\Users\Max Renn\AppData\Roaming\Kodi\addons\script.service.bluray_iso_utils\BIUinfo_builder.py): script successfully run
19:33:26.490 T:4980   DEBUG: Activating window ID: 12005
19:33:26.490 T:4980   DEBUG: ------ Window Deinit (MyPrograms.xml) ------
19:33:26.490 T:4980   DEBUG: ------ Window Init (VideoFullScreen.xml) ------
19:33:26.490 T:4980   DEBUG: CGUIWindowManager::PreviousWindow: Deactivate
19:33:26.490 T:4980   DEBUG: ------ Window Deinit (VideoFullScreen.xml) ------
19:33:26.493 T:3184 WARNING: CPythonInvoker(7, C:\Users\Max Renn\AppData\Roaming\Kodi\addons\script.service.bluray_iso_utils\BIUinfo_builder.py): the python script "C:\Users\Max Renn\AppData\Roaming\Kodi\addons\script.service.bluray_iso_utils\BIUinfo_builder.py" has left several classes in memory that we couldn't clean up. The classes include: class XBMCAddon::xbmcg...
19:33:26.493 T:3184    INFO: Python script stopped
19:33:26.493 T:3184   DEBUG: Thread LanguageInvoker 3184 terminating

Is this at all possible?

Thanks in advance!
@Wimpie

I have no idea what "PyXBMCt build window" is (I certainly didn't make any "build windows"), and and I never used xbmcgui.getCurrentWindowDialogId(). But from what I see your script works normally (albeit not as expected) because both xbmc.executebuiltin and xbmc.Player().play are non-blocking functions so your sctipt exits as soon as they executed.

As I understand, you need to temporarily close your PyXBMCt-based dialog, play some file and then restore the dialog when playback is finished. This can be done by not allowing your script to exit. Below is an over-simplified example (so use it with caution as it lacks important parts that are not relevant to your question):

Code:
import xbmc
import pyxbmct


class MyDialog(pyxbmct.AddonDialogWindow):
    def __init__(self):
        self._monitor = xbmc.Monitor()
        self._player = xbmc.Player()
        
    def play(self, path):
        self._player.play(path)
        xbmc.sleep(200)  # Wait for the player to start, adjust the timeout if necessary
        self.close()
        while self._player.isPlaying():
            if self._monitor.waitForAbort(1):
                raise SystemExit
        self.doModal()
Thanks! It works!!
How can I execute script from ./storage/downloads/script.sh on button press? I am not very good with python so can you give me some example?

Thanks in advance!
(2017-04-23, 11:55)Deso Wrote: [ -> ]How can I execute script from ./storage/downloads/script.sh on button press? I am not very good with python so can you give me some example?

Thanks in advance!

While it is possible to run an external script via subprocess.call, in case of Python scripts it is not a good practice. It is better to import "business logic" from the scripts and run necessary functions/methods from your code.
Roman thanks for reply
I will check for "business logic".
I have function:
def runShellScript():
subprocess.call(['./storage/downloads/curl.sh'])
and button
self.button = pyxbmct.Button('Lights')
self.placeControl(self.button, 8, 3)
but don't know how to execute function on button press.
(2017-04-23, 14:28)Deso Wrote: [ -> ]but don't know how to execute function on button press.

Have you actually read PyXBMCt documentation? Because this question is covered there. If you think that the documentation lacks some information, I'm open to suggestions.
Yes Roman, I read it. The problem is in my python knowledge not in documentation I think. I try with "self.connect(self.button, self.runShellScript)" but receive error.
Can you write it for me?
Roman,

I use very much .setEnabled() & .setVisible() on the controls with PyXBMCt .

Almost all work as expected, but .setEnabled() does not work with any of my textbox controls (I can't disable/gray the textbox). It does work with the other controls.

Can you confirm that this is a bug, or that I am doing something wrong?

Thanks
(2017-04-23, 17:32)Deso Wrote: [ -> ]Yes Roman, I read it. The problem is in my python knowledge not in documentation I think. I try with "self.connect(self.button, self.runShellScript)" but receive error.
Can you write it for me?

Sorry, but I don't write code for anyone. I may show some non-obvious tricks, but that's all. I don't do Python 101. I'd recommend you to improve your Python a bit more, because blind copy-pasting without understanding won't do you any good. I'm not an IT guy and learned Python from scratch all by myself, so it's not an impossible task.
(2017-04-23, 20:48)Wimpie Wrote: [ -> ]Roman,

I use very much .setEnabled() & .setVisible() on the controls with PyXBMCt .

Almost all work as expected, but .setEnabled() does not work with any of my textbox controls (I can't disable/gray the textbox). It does work with the other controls.

Can you confirm that this is a bug, or that I am doing something wrong?

Thanks

Just for clarity: .setEnabled() & .setVisible() are provided by Kodi's xbmggui module, not by PyXBMCt. And .setEnabled() works as intended because information controls, like labels and textboxes, do not have "enabled/disabled" state. Users cannot interact with a textbox, they can only look at it, so enabling/disabling a textbox does not make much sense. .setEnabled() is used for interactive controls (those that require some user interaction, like buttons and such) to prevent accidental triggering those controls when it is not desirable.
(2017-04-24, 08:46)Roman_V_M Wrote: [ -> ]
(2017-04-23, 20:48)Wimpie Wrote: [ -> ]I use very much .setEnabled() & .setVisible() on the controls with PyXBMCt .

Almost all work as expected, but .setEnabled() does not work with any of my textbox controls (I can't disable/gray the textbox). It does work with the other controls.

Can you confirm that this is a bug, or that I am doing something wrong?

Just for clarity: .setEnabled() & .setVisible() are provided by Kodi's xbmggui module, not by PyXBMCt. And .setEnabled() works as intended because information controls, like labels and textboxes, do not have "enabled/disabled" state.

Roman,

Thank you for your explanation. It sounds very logical, however... I think you are wrong.

I am atm able to use .setEnabled() on a label. It does 'gray out' if I do a .setEnabled(False).

A textbox inherits the methods from control (just like the label), if you look at the textbox docs on https://codedocs.xyz/xbmc/xbmc/group__py...xtbox.html then you see that the .setEnabled() method is available for this control.

(2017-04-24, 08:46)Roman_V_M Wrote: [ -> ]Users cannot interact with a textbox, they can only look at it, so enabling/disabling a textbox does not make much sense. .setEnabled() is used for interactive controls (those that require some user interaction, like buttons and such) to prevent accidental triggering those controls when it is not desirable.

While users can't interact with textboxes or labels, being able to 'disable' them gives a much cleaner UI look. This is the reason I would like to 'gray out' those controls.

Anyway, most likely this bug sits in 'core kodi' (over which, I assume, you have no control...).
Roman,

I noticed that as I added controls to my addon the startup time gets longer and longer. Atm my addon needs about 8 seconds between start (user clicks) and showing the addon window.

I have now 81 labels, 67 buttons and a few other controls. This would probably double by the time it's finished.

Is there some way I can speed this up or display a splash window so the user knows he has to wait a bit?

Thanks!
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