Beispiel #1
0
class WebsiteTrustManagementWindowCore(Window):
    __guid__ = 'uicls.WebsiteTrustManagementWindowCore'
    __notifyevents__ = ['OnTrustedSitesChange']
    default_windowID = 'WebsiteTrustManagementWindow'

    def ApplyAttributes(self, attributes):
        Window.ApplyAttributes(self, attributes)
        initialUrl = attributes.initialUrl
        self.SetCaption(localization.GetByLabel('UI/Browser/TrustedSites'))
        self.SetMinSize((368, 300))
        mainArea = self.GetMainArea()
        mainArea.top = 2
        self.inputContainer = Container(name='inputContainer',
                                        parent=mainArea,
                                        align=uiconst.TOTOP,
                                        height=50)
        self.bodyContainer = Container(name='bodyContainer',
                                       parent=mainArea,
                                       align=uiconst.TOALL,
                                       pos=(0, 0, 0, 0))
        self.trustContainer = Container(name='trustContainer',
                                        parent=self.bodyContainer,
                                        align=uiconst.TOTOP,
                                        height=76)
        self.ignoreContainer = Container(name='ignoreContainer',
                                         parent=self.bodyContainer,
                                         align=uiconst.TOBOTTOM,
                                         height=76)
        urlInputContainer = Container(name='urlInputContainer',
                                      parent=self.inputContainer,
                                      align=uiconst.TOTOP,
                                      height=22,
                                      top=3)
        inputButtonContainer = Container(name='urlInputButtonContainer',
                                         parent=self.inputContainer,
                                         align=uiconst.TOBOTTOM,
                                         height=20,
                                         padRight=4)
        self.urlText = Label(
            text=localization.GetByLabel('UI/Browser/EditBookmarks/URL'),
            parent=urlInputContainer,
            align=uiconst.TOLEFT,
            padLeft=6,
            state=uiconst.UI_DISABLED,
            uppercase=1,
            fontsize=10,
            letterspace=1)
        self.urlInput = SinglelineEdit(name='urlInput',
                                       parent=urlInputContainer,
                                       align=uiconst.TOTOP,
                                       padRight=const.defaultPadding,
                                       padLeft=const.defaultPadding)
        self.trustBtn = Button(
            parent=inputButtonContainer,
            label=localization.GetByLabel('UI/Browser/TrustSite'),
            align=uiconst.TORIGHT,
            padLeft=4,
            padBottom=3,
            func=self.TrustSite)
        self.trustBtn.hint = localization.GetByLabel(
            'UI/Browser/TrustManagementTrustHint')
        self.ignoreBtn = Button(
            parent=inputButtonContainer,
            label=localization.GetByLabel('UI/Browser/IgnoreSite'),
            align=uiconst.TORIGHT,
            padLeft=4,
            padBottom=3,
            func=self.IgnoreSite)
        self.ignoreBtn.hint = localization.GetByLabel(
            'UI/Browser/TrustManagementIgnoreHint')
        trustBtnContainer = Container(name='trustBtnContainer',
                                      parent=self.trustContainer,
                                      align=uiconst.TOBOTTOM,
                                      height=22,
                                      padRight=4)
        trustRemoveBtn = Button(
            parent=trustBtnContainer,
            label=localization.GetByLabel('UI/Commands/Remove'),
            align=uiconst.TORIGHT,
            padLeft=4,
            padBottom=3,
            func=self.RemoveTrustedSite)
        trustRemoveBtn.hint = localization.GetByLabel(
            'UI/Browser/TrustManagementRemoveTrustHint')
        trustTextContainer = Container(name='trustTextContainer',
                                       parent=self.trustContainer,
                                       align=uiconst.TOTOP,
                                       height=14)
        Label(text=localization.GetByLabel('UI/Browser/TrustedSites'),
              parent=trustTextContainer,
              state=uiconst.UI_DISABLED,
              fontsize=10,
              left=10,
              top=3)
        trustScrollContainer = Container(name='trustScrollContainer',
                                         parent=self.trustContainer,
                                         align=uiconst.TOALL)
        self.trustScroll = Scroll(
            parent=trustScrollContainer,
            padding=(const.defaultPadding, const.defaultPadding,
                     const.defaultPadding, const.defaultPadding))
        ignoreBtnContainer = Container(name='ignoreBtnContainer',
                                       parent=self.ignoreContainer,
                                       align=uiconst.TOBOTTOM,
                                       height=22,
                                       padRight=4)
        ignoreRemoveBtn = Button(
            parent=ignoreBtnContainer,
            label=localization.GetByLabel('UI/Commands/Remove'),
            align=uiconst.TORIGHT,
            padLeft=4,
            padBottom=3,
            func=self.RemoveIgnoredSite)
        ignoreRemoveBtn.hint = localization.GetByLabel(
            'UI/Browser/TrustManagementRemoveIgnoredHint')
        ignoreTextContainer = Container(name='ignoreTextContainer',
                                        parent=self.ignoreContainer,
                                        align=uiconst.TOTOP,
                                        height=14)
        Label(text=localization.GetByLabel('UI/Browser/IgnoredSites'),
              parent=ignoreTextContainer,
              state=uiconst.UI_DISABLED,
              fontsize=10,
              left=10,
              top=3)
        ignoreScrollContainer = Container(name='ignoreScrollContainer',
                                          parent=self.ignoreContainer,
                                          align=uiconst.TOALL)
        self.ignoreScroll = Scroll(
            parent=ignoreScrollContainer,
            padding=(const.defaultPadding, const.defaultPadding,
                     const.defaultPadding, const.defaultPadding))
        self.inited = 1
        self.sitesSvc = sm.GetService('sites')
        self.RefreshSites()
        if initialUrl is not None:
            self.urlInput.SetValue(initialUrl)

    def _OnResize(self, *args):
        uthread.new(self.__OnResize, *args)

    def __OnResize(self, *args):
        if not getattr(self, 'inited', False):
            return
        bodyHeight = self.bodyContainer.absoluteBottom - self.bodyContainer.absoluteTop
        halfSize = int(bodyHeight / 2)
        if halfSize * 2 != bodyHeight:
            self.trustContainer.height = halfSize + 1
        else:
            self.trustContainer.height = halfSize
        self.ignoreContainer.height = halfSize

    def TrustSite(self, *args):
        value = self.urlInput.GetValue()
        if not value:
            eve.Message('trustedSiteManagementPleaseEnterUrl')
            return
        value = value.strip()
        if value is not None and len(value) > 0:
            self.sitesSvc.AddTrustedSite(value)
        else:
            eve.Message('trustedSiteManagementPleaseEnterUrl')

    def IgnoreSite(self, *args):
        value = self.urlInput.GetValue()
        if not value:
            eve.Message('trustedSiteManagementPleaseEnterUrl')
            return
        value = value.strip()
        if value is not None and len(value) > 0:
            self.sitesSvc.AddIgnoredSite(value)
        else:
            eve.Message('trustedSiteManagementPleaseEnterUrl')

    def RemoveTrustedSite(self, *args):
        selected = self.trustScroll.GetSelected()
        if not len(selected):
            eve.Message('trustedSiteManagementPleaseSelectSite')
            return
        for entry in selected:
            self.sitesSvc.RemoveTrustedSite(entry.retval)

    def RemoveIgnoredSite(self, *args):
        selected = self.ignoreScroll.GetSelected()
        if not len(selected):
            eve.Message('trustedSiteManagementPleaseSelectSite')
            return
        for entry in selected:
            self.sitesSvc.RemoveTrustedSite(entry.retval)

    def OnTrustedSitesChange(self, *etc):
        self.RefreshSites()

    def OnGetTrustMenu(self, entry):
        return [(localization.GetByLabel('UI/Commands/Remove'),
                 sm.GetService('sites').RemoveTrustedSite,
                 (entry.sr.node.retval, ))]

    def RefreshSites(self):
        trustScrollList = []
        ignoreScrollList = []
        for key, value in self.sitesSvc.GetTrustedSites().iteritems():
            if value.auto:
                continue
            trustScrollList.append(
                ScrollEntryNode(decoClass=SE_GenericCore,
                                label=key,
                                retval=key,
                                trustData=value,
                                GetMenu=self.OnGetTrustMenu))

        for key, value in self.sitesSvc.GetIgnoredSites().iteritems():
            if value.auto:
                continue
            ignoreScrollList.append(
                ScrollEntryNode(decoClass=SE_GenericCore,
                                label=key,
                                retval=key,
                                trustData=value,
                                GetMenu=self.OnGetTrustMenu))

        self.trustScroll.Load(contentList=trustScrollList)
        self.ignoreScroll.Load(contentList=ignoreScrollList)
