Files
pyfa/gui/patternEditor.py
2010-10-10 17:10:02 +02:00

205 lines
7.6 KiB
Python

#===============================================================================
# Copyright (C) 2010 Diego Duclos
#
# This file is part of pyfa.
#
# pyfa is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyfa is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pyfa. If not, see <http://www.gnu.org/licenses/>.
#===============================================================================
import wx
import bitmapLoader
from wx.lib.intctrl import IntCtrl
###########################################################################
## Class DmgPatternEditorDlg
###########################################################################
class DmgPatternEditorDlg (wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__ (self, parent, id = wx.ID_ANY, title = u"Damage Pattern Editor", size = wx.Size( 350,240 ))
self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)
mainSizer = wx.BoxSizer(wx.VERTICAL)
headerSizer = wx.BoxSizer(wx.HORIZONTAL)
ccDmgPatternChoices = [ u"uniform", u"sansha", u"gurista", u"blood raiders", u"drones", u"angels", "cnc" ]
self.ccDmgPattern = wx.Choice(self)
self.ccDmgPattern.SetSelection(0)
size = None
headerSizer.Add(self.ccDmgPattern, 1, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT|wx.LEFT, 3)
for name, art in (("new", wx.ART_NEW), ("rename", bitmapLoader.getBitmap("rename", "icons")), ("copy", wx.ART_COPY), ("delete", wx.ART_DELETE)):
bitmap = wx.ArtProvider.GetBitmap(art, wx.ART_BUTTON) if name != "rename" else art
btn = wx.BitmapButton(self, wx.ID_ANY, bitmap)
if size is None:
size = btn.GetSize()
btn.SetMinSize(size)
btn.SetMaxSize(size)
btn.Layout()
setattr(self, name, btn)
btn.Enable(True)
btn.SetToolTipString("%s fit" % name.capitalize())
headerSizer.Add(btn, 0, wx.ALIGN_CENTER_VERTICAL)
mainSizer.Add(headerSizer, 0, wx.EXPAND | wx.ALL, 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", "icons")
self.thermbitmap = bitmapLoader.getBitmap("thermal_big", "icons")
self.kinbitmap = bitmapLoader.getBitmap("kinetic_big", "icons")
self.expbitmap = bitmapLoader.getBitmap("explosive_big", "icons")
dmgeditSizer = wx.FlexGridSizer(2, 4, 0, 2)
dmgeditSizer.AddGrowableCol(1)
dmgeditSizer.AddGrowableCol(2)
dmgeditSizer.SetFlexibleDirection(wx.BOTH)
dmgeditSizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)
width = -1
defSize = wx.Size(width,-1)
self.editEM = IntCtrl(self, wx.ID_ANY, 0, wx.DefaultPosition, defSize, wx.TE_RIGHT)
dmgeditSizer.Add(self.editEM, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
self.bmpEM = wx.StaticBitmap(self, wx.ID_ANY, self.embitmap)
dmgeditSizer.Add(self.bmpEM, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5)
self.bmpTHERM = wx.StaticBitmap(self, wx.ID_ANY, self.thermbitmap)
dmgeditSizer.Add(self.bmpTHERM, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, 5)
self.editTHERM = IntCtrl(self, wx.ID_ANY, 0, wx.DefaultPosition, defSize, 0)
dmgeditSizer.Add(self.editTHERM, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
self.editKIN = IntCtrl(self, wx.ID_ANY, 0, wx.DefaultPosition, defSize, wx.TE_RIGHT)
dmgeditSizer.Add(self.editKIN, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
self.bmpKIN = wx.StaticBitmap(self, wx.ID_ANY, self.kinbitmap)
dmgeditSizer.Add(self.bmpKIN, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5)
self.bmpEXP = wx.StaticBitmap(self, wx.ID_ANY, self.expbitmap)
dmgeditSizer.Add(self.bmpEXP, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, 5)
self.editEXP = IntCtrl(self, wx.ID_ANY, 0, wx.DefaultPosition, defSize, 0)
dmgeditSizer.Add(self.editEXP, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
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.stPercentages = wx.StaticText(self, wx.ID_ANY, u"")
self.stPercentages.Wrap(-1)
perSizer.Add(self.stPercentages, 0, wx.BOTTOM | wx.LEFT, 5)
footerSizer.Add(perSizer, 0, 0, 5)
self.totSizer = wx.BoxSizer(wx.VERTICAL)
self.stTotal = wx.StaticText(self, wx.ID_ANY, u"")
self.stTotal.Wrap(-1)
self.totSizer.Add(self.stTotal, 0, wx.ALIGN_RIGHT | wx.BOTTOM | wx.RIGHT, 5)
footerSizer.Add(self.totSizer, 1, 0, 5)
contentSizer.Add(footerSizer, 0, wx.EXPAND, 5)
mainSizer.Add(contentSizer, 1, wx.EXPAND, 0)
self.SetSizer(mainSizer)
self.Layout()
self.ValuesUpdated(None)
bsize = self.GetBestSize()
self.SetSize((-1,bsize.height))
#
# edit controls are editEM editTHERM editKIN editEXP
# editctrl values are always stored in self._EM .. _THERM .. _KIN .. _EXP
#
self.editEM.SetLimited(True)
self.editTHERM.SetLimited(True)
self.editKIN.SetLimited(True)
self.editEXP.SetLimited(True)
self.editEM.SetMin(0)
self.editTHERM.SetMin(0)
self.editKIN.SetMin(0)
self.editEXP.SetMin(0)
self.editEM.SetMax(99999)
self.editTHERM.SetMax(99999)
self.editKIN.SetMax(99999)
self.editEXP.SetMax(99999)
self.new.Bind(wx.EVT_BUTTON, self.newPattern)
self.rename.Bind(wx.EVT_BUTTON, self.renamePattern)
self.delete.Bind(wx.EVT_BUTTON, self.deletePattern)
self.copy.Bind(wx.EVT_BUTTON, self.copyPattern)
self.editEM.Bind(wx.EVT_TEXT, self.ValuesUpdated)
self.editTHERM.Bind(wx.EVT_TEXT, self.ValuesUpdated)
self.editKIN.Bind(wx.EVT_TEXT, self.ValuesUpdated)
self.editEXP.Bind(wx.EVT_TEXT, self.ValuesUpdated)
def ValuesUpdated(self, event):
self._EM = self.editEM.GetValue()
self._THERM = self.editTHERM.GetValue()
self._KIN = self.editKIN.GetValue()
self._EXP = self.editEXP.GetValue()
total = self._EM + self._THERM + self._KIN + self._EXP
format = "EM: % 3d%% THERM: % 3d%% KIN: % 3d%% EXP: % 3d%%"
if total > 0:
ltext = format %(self._EM*100/total, self._THERM*100/total, self._KIN*100/total, self._EXP*100/total)
else:
ltext = format %(0, 0, 0, 0)
ttext = "Total: % 6d" % (total)
self.stPercentages.SetLabel(ltext)
self.stTotal.SetLabel(ttext)
self.totSizer.Layout()
if event is not None:
event.Skip()
def newPattern(self,event):
event.Skip()
def renamePattern(self,event):
event.Skip()
def copyPattern(self,event):
event.Skip()
def deletePattern(self,event):
event.Skip()
def __del__( self ):
pass