def Load(self):
        self.Flush()
        toggleButtonCont = Container(name='btnGroupCont',
                                     parent=self,
                                     align=uiconst.TOTOP,
                                     height=45)
        btnGroup = ToggleButtonGroup(parent=toggleButtonCont,
                                     align=uiconst.CENTER,
                                     height=toggleButtonCont.height,
                                     width=330,
                                     padding=(10, 4, 10, 3),
                                     callback=self.LoadCertificateSkillsLevel)
        btns = ((1, 'res:/UI/Texture/icons/79_64_2.png'),
                (2, 'res:/UI/Texture/icons/79_64_3.png'),
                (3, 'res:/UI/Texture/icons/79_64_4.png'),
                (4, 'res:/UI/Texture/icons/79_64_5.png'),
                (5, 'res:/UI/Texture/icons/79_64_6.png'))
        for level, iconPath in btns:
            hint = localization.GetByLabel(
                'UI/InfoWindow/CertificateLevelButtonHint', level=level)
            btnGroup.AddButton(btnID=level,
                               iconPath=iconPath,
                               iconSize=32,
                               hint=hint)

        self.masteryTimeLabel = EveLabelMediumBold(name='masteryTimeLabel',
                                                   parent=self,
                                                   align=uiconst.TOTOP,
                                                   top=10,
                                                   left=10)
        self.scroll = Scroll(name='certSkillScroll',
                             parent=self,
                             padding=const.defaultPadding)
        cert = sm.GetService('certificates').GetCertificate(self.certificateID)
        btnGroup.SelectByID(max(1, cert.GetLevel()))
Beispiel #2
0
    def Load(self):
        self.Flush()
        topCont = ContainerAutoSize(parent=self,
                                    align=uiconst.TOTOP,
                                    padding=(0, 2, 0, 2))
        btnGroup = ToggleButtonGroup(parent=topCont,
                                     align=uiconst.CENTER,
                                     height=38,
                                     width=248,
                                     callback=self.LoadActivity)
        for activityID in industry.ACTIVITIES:
            isDisabled = activityID not in self.bpData.activities
            color = industryUIConst.GetActivityColor(activityID)
            color = color[:3] + (0.5, )
            btnGroup.AddButton(
                activityID,
                iconPath=industryUIConst.ACTIVITY_ICONS_LARGE[activityID],
                iconSize=26,
                colorSelected=color,
                isDisabled=isDisabled,
                btnClass=ActivityToggleButtonGroupButton,
                activityID=activityID)

        self.activityNameLabel = EveLabelMediumBold(name='label',
                                                    parent=self,
                                                    align=uiconst.TOTOP,
                                                    padding=(6, 0, 0, 0))
        self.scroll = Scroll(parent=self, padding=const.defaultPadding)
        activityID = self.GetSelectedActivityID(activityID)
        btnGroup.SelectByID(activityID)
    def Load(self):
        self.Flush()
        toggleButtonCont = Container(name='btnGroupCont',
                                     parent=self,
                                     align=uiconst.TOTOP,
                                     height=45)
        btnGroup = ToggleButtonGroup(parent=toggleButtonCont,
                                     align=uiconst.CENTER,
                                     height=toggleButtonCont.height,
                                     width=330,
                                     padding=(10, 4, 10, 3),
                                     callback=self.LoadMasteryLevel)
        for level, iconPath in BUTTONS:
            hint = localization.GetByLabel(
                'UI/InfoWindow/MasteryLevelButtonHint', level=level)
            if level == 5:
                color = Color(*shipTreeConst.COLOR_MASTERED).SetBrightness(
                    0.2).GetRGBA()
            else:
                color = Color(
                    *shipTreeConst.COLOR_BG).SetBrightness(0.35).GetRGBA()
            btnGroup.AddButton(btnID=level,
                               iconPath=iconPath,
                               iconSize=45,
                               hint=hint,
                               colorSelected=color)

        self.masteryHeader = Container(name='masteryHeader',
                                       parent=self,
                                       align=uiconst.TOTOP,
                                       height=25)
        self.settingsMenu = uicls.UtilMenu(
            menuAlign=uiconst.TOPLEFT,
            parent=self.masteryHeader,
            align=uiconst.BOTTOMLEFT,
            left=4,
            GetUtilMenu=self.GetSettingsMenu,
            texturePath='res:/UI/Texture/SettingsCogwheel.png',
            width=16,
            height=16,
            iconSize=18)
        self.masteryTimeLabel = EveLabelMediumBold(name='masteryTimeLabel',
                                                   parent=self.masteryHeader,
                                                   align=uiconst.BOTTOMLEFT,
                                                   left=24)
        self.masteryScroll = Scroll(name='masteryScroll',
                                    parent=self,
                                    padding=const.defaultPadding)
        level = sm.GetService('certificates').GetCurrCharMasteryLevel(
            self.typeID)
        level = max(level, 1)
        btnGroup.SelectByID(level)
Beispiel #4
0
 def ApplyAttributes(self, attributes):
     self.viewState = sm.GetService('viewState')
     if not settings.user.ui.Get('stationservicebtns', 1):
         minWidth = BIGBUTTONSIZE + (BIGBUTTONSIZE + BUTTONGAP) * 3 + 14
         minHeight = 495
     else:
         minWidth = SMALLBUTTONSIZE + (SMALLBUTTONSIZE + BUTTONGAP) * 5 + 10
         minHeight = 470
     self.default_minSize = (minWidth, minHeight)
     Window.ApplyAttributes(self, attributes)
     self.stationSvc = sm.GetService('station')
     self.guestScroll = None
     self.sr.serviceAccessCache = {}
     self.SetWndIcon(None)
     self.HideHeader()
     self.scope = 'station'
     self.MakeUnKillable()
     self.MakeUnstackable()
     self.SetTopparentHeight(0)
     main = self.sr.main
     main.clipChildren = True
     self.corpLogoParent = Container(name='corpLogoParent', align=uiconst.TOTOP, height=160, parent=main)
     self.corpName = CaptionLabel(parent=main, align=uiconst.TOTOP, name='corpName', uppercase=False)
     self.undockparent = Container(name='undockparent', align=uiconst.TOTOP, height=78, parent=main)
     self.AddCQButton(parent=self.undockparent)
     self.AddUndockButton(parent=self.undockparent)
     EveLabelMedium(text=localization.GetByLabel('UI/Station/StationServices'), align=uiconst.TOTOP, parent=main, bold=True, padding=(6, 6, 6, 0))
     self.serviceButtons = FlowContainer(name='serviceButtons', align=uiconst.TOTOP, parent=main, contentSpacing=(BUTTONGAP, BUTTONGAP), padding=(6, 6, 3, 6))
     btnGroup = ToggleButtonGroup(name='btnGroup', parent=main, align=uiconst.TOTOP, height=32, padding=(6, 6, 6, 6), idx=-1, callback=self.OnButtonGroupSelection)
     self.mainButtonGroup = btnGroup
     self.guestsPanel = Container(name=GUESTSPANEL, parent=main, padding=const.defaultPadding)
     self.quickFilter = QuickFilterEdit(name='quickFilterEdit', parent=self.guestsPanel)
     self.quickFilter.ReloadFunction = lambda : self.ShowGuests()
     self.guestScroll = BasicDynamicScroll(parent=self.guestsPanel, padTop=const.defaultPadding + self.quickFilter.height)
     guestSettingsMenu = UtilMenu(menuAlign=uiconst.TOPRIGHT, parent=self.guestsPanel, align=uiconst.TOPRIGHT, GetUtilMenu=self.SettingMenu, texturePath='res:/UI/Texture/SettingsCogwheel.png', width=18, height=18, iconSize=18)
     self.userType = settings.user.ui.Get('guestCondensedUserList', False)
     self.agentsPanel = Container(name=AGENTSPANEL, parent=main, padding=const.defaultPadding)
     self.agentFinderBtn = Button(label=localization.GetByLabel('UI/AgentFinder/AgentFinder'), parent=self.agentsPanel, align=uiconst.CENTERTOP, func=uicore.cmd.OpenAgentFinder)
     self.agentScroll = Scroll(parent=self.agentsPanel, padTop=const.defaultPadding + self.agentFinderBtn.height)
     self.officesPanel = Container(name=OFFICESPANEL, parent=main, padding=const.defaultPadding)
     self.officesButtons = FlowContainer(name='officesButtons', align=uiconst.TOTOP, parent=self.officesPanel, contentSpacing=(4, 4), centerContent=True)
     self.officesScroll = Scroll(parent=self.officesPanel, padTop=const.defaultPadding)
     agentsButton = btnGroup.AddButton(AGENTSPANEL, '<center>' + localization.GetByLabel('UI/Station/Lobby/Agents'), self.agentsPanel, btnClass=LobbyToggleButtonGroupButton, hint=localization.GetByLabel('Tooltips/StationServices/AgentsTab_descrtiption'))
     agentsButton.name = 'stationInformationTabAgents'
     guestsButton = btnGroup.AddButton(GUESTSPANEL, '<center>' + localization.GetByLabel('UI/Station/Lobby/Guests'), self.guestsPanel, btnClass=LobbyToggleButtonGroupButton, hint=localization.GetByLabel('Tooltips/StationServices/GuestsTab_description'))
     guestsButton.counter = CounterBox(parent=guestsButton, align=uiconst.TOPRIGHT, left=2, top=-5)
     self.guestsButton = guestsButton
     btnGroup.AddButton(OFFICESPANEL, '<center>' + localization.GetByLabel('UI/Station/Lobby/Offices'), self.officesPanel, btnClass=LobbyToggleButtonGroupButton, hint=localization.GetByLabel('Tooltips/StationServices/OfficesTab_description'))
     activePanel = settings.user.ui.Get('stationsLobbyTabs', AGENTSPANEL)
     if settings.char.windows.Get('dockshipsanditems', 0):
         self.inventoryPanel = Container(name=INVENTORYPANEL, parent=main)
         self.sr.shipsContainer = Container(parent=self.inventoryPanel, state=uiconst.UI_HIDDEN, padding=const.defaultPadding)
         self.sr.itemsContainer = Container(parent=self.inventoryPanel, state=uiconst.UI_HIDDEN, padding=const.defaultPadding)
         tabs = [[localization.GetByLabel('UI/Station/Ships'),
           self.sr.shipsContainer,
           self,
           'lobby_ships'], [localization.GetByLabel('UI/Station/Items'),
           self.sr.itemsContainer,
           self,
           'lobby_items']]
         self.inventoryTabs = TabGroup(name='inventoryPanel', parent=self.inventoryPanel, idx=0)
         self.inventoryTabs.Startup(tabs, 'lobbyInventoryPanel', autoselecttab=True, UIIDPrefix='lobbyInventoryPanelTab')
         self.invButton = btnGroup.AddButton(INVENTORYPANEL, '<center>' + localization.GetByLabel('UI/Station/Lobby/Hangars'), self.inventoryPanel, btnClass=LobbyToggleButtonGroupButton, hint='<b>%s</b><br>%s' % (localization.GetByLabel('Tooltips/StationServices/Hangars'), localization.GetByLabel('Tooltips/StationServices/Hangars_description')))
     elif activePanel == INVENTORYPANEL:
         activePanel = AGENTSPANEL
     btnGroup.SelectByID(activePanel)
     myDefaultView = 'hangar' if session.userid % 2 == 1 else 'station'
     curView = collections.namedtuple('FakeViewInfo', ['name'])(settings.user.ui.Get('defaultDockingView', myDefaultView))
     self.OnPrimaryViewChanged(curView, curView)
     self.LoadOwnerInfo()
     self.LoadServiceButtons()
     if self.destroyed:
         return
     sm.RegisterNotify(self)
     self.UpdateGuestTabText()
