Exemplo n.º 1
0
def OK_Dialog(title, msg):
    class OK_Box(xbmcgui.WindowXMLDialog):
        # until now we have a blank window, the onInit function will parse your xml file
        def onInit(self):
            self.colors = themecontrol.ThemeColors()

            self.title = 1
            self.body = 2
            self.okbtn = 5

            self.getControl(self.title).setLabel(title)
            self.setProperty('dhtext', self.colors.dh_color)
            self.setProperty('btnfocus', self.colors.btn_focus)
            self.getControl(self.body).setText(msg)

            xbmc.sleep(100)
            # this puts the focus on the top item of the container
            self.setFocusId(self.getCurrentContainerId())
            self.setFocus(self.getControl(self.okbtn))
            xbmc.executebuiltin("Dialog.Close(busydialog)")

        def onClick(self, controlId):
            if (controlId == self.okbtn):
                self.close()

        def onAction(self, action):
            if action == themecontrol.ACTION_PREVIOUS_MENU or action == themecontrol.ACTION_NAV_BACK:
                self.close()

    ok = OK_Box('Dialog_OK.xml', control.skinModule(), control.skinTheme(), '1080i', title=title, msg=msg)
    ok.doModal()
    del ok
Exemplo n.º 2
0
def YN_Dialog(title, msg, yestext='Yes', notext='No'):
    class YN_Box(xbmcgui.WindowXMLDialog):
        # until now we have a blank window, the onInit function will parse your xml file
        def onInit(self):
            self.colors = themecontrol.ThemeColors()

            self.title = 1
            self.body = 2
            self.yesbtn = 5
            self.nobtn = 6

            self.getControl(self.title).setLabel(title)
            self.setProperty('dhtext', self.colors.dh_color)
            self.setProperty('btnfocus', self.colors.btn_focus)
            self.getControl(self.body).setText(msg)
            self.getControl(self.yesbtn).setLabel(yestext)
            self.getControl(self.nobtn).setLabel(notext)

            xbmc.sleep(100)
            # this puts the focus on the top item of the container
            self.setFocusId(self.getCurrentContainerId())
            self.setFocus(self.getControl(self.nobtn))
            xbmc.executebuiltin("Dialog.Close(busydialog)")

        def onClick(self, controlId):
            if (controlId == self.nobtn):
                self.close()
            if (controlId == self.yesbtn):
                self.close()

        def onAction(self, action):
            if action == themecontrol.ACTION_PREVIOUS_MENU or action == themecontrol.ACTION_NAV_BACK:
                self.close()

    yn = YN_Box('Dialog_YesNo.xml',
                control.skinModule(),
                control.skinTheme(),
                '1080i',
                title=title,
                msg=msg,
                yestext=yestext,
                notext=notext)
    yn.doModal()
    ret = yn.getProperty('btnret')
    del yn
    if ret == 'true':
        return True
    else:
        return False
Exemplo n.º 3
0
def showResult(message, url=None):
    if url:
        imagefile = os.path.join(xbmc.translatePath(PROFILE),
                                 '%s.png' % str(url.split('/')[-1]))
        qrIMG = pyqrcode.create(url)
        qrIMG.png(imagefile, scale=10)
        qr = QRCode("LogViewer_QR.xml",
                    control.skinModule(),
                    control.skinTheme(),
                    '1080i',
                    image=imagefile,
                    text=message)
        qr.doModal()
        del qr
        xbmcvfs.delete(imagefile)
    else:
        from resources.lib.dialogs import ok
        ok.OK_Dialog('Upload Complete', message)
