• 1
  • 2
  • 3
  • 4(current)
  • 5
  • 6
  • 27
Release PyXBMCt: a Python framework for simple creating UI for XBMC addons
#46
(2014-03-17, 14:45)Roman_V_M Wrote:
(2014-03-17, 14:39)Aweponken Wrote: So the problem is, how do I execute python code in a PHP based plugin? Tongue

Not sure if I understand, but what is "PHP based plugin"? XBMC does not support PHP and all plugins are written in Python.
Oh, haha I got a bit carried away and the code on the mainpage is under the PHP-tag instead of the Code-tag. Made me a bit confused Wink
Reply
#47
So I'm having a few problems getting this to work.
I'm trying to make a local version work.
My plugin contains the following items:
The latest version of the pyxbmct folder
icon.png
addon.xml with the following code:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.pyxbmct.demo"
   name="Husvagn Demo"
   version="0.0.1"
   provider-name="Aweponken">
  <requires>
    <import addon="xbmc.python" version="2.1"/>  
  </requires>
  <extension point="xbmc.python.script" library="default.py">
    <provides>executable</provides>
  </extension>
  <extension point="xbmc.addon.metadata">
    <platform>all</platform>
    <summary lang="en">Husvagn Demo</summary>
    <description lang="en">Just a testing demo...</description>
  </extension>
</addon>
default.py containing the following code:
Code:
# Import PyXBMCt module.
from pyxbmct.addonwindow import *

# Create a window instance.
window = AddonDialogWindow('Hello, World!')
# Set window width, height and grid resolution.
window.setGeometry(400, 400, 1, 1)
# Show the created window.
window.doModal()

I've just modified the addon.xml from script.pyxbmct.demo. XBMC can't start the plugin at all. It's kinda weird that I've changed the icon.png to a different picture than the script.pyxbmct.demo but it still shows the "under construction" image, even after reinstall.
Any help?
Reply
#48
(2014-03-17, 17:15)Aweponken Wrote: I've just modified the addon.xml from script.pyxbmct.demo. XBMC can't start the plugin at all. It's kinda weird that I've changed the icon.png to a different picture than the script.pyxbmct.demo but it still shows the "under construction" image, even after reinstall.
Any help?

Please provide a debug log on xbmclogs.com.

As for the icon, XBMC image cache is real PITA.
Reply
#49
(2014-03-17, 14:45)Roman_V_M Wrote:
(2014-03-17, 13:42)phr3n1c Wrote: Hi,

I'm currently using XBCMSwift2 for the basic UI and want to use PyXBMCt for additional windows like modals, notifications and so on.

For testing, I used the code of the example in your first post in this thread but changed the button to start playing the url (mp4):
Code:
self.connect(button, xbmc.PlayMedia(asset['path']))

But as soon as the window is shown, the video starts playing. Is there a way to prevent the automatic start?

Thank you!

You are trying to connect a function call, which is wrong. Please read the Quick Start Guide carefully - such scenario is describe there.

I guess, you're refering to
Code:
self.connect(self.hello_buton, lambda: xbmc.executebuiltin('Notification(Hello %s!, Welcome to PyXBMCt.)' % self.name_field.getText()))

So it should be like this?
Code:
self.connect(button, lambda: xbmc.PlayMedia(asset['path']))

or like this?
Code:
self.connect(button, lambda: xbmc.executebuiltin('xbmc.PlayMedia(%s)' % asset['path']))
Reply
#50
(2014-03-17, 17:26)Roman_V_M Wrote:
(2014-03-17, 17:15)Aweponken Wrote: I've just modified the addon.xml from script.pyxbmct.demo. XBMC can't start the plugin at all. It's kinda weird that I've changed the icon.png to a different picture than the script.pyxbmct.demo but it still shows the "under construction" image, even after reinstall.
Any help?

Please provide a debug log on xbmclogs.com.

As for the icon, XBMC image cache is real PITA.

So I upgraded XBMC to the newest version and:
Here's the log Smile
So now I can't even install it. But the best version to use i Gotham?
Reply
#51
(2014-03-17, 18:26)phr3n1c Wrote: So it should be like this?
Code:
self.connect(button, lambda: xbmc.PlayMedia(asset['path']))

or like this?
Code:
self.connect(button, lambda: xbmc.executebuiltin('xbmc.PlayMedia(%s)' % asset['path']))

As to my knowledge, XBMC Python function xbmc.PlayMedia does not exist.
Reply
#52
(2014-03-17, 18:39)Aweponken Wrote: So I upgraded XBMC to the newest version and:
Here's the log Smile
So now I can't even install it. But the best version to use i Gotham?

Are you sure you're using the newest version? Because Gotham does provide Python API v 2.1. Anyway, try not to install from ZIP but copy your addon to /addons folder of your XBMC profile.
Reply
#53
(2014-03-17, 22:44)Roman_V_M Wrote: Are you sure you're using the newest version? Because Gotham does provide Python API v 2.1. Anyway, try not to install from ZIP but copy your addon to /addons folder of your XBMC profile.
Yes, it tells me I'm running Gotham during startup. So I copied the folder to C:\Program Files (x86)\XBMC\addons. How do I enable it? Or is it supposed to be in the %appdata%\XBMC\userdata\addons_data folder?
Reply
#54
(2014-03-17, 21:34)Roman_V_M Wrote: As to my knowledge, XBMC Python function xbmc.PlayMedia does not exist.

