fontAttributePanel.py (8877B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\control\fontAttributePanel.py 2 import localization 3 import telemetry 4 from carbon.client.script.environment.AudioUtil import PlaySound 5 from carbon.common.script.util.commonutils import StripTags 6 from carbonui import uiconst 7 from carbonui.control.combo import Combo 8 from carbonui.control.editPlainText import EditPlainTextCore 9 from carbonui.control.label import LabelOverride as Label 10 from carbonui.primitives.container import Container 11 from carbonui.primitives.containerAutoSize import ContainerAutoSize 12 from carbonui.text.color import TextColor 13 from carbonui.uicore import uicore 14 from eve.client.script.ui.shared.dropdownColorPicker import DropdownColorPicker 15 from player_messaging.client.ui_message import prompt_player_fsd_dialog 16 17 class FontAttributePanel(Container): 18 __guid__ = 'uicontrols.FontAttribPanel' 19 default_height = 32 20 21 def ApplyAttributes(self, attributes): 22 Container.ApplyAttributes(self, attributes) 23 self.counterMax = attributes.counterMax 24 self.countWithTags = attributes.countWithTags 25 self.boldBtn = LabelButton(text=localization.GetByLabel('/Carbon/UI/Controls/EditRichText/BoldSymbol'), parent=self, width=12, align=uiconst.TOLEFT, fontsize=14, padLeft=4, state=uiconst.UI_NORMAL, func=self.ToggleBold, hint=localization.GetByLabel('/Carbon/UI/Controls/EditRichText/Bold')) 26 self.italicBtn = LabelButton(text=localization.GetByLabel('/Carbon/UI/Controls/EditRichText/ItalicSymbol'), parent=self, pos=(0, 0, 12, 0), align=uiconst.TOLEFT, fontsize=14, state=uiconst.UI_NORMAL, func=self.ToggleItalic, minWidth=10, hint=localization.GetByLabel('/Carbon/UI/Controls/EditRichText/Italic')) 27 self.underlineBtn = LabelButton(text=localization.GetByLabel('/Carbon/UI/Controls/EditRichText/UnderlineSymbol'), parent=self, pos=(0, 0, 12, 0), align=uiconst.TOLEFT, fontsize=14, state=uiconst.UI_NORMAL, func=self.ToggleUnderline, hint=localization.GetByLabel('/Carbon/UI/Controls/EditRichText/Underline')) 28 self.colorPicker = EditTextColorPickerCont(parent=self, pos=(0, 0, 12, 12), callback=self.SetColorForLabel, align=uiconst.TOLEFT, padLeft=4) 29 options = [[localization.formatters.FormatNumeric(8), 8], 30 [localization.formatters.FormatNumeric(9), 9], 31 [localization.formatters.FormatNumeric(10), 10], 32 [localization.formatters.FormatNumeric(11), 11], 33 [localization.formatters.FormatNumeric(12), 12], 34 [localization.formatters.FormatNumeric(13), 13], 35 [localization.formatters.FormatNumeric(14), 14], 36 [localization.formatters.FormatNumeric(18), 18], 37 [localization.formatters.FormatNumeric(24), 24], 38 [localization.formatters.FormatNumeric(30), 30], 39 [localization.formatters.FormatNumeric(36), 36]] 40 self.fontSizeCombo = Combo(parent=self, options=options, name='fontsize', select=12, callback=self.OnFontSizeChange, align=uiconst.TOLEFT, width=56, padding=(8, 4, 0, 4), hint=localization.GetByLabel('/Carbon/UI/Controls/EditRichText/FontSize')) 41 self.urlBtn = LabelButton(name='anchor', text=localization.GetByLabel('/Carbon/UI/Controls/EditRichText/LinkSymbol'), parent=self, align=uiconst.TOLEFT, fontsize=10, state=uiconst.UI_NORMAL, func=self.OnAnchorBtn, padding=(4, 0, 4, 0), hint=localization.GetByLabel('/Carbon/UI/Controls/EditRichText/AddLink')) 42 self.clearBtn = LabelButton(name='clearnote', text=localization.GetByLabel('/Carbon/UI/Controls/EditRichText/ClearTextSymbol'), parent=self, width=12, align=uiconst.TOLEFT, hint=localization.GetByLabel('/Carbon/UI/Controls/EditRichText/ClearText'), fontsize=14, state=uiconst.UI_NORMAL, func=self.ClearNote) 43 self.clearBtn.hint = localization.GetByLabel('/Carbon/UI/Controls/EditRichText/ClearText') 44 if self.counterMax is not None: 45 self.charCounter = Label(text='0/%s' % self.counterMax, parent=self, color=(1.0, 1.0, 1.0, 0.6), fontsize=12, left=4, align=uiconst.CENTERRIGHT, state=uiconst.UI_NORMAL) 46 self.expanding = 0 47 self.expanded = 0 48 49 def OnAnchorBtn(self): 50 PlaySound(uiconst.SOUND_BUTTON_CLICK) 51 return self.AddAnchor() 52 53 def ClearNote(self, *args): 54 PlaySound(uiconst.SOUND_BUTTON_CLICK) 55 response = prompt_player_fsd_dialog('ConfirmClearText', {}, uiconst.YESNO, uiconst.ID_YES) 56 if response == uiconst.ID_YES: 57 self.parent.SetValue('') 58 uicore.registry.SetFocus(self.parent) 59 60 def ToggleBold(self, *args): 61 self.parent.ToggleBold() 62 63 def ToggleUnderline(self, *args): 64 self.parent.ToggleUnderline() 65 66 def ToggleItalic(self, *args): 67 self.parent.ToggleItalic() 68 69 def AddAnchor(self, *args): 70 self.parent.AddAnchor() 71 72 def OnFontSizeChange(self, entry, header, value, *args): 73 self.parent.ChangeFontSize(value) 74 75 def AttribStateChange(self, bold, italic, underline, size, color, url, *args): 76 self.boldBtn.SetHighlighted(bold) 77 self.italicBtn.SetHighlighted(italic) 78 self.underlineBtn.SetHighlighted(underline) 79 self.colorPicker.SetCurrentFill(color) 80 self.fontSizeCombo.SelectItemByValue(size) 81 self.urlBtn.SetHighlighted(bool(url)) 82 83 def ShowOrHideCharacterCounter(self, showCounter = True): 84 if getattr(self, 'charCounter', None) is None: 85 return 86 self.charCounter.display = showCounter 87 88 @telemetry.ZONE_METHOD 89 def UpdateCounter(self, currentCount = None, *args): 90 if getattr(self, 'charCounter', None) is None or self.parent is None: 91 return 92 parent = self.parent 93 if currentCount is not None: 94 currentLen = currentCount 95 elif self.countWithTags: 96 currentLen = len(parent.GetValue()) 97 self._currentLen = currentLen 98 elif isinstance(parent, EditPlainTextCore): 99 currentLen = len(parent.GetAllText()) 100 else: 101 currentLen = len(StripTags(parent.GetSelectedText(getAll=True))) 102 currentLenText = currentLen 103 hint = '' 104 if currentLen > self.counterMax: 105 currentLenText = '<color=red>%s</color>' % currentLenText 106 hint = localization.GetByLabel('UI/Notepad/TooLongText') 107 self.charCounter.text = '%s/%s' % (currentLenText, self.counterMax) 108 self.charCounter.hint = hint 109 110 def SetColorForLabel(self, color, *args): 111 if color: 112 newColor = color + (1.0,) 113 else: 114 newColor = TextColor.NORMAL 115 self.parent.ChangeFontColor(newColor) 116 117 def HideEditOptions(self): 118 for eachElement in [self.boldBtn, 119 self.italicBtn, 120 self.underlineBtn, 121 self.colorPicker, 122 self.fontSizeCombo, 123 self.urlBtn, 124 self.clearBtn]: 125 eachElement.display = False 126 127 charCounter = getattr(self, 'charCounter', None) 128 if charCounter: 129 charCounter.left = 0 130 131 132 class LabelButton(ContainerAutoSize): 133 default_padLeft = 1 134 default_padRight = 1 135 default_minWidth = 10 136 137 def ApplyAttributes(self, attributes): 138 super(LabelButton, self).ApplyAttributes(attributes) 139 self.isHighlited = False 140 self.label = Label(parent=self, align=uiconst.CENTER, text=attributes.text, fontsize=attributes.fontsize, uppercase=attributes.uppercase, opacity=1.0) 141 self.func = attributes.func 142 self.hint = attributes.hint 143 144 def OnMouseEnter(self): 145 self.UpdateOpacity() 146 PlaySound(uiconst.SOUND_BUTTON_HOVER) 147 148 def OnMouseExit(self): 149 self.UpdateOpacity() 150 151 def OnClick(self): 152 PlaySound(uiconst.SOUND_BUTTON_CLICK) 153 self.func() 154 155 def SetHighlighted(self, isHighlighted): 156 self.isHighlited = isHighlighted 157 self.UpdateOpacity() 158 159 def UpdateOpacity(self): 160 if self.isHighlited: 161 self.SetOpacity(1.0) 162 elif uicore.uilib.mouseOver == self: 163 self.SetOpacity(0.8) 164 else: 165 self.SetOpacity(0.6) 166 167 168 class EditTextColorPickerCont(DropdownColorPicker): 169 __guid__ = 'editTextColorPickerCont' 170 default_height = 14 171 default_width = 14 172 default_colorPos = (0, 0, 16, 16) 173 default_numColumns = 4 174 COLOR_LIST = [(1.0, 1.0, 1.0), 175 (0.7, 0.7, 0.7), 176 (0.3, 0.3, 0.3), 177 (0.0, 0.0, 0.0), 178 (1.0, 1.0, 0.0), 179 (0.0, 1.0, 0.0), 180 (1.0, 0.0, 0.0), 181 (0.0, 0.0, 1.0), 182 (0.5, 0.5, 0.0), 183 (0.0, 0.5, 0.0), 184 (0.5, 0.0, 0.0), 185 (0.0, 0.0, 0.5), 186 (0.5, 0.0, 0.5), 187 (0.0, 1.0, 1.0), 188 (1.0, 0.0, 1.0), 189 (0.0, 0.5, 1.0)] 190 191 def ApplyAttributes(self, attributes): 192 DropdownColorPicker.ApplyAttributes(self, attributes) 193 self.arrowSprite.display = False 194 self.colorCont.width = self.width - 2 195 self.colorCont.height = self.height - 2