Exemple #1
0
 def OnTabSelect(self):
     if self.isInitialized:
         self.UpdateScroll()
         return
     self.isInitialized = True
     self.topPanel = Container(name='topPanel',
                               parent=self,
                               align=uiconst.TOTOP,
                               height=20,
                               padding=(0, 6, 0, 6))
     self.scroll = Scroll(parent=self, id='InstallationBrowser')
     self.scroll.OnSelectionChange = self.OnScrollSelectionChange
     self.ownerCombo = Combo(name='ownerCombo',
                             parent=self.topPanel,
                             align=uiconst.TOLEFT,
                             prefsKey='IndustryBlueprintOwner',
                             callback=self.OnOwnerCombo,
                             options=self.GetOwnerOptions(),
                             width=120,
                             padRight=4)
     self.activityCombo = Combo(name='activityCombo',
                                parent=self.topPanel,
                                align=uiconst.TOLEFT,
                                prefsKey='IndustryBlueprintActivity',
                                callback=self.OnActivityCombo,
                                options=self.GetActivityOptions(),
                                width=120,
                                padRight=4)
     self.viewModeButtons = ViewModeButtons(
         parent=self.topPanel,
         align=uiconst.TORIGHT,
         controller=self,
         settingsID='IndustryBlueprintBrowserViewMode')
     self.filterEdit = QuickFilterEdit(
         name='searchField',
         parent=self.topPanel,
         hinttext=localization.GetByLabel('UI/Inventory/Filter'),
         maxLength=64,
         align=uiconst.TORIGHT,
         OnClearFilter=self.OnFilterEditCleared,
         padRight=4)
     self.filterEdit.ReloadFunction = self.OnFilterEdit
     self.UpdateScroll()
Exemple #2
0
 def OnTabSelect(self):
     if self.isInitialized:
         self.UpdateOwnerCombo()
         self.UpdateScroll()
         return
     self.isInitialized = True
     self.topPanel = Container(name='topPanel', parent=self, align=TOTOP, height=20, padding=(0, 6, 0, 6))
     self.scroll = Scroll(parent=self, id='BlueprintBrowser')
     self.scroll.OnSelectionChange = self.OnScrollSelectionChange
     self.scroll.OnKeyDown = self.OnScrollKeyDown
     self.scroll.OnChar = self.OnScrollChar
     utilMenuCont = Container(align=uiconst.TOLEFT, parent=self.topPanel, width=20)
     UtilMenu(menuAlign=uiconst.BOTTOMLEFT, parent=utilMenuCont, align=uiconst.CENTERLEFT, GetUtilMenu=self.GetSettingsMenu, texturePath='res:/UI/Texture/SettingsCogwheel.png', width=16, height=16, iconSize=18)
     self.ownerCombo = Combo(name='ownerCombo', parent=self.topPanel, align=uiconst.TOLEFT, callback=self.OnOwnerCombo, width=120)
     self.facilityCombo = Combo(name='facilityCombo', parent=self.topPanel, align=uiconst.TOLEFT, callback=self.OnFacilityCombo, width=200, padLeft=5)
     self.invLocationCombo = Combo(name='invLocationCombo', parent=self.topPanel, align=uiconst.TOLEFT, callback=self.OnInvLocationCombo, padLeft=5, width=120, settingsID='IndustryBlueprintBrowserInvLocation')
     self.blueprintTypeCombo = Combo(name='blueprintTypeCombo', parent=self.topPanel, align=uiconst.TOLEFT, callback=self.OnBlueprintTypeCombo, padLeft=5, width=100, settingsID='IndustryBlueprintBrowserType', options=self.GetBlueprintTypeComboOptions())
     self.categoryGroupCombo = Combo(name='categoryGroupCombo ', parent=self.topPanel, align=uiconst.TOLEFT, callback=self.OnCategoryGroupCombo, padLeft=5, width=100)
     self.viewModeButtons = ViewModeButtons(parent=self.topPanel, align=uiconst.TORIGHT, controller=self, settingsID='IndustryBlueprintBrowserViewMode')
     self.filterEdit = QuickFilterEdit(name='searchField', parent=self.topPanel, hinttext=localization.GetByLabel('UI/Inventory/Filter'), maxLength=64, align=uiconst.TORIGHT, padRight=4)
     self.filterEdit.ReloadFunction = self.OnFilterEdit
     self.UpdateOwnerCombo()
     self.UpdateBlueprintTypeCombo()
     self.UpdateScroll()