Exemplo n.º 4
0
def ChangelogViewer(cl_text=None):
    class Changelog_Window(xbmcgui.WindowXMLDialog):
        def onInit(self):
            self.colors = themecontrol.ThemeColors()

            self.cl_text = cl_text

            self.skin_text = 102
            self.btn_close = 202

            self.showdialog()

        def showdialog(self):
            self.setProperty('dhtext', self.colors.dh_color)
            self.getControl(self.skin_text).setText(self.cl_text)
            self.setFocusId(self.btn_close)

        def onClick(self, controlId):
            if controlId == self.btn_close:
                self.close()

        def onAction(self, action):
            if action == themecontrol.ACTION_PREVIOUS_MENU or action == themecontrol.ACTION_NAV_BACK:
                self.close()

    changelogfile = os.path.join(control.addonPath, 'changelog.txt')
    r = open(changelogfile)
    cl_text = r.read()
    r.close()
    viewer = Changelog_Window('Changelog.xml',
                              control.skinModule(),
                              control.skinTheme(),
                              '1080i',
                              cl_text=cl_text)
    viewer.doModal()
    del viewer
Exemplo n.º 5
0
def Pair_Dialog():
    class Pair_Window(xbmcgui.WindowXMLDialog):
        # until now we have a blank window, the onInit function will parse your xml file
        def onInit(self):
            self.last_selection = ''
            self.colors = themecontrol.ThemeColors()
            self.open_browser = control.setting('browser.pair')
            if self.open_browser == '' or self.open_browser == 'true':
                self.open_browser = True
            else:
                self.open_browser = False

            self.menu_list = 100
            self.menu = self.getControl(self.menu_list)
            self.browserbtn = 150
            self.OpenButton = self.getControl(self.browserbtn)
            self.OpenButton.setSelected(self.open_browser)
            self.right_pane = 200
            self.content = self.getControl(self.right_pane)

            self.setProperty('dhtext', self.colors.dh_color)
            self.setProperty('mhtext', self.colors.mh_color)
            self.setProperty('mttext', self.colors.mt_color)
            self.setProperty('fttext', self.colors.focus_textcolor)

            menu_items = []
            menu_items.append(control.item(label='Pairing'))
            menu_items.append(control.item(label='Authorize'))
            self.menu.addItems(menu_items)

            self.pairItems = []
            for item in PAIR_LIST:
                the_title = 'Pair for %s' % (item[0].replace('_',
                                                             ' ').capitalize())
                the_item = control.item(label=the_title)
                the_icon = item[2].decode('base64')
                the_item.setArt({'icon': the_icon, 'thumb': the_icon})
                self.pairItems.append(the_item)

            self.authItems = []
            for item in AUTH_LIST:
                the_title = 'Authorize %s' % (item[0].replace(
                    '_', ' ').capitalize())
                the_item = control.item(label=the_title)
                the_icon = item[2].decode('base64')
                the_item.setArt({'icon': the_icon, 'thumb': the_icon})
                self.authItems.append(the_item)

            self.content.addItems(self.pairItems)

            xbmc.sleep(100)
            # this puts the focus on the top item of the container
            self.setFocusId(self.getCurrentContainerId())
            self.setFocus(self.getControl(self.menu_list))
            xbmc.executebuiltin("Dialog.Close(busydialog)")

        def onClick(self, controlId):
            if (controlId == self.browserbtn):
                if self.OpenButton.isSelected():
                    self.open_browser = True
                    control.setSetting('browser.pair', 'true')
                else:
                    self.open_browser = False
                    control.setSetting('browser.pair', 'false')
            elif (controlId == self.right_pane):
                selection = self.content.getListItem(
                    self.content.getSelectedPosition()).getLabel()
                if 'Pair for' in selection:
                    self.pairHandler(selection)
                elif 'Authorize' in selection:
                    self.authHandler(selection)

        def onAction(self, action):
            if action == themecontrol.ACTION_PREVIOUS_MENU or action == themecontrol.ACTION_NAV_BACK:
                self.close()
            elif any(i == action for i in themecontrol.MENU_ACTIONS):
                try:
                    '''
                    self.last_selection is used so the same code does keep running while the mouse is
                    hovering over the same item during movement.
                    '''
                    if (self.getFocusId() > 0):
                        self.setFocusId(self.getFocusId())
                    if self.getFocusId() == self.menu_list:
                        try:
                            selection = self.menu.getListItem(
                                self.menu.getSelectedPosition()).getLabel()
                            if self.last_selection != selection:
                                self.last_selection = selection
                                self.content.reset()
                                if selection == 'Pairing':
                                    self.content.addItems(self.pairItems)
                                elif selection == 'Authorize':
                                    self.content.addItems(self.authItems)
                        except Exception:
                            failure = traceback.format_exc()
                            log_utils.log('F**k, it failed.\n' + failure)
                except Exception:
                    # Nothing has focus in this case, like when just moving the mouse around in general
                    pass

        def pairHandler(self, selection):
            self.close()

            pair_item = re.sub('\[.*?]', '',
                               selection).replace('Pair for ',
                                                  '').replace(' ',
                                                              '_').lower()
            log_utils.log(selection)
            log_utils.log(pair_item)
            for item in PAIR_LIST:
                if str(item[0]) == pair_item:
                    site = item[1]
                    site_name = item[0].replace('_', ' ').capitalize()
                    break

            if self.open_browser:
                check_os = platform()
                if check_os == 'android':
                    xbmc.executebuiltin(
                        'StartAndroidActivity(,android.intent.action.VIEW,,%s)'
                        % (site))
                elif check_os == 'osx':
                    os.system("open " + site)
                else:
                    webbrowser.open(site)
            else:
                try:
                    from resources.lib.dialogs import ok
                    ok.OK_Dialog(
                        '%s Stream Authorization' % (site_name),
                        'Using a device on your network, visit the link below to authorize streams:[CR][CR]%s'
                        % (site))
                except Exception:
                    failure = traceback.format_exc()
                    log_utils.log('Pairing - Exception: \n' + str(failure))
                    return

        def authHandler(self, selection):
            self.close()

            auth_item = re.sub('\[.*?]', '',
                               selection).replace('Authorize ',
                                                  '').replace(' ',
                                                              '_').lower()
            func = None
            for item in AUTH_LIST:
                if str(item[0]) == auth_item:
                    func = item[1]
                    break

            if func is not None:
                xbmc.executebuiltin(func)

    pair = Pair_Window('Pair_Tool.xml', control.skinModule(),
                       control.skinTheme(), '1080i')
    pair.doModal()
    del pair
