RuneOptimizerFrame.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 RuneOptimizerFrame(wx.Frame):
  15. """
  16. The main application window.
  17. """
  18. def __init__(self, *args, **kw):
  19. """
  20. Initializes the class.
  21. Sets upt all the widgets.
  22. """
  23. global conn
  24. super(RuneOptimizerFrame, self).__init__(*args, **kw)
  25. # Create and configure the menue
  26. pnl = wx.Panel(self)
  27. self._make_menu_bar()
  28. # Create the statsusbar
  29. status = "Status: "
  30. cursor = conn.execute("""
  31. SELECT
  32. player_id,
  33. player_name,
  34. player_level,
  35. ts,
  36. modified
  37. FROM info
  38. """)
  39. row = cursor.fetchone()
  40. if row is None:
  41. status = "No data. Use the update menu."
  42. else:
  43. status = \
  44. row[1] + ", Lv" + str(row[2]) + " (ID #" +str(row[0]) + ")."
  45. status += " Last updated " + str(row[3])
  46. if (row[4] == 1):
  47. status += ". Modifications applied since."
  48. else:
  49. status += ". No modifications applied since."
  50. self.CreateStatusBar()
  51. self.SetStatusText(status)
  52. # Create tabs
  53. tabs = Tab_List(parent=pnl, id=wx.ID_ANY)
  54. def _make_menu_bar(self):
  55. """
  56. Sets up the application menu.
  57. """
  58. update_menu = wx.Menu()
  59. update_json = update_menu.Append(
  60. -1,
  61. "&Update from JSON file\tCtrl-J",
  62. "Updates the database from a profile JSON file."
  63. );
  64. update_swdb = update_menu.Append(
  65. -1,
  66. "&Update from SWDB\tCtrl-W",
  67. "Updates the database from data retrieved from a SWDB instance."
  68. );
  69. update_swarfarm = update_menu.Append(
  70. -1,
  71. "&Update from Sarfarm\tCtrl-F",
  72. "Updates the database from data retrieved from Swarfarm."
  73. );
  74. update_sqlite = update_menu.Append(
  75. -1,
  76. "&Update from a sqlite database\tCtrl-Q",
  77. "Updates the database from a SWDB sqlite database."
  78. );
  79. file_menu = wx.Menu()
  80. file_about = file_menu.Append(wx.ID_ABOUT)
  81. file_menu.AppendSeparator()
  82. file_exit = file_menu.Append(wx.ID_EXIT)
  83. # Make the menu bar.
  84. menu_bar = wx.MenuBar()
  85. menu_bar.Append(file_menu, "&File")
  86. menu_bar.Append(update_menu, "&Update")
  87. self.SetMenuBar(menu_bar)
  88. # Bind menu items
  89. self.Bind(wx.EVT_MENU, self._close_app, file_exit)
  90. self.Bind(wx.EVT_MENU, self._show_about, file_about)
  91. self.Bind(wx.EVT_MENU, self._update_from_json, update_json)
  92. self.Bind(wx.EVT_MENU, self._update_from_swdb, update_swdb)
  93. self.Bind(wx.EVT_MENU, self._update_from_swarfarm, update_swarfarm)
  94. self.Bind(wx.EVT_MENU, self._update_from_sqlite, update_sqlite)
  95. def _close_app(self, event):
  96. """
  97. Closes the app.
  98. Parameters
  99. ----------
  100. event : wx.Event, optional
  101. The event that triggered the call (default is None).
  102. """
  103. self.Close(True)
  104. def _show_about(self, event):
  105. """
  106. Display an About dialog.
  107. Parameters
  108. ----------
  109. event : wx.Event, optional
  110. The event that triggered the call (default is None).
  111. """
  112. wx.MessageBox(
  113. parent=self,
  114. message="An about text!",
  115. caption="RuneOptimizer",
  116. style=wx.OK | wx.ICON_INFORMATION
  117. )
  118. def _update_from_json(self, event = None):
  119. """
  120. Shows a dialog to update data from a JSON file.
  121. Parameters
  122. ----------
  123. event : wx.Event, optional
  124. The event that triggered the call (default is None).
  125. """
  126. with DialogUpdateJson(self) as dlg:
  127. if dlg.ShowModal() == wx.ID_OK:
  128. # do something here
  129. if (dlg.update_done == True and dlg.update_error == False):
  130. print("Update succesfull!")
  131. # TODO: Recalculate status bas message
  132. def _update_from_swdb(self, event):
  133. """
  134. Updates data from a SWDB instance.
  135. TODO
  136. Parameters
  137. ----------
  138. event : wx.Event, optional
  139. The event that triggered the call (default is None).
  140. """
  141. self._show_unimplemented()
  142. def _update_from_swarfarm(self, event):
  143. """
  144. Updates data from Swarfarm.
  145. TODO
  146. Parameters
  147. ----------
  148. event : wx.Event, optional
  149. The event that triggered the call (default is None).
  150. """
  151. self._show_unimplemented()
  152. def _update_from_sqlite(self, event):
  153. """
  154. Updates data from a Sqlite file.
  155. TODO
  156. Parameters
  157. ----------
  158. event : wx.Event, optional
  159. The event that triggered the call (default is None).
  160. """
  161. self._show_unimplemented()
  162. def _show_unimplemented(self, event=None):
  163. """
  164. Displays a message for unimplemented features.
  165. Parameters
  166. ----------
  167. event : wx.Event, optional
  168. The event that triggered the call (default is None).
  169. """
  170. wx.MessageBox(
  171. parent=self,
  172. message="This functionality is not yet implemented",
  173. caption="Unimplemented"
  174. )