Exemple #3
0
 def OnTabSelect(self):
     if self.isInitialized:
         self.UpdateOwnerCombo()
         self.UpdateInstallerCombo()
         self.UpdateScroll()
         return
     self.isInitialized = True
     self.topPanel = Container(name='topPanel',
                               parent=self,
                               align=uiconst.TOTOP,
                               height=20,
                               padding=(0, 6, 0, 6))
     self.bottomButtons = ButtonGroup(parent=self)
     self.deliverSelectedBtn = self.bottomButtons.AddButton(
         localization.GetByLabel('UI/Industry/DeliverSelectedJobs'),
         self.DeliverSelectedJobs)
     self.deliverAllBtn = self.bottomButtons.AddButton(
         localization.GetByLabel('UI/Industry/DeliverAllJobs'),
         self.DeliverAllJobs)
     self.scroll = Scroll(parent=self, id='JobBrowser')
     self.scroll.OnSelectionChange = self.OnScrollSelectionChange
     self.scroll.Confirm = self.OnScrollReturn
     self.viewModeButtons = ViewModeButtons(
         parent=self.topPanel,
         align=uiconst.TORIGHT,
         controller=self,
         settingsID='IndustryBlueprintBrowserViewMode')
     self.ownerCombo = Combo(name='ownerCombo',
                             parent=self.topPanel,
                             align=uiconst.TOLEFT,
                             callback=self.OnOwnerCombo,
                             width=120,
                             padRight=4)
     self.statusCombo = Combo(name='statusCombo',
                              parent=self.topPanel,
                              align=uiconst.TOLEFT,
                              prefsKey='IndustryJobStatus',
                              callback=self.OnStatusCombo,
                              width=120,
                              padRight=4)
     self.activityCombo = Combo(name='activityCombo',
                                parent=self.topPanel,
                                align=uiconst.TOLEFT,
                                prefsKey='IndustryBlueprintActivity',
                                callback=self.OnActivityCombo,
                                options=self.GetActivityOptions(),
                                width=120,
                                padRight=4)
     self.installerCombo = Combo(name='installerCombo',
                                 parent=self.topPanel,
                                 align=uiconst.TOLEFT,
                                 callback=self.OnInstallerCombo,
                                 options=self.GetInstallerOptions(),
                                 width=140,
                                 padRight=4)
     self.filterEdit = QuickFilterEdit(
         name='searchField',
         parent=self.topPanel,
         hinttext=localization.GetByLabel('UI/Inventory/Filter'),
         maxLength=64,
         align=uiconst.TORIGHT,
         OnClearFilter=self.OnFilterEditCleared,
         padRight=4)
     self.filterEdit.ReloadFunction = self.OnFilterEdit
     self.UpdateStatusCombo()
     self.UpdateOwnerCombo()
     self.UpdateInstallerCombo()
     self.UpdateScroll()
     uthread.new(self._UpdateJobCountersThread)