Exemplo n.º 6
0
def Cache_Dialog():
    class Cache_Window(xbmcgui.WindowXMLDialog):
        # until now we have a blank window, the onInit function will parse your xml file
        def onInit(self):
            self.last_selection = 'base'
            self.colors = themecontrol.ThemeColors()

            self.setProperty('mhtext', self.colors.mh_color)
            self.setProperty('mttext', self.colors.mt_color)
            self.setProperty('dhtext', self.colors.dh_color)
            self.setProperty('dttext', self.colors.dt_color)
            self.setProperty('fttext', self.colors.focus_textcolor)

            self.menu_list = 100
            self.menu = self.getControl(self.menu_list)
            self.header_id = 400
            self.header = self.getControl(self.header_id)
            self.desc_id = 501
            self.desc = self.getControl(self.desc_id)
            self.closebtn = 150
            self.clearbtn = 250

            menu_items = []
            for item in CACHE_LIST:
                the_item = control.item(label=item[0])
                menu_items.append(the_item)
            self.menu.addItems(menu_items)
            self.last_selection = 'Base'
            self.header.setLabel("Clear Base Cache")
            self.desc.setText(control.lang(32648).encode('utf-8'))

            # this puts the focus on the top item of the container
            self.setFocusId(self.getCurrentContainerId())
            self.setFocus(self.getControl(self.menu_list))
            xbmc.executebuiltin("Dialog.Close(busydialog)")

        def onClick(self, controlId):
            if (controlId == self.closebtn):
                self.close()
            elif (controlId == self.clearbtn):
                control.idle()
                from resources.lib.dialogs import yesno
                yes = yesno.YN_Dialog('Cache Tool',
                                      control.lang(32056).encode('utf-8'))
                if not yes:
                    return
                self.close()

                func = None
                for item in CACHE_LIST:
                    if str(item[0]) == self.last_selection:
                        func = item[3]
                        break

                if func is not None:
                    xbmc.executebuiltin(func)

                control.infoDialog(control.lang(32057).encode('utf-8'),
                                   sound=True,
                                   icon='INFO')

        def onAction(self, action):
            if action == themecontrol.ACTION_PREVIOUS_MENU or action == themecontrol.ACTION_NAV_BACK:
                self.close()
            elif any(i == action for i in themecontrol.MENU_ACTIONS):
                try:
                    '''
                    self.last_selection is used so the same code does keep running while the mouse is
                    hovering over the same item during movement.
                    '''
                    if (self.getFocusId() > 0):
                        self.setFocusId(self.getFocusId())
                    '''
                    Moving through the menu, so works to adjust the visibility of labels and buttons in
                    the XML. The property is also used to determine the onclick action of the button.
                    Allowing us to reduce actual code needing to be ran for control of a more or less
                    static XML and Code that most likely will never change once done.
                    '''
                    if self.getFocusId() == self.menu_list:
                        try:
                            selection = self.menu.getListItem(
                                self.menu.getSelectedPosition()).getLabel()
                            if self.last_selection != selection:
                                self.last_selection = selection
                                for item in CACHE_LIST:
                                    if self.last_selection == item[0]:
                                        self.header.setLabel(item[1])
                                        self.desc.setText(
                                            control.lang(
                                                item[2]).encode('utf-8'))
                        except Exception:
                            failure = traceback.format_exc()
                            log_utils.log('F**k, it failed.\n' + failure)
                except Exception:
                    pass

    cwindow = Cache_Window('Cache_Tool.xml', control.skinModule(),
                           control.skinTheme(), '1080i')
    cwindow.doModal()
    del cwindow
