xbmcgui dialog.domodal contol buttons with kodi remote control
#1
Hello,

i´ve made a radio script addon with I2C SI4703 radiomodule. All works fine with touchscreen,
but if i try to control it with kodi remote nothing happens. Neither the buttonfocus
changes nor any button ist pressed.

best regards
Martin
Reply
#2
(2017-01-03, 23:52)maral Wrote: Hello,

i´ve made a radio script addon with I2C SI4703 radiomodule. All works fine with touchscreen,
but if i try to control it with kodi remote nothing happens. Neither the buttonfocus
changes nor any button ist pressed.

best regards
Martin

Did you set the default control focus for the window? If you have no default focus set then the remote or any other non touch input will not know what to move to, to focus. You also need to set the directional focus for each control you want the user to access. onleft, onright, ondown, onup. If you share your code it will be easier to provide a more accurate answer.
Reply
#3
thank you for the hints

i´ve seen such focus things, but found no example how to use.
my addon ist very simple. It has some station buttons save settings etc.

here ist the code (my first python programm, and my first addon - maybe somethings could be done better)

Code:
# -*- coding: iso-8859-1 -*-
import sys
import os
import xbmc
import xbmcaddon
import xbmcgui
import pickle


addonW = 1280
addonH = 720

volume_buttons_x = 1100
volume_buttons_y = 600
TEXT_ALIGN_CENTER_X = 2

stationx =  50
stationy = 400

freq = 87.00;

rdspi  =   "/storage/wiringPi/RdSpi/rdspi "
rdtune =   "tune "
rdvolume = "volume "

#plugin.audio.radiotuner  ML 2016
#addon = xbmcaddon.Addon(id = "script.audio.radiotuner")
addon       = xbmcaddon.Addon()
addonname   = addon.getAddonInfo('name')


stations=[['RLW Hamm',105.00],['WDR2',99.20],['WDR2-2',93.25],['WDR1Live',106.75],['WDR3',97.00],['WDR4',101.30]]

settings={}
settings["Volume"]=5
settings["Station"]=1


#get path
mediaPath = os.path.join(addon.getAddonInfo('path'),'resources') + '/'
addonpath = os.path.join(addon.getAddonInfo('path')) + '/'


#RadioReceiver as GUI Program
#modal
class FMReceiver(xbmcgui.WindowDialog):

    def __init__(self):
        global freq,stations,settings

        self.w = addonW
        self.h = addonH
        self.background=xbmcgui.ControlImage(0, 0, self.w, self.h, mediaPath + "background.png")
        self.addControl(self.background)

        self.frequenzlabel=xbmcgui.ControlLabel (380, 150, 500, 75, 'Frequenz',alignment=TEXT_ALIGN_CENTER_X,textColor='0xf000fF00', font='WeatherTemp', angle=0)
        self.addControl(self.frequenzlabel)

        self.label1=xbmcgui.ControlLabel (100, 600, 500, 75, '----', angle=0)
        self.addControl(self.label1)

#edit don´t work
#        self.edit1 =xbmcgui.ControlEdit (500, 100, 166, 107, 'Status',textColor='0xf000fF00',font='WeatherTemp',
#                                                                    focusTexture=mediaPath + 'stationp.png',
#                                                                    noFocusTexture=mediaPath + 'station.png')
#        self.addControl(self.edit1)
#        self.edit1.setText('xy')

