RuneOptimizerFrame.py 6.3 KB

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