Exemple #4
0
class BrowserJobs(Container):
    default_name = 'BrowserJobs'
    __notifyevents__ = [
        'OnIndustryJob', 'OnFacilityReload', 'OnSessionChanged'
    ]

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        sm.RegisterNotify(self)
        self.callback = attributes.callback
        self.isInitialized = False

    def _OnClose(self, *args):
        sm.UnregisterNotify(self)

    def OnTabSelect(self):
        if self.isInitialized:
            self.UpdateOwnerCombo()
            self.UpdateInstallerCombo()
            self.UpdateScroll()
            return
        self.isInitialized = True
        self.topPanel = Container(name='topPanel',
                                  parent=self,
                                  align=uiconst.TOTOP,
                                  height=20,
                                  padding=(0, 6, 0, 6))
        self.bottomButtons = ButtonGroup(parent=self)
        self.deliverSelectedBtn = self.bottomButtons.AddButton(
            localization.GetByLabel('UI/Industry/DeliverSelectedJobs'),
            self.DeliverSelectedJobs)
        self.deliverAllBtn = self.bottomButtons.AddButton(
            localization.GetByLabel('UI/Industry/DeliverAllJobs'),
            self.DeliverAllJobs)
        self.scroll = Scroll(parent=self, id='JobBrowser')
        self.scroll.OnSelectionChange = self.OnScrollSelectionChange
        self.scroll.Confirm = self.OnScrollReturn
        self.viewModeButtons = ViewModeButtons(
            parent=self.topPanel,
            align=uiconst.TORIGHT,
            controller=self,
            settingsID='IndustryBlueprintBrowserViewMode')
        self.ownerCombo = Combo(name='ownerCombo',
                                parent=self.topPanel,
                                align=uiconst.TOLEFT,
                                callback=self.OnOwnerCombo,
                                width=120,
                                padRight=4)
        self.statusCombo = Combo(name='statusCombo',
                                 parent=self.topPanel,
                                 align=uiconst.TOLEFT,
                                 prefsKey='IndustryJobStatus',
                                 callback=self.OnStatusCombo,
                                 width=120,
                                 padRight=4)
        self.activityCombo = Combo(name='activityCombo',
                                   parent=self.topPanel,
                                   align=uiconst.TOLEFT,
                                   prefsKey='IndustryBlueprintActivity',
                                   callback=self.OnActivityCombo,
                                   options=self.GetActivityOptions(),
                                   width=120,
                                   padRight=4)
        self.installerCombo = Combo(name='installerCombo',
                                    parent=self.topPanel,
                                    align=uiconst.TOLEFT,
                                    callback=self.OnInstallerCombo,
                                    options=self.GetInstallerOptions(),
                                    width=140,
                                    padRight=4)
        self.filterEdit = QuickFilterEdit(
            name='searchField',
            parent=self.topPanel,
            hinttext=localization.GetByLabel('UI/Inventory/Filter'),
            maxLength=64,
            align=uiconst.TORIGHT,
            OnClearFilter=self.OnFilterEditCleared,
            padRight=4)
        self.filterEdit.ReloadFunction = self.OnFilterEdit
        self.UpdateStatusCombo()
        self.UpdateOwnerCombo()
        self.UpdateInstallerCombo()
        self.UpdateScroll()
        uthread.new(self._UpdateJobCountersThread)

    def OnTabDeselect(self):
        if self.isInitialized:
            self.scroll.Clear()

    def OnScrollSelectionChange(self, entries):
        if entries:
            self.callback(entries[0].jobData)
        self.UpdateDeliverButtons()

    def OnScrollReturn(self, *args):
        self.DeliverJobs(self.scroll.GetSelected())

    def OnFilterEdit(self):
        self.UpdateScroll()

    def OnFilterEditCleared(self):
        self.UpdateScroll()

    def OnViewModeChanged(self, viewMode):
        self.UpdateScroll()

    def OnIndustryJob(self, jobID, ownerID, blueprintID, installerID, status,
                      successfulRuns):
        """
        Server telling us that a job changed it's state
        """
        if self.destroyed or self.IsHidden():
            return
        if self.isInitialized and self.display:
            self.UpdateJobEntry(jobID, status, successfulRuns)
            self.UpdateDeliverButtons()

    def OnFacilityReload(self, facilityID):
        """
        Server telling us a facility was modified. If this applies to any jobs currently
        displayed then we should reload the scroll.
        """
        if self.destroyed or self.IsHidden():
            return
        if self.isInitialized and self.display:
            for node in self.scroll.GetNodes():
                if facilityID is None or node.jobData.facilityID == facilityID:
                    self.UpdateScroll()
                    return

    def OnSessionChanged(self, isRemote, session, change):
        """
        If we change solarsystem then reload the jobs tab.
        """
        if 'solarsystemid2' in change or 'stationid2' in change:
            self.UpdateScroll()
        if 'corpid' in change:
            self.UpdateOwnerCombo()
            self.UpdateScroll()

    def UpdateJobEntry(self, jobID, status, successfulRuns):
        """
         Update the state of an individual job entry
        """
        for node in self.scroll.GetNodes():
            if node.jobData.jobID == jobID and node.panel:
                node.panel.OnStatusChanged(status, successfulRuns)
                break
        else:
            self.UpdateScroll()

    def IsSomeJobReady(self):
        for node in self.scroll.GetNodes():
            if node.jobData.status == industry.STATUS_READY:
                return True

        return False

    def IsSomeReadyJobSelected(self):
        for node in self.scroll.GetSelected():
            if node.jobData.status == industry.STATUS_READY:
                return True

        return False

    def UpdateDeliverButtons(self):
        self.deliverAllBtn.display = self.IsSomeJobReady()
        self.bottomButtons.display = self.deliverAllBtn.display
        self.deliverSelectedBtn.display = self.IsSomeReadyJobSelected()
        self.bottomButtons.ResetLayout()

    def UpdateScroll(self):
        if not self.isInitialized:
            return
        statusFilter = self.statusCombo.selectedValue
        jobs = self.GetJobData(statusFilter == STATUS_COMPLETED)
        scrollList = self.GetScrollList(jobs)
        self.scroll.sr.defaultColumnWidth = JobEntry.GetDefaultColumnWidth()
        isPersonalJob = self.ownerCombo.GetValue() == OWNER_ME
        self.scroll.LoadContent(
            contentList=scrollList,
            headers=JobEntry.GetHeaders(isPersonalJob=isPersonalJob),
            noContentHint=localization.GetByLabel('UI/Industry/NoJobsFound'))
        self.UpdateDeliverButtons()

    def GetJobData(self, includeCompleted):
        if self.IsCorpSelected():
            jobs = sm.GetService('industrySvc').GetCorporationJobs(
                includeCompleted)
        else:
            jobs = sm.GetService('industrySvc').GetCharacterJobs(
                includeCompleted)
        return jobs

    def GetScrollList(self, jobs):
        scrollList = []
        for jobData in jobs:
            if self.IsFilteredOut(jobData):
                continue
            node = Bunch(jobData=jobData,
                         decoClass=JobEntry,
                         sortValues=JobEntry.GetColumnSortValues(
                             jobData, jobData.distance),
                         viewMode=self.viewModeButtons.GetViewMode(),
                         jumps=max(0, jobData.distance))
            scrollList.append(node)

        return scrollList

    def IsFilteredOut(self, jobData):
        statusFilter = self.statusCombo.selectedValue
        if statusFilter == STATUS_INCOMPLETE and jobData.completed or statusFilter == STATUS_READY and not jobData.status == industry.STATUS_READY or statusFilter == STATUS_INSTALLED and not jobData.status == industry.STATUS_INSTALLED or statusFilter == STATUS_COMPLETED and not jobData.completed or statusFilter == STATUS_PAUSED and not jobData.status == industry.STATUS_PAUSED:
            return True
        if self.IsCorpSelected():
            installerType = self.installerCombo.GetValue()
            if installerType == INSTALLER_ME and jobData.installerID != session.charid:
                return True
            if installerType == INSTALLER_CORPMATE and jobData.installerID == session.charid:
                return True
        filterText = self.filterEdit.GetValue().strip().lower()
        if filterText:
            text = jobData.blueprint.GetName() + jobData.GetFacilityName(
            ) + jobData.GetInstallerName()
            if text.lower().find(filterText) == -1:
                return True
        activityValue = self.activityCombo.GetValue()
        if activityValue and activityValue != jobData.activityID:
            return True
        return False

    def OnStatusCombo(self, combo, key, value):
        settings.user.ui.Set('IndustryJobBrowserStatus', value)
        self.UpdateScroll()

    def UpdateStatusCombo(self):
        options = ((localization.GetByLabel('UI/Industry/StatusAllActiveJobs'),
                    STATUS_INCOMPLETE),
                   (localization.GetByLabel('UI/Industry/StatusInProgress'),
                    STATUS_INSTALLED, None, STATUS_ICONS[STATUS_INSTALLED]),
                   (localization.GetByLabel('UI/Industry/StatusReady'),
                    STATUS_READY, None, STATUS_ICONS[STATUS_READY]),
                   (localization.GetByLabel('UI/Industry/StatusHalted'),
                    STATUS_PAUSED, None, STATUS_ICONS[STATUS_PAUSED]),
                   (localization.GetByLabel('UI/Industry/StatusHistory'),
                    STATUS_COMPLETED, None, STATUS_ICONS[STATUS_COMPLETED]))
        select = settings.user.ui.Get('IndustryJobBrowserStatus',
                                      STATUS_INCOMPLETE)
        self.statusCombo.LoadOptions(options, select=select)

    def OnActivityCombo(self, *args):
        self.UpdateScroll()

    def GetActivityOptions(self):
        ret = [
            (localization.GetByLabel(ACTIVITY_NAMES[activityID]), activityID,
             None, industryUIConst.ACTIVITY_ICONS_SMALL[activityID])
            for activityID in industry.ACTIVITIES
        ]
        ret.insert(0,
                   (localization.GetByLabel('UI/Industry/AllActivities'), 0))
        return ret

    def GetInstallerOptions(self):
        return ((localization.GetByLabel('UI/Industry/InstalledByAnyone'),
                 INSTALLER_ANY),
                (localization.GetByLabel('UI/Industry/InstalledByMe'),
                 INSTALLER_ME, None,
                 'res:/UI/Texture/classes/Industry/iconPersonal.png'),
                (localization.GetByLabel('UI/Industry/InstalledByCorpmates'),
                 INSTALLER_CORPMATE, None,
                 'res:/UI/Texture/classes/Industry/iconCorp.png'))

    def OnInstallerCombo(self, combo, key, value):
        settings.user.ui.Set('IndustryJobsBrowserInstaller', value)
        self.UpdateScroll()

    def UpdateInstallerCombo(self):
        self.installerCombo.display = self.IsCorpSelected()
        value = settings.user.ui.Get('IndustryJobsBrowserInstaller',
                                     INSTALLER_ANY)
        self.installerCombo.SelectItemByValue(value)

    def OnOwnerCombo(self, combo, key, value):
        settings.user.ui.Set('IndustryBlueprintBrowserOwner', value)
        self.UpdateInstallerCombo()
        self.UpdateScroll()

    def IsCorpSelected(self):
        return self.ownerCombo.GetValue() == OWNER_CORP

    def UpdateOwnerCombo(self):
        options = [(localization.GetByLabel('UI/Industry/OwnedByMe'), OWNER_ME)
                   ]
        if sm.GetService('blueprintSvc').CanSeeCorpBlueprints():
            options.append((localization.GetByLabel('UI/Industry/OwnedByCorp'),
                            OWNER_CORP, None,
                            'res:/UI/Texture/classes/Industry/iconCorp.png'))
        select = settings.user.ui.Get('IndustryBlueprintBrowserOwner',
                                      OWNER_ME)
        self.ownerCombo.LoadOptions(options, select=select)

    def _UpdateJobCountersThread(self):
        msecs = 0
        while not self.destroyed:
            animate = False
            msecs += INTERVAL_UPDATE
            if msecs >= INTERVAL_FLASH:
                msecs = 0
                animate = True
            nodes = self.scroll.GetVisibleNodes()
            for i, node in enumerate(nodes):
                if node.panel:
                    node.panel.UpdateValues(animate, i)

            blue.synchro.SleepWallclock(INTERVAL_UPDATE)

    def DeliverAllJobs(self, *args):
        self.DeliverJobs(self.scroll.GetNodes())

    def DeliverSelectedJobs(self, *args):
        self.DeliverJobs(self.scroll.GetSelected())

    def DeliverJobs(self, nodes):
        jobIDs = [
            node.jobData.jobID for node in nodes
            if node.jobData.status == industry.STATUS_READY
        ]
        sm.GetService('industrySvc').CompleteJobs(jobIDs)
        sm.GetService('audio').SendUIEvent('ind_jobDelivered')
