2020년 12월 5일 토요일

[IronPython] WPF VBox Layout

WPF VBox 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 WpfVBox(layout.WpfLayout):
    def __init__(self):
        self.ctrl = Grid()
        self.ctrl.Margin = Thickness(1)
        self.rows = 0
        
    def add_item(self,item,expand=False,border=False,group=None,height=1):
        if expand: length = GridLength(height, GridUnitType.Star)
        else: length = GridLength(height, GridUnitType.Auto)
        self.ctrl.RowDefinitions.Add(RowDefinition(Height = length))
        Grid.SetRow(item, self.rows);
        if group:
            gbox = GroupBox()
            gbox.Header = group
            gbox.AddChild(item)
            Grid.SetRow(gbox, self.rows);
            self.ctrl.Children.Add(gbox)
        else:
            if border:
                rect = Rectangle()
                rect.Stroke = Brushes.Gray
                rect.Fill = Brushes.Transparent
                Grid.SetRow(rect, self.rows);
                self.ctrl.Children.Add(rect)
            self.ctrl.Children.Add(item)
        self.rows = self.rows + 1
        
    def add_splitter(self,width=1):
        from System.Windows.Controls import GridSplitter
        item = GridSplitter()
        item.HorizontalAlignment = HorizontalAlignment.Stretch
        item.VerticalAlignment = VerticalAlignment.Center
        item.ShowsPreview = True
        item.Height = 5
        length = GridLength(width, GridUnitType.Auto)
        self.ctrl.RowDefinitions.Add(RowDefinition(Height = length))
        Grid.SetRow(item, self.rows);
        self.ctrl.Children.Add(item)
        self.rows = self.rows + 1
          
    def add_spacer(self):
        self.add_item( Label(), expand=True )
        
       
if __name__ == "__main__":
    import win
    app = win.Win("HSplit Demo",320,240)
    h = WpfVBox()
    h.add_button( "Button1" )
    h.add_spacer()
    h.add_button( "Button2" )
    app.set_content(h.ctrl)
    app.run()
            
                    

댓글 없음:

댓글 쓰기