2020년 12월 5일 토요일

[IronPython] WPF StatusBar

WPF StatusBar

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 WpfStatusBar():
    def __init__(self):
        self.ctrl = StatusBar()
        self.ctrl.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
        self.ctrl.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;        
    def add_item(self,ctrl):
        item = StatusBarItem()
        item.Content = ctrl   
        self.ctrl.Items.Add(item)
    def add_separater(self,parent=None):
        self.ctrl.Items.Add(Separator())
    def add_label(self,text):
        label = Label()
        label.Content = text
        self.add_item( label )    
    def add_button(self,text,handler=None):
        button = Button()
        button.Content = text
        if handler: button.Click += handler
        self.add_item( button )    
        
if __name__ == "__main__":
    import win
    import icon as ic
    app = win.Win("Status Demo",320,240)

    content = Button()
    content.Content = "Content"
    app.set_content(content)

    s = WpfStatusBar()

    button = Button()
    button.Content = "Exit"
    button.Click += lambda s,e: app.Close()
    s.add_item(button)

    stack = StackPanel()
    button = Button()
    button.Content = stack
    button.Click += lambda s,e: app.Close()
    img = Image()
    img.Source = ic.GetExitBitmapImage()
    img.Width = 16 
    img.Height = 16
    stack.Children.Add(img)
    s.add_item(button)

    app.add_statusbar(s)
    
    app.run()

댓글 없음:

댓글 쓰기