WPF HBox Layout
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 layout class WpfHBox(layout.WpfLayout): def __init__(self): self.ctrl = Grid() self.ctrl.Margin = Thickness(1) self.cols = 0 def add_item(self,item,expand=False,group=None,border=False,width=1): if expand: length = GridLength(width, GridUnitType.Star) else: length = GridLength(width, GridUnitType.Auto) self.ctrl.ColumnDefinitions.Add(ColumnDefinition(Width = length)) Grid.SetColumn(item, self.cols); if group: gbox = GroupBox() gbox.Header = group gbox.AddChild(item) Grid.SetColumn(gbox, self.cols); self.ctrl.Children.Add(gbox) else: if border: rect = Rectangle() rect.Stroke = Brushes.Gray rect.Fill = Brushes.Transparent Grid.SetColumn(rect, self.cols); self.ctrl.Children.Add(rect) self.ctrl.Children.Add(item) self.cols = self.cols + 1 def add_splitter(self,width=1): from System.Windows.Controls import GridSplitter item = GridSplitter() item.HorizontalAlignment = HorizontalAlignment.Center item.VerticalAlignment = VerticalAlignment.Stretch item.ShowsPreview = True item.Width = 5 length = GridLength(width, GridUnitType.Auto) self.ctrl.ColumnDefinitions.Add(ColumnDefinition(Width = length)) Grid.SetColumn(item, self.cols); self.ctrl.Children.Add(item) self.cols = self.cols + 1 def add_spacer(self): self.add_item( Label(), expand=True ) if __name__ == "__main__": import win app = win.Win("HSplit Demo",320,240) h = WpfHBox() h.add_button( "Button1" ) h.add_spacer() h.add_button( "Button2" ) app.set_content(h.ctrl) app.run()
댓글 없음:
댓글 쓰기