pyXBMCt Where is it??
#1
Rainbow 
Hey guys, I want to add a pyXBMCt script but I cannot find this at all. From what I can tell, it used to be part of Gothem? Im new to the whole thing but why dont I have the official Kodi repo? Is it even on it?
Reply
#2
Library addons are not visible in the Kodi Addon Manager (although they used to be and I think it was a mistake to remove this feature). More info about PyXBMCt you can find in this thread: https://forum.kodi.tv/showthread.php?tid=174859 Please carefully read all the available documentation before using PyXBMCt.
Reply
#3
(2017-06-09, 17:21)Roman_V_M Wrote: Library addons are not visible in the Kodi Addon Manager (although they used to be and I think it was a mistake to remove this feature). More info about PyXBMCt you can find in this thread: https://forum.kodi.tv/showthread.php?tid=174859 Please carefully read all the available documentation before using PyXBMCt.

I got it running now. I use one of your demos to do what I want to do but I dont know how to change the label or add a script to it. Its a list window with 5 item choices. I would like to run the script I made for different GPIO actions. I have no idea what im doing outside of that with pyXBMCt. Alot of this stuff is over my head right now.
Reply
#4
You need to learn a bit of python and how to use the module. I won't do it all for you as you'll learn nothing.

Have a read of the documentation. You should get an idea of how to change labels and add actions.

Once you've done that, I will help you link this to your gpio pins.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#5
(2017-06-09, 22:42)el_Paraguayo Wrote: You need to learn a bit of python and how to use the module. I won't do it all for you as you'll learn nothing.

Have a read of the documentation. You should get an idea of how to change labels and add actions.

Once you've done that, I will help you link this to your gpio pins.

Ok, I have it edited to how I want the menu. Im lost as far as how I can controle more GPIO pins though. DO I need to repeat the script for each instance? Ill post my script:

PHP Code:
import xbmcaddon
import xbmcgui
import os
import xbmc
import sys
sys
.path.append('/storage/.kodi/addons/script.module.pyxbmct/lib')
import pyxbmct
# Import PyXBMCt module.
import pyxbmct


