2017-09-08, 11:20
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.
The new Gui (PyXBMCt Framework) without operation for changing brightness.
Ref Gui
.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