Exemple #5
0
class BrowserBlueprints(Container):
    default_name = 'BrowserBlueprints'
    default_isCorp = False
    __notifyevents__ = ['OnBlueprintReload', 'OnIndustryJob']

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        sm.RegisterNotify(self)
        self.callback = attributes.callback
        self.isInitialized = False
        self.jobData = None
        self.solarsystemIDbyFacilityID = {}

    def SetFocus(self, *args):
        if self.isInitialized:
            uicore.registry.SetFocus(self.scroll)

    def UpdateSelectedEntry(self):
        if self.jobData:
            self.OnActivitySelected(self.jobData.blueprintID, self.jobData.activityID)

    def OnNewJobData(self, jobData):
        self.jobData = jobData
        if self.isInitialized:
            self.UpdateSelectedEntry()

    def OnTabSelect(self):
        if self.isInitialized:
            self.UpdateOwnerCombo()
            self.UpdateScroll()
            return
        self.isInitialized = True
        self.topPanel = Container(name='topPanel', parent=self, align=TOTOP, height=20, padding=(0, 6, 0, 6))
        self.scroll = Scroll(parent=self, id='BlueprintBrowser')
        self.scroll.OnSelectionChange = self.OnScrollSelectionChange
        self.scroll.OnKeyDown = self.OnScrollKeyDown
        self.scroll.OnChar = self.OnScrollChar
        utilMenuCont = Container(align=uiconst.TOLEFT, parent=self.topPanel, width=20)
        UtilMenu(menuAlign=uiconst.BOTTOMLEFT, parent=utilMenuCont, align=uiconst.CENTERLEFT, GetUtilMenu=self.GetSettingsMenu, texturePath='res:/UI/Texture/SettingsCogwheel.png', width=16, height=16, iconSize=18)
        self.ownerCombo = Combo(name='ownerCombo', parent=self.topPanel, align=uiconst.TOLEFT, callback=self.OnOwnerCombo, width=120)
        self.facilityCombo = Combo(name='facilityCombo', parent=self.topPanel, align=uiconst.TOLEFT, callback=self.OnFacilityCombo, width=200, padLeft=5)
        self.invLocationCombo = Combo(name='invLocationCombo', parent=self.topPanel, align=uiconst.TOLEFT, callback=self.OnInvLocationCombo, padLeft=5, width=120, settingsID='IndustryBlueprintBrowserInvLocation')
        self.blueprintTypeCombo = Combo(name='blueprintTypeCombo', parent=self.topPanel, align=uiconst.TOLEFT, callback=self.OnBlueprintTypeCombo, padLeft=5, width=100, settingsID='IndustryBlueprintBrowserType', options=self.GetBlueprintTypeComboOptions())
        self.categoryGroupCombo = Combo(name='categoryGroupCombo ', parent=self.topPanel, align=uiconst.TOLEFT, callback=self.OnCategoryGroupCombo, padLeft=5, width=100)
        self.viewModeButtons = ViewModeButtons(parent=self.topPanel, align=uiconst.TORIGHT, controller=self, settingsID='IndustryBlueprintBrowserViewMode')
        self.filterEdit = QuickFilterEdit(name='searchField', parent=self.topPanel, hinttext=localization.GetByLabel('UI/Inventory/Filter'), maxLength=64, align=uiconst.TORIGHT, padRight=4)
        self.filterEdit.ReloadFunction = self.OnFilterEdit
        self.UpdateOwnerCombo()
        self.UpdateBlueprintTypeCombo()
        self.UpdateScroll()

    def GetSettingsMenu(self, menuParent):
        menuParent.AddCheckBox(text=localization.GetByLabel('UI/Industry/ShowBlueprintsInUse'), checked=self.IsBlueprintsInUseShown(), callback=self.ToggleShowBlueprintsInUse)

    def ToggleShowBlueprintsInUse(self):
        settings.user.ui.Set('industryShowBlueprintsInUse', not self.IsBlueprintsInUseShown())
        self.UpdateScroll()

    @telemetry.ZONE_METHOD
    def OnActivitySelected(self, itemID, activityID = None):
        if not self.isInitialized or activityID is None:
            return
        for node in self.scroll.GetNodes():
            node.selected = node.bpData.blueprintID == itemID
            self.scroll.UpdateSelection(node)
            if node.panel is None:
                continue
            node.panel.OnActivitySelected(itemID, activityID)

    def OnBlueprintReload(self, ownerID):
        if self.destroyed or not self.isInitialized:
            return
        if self.isInitialized and self.display:
            self.UpdateScroll()

    def OnIndustryJob(self, jobID, ownerID, blueprintID, installerID, status, successfulRuns):
        if not self.isInitialized:
            return
        for node in self.scroll.GetNodes():
            if node.bpData.blueprintID == blueprintID:
                if status < industry.STATUS_COMPLETED:
                    node.bpData.jobID = jobID
                else:
                    node.bpData.jobID = None
                if node.panel:
                    node.panel.OnJobStateChanged(status)

    def OnFilterEdit(self):
        self.UpdateScroll()

    def OnViewModeChanged(self, viewMode):
        self.UpdateScroll()

    def UpdateFacilityCombo(self, facilities):
        options = [(localization.GetByLabel('UI/Industry/AllFacilities'), FACILITY_ALL)]
        defaultFacilityID = self.GetDefaultFacilitySelection()
        facilities.setdefault(defaultFacilityID, 0)
        for facilityID, blueprintCount in facilities.iteritems():
            try:
                facility = sm.GetService('facilitySvc').GetFacility(facilityID)
                if facility:
                    self.solarsystemIDbyFacilityID[facilityID] = facility.solarSystemID
                    options.append((self.GetFacilityLabel(facility, blueprintCount), facilityID))
            except UserError:
                pass

        options = sorted(options, key=self._GetFacilitySortKey)
        self.facilityCombo.LoadOptions(options, select=defaultFacilityID)

    def GetDefaultFacilitySelection(self):
        if self.IsCorpSelected():
            facilityID = settings.user.ui.Get('BrowserBlueprintsFacilitiesCorp', FACILITY_CURRENT)
        else:
            facilityID = settings.user.ui.Get('BrowserBlueprintsFacilities', FACILITY_CURRENT)
        if isinstance(facilityID, tuple) or facilityID is None:
            facilityID = FACILITY_CURRENT
        if facilityID == FACILITY_CURRENT:
            facilityID = session.stationid2
        return facilityID

    def GetDefaultInvLocationSelection(self):
        if self.IsCorpSelected():
            return settings.user.ui.Get('BrowserBlueprintsInvLocationCorp', None)
        else:
            return settings.user.ui.Get('BrowserBlueprintsInvLocation', None)

    def _GetFacilitySortKey(self, option):
        _, facilityID = option
        if facilityID == FACILITY_ALL:
            return FACILITY_ALL
        if facilityID == session.stationid2:
            return FACILITY_CURRENT
        solarsystemID = self.solarsystemIDbyFacilityID[facilityID]
        return self.GetJumpsTo(solarsystemID)

    def GetFacilityLabel(self, facility, blueprintCount):
        if session.stationid2 and facility.facilityID == session.stationid2:
            return localization.GetByLabel('UI/Industry/CurrentStation')
        return localization.GetByLabel('UI/ScienceAndIndustry/ScienceAndIndustryWindow/LocationNumberOfBlueprintsNumberOfJumps', locationName=facility.GetName(), blueprints=blueprintCount, jumps=facility.distance)

    def GetJumpsTo(self, solarsystemID):
        return sm.GetService('clientPathfinderService').GetJumpCountFromCurrent(solarsystemID) or 0

    def OnFacilityCombo(self, combo, key, value):
        if value == session.stationid2:
            value = FACILITY_CURRENT
        if self.IsCorpSelected():
            settings.user.ui.Set('BrowserBlueprintsFacilitiesCorp', value)
        else:
            settings.user.ui.Set('BrowserBlueprintsFacilities', value)
        self.UpdateScroll()

    def GetInvLocations(self, blueprints):
        locations = {}
        for bpData in blueprints:
            flagID = bpData.flagID
            if self.IsContainerFlag(flagID):
                flagID = const.flagHangar
            locations[bpData.locationID, flagID] = bpData

        locations = locations.items()
        locations = sorted(locations, cmp=self._CompareLocations)
        return locations

    def _CompareLocations(self, location1, location2):
        (locationID1, flagID1), bpData1 = location1
        (locationID2, flagID2), bpData2 = location2
        idx1 = CORP_DIVISIONS.index(flagID1) if flagID1 in CORP_DIVISIONS else None
        idx2 = CORP_DIVISIONS.index(flagID2) if flagID2 in CORP_DIVISIONS else None
        if idx1 is None and idx2 is None:
            return cmp(bpData1.GetLocationName(), bpData2.GetLocationName())
        elif idx1 is None and idx2 is not None:
            return 1
        elif idx1 is not None and idx2 is None:
            return -1
        else:
            return cmp(idx1, idx2)

    def GetSelectedFacilityID(self):
        facilityID = self.facilityCombo.GetValue()
        if facilityID == FACILITY_CURRENT:
            return session.stationid2
        return facilityID

    def UpdateInvLocationCombo(self, blueprints):
        facilityID = self.GetSelectedFacilityID()
        options = []
        if facilityID and facilityID != FACILITY_ALL:
            locations = self.GetInvLocations(blueprints)
            options.extend([ (bpData.GetLocationName(),
             key,
             None,
             bpData.location.GetIcon()) for key, bpData in locations ])
            options = sorted(options)
        if len(options) != 1:
            options.insert(0, (localization.GetByLabel('UI/Industry/AllInventoryLocations'), (None, None)))
        self.invLocationCombo.LoadOptions(options, select=self.GetDefaultInvLocationSelection())

    def OnOwnerCombo(self, combo, key, value):
        settings.user.ui.Set('IndustryBlueprintBrowserOwner', value)
        self.UpdateBlueprintTypeCombo()
        self.UpdateScroll()

    def OnInvLocationCombo(self, combo, key, value):
        if self.IsCorpSelected():
            settings.user.ui.Set('BrowserBlueprintsInvLocationCorp', value)
        else:
            settings.user.ui.Set('BrowserBlueprintsInvLocation', value)
        self.UpdateScroll()

    def UpdateBlueprintTypeCombo(self):
        value = self.GetDefaultBlueprintTypeSelection()
        self.blueprintTypeCombo.SelectItemByValue(value)

    def GetDefaultBlueprintTypeSelection(self):
        if self.IsCorpSelected():
            return settings.user.ui.Get('BrowserBlueprintsBlueprintTypeCorp', BLUEPRINTS_ALL)
        else:
            return settings.user.ui.Get('BrowserBlueprintsBlueprintType', BLUEPRINTS_ALL)

    def OnBlueprintTypeCombo(self, combo, key, value):
        if self.IsCorpSelected():
            settings.user.ui.Set('BrowserBlueprintsBlueprintTypeCorp', value)
        else:
            settings.user.ui.Set('BrowserBlueprintsBlueprintType', value)
        self.UpdateScroll()

    def GetBlueprintTypeComboOptions(self):
        return ((localization.GetByLabel('UI/Industry/AllBlueprints'), BLUEPRINTS_ALL), (localization.GetByLabel('UI/Industry/Originals'),
          BLUEPRINTS_ORIGINAL,
          None,
          'res:/UI/Texture/icons/bpo.png'), (localization.GetByLabel('UI/Industry/Copies'),
          BLUEPRINTS_COPY,
          None,
          'res:/UI/Texture/icons/bpc.png'))

    def OnCategoryGroupCombo(self, combo, key, value):
        if self.IsCorpSelected():
            settings.user.ui.Set('BrowserBlueprintsCategoryGroupCorp', value)
        else:
            settings.user.ui.Set('BrowserBlueprintsCategoryGroup', value)
        self.UpdateScroll()

    def GetDefaultCategoryGroup(self):
        if self.IsCorpSelected():
            return settings.user.ui.Get('BrowserBlueprintsCategoryGroupCorp', GROUPS_ALL)
        else:
            return settings.user.ui.Get('BrowserBlueprintsCategoryGroup', GROUPS_ALL)

    def UpdateCategoryGroupCombo(self, blueprints):
        groupsByCategories = self.GetGroupsByCategories(blueprints)
        options = [(localization.GetByLabel('UI/Industry/AllGroups'), GROUPS_ALL)]
        for (categoryName, categoryID), groups in groupsByCategories:
            options.append((categoryName, (categoryID, None)))
            for groupName, groupID in groups:
                options.append((groupName,
                 (categoryID, groupID),
                 '',
                 None,
                 1))

        self.categoryGroupCombo.LoadOptions(options, select=self.GetDefaultCategoryGroup())

    def GetGroupsByCategories(self, blueprints):
        ids = defaultdict(set)
        for bpData in blueprints:
            groupAndCategory = bpData.GetProductGroupAndCategory()
            ids[groupAndCategory.categoryName, groupAndCategory.categoryID].add((groupAndCategory.groupName, groupAndCategory.groupID))

        ret = []
        for category, groups in ids.iteritems():
            ret.append((category, list(groups)))

        ret.sort()
        for category, groups in ret:
            groups.sort()

        return ret

    def IsCorpSelected(self):
        return self.ownerCombo.GetValue() == OWNER_CORP

    def UpdateScroll(self):
        if self.IsHidden() or self.destroyed:
            return None
        self.scroll.ShowLoading()
        facilityID = self.GetDefaultFacilitySelection()
        blueprints, facilities = self.GetBlueprintsData(facilityID)
        self.UpdateFacilityCombo(facilities)
        self.UpdateInvLocationCombo(blueprints)
        self.scroll.HideLoading()
        if not len(blueprints):
            self.scroll.LoadContent(noContentHint=localization.GetByLabel('UI/Industry/NoBlueprintsFound'))
            return None
        showFacility = facilityID == FACILITY_ALL
        showLocation = self.invLocationCombo.GetValue() == (None, None)
        scrollList = self.GetScrollList(blueprints, showFacility, showLocation)
        self.scroll.sr.defaultColumnWidth = BlueprintEntry.GetDefaultColumnWidth()
        self.scroll.sr.fixedColumns = BlueprintEntry.GetFixedColumns(self.viewModeButtons.GetViewMode())
        self.scroll.LoadContent(contentList=scrollList, headers=BlueprintEntry.GetHeaders(showFacility=showFacility, showLocation=showLocation), noContentHint=localization.GetByLabel('UI/Industry/NoBlueprintsFound'))
        self.UpdateSelectedEntry()

    def GetFilteredBlueprints(self, blueprints):
        jumpsCache = {}
        jumpsAndBlueprints = []
        for bpData in blueprints:
            if self.IsFilteredOut(bpData):
                continue
            jumpsAndBlueprints.append((jumpsCache.setdefault(bpData.facilityID, bpData.GetDistance()), bpData))
            blue.pyos.BeNice()

        self.UpdateCategoryGroupCombo([ bpData for _, bpData in jumpsAndBlueprints ])
        categoryID, groupID = self.categoryGroupCombo.GetValue()
        if (categoryID, groupID) == GROUPS_ALL:
            return jumpsAndBlueprints
        ret = []
        for jumps, bpData in jumpsAndBlueprints:
            typeID = bpData.GetProductOrBlueprintTypeID()
            if groupID:
                if evetypes.GetGroupID(typeID) == groupID:
                    ret.append((jumps, bpData))
            elif evetypes.GetCategoryID(typeID) == categoryID:
                ret.append((jumps, bpData))

        return ret

    def GetScrollList(self, blueprints, showFacility = True, showLocation = True):
        scrollList = []
        jumpsAndBlueprints = self.GetFilteredBlueprints(blueprints)
        for jumps, bpData in jumpsAndBlueprints:
            node = Bunch(bpData=bpData, decoClass=BlueprintEntry, sortValues=BlueprintEntry.GetColumnSortValues(bpData, jumps, showFacility, showLocation), viewMode=self.viewModeButtons.GetViewMode(), jumps=jumps, activityCallback=self.SelectActivity, showFacility=showFacility, showLocation=showLocation, item=bpData.GetItem(), charIndex=bpData.GetLabel())
            scrollList.append(node)
            blue.pyos.BeNice()

        return scrollList

    def GetBlueprintsData(self, facilityID):
        facilityID = facilityID if facilityID != FACILITY_ALL else None
        if self.IsCorpSelected():
            return sm.GetService('blueprintSvc').GetCorporationBlueprints(facilityID)
        else:
            return sm.GetService('blueprintSvc').GetCharacterBlueprints(facilityID)

    def IsFilteredOut(self, bpData):
        filterText = self.filterEdit.GetValue().strip().lower()
        if filterText:
            productTypeObj = bpData.GetProductGroupAndCategory()
            text = bpData.GetName() + bpData.GetFacilityName() + bpData.GetLocationName() + productTypeObj.groupName + productTypeObj.categoryName
            if text.lower().find(filterText) == -1:
                return True
        locationID, flagID = self.invLocationCombo.GetValue()
        if locationID:
            if bpData.locationID != locationID:
                return True
            if bpData.flagID != flagID and not self.IsContainerFlag(bpData.flagID):
                return True
        bpType = self.blueprintTypeCombo.GetValue()
        if bpType != BLUEPRINTS_ALL:
            if bpData.original != (bpType == BLUEPRINTS_ORIGINAL):
                return True
        if not self.IsBlueprintsInUseShown():
            if bpData.jobID is not None:
                return True
        return False

    def IsBlueprintsInUseShown(self):
        return settings.user.ui.Get('industryShowBlueprintsInUse', True)

    def IsContainerFlag(self, flagID):
        return flagID in (const.flagLocked, const.flagUnlocked)

    def OnScrollSelectionChange(self, entries):
        self.SelectActivity(entries[0].bpData)

    def OnScrollKeyDown(self, key, flag):
        Scroll.OnKeyDown(self.scroll, key, flag)
        if key in (uiconst.VK_LEFT, uiconst.VK_RIGHT):
            sm.ScatterEvent('OnIndustryLeftOrRightKey', key)

    def OnScrollChar(self, key, flag):
        if key >= uiconst.VK_0 and key <= uiconst.VK_9 or key == uiconst.VK_BACK:
            sm.ScatterEvent('OnBlueprintBrowserNumericInput', key, flag)

    def SelectActivity(self, bpData, activityID = None):
        self.callback(bpData, activityID)

    def UpdateOwnerCombo(self):
        options = [(localization.GetByLabel('UI/Industry/OwnedByMe'), OWNER_ME)]
        if sm.GetService('blueprintSvc').CanSeeCorpBlueprints():
            options.append((localization.GetByLabel('UI/Industry/OwnedByCorp'),
             OWNER_CORP,
             None,
             'res:/UI/Texture/classes/Industry/iconCorp.png'))
        select = settings.user.ui.Get('IndustryBlueprintBrowserOwner', OWNER_ME)
        self.ownerCombo.LoadOptions(options, select=select)
