DialogNewTeam.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. Allows for name and priority input.
  18. """
  19. _name_text = None
  20. _priority_text = None
  21. def __init__(self, parent, id=wx.ID_ANY):
  22. """Initializes the dialog.
  23. Sets upt all the widgets.
  24. parent : wx.*
  25. Dialog parent.
  26. id : int, optional
  27. ID for the dialig (default wx.ID_ANY).
  28. """
  29. # Parent constructor
  30. wx.Dialog.__init__(
  31. self, parent=parent, id=id, pos=(50, 50), size=(300, 180),
  32. title="Create new team", style=wx.DEFAULT_DIALOG_STYLE
  33. )
  34. wx.StaticText(
  35. parent=self, id=wx.ID_ANY, label="Name:",
  36. pos=(30, 30), size=(60, 30)
  37. )
  38. self._title_text = wx.TextCtrl(
  39. parent=self, id=wx.ID_ANY,
  40. pos=(90, 30), size=(180, 25), style=wx.TE_RICH|wx.TE_MULTILINE
  41. )
  42. wx.StaticText(
  43. parent=self, id=wx.ID_ANY, label="Priority:",
  44. pos=(30, 63), size=(60, 30)
  45. )
  46. self._priority_text = wx.TextCtrl(
  47. parent=self, id=wx.ID_ANY, value="0",
  48. pos=(90, 60), size=(30, 25), style=wx.TE_RICH|wx.TE_MULTILINE)
  49. wx.Button(
  50. parent=self, id=wx.ID_ANY, pos=(33, 100),
  51. size=(100, 40), style=wx.LC_REPORT, label="Accept"
  52. ).Bind(wx.EVT_BUTTON, self._accept)
  53. wx.Button(
  54. parent=self, id=wx.ID_CANCEL, pos=(166, 100),
  55. size=(100, 40), style=wx.LC_REPORT, label="Close"
  56. )
  57. def _accept(self, event=None):
  58. error = False
  59. name = self._title_text.GetValue().strip()
  60. priority = self._priority_text.GetValue()
  61. if len(name.replace(" ", "")) < 4:
  62. error = True
  63. self._title_text.SetStyle(
  64. 0, len(self._title_text.GetValue()),
  65. wx.TextAttr(colText=wx.RED)
  66. )
  67. if priority.isnumeric() == False or \
  68. int(priority) < 0 or int(priority) > 50:
  69. error = True
  70. self._priority_text.SetStyle(
  71. 0, len(self._priority_text.GetValue()),
  72. wx.TextAttr(colText=wx.RED)
  73. )
  74. if error == False:
  75. # TODO: Use a command
  76. cursor = conn.execute("""
  77. INSERT INTO teams (id, name, priority) VALUES (
  78. (SELECT max(CAST(id AS INTEGER)) + 1 FROM teams), ?, ?)
  79. """, (name, priority))
  80. conn.commit()
  81. reload_teams()
  82. self.EndModal(wx.ID_OK)