Beispiel #5
0
class LeftPanel(Container):
    default_clipChildren = True
    default_padBottom = 4
    default_padLeft = 10
    __notifyevents__ = [
        'OnFittingsUpdated', 'OnFittingDeleted', 'OnSkillFilteringUpdated',
        'OnSlotDblClicked'
    ]

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        self.fittingSvc = sm.GetService('fittingSvc')
        self.configName = attributes.configName
        self.controller = attributes.controller
        self.ChangeSignalConnection()
        self.loaded = False
        padding = 0
        self.ammoShowingForType = None
        btnCont = FlowContainer(parent=self,
                                align=uiconst.TOBOTTOM,
                                contentAlignment=CONTENT_ALIGN_RIGHT,
                                padTop=4,
                                padRight=0,
                                contentSpacing=uiconst.BUTTONGROUPMARGIN)
        self.fitBtn = Button(parent=btnCont,
                             label='Fit Ship',
                             func=self.FitShip,
                             align=uiconst.NOALIGN)
        self.builtShipBtn = Button(
            parent=btnCont,
            label=GetByLabel('UI/Fitting/FittingWindow/BuildShip'),
            func=self.BuildShip,
            align=uiconst.NOALIGN)
        self.saveBtn = Button(
            parent=btnCont,
            label=GetByLabel('UI/Fitting/FittingWindow/SaveFitAs'),
            func=self.SaveFitting,
            align=uiconst.NOALIGN)
        SetFittingTooltipInfo(targetObject=self.saveBtn,
                              tooltipName='SaveFitting',
                              includeDesc=False)
        self.AdjustButtons()
        self.btnGroup = ToggleButtonGroup(name='fittingToggleBtnGroup',
                                          parent=self,
                                          align=uiconst.TOTOP,
                                          callback=self.BrowserSelected,
                                          height=40,
                                          idx=-1)
        self.AddExportImportMenu()
        self.AddSearchFields()
        self.AddFilterCont()
        self.hwBrowserBtns = self.AddHardwareSelcetionCont()
        self.AddFittingFilterButtons()
        self.hardwareFilterBtns = self.AddHardwareFilterButtons()
        self.AddChargeFilterButtons()
        self.browserBtns = {}
        self.moduleChargeButtons = {}
        for btnID, labelPath, iconPath, dblClickCallback in (
            (BROWSE_FITTINGS, 'UI/Fitting/FittingWindow/ShipAndFittings',
             'res:/UI/Texture/classes/Fitting/tabFittings.png',
             self.LoadFittingSetup),
            (BROWSE_HARDWARE, 'UI/Fitting/FittingWindow/Hardware',
             'res:/UI/Texture/classes/Fitting/tabHardware.png', None)):
            btn = self.btnGroup.AddButton(btnID,
                                          GetByLabel(labelPath),
                                          iconPath=iconPath,
                                          btnClass=ToggleButtonGhost)
            self.browserBtns[btnID] = btn
            if dblClickCallback:
                btn.OnDblClick = dblClickCallback

        self.scroll = Scroll(parent=self,
                             align=uiconst.TOALL,
                             padding=(padding, 2, padding, 0))
        self.scroll.sr.content.OnDropData = self.OnDropData
        sm.RegisterNotify(self)

    def ChangeSignalConnection(self, connect=True):
        signalAndCallback = [
            (self.controller.on_new_itemID, self.OnSimulatedShipLoaded),
            (self.controller.on_slots_changed, self.OnSlotsChanged),
            (self.controller.on_simulation_state_changed,
             self.OnSimulationStateChanged)
        ]
        ChangeSignalConnect(signalAndCallback, connect)

    def AddExportImportMenu(self):
        m = UtilMenu(
            menuAlign=uiconst.BOTTOMLEFT,
            parent=self,
            align=uiconst.BOTTOMLEFT,
            label=GetByLabel('UI/Fitting/FittingWindow/ImportAndExport'),
            labelAlign=uiconst.CENTERRIGHT,
            GetUtilMenu=self.GetExportImportMenu,
            texturePath='res:/ui/texture/icons/73_16_50.png',
            left=-8)

    def GetExportImportMenu(self, menuParent, *args):
        if boot.region != 'optic':
            text = GetByLabel(
                'UI/Fitting/FittingWindow/FittingManagement/ImportFromClipboard'
            )
            hint = GetByLabel(
                'UI/Fitting/FittingWindow/FittingManagement/ImportFromClipboardHint'
            )
            menuParent.AddIconEntry(
                icon=ACTION_ICON,
                text=text,
                hint=hint,
                callback=sm.GetService(
                    'fittingSvc').ImportFittingFromClipboard)
            menuParent.AddDivider()
        menuParent.AddIconEntry(icon=ACTION_ICON,
                                text=GetByLabel('UI/Commands/Import'),
                                callback=self.ImportFittings)
        menuParent.AddIconEntry(icon=ACTION_ICON,
                                text=GetByLabel('UI/Commands/Export'),
                                callback=self.ExportFittings)

    def ImportFittings(self, *args):
        ImportFittingsWindow.Open()

    def ExportFittings(self, *args):
        isCorp = False
        ExportFittingsWindow.Open(isCorp=isCorp)

    def Load(self):
        if self.loaded:
            return
        self.hardwareBtnGroup.SelectByID(
            settings.user.ui.Get(HW_BTN_ID_CONFIG, BROWSE_MODULES))
        self.btnGroup.SelectByID(
            settings.user.ui.Get(BROWSER_BTN_ID_CONFIG, BROWSE_FITTINGS))
        self.loaded = True

    @telemetry.ZONE_METHOD
    def AddSearchFields(self):
        self.searchparent = SearchCont(name='searchparent',
                                       parent=self,
                                       align=uiconst.TOTOP,
                                       height=18,
                                       padding=(0, 4, 0, 4),
                                       searchFunc=self.Search)

    def ReloadBrowser(self):
        btnID = settings.user.ui.Get(BROWSER_BTN_ID_CONFIG, BROWSE_FITTINGS)
        self.BrowserSelected(btnID)

    def OnSlotDblClicked(self, flagID, *args):
        SetSettingForFilterBtns(flagID, self.hardwareFilterBtns)
        btn = self.browserBtns.get(BROWSE_HARDWARE)
        if not btn.IsSelected():
            btn.OnClick()
        hwBtn = self.hwBrowserBtns.get(BROWSE_MODULES)
        hwBtn.OnClick()

    @telemetry.ZONE_METHOD
    def BrowserSelected(self, btnID, *args):
        settings.user.ui.Set(BROWSER_BTN_ID_CONFIG, btnID)
        if btnID == BROWSE_FITTINGS:
            self.chargeFilterCont.display = False
            self.hardwareFilterCont.display = False
            self.hardwarSelectionCont.display = False
            self.searchparent.ChangeSearchMode(FITTING_MODE)
            self.ShowOrHideElements(display=False)
            self.LoadFittings()
        elif btnID == BROWSE_HARDWARE:
            self.hardwarSelectionCont.display = True
            self.searchparent.ChangeSearchMode(HARDWARE_MODE)
            self.AddHardwareForChargesButtons()
            self.ShowOrHideElements(display=True)
            self.LoadHardware()

    def ShowOrHideElements(self, display=True):
        self.hardwareFilterCont.display = display
        self.fittingFilterCont.display = not display
        self.fittingFilterCont.display = not display

    def OnFittingDeleted(self, ownerID, fitID):
        self.OnFittingsUpdated()

    def OnFittingsUpdated(self):
        if settings.user.ui.Get(BROWSER_BTN_ID_CONFIG,
                                BROWSE_FITTINGS) == BROWSE_FITTINGS:
            self.ReloadBrowser()

    def OnSkillFilteringUpdated(self):
        if IsHardwareTabSelected():
            self.ReloadBrowser()

    def LoadFittings(self):
        scrolllist = self.GetFittingScrolllist()
        self.searchparent.display = True
        self.scroll.Load(contentList=scrolllist, scrolltotop=0)

    @telemetry.ZONE_METHOD
    def LoadHardware(self):
        self.scroll.HideLoading()
        self.chargeFilterCont.display = False
        self.hardwareFilterCont.display = False
        if IsHardwareTabSelected() and IsChargeTabSelected():
            self.searchparent.display = False
            self.AddHardwareForChargesButtons()
            return
        self.searchparent.display = True
        self.hardwareFilterCont.display = True
        self.ChangeResourceBtn()
        uthread.new(self.LoadHardware_thread)

    @telemetry.ZONE_METHOD
    def LoadHardware_thread(self):
        self.scroll.Load(contentList=[])
        self.scroll.ShowLoading()
        resourceBtn = None
        if settings.user.ui.Get('fitting_filter_hardware_resources', False):
            resourceBtn = self.hardwareFilterBtns.get(BTN_TYPE_RESOURCES, None)
            if resourceBtn:
                resourceBtn.ShowLoading()
        scrolllist = self._GetHardwareScrollList()
        if IsModuleTabSelected() and IsHardwareTabSelected():
            self.scroll.Load(contentList=scrolllist,
                             scrolltotop=0,
                             noContentHint=GetByLabel(
                                 'UI/Fitting/FittingWindow/NoModulesFound'))
        self.scroll.HideLoading()
        if resourceBtn:
            resourceBtn.HideLoading()

    def _GetHardwareScrollList(self):
        if settings.user.ui.Get('fitting_hardwareSearchField', ''):
            scrolllist = self.GetSearchResults()
        else:
            hardwareBrowserListProvider = HardwareBrowserListProvider(
                self.fittingSvc.searchFittingHelper, self.OnDropData)
            scrolllist = hardwareBrowserListProvider.GetGroupListForBrowse(
                marketGroupID=const.marketCategoryShipEquipment)
            scrolllist += hardwareBrowserListProvider.GetGroupListForBrowse(
                marketGroupID=const.marketCategoryShipModifications)
            scrolllist += hardwareBrowserListProvider.GetGroupListForBrowse(
                marketGroupID=const.marketCategoryDrones)
            scrolllist += self.GetStructureGroup()
        return scrolllist

    def GetStructureGroup(self):
        from eve.client.script.ui.control import entries as listentry
        label = 'Structure'
        data = {
            'GetSubContent': self.GetStructureGroupSubContent,
            'label': label,
            'id': ('ghostfitting_group', 'structure'),
            'showlen': 0,
            'sublevel': 0,
            'showicon': 'hide',
            'state': 'locked',
            'BlockOpenWindow': True
        }
        return [listentry.Get('Group', data=data)]

    def GetStructureGroupSubContent(self, nodedate, *args):
        hardwareBrowserListProvider = HardwareBrowserListProvider(
            self.fittingSvc.searchFittingHelper, self.OnDropData)
        scrolllist = hardwareBrowserListProvider.GetGroupListForBrowse(
            marketGroupID=const.marketCategoryStructureEquipment, sublevel=1)
        scrolllist += hardwareBrowserListProvider.GetGroupListForBrowse(
            marketGroupID=const.marketCategoryStructureModifications,
            sublevel=1)
        return scrolllist

    def ExitSimulation(self, *args):
        sm.GetService('fittingSvc').SetSimulationState(False)
        shipID = GetActiveShip()
        sm.GetService('ghostFittingSvc').SendOnSimulatedShipLoadedEvent(
            shipID, None)

    def LoadCurrentShip(self, *args):
        sm.GetService('ghostFittingSvc').LoadCurrentShip()

    def SaveFitting(self, *args):
        return self.fittingSvc.SaveFitting()

    def FitShip(self, *args):
        fittingSvc = sm.GetService('fittingSvc')
        if not fittingSvc.IsShipSimulated():
            return
        clientDL = sm.GetService('clientDogmaIM').GetDogmaLocation()
        fittingDL = sm.GetService('clientDogmaIM').GetFittingDogmaLocation()
        actualShip = clientDL.GetShip()
        simulatedShip = fittingDL.GetShip()
        if actualShip.typeID != simulatedShip.typeID:
            UserError('CustomNotify',
                      {'notify': "Actual ship and simulated ship don't match"})
        fitting = fittingSvc.GetFittingForCurrentInWnd(
            putModuleAmmoInHangar=False)
        failedToLoad = fittingSvc.LoadFitting(fitting,
                                              getFailedDict=True) or {}
        failedToLoadCounter = Counter({x[0]: x[1] for x in failedToLoad})
        simulated_chargeTypesAndQtyByFlagID = fittingSvc.GetChargesAndQtyByFlag(
            simulatedShip.GetFittedItems().values())
        ammoFailedToLoad = fittingSvc.RemoveAndLoadChargesFromSimulatedShip(
            clientDL, actualShip.itemID, simulated_chargeTypesAndQtyByFlagID)
        faildToLoadInfo = failedToLoadCounter + Counter(ammoFailedToLoad)
        if faildToLoadInfo:
            self.OpenBuyAllBox(faildToLoadInfo)

    def OpenBuyAllBox(self, faildToLoadInfoCounters):
        faildToLoadInfo = dict(faildToLoadInfoCounters)
        BuyAllMessageBox.Open(
            missingText=GetByLabel('UI/Fitting/MissingItemsHeader'),
            faildToLoadInfo=faildToLoadInfo)

    def BuildShip(self, *args):
        fitting = sm.GetService('fittingSvc').GetFittingForCurrentInWnd()
        if not fitting.fitData:
            eve.Message('uiwarning03')
            return
        wnd = OpenOrLoadMultiFitWnd(fitting)
        wnd.Maximize()

    def GetFittingScrolllist(self, *args):
        fittingListProvider = FittingBrowserListProvider(self.OnDropData)
        return fittingListProvider.GetFittingScrolllist()

    @telemetry.ZONE_METHOD
    def Search(self, settingConfig, searchString):
        settings.user.ui.Set(settingConfig, searchString)
        self.ReloadBrowser()

    def LoadFittingSetup(self, *args):
        if sm.GetService('fittingSvc').HasLegacyClientFittings():
            wnd = ImportLegacyFittingsWindow.Open()
        else:
            wnd = FittingMgmt.Open()
        if wnd is not None and not wnd.destroyed:
            wnd.Maximize()

    def OnSimulatedShipLoaded(self, *args):
        self.AdjustButtons()

    def AdjustButtons(self):
        self._SetBtnStates()
        self.fitBtn.display = False
        self.builtShipBtn.display = False
        if self.controller.IsSimulated():
            if sm.GetService('ghostFittingSvc').IsSimulatingCurrentShipType():
                self.fitBtn.display = True
            else:
                self.builtShipBtn.display = True

    def _SetBtnStates(self):
        shipItem = self.controller.dogmaLocation.GetShip()
        shipTypeID = shipItem.typeID
        self.fitBtn.Disable()
        self.builtShipBtn.Disable()
        if IsDocked():
            self.fitBtn.Enable()
            if not IsModularShip(shipTypeID):
                self.builtShipBtn.Enable()

    @telemetry.ZONE_METHOD
    def AddHardwareForChargesButtons(self):
        self.chargeFilterCont.display = True
        self.hardwareFilterCont.display = False
        self.chargeFilterCont.Flush()
        Container(name='scaler',
                  parent=self.chargeFilterCont,
                  pos=(0, 0, 0, 30),
                  align=uiconst.NOALIGN)
        hardware = self.GetHardware()
        self.moduleChargeButtons.clear()
        infoSvc = sm.GetService('info')
        for moduleTypeID in hardware:
            chargeTypeIDs = infoSvc.GetUsedWithTypeIDs(moduleTypeID)
            if not chargeTypeIDs:
                continue
            moduleName = evetypes.GetName(moduleTypeID)
            cont = ModuleChargeButton(parent=self.chargeFilterCont,
                                      pos=(0, 0, 30, 30),
                                      align=uiconst.NOALIGN,
                                      state=uiconst.UI_NORMAL,
                                      moduleTypeID=moduleTypeID,
                                      onClickFunc=self.OnHardwareIconClicked,
                                      usedWithChargesIDs=chargeTypeIDs)
            cont.hint = moduleName
            self.moduleChargeButtons[moduleTypeID] = cont

        btnSelected = self.moduleChargeButtons.get(self.ammoShowingForType,
                                                   None)
        if not btnSelected and self.moduleChargeButtons:
            btnSelected = self.moduleChargeButtons.values()[0]
        if btnSelected:
            btnSelected.OnClick()
        else:
            self.scroll.Load(contentList=[],
                             noContentHint=GetByLabel(
                                 'UI/Fitting/FittingWindow/NoChargesFound'))

    def OnHardwareIconClicked(self, moduleTypeID, chargeTypeIDs):
        self.ammoShowingForType = moduleTypeID
        for btn in self.moduleChargeButtons.itervalues():
            if btn.GetModuleType() == moduleTypeID:
                btn.SetSelected()
            else:
                btn.SetDeselected()

        self.LoadChargesScrollList(moduleTypeID, chargeTypeIDs)

    def LoadChargesScrollList(self, moduleTypeID, chargeTypeIDs):
        provider = ChargeBrowserListProvider(dblClickFunc=self.TryFit,
                                             onDropDataFunc=self.OnDropData,
                                             reloadFunc=self.ReloadBrowser)
        scrolllist = provider.GetChargesScrollList(moduleTypeID, chargeTypeIDs)
        self.scroll.Load(contentList=scrolllist,
                         noContentHint=GetByLabel(
                             'UI/Fitting/FittingWindow/NoChargesFound'))

    def TryFit(self, entry, moduleTypeID, ammoTypeID):
        ghostFittingSvc = sm.GetService('ghostFittingSvc')
        ghostFittingSvc.TryFitAmmoTypeToAll(moduleTypeID, ammoTypeID)

    def GetHardware(self):
        dogmaLocation = self.controller.GetDogmaLocation()
        shipDogmaItem = dogmaLocation.GetShip()
        hardwareDict = {}
        for module in shipDogmaItem.GetFittedItems().itervalues():
            typeID = module.typeID
            if self.IsCharge(typeID):
                continue
            flagID = module.flagID
            flagInHardware = hardwareDict.get(typeID, None)
            if flagInHardware:
                flagID = min(flagInHardware, flagID)
            hardwareDict[typeID] = flagID

        hardwareList = [(flagID, typeID)
                        for typeID, flagID in hardwareDict.iteritems()]
        return SortListOfTuples(hardwareList, reverse=True)

    def IsCharge(self, typeID):
        return evetypes.GetCategoryID(typeID) == const.categoryCharge

    def OnSlotsChanged(self):
        if not IsHardwareTabSelected():
            return
        if not IsChargeTabSelected():
            return
        self.AddHardwareForChargesButtons()

    def OnSimulationStateChanged(self, inSimulation):
        if IsModuleTabSelected() and IsHardwareTabSelected(
        ) and settings.user.ui.Get('fitting_filter_hardware_resources', False):
            self.LoadHardware()
        self.ChangeResourceBtn()

    def OnDropData(self, dragObj, nodes):
        node = nodes[0]
        itemKey = node.itemID
        ghostFittingSvc = sm.GetService('ghostFittingSvc')
        ghostFittingSvc.UnfitModule(itemKey)
        ghostFittingSvc.SendFittingSlotsChangedEvent()

    @telemetry.ZONE_METHOD
    def AddFilterCont(self):
        self.filterCont = ContainerAutoSize(name='filterCont',
                                            parent=self,
                                            align=uiconst.TOTOP,
                                            padding=(0, 0, 0, 6))

    @telemetry.ZONE_METHOD
    def AddHardwareSelcetionCont(self):
        self.hardwarSelectionCont = Container(name='hardwarSelectionCont',
                                              parent=self,
                                              align=uiconst.TOTOP,
                                              height=20,
                                              padding=(0, 4, 0, 4))
        btnDict = {}
        self.hardwareBtnGroup = ToggleButtonGroup(
            name='fittingToggleBtnGroup',
            parent=self.hardwarSelectionCont,
            align=uiconst.TOTOP,
            callback=self.ChangeHardwareGroupSelected,
            height=20,
            idx=-1)
        for btnID, label in ((BROWSE_MODULES,
                              'UI/Fitting/FittingWindow/Modules'),
                             (BROWSE_CHARGES,
                              'UI/Fitting/FittingWindow/Charges')):
            btn = self.hardwareBtnGroup.AddButton(btnID,
                                                  GetByLabel(label),
                                                  btnClass=ToggleButtonGhost)
            btnDict[btnID] = btn

        return btnDict

    def ChangeHardwareGroupSelected(self, btnID, *args):
        settings.user.ui.Set(HW_BTN_ID_CONFIG, btnID)
        self.LoadHardware()

    @telemetry.ZONE_METHOD
    def AddHardwareFilterButtons(self):
        self.hardwareFilterCont = FlowContainer(
            parent=self.filterCont,
            align=uiconst.TOTOP,
            contentAlignment=CONTENT_ALIGN_LEFT,
            padTop=4,
            contentSpacing=uiconst.BUTTONGROUPMARGIN)
        return AddHardwareButtons(self.hardwareFilterCont,
                                  'fitting_filter_hardware_%s',
                                  self.HardwareFilterClicked,
                                  self.GetHardwareMenu,
                                  hintFunc=self.GetFilterHint)

    @telemetry.ZONE_METHOD
    def AddChargeFilterButtons(self):
        self.chargeFilterCont = FlowContainer(
            parent=self.filterCont,
            align=uiconst.TOTOP,
            contentAlignment=CONTENT_ALIGN_LEFT,
            padTop=4,
            contentSpacing=uiconst.BUTTONGROUPMARGIN)

    @telemetry.ZONE_METHOD
    def AddFittingFilterButtons(self):
        self.fittingFilterCont = FlowContainer(
            name='fittingFilterCont',
            parent=self.filterCont,
            align=uiconst.TOTOP,
            contentAlignment=CONTENT_ALIGN_LEFT,
            padTop=4,
            contentSpacing=uiconst.BUTTONGROUPMARGIN)
        AddFittingFilterButtons(self.fittingFilterCont,
                                'fitting_filter_ship_%s',
                                self.FittingFilterClicked,
                                hintFunc=self.GetFilterHint)

    def FittingFilterClicked(self, filterBtn, buttonType):
        self.FilterButtonClicked(filterBtn)
        self.LoadFittings()

    def HardwareFilterClicked(self, filterBtn, buttonType):
        self.FilterButtonClicked(filterBtn)
        self.LoadHardware()

    def GetHardwareMenu(self, filterBtn):
        m = []
        if filterBtn.buttonType == BTN_TYPE_RESOURCES:
            settingName = 'fitting_filter_resourcesOnOutput'
            onTotalOutput = settings.user.ui.Get(settingName, True)
            if onTotalOutput:
                text = GetByLabel(
                    'UI/Fitting/FittingWindow/FilterResourcesSettingRemaining')
            else:
                text = GetByLabel(
                    'UI/Fitting/FittingWindow/FilterResourcesSettingTotal')
            m += [(text, self.ToggleHardwareSetting, (settingName, ))]
        return m

    def GetFilterHint(self, filterBtn):
        if filterBtn.buttonType == BTN_TYPE_RESOURCES:
            onTotalOutput = settings.user.ui.Get(
                'fitting_filter_resourcesOnOutput', True)
            if onTotalOutput:
                typeOfFiltering = GetByLabel(
                    'UI/Fitting/FittingWindow/FilterResourcesTotal')
            else:
                typeOfFiltering = GetByLabel(
                    'UI/Fitting/FittingWindow/FilterResourcesRemaining')
            hint = GetByLabel(filterBtn.hintLabelPath,
                              typeOfFiltering=typeOfFiltering)
            if not self.controller.IsSimulated():
                hint += '<br><br>%s' % GetByLabel(
                    'UI/Fitting/FittingWindow/OnlyAvailableInSimulation')
            return hint
        elif filterBtn.buttonType == BTN_TYPE_PERSONAL_FITTINGS:
            personalFittings = self.fittingSvc.GetFittings(session.charid)
            numFittings = '(%s/%s)' % (len(personalFittings),
                                       const.maxCharFittings)
            return GetByLabel(filterBtn.hintLabelPath, numFittings=numFittings)
        elif filterBtn.buttonType == BTN_TYPE_CORP_FITTINGS:
            corpFittings = self.fittingSvc.GetFittings(session.corpid)
            numFittings = '(%s/%s)' % (len(corpFittings),
                                       const.maxCorpFittings)
            return GetByLabel(filterBtn.hintLabelPath, numFittings=numFittings)
        else:
            return GetByLabel(filterBtn.hintLabelPath)

    def ToggleHardwareSetting(self, settingName):
        currentValue = settings.user.ui.Get(settingName, True)
        newValue = not currentValue
        settings.user.ui.Set(settingName, newValue)
        self.LoadHardware()

    def FilterButtonClicked(self, filterBtn):
        btnSettingConfig = filterBtn.btnSettingConfig
        filterOn = filterBtn.IsChecked()
        settings.user.ui.Set(btnSettingConfig, filterOn)

    def GetSearchResults(self):
        listProvider = SearchBrowserListProvider(
            self.fittingSvc.searchFittingHelper, self.OnDropData)
        scrolllist = listProvider.GetSearchResults()
        return scrolllist

    def CreateCurrentShipCont(self):
        self.shipCont.Flush()
        Frame(parent=self.shipCont, color=(1, 1, 1, 0.1))
        activeShip = GetActiveShip()
        clientDogmaLocation = sm.GetService('clientDogmaIM').GetDogmaLocation()
        shipDogmaItem = clientDogmaLocation.GetShip()
        shipTypeID = shipDogmaItem.typeID
        icon = Icon(parent=self.shipCont,
                    pos=(0, 0, 40, 40),
                    ignoreSize=True,
                    state=uiconst.UI_DISABLED)
        if self.fittingSvc.IsShipSimulated():
            self.shipCont.OnClick = self.ExitSimulation
            icon.LoadIconByTypeID(shipTypeID)
        else:
            self.shipCont.OnClick = self.LoadCurrentShip
            hologramTexture = inventorycommon.typeHelpers.GetHoloIconPath(
                shipTypeID)
            icon.LoadTexture(hologramTexture)
        shipName = cfg.evelocations.Get(activeShip).name
        text = '%s<br>%s' % (evetypes.GetName(shipTypeID), shipName)
        self.shipnametext = EveLabelMedium(text=text,
                                           parent=self.shipCont,
                                           align=uiconst.TOTOP,
                                           top=2,
                                           padLeft=48)

    def ChangeResourceBtn(self):
        btn = self.hardwareFilterBtns.get(BTN_TYPE_RESOURCES, None)
        if not btn:
            return
        if self.controller.IsSimulated():
            btn.Enable()
        else:
            btn.Disable(opacity=0.3)

    def Close(self):
        try:
            self.ChangeSignalConnection(connect=False)
        except Exception as e:
            log.LogError('Failed at closing fitting left panel, e = ', e)
        finally:
            Container.Close(self)
