""" This file is part of RuneOptimizer. RuneOptimizer 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. RuneOptimizer 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 RuneOptimizer. If not, see . """ class DialogNewTeam(wx.Dialog): """ Dialog for team creation. Allows for name and priority input. """ _name_text = None _priority_text = None def __init__(self, parent, id=wx.ID_ANY): """Initializes the dialog. Sets upt all the widgets. parent : wx.* Dialog parent. id : int, optional ID for the dialig (default wx.ID_ANY). """ # Parent constructor wx.Dialog.__init__( self, parent=parent, id=id, pos=(50, 50), size=(300, 180), title="Create new team", style=wx.DEFAULT_DIALOG_STYLE ) wx.StaticText( parent=self, id=wx.ID_ANY, label="Name:", pos=(30, 30), size=(60, 30) ) self._title_text = wx.TextCtrl( parent=self, id=wx.ID_ANY, pos=(90, 30), size=(180, 25), style=wx.TE_RICH|wx.TE_MULTILINE ) wx.StaticText( parent=self, id=wx.ID_ANY, label="Priority:", pos=(30, 63), size=(60, 30) ) self._priority_text = wx.TextCtrl( parent=self, id=wx.ID_ANY, value="0", pos=(90, 60), size=(30, 25), style=wx.TE_RICH|wx.TE_MULTILINE) wx.Button( parent=self, id=wx.ID_ANY, pos=(33, 100), size=(100, 40), style=wx.LC_REPORT, label="Accept" ).Bind(wx.EVT_BUTTON, self._accept) wx.Button( parent=self, id=wx.ID_CANCEL, pos=(166, 100), size=(100, 40), style=wx.LC_REPORT, label="Close" ) def _accept(self, event=None): error = False name = self._title_text.GetValue().strip() priority = self._priority_text.GetValue() if len(name.replace(" ", "")) < 4: error = True self._title_text.SetStyle( 0, len(self._title_text.GetValue()), wx.TextAttr(colText=wx.RED) ) if priority.isnumeric() == False or \ int(priority) < 0 or int(priority) > 50: error = True self._priority_text.SetStyle( 0, len(self._priority_text.GetValue()), wx.TextAttr(colText=wx.RED) ) if error == False: # TODO: Use a command cursor = conn.execute(""" INSERT INTO teams (id, name, priority) VALUES ( (SELECT max(CAST(id AS INTEGER)) + 1 FROM teams), ?, ?) """, (name, priority)) conn.commit() reload_teams() self.EndModal(wx.ID_OK)