#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import wx, subprocess
from pubsub import pub
from wxglade_out import MyApp, MyFrame
class Model(object):
def __init__(self):
pub.subscribe(self.eval, "Model")
def eval(self, x):
# print(x) # デバッグ用
pub.sendMessage("View.setProperties", x = subprocess.run(["convert"] + x))
# wxglade_out.MyFrame を継承して作る
class View(MyFrame):
def __init__(self, *args, **kwds):
# 親クラス(wxglade_out.MyFrame) を初期化
super().__init__(*args, **kwds)
# View 独自のプロパティ
pub.subscribe(self.setProperties, "View")
def setProperties(self, x):
self.text_ctrl_1.Clear()
self.button_2.Enable(True)
# wxglade_out.MyFrame の chooseFile をオーバーライド
def chooseFile(self, event):
with OpenFile(self, wildcard = "BMP, GIF, PNG, JPEG files (*.bmp;*.gif;*.png;*.jpeg;*.jpg)|*.bmp;*.gif;*.png;*.jpeg;*.jpg") as fileDialog:
if fileDialog.ShowModal() == wx.ID_CANCEL:
return
d = fileDialog.GetDirectory()
self.text_ctrl_1.write(",".join([f"{d}/{i}" for i in
fileDialog.GetFilenames()]))
# wxglade_out.MyFrame の convert をオーバーライド
def convert(self, event):
self.button_2.Enable(False)
pub.sendMessage("Controller.read",
x = {"files": self.text_ctrl_1.GetLineText(0),
"resize": self.combo_box_1.GetStringSelection(),
"pdf": self.text_ctrl_2.GetLineText(0)})
class Controller(object):
def __init__(self):
pub.subscribe(self.read, "Controller")
def read(self, x):
# print(x) # デバッグ用
pub.sendMessage("Model.eval",
x = [i.strip() for i in x["files"].split(",")]
+ ["-resize", x["resize"]]
+ [x["pdf"] + ".pdf"])
# ここは継承しても無意味なんで、wxglade_out.MyDialog をコピペして作る
class OpenFile(wx.FileDialog):
def __init__(self, *args, **kwds):
# begin wxGlade: MyDialog.__init__
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_DIALOG_STYLE | wx.FD_MULTIPLE
wx.Dialog.__init__(self, *args, **kwds)
self.SetTitle("Open")
self.Layout()
# end wxGlade
# end of class OpenFile
# wxglade_out.MyFrame の MyApp を継承して作る(あまり意味はないが・笑)
class PDFConverter(MyApp):
# wxglade_out.MyApp の OnInit をオーバーライド
def OnInit(self):
self.view = View(None, wx.ID_ANY, "") # View のインスタンス
self.SetTopWindow(self.view)
self.view.Show()
return True
# これも wxglade_out のコピペ
if __name__ == "__main__":
c = Controller() # Controller のインスタンスを追加
m = Model() # Model のインスタンスを追加
App = PDFConverter(0) # PDFConverter のインスタンス
App.MainLoop()
IyEvdXNyL2Jpbi9lbnYgcHl0aG9uMwojIC0qLSBjb2Rpbmc6IFVURi04IC0qLQoKaW1wb3J0IHd4LCBzdWJwcm9jZXNzCmZyb20gcHVic3ViIGltcG9ydCBwdWIKZnJvbSB3eGdsYWRlX291dCBpbXBvcnQgTXlBcHAsIE15RnJhbWUKCmNsYXNzIE1vZGVsKG9iamVjdCk6CiAgICBkZWYgX19pbml0X18oc2VsZik6CiAgICAgICAgcHViLnN1YnNjcmliZShzZWxmLmV2YWwsICJNb2RlbCIpCiAgICBkZWYgZXZhbChzZWxmLCB4KToKICAgICAgICAjIHByaW50KHgpICMg44OH44OQ44OD44Kw55SoCiAgICAgICAgcHViLnNlbmRNZXNzYWdlKCJWaWV3LnNldFByb3BlcnRpZXMiLCB4ID0gc3VicHJvY2Vzcy5ydW4oWyJjb252ZXJ0Il0gKyB4KSkKCiMgd3hnbGFkZV9vdXQuTXlGcmFtZSDjgpLntpnmib/jgZfjgabkvZzjgosgICAgCmNsYXNzIFZpZXcoTXlGcmFtZSk6CiAgICBkZWYgX19pbml0X18oc2VsZiwgKmFyZ3MsICoqa3dkcyk6CiAgICAgICAgIyDopqrjgq/jg6njgrkod3hnbGFkZV9vdXQuTXlGcmFtZSkg44KS5Yid5pyf5YyWCiAgICAgICAgc3VwZXIoKS5fX2luaXRfXygqYXJncywgKiprd2RzKQogICAgICAgICMgVmlldyDni6zoh6rjga7jg5fjg63jg5Hjg4bjgqMKICAgICAgICBwdWIuc3Vic2NyaWJlKHNlbGYuc2V0UHJvcGVydGllcywgIl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ZVRleHQoMCksCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgInJlc2l6ZSI6IHNlbGYuY29tYm9fYm94XzEuR2V0U3RyaW5nU2VsZWN0aW9uKCksCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgInBkZiI6IHNlbGYudGV4dF9jdHJsXzIuR2V0TGluZVRleHQoMCl9KQoKY2xhc3MgQ29udHJvbGxlcihvYmplY3QpOgogICAgZGVmIF9faW5pdF9fKHNlbGYpOgogICAgICAgIHB1Yi5zdWJzY3JpYmUoc2VsZi5yZWFkLCAiQ29udHJvbGxlciIpCiAgICBkZWYgcmVhZChzZWxmLCB4KToKICAgICAgICAjIHByaW50KHgpICMg44OH44OQ44OD44Kw55SoCiAgICAgICAgcHViLnNlbmRNZXNzYWdlKCJNb2RlbC5ldmFsIiwKICAgICAgICAgICAgICAgICAgICAgICAgeCA9IFtpLnN0cmlwKCkgZm9yIGkgaW4geFsiZmlsZXMiXS5zcGxpdCgiLCIpXQogICAgICAgICAgICAgICAgICAgICAgICArIFsiLXJlc2l6ZSIsIHhbInJlc2l6ZSJdXQogICAgICAgICAgICAgICAgICAgICAgICArIFt4WyJwZGYiXSArICIucGRmIl0pCgojIOOBk+OBk+OBr+e2meaJv+OBl+OBpuOCgueEoeaEj+WRs+OBquOCk+OBp+OAgXd4Z2xhZGVfb3V0Lk15RGlhbG9nIOOCkuOCs+ODlOODmuOBl+OBpuS9nOOCiwpjbGFzcyBPcGVuRmlsZSh3eC5GaWxlRGlhbG9nKToKICAgIGRlZiBfX2luaXRfXyhzZWxmLCAqYXJncywgKiprd2RzKToKICAgICAgICAjIGJlZ2luIHd4R2xhZGU6IE15RGlhbG9nLl9faW5pdF9fCiAgICAgICAga3dkc1sic3R5bGUiXSA9IGt3ZHMuZ2V0KCJzdHlsZSIsIDApIHwgd3guREVGQVVMVF9ESUFMT0dfU1RZTEUgfCB3eC5GRF9NVUxUSVBMRQogICAgICAgIHd4LkRpYWxvZy5fX2luaXRfXyhzZWxmLCAqYXJncywgKiprd2RzKQogICAgICAgIHNlbGYuU2V0VGl0bGUoIk9wZW4iKQogICAgICAgIHNlbGYuTGF5b3V0KCkKICAgICAgICAjIGVuZCB3eEdsYWRlCgojIGVuZCBvZiBjbGFzcyBPcGVuRmlsZQoKIyB3eGdsYWRlX291dC5NeUZyYW1lIOOBriBNeUFwcCDjgpLntpnmib/jgZfjgabkvZzjgoso44GC44G+44KK5oSP5ZGz44Gv44Gq44GE44GM44O756yRKSAgICAgICAgCmNsYXNzIFBERkNvbnZlcnRlcihNeUFwcCk6CiAgICAjIHd4Z2xhZGVfb3V0Lk15QXBwIOOBriBPbkluaXQg44KS44Kq44O844OQ44O844Op44Kk44OJCiAgICBkZWYgT25Jbml0KHNlbGYpOgogICAgICAgIHNlbGYudmlldyA9IFZpZXcoTm9uZSwgd3guSURfQU5ZLCAiIikgIyBWaWV3IOOBruOCpOODs+OCueOCv+ODs+OCuQogICAgICAgIHNlbGYuU2V0VG9wV2luZG93KHNlbGYudmlldykKICAgICAgICBzZWxmLnZpZXcuU2hvdygpCiAgICAgICAgcmV0dXJuIFRydWUKCiMg44GT44KM44KCIHd4Z2xhZGVfb3V0IOOBruOCs+ODlOODmgppZiBfX25hbWVfXyA9PSAiX19tYWluX18iOgogICAgYyA9IENvbnRyb2xsZXIoKSAgICAgICMgQ29udHJvbGxlciDjga7jgqTjg7Pjgrnjgr/jg7PjgrnjgpLov73liqAKICAgIG0gPSBNb2RlbCgpICAgICAgICAgICAjIE1vZGVsIOOBruOCpOODs+OCueOCv+ODs+OCueOCkui/veWKoAogICAgQXBwID0gUERGQ29udmVydGVyKDApICMgUERGQ29udmVydGVyIOOBruOCpOODs+OCueOCv+ODs+OCuQogICAgQXBwLk1haW5Mb29wKCkK