class BrowserSettingsWindowCore(Window):
    __guid__ = 'uicls.BrowserSettingsWindowCore'
    default_windowID = 'BrowserSettingsWindow'

    def ApplyAttributes(self, attributes):
        Window.ApplyAttributes(self, attributes)
        self.showNavigationBar = settings.user.ui.Get('browserShowNavBar', True)
        self.showStatusBar = settings.user.ui.Get('browserShowStatusBar', True)
        self.SetCaption(localization.GetByLabel('UI/Browser/BrowserSettings/BrowserSettingsCaption'))
        self.SetButtons(uiconst.OKCLOSE, okLabel=localization.GetByLabel('UI/Browser/BrowserSettings/SaveChanges'), okFunc=self.Save, okModalResult=uiconst.ID_NONE)
        main = self.GetMainArea()
        main.clipChildren = 0
        main.padding = 6
        c = Container(name='homeCont', parent=main, align=uiconst.TOTOP, height=32)
        l = Container(name='left', parent=c, align=uiconst.TOLEFT, width=100, state=uiconst.UI_PICKCHILDREN)
        r = Container(name='right', parent=c, align=uiconst.TORIGHT, width=80, state=uiconst.UI_PICKCHILDREN)
        text = Label(text=localization.GetByLabel('UI/Browser/BrowserSettings/Homepage'), align=uiconst.TOALL, state=uiconst.UI_DISABLED, parent=l, left=0, top=4, width=2)
        top = (text.textheight - 16) / 2 + 2 if text.textheight > 16 else 0
        totalTop = top
        btn = Button(parent=r, label=localization.GetByLabel('UI/Browser/BrowserSettings/ResetHomepage'), func=self.ResetHomePage, pos=(0,
         top,
         0,
         0), align=uiconst.TOPRIGHT)
        if btn.width > 80:
            r.width = btn.width
        self.homeEdit = SinglelineEdit(name='homeEdit', setvalue=settings.user.ui.Get('HomePage2', browserutil.DefaultHomepage()), align=uiconst.TOTOP, pos=(0,
         top,
         0,
         0), parent=c)
        Line(parent=main, align=uiconst.TOTOP, color=(0.5, 0.5, 0.5, 0.75))
        self.showHideContainer = Container(name='showHideContainer', parent=main, align=uiconst.TOTOP, height=35, top=0, state=uiconst.UI_PICKCHILDREN)
        self.showStatusBarCbx = Checkbox(text=localization.GetByLabel('UI/Browser/BrowserSettings/ShowStatusBar'), parent=self.showHideContainer, configName='', retval=0, checked=self.showStatusBar)
        self.showNavBarCbx = Checkbox(text=localization.GetByLabel('UI/Browser/BrowserSettings/ShowNavigationBar'), parent=self.showHideContainer, configName='', retval=0, checked=self.showNavigationBar)
        Line(parent=main, align=uiconst.TOTOP, color=(0.5, 0.5, 0.5, 0.75))
        self.cacheContainer = Container(name='cacheContainer', parent=main, align=uiconst.TOTOP, height=26, top=8, state=uiconst.UI_PICKCHILDREN)
        l = Container(name='cacheLeft', parent=self.cacheContainer, align=uiconst.TOLEFT, width=100, state=uiconst.UI_PICKCHILDREN)
        r = Container(name='cacheRight', parent=self.cacheContainer, align=uiconst.TORIGHT, width=80, state=uiconst.UI_PICKCHILDREN)
        if not blue.win32.IsTransgaming():
            text = Label(text=localization.GetByLabel('UI/Browser/BrowserSettings/CacheLocation'), align=uiconst.TOLEFT, state=uiconst.UI_DISABLED, parent=l, padding=(2, 4, 2, 4))
            top = (text.textheight - 16) / 2 + 2 if text.textheight > 16 else 0
            totalTop += top
            btn = Button(parent=r, label=localization.GetByLabel('UI/Browser/BrowserSettings/ResetCacheLocation'), func=self.ResetCacheLocation, pos=(0,
             top,
             0,
             0), align=uiconst.TOPRIGHT)
            if btn.width > r.width:
                r.width = btn.width
            if text.textwidth > l.width:
                l.width = text.textwidth + 4
            self.cacheEdit = SinglelineEdit(name='cacheEdit', setvalue=settings.public.generic.Get('BrowserCache', corebrowserutil.DefaultCachePath()), align=uiconst.TOTOP, pos=(0,
             top,
             0,
             0), parent=self.cacheContainer)
            explainContainer = Container(name='cacheExplainContainer', parent=main, align=uiconst.TOTOP, height=26)
            Label(text=localization.GetByLabel('UI/Browser/BrowserSettings/CacheCaption'), align=uiconst.TOALL, state=uiconst.UI_DISABLED, parent=explainContainer, padLeft=4, fontsize=10)
            totalTop += 26
            clearCacheContainer = Container(name='clearCacheContainer', parent=main, align=uiconst.TOTOP, height=14)
            btn = Button(parent=clearCacheContainer, label=localization.GetByLabel('UI/Browser/BrowserSettings/ClearCache'), func=self.ClearCache)
            btn.hint = (localization.GetByLabel('UI/Browser/BrowserSettings/ClearCacheHint'),)
            totalTop += 16
        else:
            totalTop -= 32
        self.SetMinSize((500, 204 + totalTop))
        sm.StartService('sites')

    def ResetHomePage(self, *args):
        settings.user.ui.Set('HomePage2', browserutil.DefaultHomepage())
        self.homeEdit.SetValue(settings.user.ui.Get('HomePage2', browserutil.DefaultHomepage()))

    def ResetCacheLocation(self, *args):
        settings.public.generic.Set('BrowserCache', corebrowserutil.DefaultCachePath())
        self.cacheEdit.SetValue(corebrowserutil.DefaultCachePath())

    def Save(self, *args):
        url = self.homeEdit.GetValue().strip()
        if url and url.find('://') < 0:
            url = 'http://' + url
            self.homeEdit.SetValue(url)
        settings.user.ui.Set('HomePage2', url)
        if not blue.win32.IsTransgaming():
            cachePath = self.cacheEdit.GetValue().strip()
            cachePath = blue.paths.ResolvePath(cachePath)
            if cachePath:
                self.cacheEdit.SetValue(cachePath)
            settings.public.generic.Set('BrowserCache', cachePath)
        show = bool(self.showStatusBarCbx.GetValue())
        if bool(self.showStatusBar) != show:
            self.showStatusBar = show
            settings.user.ui.Set('browserShowStatusBar', show)
            sm.ScatterEvent('OnBrowserShowStatusBarChange')
        show = bool(self.showNavBarCbx.GetValue())
        if bool(self.showNavigationBar) != show:
            self.showNavigationBar = show
            settings.user.ui.Set('browserShowNavBar', show)
            sm.ScatterEvent('OnBrowserShowNavigationBarChange')

    def ClearCache(self, *args):
        if uicore.Message('BrowserClearCache', {}, uiconst.YESNO) == uiconst.ID_YES:
            from carbonui.control.browser.browserWindow import BrowserWindowCore
            for wnd in uicore.registry.GetWindows()[:]:
                if issubclass(wnd.__class__, BrowserWindowCore):
                    wnd.Close()

            sm.GetService('browserHostManager').RestartBrowserHost(clearCache=True)
            self.CloseByUser()
