gfxpreviewer.py (8956B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\eveclientqatools\gfxpreviewer.py 2 from __future__ import print_function 3 import evetypes 4 import trinity 5 import carbonui.const as uiconst 6 import evespacescene 7 from carbonui.control.singlelineedits.singleLineEditText import SingleLineEditText 8 from carbonui.primitives.container import Container 9 from carbonui.control.button import Button 10 from carbonui.control.radioButton import RadioButton 11 from carbonui.control.window import Window 12 from fsdBuiltData.common.graphicIDs import GetGraphicFile 13 14 class ToolsWindow(object): 15 16 def __init__(self, name, caption): 17 self._name = name 18 self._windowID = 'ToolsWindow_ ' + name 19 self._components = [] 20 self._caption = caption 21 self._minWidth = 340 22 self._onCloseHandler = None 23 24 def SetCaption(self, caption): 25 self._caption = caption 26 27 def AddComponent(self, component): 28 self._components.append(component) 29 30 def Show(self): 31 Window.CloseIfOpen(windowID=self._windowID) 32 wnd = Window.Open(windowID=self._windowID) 33 wnd.SetMinSize([self._minWidth, 100]) 34 wnd.SetCaption(self._caption) 35 wnd._OnClose = self._OnClose 36 main = wnd.GetMainArea() 37 for i in range(len(self._components)): 38 height = self._components[i].GetHeight() 39 cont = Container(parent=main, align=uiconst.TOTOP, height=height, padTop=0) 40 compName = self._windowID + '_comp' + str(i) 41 self._components[i].Show(cont, compName, self._windowID) 42 43 def SetOnCloseHandler(self, handler): 44 self._onCloseHandler = handler 45 46 def _OnClose(self): 47 if self._onCloseHandler is not None: 48 self._onCloseHandler() 49 50 51 class ReportComponent(object): 52 53 def __init__(self): 54 self._height = 20 55 self._alignment = uiconst.TOLEFT 56 57 def SetHeight(self, height): 58 self._height = height 59 60 def GetHeight(self): 61 return self._height 62 63 def Show(self, parent, name, windowID): 64 pass 65 66 67 class RadioButtonRibbon(ReportComponent): 68 69 def __init__(self, groupID = 'radioGroup', itemWidth = 200): 70 ReportComponent.__init__(self) 71 self.buttons = [] 72 self.eventFunction = None 73 self.SetHeight(20) 74 self._itemWidth = itemWidth 75 self._groupID = groupID 76 77 def AddButton(self, text, id): 78 self.buttons.append((text, id)) 79 80 def Show(self, parent, name, windowID): 81 first = True 82 for text, retval in self.buttons: 83 RadioButton(parent=parent, text=text, groupname=self._groupID, align=self._alignment, checked=first, callback=self._radioButtonsChanged, retval=retval, width=self._itemWidth) 84 first = False 85 86 def SetHandler(self, function): 87 self.eventFunction = function 88 89 def _radioButtonsChanged(self, button): 90 id = button.GetGroupValue() 91 if self.eventFunction is not None: 92 self.eventFunction(id) 93 94 95 class TextEditComp(ReportComponent): 96 97 def __init__(self): 98 ReportComponent.__init__(self) 99 self._handler = None 100 self._textBox = None 101 self._text = '' 102 103 def SetHandler(self, handler): 104 self._handler = handler 105 106 def SetText(self, text): 107 self._text = text 108 if self._textBox is not None: 109 self._textBox.SetValue(unicode(text)) 110 111 def _textChanged(self, text): 112 self._text = text 113 if self._handler is not None: 114 self._handler(text) 115 116 def Show(self, parent, name, windowID): 117 self._textBox = SingleLineEditText(parent=parent, align=self._alignment, OnChange=self._textChanged, setvalue=self._text, width=300) 118 119 120 class ButtonRibbon(ReportComponent): 121 122 def __init__(self): 123 ReportComponent.__init__(self) 124 self.buttons = [] 125 self.buttonHandlers = {} 126 self.SetHeight(20) 127 128 def AddButton(self, text, handler): 129 self.buttons.append((text, handler)) 130 self.buttonHandlers[text] = handler 131 132 def _buttonEvent(self, *args): 133 button, = args 134 eventFunction = self.buttonHandlers[button.name] 135 if eventFunction is not None: 136 eventFunction() 137 138 def _createButton(self, container, text): 139 Button(parent=container, align=self._alignment, label=text, name=text, func=self._buttonEvent) 140 141 def Show(self, parent, name, windowID): 142 for text, eventFun in self.buttons: 143 self._createButton(parent, text) 144 145 146 class RowContainer(ReportComponent): 147 148 def __init__(self): 149 ReportComponent.__init__(self) 150 self.items = [] 151 152 def AddComponent(self, component): 153 self.items.append(component) 154 155 def Show(self, parent, name, windowID): 156 for item in self.items: 157 item.Show(parent, name, windowID) 158 159 160 class AssetPreviewer(object): 161 sources = ['graphicID', 'resPath', 'typeID'] 162 supportedTypes = evespacescene.EVESPACE_TRINITY_CLASSES 163 164 def __init__(self, sceneManager): 165 self._sceneManager = sceneManager 166 self.sourceType = 'graphicID' 167 self.graphicID = -1 168 self.typeID = -1 169 self.resPath = '' 170 self.resource = None 171 self._displayObjects = True 172 self._messageFunc = None 173 174 def Clear(self): 175 self.graphicID = -1 176 self.typeID = -1 177 self.resPath = '' 178 if self.resource is not None: 179 scene = self._sceneManager.GetRegisteredScene('default') 180 scene.objects.fremove(self.resource) 181 self.resource = None 182 183 def _getResourceFromTypeID(self, typeID): 184 try: 185 graphicID = evetypes.GetGraphicID(typeID) 186 except evetypes.TypeNotFoundException: 187 graphicID = None 188 189 if graphicID is None: 190 self._showMessage('Could not get graphicID from typeID ' + str(typeID)) 191 return 192 return self._getResourceFromGraphicID(graphicID) 193 194 def _getResourceFromGraphicID(self, graphicID): 195 resPath = GetGraphicFile(graphicID) 196 if resPath is None: 197 self._showMessage('Could not get resPath from graphicID ' + str(graphicID)) 198 return 199 return self._getResourceFromResPath(resPath) 200 201 def _getResourceFromResPath(self, path): 202 res = trinity.Load(path) 203 if getattr(res, '__bluetype__', None) not in AssetPreviewer.supportedTypes: 204 self._showMessage('resPath ' + path + ' does not contain a supported resource.') 205 return 206 return res 207 208 def Cleanup(self): 209 self.Clear() 210 if not self._displayObjects: 211 self._toggleHideSceneObjects() 212 213 def SetSourceType(self, type): 214 self.sourceType = type 215 216 def PreviewResource(self, source): 217 self.Clear() 218 if self.sourceType == 'typeID': 219 self.resource = self._getResourceFromTypeID(long(source)) 220 elif self.sourceType == 'graphicID': 221 self.resource = self._getResourceFromGraphicID(long(source)) 222 else: 223 self.resource = self._getResourceFromResPath(source) 224 if self.resource is None: 225 return 226 scene = self._sceneManager.GetRegisteredScene('default') 227 scene.objects.append(self.resource) 228 self._showMessage(self.sourceType + ' ' + source + ' loaded successfully.') 229 230 def _showMessage(self, text): 231 if self._messageFunc is None: 232 print(text) 233 else: 234 self._messageFunc(text) 235 236 def _toggleHideSceneObjects(self): 237 self._displayObjects = not self._displayObjects 238 scene = self._sceneManager.GetRegisteredScene('default') 239 for obj in scene.objects: 240 if obj is not self.resource and hasattr(obj, 'display'): 241 obj.display = self._displayObjects 242 243 def ShowUI(self): 244 window = ToolsWindow('AssetPreview', 'Graphic Asset Preview') 245 window.SetOnCloseHandler(self.Cleanup) 246 source = [''] 247 248 def updateSource(text): 249 source[0] = text 250 251 def _previewSource(): 252 self.PreviewResource(source[0]) 253 254 buttons = ButtonRibbon() 255 buttons.AddButton('Preview', _previewSource) 256 buttons.AddButton('Toggle Scene Display', self._toggleHideSceneObjects) 257 buttons.AddButton('Clear', self.Clear) 258 window.AddComponent(buttons) 259 radioGroup = RadioButtonRibbon() 260 radioGroup.AddButton('graphicID', 'graphicID') 261 radioGroup.AddButton('resPath', 'resPath') 262 radioGroup.AddButton('typeID', 'typeID') 263 radioGroup.SetHandler(self.SetSourceType) 264 window.AddComponent(radioGroup) 265 infoText = TextEditComp() 266 infoText.SetText('id or path to load') 267 infoText.SetHandler(updateSource) 268 window.AddComponent(infoText) 269 textOut = TextEditComp() 270 textOut.SetText('(info)') 271 self._messageFunc = textOut.SetText 272 window.AddComponent(textOut) 273 window.Show()