""" 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. Parameters ---------- nameText : wx.TextCtrl Textbox for the new team name. priorityCheck : wx.TextCtrl Textbox for the new team priority. Methods ------- accept(event) Checks from accept button. Validates and creates the team . Parameters ---------- parent : wx.* Dialog parent. id : int, optional ID for the dialig (default wx.ID_ANY). """ nameText = None priorityText = 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.titleText = 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.priorityText = wx.TextCtrl( parent=self, id=wx.ID_ANY, value="0", pos=(90, 60), size=(30, 25), style=wx.TE_RICH|wx.TE_MULTILINE) btAccept = wx.Button( parent=self, id=wx.ID_ANY, pos=(33, 100), size=(100, 40), style=wx.LC_REPORT, label="Accept" ) btClose = wx.Button( parent=self, id=wx.ID_CANCEL, pos=(166, 100), size=(100, 40), style=wx.LC_REPORT, label="Close" ) self.Bind(wx.EVT_BUTTON, self.accept, btAccept) def accept(self, event=None): error = False name = self.titleText.GetValue().strip() priority = self.priorityText.GetValue() if len(name.replace(" ", "")) < 4: error = True self.titleText.SetStyle( 0, len(self.titleText.GetValue()), wx.TextAttr(colText=wx.RED) ) if priority.isnumeric() == False or \ int(priority) < 0 or int(priority) > 50: error = True self.priorityText.SetStyle( 0, len(self.priorityText.GetValue()), wx.TextAttr(colText=wx.RED) ) if error == False: cursor = conn.execute(""" INSERT INTO teams (id, name, priority) VALUES ( (SELECT max(CAST(id AS INTEGER)) + 1 FROM teams), ?, ?) """, (name, priority)) conn.commit() self.EndModal(wx.ID_OK)