DialogNewTeam.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. """
  2. This file is part of RuneOptimizer.
  3. RuneOptimizer is free software: you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the Free
  5. Software Foundation, either version 3 of the License, or (at your option)
  6. any later version.
  7. RuneOptimizer is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. RuneOptimizer. If not, see <https://www.gnu.org/licenses/>.
  13. """
  14. class DialogNewTeam(wx.Dialog):
  15. """
  16. Dialog for team creation.
  17. Parameters
  18. ----------
  19. nameText : wx.TextCtrl
  20. Textbox for the new team name.
  21. priorityCheck : wx.TextCtrl
  22. Textbox for the new team priority.
  23. Methods
  24. -------
  25. accept(event)
  26. Checks from accept button. Validates and creates the team .
  27. Parameters
  28. ----------
  29. parent : wx.*
  30. Dialog parent.
  31. id : int, optional
  32. ID for the dialig (default wx.ID_ANY).
  33. """
  34. nameText = None
  35. priorityText = None
  36. def __init__(self, parent, id=wx.ID_ANY):
  37. """Initializes the dialog.
  38. Sets upt all the widgets.
  39. parent : wx.*
  40. Dialog parent.
  41. id : int, optional
  42. ID for the dialig (default wx.ID_ANY).
  43. """
  44. # Parent constructor
  45. wx.Dialog.__init__(
  46. self, parent=parent, id=id, pos=(50, 50), size=(300, 180),
  47. title="Create new team", style=wx.DEFAULT_DIALOG_STYLE
  48. )
  49. wx.StaticText(
  50. parent=self, id=wx.ID_ANY, label="Name:",
  51. pos=(30, 30), size=(60, 30)
  52. )
  53. self.titleText = wx.TextCtrl(
  54. parent=self, id=wx.ID_ANY,
  55. pos=(90, 30), size=(180, 25), style=wx.TE_RICH|wx.TE_MULTILINE
  56. )
  57. wx.StaticText(
  58. parent=self, id=wx.ID_ANY, label="Priority:",
  59. pos=(30, 63), size=(60, 30)
  60. )
  61. self.priorityText = wx.TextCtrl(
  62. parent=self, id=wx.ID_ANY, value="0",
  63. pos=(90, 60), size=(30, 25), style=wx.TE_RICH|wx.TE_MULTILINE)
  64. btAccept = wx.Button(
  65. parent=self, id=wx.ID_ANY, pos=(33, 100),
  66. size=(100, 40), style=wx.LC_REPORT, label="Accept"
  67. )
  68. btClose = wx.Button(
  69. parent=self, id=wx.ID_CANCEL, pos=(166, 100),
  70. size=(100, 40), style=wx.LC_REPORT, label="Close"
  71. )
  72. self.Bind(wx.EVT_BUTTON, self.accept, btAccept)
  73. def accept(self, event=None):
  74. error = False
  75. name = self.titleText.GetValue().strip()
  76. priority = self.priorityText.GetValue()
  77. if len(name.replace(" ", "")) < 4:
  78. error = True
  79. self.titleText.SetStyle(
  80. 0, len(self.titleText.GetValue()),
  81. wx.TextAttr(colText=wx.RED)
  82. )
  83. if priority.isnumeric() == False or \
  84. int(priority) < 0 or int(priority) > 50:
  85. error = True
  86. self.priorityText.SetStyle(
  87. 0, len(self.priorityText.GetValue()),
  88. wx.TextAttr(colText=wx.RED)
  89. )
  90. if error == False:
  91. cursor = conn.execute("""
  92. INSERT INTO teams (id, name, priority) VALUES (
  93. (SELECT max(CAST(id AS INTEGER)) + 1 FROM teams), ?, ?)
  94. """, (name, priority))
  95. conn.commit()
  96. self.EndModal(wx.ID_OK)