The Cobra Programming Language
How To
Print Hello World
Write Basic Syntax
Use Properties
Make An If Else Ladder
Make A Branch Statement
Declare Inits
Use Lists
Use Arrays
Make A Class Hierarchy
Use Nil And Nilable Types
Use Dynamic Typing
Declare Variable Number Of Args
Read And Write Files
Check Inheritance And Implementation
Pass References To Methods
Translate Pseudo Code To Cobra1
Translate Pseudo Code To Cobra2
Implement IEnumerable1
Implement IEnumerable2
Iterate Through Recursive Data With Yield
Make A Collection Class
Declare Contracts
Threads
Win Forms
WPF
GTK
Qyoto
Access MySQL
"""
A very basic Windows Presentation Foundation (WPF) application to get you started.
"""

@ref 'C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework'
@ref 'C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore'
@ref 'C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase'

use System.Windows
use System.Windows.Controls
use System.Windows.Controls.Primitives
use System.Windows.Media
use System.Windows.Threading


class MainWindow inherits Window

    cue init
        base.init
        
        .title = 'WPF Test'

        panel = StackPanel()
        .content = panel
        
        for i in 10
            button = Button(content='Click me.', tag=i)
            listen button.click, ref .buttonClicked
            panel.children.add(button)

    def buttonClicked(sender, ev as RoutedEventArgs )
        sender.content = 'Hey! You have clicked me!  ([sender.tag])'


class Program

    def main has STAThread
        Program().run
    
    def run
        app = Application()
        listen app.dispatcherUnhandledException, ref .dispatcherUnhandledException
        # other events:
        # .startup StartupEventArgs .args
        # .activated EventArgs
        # .deactivated EventArgs
        # .sessionEnding SessionEndingCancelEventArgs  .reasonSessionEnding  .cancel
        # .exit ExitEventArgs .applicationExitCode
        app.run(MainWindow())

    def dispatcherUnhandledException(sender, args as DispatcherUnhandledExceptionEventArgs)
        # you could log and/or email the exception
        # of course, you don't want this interception when using a debugger
        msg = 'Exception: ' + args.exception.message
        MessageBox.show(msg, 'Unhandled Exception', MessageBoxButton.OK)
        args.handled = true