class ControlCatalogWindow(Window):
    default_windowID = 'ControlCatalogWindow'
    default_topParentHeight = 0
    default_caption = 'UI Control Catalog'
    default_width = 900
    default_height = 800

    def ApplyAttributes(self, attributes):
        Window.ApplyAttributes(self, attributes)
        self.entriesByID = {}
        self.currClassData = None
        self.currSampleNum = 1
        self.numSamples = 0
        uthread.new(self.ConstuctLayout)

    def ConstuctLayout(self):
        self.leftCont = DragResizeCont(
            name='leftCont',
            parent=self.sr.main,
            align=uiconst.TOLEFT_PROP,
            settingsID='ControlCatalogWindowLeftCont')
        self.infoCont = ContainerAutoSize(name='infoCont',
                                          parent=self.sr.main,
                                          align=uiconst.TOTOP,
                                          padding=6)
        self.topCont = DragResizeCont(
            name='topCont',
            parent=self.sr.main,
            align=uiconst.TOTOP_PROP,
            settingsID='ControlCatalogWindowSampleCont',
            minSize=0.3,
            maxSize=0.9,
            defaultSize=0.5,
            clipChildren=True)
        tabCont = ContainerAutoSize(name='tabCont',
                                    parent=self.topCont.mainCont,
                                    align=uiconst.TOBOTTOM)
        self.mainButtonGroup = ButtonGroup(name='mainButtonGroup',
                                           parent=self.sr.main)
        self.editCont = Container(name='editCont', parent=self.sr.main)
        GradientSprite(bgParent=self.leftCont,
                       rotation=0,
                       rgbData=[(0, (1.0, 1.0, 1.3))],
                       alphaData=[(0.8, 0.0), (1.0, 0.05)])
        self.controlScroll = ScrollContainer(parent=self.leftCont)
        self.PopulateScroll()
        self.leftButtonGroup = ButtonGroup(name='leftButtonGroup',
                                           parent=self.leftCont,
                                           idx=0)
        self.ConstructLeftButtonGroup()
        self.classNameLabel = Label(parent=self.infoCont,
                                    align=uiconst.TOTOP,
                                    fontsize=15,
                                    bold=True)
        self.classDocLabel = EveLabelSmall(parent=self.infoCont,
                                           align=uiconst.TOTOP)
        GradientSprite(align=uiconst.TOTOP,
                       parent=self.infoCont,
                       rotation=-math.pi / 2,
                       height=16,
                       padding=(-4, -10, -4, 0),
                       rgbData=[(0, (1.0, 1.0, 1.3))],
                       alphaData=[(0.0, 0.0), (1.0, 0.03)])
        GradientSprite(align=uiconst.TOTOP,
                       parent=tabCont,
                       state=uiconst.UI_DISABLED,
                       rotation=math.pi / 2,
                       height=16,
                       padding=(-4, 0, -4, -10),
                       rgbData=[(0, (1.0, 1.0, 1.3))],
                       alphaData=[(0.0, 0.0), (1.0, 0.03)])
        self.sampleNameLabel = EveLabelSmall(parent=tabCont,
                                             align=uiconst.TOTOP,
                                             padBottom=5)
        self.tabs = ToggleButtonGroup(parent=Container(parent=tabCont,
                                                       align=uiconst.TOTOP,
                                                       height=16),
                                      align=uiconst.CENTER,
                                      height=16,
                                      callback=self.OnTabSelected)
        sampleParent = Container(name='sampleParent',
                                 parent=self.topCont.mainCont,
                                 clipChildren=True)
        self.sampleCont = ContainerAutoSize(name='sampleCont',
                                            parent=sampleParent,
                                            align=uiconst.CENTER)
        self.codeEdit = EditPlainText(parent=self.editCont,
                                      align=uiconst.TOALL,
                                      fontcolor=(1, 1, 1, 1),
                                      ignoreTags=True)
        self.codeEdit.OnKeyDown = self.OnCodeEditKeyDown
        self.ConstructMainButtonGroup()
        uthread.new(self._SpyOnSampleCodeReloadThread)

    def OnSampleFileReload(self, path):
        self.PopulateScroll()
        self.SetSelectedControl(self.currClassData)

    def _SpyOnSampleCodeReloadThread(self):
        try:
            from eve.common.modules.sake.platform.win32.win32api import Waitables
            from eve.common.modules.sake.autocompile import SpyFolder

            class ControlCatalogSpyFolder(SpyFolder):
                def __init__(self, callback, *args, **kw):
                    SpyFolder.__init__(self, *args, **kw)
                    self.callback = callback

                def process_folder(self, path):
                    try:
                        self.callback(path)
                    except Exception as e:
                        log.LogException(e)

            spy = ControlCatalogSpyFolder(
                self.OnSampleFileReload, Waitables(),
                (os.path.abspath(os.path.dirname(__file__)), ))
            while not self.destroyed:
                spy.waitables.Wait(0)
                blue.pyos.synchro.Sleep(50)

        except ImportError:
            pass

    def ConstructLeftButtonGroup(self):
        for label, func in (('Browse', self.BrowseControls), ):
            self.leftButtonGroup.AddButton(label, func)

    def ConstructMainButtonGroup(self):
        for label, func, hint in (('Reload', self.ReloadSamples,
                                   'Reload all sample code [ctrl+s]'),
                                  ('Edit module', self.OpenModuleCodeInEditor,
                                   'Open module containing class in editor'),
                                  ('Edit samples', self.OpenSampleCodeInEditor,
                                   'Open sample code in editor')):
            self.mainButtonGroup.AddButton(label, func, hint=hint)

    def OpenSampleCodeInEditor(self, *args):
        self.currClassData.OpenSampleCodeInEditor()

    def BrowseControls(self, *args):
        controlData.BrowseControls()

    def OpenModuleCodeInEditor(self, *args):
        self.currClassData.OpenModuleCodeInEditor()

    def PopulateScroll(self):
        self.controlScroll.Flush()
        for data in controlData.GetControlData():
            TreeViewEntry(parent=self.controlScroll,
                          data=data,
                          eventListener=self)
            if self.currClassData and self.currClassData.GetID() == data.GetID(
            ):
                self.currClassData = data

    def RegisterID(self, entry, entryID):
        if entryID in self.entriesByID:
            raise ValueError('Same entry registered again: %s' % entryID)
        self.entriesByID[entryID] = entry

    def UnregisterID(self, entryID):
        self.entriesByID.pop(entryID)

    def OnTreeViewClick(self, selected):
        if selected.data.HasChildren():
            selected.ToggleChildren()
        else:
            for entry in self.entriesByID.values():
                entry.UpdateSelectedState((selected.data.GetID(), ))

            self.currSampleNum = 1
            self.SetSelectedControl(selected.data)

    def SetSelectedControl(self, data):
        self.codeEdit.Clear()
        self.sampleCont.Flush()
        self.codeEdit.SetText(data.GetCode(), html=False)
        self.currClassData = data
        self.UpdateInfoCont()
        self.ReloadSamples()

    def UpdateInfoCont(self):
        cls = self.currClassData.GetBaseClass()
        if not hasattr(cls, '__module__'):
            raise RuntimeError(
                'Unable to identify sample class. IMPORTANT: Make sure the first line in the example imports the example class itself.'
            )
        self.classNameLabel.text = '<center>' + cls.__module__ + '.' + cls.__name__
        doc = cls.__doc__ or ''
        self.classDocLabel.text = '<center>' + doc.strip()
        if 'depricated' in doc.lower():
            self.classNameLabel.text = '<color=red>' + self.classNameLabel.text
            self.classDocLabel.text = '<color=red>' + self.classDocLabel.text

    def GetCodeText(self):
        return self.codeEdit.GetAllText()

    def ReloadSamples(self, *args):
        numSamples = controlData.GetNumSamples(self.GetCodeText())
        if numSamples != self.numSamples:
            self.numSamples = numSamples
            self.ReconstructTabs()
        self.tabs.SelectByID(self.currSampleNum)

    def ReconstructTabs(self):
        self.tabs.ClearButtons()
        for i in xrange(1, self.numSamples + 1):
            self.tabs.AddButton(i, 'Sample %s' % i)

        self.tabs.width = self.numSamples * 65

    def OnTabSelected(self, sampleNum):
        self.currSampleNum = sampleNum
        self.ReloadCurrentSample()

    def ReloadCurrentSample(self):
        self.sampleCont.Flush()
        uicore.animations.FadeTo(self.sampleCont, 0.0, 1.0, 0.1)
        if self.numSamples:
            exec(self.GetCodeText() + '\n', globals())
            exec 'Sample%s(parent=self.sampleCont)' % self.currSampleNum
            sampleName = None
            exec 'sampleName = Sample%s.__doc__' % self.currSampleNum
            if sampleName:
                self.sampleNameLabel.Show()
                self.sampleNameLabel.text = '<center>' + sampleName
            else:
                self.sampleNameLabel.Hide()
                self.sampleNameLabel.text = ''

    def OnCodeEditKeyDown(self, key, flag):
        if uicore.uilib.Key(uiconst.VK_CONTROL) and key == uiconst.VK_S:
            self.ReloadSamples()
        else:
            return EditPlainText.OnKeyDown(self.codeEdit, key, flag)