It's working! Here's my code:

Code:
class WindowVideoDetails(AddonDialogWindow):
    def __init__(self, title='test', url=None):
        super(WindowVideoDetails, self).__init__(title)
        self.setGeometry(350, 150, 2, 3)
        label = Label('Video Details', alignment=ALIGN_CENTER)
        self.placeControl(label, 0, 0, columnspan=3)
        button = Button('Close')
        self.placeControl(button, 1, 1)
        self.setFocus(button)
        listitem = xbmcgui.ListItem('Ironman')
        listitem.setInfo('video', {'Title': 'Ironman', 'Genre': 'Science Fiction'})
        self.connect(button, lambda: self._play_video(url, listitem))
        self.connect(ACTION_NAV_BACK, self.close)

    def _play_video(self, url, listitem=None):
        player = xbmc.Player(xbmc.PLAYER_CORE_MPLAYER)
        player.play(url, listitem)
        self.close()
Reply
#55
(2014-03-18, 15:43)Aweponken Wrote: Yes, it tells me I'm running Gotham during startup. So I copied the folder to C:\Program Files (x86)\XBMC\addons. How do I enable it? Or is it supposed to be in the %appdata%\XBMC\userdata\addons_data folder?

Neither. As I said, you need to copy your plugin in \addons folder of your user profile. If addon is already in place, you do not need to enable it explicitly, it should be picked up when XBMC starts.

(2014-03-18, 20:16)phr3n1c Wrote:
(2014-03-17, 21:34)Roman_V_M Wrote: As to my knowledge, XBMC Python function xbmc.PlayMedia does not exist.

It's working! Here's my code:

I'm glad that you've figured this out.Smile
Reply
#56
(2014-03-18, 21:12)Roman_V_M Wrote: Neither. As I said, you need to copy your plugin in \addons folder of your user profile. If addon is already in place, you do not need to enable it explicitly, it should be picked up when XBMC starts.

Ah, I managed to get it working, thank you very much!
As I described before, I'm going to use eight radiobuttons to send a line of code to the terminal. Should I use do the coding with or without OOP?
Reply
#57
(2014-03-19, 10:14)Aweponken Wrote: As I described before, I'm going to use eight radiobuttons to send a line of code to the terminal. Should I use do the coding with or without OOP?

That depends on your preferences. Coding style is completely up to you, as long as it works and supportable.
Reply
#58
(2014-03-19, 12:03)Roman_V_M Wrote: That depends on your preferences. Coding style is completely up to you, as long as it works and supportable.
Oh, okay!
So I'm trying to convert the radiobutton from the demo version.
The original code looks like this:
PHP Code:
def radio_update(self):
        
# Update radiobutton caption on toggle
        
if self.radiobutton.isSelected():
            
self.radiobutton.setLabel('On')
        else:
            
self.radiobutton.setLabel('Off'
And all I've come up with it is:
PHP Code:
def radio_update():
        
# Update radiobutton caption on toggle
        
if radiobutton.isSelected():
            
radiobutton.setLabel('On')
        else:
            
radiobutton.setLabel('Off'
And the old call for the function looked like this:
PHP Code:
self.connect(self.radiobuttonself.radio_update
Should be something like(?):
PHP Code:
window.connect(radiobuttonradio_update
Reply
#59
(2014-03-19, 14:54)Aweponken Wrote:
(2014-03-19, 12:03)Roman_V_M Wrote: That depends on your preferences. Coding style is completely up to you, as long as it works and supportable.
Oh, okay!
So I'm trying to convert the radiobutton from the demo version.
The original code looks like this:

Should be something like(?):
PHP Code:
window.connect(radiobuttonradio_update

This should work, though personally I think that it is not too good that your function refers to an object (radiobutton) from outside (global?) scope. Usually this means bad code style. For good code style your function should communicate with the rest of your program only via its interface, i.e. function call signature and return/yield statement.
If you really don't want to use OOP then it should be something like this:
PHP Code:
def radio_update(radiobutton):
        
# Update radiobutton caption on toggle
        
if radiobutton.isSelected():
            
radiobutton.setLabel('On')
        else:
            
radiobutton.setLabel('Off'
and you need to connect the function call via lambda.
Reply
#60
(2014-03-19, 15:38)Roman_V_M Wrote: This should work, though personally I think that it is not too good that your function refers to an object (radiobutton) from outside (global?) namespace. Usually this means bad code style. For good code style your function should communicate with the rest of your program only via its interface, i.e. function call signature and return/yield statement.
If you really don't want to use OOP then it should be something like this:
PHP Code:
def radio_update(radiobutton):
        
# Update radiobutton caption on toggle
        
if radiobutton.isSelected():
            
radiobutton.setLabel('On')
        else:
            
radiobutton.setLabel('Off'
and you need to connect the function call via lambda.
EDIT:
So I took your advice and I recreated the whole design with OOP(it turned out using a proper python editor made a HUGE difference). I will try implementing the functions of pilight after the weekend, if I manage to get the beta update on Xbian working.
Is there a way to save the state of the radiobuttons? If I turn on a button, close the addon and then relaunch it, the state of the button will be set to Off again.
Reply
  • 1
  • 2
  • 3
  • 4(current)
  • 5
  • 6
  • 27

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