fork download
  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3.  
  4. import wx, subprocess
  5. from pubsub import pub
  6. from wxglade_out import MyApp, MyFrame
  7.  
  8. class Model(object):
  9. def __init__(self):
  10. pub.subscribe(self.eval, "Model")
  11. def eval(self, x):
  12. # print(x) # デバッグ用
  13. pub.sendMessage("View.setProperties", x = subprocess.run(["convert"] + x))
  14.  
  15. # wxglade_out.MyFrame を継承して作る
  16. class View(MyFrame):
  17. def __init__(self, *args, **kwds):
  18. # 親クラス(wxglade_out.MyFrame) を初期化
  19. super().__init__(*args, **kwds)
  20. # View 独自のプロパティ
  21. pub.subscribe(self.setProperties, "View")
  22. def setProperties(self, x):
  23. self.text_ctrl_1.Clear()
  24. self.button_2.Enable(True)
  25. # wxglade_out.MyFrame の chooseFile をオーバーライド
  26. def chooseFile(self, event):
  27. with OpenFile(self, wildcard = "BMP, GIF, PNG, JPEG files (*.bmp;*.gif;*.png;*.jpeg;*.jpg)|*.bmp;*.gif;*.png;*.jpeg;*.jpg") as fileDialog:
  28. if fileDialog.ShowModal() == wx.ID_CANCEL:
  29. return
  30. d = fileDialog.GetDirectory()
  31. self.text_ctrl_1.write(",".join([f"{d}/{i}" for i in
  32. fileDialog.GetFilenames()]))
  33. # wxglade_out.MyFrame の convert をオーバーライド
  34. def convert(self, event):
  35. self.button_2.Enable(False)
  36. pub.sendMessage("Controller.read",
  37. x = {"files": self.text_ctrl_1.GetLineText(0),
  38. "resize": self.combo_box_1.GetStringSelection(),
  39. "pdf": self.text_ctrl_2.GetLineText(0)})
  40.  
  41. class Controller(object):
  42. def __init__(self):
  43. pub.subscribe(self.read, "Controller")
  44. def read(self, x):
  45. # print(x) # デバッグ用
  46. pub.sendMessage("Model.eval",
  47. x = [i.strip() for i in x["files"].split(",")]
  48. + ["-resize", x["resize"]]
  49. + [x["pdf"] + ".pdf"])
  50.  
  51. # ここは継承しても無意味なんで、wxglade_out.MyDialog をコピペして作る
  52. class OpenFile(wx.FileDialog):
  53. def __init__(self, *args, **kwds):
  54. # begin wxGlade: MyDialog.__init__
  55. kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_DIALOG_STYLE | wx.FD_MULTIPLE
  56. wx.Dialog.__init__(self, *args, **kwds)
  57. self.SetTitle("Open")
  58. self.Layout()
  59. # end wxGlade
  60.  
  61. # end of class OpenFile
  62.  
  63. # wxglade_out.MyFrame の MyApp を継承して作る(あまり意味はないが・笑)
  64. class PDFConverter(MyApp):
  65. # wxglade_out.MyApp の OnInit をオーバーライド
  66. def OnInit(self):
  67. self.view = View(None, wx.ID_ANY, "") # View のインスタンス
  68. self.SetTopWindow(self.view)
  69. self.view.Show()
  70. return True
  71.  
  72. # これも wxglade_out のコピペ
  73. if __name__ == "__main__":
  74. c = Controller() # Controller のインスタンスを追加
  75. m = Model() # Model のインスタンスを追加
  76. App = PDFConverter(0) # PDFConverter のインスタンス
  77. App.MainLoop()
  78.  
Runtime error #stdin #stdout #stderr 0.16s 25368KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 4, in <module>
ModuleNotFoundError: No module named 'wx'