class CorpRolesNew(Container):
    __guid__ = 'form.CorpRolesNew'
    __nonpersistvars__ = []

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        self.corpSvc = sm.GetService('corp')
        self.membersToShow = []
        self.corp = attributes.corp
        self.viewFrom = 0
        self.isSearched = False
        self.isCleared = False
        self.isBrowsed = False
        self.memberIDs = None
        self.roleGroupings = self.corpSvc.GetRoleGroupings()
        self.divisions = self.corpSvc.GetDivisionNames()
        self.titles = self.corpSvc.GetTitles()
        self.myBaseID = self.corpSvc.GetMember(session.charid).baseID
        self.myGrantableRoles = self.corpSvc.GetMyGrantableRoles()
        self.bases = self.GetBaseOptions()
        self.lastClickedBtn = None
        buttons = [[GetByLabel('UI/Common/Buttons/SaveChanges'),
          self.SaveChanges,
          (),
          81]]
        btns = ButtonGroup(btns=buttons)
        self.children.insert(0, btns)
        self.mainCont = Container(parent=self, padding=4)
        self.topCont = Container(parent=self.mainCont, height=40, align=uiconst.TOTOP)
        self.browseCont = Container(name='browseCont', parent=self.mainCont, align=uiconst.TOBOTTOM, height=22, padding=(const.defaultPadding,
         0,
         const.defaultPadding,
         0), state=uiconst.UI_NORMAL)

    def Load(self, populateView = 1, *args):
        sm.GetService('corpui').LoadTop('res:/ui/Texture/WindowIcons/corporationmembers.png', GetByLabel('UI/Corporations/Common/Members'))
        if not self.sr.Get('inited', 0):
            self.sr.inited = 1
            self.roleScroll = Scroll(parent=self.mainCont, id='rolesScroll')
            self.roleScroll.adjustableColumns = False
            self.roleScroll.sr.id = 'CorpRolesMembers'
            self.rolesSortHeaders = VerticalScrollHeader(parent=self.roleScroll.sr.maincontainer, settingsID='memberRoles', idx=0, scroll=self.roleScroll)
            self.rolesSortHeaders.OnSortingChange = self.ChangeRolesSort
            self.accessScroll = Scroll(parent=self.mainCont, id='accessScroll')
            self.accessScroll.sr.id = 'CorpAccessRolesMembers'
            self.accessSortHeaders = VerticalScrollHeader(parent=self.accessScroll.sr.maincontainer, settingsID='memberAccess', idx=0, scroll=self.accessScroll)
            self.accessSortHeaders.OnSortingChange = self.ChangeAccessSort
            self.titlesScroll = Scroll(parent=self.mainCont, id='accessScroll')
            self.titlesScroll.sr.id = 'CorpTitlesRolesMembers'
            self.titlesSortHeaders = VerticalScrollHeader(parent=self.titlesScroll.sr.maincontainer, settingsID='membertitles', idx=0, scroll=self.titlesScroll)
            self.titlesSortHeaders.OnSortingChange = self.ChangeTitlesSort
            self.members = self.corpSvc.GetMembers()
            self.serverMembers = self.members.PopulatePage(1)
            self.GetMembersToShow(updateState=False)
            self.roleGroupsBtns = ToggleButtonGroup(name='roleGroupsBtns', parent=self.topCont, align=uiconst.TOPLEFT, top=4, width=400, callback=self.ChangeState)
            self.AddRoleGroupButtons(self.roleGroupsBtns)
            selectedState = self.GetSelectedState()
            self.roleGroupsBtns.SelectByID(selectedState)
            self.searchInput = SearchInput(name='search', parent=self.topCont, maxLength=100, width=120, top=8, align=uiconst.TOPRIGHT, GetSearchEntries=self.Search, OnSearchEntrySelected=self.OnSearchEntrySelected, hinttext=GetByLabel('UI/EVEMail/MailingLists/SearchByName'))
            self.searchInput.displayHistory = False
            self.prevBtn = BrowseButton(parent=self.browseCont, prev=True, state=uiconst.UI_NORMAL, func=self.BrowseRoles)
            self.nextBtn = BrowseButton(parent=self.browseCont, prev=False, state=uiconst.UI_NORMAL, align=uiconst.TOPRIGHT, func=self.BrowseRoles)
            self.prevBtn.Disable()
            self.pageNrLabel = EveLabelMedium(parent=self.browseCont, align=uiconst.CENTER)
            self.UpdatePageNrText()
            if self.members.totalCount < MEMBERS_PER_PAGE:
                self.browseCont.display = False
        else:
            self.UpdateScroll(self.GetSelectedState())

    def OnSearchEntrySelected(self, result, *args, **kwargs):
        owner = result[0].info
        self.isSearched = True
        self.isCleared = False
        self.GetMembersToShow(owner.ownerID)

    def ClearSearch(self):
        self.isSearched = False
        self.isCleared = True
        self.GetMembersToShow()

    def Search(self, searchString):
        if searchString == '':
            self.ClearSearch()
            return
        else:
            if self.memberIDs is None:
                self.memberIDs = self.corpSvc.GetMemberIDs()
            if len(searchString) < 3:
                return []
            return searchUtil.SearchCharactersInCorp(searchString, self.memberIDs)

    def ChangeSort(self, scroll, activeColumn, activeDirection):
        scroll.Sort(activeColumn, activeDirection)

    def ChangeRolesSort(self, *args):
        activeColumn, activeDirection = self.rolesSortHeaders.GetCurrentActive()
        self.ChangeSort(self.roleScroll, activeColumn, activeDirection)

    def ChangeAccessSort(self, *args):
        activeColumn, activeDirection = self.accessSortHeaders.GetCurrentActive()
        self.ChangeSort(self.accessScroll, activeColumn, activeDirection)

    def ChangeTitlesSort(self, *args):
        activeColumn, activeDirection = self.titlesSortHeaders.GetCurrentActive()
        self.ChangeSort(self.titlesScroll, activeColumn, activeDirection)

    def AddRoleGroupButtons(self, roleGroupsBtns):
        roleGroupsBtns.AddButton(PERMISSIONS, GetByLabel('UI/Corporations/RoleManagement/Permissions'))
        roleGroupsBtns.AddButton(STATION_SERVICE, GetByLabel('UI/Corporations/RoleManagement/StationService'))
        roleGroupsBtns.AddButton(ACCOUNTING, GetByLabel('UI/Corporations/RoleManagement/Accounting'))
        roleGroupsBtns.AddButton(ACCESS, GetByLabel('UI/Corporations/RoleManagement/Access'))
        roleGroupsBtns.AddButton(GROUPS, GetByLabel('UI/Corporations/Common/Titles'))

    def GetMembersToShow(self, searchedCharID = None, updateState = True):
        self.membersToShow = []
        if self.isSearched and searchedCharID:
            self.membersToShow.append(self.corpSvc.GetMember(searchedCharID))
        else:
            count = min(MEMBERS_PER_PAGE, self.members.totalCount - self.viewFrom)
            serverPage = self.viewFrom / self.members.perPage + 1
            self.serverMembers = self.members.PopulatePage(serverPage)
            for number in xrange(count):
                index = (number + self.viewFrom) % self.members.perPage
                currentServerPage = (number + self.viewFrom) / self.members.perPage + 1
                if serverPage != currentServerPage:
                    self.serverMembers = self.members.PopulatePage(currentServerPage)
                    serverPage = currentServerPage
                self.membersToShow.append(self.serverMembers[index])

        if updateState:
            self.ChangeState(self.GetSelectedState())

    def UpdatePageNrText(self):
        viewPage, viewPagesTotal = self.GetViewPageAndTotalPages()
        self.pageNrLabel.text = '%s/%s' % (viewPage, viewPagesTotal)

    def GetViewPageAndTotalPages(self):
        viewPage = self.viewFrom / MEMBERS_PER_PAGE + 1
        viewPagesTotal = self.members.totalCount / MEMBERS_PER_PAGE + 1
        return (viewPage, viewPagesTotal)

    def BrowseRoles(self, btn, *args):
        self.isBrowsed = True
        browse = btn.backforth
        self.viewFrom = self.viewFrom + browse * MEMBERS_PER_PAGE
        if self.viewFrom < 0:
            self.viewFrom = 0
        self.ShowHideBrowseButtons()
        self.UpdatePageNrText()
        self.GetMembersToShow()

    def ShowHideBrowseButtons(self):
        viewPage, viewPagesTotal = self.GetViewPageAndTotalPages()
        if viewPage < viewPagesTotal:
            self.nextBtn.Enable()
        else:
            self.nextBtn.Disable()
        if viewPage == 1:
            self.prevBtn.Disable()
        else:
            self.prevBtn.Enable()

    def GetSelectedState(self):
        return settings.user.ui.Get('selectedRoleGroupState', PERMISSIONS)

    def LoadScroll(self, scroll, sortHeaders, headers, fixedHeaders, scrollList):
        sortHeaders.CreateColumns(headers, fixedHeaders)
        currentActive, currentDirection = sortHeaders.GetCurrentActive()
        scroll.sr.headers = sortHeaders.GetCurrentColumns()
        scroll.Load(contentList=scrollList, sortby=currentActive, reversesort=currentDirection)
        scroll.HideLoading()

    def LoadRolesScroll(self):
        headers = self.GetRoleHeaders()
        self.LoadScroll(self.roleScroll, self.rolesSortHeaders, headers, self.GetFixedColumns(headers), self.GetRolesScrollList())

    def LoadAccessScroll(self):
        self.accessScroll.ShowLoading()
        blue.synchro.Yield()
        headers = self.GetAccessRoleHeaders()
        self.LoadScroll(self.accessScroll, self.accessSortHeaders, headers, self.GetFixedAccessHeaders(headers), self.GetAccessScrollList())

    def LoadTitlesScroll(self):
        headers = self.GetTitleHeaders()
        self.LoadScroll(self.titlesScroll, self.titlesSortHeaders, headers, self.GetFixedColumns(headers), self.GetTitlesScrollList())

    def GetFixedColumns(self, headers):
        fixedHeaders = {GetByLabel('UI/Corporations/CorporationWindow/Members/CorpMemberName'): NAME_COL_WIDTH,
         GetByLabel('UI/Corporations/CorporationWindow/Members/CorpMemberBase'): BASE_COL_WIDTH}
        for header in headers[2:]:
            fixedHeaders[header] = CHECKBOX_COL_WIDTH

        return fixedHeaders

    def GetTitleHeaders(self):
        header = [GetByLabel('UI/Corporations/CorporationWindow/Members/CorpMemberName'), GetByLabel('UI/Corporations/CorporationWindow/Members/CorpMemberBase')]
        for title in sorted(self.titles.itervalues(), key=lambda x: x.titleID):
            header.append(title.titleName)

        return header

    def GetAccessRoleHeaders(self):
        header = [GetByLabel('UI/Corporations/CorporationWindow/Members/CorpMemberName'), GetByLabel('UI/Corporations/CorporationWindow/Members/CorpMemberBase'), GetByLabel('UI/Corporations/RoleManagement/Type')]
        for divisionID in xrange(1, 8):
            header.append(self.divisions[divisionID])

        return header

    def GetFixedAccessHeaders(self, headers):
        fixedHeaders = {GetByLabel('UI/Corporations/CorporationWindow/Members/CorpMemberName'): NAME_COL_WIDTH,
         GetByLabel('UI/Corporations/CorporationWindow/Members/CorpMemberBase'): BASE_COL_WIDTH,
         GetByLabel('UI/Corporations/RoleManagement/Type'): 50}
        for header in headers[3:]:
            fixedHeaders[header] = ACCESS_COL_WIDTH

        return fixedHeaders

    def GetRoleHeaders(self):
        header = [GetByLabel('UI/Corporations/CorporationWindow/Members/CorpMemberName'), GetByLabel('UI/Corporations/CorporationWindow/Members/CorpMemberBase')]
        for column in self.roleGroupings[self.GetSelectedState()].columns:
            columnName, subColumns = column
            colName = ReplaceStringWithTags(columnName)
            header.append(colName)

        return header

    def ChangeState(self, selectedState):
        selectedBtn = self.roleGroupsBtns.GetSelected()
        isSearchedOrClearedOrBrowsed = self.isSearched or self.isCleared or self.isBrowsed
        if self.lastClickedBtn == selectedBtn and not isSearchedOrClearedOrBrowsed:
            return
        self.lastClickedBtn = selectedBtn
        if len(self.GetNodesToUpdate()):
            if eve.Message('CrpMembersSaveChanges', {}, uiconst.YESNO) == uiconst.ID_YES:
                self.SaveChanges()
            else:
                for node in self.GetNodesToUpdate():
                    self.ClearRoleChanges(node)

        settings.user.ui.Set('selectedRoleGroupState', selectedState)
        self.isCleared = False
        self.isSearched = False
        self.isBrowsed = False
        uthread.new(self.UpdateScroll, selectedState)

    def GetBaseOptions(self):
        offices = self.corpSvc.GetMyCorporationsOffices()
        offices.Fetch(0, len(offices))
        bases = [('-', None)]
        if offices:
            for office in offices:
                if util.IsStation(office.locationID):
                    bases.append((cfg.evelocations.Get(office.locationID).locationName, office.locationID))

        return bases

    def UpdateScroll(self, selectedState):
        if selectedState == ACCESS:
            self.roleScroll.display = False
            self.titlesScroll.display = False
            self.accessScroll.display = True
            self.LoadAccessScroll()
        elif selectedState == GROUPS:
            self.roleScroll.display = False
            self.accessScroll.display = False
            self.titlesScroll.display = True
            self.LoadTitlesScroll()
        else:
            self.accessScroll.display = False
            self.titlesScroll.display = False
            self.roleScroll.display = True
            self.LoadRolesScroll()

    def GetScrollList(self, decoClass, sortFunction, roleGroup = None, titles = None, divisionNames = None):
        scrollList = []
        for member in self.membersToShow:
            scrollList.append(Bunch(decoClass=decoClass, member=member, charID=member.characterID, corp=self.corp, label=cfg.eveowners.Get(member.characterID).ownerName, roleGroup=roleGroup, GetSortValue=sortFunction, roleGroupings=self.roleGroupings, myBaseID=self.myBaseID, myGrantableRoles=self.myGrantableRoles, titles=titles, divisionNames=divisionNames, bases=self.bases))
            blue.pyos.BeNice()
            if self.destroyed:
                return scrollList

        return scrollList

    def GetHeaderSortValue(self, node, columnID, sortDirection, idx = None):
        sortValue = (0, None)
        if sortDirection:
            sortValue = (1000, None)
        node.Set('sort_%s' % columnID, sortValue)
        return self.GetSortValue(node, columnID, sortDirection, idx=None)

    def GetAccessSortValue(self, node, columnID, sortDirection, idx = None):
        self.SetNameAndBaseSorting(node)
        if node.Get('sort_%s' % columnID, None) is None:
            roleGrouping = self.roleGroupings
            totalValue = 0
            for divisionID in xrange(4, 10):
                roleGroup = roleGrouping[divisionID]
                rolesAppliesTo = getattr(node.member, roleGroup.appliesTo)
                grantableRolesAppliesTo = getattr(node.member, roleGroup.appliesToGrantable)
                if self.CheckIfDirectorOrCEO(node, node.member.roles):
                    rolesAppliesTo |= roleGroup.roleMask
                    grantableRolesAppliesTo |= roleGroup.roleMask
                for columnName, subColumns in roleGroup.columns:
                    if columnName.replace(' ', '') != StripTags(columnID).replace(' ', ''):
                        continue
                    for _, role in subColumns:
                        checkValue = GetCheckStateForRole(rolesAppliesTo, grantableRolesAppliesTo, role)
                        totalValue += checkValue

            node.Set('sort_%s' % columnID, (0, totalValue))
        return self.GetSortValue(node, columnID, sortDirection, idx=None)

    def GetTitlesSortValue(self, node, columnID, sortDirection, idx = None):
        self.SetNameAndBaseSorting(node)
        if node.Get('sort_%s' % columnID, None) is None:
            for title in sorted(self.titles.itervalues(), key=lambda x: x.titleID):
                isChecked = node.member.titleMask & title.titleID == title.titleID
                node.Set('sort_%s' % title.titleName, (0, isChecked))

        return self.GetSortValue(node, columnID, sortDirection, idx=None)

    def GetRolesSortValue(self, node, columnID, sortDirection, idx = None):
        self.SetNameAndBaseSorting(node)
        if node.Get('sort_%s' % columnID, None) is None:
            roles = getattr(node.member, node.roleGroup.appliesTo)
            grantableRoles = getattr(node.member, node.roleGroup.appliesToGrantable)
            if self.CheckIfDirectorOrCEO(node, roles):
                roles |= node.roleGroup.roleMask
                grantableRoles |= node.roleGroup.roleMask
            for columnName, subColumns in node.roleGroup.columns:
                for subColumnName, role in subColumns:
                    if columnName.replace(' ', '') == StripTags(columnID).replace(' ', ''):
                        checkValue = GetCheckStateForRole(roles, grantableRoles, role)
                        node.Set('sort_%s' % columnID, (0, checkValue))

        return self.GetSortValue(node, columnID, sortDirection, idx=None)

    def CheckIfDirectorOrCEO(self, node, roles):
        isCEO = node.member.characterID == node.corp.ceoID
        isDirector = roles & const.corpRoleDirector == const.corpRoleDirector
        return isDirector or isCEO

    def GetSortValue(self, node, columnID, sortDirection, idx = None):
        return node.Get('sort_%s' % columnID, (0, 0))

    def SetNameAndBaseSorting(self, node):
        node.Set('sort_%s' % GetByLabel('UI/Corporations/CorporationWindow/Members/CorpMemberName'), (0, node.charLabel))
        if node.member and node.member.baseID:
            locationName = cfg.evelocations.Get(node.member.baseID).locationName
        else:
            locationName = ''
        node.Set('sort_%s' % GetByLabel('UI/Corporations/CorporationWindow/Members/CorpMemberBase'), (0, locationName))

    def GetTitlesScrollList(self):
        titles = self.corpSvc.GetTitles()
        return self.GetScrollList(TitleEntry, self.GetTitlesSortValue, titles=titles)

    def GetRolesScrollList(self):
        roleGroup = self.roleGroupings[self.GetSelectedState()]
        return self.GetScrollList(RoleEntry, self.GetRolesSortValue, roleGroup)

    def GetAccessScrollList(self):
        divisionNames = self.corpSvc.GetDivisionNames()
        scrollList = [Bunch(decoClass=RoleHeaderEntry, member=None, GetSortValue=self.GetHeaderSortValue)]
        scrollList.extend(self.GetScrollList(RoleAccessEntry, self.GetAccessSortValue, divisionNames=divisionNames))
        return scrollList

    def HaveRolesChanged(self, node):
        if node.rec.roles != node.rec.oldRoles:
            return True
        if node.rec.grantableRoles != node.rec.oldGrantableRoles:
            return True
        if node.rec.rolesAtHQ != node.rec.oldRolesAtHQ:
            return True
        if node.rec.grantableRolesAtHQ != node.rec.oldGrantableRolesAtHQ:
            return True
        if node.rec.rolesAtBase != node.rec.oldRolesAtBase:
            return True
        if node.rec.grantableRolesAtBase != node.rec.oldGrantableRolesAtBase:
            return True
        if node.rec.rolesAtOther != node.rec.oldRolesAtOther:
            return True
        if node.rec.grantableRolesAtOther != node.rec.oldGrantableRolesAtOther:
            return True
        if node.rec.baseID != node.rec.oldBaseID:
            return True
        if node.rec.titleMask != node.rec.oldTitleMask:
            return True
        return False

    def GetNodesToUpdate(self):
        nodesToUpdate = []
        try:
            sm.GetService('loading').Cycle(GetByLabel('UI/Common/PreparingToUpdate'))
            nodesToUpdate.extend(self.GetNodesList(self.accessScroll.GetNodes()))
            nodesToUpdate.extend(self.GetNodesList(self.roleScroll.GetNodes()))
            nodesToUpdate.extend(self.GetNodesList(self.titlesScroll.GetNodes()))
        finally:
            sm.GetService('loading').StopCycle()

        return nodesToUpdate

    def GetNodesList(self, nodesList):
        nodesToUpdate = []
        for node in nodesList:
            if not node or not node.rec:
                continue
            if self.HaveRolesChanged(node):
                nodesToUpdate.append(node)

        return nodesToUpdate

    def _CreateRowsToUpdate(self, node):
        entry = node.rec
        characterID = entry.characterID
        roles = entry.roles
        grantableRoles = entry.grantableRoles
        rolesAtHQ = entry.rolesAtHQ
        grantableRolesAtHQ = entry.grantableRolesAtHQ
        rolesAtBase = entry.rolesAtBase
        grantableRolesAtBase = entry.grantableRolesAtBase
        rolesAtOther = entry.rolesAtOther
        grantableRolesAtOther = entry.grantableRolesAtOther
        baseID = entry.baseID
        titleMask = entry.titleMask
        if entry.titleMask == entry.oldTitleMask:
            titleMask = None
        if roles & const.corpRoleDirector == const.corpRoleDirector:
            roles = const.corpRoleDirector
            grantableRoles = 0
            rolesAtHQ = 0
            grantableRolesAtHQ = 0
            rolesAtBase = 0
            grantableRolesAtBase = 0
            rolesAtOther = 0
            grantableRolesAtOther = 0
        row = [characterID,
         None,
         None,
         None,
         roles,
         grantableRoles,
         rolesAtHQ,
         grantableRolesAtHQ,
         rolesAtBase,
         grantableRolesAtBase,
         rolesAtOther,
         grantableRolesAtOther,
         baseID,
         titleMask]
        return row

    def ClearRoleChanges(self, node):
        node.rec.roles = node.rec.oldRoles
        node.rec.grantableRoles = node.rec.oldGrantableRoles
        node.rec.rolesAtHQ = node.rec.oldRolesAtHQ
        node.rec.grantableRolesAtHQ = node.rec.oldGrantableRolesAtHQ
        node.rec.rolesAtBase = node.rec.oldRolesAtBase
        node.rec.grantableRolesAtBase = node.rec.oldGrantableRolesAtBase
        node.rec.rolesAtOther = node.rec.oldRolesAtOther
        node.rec.grantableRolesAtOther = node.rec.oldGrantableRolesAtOther
        node.rec.baseID = node.rec.oldBaseID
        node.rec.titleMask = node.rec.oldTitleMask

    def UpdateOldRolesForNode(self, node):
        node.rec.oldRoles = node.rec.roles
        node.rec.oldGrantableRoles = node.rec.grantableRoles
        node.rec.oldRolesAtHQ = node.rec.rolesAtHQ
        node.rec.oldGrantableRolesAtHQ = node.rec.grantableRolesAtHQ
        node.rec.oldRolesAtBase = node.rec.rolesAtBase
        node.rec.oldGrantableRolesAtBase = node.rec.grantableRolesAtBase
        node.rec.oldRolesAtOther = node.rec.rolesAtOther
        node.rec.oldGrantableRolesAtOther = node.rec.grantableRolesAtOther
        node.rec.oldBaseID = node.rec.baseID
        node.rec.oldTitleMask = node.rec.titleMask

    def SaveChanges(self, *args):
        nodesToUpdate = self.GetNodesToUpdate()
        nCount = len(nodesToUpdate)
        if nCount == 0:
            return
        try:
            sm.GetService('loading').ProgressWnd(GetByLabel('UI/Common/Updating'), '', 0, nCount)
            blue.pyos.synchro.Yield()
            rows = None
            myRow = None
            for node in nodesToUpdate:
                row = self._CreateRowsToUpdate(node)
                if node.rec.characterID == eve.session.charid:
                    if myRow is None:
                        myRow = Rowset(self.GetRowHeader())
                    myRow.append(row)
                else:
                    if rows is None:
                        rows = Rowset(self.GetRowHeader())
                    rows.append(row)

            if rows is not None:
                self.corpSvc.UpdateMembers(rows)
                sm.ScatterEvent('OnRoleEdit', rows)
            if myRow is not None:
                sm.GetService('sessionMgr').PerformSessionChange('corp.UpdateMembers', self.corpSvc.UpdateMembers, myRow)
        finally:
            if nCount:
                for node in nodesToUpdate:
                    self.UpdateOldRolesForNode(node)

                sm.GetService('loading').ProgressWnd(GetByLabel('UI/Common/Updated'), '', nCount - 1, nCount)
                blue.pyos.synchro.SleepWallclock(500)
                sm.GetService('loading').ProgressWnd(GetByLabel('UI/Common/Updated'), '', nCount, nCount)
                blue.pyos.synchro.Yield()

    def GetRowHeader(self):
        return ['characterID',
         'title',
         'divisionID',
         'squadronID',
         'roles',
         'grantableRoles',
         'rolesAtHQ',
         'grantableRolesAtHQ',
         'rolesAtBase',
         'grantableRolesAtBase',
         'rolesAtOther',
         'grantableRolesAtOther',
         'baseID',
         'titleMask']

    def OnTabDeselect(self):
        if not self.sr.Get('inited', 0):
            return
        if len(self.GetNodesToUpdate()):
            if eve.Message('CrpMembersSaveChanges', {}, uiconst.YESNO) == uiconst.ID_YES:
                self.SaveChanges()