formWindow.py (3491B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\control\forms\formWindow.py 2 from carbonui import uiconst, AxisAlignment 3 from carbonui.button.group import ButtonGroup 4 from carbonui.control.forms import formFields 5 from carbonui.control.scrollContainer import ScrollContainer 6 from carbonui.control.window import Window 7 from carbonui.primitives.containerAutoSize import ContainerAutoSize 8 from carbonui.uicore import uicore 9 from player_messaging.client.ui_message import message_player, prompt_player_fsd_dialog 10 11 class FormWindow(Window): 12 default_windowID = 'FormWindow' 13 default_width = 400 14 default_isMinimizable = False 15 default_isStackable = False 16 default_isCollapseable = False 17 __notifyevents__ = ['OnEndChangeDevice', 'OnUIScalingChange'] 18 19 def ApplyAttributes(self, attributes): 20 super(FormWindow, self).ApplyAttributes(attributes) 21 self.form = attributes.form 22 self.SetCaption(self.form.name) 23 if self.form.icon: 24 self.icon = self.form.icon 25 self.scroll = ScrollContainer(parent=self.content, align=uiconst.TOALL) 26 self.formCont = ContainerAutoSize(name='formCont', parent=self.scroll, align=uiconst.TOTOP, callback=self.OnFormContHeightChanged) 27 self.ConstructLayout() 28 self.ConnectSignals() 29 30 def ConstructLayout(self): 31 self.ConstructFields() 32 self.ConstructButtons() 33 34 def ConstructFields(self): 35 formFields.ConstructFields(self.formCont, self.form) 36 37 def ConstructButtons(self): 38 self.button_group = ButtonGroup(parent=self.formCont, align=uiconst.TOTOP, padTop=16, button_alignment=AxisAlignment.END) 39 for submit_action in self.form.actions: 40 self.button_group.AddButton(submit_action.label, lambda button, s = submit_action: self._execute_submit_action(s, button), hint=submit_action.hint) 41 42 def ConnectSignals(self): 43 self.form.on_submitted.connect(self.OnSubmitActionExecuted) 44 self.form.on_submit_failed.connect(self.OnSubmitActionFailed) 45 self.form.on_canceled.connect(self.CloseByUser) 46 47 def _execute_submit_action(self, submit_action, button): 48 button.Disable() 49 button.busy = True 50 try: 51 submit_action.execute(self.form) 52 finally: 53 button.busy = False 54 button.Enable() 55 56 def OnSubmitActionFailed(self, action): 57 message_player(self.form.get_submit_failed_reasons_text()) 58 59 def OnSubmitActionExecuted(self, action): 60 self.Close() 61 62 def CloseByUser(self, *args): 63 if self.form.cancel_dialog: 64 if prompt_player_fsd_dialog(self.form.cancel_dialog, buttons=uiconst.YESNO) != uiconst.ID_YES: 65 return 66 super(FormWindow, self).CloseByUser(*args) 67 68 def OnFormContHeightChanged(self, *args): 69 self.UpdateFixedHeight() 70 71 def UpdateFixedHeight(self): 72 max_height = uicore.desktop.height * 0.9 73 _, height = self.GetWindowSizeForContentSize(height=self.formCont.height) 74 self.SetFixedHeight(min(max_height, height)) 75 76 def Confirm(self, *args): 77 button = self.button_group.buttons[0] 78 self._execute_submit_action(button, self.form.actions[0]) 79 80 def OnEndChangeDevice(self, *args, **kwargs): 81 self.UpdateFixedHeight() 82 self.scroll.ScrollToVertical(0.0) 83 84 def OnUIScalingChange(self, *args, **kwargs): 85 self.UpdateFixedHeight() 86 self.scroll.ScrollToVertical(0.0)