import wx class FileDrop(wx.FileDropTarget): def __init__(self, window): wx.FileDropTarget.__init__(self) self.window = window def OnDropFiles(self, x, y, filenames): self.window.drop_handle(filenames) return True class VBox(wx.Panel): def __init__(self,parent): super().__init__( parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) self.box = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self.box) def Add(self,ctrl,border=5,expand=False,fill=False,bottom=False): flag = wx.ALIGN_BOTTOM if bottom else 0 flag |= wx.EXPAND if expand else 0 flag |= wx.ALL if border else 0 self.box.Add( ctrl, 1 if fill else 0, flag, border ) return ctrl class HBox(wx.Panel): def __init__(self, parent): super().__init__( parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) self.box = wx.BoxSizer(wx.HORIZONTAL) self.SetSizer(self.box) def Add(self,ctrl,border=5,expand=False,fill=False,right=False): flag = wx.ALIGN_CENTER_VERTICAL flag |= wx.ALIGN_RIGHT if right else 0 flag |= wx.EXPAND if expand else 0 flag |= wx.ALL if border else 0 self.box.Add( ctrl, 1 if fill else 0, flag, border ) return ctrl class Label(wx.StaticText): def __init__(self, parent, label): super().__init__( parent, wx.ID_ANY, label, wx.DefaultPosition, wx.DefaultSize, 0 ) self.Wrap(-1) class Button(wx.Button): def __init__(self, parent, label, handler=None): super().__init__( parent, wx.ID_ANY, label, wx.DefaultPosition, wx.DefaultSize, 0 ) if handler: self.Bind(wx.EVT_BUTTON, handler) class TextField(wx.TextCtrl): def __init__(self, parent, label=wx.EmptyString, handler=None): super().__init__( parent, wx.ID_ANY, label, wx.DefaultPosition, wx.DefaultSize, 0 ) if handler: pass class Text(wx.TextCtrl): def __init__(self, parent, label=wx.EmptyString, handler=None): super().__init__( parent, wx.ID_ANY, label, wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE|wx.TE_WORDWRAP ) class WxWin(wx.Frame): def __init__(self,title="Untitled",width=600,height=400): self.app = wx.App(False) super().__init__( None, id = wx.ID_ANY, title = title, pos = wx.DefaultPosition, size = wx.Size( width, height ), style = wx.CAPTION|wx.CLOSE_BOX|wx.MAXIMIZE_BOX|wx.MINIMIZE_BOX|wx.SYSTEM_MENU|wx.TAB_TRAVERSAL ) self.vbox = wx.BoxSizer( wx.VERTICAL ) def VBox(self): panel = wx.Panel( wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) box = wx.BoxSizer( wx.VERTICAL ) return (panel, box) def HBox(self): panel = wx.Panel( wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) box = wx.BoxSizer( wx.HORIZONTAL ) return (panel, box) def Add(self,panel,expand=False, fill=False): flag = wx.ALL flag |= wx.EXPAND if expand else 0 self.vbox.Add( panel, 1 if fill else 0, flag, 0 ) def Run(self): self.SetSizer( self.vbox ) self.Layout() self.Centre( wx.BOTH ) self.Show(True) self.app.MainLoop() if __name__ == "__main__": def open_handler(event): print(event) def get_output_panel(parent): hbox = HBox(parent) hbox.Add( Label(hbox, "Ouput:" ) ) hbox.Add( TextField(hbox), fill=True ) hbox.Add( Button(hbox, "Open", open_handler) ) return hbox def get_main_panel(parent): vbox = VBox(win) vbox.Add( Text(vbox), expand=True, fill=True ) return vbox win = WxWin("WxWidget Demo", 400, 300) out_panel = get_output_panel(win) main_panel = get_main_panel(win) win.Add(out_panel, expand=True) win.Add(main_panel, expand=True, fill=True) win.Run()
댓글 없음:
댓글 쓰기