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 WpfMenuBar(): def __init__(self): self.ctrl = Menu() self.ctrl.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch self.ctrl.VerticalAlignment = System.Windows.VerticalAlignment.Top def add_separater(self,parent=None): self.menu.Items.Add(Separator()) def add_menu(self,name,parent=None): self.menu = MenuItem() self.menu.Header = name; if not parent: parent = self.ctrl parent.Items.Add(self.menu) return self.menu def add_item(self,name,handler=None,icon=None,iconfile=None,tooltip=None,parent=None): item = MenuItem() if name: item.Header = name; if handler: item.Click += handler if icon: image = Image(); image.Source = icon; item.Icon = image if iconfile: image = Image(); image.Source = self.get_imagefile(iconfile); item.Icon = image if tooltip: tip = ToolTip(); tip.Content = tooltip; item.ToolTip = tip if not parent: parent = self.menu parent.Items.Add(item) return item def get_imagefile(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 = WpfMenuBar() m.add_menu("File"); m.add_item("Exit", iconfile="exit.png", handler=lambda s,e: app.Close()) m.add_item("Exit", icon=ic.GetExitBitmapImage(), handler=lambda s,e: app.Close()) app.add_menubar(m) app.run()
2020년 12월 5일 토요일
[IronPython] WPF Menu
WPF Menu
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기