import clr clr.AddReference("PresentationFramework") clr.AddReference("PresentationCore"); clr.AddReference('WindowsBase') clr.AddReference('System.Data') clr.AddReference('System.ComponentModel') import System from System import * from System.Data import * from System.Threading.Tasks import * from System.ComponentModel import * 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 * from System.Windows.Data import * from System.Windows.Ink import * from Microsoft.Win32 import ( OpenFileDialog, SaveFileDialog ) class WpfToolBar(): def __init__(self): self.ctrl = ToolBarTray() def add_toolbar(self,parent=None): self.tool = ToolBar() self.tool.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; self.tool.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; if not parent: parent = self.ctrl parent.AddChild(self.tool) def add_item(self,ctrl,handler=None,icon=None,tooltip=None,parent=None): if handler: ctrl.Click += handler if icon: image = Image(); image.Source = self.get_image(icon); ctrl.Icon = image if tooltip: tip = ToolTip(); tip.Content = tooltip; ctrl.ToolTip = tip if not parent: parent = self.tool parent.Items.Add(ctrl) def add_separater(self,parent=None): if not parent: parent = self.tool parent.Items.Add(Separator()) def get_image(self,filename): return BitmapImage(System.Uri(filename,System.UriKind.Relative)) if __name__ == "__main__": import win import icon as ic app = win.Win("Window Demo",320,240) m = WpfToolBar() m.add_toolbar(); button = Button() button.Content = "Exit" button.Click += lambda s,e: app.Close() m.add_item(button) stack = StackPanel() button = Button() button.Content = stack button.Click += lambda s,e: app.Close() img = Image() #img.Source = BitmapImage(System.Uri("exit.png",System.UriKind.Relative)) img.Source = ic.GetExitBitmapImage() stack.Children.Add(img) m.add_item(button) app.add_toolbar(m) app.run()
2020년 12월 5일 토요일
[IronPython] WPF ToolBar
WPF ToolBar
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기