singleLineEditHistory.py (4582B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\control\singlelineedits\singleLineEditHistory.py 2 from carbonui.control.buttonIcon import ButtonIcon 3 from carbonui.primitives.container import Container 4 from carbonui import uiconst 5 from carbonui.primitives.fill import Fill 6 from carbonui.primitives.frame import Frame 7 from carbonui.primitives.line import Line 8 from eve.client.script.ui.control.eveLabel import Label 9 from localization.formatters.timeIntervalFormatters import GetByLabel 10 11 class SingleLineEditHistory(Container): 12 default_name = 'historyMenuParent' 13 default_align = uiconst.TOPLEFT 14 15 def ApplyAttributes(self, attributes): 16 Container.ApplyAttributes(self, attributes) 17 self.dynamicHistoryWidth = attributes.dynamicHistoryWidth 18 self.historyMenuSub = self.sr.entries = Container(name='historyMenuSub', parent=self) 19 self.mouseDownFunc = attributes.mouseDownFunc 20 self.mouseUpFunc = attributes.mouseUpFunc 21 self.currentText = attributes.currentText 22 self.deleteHistoryEntryFunc = attributes.deleteHistoryEntryFunc 23 Frame(parent=self, frameConst=uiconst.FRAME_BORDER1_CORNER0, color=(1.0, 1.0, 1.0, 0.2)) 24 Frame(parent=self, frameConst=uiconst.FRAME_FILLED_CORNER0, color=(0.0, 0.0, 0.0, 0.75)) 25 26 def PopulateHistoryMenu(self, history): 27 for entry in history: 28 historyEntry = EditHistoryEntry(parent=self.historyMenuSub, displayText=entry.displayText, editText=entry.editText, info=entry.info, removeable=getattr(entry, 'removeable', False), mouseDownFunc=self.mouseDownFunc, mouseUpFunc=self.mouseUpFunc, historyEntry=entry.historyEntry, deleteHistoryEntryFunc=self.deleteHistoryEntryFunc) 29 historyEntry.sr.menu = self 30 self.height += historyEntry.height 31 if self.historyMenuSub: 32 self.width = max(self.width, historyEntry.textWidth) 33 34 def GetSelectedEntry(self): 35 for _entry in self.sr.entries.children: 36 _entry.sr.hilite.display = False 37 if _entry.selected: 38 return _entry 39 40 def GetTextEntered(self): 41 return self.currentText 42 43 44 class EditHistoryEntry(Container): 45 default_name = 'entryParent' 46 default_clipChildren = True 47 default_align = uiconst.TOTOP 48 default_state = uiconst.UI_NORMAL 49 default_height = 16 50 51 def ApplyAttributes(self, attributes): 52 Container.ApplyAttributes(self, attributes) 53 displayText = attributes.displayText 54 editText = attributes.editText 55 removeable = attributes.removeable 56 info = attributes.info 57 historyEntry = attributes.historyEntry 58 self.deleteHistoryEntryFunc = attributes.deleteHistoryEntryFunc 59 self.mouseDownFunc = attributes.mouseDownFunc 60 self.mouseUpFunc = attributes.mouseUpFunc 61 labelPadding = 0 62 if removeable and self.deleteHistoryEntryFunc: 63 ButtonIcon(name='deleteIcon', texturePath='res:/UI/Texture/Icons/73_16_210.png', pos=(5, 0, 16, 16), align=uiconst.CENTERRIGHT, parent=self, idx=0, func=self.DeleteFromHistory, hint=GetByLabel('UI/Common/Delete')) 64 labelPadding = 20 65 t = Label(text=displayText, parent=self, left=6, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED, padRight=labelPadding) 66 self.height = t.textheight + 4 67 self.textWidth = t.width + 12 68 self.sr.hilite = Fill(parent=self, color=(1.0, 1.0, 1.0, 0.25), pos=(1, 1, 1, 1), state=uiconst.UI_DISABLED) 69 self.sr.hilite.display = False 70 Line(parent=self, align=uiconst.TOBOTTOM) 71 self.selected = 0 72 self.string = editText 73 self.info = info 74 self.historyEntry = historyEntry 75 76 def DeleteFromHistory(self, *args): 77 self.deleteHistoryEntryFunc(self) 78 79 def OnMouseDown(self, mouseButton, *args): 80 self.mouseDownFunc(self, mouseButton) 81 82 def OnMouseUp(self, mouseButton, *args): 83 self.mouseUpFunc(self, mouseButton) 84 85 def OnMouseEnter(self, *args): 86 hm = self.sr.menu 87 if not hm or hm.destroyed: 88 return 89 for _entry in hm.sr.entries.children: 90 _entry.sr.hilite.display = False 91 _entry.selected = 0 92 93 self.sr.hilite.display = True 94 self.selected = 1 95 96 97 class HistoryData(object): 98 99 def __init__(self, displayText, editText, removeable = True): 100 self.displayText = displayText 101 self.editText = editText 102 self.removeable = removeable 103 104 def __repr__(self): 105 return '<HistoryData %s>' % self.__dict__