#textbox don´t work
#        self.textbox = xbmcgui.ControlTextBox(100, 250, 300, 300, textColor='0xFFFFFFFF')
#        self.addControl(self.textbox)
        
        # Home button
        self.button_home=xbmcgui.ControlButton(0,0, 83, 83,
                                                "",
                                                "floor_buttonFO.png",
                                                "floor_button.png",
                                                0,
                                                0)
        self.addControl(self.button_home)
        self.addControl(xbmcgui.ControlImage(0, 0, 83, 83,
                                                mediaPath + "icon_home.png"))


        # Volume up button
        self.button_volume_up=xbmcgui.ControlButton(volume_buttons_x - 70,
                                                volume_buttons_y,
                                                70,70,
                                                '',
                                                mediaPath + 'volume-up2.png',
                                                mediaPath + 'volume-up.png',
                                                0,
                                                0,
                                                alignment=TEXT_ALIGN_CENTER_X)
        self.addControl(self.button_volume_up)
        self.setFocus(self.button_volume_up)

        # Volume down button
        self.button_volume_down=xbmcgui.ControlButton(volume_buttons_x,
                                                volume_buttons_y,
                                                70,70,
                                                '',
                                                mediaPath + 'volume-down2.png',
                                                mediaPath + 'volume-down.png',
                                                0,
                                                0,
                                                alignment=TEXT_ALIGN_CENTER_X)
        self.addControl(self.button_volume_down)
        self.setFocus(self.button_volume_down)

        # Tune up button
        self.button_tune_up=xbmcgui.ControlButton(900,150,
                                                166,107,
                                                'Tune up',
                                                mediaPath + 'next.png',
                                                mediaPath + 'next_focus.png',
                                                0,
                                                0,
                                                alignment=TEXT_ALIGN_CENTER_X)
        self.addControl(self.button_tune_up)

        # Tune down button
        self.button_tune_down=xbmcgui.ControlButton(200,150,
                                                166,107,
                                                'Tune Down',
                                                mediaPath + 'prev.png',
                                                mediaPath + 'prev_focus.png',
                                                0,
                                                0,
                                                alignment=TEXT_ALIGN_CENTER_X)
                                                
        self.addControl(self.button_tune_down)

        self.button_set=xbmcgui.ControlButton(800,600,
                                        166,107,
                                        '',
                                        mediaPath + 'settings.png',
                                        mediaPath + 'settings_focus.png',
                                        0,
                                        0,
                                        alignment=TEXT_ALIGN_CENTER_X)
        self.addControl(self.button_set)

        
        for i in range(len(stations)):
                                                
            # Station 1 button
            if i==0:
                self.button_station_1=xbmcgui.ControlButton(stationx,stationy,
                                                        166,107,
                                                        stations[i][0],
                                                        mediaPath + 'station.png',
                                                        mediaPath + 'stationp.png',
                                                        0,
                                                        0,
                                                        alignment=TEXT_ALIGN_CENTER_X)
                self.addControl(self.button_station_1)

            # Station 2 button
            if i==1:
                self.button_station_2=xbmcgui.ControlButton(stationx+200,stationy,
                                                        166,107,
                                                        stations[i][0],
                                                        mediaPath + 'station.png',
                                                        mediaPath + 'stationp.png',
                                                        0,
                                                        0,
                                                        alignment=TEXT_ALIGN_CENTER_X)
                self.addControl(self.button_station_2)

            # Station 3 button
            if i==2:
                self.button_station_3=xbmcgui.ControlButton(stationx+400,stationy,
                                                        166,107,
                                                        stations[i][0],
                                                        mediaPath + 'station.png',
                                                        mediaPath + 'stationp.png',
                                                        0,
                                                        0,
                                                        alignment=TEXT_ALIGN_CENTER_X)
                self.addControl(self.button_station_3)
        
            # Station 4 button
            if i==3:
                self.button_station_4=xbmcgui.ControlButton(stationx+600,stationy,
                                                        166,107,
                                                        stations[i][0],
                                                        mediaPath + 'station.png',
                                                        mediaPath + 'stationp.png',
                                                        0,
                                                        0,
                                                        alignment=TEXT_ALIGN_CENTER_X)
                self.addControl(self.button_station_4)

            # Station 5 button
            if i==4:
                self.button_station_5=xbmcgui.ControlButton(stationx+800,stationy,
                                                        166,107,
                                                        stations[i][0],
                                                        mediaPath + 'station.png',
                                                        mediaPath + 'stationp.png',
                                                        0,
                                                        0,
                                                        alignment=TEXT_ALIGN_CENTER_X)
                self.addControl(self.button_station_5)

            # Station 6 button
            if i==5:
                self.button_station_6=xbmcgui.ControlButton(stationx+1000,stationy,
                                                        166,107,
                                                        stations[i][0],
                                                        mediaPath + 'station.png',
                                                        mediaPath + 'stationp.png',
                                                        0,
                                                        0,
                                                        alignment=TEXT_ALIGN_CENTER_X)
                self.addControl(self.button_station_6)
            
            
        self.setFocus(self.button_station_1)
        loadsettings(self)        
        setvolume(self,settings["Volume"])    
        loadstations(self)
        
        

        
    def onControl(self, controlID):
        
        global freq,stations,settings
        
        # HOME button
        if controlID == self.button_home:
            strWndFnc = "XBMC.ActivateWindow(10000)"
            xbmc.executebuiltin(strWndFnc)
            self.close()

        if controlID == self.button_volume_up:
            if settings["Volume"]<10:
                settings["Volume"]+=1;
            setvolume(self,settings["Volume"])    
        
        # Volume Down
        if controlID == self.button_volume_down:
            if settings["Volume"]>1:
                settings["Volume"]-=1;
            setvolume(self,settings["Volume"])    

        # Tune Up
        if controlID == self.button_tune_up:
            freq=freq+0.05
            setfrequenz(self,freq)

        # Tune Down
        if controlID == self.button_tune_down:
            freq=freq-0.05
            setfrequenz(self,freq)
            
        # Save Settings
        if controlID == self.button_set:
            #Frequenz des aktuelle Stationsbuttons speichern
            stations[settings["Station"]][1]=freq
            kb = xbmc.Keyboard('default', 'heading', True)
            #kb.setDefault(stations[settings["Station"]][0])
            print stations[settings["Station"]][0]
            text=stations[settings["Station"]][0]
            kb.setDefault(text)
            kb.setHiddenInput(False)
            kb.doModal()
            if (kb.isConfirmed()):
                text = kb.getText()
                print text
                stations[settings["Station"]][0]=text
            savestations(self)
            loadstations(self)
            
        # Station 1
        if controlID == self.button_station_1:
            freq = stations[0][1]
            settings["Station"]=0
            setfrequenz(self,freq)

        # Station 2
        if controlID == self.button_station_2:
            freq = stations[1][1]
            settings["Station"]=1
            setfrequenz(self,freq)

        # Station 3
        if controlID == self.button_station_3:
            freq = stations[2][1];
            settings["Station"]=2
            setfrequenz(self,freq)

        # Station 4
        if controlID == self.button_station_4:
            freq = stations[3][1];
            settings["Station"]=3            
            setfrequenz(self,freq)

        # Station 5
        if controlID == self.button_station_5:
            freq = stations[4][1];
            settings["Station"]=4            
            setfrequenz(self,freq)

        # Station 6
        if controlID == self.button_station_6:
            freq = stations[5][1];
            settings["Station"]=5            
            setfrequenz(self,freq)

