fork download
  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # generated by wxGlade 1.0.4 on Tue Apr 25 15:00:54 2023
  5. #
  6.  
  7. import wx
  8.  
  9. # begin wxGlade: dependencies
  10. # end wxGlade
  11.  
  12. # begin wxGlade: extracode
  13. from pubsub import pub
  14. from simple_database import Env, install_package, interp
  15. import sys
  16.  
  17. class Controller(object):
  18. def __init__(self):
  19. pub.subscribe(self.read, "Controller")
  20. self.table = {"OnNewFile": "new_file",
  21. "OnOpen": "open_file",
  22. "OnSaveFile": "save_file",
  23. "OnSaveFileAs": "save_file_as",
  24. "OnQuit": "quit",
  25. "OnAddCD": "insert_value",
  26. "Delete": "delete"}
  27. def read(self, x, env):
  28. pub.sendMessage("Model.eval",
  29. x = [self.table[x[0]]] + x[1:],
  30. env = env)
  31.  
  32. class Model(object):
  33. def __init__(self):
  34. pub.subscribe(self.eval, "Model")
  35. def eval(self, x, env):
  36. pub.sendMessage("View.SetProperties", env = interp(x, env))
  37. def OnNewFile(self):
  38. with NewFile(self) as fileDialog:
  39. if fileDialog.ShowModal() == wx.ID_CANCEL:
  40. return
  41. pub.sendMessage("Controller.read",
  42. x = ["OnNewFile", fileDialog.GetPath()],
  43. env = self.env)
  44. def OnOpen(self):
  45. with OpenFile(self) as fileDialog:
  46. if fileDialog.ShowModal() == wx.ID_CANCEL:
  47. return
  48. pub.sendMessage("Controller.read",
  49. x = ["OnOpen", fileDialog.GetPath()],
  50. env = self.env)
  51. def OnSaveFileAs(self):
  52. with SaveFileAs(self) as fileDialog:
  53. if fileDialog.ShowModal() == wx.ID_CANCEL:
  54. return
  55. pub.sendMessage("Controller.read",
  56. x = ["OnSaveFileAs", fileDialog.GetPath()],
  57. env = self.env)
  58. # end wxGlade
  59.  
  60.  
  61. class View(wx.Frame):
  62. def __init__(self, *args, **kwds):
  63. # begin wxGlade: View.__init__
  64. self.env = install_package()
  65. kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
  66. wx.Frame.__init__(self, *args, **kwds)
  67. self.SetSize((400, 300))
  68. self.SetTitle("Simple Database")
  69.  
  70. # Menu Bar
  71. self.frame_menubar = wx.MenuBar()
  72. wxglade_tmp_menu = wx.Menu()
  73. item = wxglade_tmp_menu.Append(wx.ID_ANY, u"新規作成\tCtrl+N", "")
  74. self.Bind(wx.EVT_MENU, self.lambda event: OnNewFile(self), item)
  75. item = wxglade_tmp_menu.Append(wx.ID_ANY, u"開く...\tCtrl+O", "")
  76. self.Bind(wx.EVT_MENU, self.lambda event: OnOpen(self), item)
  77. item = wxglade_tmp_menu.Append(wx.ID_ANY, u"保存\tCtrl+S", "")
  78. self.Bind(wx.EVT_MENU, lambda event: pub.sendMessage('Controller.read', x = ['OnSaveFile'], env = self.env), item)
  79. item = wxglade_tmp_menu.Append(wx.ID_ANY, u"名前を付けて保存...\tShift+Ctrl+S", "")
  80. self.Bind(wx.EVT_MENU, self.lambda event: OnSaveAs(self), item)
  81. item = wxglade_tmp_menu.Append(wx.ID_ANY, "Quit\tCtrl+Q", "")
  82. self.Bind(wx.EVT_MENU, lambda event: pub.sendMessage('Controller.read', x = ['OnQuit'], env = self.env), item)
  83. self.frame_menubar.Append(wxglade_tmp_menu, u"ファイル")
  84. self.SetMenuBar(self.frame_menubar)
  85. # Menu Bar end
  86.  
  87. sizer_1 = wx.BoxSizer(wx.VERTICAL)
  88.  
  89. self.AddCD = wx.Button(self, wx.ID_ANY, "AddCD")
  90. sizer_1.Add(self.AddCD, 0, 0, 0)
  91.  
  92. self.list_ctrl_1 = wx.ListCtrl(self, wx.ID_ANY, style=wx.LC_HRULES | wx.LC_REPORT | wx.LC_VRULES)
  93. self.list_ctrl_1.AppendColumn(u"タイトル", format=wx.LIST_FORMAT_LEFT, width=-1)
  94. self.list_ctrl_1.AppendColumn(u"アーティスト", format=wx.LIST_FORMAT_LEFT, width=-1)
  95. self.list_ctrl_1.AppendColumn(u"レーティング", format=wx.LIST_FORMAT_LEFT, width=-1)
  96. self.list_ctrl_1.AppendColumn(u"リップ", format=wx.LIST_FORMAT_LEFT, width=-1)
  97. sizer_1.Add(self.list_ctrl_1, 1, wx.EXPAND, 0)
  98.  
  99. self.SetSizer(sizer_1)
  100.  
  101. self.Layout()
  102. pub.subscribe(self.SetProperties, 'View')
  103.  
  104. self.Bind(wx.EVT_BUTTON, lambda event: AddCDDialog(self).ShowModal(), self.AddCD)
  105. self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.rclick, self.list_ctrl_1)
  106. # end wxGlade
  107.  
  108. def rclick(self, event): # wxGlade: View.<event_handler>
  109. print("Event handler 'rclick' not implemented!")
  110. event.Skip()
  111.  
  112. # end of class View
  113.  
  114. class AddCDDialog(wx.Dialog):
  115. def __init__(self, *args, **kwds):
  116. # begin wxGlade: AddCDDialog.__init__
  117. self.env = args[0].env
  118. kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_DIALOG_STYLE
  119. wx.Dialog.__init__(self, *args, **kwds)
  120. self.SetTitle("Add CD")
  121.  
  122. sizer_1 = wx.BoxSizer(wx.VERTICAL)
  123.  
  124. grid_sizer_1 = wx.GridSizer(4, 2, 0, 0)
  125. sizer_1.Add(grid_sizer_1, 1, wx.EXPAND, 0)
  126.  
  127. Title = wx.StaticText(self, wx.ID_ANY, u"タイトル")
  128. grid_sizer_1.Add(Title, 0, wx.ALIGN_CENTER, 0)
  129.  
  130. self.text_ctrl_1 = wx.TextCtrl(self, wx.ID_ANY, "")
  131. grid_sizer_1.Add(self.text_ctrl_1, 0, wx.ALIGN_CENTER, 0)
  132.  
  133. Artist = wx.StaticText(self, wx.ID_ANY, u"アーティスト")
  134. grid_sizer_1.Add(Artist, 0, wx.ALIGN_CENTER, 0)
  135.  
  136. self.text_ctrl_2 = wx.TextCtrl(self, wx.ID_ANY, "")
  137. grid_sizer_1.Add(self.text_ctrl_2, 0, wx.ALIGN_CENTER, 0)
  138.  
  139. Rating = wx.StaticText(self, wx.ID_ANY, u"レーティング")
  140. grid_sizer_1.Add(Rating, 0, wx.ALIGN_CENTER, 0)
  141.  
  142. self.text_ctrl_3 = wx.TextCtrl(self, wx.ID_ANY, "")
  143. grid_sizer_1.Add(self.text_ctrl_3, 0, wx.ALIGN_CENTER, 0)
  144.  
  145. Ripped = wx.StaticText(self, wx.ID_ANY, u"リップ")
  146. grid_sizer_1.Add(Ripped, 0, wx.ALIGN_CENTER, 0)
  147.  
  148. self.text_ctrl_4 = wx.TextCtrl(self, wx.ID_ANY, "")
  149. grid_sizer_1.Add(self.text_ctrl_4, 0, wx.ALIGN_CENTER, 0)
  150.  
  151. sizer_2 = wx.StdDialogButtonSizer()
  152. sizer_1.Add(sizer_2, 0, wx.ALIGN_RIGHT | wx.ALL, 4)
  153.  
  154. self.button_OK = wx.Button(self, wx.ID_OK, "")
  155. self.button_OK.SetDefault()
  156. sizer_2.AddButton(self.button_OK)
  157.  
  158. self.button_CANCEL = wx.Button(self, wx.ID_CANCEL, "")
  159. sizer_2.AddButton(self.button_CANCEL)
  160.  
  161. sizer_2.Realize()
  162.  
  163. self.SetSizer(sizer_1)
  164. sizer_1.Fit(self)
  165.  
  166. self.SetAffirmativeId(self.button_OK.GetId())
  167. self.SetEscapeId(self.button_CANCEL.GetId())
  168.  
  169. self.Layout()
  170.  
  171. self.Bind(wx.EVT_BUTTON, lambda event: self.OnAddCD(), self.button_OK)
  172. self.Bind(wx.EVT_BUTTON, lambda event: self.Destroy(), self.button_CANCEL)
  173. # end wxGlade
  174.  
  175. # end of class AddCDDialog
  176.  
  177. class NewFile(wx.Dialog):
  178. def __init__(self, *args, **kwds):
  179. # begin wxGlade: NewFile.__init__
  180. self.env = args[0].env
  181. kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_DIALOG_STYLE
  182. wx.Dialog.__init__(self, *args, **kwds)
  183. self.SetTitle(u"新規作成")
  184. self.Layout()
  185. # end wxGlade
  186.  
  187. # end of class NewFile
  188.  
  189. class OpenFile(wx.Dialog):
  190. def __init__(self, *args, **kwds):
  191. # begin wxGlade: OpenFile.__init__
  192. self.env = args[0].env
  193. kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_DIALOG_STYLE
  194. wx.Dialog.__init__(self, *args, **kwds)
  195. self.SetTitle(u"開く...")
  196. self.Layout()
  197. # end wxGlade
  198.  
  199. # end of class OpenFile
  200.  
  201. class SaveFileAs(wx.Dialog):
  202. def __init__(self, *args, **kwds):
  203. # begin wxGlade: SaveFileAs.__init__
  204. self.env = args[0].env
  205. kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_DIALOG_STYLE
  206. wx.Dialog.__init__(self, *args, **kwds)
  207. self.SetTitle(u"名前を付けて保存...")
  208. self.Layout()
  209. # end wxGlade
  210.  
  211. # end of class SaveFileAs
  212.  
  213. class SimpleDatabase(wx.App):
  214. def OnInit(self):
  215. self.View = View(None, wx.ID_ANY, "")
  216. self.SetTopWindow(self.View)
  217. self.View.Show()
  218. return True
  219.  
  220. # end of class SimpleDatabase
  221.  
  222. if __name__ == "__main__":
  223. SimpleDatabase = SimpleDatabase(0)
  224. SimpleDatabase.MainLoop()
  225.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Traceback (most recent call last):
  File "/usr/lib/python3.9/py_compile.py", line 144, in compile
    code = loader.source_to_code(source_bytes, dfile or file,
  File "<frozen importlib._bootstrap_external>", line 918, in source_to_code
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "./prog.py", line 74
    self.Bind(wx.EVT_MENU, self.lambda event: OnNewFile(self), item)
                                ^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.9/py_compile.py", line 150, in compile
    raise py_exc
py_compile.PyCompileError:   File "./prog.py", line 74
    self.Bind(wx.EVT_MENU, self.lambda event: OnNewFile(self), item)
                                ^
SyntaxError: invalid syntax

stdout
Standard output is empty