Something I forgot to mention is that you still need to grab the current active window id before showing the dialog. Assuming you want to do something similar for a service addon you can add this inside your service loop:
Code:
import xbmc,xbmcgui,json
while........
current_window = xbmc.executeJSONRPC('{"jsonrpc":"2.0","id":1,"method":"GUI.GetProperties","params":{"properties":["currentwindow"]}}')
window_id = json.loads(current_window)["result"]["currentwindow"]["id"]
lat123 = OverlayText(window_id)
try: lat123.show()
except: pass
xbmc.sleep(200)
The modified class is:
Code:
class OverlayText(object):
def __init__(self,windowid):
self.showing = False
self.window = xbmcgui.Window(windowid)
viewport_w, viewport_h = self._get_skin_resolution()
font_max = 'font13'
font_min = 'font10'
origin_x = int(float(viewport_w)/1.3913)
origin_y = int(float(viewport_h)/8.0)
window_w = int(float(viewport_w)/3.7647)
window_h = int(float(viewport_h)/2.5714)
acelogo_w = int(float(window_w)/8.5)
acelogo_h = int(float(window_w)/11.0)
text_lat = int(float(window_w)/15)
text_w = int(float(window_w)/1.7)
text_h = int(float(window_h)/14)
fst_setting = int(float(window_h)/3.5)
fst_stat_setting = int(float(window_h)/1.4)
#main window
self._background = xbmcgui.ControlImage(origin_x, origin_y, window_w, window_h, "")
self._acestreamlogo = xbmcgui.ControlImage(origin_x + int(float(window_w)/11.3), origin_y + int(float(window_h)/14), acelogo_w, acelogo_h, "")
self._supseparator = xbmcgui.ControlImage(origin_x, origin_y + int(float(viewport_h)/12.176), window_w-10, 1, "")
self._botseparator = xbmcgui.ControlImage(origin_x, origin_y + window_h - 30, window_w-10, 1, "")
self._title = xbmcgui.ControlLabel(origin_x+int(float(window_w)/3.4), origin_y + text_h, window_w - 140, text_h, "teste", font=font_max, textColor='0xFFEB9E17')
self._total_stats_label = xbmcgui.ControlLabel(origin_x+int(float(window_h)/1.72), origin_y + int(float(window_h)/1.6), int(float(window_w)/1.7), 20, "teste", font=font_min, textColor='0xFFEB9E17')
#labels
self._action = xbmcgui.ControlLabel(origin_x + text_lat, origin_y + fst_setting, int(float(text_w)*1.6), text_h, "teste" + ' N/A', font=font_min)
self._download = xbmcgui.ControlLabel(origin_x + text_lat, origin_y + fst_setting + text_h, int(float(text_w)*1.6), text_h, "teste" + ' N/A', font=font_min)
self._upload = xbmcgui.ControlLabel(origin_x + text_lat, origin_y + fst_setting + 2*text_h, text_w, text_h, "teste" + ' N/A', font=font_min)
self._seeds = xbmcgui.ControlLabel(origin_x + text_lat, origin_y + fst_setting + 3*text_h, text_w, text_h, "teste" + ' N/A', font=font_min)
self._total_download = xbmcgui.ControlLabel(origin_x + text_lat, origin_y + fst_stat_setting, text_w, text_h, "teste" + ' N/A', font=font_min)
self._total_upload = xbmcgui.ControlLabel(origin_x + text_lat, origin_y + fst_stat_setting + text_h, text_w, text_h, "teste" + ' N/A', font=font_min)
self._percent_value = xbmcgui.ControlLabel(origin_x+int(float(window_h)/1.05), origin_y + fst_setting, text_w, text_h,'N/A', font=font_min)
def show(self):
self.showing=True
self.window.addControl(self._background)
self.window.addControl(self._acestreamlogo)
self.window.addControl(self._supseparator)
self.window.addControl(self._botseparator)
self.window.addControl(self._title)
self.window.addControl(self._action)
self.window.addControl(self._download)
self.window.addControl(self._upload)
self.window.addControl(self._seeds)
self.window.addControl(self._total_stats_label)
self.window.addControl(self._total_download)
self.window.addControl(self._total_upload)
self.window.addControl(self._percent_value)
def hide(self):
self.showing=False
self.window.removeControl(self._total_download)
self.window.removeControl(self._total_upload)
self.window.removeControl(self._percent_value)
self.window.removeControl(self._title)
self.window.removeControl(self._action)
self.window.removeControl(self._download)
self.window.removeControl(self._upload)
self.window.removeControl(self._seeds)
self.window.removeControl(self._total_stats_label)
self.window.removeControl(self._acestreamlogo)
self.window.removeControl(self._supseparator)
self.window.removeControl(self._botseparator)
self.window.removeControl(self._background)
def set_information(self,engine_data):
if self.showing == True:
self._action.setLabel(str(translate(50001)) + ' ' + engine_data["action"])
self._percent_value.setLabel(engine_data["percent"])
self._download.setLabel(str(translate(50002))+ ' ' + engine_data["download"])
self._upload.setLabel(str(translate(50003)) + ' ' + engine_data["upload"])
self._seeds.setLabel(str(translate(50004)) + ' ' + engine_data["seeds"])
self._total_download.setLabel(str(translate(50006)) + ' ' + engine_data["total_download"])
self._total_upload.setLabel(str(translate(50007)) + ' ' + engine_data["total_upload"])
else: pass
def _close(self):
if self.showing:
self.hide()
else:
pass
try:
self.window.clearProperties()
print("OverlayText window closed")
except: pass
#Taken from xbmctorrent
def _get_skin_resolution(self):
import xml.etree.ElementTree as ET
skin_path = xbmc.translatePath("special://skin/")
tree = ET.parse(os.path.join(skin_path, "addon.xml"))
try: res = tree.findall("./res")[0]
except: res = tree.findall("./extension/res")[0]
return int(res.attrib["width"]), int(res.attrib["height"])
This will enable the "dialog" no matter the window id of the current active window. See screenshots below:
If you are willing to follow this route probably a good idea to store the current window in an hidden setting (or something similar) and delete the window if the current active window id differs from the previous one otherwise you'll have a few copies of the same window depending on the window id you're on. This will make browsing kodi slow.
Hope I could help somehow,
Cheers