def __addInputField(self, inputDef, handledHandles, mainInput=False): if not self.__checkInputConditions(inputDef): return handledHandles.add(inputDef.handle) fieldSizer = wx.BoxSizer(wx.HORIZONTAL) tooltipText = (inputDef.mainTooltip if mainInput else inputDef.secondaryTooltip) or '' if mainInput: fieldTextBox = FloatRangeBox( self, self._storedRanges.get((inputDef.handle, inputDef.unit), inputDef.defaultRange)) fieldTextBox.Bind(wx.EVT_TEXT, self.OnMainInputChanged) else: fieldTextBox = FloatBox( self, self._storedConsts.get((inputDef.handle, inputDef.unit), inputDef.defaultValue)) fieldTextBox.Bind(wx.EVT_TEXT, self.OnNonMainInputChanged) fieldTextBox.SetToolTip(wx.ToolTip(tooltipText)) fieldSizer.Add(fieldTextBox, 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 5) fieldIcon = None if inputDef.iconID is not None: icon = BitmapLoader.getBitmap(inputDef.iconID, 'icons') if icon is not None: fieldIcon = wx.StaticBitmap(self) fieldIcon.SetBitmap(icon) fieldIcon.SetToolTip(wx.ToolTip(tooltipText)) fieldSizer.Add(fieldIcon, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 3) fieldLabel = wx.StaticText(self, wx.ID_ANY, self.formatLabel(inputDef)) fieldLabel.SetToolTip(wx.ToolTip(tooltipText)) fieldSizer.Add(fieldLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 0) self.inputsSizer.Add(fieldSizer, 0, wx.EXPAND | wx.BOTTOM, 5) # Store info about added input box inputBox = InputBox(handle=inputDef.handle, unit=inputDef.unit, textBox=fieldTextBox, icon=fieldIcon, label=fieldLabel) if mainInput: self._mainInputBox = inputBox else: self._miscInputBoxes.append(inputBox)
def __init__(self, parent): super().__init__( parent, id=wx.ID_ANY, title="Target Profile Editor", style=wx.RESIZE_BORDER, # Dropdown list widget is scaled to its longest content line on GTK, adapt to that size=wx.Size(500, 240) if "wxGTK" in wx.PlatformInfo else wx.Size(350, 240)) self.mainFrame = gui.mainFrame.MainFrame.getInstance() self.block = False self.SetSizeHints(wx.DefaultSize, wx.DefaultSize) mainSizer = wx.BoxSizer(wx.VERTICAL) self.entityEditor = TargetProfileEntityEditor(parent=self) mainSizer.Add(self.entityEditor, 0, wx.ALL | wx.EXPAND, 2) self.sl = wx.StaticLine(self) mainSizer.Add(self.sl, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 5) contentSizer = wx.BoxSizer(wx.VERTICAL) resistEditSizer = wx.FlexGridSizer(2, 6, 0, 2) resistEditSizer.AddGrowableCol(0) resistEditSizer.AddGrowableCol(5) resistEditSizer.SetFlexibleDirection(wx.BOTH) resistEditSizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) defSize = wx.Size(50, -1) for i, type_ in enumerate(self.DAMAGE_TYPES): if i % 2: style = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT border = 25 else: style = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT border = 5 ttText = self.DAMAGE_TYPES[type_] bmp = wx.StaticBitmap(self, wx.ID_ANY, BitmapLoader.getBitmap("%s_big" % type_, "gui")) bmp.SetToolTip(wx.ToolTip(ttText)) resistEditSizer.Add(bmp, 0, style, border) # set text edit editBox = FloatBox(parent=self, id=wx.ID_ANY, value=None, pos=wx.DefaultPosition, size=defSize, validator=ResistValidator()) editBox.SetToolTip(wx.ToolTip(ttText)) self.Bind(event=wx.EVT_TEXT, handler=self.OnFieldChanged, source=editBox) setattr(self, '{}Edit'.format(type_), editBox) resistEditSizer.Add(editBox, 0, wx.BOTTOM | wx.TOP | wx.ALIGN_CENTER_VERTICAL, 5) unit = wx.StaticText(self, wx.ID_ANY, "%", wx.DefaultPosition, wx.DefaultSize, 0) unit.SetToolTip(wx.ToolTip(ttText)) resistEditSizer.Add(unit, 0, wx.BOTTOM | wx.TOP | wx.ALIGN_CENTER_VERTICAL, 5) contentSizer.Add(resistEditSizer, 0, wx.EXPAND | wx.ALL, 5) miscAttrSizer = wx.BoxSizer(wx.HORIZONTAL) miscAttrSizer.AddStretchSpacer() for attr in self.ATTRIBUTES: leftPad = 25 if attr != list(self.ATTRIBUTES)[0] else 0 ttText, unitText = self.ATTRIBUTES[attr] bmp = wx.StaticBitmap(self, wx.ID_ANY, BitmapLoader.getBitmap("%s_big" % attr, "gui")) bmp.SetToolTip(wx.ToolTip(ttText)) miscAttrSizer.Add(bmp, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT, leftPad) # set text edit editBox = FloatBox(parent=self, id=wx.ID_ANY, value=None, pos=wx.DefaultPosition, size=defSize) editBox.SetToolTip(wx.ToolTip(ttText)) self.Bind(event=wx.EVT_TEXT, handler=self.OnFieldChanged, source=editBox) setattr(self, '{}Edit'.format(attr), editBox) miscAttrSizer.Add(editBox, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) unit = wx.StaticText(self, wx.ID_ANY, unitText, wx.DefaultPosition, wx.DefaultSize, 0) unit.SetToolTip(wx.ToolTip(ttText)) miscAttrSizer.Add(unit, 0, wx.BOTTOM | wx.TOP | wx.ALIGN_CENTER_VERTICAL, 5) miscAttrSizer.AddStretchSpacer() contentSizer.Add(miscAttrSizer, 1, wx.EXPAND | wx.ALL, 5) self.slfooter = wx.StaticLine(self) contentSizer.Add(self.slfooter, 0, wx.EXPAND | wx.TOP, 5) footerSizer = wx.BoxSizer(wx.HORIZONTAL) perSizer = wx.BoxSizer(wx.VERTICAL) self.stNotice = wx.StaticText(self, wx.ID_ANY, "") self.stNotice.Wrap(-1) perSizer.Add(self.stNotice, 0, wx.BOTTOM | wx.TOP | wx.LEFT, 5) footerSizer.Add(perSizer, 1, wx.ALIGN_CENTER_VERTICAL, 5) self.totSizer = wx.BoxSizer(wx.VERTICAL) contentSizer.Add(footerSizer, 0, wx.EXPAND, 5) mainSizer.Add(contentSizer, 1, wx.EXPAND, 0) self.SetSizer(mainSizer) importExport = (("Import", wx.ART_FILE_OPEN, "from"), ("Export", wx.ART_FILE_SAVE_AS, "to")) for name, art, direction in importExport: bitmap = wx.ArtProvider.GetBitmap(art, wx.ART_BUTTON) btn = wx.BitmapButton(self, wx.ID_ANY, bitmap) btn.SetMinSize(btn.GetSize()) btn.SetMaxSize(btn.GetSize()) btn.Layout() setattr(self, name, btn) btn.Enable(True) btn.SetToolTip("%s profiles %s clipboard" % (name, direction)) footerSizer.Add(btn, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_RIGHT) btn.Bind(wx.EVT_BUTTON, getattr(self, "{}Patterns".format(name.lower()))) if not self.entityEditor.checkEntitiesExist(): self.Close() return self.Layout() bsize = self.GetBestSize() self.SetSize((-1, bsize.height)) self.SetMinSize(self.GetSize()) self.CenterOnParent() self.Bind(wx.EVT_CHOICE, self.patternChanged) self.Bind(wx.EVT_CHAR_HOOK, self.kbEvent) self.inputTimer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnInputTimer, self.inputTimer) self.patternChanged()
def __init__(self, parent): super().__init__( parent, id=wx.ID_ANY, title="Damage Pattern Editor", resizeable=True, # Dropdown list widget is scaled to its longest content line on GTK, adapt to that size=wx.Size(500, 240) if "wxGTK" in wx.PlatformInfo else wx.Size(400, 240)) self.block = False self.SetSizeHints(wx.DefaultSize, wx.DefaultSize) mainSizer = wx.BoxSizer(wx.VERTICAL) self.entityEditor = DmgPatternEntityEditor(self) mainSizer.Add(self.entityEditor, 0, wx.ALL | wx.EXPAND, 2) self.sl = wx.StaticLine(self) mainSizer.Add(self.sl, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 5) contentSizer = wx.BoxSizer(wx.VERTICAL) self.embitmap = BitmapLoader.getBitmap("em_big", "gui") self.thermbitmap = BitmapLoader.getBitmap("thermal_big", "gui") self.kinbitmap = BitmapLoader.getBitmap("kinetic_big", "gui") self.expbitmap = BitmapLoader.getBitmap("explosive_big", "gui") dmgeditSizer = wx.FlexGridSizer(2, 6, 0, 2) dmgeditSizer.AddGrowableCol(0) dmgeditSizer.AddGrowableCol(5) dmgeditSizer.SetFlexibleDirection(wx.BOTH) dmgeditSizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) width = -1 defSize = wx.Size(width, -1) for i, type_ in enumerate(self.DAMAGE_TYPES): bmp = wx.StaticBitmap(self, wx.ID_ANY, BitmapLoader.getBitmap("%s_big" % type_, "gui")) if i % 2: style = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT border = 20 else: style = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT border = 5 # set text edit editBox = FloatBox(parent=self, id=wx.ID_ANY, value=0, pos=wx.DefaultPosition, size=defSize) percLabel = wx.StaticText(self, wx.ID_ANY, "0%") setattr(self, "%sEdit" % type_, editBox) setattr(self, "%sPerc" % type_, percLabel) dmgeditSizer.Add(bmp, 0, style, border) dmgeditSizer.Add(editBox, 0, wx.BOTTOM | wx.TOP | wx.ALIGN_CENTER_VERTICAL, 5) dmgeditSizer.Add(percLabel, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5) editBox.Bind(wx.EVT_TEXT, self.OnFieldChanged) contentSizer.Add(dmgeditSizer, 1, wx.EXPAND | wx.ALL, 5) self.slfooter = wx.StaticLine(self) contentSizer.Add(self.slfooter, 0, wx.EXPAND | wx.TOP, 5) footerSizer = wx.BoxSizer(wx.HORIZONTAL) perSizer = wx.BoxSizer(wx.VERTICAL) self.stNotice = wx.StaticText(self, wx.ID_ANY, "") self.stNotice.Wrap(-1) perSizer.Add(self.stNotice, 0, wx.BOTTOM | wx.TOP | wx.LEFT, 5) footerSizer.Add(perSizer, 1, wx.ALIGN_CENTER_VERTICAL, 5) self.totSizer = wx.BoxSizer(wx.VERTICAL) contentSizer.Add(footerSizer, 0, wx.EXPAND, 5) mainSizer.Add(contentSizer, 1, wx.EXPAND, 0) self.SetSizer(mainSizer) importExport = (("Import", wx.ART_FILE_OPEN, "from"), ("Export", wx.ART_FILE_SAVE_AS, "to")) for name, art, direction in importExport: bitmap = wx.ArtProvider.GetBitmap(art, wx.ART_BUTTON) btn = wx.BitmapButton(self, wx.ID_ANY, bitmap) btn.SetMinSize(btn.GetSize()) btn.SetMaxSize(btn.GetSize()) btn.Layout() setattr(self, name, btn) btn.Enable(True) btn.SetToolTip("%s patterns %s clipboard" % (name, direction)) footerSizer.Add(btn, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_RIGHT) btn.Bind(wx.EVT_BUTTON, getattr(self, "{}Patterns".format(name.lower()))) self.Layout() bsize = self.GetBestSize() self.SetSize((-1, bsize.height)) self.SetMinSize(self.GetSize()) self.CenterOnParent() self.Bind(wx.EVT_CHOICE, self.patternChanged) self.Bind(wx.EVT_CHAR_HOOK, self.kbEvent) self.inputTimer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnInputTimer, self.inputTimer) self.patternChanged()