Brightness (Backlight) Change value on PyXBMCt Framework Rpi 7" screen
#1
Hello everyone, I have been trying to integrate my code with the PyXBMC framework, only it is an incomplete work, since the function is not integrated for the change of brightness in it.

.Py Code of the working method.
Code:
import os

        
        
os.system("sudo cat /sys/class/backlight/rpi_backlight/brightness > brightness.txt" )

with open('brightness.txt') as f:
    for i in xrange(1):
        value = f.readline().rstrip()

        if 255 == int(value):
            os.system("echo 25 | sudo tee /sys/class/backlight/rpi_backlight/brightness")
        elif 25 == int(value):
            os.system("echo 50 | sudo tee /sys/class/backlight/rpi_backlight/brightness")
        elif 50 == int(value):
            os.system("echo 100 | sudo tee /sys/class/backlight/rpi_backlight/brightness")
        elif 100 == int(value):
            os.system("echo 150 | sudo tee /sys/class/backlight/rpi_backlight/brightness")
        else:
            os.system("echo 255 | sudo tee /sys/class/backlight/rpi_backlight/brightness")


The new Gui (PyXBMCt Framework) without operation for changing brightness.
Code:
# Import necessary modules
import xbmc
import pyxbmct
import os


class Brt(pyxbmct.AddonDialogWindow):          
            
# Create a window instance.
    def __init__(self, title=''):
        """Class constructor"""
        # Call the base class' constructor.
        super(Brt, self).__init__(title)
        # Set width, height and the grid parameters
        self.setGeometry(700, 400, 5, 3)
        # Call set controls method
        self.set_controls()
        # Connect Backspace button to close our addon.
        self.connect(pyxbmct.ACTION_NAV_BACK, self.close)

        

    def set_controls(self):
        """Set up UI controls"""
        # Image control
        image=pyxbmct.Image('/home/pi/.kodi/addons/script.rpi-backlight/images/bk.jpg', aspectRatio=1)
        self.placeControl(image, 0, 0, rowspan=3, columnspan=3)
        # Text label
        label = pyxbmct.Label('Brightness', alignment=pyxbmct.ALIGN_CENTER)
        self.placeControl(label, 3,0)
        # RadioButton Label
        radiobutton_label = pyxbmct.Label('Back Light', alignment=pyxbmct.ALIGN_CENTER)
        self.placeControl(radiobutton_label, 3, 2)
        # RadioButton
        self.radiobutton = pyxbmct.RadioButton ('On', _alignment=2,font ='font30')
        self.placeControl(self.radiobutton, 4, 2)
        self.connect (self.radiobutton, self.radio_update)
        # Close button
        self.close_button = pyxbmct.Button('Close',shadowColor='0xffffffff',textColor='0xffffffff', noFocusTexture='/home/pi/.kodi/addons/script.rpi-backlight/images/bt.png', focusTexture='/home/pi/.kodi/addons/script.rpi-backlight/images/bt2.png' )
        self.placeControl(self.close_button, 5, 1)
        # Connect close button
        self.connect(self.close_button, self.close)
        # Slider value label
        SLIDER_INIT_VALUE = 255
        self.slider_value = pyxbmct.Label(str(SLIDER_INIT_VALUE), alignment=pyxbmct.ALIGN_CENTER,font ='font30')
        self.placeControl(self.slider_value, 4, 0)
        # Label
        slider_caption = pyxbmct.Label('Changue Value', alignment=pyxbmct.ALIGN_CENTER)
        self.placeControl(slider_caption, 3, 1)
        # Slider
        self.slider = pyxbmct.Slider()
        self.placeControl(self.slider, 4, 1, pad_y=10)
        self.slider.setPercent(SLIDER_INIT_VALUE)
        self.connectEventList([pyxbmct.ACTION_MOVE_LEFT,
                               pyxbmct.ACTION_MOVE_RIGHT,
                               pyxbmct.ACTION_MOUSE_DRAG,
                               pyxbmct.ACTION_MOUSE_LEFT_CLICK],
                              self.slider_update)

    def radio_update(self):
        # Update radiobutton caption on toggle
        if self.radiobutton.isSelected():
            self.radiobutton.setLabel('Off')
        else:
            self.radiobutton.setLabel('On')                

    def slider_update(self):
        # Update slider value label when the slider nib moves
        try:
            if self.getFocus() == self.slider:
                self.slider_value.setLabel('{:.1F}'.format(self.slider.getPercent()))
        except (RuntimeError, SystemError):
            pass    
        
        
# Animation window
    def setAnimation(self, control):
        # Set fade animation for all add-on window controls
        control.setAnimations([('WindowOpen', 'effect=fade start=0 end=200 time=100',),
                                ('WindowClose', 'effect=fade start=100 end=0 time=500',)])

                                
# Show the created window.
if __name__ == '__main__':
    dialog = Brt("Brightness Control")
    dialog.doModal()
    del dialog

Ref Gui

watch gallery
Reply
#2
PyXBMCt topic is here: https://forum.kodi.tv/showthread.php?tid=174859 I'd recommend to discuss all related topics there. Also it is not quite clear what you are trying to accomplish.
Reply
#3
(2017-09-08, 12:36)Roman_V_M Wrote: PyXBMCt topic is here: https://forum.kodi.tv/showthread.php?tid=174859 I'd recommend to discuss all related topics there. Also it is not quite clear what you are trying to accomplish.

The purpose is to be able to change the brightness of the screen by simply sliding the adjuster, without having to do it sequentially as I have in the python code, but I do not know very well how to integrate this method into an interface like I mention.

(sorry for the bad english)
Reply
#4
slider_update method can give you a hint how to read the current slider value. As for applying this value to your hardware, you have to figure it yourself or ask on Pi forums where there's more chance to find people familiar with Pi-specific hardware. Personally I know nothing about that and use my Pi strictly as a player.
Reply

Logout Mark Read Team Forum Stats Members Help
Brightness (Backlight) Change value on PyXBMCt Framework Rpi 7" screen0