Exemple #6
0
class BrowserFacilities(Container):
    default_name = 'BrowserFacilities'
    __notifyevents__ = ['OnFacilityReload']

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        sm.RegisterNotify(self)
        self.callback = attributes.callback
        self.isInitialized = False

    def _OnClose(self, *args):
        sm.UnregisterNotify(self)

    def OnTabSelect(self):
        if self.isInitialized:
            self.UpdateScroll()
            return
        self.isInitialized = True
        self.topPanel = Container(name='topPanel',
                                  parent=self,
                                  align=uiconst.TOTOP,
                                  height=20,
                                  padding=(0, 6, 0, 6))
        self.scroll = Scroll(parent=self, id='InstallationBrowser')
        self.scroll.OnSelectionChange = self.OnScrollSelectionChange
        self.ownerCombo = Combo(name='ownerCombo',
                                parent=self.topPanel,
                                align=uiconst.TOLEFT,
                                prefsKey='IndustryBlueprintOwner',
                                callback=self.OnOwnerCombo,
                                options=self.GetOwnerOptions(),
                                width=120,
                                padRight=4)
        self.activityCombo = Combo(name='activityCombo',
                                   parent=self.topPanel,
                                   align=uiconst.TOLEFT,
                                   prefsKey='IndustryBlueprintActivity',
                                   callback=self.OnActivityCombo,
                                   options=self.GetActivityOptions(),
                                   width=120,
                                   padRight=4)
        self.viewModeButtons = ViewModeButtons(
            parent=self.topPanel,
            align=uiconst.TORIGHT,
            controller=self,
            settingsID='IndustryBlueprintBrowserViewMode')
        self.filterEdit = QuickFilterEdit(
            name='searchField',
            parent=self.topPanel,
            hinttext=localization.GetByLabel('UI/Inventory/Filter'),
            maxLength=64,
            align=uiconst.TORIGHT,
            OnClearFilter=self.OnFilterEditCleared,
            padRight=4)
        self.filterEdit.ReloadFunction = self.OnFilterEdit
        self.UpdateScroll()

    def OnFacilityReload(self, *args):
        if self.isInitialized and self.display:
            self.UpdateScroll()

    def OnScrollSelectionChange(self, entries, activityID=None):
        self.callback(entries[0].facilityData)

    def OnFilterEdit(self):
        self.UpdateScroll()

    def OnFilterEditCleared(self):
        self.UpdateScroll()

    def UpdateScroll(self):
        installations = self.GetInstallationData()
        scrollList = self.GetScrollList(installations)
        self.scroll.sr.defaultColumnWidth = FacilityEntry.GetDefaultColumnWidth(
        )
        self.scroll.sr.fixedColumns = FacilityEntry.GetFixedColumns(
            self.viewModeButtons.GetViewMode())
        self.scroll.LoadContent(contentList=scrollList,
                                headers=FacilityEntry.GetHeaders(),
                                noContentHint=localization.GetByLabel(
                                    'UI/Industry/NoFacilitiesFound'))

    def GetInstallationData(self):
        installations = sm.GetService('facilitySvc').GetFacilities()
        cfg.evelocations.Prime(
            (facilityData.facilityID for facilityData in installations))
        cfg.eveowners.Prime(
            (facilityData.ownerID for facilityData in installations))
        return installations

    def GetScrollList(self, installations):
        scrollList = []
        for facilityData in installations:
            jumps = self.GetJumpsTo(facilityData.solarSystemID)
            if self.IsFilteredOut(facilityData):
                continue
            activityID = self.activityCombo.GetValue()
            node = Bunch(facilityData=facilityData,
                         decoClass=FacilityEntry,
                         sortValues=FacilityEntry.GetColumnSortValues(
                             facilityData, jumps, activityID),
                         viewMode=self.viewModeButtons.GetViewMode(),
                         jumps=jumps,
                         charIndex=facilityData.GetName(),
                         activityID=activityID)
            scrollList.append(node)

        return scrollList

    def IsFilteredOut(self, facilityData):
        if not facilityData.activities:
            return True
        filterText = self.filterEdit.GetValue().strip().lower()
        if filterText:
            text = facilityData.GetName() + facilityData.GetOwnerName(
            ) + facilityData.GetTypeName()
            if text.lower().find(filterText) == -1:
                return True
        activityValue = self.activityCombo.GetValue()
        if activityValue and activityValue not in facilityData.activities:
            return True
        ownerValue = self.ownerCombo.GetValue()
        if ownerValue != OWNER_ANY:
            isCorporation = facilityData.ownerID == session.corpid
            if not isCorporation and ownerValue != OWNER_NPC:
                return True
            if isCorporation and ownerValue != OWNER_CORP:
                return True
        return False

    def GetJumpsTo(self, solarsystemID):
        return sm.GetService(
            'clientPathfinderService').GetJumpCountFromCurrent(solarsystemID)

    def OnViewModeChanged(self, viewMode):
        self.UpdateScroll()

    def OnActivityCombo(self, *args):
        self.UpdateScroll()

    def GetActivityOptions(self):
        ret = [
            (localization.GetByLabel(ACTIVITY_NAMES[activityID]), activityID,
             None, industryUIConst.ACTIVITY_ICONS_SMALL[activityID])
            for activityID in ACTIVITIES
        ]
        ret.insert(0,
                   (localization.GetByLabel('UI/Industry/AllActivities'), 0))
        return ret

    def GetOwnerOptions(self):
        return [
            (localization.GetByLabel('UI/Industry/AllFacilities'), OWNER_ANY),
            (localization.GetByLabel('UI/Industry/PublicFacilities'),
             OWNER_NPC, None,
             'res:/UI/Texture/Classes/Inventory/readOnly.png'),
            (localization.GetByLabel('UI/Industry/CorpOwnedFacilities'),
             OWNER_CORP, None, 'res:/UI/Texture/Classes/Industry/iconCorp.png')
        ]

    def OnOwnerCombo(self, *args):
        self.UpdateScroll()