RuneOptimizerFrame.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. status = row[1] + ", Lv" + str(row[2]) + " (ID #" +str(row[0]) + ")."
  59. status += " Last updated " + str(row[3])
  60. if (row[4] == 1):
  61. status += ". Modifications applied since."
  62. else:
  63. status += ". No modifications applied since."
  64. self.CreateStatusBar()
  65. self.SetStatusText(status)
  66. # Create tabs
  67. tabs = TabList(parent=pnl, id=wx.ID_ANY)
  68. def makeMenuBar(self):
  69. """
  70. Sets up the application menu.
  71. """
  72. updateMenu = wx.Menu()
  73. updateJson = updateMenu.Append(
  74. -1,
  75. "&Update from JSON file\tCtrl-J",
  76. "Updates the database from a profile JSON file."
  77. );
  78. updateSwdb = updateMenu.Append(
  79. -1,
  80. "&Update from SWDB\tCtrl-W",
  81. "Updates the database from data retrieved from a SWDB instance."
  82. );
  83. updateSwarfarm = updateMenu.Append(
  84. -1,
  85. "&Update from Sarfarm\tCtrl-F",
  86. "Updates the database from data retrieved from Swarfarm."
  87. );
  88. updateSqlite = updateMenu.Append(
  89. -1,
  90. "&Update from a sqlite database\tCtrl-Q",
  91. "Updates the database from a SWDB sqlite database."
  92. );
  93. fileMenu = wx.Menu()
  94. aboutItem = fileMenu.Append(wx.ID_ABOUT)
  95. fileMenu.AppendSeparator()
  96. exitItem = fileMenu.Append(wx.ID_EXIT)
  97. # Make the menu bar.
  98. menuBar = wx.MenuBar()
  99. menuBar.Append(fileMenu, "&File")
  100. menuBar.Append(updateMenu, "&Update")
  101. self.SetMenuBar(menuBar)
  102. # Bind menu items
  103. self.Bind(wx.EVT_MENU, self.closeApp, exitItem)
  104. self.Bind(wx.EVT_MENU, self.showAbout, aboutItem)
  105. self.Bind(wx.EVT_MENU, self.updateFromJson, updateJson)
  106. self.Bind(wx.EVT_MENU, self.updateFromSwdb, updateSwdb)
  107. self.Bind(wx.EVT_MENU, self.updateFromSwarfarm, updateSwarfarm)
  108. self.Bind(wx.EVT_MENU, self.updateFromSqlite, updateSqlite)
  109. def closeApp(self, event):
  110. """
  111. Closes the app.
  112. Parameters
  113. ----------
  114. event : wx.Event, optional
  115. The event that triggered the call (default is None).
  116. """
  117. self.Close(True)
  118. def showAbout(self, event):
  119. """
  120. Display an About dialog.
  121. Parameters
  122. ----------
  123. event : wx.Event, optional
  124. The event that triggered the call (default is None).
  125. """
  126. wx.MessageBox("RuneOptimizerAbout", wx.OK | wx.ICON_INFORMATION)
  127. def updateFromJson(self, event = None):
  128. """
  129. Shows a dialog to update data from a JSON file.
  130. Parameters
  131. ----------
  132. event : wx.Event, optional
  133. The event that triggered the call (default is None).
  134. """
  135. with DialogUpdateJson(self) as dlg:
  136. if dlg.ShowModal() == wx.ID_OK:
  137. # do something here
  138. if (dlg.updateDone == True and dlg.updateError == False):
  139. print("Update succesfull!")
  140. else:
  141. print('Update cancelled')
  142. def updateFromSwdb(self, event):
  143. """
  144. Updates data from a SWDB instance.
  145. TODO
  146. Parameters
  147. ----------
  148. event : wx.Event, optional
  149. The event that triggered the call (default is None).
  150. """
  151. self.showUnimplemented()
  152. def updateFromSwarfarm(self, event):
  153. """
  154. Updates data from Swarfarm.
  155. TODO
  156. Parameters
  157. ----------
  158. event : wx.Event, optional
  159. The event that triggered the call (default is None).
  160. """
  161. self.showUnimplemented()
  162. def updateFromSqlite(self, event):
  163. """
  164. Updates data from a Sqlite file.
  165. TODO
  166. Parameters
  167. ----------
  168. event : wx.Event, optional
  169. The event that triggered the call (default is None).
  170. """
  171. self.showUnimplemented()
  172. def showUnimplemented(self, event):
  173. """
  174. Displays a message for unimplemented features.
  175. Parameters
  176. ----------
  177. event : wx.Event, optional
  178. The event that triggered the call (default is None).
  179. """
  180. wx.MessageBox(
  181. parent=self,
  182. message="This functionality is not yet implemented",
  183. caption="Unimplemented"
  184. )