NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

encodedItemsWindow.py (5055B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\services\encodedItemsWindow.py
      2 import uthread2
      3 from carbonui.control.contextMenu.menuData import MenuData
      4 from carbonui.control.window import Window
      5 from carbonui.primitives.container import Container
      6 from carbonui.primitives.sprite import StreamingVideoSprite, Sprite
      7 from carbonui.uiconst import TOALL, CENTER
      8 import blue
      9 from dogma.const import attributeAspectRatioWidth, attributeAspectRatioHeight
     10 from localization import GetByLabel
     11 from player_messaging.client.ui_message import prompt_player_fsd_dialog
     12 VIDEO_TYPE = '.webm'
     13 IMAGE_TYPE = '.png'
     14 
     15 class EncodedItemsWindow(Window):
     16     __guid__ = 'form.EncryptedItemsResultWindow'
     17     default_windowID = 'encodedItemsWindow'
     18     default_width = 900
     19     default_height = 480
     20 
     21     def ApplyAttributes(self, attributes):
     22         self.apectRatio = 1.0
     23         super(EncodedItemsWindow, self).ApplyAttributes(attributes)
     24         self.downloadingFile = False
     25         self.typeID = attributes.typeID
     26         resourcePath = attributes.url
     27         self.resourceUrl = resourcePath
     28         if self.isVideo:
     29             self.spriteCont = Container(name='spriteCont', parent=self.content, align=TOALL)
     30             self.sprite = StreamingVideoSprite(parent=self.spriteCont, align=TOALL, videoPath=resourcePath, videoAutoPlay=True)
     31         else:
     32             clientDogmaStaticSvc = sm.GetService('clientDogmaStaticSvc')
     33             aspectRatioWidth = clientDogmaStaticSvc.GetTypeAttribute(self.typeID, attributeAspectRatioWidth, 1)
     34             aspectRatioHeight = clientDogmaStaticSvc.GetTypeAttribute(self.typeID, attributeAspectRatioHeight, 1)
     35             self.apectRatio = float(aspectRatioWidth) / aspectRatioHeight
     36             self.spriteCont = Container(name='spriteCont', parent=self.content, align=CENTER)
     37             texture, _, _ = sm.GetService('photo').GetTextureFromURL(resourcePath)
     38             self.sprite = Sprite(parent=self.spriteCont, align=TOALL)
     39             self.sprite.texture = texture
     40             w, h = self._GetNewWidthAndHeight(self.width, self.height)
     41             self.width = w
     42             self.height = h
     43         self.sprite.GetMenu = self.GetResourceMenu
     44         self.UpdateSpriteContSize()
     45 
     46     def GetResourceMenu(self):
     47         m = MenuData()
     48         if self.isVideo:
     49             labelPath = GetByLabel('UI/VideoPlayer/DownloadVideo')
     50         elif self.isImage:
     51             labelPath = GetByLabel('UI/VideoPlayer/DownloadImage')
     52         else:
     53             return m
     54         m.AddEntry(labelPath, func=lambda : self.DownloadFile())
     55         return m
     56 
     57     def DownloadFile(self):
     58         if self.downloadingFile:
     59             raise UserError('CustomNotify', {'notify': 'UI/VideoPlayer/AlreadyDownloadingFile'})
     60         self.downloadingFile = True
     61         uthread2.StartTasklet(self._DownloadFile)
     62 
     63     def _DownloadFile(self):
     64         failureMsgPath = 'UI/VideoPlayer/FailedToDownloadVideo'
     65         try:
     66             if self.isVideo:
     67                 fileName = blue.sysinfo.GetUserDocumentsDirectory() + '/EVE/capture/Screenshots/VideoFragment_%s%s' % (self.typeID, VIDEO_TYPE)
     68                 successMsgPath = 'UI/VideoPlayer/VideoDownloaded'
     69             elif self.isImage:
     70                 fileName = blue.sysinfo.GetUserDocumentsDirectory() + '/EVE/capture/Screenshots/ImageFragment_%s%s' % (self.typeID, IMAGE_TYPE)
     71                 successMsgPath = 'UI/VideoPlayer/ImageDownloaded'
     72             else:
     73                 raise RuntimeError('Video is not of the right format')
     74             stream = blue.BlueNetworkStream(unicode(self.resourceUrl).encode('utf-8'))
     75             data = stream.read()
     76             with open(fileName, 'wb') as outputPath:
     77                 outputPath.write(data)
     78                 prompt_player_fsd_dialog('CustomNotify', {'notify': GetByLabel(successMsgPath)})
     79         except Exception:
     80             prompt_player_fsd_dialog('CustomNotify', {'notify': GetByLabel(failureMsgPath)})
     81             raise
     82         finally:
     83             self.downloadingFile = False
     84 
     85     def OnResize_(self, *args):
     86         self.UpdateSpriteContSize()
     87 
     88     def UpdateSpriteContSize(self):
     89         if self.isImage:
     90             lPad, tPad, rPad, bPad = self.GetContentToWindowEdgePadding()
     91             availWidth = self.width - lPad - rPad
     92             availHeight = self.height - tPad - bPad
     93             newWidth, newHeight = self._GetNewWidthAndHeight(availWidth, availHeight)
     94             self.spriteCont.width = newWidth
     95             self.spriteCont.height = newHeight
     96 
     97     def _GetNewWidthAndHeight(self, availWidth, availHeight):
     98         if float(availWidth) / availHeight > self.apectRatio:
     99             newHeight = availHeight
    100             newWidth = self.apectRatio * newHeight
    101         else:
    102             newWidth = availWidth
    103             newHeight = newWidth / self.apectRatio
    104         return (newWidth, newHeight)
    105 
    106     @property
    107     def isVideo(self):
    108         return self.resourceUrl.endswith(VIDEO_TYPE)
    109 
    110     @property
    111     def isImage(self):
    112         return self.resourceUrl.endswith(IMAGE_TYPE)