_addon 
xbmcaddon.Addon()
_path _addon.getAddonInfo("path")
_check_icon os.path.join(_path"check.png"# Don't decode _path to utf-8!!!


class MultiChoiceDialog(pyxbmct.AddonDialogWindow):
    
def __init__(selftitle=""items=None):
        
super(MultiChoiceDialogself).__init__(title)
        
self.setGeometry(45030044)
        
self.selected = []
        
self.set_controls()
        
self.connect_controls()
        
self.listing.addItems(items or [])
        
self.set_navigation()

    
def set_controls(self):
        
self.listing pyxbmct.List(_imageWidth=15)
        
self.placeControl(self.listing00rowspan=3columnspan=4)
        
self.ok_button pyxbmct.Button("OK")
        
self.placeControl(self.ok_button31)
        
self.cancel_button pyxbmct.Button("Cancel")
        
self.placeControl(self.cancel_button32)

    
def connect_controls(self):
        
self.connect(self.listingself.check_uncheck)
        
self.connect(self.ok_buttonself.ok)
        
self.connect(self.cancel_buttonself.close)

    
def set_navigation(self):
        
self.listing.controlUp(self.ok_button)
        
self.listing.controlDown(self.ok_button)
        
self.ok_button.setNavigation(self.listingself.listingself.cancel_buttonself.cancel_button)
        
self.cancel_button.setNavigation(self.listingself.listingself.ok_buttonself.ok_button)
        if 
self.listing.size():
            
self.setFocus(self.listing)
        else:
            
self.setFocus(self.cancel_button)

    
def check_uncheck(self):
        
list_item self.listing.getSelectedItem()
        if 
list_item.getLabel2() == "checked":
            
list_item.setIconImage("")
            
list_item.setLabel2("unchecked")
        else:
            
list_item.setIconImage(_check_icon)
            
list_item.setLabel2("checked")

    
def ok(self):
        
self.selected = [index for index in xrange(self.listing.size())
                                if 
self.listing.getListItem(index).getLabel2() == "checked"]
        
super(MultiChoiceDialogself).close()

    
def close(self):
        
self.selected = []
        
super(MultiChoiceDialogself).close()

if 
__name__ == "__main__":
    
items = ["Relay {0}".format(i) for i in xrange(111)]
    
dialog MultiChoiceDialog("Activate/deactivate"items)
    
dialog.doModal()
    
xbmcgui.Dialog().notification("Finished""Selected: {0}".format(str(dialog.selected)))
    
del dialog #You need to delete your instance when it is no longer needed
#because underlying xbmcgui classes are not grabage-collected.

sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')

import RPi.GPIO as GPIO

# Set pin number once
RELAY_PIN 18

GPIO
.setmode(GPIO.BCM)

GPIO.setup(RELAY_PINGPIO.OUT)

# read the current state of the pin
current_state GPIO.input(RELAY_PIN)

if 
current_state == GPIO.HIGH:

    
# Pin is on so we should turn off
    
GPIO.output(RELAY_PINGPIO.LOW)
    
state "off"

else:

    
# Pin is off so we should turn on
    
GPIO.output(RELAY_PINGPIO.HIGH)
    
state "on"

# Send notification
xbmcgui.Dialog().notification("Relay""Relay is now {0}!".format(state))

addon       xbmcaddon.Addon()
addonname   addon.getAddonInfo('name')

line1 "Turned on/off a relay"
line2 "Version: " addon.getAddonInfo('version')

os.system("sh /storage/.kodi/addons/relay-addon-kodi-master/relay.sh")

xbmc.executebuiltin('Notification(Relay Addon, The relay was turned on/off,5000,//storage/.kodi/addons/script.relay.master/icon.png)')
#xbmcgui.Dialog().ok(addonname, line1, line2) 
Reply
#6
I'll see if I can take a look at this tonight for you.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#7
(2017-06-12, 17:53)el_Paraguayo Wrote: I'll see if I can take a look at this tonight for you.

Thank you. I really do appreciate it.
Reply
#8
Try this:
Code:
import xbmcaddon
import xbmcgui
import os
import xbmc
import sys
sys.path.append('/storage/.kodi/addons/script.module.pyxbmct/lib')
import pyxbmct

sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
import RPi.GPIO as GPIO

RELAYS = [("Relay 1", 13),
          ("Relay 2", 18),
          ("Relay 3", 22),
          ("Relay 4", 25)]


_addon = xbmcaddon.Addon()
_path = _addon.getAddonInfo("path")
_check_icon = os.path.join(_path, "check.png") # Don't decode _path to utf-8!!!


class MultiChoiceDialog(pyxbmct.AddonDialogWindow):
    def __init__(self, title="", items=None):
        super(MultiChoiceDialog, self).__init__(title)
        GPIO.setmode(GPIO.BCM)
        self.item_labels = [x[0] for x in items]
        self.item_pins = [x[1] for x in items]
        GPIO.setup(self.item_pins, GPIO.OUT)
        self.setGeometry(450, 300, 4, 4)
        self.selected = []
        self.set_controls()
        self.connect_controls()
        self.listing.addItems(self.item_labels or [])
        self.get_initial_state()
        self.set_navigation()

    def get_initial_state(self):
        for index, pin in enumerate(self.item_pins):
            if GPIO.input(pin):
                item = self.listing.getListItem(index)
                self.toggle_relay(item, update=False)

    def set_controls(self):
        self.listing = pyxbmct.List(_imageWidth=15)
        self.placeControl(self.listing, 0, 0, rowspan=3, columnspan=4)
        self.ok_button = pyxbmct.Button("Finished")
        self.placeControl(self.ok_button, 3, 1, columnspan=2)

    def connect_controls(self):
        self.connect(self.listing, self.toggle_relay)
        self.connect(self.ok_button, self.ok)

    def set_navigation(self):
        self.listing.controlUp(self.ok_button)
        self.listing.controlDown(self.ok_button)
        self.ok_button.setNavigation(self.listing, self.listing, self.ok_button, self.ok_button)
        if self.listing.size():
            self.setFocus(self.listing)
        else:
            self.setFocus(self.cancel_button)

    def toggle_relay(self, item=None, update=True):

        if item is None:
            list_item = self.listing.getSelectedItem()
            pos = self.listing.getSelectedPosition()
        else:
            list_item = item
            pos = -1

        if list_item.getLabel2() == "checked":
            list_item.setIconImage("")
            list_item.setLabel2("unchecked")
            if update and pos >= 0:
                GPIO.output(self.item_pins[pos], GPIO.LOW)
        else:
            list_item.setIconImage(_check_icon)
            list_item.setLabel2("checked")
            if update and pos >= 0:
                GPIO.output(self.item_pins[pos], GPIO.HIGH)

    def ok(self):
        super(MultiChoiceDialog, self).close()


if __name__ == "__main__":
    dialog = MultiChoiceDialog("Activate/deactivate", RELAYS)
    dialog.doModal()
    del dialog #You need to delete your instance when it is no longer needed

If you look near the top, you'll see a variable called RELAYS. This is where you define your relays. Each item in the list is a "tuple": the first item is the name of the relay (i.e what shows on the screen), the second item is the GPIO pin number.

When the script runs, it will check which relays are already on and will set the "checked" flag accordingly.

Clicking on an item toggles the relay on and off.

Click "Finished" when you're done.

Let me know if it works. I've done it on my laptop so can't test it.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#9
(2017-06-12, 20:06)el_Paraguayo Wrote: Try this:
Code:
import xbmcaddon
import xbmcgui
import os
import xbmc
import sys
sys.path.append('/storage/.kodi/addons/script.module.pyxbmct/lib')
import pyxbmct

sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
import RPi.GPIO as GPIO

RELAYS = [("Relay 1", 13),
          ("Relay 2", 18),
          ("Relay 3", 22),
          ("Relay 4", 25)]


_addon = xbmcaddon.Addon()
_path = _addon.getAddonInfo("path")
_check_icon = os.path.join(_path, "check.png") # Don't decode _path to utf-8!!!


class MultiChoiceDialog(pyxbmct.AddonDialogWindow):
    def __init__(self, title="", items=None):
        super(MultiChoiceDialog, self).__init__(title)
        GPIO.setmode(GPIO.BCM)
        self.item_labels = [x[0] for x in items]
        self.item_pins = [x[1] for x in items]
        GPIO.setup(self.item_pins, GPIO.OUT)
        self.setGeometry(450, 300, 4, 4)
        self.selected = []
        self.set_controls()
        self.connect_controls()
        self.listing.addItems(self.item_labels or [])
        self.get_initial_state()
        self.set_navigation()

    def get_initial_state(self):
        for index, pin in enumerate(self.item_pins):
            if GPIO.input(pin):
                item = self.listing.getListItem(index)
                self.toggle_relay(item, update=False)

    def set_controls(self):
        self.listing = pyxbmct.List(_imageWidth=15)
        self.placeControl(self.listing, 0, 0, rowspan=3, columnspan=4)
        self.ok_button = pyxbmct.Button("Finished")
        self.placeControl(self.ok_button, 3, 1, columnspan=2)

    def connect_controls(self):
        self.connect(self.listing, self.toggle_relay)
        self.connect(self.ok_button, self.ok)

    def set_navigation(self):
        self.listing.controlUp(self.ok_button)
        self.listing.controlDown(self.ok_button)
        self.ok_button.setNavigation(self.listing, self.listing, self.ok_button, self.ok_button)
        if self.listing.size():
            self.setFocus(self.listing)
        else:
            self.setFocus(self.cancel_button)

    def toggle_relay(self, item=None, update=True):

        if item is None:
            list_item = self.listing.getSelectedItem()
            pos = self.listing.getSelectedPosition()
        else:
            list_item = item
            pos = -1

        if list_item.getLabel2() == "checked":
            list_item.setIconImage("")
            list_item.setLabel2("unchecked")
            if update and pos >= 0:
                GPIO.output(self.item_pins[pos], GPIO.LOW)
        else:
            list_item.setIconImage(_check_icon)
            list_item.setLabel2("checked")
            if update and pos >= 0:
                GPIO.output(self.item_pins[pos], GPIO.HIGH)

    def ok(self):
        super(MultiChoiceDialog, self).close()


if __name__ == "__main__":
    dialog = MultiChoiceDialog("Activate/deactivate", RELAYS)
    dialog.doModal()
    del dialog #You need to delete your instance when it is no longer needed

If you look near the top, you'll see a variable called RELAYS. This is where you define your relays. Each item in the list is a "tuple": the first item is the name of the relay (i.e what shows on the screen), the second item is the GPIO pin number.

When the script runs, it will check which relays are already on and will set the "checked" flag accordingly.

Clicking on an item toggles the relay on and off.

Click "Finished" when you're done.

Let me know if it works. I've done it on my laptop so can't test it.

You are awesome!!! Works as advertised!! Man, I have alot to learn lol. Thank you so much!
Reply
#10
My pleasure. Happy to help.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply

Logout Mark Read Team Forum Stats Members Help
pyXBMCt Where is it??0