templateSavingUtil.py (4544B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\planet\templateSavingUtil.py 2 import blue 3 import codecs 4 import localization 5 import logging 6 import os 7 from bannedwords.client import bannedwords 8 from carbon.common.script.util.commonutils import StripTags 9 from carbon.common.script.util.format import FmtDate 10 from carbonui import Align, uiconst 11 from carbonui.text.styles import TextBody 12 from carbonui.button.group import ButtonGroup, ButtonSizeMode 13 from carbonui.control.checkbox import Checkbox 14 from carbonui.control.singlelineedits.singleLineEditText import SingleLineEditText 15 from carbonui.control.window import Window 16 from carbonui.primitives.containerAutoSize import ContainerAutoSize 17 from eve.client.script.ui.shared.planet.colonyTemplate import ColonyTemplate 18 from eve.client.script.ui.shared.planet.planetUtil import IsSerenity 19 from localization import GetByLabel 20 from player_messaging.client.ui_message import message_player, prompt_player_fsd_dialog 21 22 class ConfirmExportWnd(Window): 23 default_minSize = (480, 240) 24 default_fixedWidth = 480 25 default_fixedHeight = 200 26 default_captionLabelPath = 'UI/PI/SaveNewTemplate' 27 default_windowID = 'comfirmPIexport' 28 29 def ApplyAttributes(self, attributes): 30 super(ConfirmExportWnd, self).ApplyAttributes(attributes) 31 defaultNote = attributes.defaultNote 32 captionPath = attributes.captionPath 33 okPath = attributes.okPath 34 self.MakeUnResizeable() 35 self.result = None 36 self.btnGroup = ButtonGroup(parent=self.content, align=Align.TOBOTTOM, button_size_mode=ButtonSizeMode.STRETCH) 37 self.innerCont = ContainerAutoSize(parent=self.content, align=uiconst.TOTOP, callback=self._UpdateWindowHeight) 38 self.SetCaption(GetByLabel(captionPath)) 39 self.btnGroup.AddButton(GetByLabel(okPath), self.ClickOK) 40 self.btnGroup.AddButton(GetByLabel('UI/Common/Buttons/Cancel'), self.Close) 41 TextBody(parent=self.innerCont, align=Align.TOTOP, text=GetByLabel('UI/PI/EnterTemplateName'), top=8) 42 self.editField = SingleLineEditText(parent=self.innerCont, maxLength=200, setvalue=defaultNote, align=Align.TOTOP, top=2, OnReturn=self.ClickOK) 43 if IsSerenity(): 44 self.cb = Checkbox(parent=self.innerCont, align=uiconst.TOTOP, text=localization.GetByLabel('UI/PI/DoNotIncludeCmdCtr'), top=2) 45 else: 46 self.cb = None 47 self._UpdateWindowHeight() 48 49 def _UpdateWindowHeight(self): 50 btnTopPadding = 12 51 height = self.innerCont.height + self.btnGroup.height + btnTopPadding 52 _, height = self.GetWindowSizeForContentSize(height=height) 53 self.SetFixedHeight(height) 54 55 def ClickOK(self, *args): 56 note = StripTags(self.editField.GetValue()) 57 if self.cb: 58 includeCmdCtr = not self.cb.GetValue() 59 else: 60 includeCmdCtr = False 61 self.result = {'note': note, 62 'includeCmdCtr': includeCmdCtr} 63 self.SetModalResult(1) 64 65 66 def GetDefaultStoragePath(): 67 return os.path.join(blue.sysinfo.GetUserDocumentsDirectory(), 'EVE', 'PlanetaryInteractionTemplates') 68 69 70 def SaveToLocalFile(newJSON, filename = None, encoding = None): 71 try: 72 ct = ColonyTemplate(newJSON, '') 73 bannedwords.check_words_allowed(ct.description) 74 except UserError as e: 75 raise 76 except Exception as e: 77 logging.exception('PI Templates: Error while saving file') 78 prompt_player_fsd_dialog('CustomError', {'error': GetByLabel('UI/PI/ErrorSavingToFile')}) 79 return False 80 81 try: 82 defaultStoragePath = GetDefaultStoragePath() 83 if filename is None: 84 dateStr = str(FmtDate(blue.os.GetWallclockTime(), 'll').replace(':', '')) 85 filename = u'{0}.json'.format(os.path.join(defaultStoragePath, dateStr)) 86 if not os.path.exists(defaultStoragePath): 87 os.makedirs(defaultStoragePath) 88 if encoding is None: 89 outfile = codecs.open(filename, 'w') 90 else: 91 outfile = codecs.open(filename, 'w', encoding=encoding) 92 outfile.write(newJSON) 93 message_player(GetByLabel('UI/PI/WrittenToFile', path=filename)) 94 except Exception as e: 95 logging.exception('PI Templates: Error while saving file') 96 prompt_player_fsd_dialog('CustomError', {'error': GetByLabel('UI/PI/ErrorSavingToFile')}) 97 return False 98 99 sm.ScatterEvent('OnPITemplatesUpdated') 100 message_player(GetByLabel('UI/PI/SavedToLocalSuccess')) 101 return True