Exemplo n.º 7
0
def LogViewer(logfile=None):
    class LogViewver_Window(xbmcgui.WindowXMLDialog):
        # until now we have a blank window, the onInit function will parse your xml file
        def onInit(self):
            self.colors = themecontrol.ThemeColors()

            self.title = 101
            self.msg = 102
            self.scrollbar = 103
            self.upload = 201
            self.kodi = 202
            self.kodiold = 203
            self.addonlog = 204
            self.okbutton = 205

            self.logfile = os.path.join(log_utils.LOG_PATH, logfile)

            self.logmsg = log_utils.readLog(self.logfile)
            self.titlemsg = "%s: %s" % (control.addonName(), logfile)
            self.showdialog()

        def showdialog(self):
            self.setProperty('dhtext', self.colors.dh_color)
            self.getControl(self.title).setLabel(self.titlemsg)
            self.getControl(self.msg).setText(log_utils.highlightText(self.logmsg))
            self.setFocusId(self.scrollbar)

        def onClick(self, controlId):
            if controlId == self.okbutton:
                self.close()
            elif controlId == self.upload:
                self.close()
                upload_check = log_utils.uploadLog(self.logmsg)
                if upload_check[0]:
                    data = 'Post this url or scan QRcode for your log, together with a problem description, in the Bug Report tool: %s' % (upload_check[1])
                    log_utils.showResult(data, upload_check[1])
            elif controlId == self.kodi:
                filename = 'kodi.log'
                self.logfile = os.path.join(log_utils.LOG_PATH, filename)
                self.logmsg = log_utils.readLog(self.logfile)

                if len(self.logmsg) < 10:
                    self.titlemsg = "%s: View Log Error" % control.addonName()
                    self.getControl(self.msg).setText("Log File Does Not Exists Or Is Too Large!")
                else:
                    self.titlemsg = "%s: %s" % (control.addonName(), filename.replace(log_utils.LOG_PATH, ''))
                    self.getControl(self.title).setLabel(self.titlemsg)
                    self.getControl(self.msg).setText(log_utils.highlightText(self.logmsg))
                    self.setFocusId(self.scrollbar)
            elif controlId == self.kodiold:
                filename = 'kodi.old.log'
                self.logfile = os.path.join(log_utils.LOG_PATH, filename)
                self.logmsg = log_utils.readLog(self.logfile)

                if len(self.logmsg) < 10:
                    self.titlemsg = "%s: View Log Error" % control.addonName()
                    self.getControl(self.msg).setText("Log File Does Not Exists!")
                else:
                    self.titlemsg = "%s: %s" % (control.addonName(), filename.replace(log_utils.LOG_PATH, ''))
                    self.getControl(self.title).setLabel(self.titlemsg)
                    self.getControl(self.msg).setText(log_utils.highlightText(self.logmsg))
                    self.setFocusId(self.scrollbar)
            elif controlId == self.addonlog:
                filename = 'atreides.log'
                self.logfile = os.path.join(log_utils.LOG_PATH, filename)
                self.logmsg = log_utils.readLog(self.logfile)

                if len(self.logmsg) < 10:
                    self.titlemsg = "%s: View Log Error" % control.addonName()
                    self.getControl(self.msg).setText("Log File Does Not Exists!")
                else:
                    self.titlemsg = "%s: %s" % (control.addonName(), filename.replace(log_utils.LOG_PATH, ''))
                    self.getControl(self.title).setLabel(self.titlemsg)
                    self.getControl(self.msg).setText(log_utils.highlightText(self.logmsg))
                    self.setFocusId(self.scrollbar)

        def onAction(self, action):
            if action == themecontrol.ACTION_PREVIOUS_MENU or action == themecontrol.ACTION_NAV_BACK:
                self.close()


    viewer = LogViewver_Window('LogViewer.xml', control.skinModule(), control.skinTheme(), '1080i', logfile=logfile)
    viewer.doModal()
    del viewer
