WPF Edit (Text Box)
import clr clr.AddReference("PresentationFramework") clr.AddReference("PresentationCore"); clr.AddReference('System.Data') clr.AddReference('System.Windows.Forms') import System from System import * from System.Data import * from System.Type import GetType from System.Threading.Tasks import Task from System.Windows import * from System.Windows.Controls import * from System.Windows.Controls.Primitives import * from System.Windows.Media import * from System.Windows.Media.Imaging import * from System.Windows.Media.Effects import * from System.Windows.Shapes import Rectangle from System.Windows.Data import Binding from System.Windows.Ink import Stroke from System.Windows.Forms import ( FolderBrowserDialog, DialogResult ) from Microsoft.Win32 import ( OpenFileDialog, SaveFileDialog ) import ctrl import vbox import hbox def ClipboardGetTextData(): return Clipboard.GetData(DataFormats.Text) def ClipboardSetTextData(text): Clipboard.SetData(DataFormats.Text, text) def ClipboardGetHtmlData(): return Clipboard.GetData(DataFormats.Html) def ClipboardSetHtmlData(text): Clipboard.SetData(DataFormats.Html, text) def ClipboardGetText(): return Clipboard.GetText() def ClipboardSetText(text): Clipboard.SetText(text) class WpfEdit(ctrl.WpfCtrl): def __init__(self,text=None,multiline=True,tool=False,handler=None,image=None,size=None,vert=True,**kwargs): self.text = TextBox() self.ctrl = self.text self.init(**kwargs) if multiline: self.ctrl.AcceptsReturn = True self.ctrl.AcceptsTab = True self.ctrl.TextWrapping = TextWrapping.NoWrap self.ctrl.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto self.ctrl.VerticalScrollBarVisibility = ScrollBarVisibility.Auto if handler: self.ctrl.Click += handler if tool: self.vbox = vbox.WpfVBox() self.hbox = hbox.WpfHBox() self.hbox.add_item(self.get_button("Clear", self.clear_handler)) self.hbox.add_item(self.get_button("Copy", self.copy_handler)) self.hbox.add_item(self.get_button("CopyAll", self.copy_all_handler)) self.hbox.add_item(self.get_button("Paste", self.paste_handler)) self.hbox.add_item(self.get_button("PasteHtml", self.paste_html_handler)) self.vbox.add_item(self.hbox.ctrl) self.vbox.add_item(self.text,expand=True) self.ctrl = self.vbox.ctrl def clear(self): self.text.Text = "" def get_value(self): return self.text.Text def set_value(self,text): self.text.Text = text def append_text(self,text): self.text.Text += text def set_width(self,width): self.text.Width = width def scroll_to_end(self): self.text.ScrollToEnd() def set_wrap(self,wrap): self.text.TextWrapping = TextWrapping.Wrap if wrap else TextWrapping.NoWrap def get_button(self,label,handler): b = Button() b.Content = label b.Click += handler return b def clear_handler(self,sender,args): self.text.Clear() def copy_handler(self,sender,args): self.text.Copy() def copy_all_handler(self,sender,args): self.text.SelectAll() self.text.Copy() def paste_handler(self,sender,args): self.text.Paste() def paste_html_handler(self,sender,args): self.text.Text = ClipboardGetHtmlData() if __name__ == "__main__": import win app = win.Win("Edit Demo",320,240) b = WpfEdit("Exit", multiline=True, tool=True) app.set_content(b.ctrl) app.run()
댓글 없음:
댓글 쓰기