#        if controlID == self.edit1:
#            xbmcgui.Dialog().ok("Edit1")

            


def setvolume(self,_vol):
    s2 = rdspi + rdvolume + "%d" % _vol
    self.label1.setLabel(s2)
    os.system(s2)

            
def setfrequenz(self,_frequenz):
    freq = _frequenz
    s1="%.2f MHz" % freq
    self.frequenzlabel.setLabel(s1)
    s2 = rdspi + rdtune + "%.2f" % freq
    self.label1.setLabel(s2)
    os.system(s2)
                

def savestations(self):
    self.label1.setLabel(addonpath + "stations")
    f = open(addonpath + "stations","wb")
    pickle.dump(stations,f)
    f.close();


def loadstations(self):
    global stations
    f = open(addonpath + "stations","rb")
    stations=pickle.load(f)
    f.close();
    if settings["Station"]==0:
        self.setFocus(self.button_station_1)
        self.button_station_1.setLabel(stations[0][0])
        freq = stations[0][1];
        setfrequenz(self,freq)
    if settings["Station"]==1:
        self.setFocus(self.button_station_2)
        self.button_station_2.setLabel(stations[1][0])
        freq = stations[1][1];
        setfrequenz(self,freq)
    if settings["Station"]==2:
        self.setFocus(self.button_station_3)
        self.button_station_3.setLabel(stations[2][0])
        freq = stations[2][1];
        setfrequenz(self,freq)
    if settings["Station"]==3:
        self.setFocus(self.button_station_4)
        self.button_station_2.setLabel(stations[3][0])            
        freq = stations[3][1];
        setfrequenz(self,freq)
    if settings["Station"]==4:
        self.setFocus(self.button_station_5)
        self.button_station_5.setLabel(stations[4][0])            
        freq = stations[4][1];
        setfrequenz(self,freq)
    if settings["Station"]==5:
        self.setFocus(self.button_station_6)
        self.button_station_6.setLabel(stations[5][0])            
        freq = stations[5][1];
        setfrequenz(self,freq)
    

def savesettings():  
    f = open(addonpath + "settings","wb")
    pickle.dump(settings,f)
    f.close();


def loadsettings(self):
    global settings
    f = open(addonpath + "settings","rb")
    settings=pickle.load(f)
    f.close();

    

#Hello World test
line1 = "Radioreceiver"
line2 = "ML"
line3 = "Using Python"

#xbmcgui.Dialog().ok(addonname, line1, line2, line3)

# Start the Addon
dialog = FMReceiver()
dialog.doModal()
savesettings()
del dialog
del addon
Reply
#4
I believe since you are not using xml. You want setFocusId or setfocus to set the default focus and then controlUp/down/left/right to set the navigation controls. Of you look at the documentation for controls they have those 4 controls for each item. Basically you pass the control you want to target as the parameter. Express. Self.button.controlUp(button2)
Reply
#5
thank you very much

now it works all as expected.
Reply
#6
(2017-01-05, 23:20)maral Wrote: thank you very much

now it works all as expected.

You are welcome
Reply

Logout Mark Read Team Forum Stats Members Help
xbmcgui dialog.domodal contol buttons with kodi remote control0