Exemplo n.º 8
0
def BugReporter(open_bugs=None):
    class BugReporter_Window(xbmcgui.WindowXMLDialog):
        # until now we have a blank window, the onInit function will parse your xml file
        def onInit(self):
            self.colors = themecontrol.ThemeColors()
            self.report_text = themecontrol.getDialogText(br_file)
            self.open_bugs = open_bugs

            self.br_text = 102
            self.br_input = 103
            self.br_open = 104
            self.btn_submit = 201
            self.btn_close = 202

            self.showdialog()

        def showdialog(self):
            self.setProperty('dhtext', self.colors.dh_color)
            self.getControl(self.br_text).setText(self.report_text)
            self.getControl(self.br_open).setText(self.open_bugs)
            self.setFocusId(self.btn_close)

        def onClick(self, controlId):
            if controlId == self.btn_close:
                self.close()
            elif controlId == self.btn_submit:
                reportText = self.getControl(self.br_input).getText()
                if len(reportText) == 0:
                    xbmc.executebuiltin(
                        "XBMC.Notification(%s, %s, %s, %s)" %
                        ('Atreides Bug Report', 'Bug Report Incomplete', 4000,
                         control.addonIcon()))
                    return
                self.close()
                result = webform.webform().bug_report('Atreides', reportText)
                if result is None:
                    # Wait before submitting another report you f****n spammer
                    xbmc.executebuiltin(
                        "XBMC.Notification(%s, %s, %s, %s)" %
                        ('Atreides Bug Report', 'Wait Before Next Submission',
                         4000, control.addonIcon()))
                elif result is False:
                    # Failed to send. Site timed out or is down. Ya'll suck
                    xbmc.executebuiltin(
                        "XBMC.Notification(%s, %s, %s, %s)" %
                        ('Atreides Bug Report', 'Submission Failed', 4000,
                         control.addonIcon()))
                elif result is True:
                    # Bug Report worked, F**K YEAH!
                    xbmc.executebuiltin(
                        "XBMC.Notification(%s, %s, %s, %s)" %
                        ('Atreides Bug Report', 'Bug Report Completed', 4000,
                         control.addonIcon()))

        def onAction(self, action):
            if action == themecontrol.ACTION_PREVIOUS_MENU or action == themecontrol.ACTION_NAV_BACK:
                self.close()

    open_bugs = webform.webform().get_bugs()
    viewer = BugReporter_Window('BugReporter.xml',
                                control.skinModule(),
                                control.skinTheme(),
                                '1080i',
                                open_bugs=open_bugs)
    viewer.doModal()
    del viewer