Skip to content

Instantly share code, notes, and snippets.

@dahlia
Last active December 29, 2015 19:29
Show Gist options
  • Save dahlia/7717189 to your computer and use it in GitHub Desktop.
Save dahlia/7717189 to your computer and use it in GitHub Desktop.
WPF Étude w/ IronPython
import clr
clr.AddReference('PresentationCore')
clr.AddReference('PresentationFramework')
clr.AddReference('WindowsBase')
from System.Windows import Application, MessageBox, Window
def WindowOnMouseDown(sender, args):
message = 'Window clicked with {0} button at point ({1})'.format(
args.ChangedButton, args.GetPosition(sender)
)
MessageBox.Show(message, sender.Title)
win = Window()
win.Title = 'Handle An Event'
win.MouseDown += WindowOnMouseDown
Application().Run(win)
import clr
clr.AddReference('PresentationCore')
clr.AddReference('PresentationFramework')
clr.AddReference('WindowsBase')
from System.Windows import (Application, MessageBox, MessageBoxButton,
MessageBoxImage, MessageBoxResult, Window)
class InheritTheApp(Application):
def OnStartup(self, args):
Application.OnStartup(self, args)
win = Window()
win.Title = 'Inherit the App'
win.Show()
def OnSessionEnding(self, args):
Application.OnSessionEnding(self, args)
result = MessageBox.Show(
'Do you want to save your data?',
self.MainWindow.Title,
MessageBoxButton.YesNoCancel,
MessageBoxImage.Question,
MessageBoxResult.Yes
)
args.Cancel = result == MessageBoxResult.Cancel
InheritTheApp().Run()
import clr
clr.AddReference('PresentationCore')
clr.AddReference('PresentationFramework')
clr.AddReference('WindowsBase')
from System.Windows import Application, Window
win = Window()
win.Title = 'Say Hello'
Application().Run(win)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment