contactManagementWindow.py (7665B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\addressBook\contactManagementWindow.py 2 import localization 3 from carbonui import ButtonVariant, uiconst 4 from carbonui.button.group import ButtonGroup 5 from carbonui.control.button import Button 6 from carbonui.control.combo import Combo 7 from carbonui.control.window import Window 8 from carbonui.primitives.container import Container 9 from carbonui.primitives.containerAutoSize import ContainerAutoSize 10 from carbonui.uicore import uicore 11 from carbonui.util import various_unsorted 12 from eve.client.script.ui.shared.standings.levelSelector import StandingLevelSelector 13 from eve.client.script.ui.control import eveEditPlainText, eveIcon, eveLabel 14 from carbonui.control.checkbox import Checkbox 15 from eve.common.lib import appConst 16 from eve.common.script.sys import idCheckers 17 from localization import GetByLabel 18 STANDING_DESCRIPTION = {appConst.contactHighStanding: localization.GetByLabel('UI/PeopleAndPlaces/ExcellentStanding'), 19 appConst.contactGoodStanding: localization.GetByLabel('UI/PeopleAndPlaces/GoodStanding'), 20 appConst.contactNeutralStanding: localization.GetByLabel('UI/PeopleAndPlaces/NeutralStanding'), 21 appConst.contactBadStanding: localization.GetByLabel('UI/PeopleAndPlaces/BadStanding'), 22 appConst.contactHorribleStanding: localization.GetByLabel('UI/PeopleAndPlaces/TerribleStanding')} 23 24 class ContactManagementWnd(Window): 25 default_captionLabelPath = 'UI/PeopleAndPlaces/ContactManagement' 26 default_fixedWidth = 280 27 28 def ApplyAttributes(self, attributes): 29 super(ContactManagementWnd, self).ApplyAttributes(attributes) 30 entityID = attributes.entityID 31 level = attributes.level 32 if level is None: 33 level = appConst.contactNeutralStanding 34 watchlist = attributes.watchlist 35 isContact = attributes.isContact 36 self.labelID = attributes.get('labelID', None) 37 self.result = None 38 self.entityID = entityID 39 self.level = level 40 self.watchlist = watchlist 41 self.isContact = isContact 42 self.notify = False 43 self.ConstructLayout() 44 45 def OnMainContainerSizeChanged(self, *args, **kwds): 46 _, height = self.GetWindowSizeForContentSize(height=self.mainCont.height) 47 self.SetFixedHeight(height) 48 49 def ConstructLayout(self): 50 self.mainCont = ContainerAutoSize(name='topCont', parent=self.sr.main, align=uiconst.TOTOP, alignMode=uiconst.TOTOP, callback=self.OnMainContainerSizeChanged) 51 self.ConstructImage() 52 self.ConstructNameLabel() 53 self.ConstructLevelSelector() 54 self.ConstructLabelsCombo() 55 if idCheckers.IsCharacter(self.entityID): 56 self.ConstructCharacterOptions() 57 self.ConstructBottomButtons() 58 59 def ConstructNameLabel(self): 60 charName = self._GetCharName() 61 label = eveLabel.EveLabelLargeBold(text=charName, parent=self.mainCont, align=uiconst.TOTOP) 62 63 def _GetCharName(self): 64 charName = cfg.eveowners.Get(self.entityID).name 65 return charName 66 67 def ConstructImage(self): 68 imgCont = Container(name='imgCont', parent=self.mainCont, align=uiconst.TOLEFT, width=64, padRight=uiconst.defaultPadding) 69 eveIcon.GetOwnerLogo(imgCont, self.entityID, size=64, noServerCall=True) 70 71 def ConstructBottomButtons(self): 72 if self.isContact: 73 confirmText = localization.GetByLabel('UI/PeopleAndPlaces/EditContact') 74 else: 75 confirmText = localization.GetByLabel('UI/PeopleAndPlaces/AddContact') 76 self.btnGroup = ButtonGroup(parent=self.mainCont, align=uiconst.TOTOP, padTop=16, padLeft=-64) 77 confirm_button = Button(parent=self.btnGroup, label=confirmText, func=self.Confirm, args=(), btn_modalresult=1, btn_default=1, variant=ButtonVariant.PRIMARY) 78 Button(parent=self.btnGroup, label=GetByLabel('UI/Common/Buttons/Cancel'), func=self.Cancel, args=()) 79 uicore.registry.SetFocus(confirm_button) 80 81 def ConstructCharacterOptions(self): 82 self.inWatchlistCb = Checkbox(text=localization.GetByLabel('UI/PeopleAndPlaces/AddContactToWatchlist'), parent=self.mainCont, settingsKey='inWatchlistCb', checked=self.watchlist, align=uiconst.TOTOP, hint=localization.GetByLabel('UI/PeopleAndPlaces/BuddyListHint'), padTop=16) 83 charName = self._GetCharName() 84 self.sendNotificationCb = Checkbox(text=localization.GetByLabel('UI/PeopleAndPlaces/SendNotificationTo', contactName=charName), parent=self.mainCont, settingsKey='sendNotificationCb', checked=0, align=uiconst.TOTOP, callback=self.OnNotificationChange) 85 self.message = eveEditPlainText.EditPlainText(setvalue='', parent=self.mainCont, align=uiconst.TOTOP, height=70, state=uiconst.UI_DISABLED, opacity=0.3, maxLength=120, padBottom=uiconst.defaultPadding, hintText=GetByLabel('UI/PeopleAndPlaces/MessageTo', charName=charName)) 86 87 def ConstructLabelsCombo(self): 88 labels = sm.GetService('addressbook').GetContactLabels('contact').values() 89 if not self.isContact and len(labels): 90 options = self._GetLabelComboOptions(labels) 91 self.labelsCombo = Combo(name='labelscombo', label='', parent=self.mainCont, align=uiconst.TOTOP, options=options, padTop=8) 92 if self.labelID: 93 self.labelsCombo.SetValue(self.labelID) 94 else: 95 self.labelsCombo = None 96 97 def _GetLabelComboOptions(self, labels): 98 options = [] 99 for label in labels: 100 options.append((label.name.lower(), (label.name, label.labelID))) 101 102 options = various_unsorted.SortListOfTuples(options) 103 assignLabelText = '-- %s --' % localization.GetByLabel('UI/Mail/AssignLabel') 104 options.insert(0, (assignLabelText, None)) 105 return options 106 107 def ConstructLevelSelector(self): 108 self.levelText = eveLabel.EveLabelMedium(text=self._GetLevelText(), parent=self.mainCont, align=uiconst.TOTOP, state=uiconst.UI_DISABLED, padTop=4) 109 self.levelSelector = StandingLevelSelector(name='levelCont', parent=self.mainCont, align=uiconst.TOTOP, height=20, padTop=4, level=self.level) 110 self.levelSelector.OnStandingLevelSelected = self.OnStandingLevelSelected 111 112 def _GetLevelText(self): 113 if self.level is None: 114 levelText = localization.GetByLabel('UI/PeopleAndPlaces/SelectStanding') 115 else: 116 levelText = STANDING_DESCRIPTION.get(self.level, u'') 117 return levelText 118 119 def OnNotificationChange(self, cb): 120 if cb.GetValue(): 121 self.message.opacity = 1.0 122 self.message.Enable() 123 else: 124 self.message.opacity = 0.3 125 self.message.Disable() 126 127 def OnStandingLevelSelected(self, level): 128 self.level = level 129 self.levelText.text = STANDING_DESCRIPTION.get(self.level, u'') 130 131 def Confirm(self): 132 relationshipID = self.level 133 inWatchlist = False 134 sendNotification = False 135 message = None 136 contactLabel = None 137 if self.labelsCombo: 138 contactLabel = self.labelsCombo.GetValue() 139 if idCheckers.IsCharacter(self.entityID): 140 inWatchlist = self.inWatchlistCb.checked 141 sendNotification = self.sendNotificationCb.checked 142 message = self.message.GetValue() 143 self.result = (relationshipID, 144 inWatchlist, 145 sendNotification, 146 message, 147 contactLabel) 148 if getattr(self, 'isModal', None): 149 self.SetModalResult(1) 150 151 def Cancel(self): 152 self.result = None 153 if getattr(self, 'isModal', None): 154 self.SetModalResult(0)