Troubleshooting the window.removeControl command
#1
Hello again, Kodi community. As mentioned in a previous post, I'm developing an add-on that involves a custom overlay. It's almost completely working now, except for one runtime error I get every time I start a video, after reaching 5 seconds in the video ("Error Contents: Control does not exist in window"). Here's the code for addon.py below:
python:

import xbmc, xbmcaddon, xbmcgui, os
ADDON = xbmcaddon.Addon()
addonpath = ADDON.getAddonInfo('path')

class OverlayBackground(object):
   def __init__(self):
      self.showing = False
      self.window = xbmcgui.Window()
      origin_x = 0
      origin_y = 0
      window_w = self.window.getWidth()
      window_h = self.window.getHeight()
      self._background = xbmcgui.ControlImage(origin_x, origin_y, window_w, window_h, os.path.join(addonpath,"resources","skins","default","media","background.png"))
   def show(self):
      self.showing=True
      self.window.addControl(self._background)
   def hide(self):
      self.showing=False
      self.window.removeControl(self._background)
   def _close(self):
      if self.showing:
         self.hide()
      else:
         pass
      try:
         self.window.clearProperties()
      except: pass

if (__name__ == '__main__'):
   monitor = xbmc.Monitor()
   while not monitor.abortRequested():
      if xbmc.Player().isPlaying():
         theOverlay = OverlayBackground()
         if(xbmc.Player().getTime() < 5):
            theOverlay.show()
         else:
            theOverlay.hide()
         xbmc.sleep(1000)

The error came from "self.window.removeControl(self._background)", as mentioned in this paste bin. It seems odd, because I'm sure that the control was added prior to running this command, so I'm not sure what's causing this command to crash the add-on. I would highly appreciate any help I could get in troubleshooting this. Thank you so much! This community is amazing!
Reply
#2
*bump*
Reply
#3
You need to get the ID of the player you are controlling. https://romanvm.github.io/Kodistubs/_mod...ml#Control
Reply
#4
Thanks for the reply! I've been trying to figure out how to implement your answer, but I'm confused at whether the ID of the player is needed or the ID of the control. If it's the former, how should I pass the player's ID to the OverlayBackground instance. If it's the latter, how do I declare the control's ID (like in the init function?) and reference to it when I create the OverlayBackground instance? Any clarification on that would be greatly appreciated.
Reply
#5
P.S. So sorry for all my late replies!
Reply
#6
I found an alternative solution by checking if the window is showing or not before showing or hiding it (no errors anymore):
python:
def show(self):
    if not self.showing:
        self.showing=True
        self.window.addControl(self._background)
def hide(self):
    if self.showing:
       self.showing=False
       self.window.removeControl(self._background)
Thank you so much for your time and help!
Reply

Logout Mark Read Team Forum Stats Members Help
Troubleshooting the window.removeControl command0