class LoadFlagTester(Window):
    __guid__ = 'uicls.LoadFlagTester'
    default_topParentHeight = 0
    default_windowID = 'LoadFlagTester'
    default_caption = 'Font Browser'

    def ApplyAttributes(self, attributes):
        Window.ApplyAttributes(self, attributes)
        self.SetMinSize((500, 300))
        main = self.GetMainArea()
        main.clipChildren = True
        options = Container(parent=main, align=uiconst.TOLEFT, width=180, padTop=4, padLeft=5)
        fontsParent = Container(parent=options)
        flagsParent = Container(parent=options)
        tabs = uicontrols.TabGroup(parent=options, tabs=[('Fonts',
          fontsParent,
          self,
          'properties'), ('Load Flags',
          flagsParent,
          self,
          'flags')], padBottom=6, idx=0)
        for each in (STYLECLASSES, CLIENTFONTS, WINDOWSFONTS):
            Checkbox(parent=fontsParent, text='Browse ' + each, groupname='browseType', checked=each == STYLECLASSES, callback=self.OnBrowseTypeChange, retval=each)

        import uicls
        clientLabelClasses = []
        for className, cls in uicls.__dict__.iteritems():
            try:
                if issubclass(cls, LabelCore) and cls is not LabelCore and getattr(cls, '__guid__', None) is not None:
                    clientLabelClasses.append((className, (className, cls)))
            except:
                pass

        clientLabelClasses = SortListOfTuples(clientLabelClasses)
        self.styleClassesLabel = Label(parent=fontsParent, text='Style Classes', align=uiconst.TOTOP, padTop=10)
        self.styleClassesCombo = Combo(parent=fontsParent, align=uiconst.TOTOP, options=clientLabelClasses, callback=self.OnStyleClassChange)
        clientFaces = []
        clientFonts = os.listdir(blue.paths.ResolvePathForWriting(u'res:') + '\\UI\\Fonts')
        clientFonts.sort()
        for fontName in clientFonts:
            if fontName.lower().endswith('.ttf') or fontName.lower().endswith('.otf'):
                clientFaces.append((fontName, 'res:/UI/Fonts/' + fontName))

        self.clientFontsLabel = Label(parent=fontsParent, text='Client Fonts', align=uiconst.TOTOP, padTop=10)
        self.clientFontsCombo = typeFaceCombo = Combo(parent=fontsParent, align=uiconst.TOTOP, options=clientFaces, callback=self.OnTypeFaceChange)
        windowsFaces = []
        windowsFonts = os.listdir(blue.win32.SHGetFolderPath(blue.win32.CSIDL_FONTS))
        windowsFonts.sort()
        for fontName in windowsFonts:
            if fontName.lower().endswith('.ttf') or fontName.lower().endswith('.otf'):
                windowsFaces.append((fontName, blue.win32.SHGetFolderPath(blue.win32.CSIDL_FONTS) + '\\' + fontName))

        self.windowsFontsLabel = Label(parent=fontsParent, text='Windows Fonts', align=uiconst.TOTOP, padTop=10)
        self.windowsFontsCombo = typeFaceCombo = Combo(parent=fontsParent, align=uiconst.TOTOP, options=windowsFaces, callback=self.OnTypeFaceChange)
        Label(parent=fontsParent, text='Fontsize', align=uiconst.TOTOP, padTop=10)
        self.fontSizeEdit = SinglelineEdit(ints=(6, 128), parent=fontsParent, align=uiconst.TOTOP, OnChange=self.OnFontSizeChange, setvalue=unicode(Label.default_fontsize))
        Label(parent=fontsParent, text='Letterspace', align=uiconst.TOTOP, padTop=10)
        self.letterSpaceEdit = SinglelineEdit(ints=(-10, 10), parent=fontsParent, align=uiconst.TOTOP, OnChange=self.OnLetterSpaceChange, setvalue=unicode(Label.default_letterspace))
        Label(parent=fontsParent, text='LineSpacing', align=uiconst.TOTOP, padTop=10)
        self.lineSpacingEdit = SinglelineEdit(floats=(-1.0, 1.0, 2), parent=fontsParent, align=uiconst.TOTOP, OnChange=self.OnLineSpacingChange, setvalue=unicode(0.0))
        current = trinity.fontMan.loadFlag
        self.loadFlagCheckBoxes = []
        for flagName, flagValue in loadFlags:
            active = current & flagValue == flagValue
            cb = Checkbox(parent=flagsParent, align=uiconst.TOTOP, text=flagName.replace('FT_LOAD_', ''), callback=self.OnLoadFlagChange, retval=flagValue, checked=active)
            cb.flagName = flagName
            cb.flagValue = flagValue
            self.loadFlagCheckBoxes.append(cb)

        Label(parent=flagsParent, text='Render flags', align=uiconst.TOTOP, padTop=10)
        self.renderFlagCheckBoxes = []
        for flagName, flagValue in renderFlags:
            active = current & flagValue == flagValue
            cb = Checkbox(parent=flagsParent, align=uiconst.TOTOP, text=flagName.replace('FT_RENDER_MODE_', ''), groupname='renderFlag', callback=self.OnRenderFlagChange, retval=flagValue, checked=active)
            cb.flagName = flagName
            cb.flagValue = flagValue
            self.renderFlagCheckBoxes.append(cb)

        sampleSelectionParent = Container(parent=main, align=uiconst.TOTOP, height=38, padTop=20)
        Line(parent=main, align=uiconst.TOTOP, padTop=10, padRight=10, padLeft=10)
        self.sampleCombo = Combo(parent=sampleSelectionParent, align=uiconst.TOPLEFT, width=100, left=10, options=[('Lorem...', samplText), ('Ansi charset', ANSI), ('Cyrillic charset', CYRILLIC)], callback=self.OnSampleComboChange)
        orlabel = Label(parent=sampleSelectionParent, text='-or-', left=self.sampleCombo.left + self.sampleCombo.width + 5)
        self.sampleInput = EditPlainText(parent=sampleSelectionParent, align=uiconst.TOALL, padLeft=140, padRight=10, text='asdf sfdasfasfdasfd safd')
        self.sampleInput.OnChange = self.OnCustomTextChange
        self.samples = []
        for typeFace in clientFonts[:1]:
            sampl = Label(parent=main, align=uiconst.TOTOP, text=samplText, padding=10)
            self.samples.append(sampl)

        self.LoadBrowseType(STYLECLASSES)

    def OnBrowseTypeChange(self, checkBox, *args):
        self.LoadBrowseType(checkBox.data['value'])

    def LoadBrowseType(self, browseType):
        if browseType == STYLECLASSES:
            self.windowsFontsCombo.Hide()
            self.windowsFontsLabel.Hide()
            self.clientFontsCombo.Hide()
            self.clientFontsLabel.Hide()
            self.styleClassesLabel.Show()
            self.styleClassesCombo.Show()
            current = self.styleClassesCombo.GetValue()
            self.LoadFontClass(current)
        elif browseType == CLIENTFONTS:
            self.windowsFontsCombo.Hide()
            self.windowsFontsLabel.Hide()
            self.styleClassesLabel.Hide()
            self.styleClassesCombo.Hide()
            self.clientFontsCombo.Show()
            self.clientFontsLabel.Show()
            current = self.clientFontsCombo.GetValue()
            self.LoadFontPath(current)
        elif browseType == WINDOWSFONTS:
            self.styleClassesLabel.Hide()
            self.styleClassesCombo.Hide()
            self.clientFontsCombo.Hide()
            self.clientFontsLabel.Hide()
            self.windowsFontsCombo.Show()
            self.windowsFontsLabel.Show()
            current = self.windowsFontsCombo.GetValue()
            self.LoadFontPath(current)

    def OnLoadFlagChange(self, checkBox):
        self.UpdateFlags()

    def OnRenderFlagChange(self, checkBox):
        self.UpdateFlags()

    def UpdateFlags(self):
        loadFlag = 0
        for cb in self.loadFlagCheckBoxes:
            if cb.GetValue():
                loadFlag = loadFlag | cb.flagValue

        for cb in self.renderFlagCheckBoxes:
            if cb.GetValue():
                loadFlag = loadFlag | cb.flagValue
                break

        trinity.fontMan.loadFlag = loadFlag
        for sampl in self.samples:
            sampl.text = sampl.text

    def OnFontSizeChange(self, text):
        try:
            newFontSize = int(text)
            for sampl in self.samples:
                sampl.fontsize = newFontSize

        except:
            pass

    def OnLetterSpaceChange(self, text):
        try:
            newLetterSpace = int(text)
            for sampl in self.samples:
                sampl.letterspace = newLetterSpace

        except:
            pass

    def OnLineSpacingChange(self, text):
        try:
            newLineSpacing = float(text)
            for sampl in self.samples:
                sampl.lineSpacing = newLineSpacing

        except:
            pass

    def OnStyleClassChange(self, combo, header, value):
        self.LoadFontClass(value)

    def LoadFontClass(self, fontClass):
        for sampl in self.samples:
            sampl.fontPath = fontClass.default_fontPath
            sampl.fontFamily = fontClass.default_fontFamily
            sampl.fontStyle = fontClass.default_fontStyle

        self.fontSizeEdit.SetValue(fontClass.default_fontsize)
        self.letterSpaceEdit.SetValue(fontClass.default_letterspace)
        self.lineSpacingEdit.SetValue(fontClass.default_lineSpacing)

    def OnTypeFaceChange(self, combo, header, value):
        self.LoadFontPath(value)

    def LoadFontPath(self, fontPath):
        for sampl in self.samples:
            sampl.fontPath = fontPath

    def OnSampleComboChange(self, combo, header, value):
        for sampl in self.samples:
            sampl.text = value

    def OnCustomTextChange(self, *args):
        current = self.sampleInput.GetValue()
        for sampl in self.samples:
            sampl.text = current
Beispiel #4
0
class BrowserWindowCore(Window):
    __guid__ = 'uicls.BrowserWindowCore'
    __notifyevents__ = [
        'OnTrustedSitesChange', 'OnSessionChanged',
        'OnClientBrowserLockdownChange', 'OnClientFlaggedListsChange',
        'OnEndChangeDevice', 'OnBrowserShowStatusBarChange',
        'OnBrowserShowNavigationBarChange', 'OnBrowserHistoryCleared'
    ]
    default_width = 600
    default_height = 600
    default_iconNum = 'res:/ui/Texture/WindowIcons/browser.png'

    def ApplyAttributes(self, attributes):
        Window.ApplyAttributes(self, attributes)
        initialUrl = attributes.initialUrl
        self.reloadingTrustedSites = False
        self.awaitingTitle = False
        self.nextTabID = 1
        self.currentTab = None
        self.browserHostManager = sm.GetService(
            'browserHostManager').GetBrowserHost()
        self.tabs = []
        self.browserButtons = (('Back', self.HistoryBack, 20, 'back',
                                'UI/Browser/Back'),
                               ('Forward', self.HistoryForward, 60, 'next',
                                'UI/Browser/Forward'), (None, None, None, None,
                                                        None),
                               ('Reload', self.ReloadPage, -40, 'reload',
                                'UI/Browser/Reload'),
                               ('Stop', self.StopLoading, 20, 'stop',
                                'UI/Browser/Stop'), (None, None, None, None,
                                                     None),
                               ('Home', self.GoHome, 0, 'home',
                                'UI/Browser/Home'))
        self.MakeUnstackable()
        self.SetMinSize([260, 180])
        self.SetMaxSize([uicore.desktop.width, uicore.desktop.height])
        self.PrepareMenuBar()
        self.PrepareNavigationBar()
        self.PrepareNavigationButtons()
        self.PrepareTabBar()
        self.PrepareStatusBar()
        mainArea = self.GetMainArea()
        if not settings.user.ui.Get('browserShowNavBar', True):
            self.navigationBar.state = uiconst.UI_HIDDEN
        if not settings.user.ui.Get('browserShowStatusBar', True):
            self.statusBar.state = uiconst.UI_HIDDEN
        for name, GetMenu in [
            (localization.GetByLabel('UI/Browser/View'), lambda:
             [(localization.GetByLabel('UI/Browser/Reload'), self.ReloadPage,
               ()),
              (localization.GetByLabel('UI/Browser/ViewSource'), self.
               DocumentSource, ()),
              (localization.GetByLabel(
                  'UI/Browser/BrowserHistory/BrowserHistoryCaption'), self.
               OpenBrowserHistory, ())]),
            (localization.GetByLabel('UI/Browser/Bookmarks'),
             self.GetBookmarkMenu),
            (localization.GetByLabel('UI/Browser/Options'),
             lambda: [(localization.GetByLabel('UI/Browser/GeneralSettings'),
                       self.EditGeneralSettings, ()), None,
                      (localization.GetByLabel('UI/Browser/TrustedSites'), self
                       .EditSites, ('trusted', ))])
        ]:
            opt = WindowDropDownMenu(name='menuoption', parent=self.menuBar)
            opt.Setup(name, GetMenu)

        self.crashNotifierContainer = Container(name='crashNotifierContainer',
                                                parent=mainArea,
                                                align=uiconst.CENTER,
                                                state=uiconst.UI_HIDDEN,
                                                width=240,
                                                height=80,
                                                idx=0)
        crashText = Label(text=localization.GetByLabel('UI/Browser/Crashed'),
                          parent=self.crashNotifierContainer,
                          width=220,
                          left=10,
                          top=10,
                          fontsize=16,
                          letterspace=1)
        Fill(parent=self.crashNotifierContainer, color=(0.0, 0.0, 0.0, 1.0))
        self.crashNotifierContainer.height = max(80, crashText.textheight + 20)
        bp = browser.BrowserPane(parent=mainArea,
                                 align=uiconst.TOALL,
                                 state=uiconst.UI_NORMAL,
                                 padLeft=const.defaultPadding + 6,
                                 padRight=const.defaultPadding + 6,
                                 padTop=6,
                                 padBottom=6)
        bp.Startup()
        self.browserPane = bp
        Fill(parent=mainArea,
             color=(0.0, 0.0, 0.0, 1.0),
             padLeft=const.defaultPadding,
             padRight=const.defaultPadding)
        self.OnClientFlaggedListsChange()
        browseToUrl = initialUrl
        if browseToUrl is None or browseToUrl == 'home':
            browseToUrl = str(
                settings.user.ui.Get('HomePage2',
                                     browserutil.DefaultHomepage()))
        self.AddTab(browseToUrl)

    def PrepareMenuBar(self):
        mainArea = self.GetMainArea()
        self.menuBar = Container(name='menuBar',
                                 parent=mainArea,
                                 align=uiconst.TOTOP,
                                 height=16,
                                 padBottom=2)
        Line(parent=self.menuBar, align=uiconst.TOBOTTOM)

    def PrepareTabBar(self):
        mainArea = self.GetMainArea()
        self.tabBar = Container(name='tabParent',
                                parent=mainArea,
                                align=uiconst.TOTOP,
                                height=24)
        self.addTabBtn = Button(
            parent=self.tabBar,
            label=localization.uiutil.PrepareLocalizationSafeString('+'),
            align=uiconst.TOPRIGHT,
            fixedwidth=22,
            func=self.AddTabButton,
            alwaysLite=True,
            hint=localization.GetByLabel('UI/Browser/NewTab'),
            left=const.defaultPadding)

    def PrepareStatusBar(self):
        mainArea = self.GetMainArea()
        self.statusBar = Container(name='statusBar',
                                   parent=mainArea,
                                   align=uiconst.TOBOTTOM,
                                   height=22,
                                   clipChildren=1,
                                   idx=0)
        iconContainer = Container(name='trustIndicator',
                                  parent=self.statusBar,
                                  align=uiconst.TORIGHT,
                                  width=24,
                                  left=4)
        icon = Sprite(name='trustIndicatorIcon',
                      parent=iconContainer,
                      texturePath=
                      'res:/UI/Texture/classes/Browser/trustIndicatorIcon.png',
                      pos=(0, -3, 24, 24),
                      hint=localization.GetByLabel('UI/Browser/TrustedSite'),
                      ignoreSize=True,
                      state=uiconst.UI_DISABLED)
        self.trustIndicatorIcon = icon
        self.trustIndicatorIcon.state = uiconst.UI_HIDDEN
        iconContainer = Container(name='lockdownIndicator',
                                  parent=self.statusBar,
                                  align=uiconst.TOLEFT,
                                  width=28)
        Sprite(name='lockdownIndicatorIcon',
               parent=iconContainer,
               texturePath=
               'res:/UI/Texture/classes/Browser/lockdownIndicatorIcon.png',
               pos=(2, -3, 24, 24),
               hint=localization.GetByLabel('UI/Browser/LockdownEnabled'),
               ignoreSize=True,
               state=uiconst.UI_NORMAL)
        self.lockdownIconContainer = iconContainer
        self.statusText = Label(text='',
                                parent=self.statusBar,
                                maxLines=1,
                                state=uiconst.UI_NORMAL,
                                align=uiconst.CENTERLEFT)

    def PrepareNavigationBar(self):
        mainArea = self.GetMainArea()
        self.navigationBar = Container(name='navBar',
                                       parent=mainArea,
                                       align=uiconst.TOTOP,
                                       height=24,
                                       padBottom=4)
        buttonParent = Container(name='buttonParent',
                                 parent=self.navigationBar,
                                 align=uiconst.TORIGHT,
                                 padRight=const.defaultPadding)
        goBtn = Button(parent=buttonParent,
                       label=localization.GetByLabel('UI/Browser/Go'),
                       func=self.OnGoBtn,
                       align=uiconst.CENTER)
        buttonParent.width = goBtn.width
        iconContainer = Container(name='sslIndicator',
                                  parent=self.navigationBar,
                                  align=uiconst.TORIGHT,
                                  width=20,
                                  padRight=const.defaultPadding)
        Sprite(name='sslIcon',
               texturePath='res:/UI/Texture/classes/Browser/sslIcon.png',
               parent=iconContainer,
               pos=(-2, -1, 24, 24),
               hint=localization.GetByLabel('UI/Browser/SecureConnection'),
               ignoreSize=True,
               state=uiconst.UI_NORMAL)
        self.sslIconContainer = iconContainer
        self.urlInput = SinglelineEdit(name='urlInput',
                                       parent=self.navigationBar,
                                       padTop=1,
                                       padRight=const.defaultPadding,
                                       maxLength=1630,
                                       autoselect=True,
                                       align=uiconst.TOTOP)
        self.urlInput.OnReturn = self.BrowseTo
        self.urlInput.OnHistoryClick = self.OnHistoryClicked

    def PrepareNavigationButtons(self):
        buttonTop = Container(name='buttonTop',
                              parent=self.navigationBar,
                              padRight=const.defaultPadding,
                              align=uiconst.TOLEFT,
                              idx=0)
        for btnLabel, btnFunc, btnRectLeft, btnName, localizationLabel in self.browserButtons:
            if btnLabel is None:
                buttonTop.width += 6
                continue
            if localization.IsValidLabel(localizationLabel):
                thehint = localization.GetByLabel(localizationLabel)
            else:
                thehint = ''
            button = uicls.ImageButton(
                parent=buttonTop,
                name=btnLabel,
                width=20,
                height=20,
                align=uiconst.RELATIVE,
                top=2,
                left=buttonTop.width,
                idleIcon='res:/UI/Texture/classes/Browser/%sIdle.png' %
                btnName,
                mouseoverIcon='res:/UI/Texture/classes/Browser/%sMouseOver.png'
                % btnName,
                mousedownIcon='res:/UI/Texture/classes/Browser/%sIdle.png' %
                btnName,
                onclick=btnFunc,
                hint=thehint)
            button.flag = btnLabel
            setattr(self.sr, '%sButton' % btnLabel, button)
            buttonTop.width += 20

    def _OnClose(self, *args):
        sm.GetService('urlhistory').SaveHistory()
        ct = getattr(self, 'currentTab', None)
        if ct is not None:
            ct.Cleanup()
            ct = None
        if self.browserPane:
            self.browserPane.browserSession = None
            del self.browserPane
        if getattr(self, 'tabs', None):
            for tab in self.tabs[:]:
                tab.Cleanup()
                del tab

            self.tabs = []

    def PopulateWhitelistAndBlacklist(self):
        self.browserHostManager.ClearSiteList('Blacklist')
        self.browserHostManager.ClearSiteList('Whitelist')
        l = sm.GetService('sites').GetBrowserBlacklist()
        for url in l:
            self.browserHostManager.AddToSiteList('Blacklist', url)

        l = sm.GetService('sites').GetBrowserWhitelist()
        for url in l:
            self.browserHostManager.AddToSiteList('Whitelist', url)

    def OnClientFlaggedListsChange(self, *args):
        self.PopulateWhitelistAndBlacklist()
        self.browserHostManager.UpdateDynamicData()
        self.OnClientBrowserLockdownChange()
        self.OnTrustedSitesChange()

    def OnClientBrowserLockdownChange(self, *args):
        for tab in self.tabs:
            tab._OnClientBrowserLockdownChange(args)

        if sm.GetService('sites').IsBrowserInLockdown():
            self.lockdownIconContainer.state = uiconst.UI_PICKCHILDREN
            self.statusText.left = 0
        else:
            self.lockdownIconContainer.state = uiconst.UI_HIDDEN
            self.statusText.left = 6

    def OnEndChangeDevice(self, change, *args):
        self.SetMaxSize([uicore.desktop.width, uicore.desktop.height])

    def OnBrowserShowStatusBarChange(self, *args):
        show = settings.user.ui.Get('browserShowStatusBar', True)
        self.DisplayStatusBar(show)

    def OnBrowserShowNavigationBarChange(self, *args):
        show = settings.user.ui.Get('browserShowNavBar', True)
        self.DisplayNavigationBar(show)

    def OnBrowserHistoryCleared(self, *args):
        if self and not self.destroyed:
            self.urlInput.ClearHistory()

    def AddToAllOtherSites(self, header, value):
        self.browserHostManager.SetHeader('other', header, unicode(value))

    def AddToAllTrustedSites(self, header, value):
        value = self.CleanHeaderValue(value)
        self.browserHostManager.SetHeader('CCP', header, unicode(value))
        self.browserHostManager.SetHeader('COMMUNITY', header, unicode(value))
        self.browserHostManager.SetHeader('trusted', header, unicode(value))

    def RemoveFromAllTrustedSites(self, header):
        self.browserHostManager.DelHeader('CCP', header)
        self.browserHostManager.DelHeader('COMMUNITY', header)
        self.browserHostManager.DelHeader('trusted', header)

    def AddToCCPTrustedSites(self, header, value):
        value = self.CleanHeaderValue(value)
        self.browserHostManager.SetHeader('CCP', header, unicode(value))
        self.browserHostManager.SetHeader('COMMUNITY', header, unicode(value))

    def CleanHeaderValue(self, value):
        if value and isinstance(value, basestring):
            value = localization.CleanImportantMarkup(value)
        return value

    def OnSessionChanged(self, isRemote, sess, change):
        pass

    def SetupTrustedSiteHeaders(self):
        self.browserHostManager.ClearSiteList('trusted')
        self.browserHostManager.ClearSiteList('CCP')
        self.browserHostManager.ClearSiteList('COMMUNITY')

        def SiteMatch(siteA, siteB):
            if not siteA or not siteB:
                return siteA == siteB
            if siteA.find('://') == -1:
                siteA = 'http://' + siteA
            if siteB.find('://') == -1:
                siteB = 'http://' + siteB
            parsedSiteA = urlparse.urlsplit(siteA)
            parsedSiteB = urlparse.urlsplit(siteB)
            return parsedSiteA[1] == parsedSiteB[1]

        trusted = sm.GetService('sites').GetTrustedSites()
        userTrustedSites = []
        autoTrustedSites = []
        communitySites = []
        for site, flags in trusted.iteritems():
            try:
                if flags.auto == 0:
                    userTrustedSites.append(str(site))
                elif flags.community == 0:
                    autoTrustedSites.append(str(site))
                else:
                    communitySites.append(str(site))
            except:
                log.LogException('Error loading trusted sites, flags = %s' %
                                 flags)

        for site in userTrustedSites:
            cnt = False
            for siteB in autoTrustedSites:
                if SiteMatch(site, siteB):
                    cnt = True
                    break

            if cnt:
                continue
            cnt = False
            for siteB in communitySites:
                if SiteMatch(site, siteB):
                    cnt = True
                    break

            if cnt:
                continue
            self.browserHostManager.AddToSiteList('trusted', site)

        for site in autoTrustedSites:
            if site.startswith('.'):
                site = '*%s' % site
            if site.endswith('/'):
                site += '*'
            self.browserHostManager.AddToSiteList('CCP', site)

        for site in communitySites:
            if site.startswith('.'):
                site = '*%s' % site
            if site.endswith('/'):
                site += '*'
            self.browserHostManager.AddToSiteList('COMMUNITY', site)

        self.AddTrustedHeaderData()
        self.browserHostManager.UpdateDynamicData()

    def AddTrustedHeaderData(self):
        pass

    def _OnResize(self, *args):
        if self.GetState() != uiconst.RELATIVE:
            return
        if self.browserPane:
            self.browserPane.ResizeBrowser()

    def OnEndMaximize(self, *args):
        self.OnResizeUpdate()

    def GoHome(self, *args):
        if self.currentTab:
            self.currentTab.GoHome(*args)

    def BrowseTo(self, url=None, *args, **kwargs):
        if self.currentTab is None:
            return
        if url is None:
            url = self.urlInput.GetValue().encode('cp1252', 'ignore')
        if type(url) is not str:
            url = url.encode('cp1252', 'ignore')
        if url.find(':/') == -1 and url != 'about:blank':
            url = 'http://' + url
        self.browserPane.OnBrowseTo()
        self.currentTab.BrowseTo(url=url, *args)

    def OnHistoryClicked(self, historyString, *args, **kwargs):
        self.BrowseTo(historyString)

    def OnGoBtn(self, *args):
        url = None
        self.BrowseTo(url)

    def ReloadPage(self, *args):
        self.browserPane.OnBrowseTo()
        self.currentTab.ReloadPage(*args)

    def HistoryBack(self, *args):
        self.browserPane.OnBrowseTo()
        self.currentTab.HistoryBack(*args)

    def HistoryForward(self, *args):
        self.browserPane.OnBrowseTo()
        self.currentTab.HistoryForward(*args)

    def StopLoading(self, *args):
        self.currentTab.StopLoading(*args)

    def GetBookmarkMenu(self, startAt=0):
        m = []
        if startAt < 1:
            m.append((MenuLabel('UI/Browser/AddRemove'), self.EditBookmarks))
        allMarks = sm.GetService('sites').GetBookmarks()
        myMarks = allMarks[startAt:startAt + 20]
        if len(myMarks) >= 20 and len(allMarks) > startAt + 20:
            m.append((MenuLabel('UI/Common/More'),
                      ('isDynamic', self.GetBookmarkMenu, (startAt + 20, ))))
        if len(m) > 0:
            m.append(None)
        for each in myMarks:
            if each is not None:
                if each.url.find(':/') == -1:
                    each.url = 'http://' + each.url
                m.append((each.name, self.BrowseTo, (each.url, )))

        return m

    def ViewSourceOfUrl(self, url):
        BrowserSourceWindow.Open(browseTo=url)

    def DocumentSource(self):
        url = self.currentTab.GetCurrentURL()
        self.ViewSourceOfUrl(url)

    def OpenBrowserHistory(self):
        if not self.destroyed:
            BrowserHistoryWindow.Open()

    def EditGeneralSettings(self):
        if not self.destroyed:
            wnd = BrowserSettingsWindow.Open()
            wnd.ShowModal()

    def EditBookmarks(self):
        if not self.destroyed:
            wnd = EditBookmarksWindow.Open(bookmarkName=self.sr.caption.text,
                                           url=self.urlInput.GetValue())
            wnd.ShowModal()

    def EditSites(self, what):
        inputUrl = ''
        if self.currentTab is not None:
            inputUrl = self.currentTab.GetCurrentURL()
        WebsiteTrustManagementWindow.Open(initialUrl=inputUrl)

    def DisplayNavigationBar(self, display):
        if display:
            self.navigationBar.state = uiconst.UI_NORMAL
        else:
            self.navigationBar.state = uiconst.UI_HIDDEN

    def DisplayStatusBar(self, display):
        if display:
            self.statusBar.state = uiconst.UI_NORMAL
        else:
            self.statusBar.state = uiconst.UI_HIDDEN

    def DisplayTrusted(self, display):
        if display:
            self.trustIndicatorIcon.state = uiconst.UI_NORMAL
        else:
            self.trustIndicatorIcon.state = uiconst.UI_HIDDEN

    def IsTrusted(self, url):
        return sm.GetService('sites').IsTrusted(url)

    def OnTrustedSitesChange(self, *args):
        if self.reloadingTrustedSites:
            return
        try:
            self.reloadingTrustedSites = True
            self.SetupTrustedSiteHeaders()
        finally:
            self.reloadingTrustedSites = False

    def OnReattachBrowserSession(self, browserSession):
        self.SetupTrustedSiteHeaders()
        self.OnClientFlaggedListsChange()
        if browserSession == self.currentTab:
            self.crashNotifierContainer.state = uiconst.UI_HIDDEN
            self.browserPane.browserSession = browserSession
            browserSession.SetBrowserSurface(self.browserPane.GetSurface(),
                                             self.browserPane._OnSurfaceReady)
            self.browserPane.SetCursor(browserSession.cursorType)
            self.browserPane.ResizeBrowser()

    def _OnBrowserViewCrash(self, tabSession):
        if tabSession == self.currentTab:
            self.crashNotifierContainer.state = uiconst.UI_NORMAL

    def _OnBeginNavigation(self, tabSession, url, frameName):
        tabSession.hint = ''
        if tabSession == self.currentTab:
            self.statusText.text = localization.GetByLabel(
                '/Carbon/UI/Browser/BrowsingTo', url=url)
            self.ShowLoad(doBlock=False)
            self.browserPane.state = uiconst.UI_HIDDEN if self.currentTab.hidden else uiconst.UI_NORMAL

    def _OnBeginLoading(self, tabSession, url, frameName, status, mimeType):
        if frameName is None or frameName == '' or frameName == 'main':
            if tabSession == self.currentTab:
                self.urlInput.SetValue(url)
                if uicore.registry.GetFocus() is self.urlInput:
                    self.urlInput.SelectAll()
                self.DisplayTrusted(self.IsTrusted(url))

    def _OnProcessSecurityInfo(self, tabSession, securityInfo):
        if tabSession == self.currentTab:
            self.ProcessSecurityInfo(securityInfo)

    def _OnChangeCursor(self, tabSession, cursorType):
        if tabSession == self.currentTab:
            self.browserPane.SetCursor(cursorType)

    def ProcessSecurityInfo(self, securityInfo):
        try:
            secInfoInt = int(securityInfo)
        except:
            secInfoInt = 0

        if secInfoInt >= 80:
            self.sslIconContainer.state = uiconst.UI_NORMAL
        else:
            self.sslIconContainer.state = uiconst.UI_HIDDEN

    def _OnFinishLoading(self, tabSession):
        if tabSession == self.currentTab:
            self.statusText.text = tabSession.statusText
            self.SetCaption(tabSession.title)
            self.HideLoad()

    def _OnReceiveTitle(self, tabSession, title, frameName):
        if frameName is None or frameName == '' or frameName == 'main':
            if tabSession.logToHistory:
                uthread.new(self.AddToHistory, tabSession.GetCurrentURL(),
                            tabSession.title, blue.os.GetWallclockTime())
                tabSession.logToHistory = False
            for tabObject in self.tabGroup.sr.tabs:
                if tabObject.sr.args == tabSession:
                    title = localization.uiutil.PrepareLocalizationSafeString(
                        title)
                    tabObject.SetLabel(title, hint=title)
                    break

            if tabSession == self.currentTab:
                self.SetCaption(title)

    def SetCaption(self, caption):
        captionString = localization.uiutil.PrepareLocalizationSafeString(
            StripTags(caption)[:50])
        Window.SetCaption(self, captionString)

    def AddToHistory(self, url, title, ts):
        sm.GetService('urlhistory').AddToHistory(url, title, ts)
        w = BrowserHistoryWindow.GetIfOpen()
        if w:
            w.LoadHistory()

    def _OnChangeTooltip(self, tabSession, tooltip):
        self.browserPane.hint = tooltip

    def _OnChangeTargetURL(self, tabSession, url):
        if tabSession == self.currentTab:
            self.statusText.text = url

    def _OnJavascriptPrompt(self, tabSession, messageText):
        uthread.new(self._ShowAlert, messageText)

    def _ShowAlert(self, messageText):
        escapedText = cgi.escape(unicode(messageText))
        sm.GetService('gameui').MessageBox(
            str(escapedText),
            title=localization.GetByLabel('UI/Browser/JavaScriptAlert'),
            buttons=uiconst.OK,
            modal=True)

    def SetBrowserFocus(self):
        uicore.registry.SetFocus(self.browserPane)

    def AddTab(self, tabUrl=None):
        newTab = browser.BrowserSession()
        newTab.Startup('%s_%d' % (self.name, self.nextTabID),
                       initialUrl=tabUrl,
                       browserEventHandler=self)
        self.nextTabID += 1
        urlToBrowseTo = newTab.GetCurrentURL()
        newTab.BrowseTo(urlToBrowseTo)
        self.tabs.append(newTab)
        self.ReloadTabs(selectTab=-1)

    def AddTabButton(self, *args):
        self.AddTab()

    def CloseTab(self, tabID):
        if len(self.tabs) < 2:
            return
        dyingTab = None
        selectTab = -1
        for i in xrange(len(self.tabs)):
            if self.tabs[i].name == tabID:
                if self.tabs[i].name == self.currentTab.name:
                    nextIdx = i if i < len(self.tabs) - 1 else i - 1
                    selectTab = nextIdx
                dyingTab = self.tabs.pop(i)
                dyingTab.Cleanup()
                break

        self.ReloadTabs(selectTab=selectTab)

    def CloseTabButton(self, *args):
        if self.currentTab is not None:
            self.CloseTab(self.currentTab.name)

    def ReloadTabs(self, selectTab=None):
        if not self.tabs or len(self.tabs) < 1:
            return
        tabs = []
        for tab in self.tabs:
            tabData = Bunch()
            tabData.label = tab.title
            tabData.hint = tab.title
            tabData.code = self
            tabData.args = tab
            tabData.panel = None
            tabs.append(tabData)

        if getattr(self, 'tabGroup', None):
            tabGroup = self.tabGroup
        else:
            import uicontrols
            tabGroup = uicontrols.TabGroup(name='tabparent',
                                           parent=self.tabBar,
                                           minTabsize=50,
                                           maxTabsize=200,
                                           tabMenuMargin=8,
                                           align=uiconst.TOBOTTOM)
            self.tabGroup = tabGroup
        tabGroup.LoadTabs(tabs, autoselecttab=0)
        if self.currentTab is None:
            self.currentTab = self.tabs[0]
        else:
            self.currentTab.SetBrowserSurface(None, None)
            if selectTab is not None:
                self.currentTab = self.tabs[selectTab]
        tabGroup.ShowPanelByName(self.currentTab.title)

    def GetTabMenu(self, uiTab, *args):
        tabSession = uiTab.sr.args
        ops = [(localization.GetByLabel('UI/Browser/NewTab'), self.AddTab, [])]
        if len(self.tabs) > 1:
            ops.append((localization.GetByLabel('UI/Browser/CloseTab'),
                        self.CloseTab, (tabSession.name, )))
        return ops

    def LoadTabPanel(self, tabBrowserSession, container, tabgroup):
        if self.currentTab is not None:
            self.currentTab.SetBrowserSurface(None, None)
        self.statusText.text = tabBrowserSession.statusText
        self.urlInput.SetValue(tabBrowserSession.GetCurrentURL())
        self.ProcessSecurityInfo(tabBrowserSession.securityInfo)
        self.SetCaption(tabBrowserSession.title)
        if tabBrowserSession.loading:
            self.ShowLoad(doBlock=False)
        else:
            self.HideLoad()
        self.DisplayTrusted(self.IsTrusted(tabBrowserSession.GetCurrentURL()))
        self.currentTab = tabBrowserSession
        self.browserPane.browserSession = tabBrowserSession
        tabBrowserSession.SetBrowserSurface(self.browserPane.GetSurface(),
                                            self.browserPane._OnSurfaceReady)
        self.browserPane.SetCursor(self.currentTab.cursorType)
        self.browserPane.ResizeBrowser()
        self.browserPane.state = uiconst.UI_HIDDEN if self.currentTab.hidden else uiconst.UI_NORMAL
        if self.currentTab.IsAlive():
            self.crashNotifierContainer.state = uiconst.UI_HIDDEN
        else:
            self.crashNotifierContainer.state = uiconst.UI_NORMAL