module Parasitemia.GUI open System.IO open System.Windows open System.Windows.Media open System.Windows.Markup open System.Windows.Shapes open System.Windows.Controls open System.Drawing open System.Diagnostics open Microsoft.Win32 // For the common dialogs. open Emgu.CV open Emgu.CV.Structure open Emgu.CV.WPF open Config let run (defaultConfig: Config) = let app = new Application() let mainWindow = Views.MainWindow() let ctrl (name: string): 'a = mainWindow.Root.FindName(name) :?> 'a // Utils.log <- (fun m -> log mainWindow m) let state = State.State() let exit: Controls.MenuItem = ctrl "menuExit" let save: Controls.MenuItem = ctrl "menuSave" let load: Controls.MenuItem = ctrl "menuOpen" let txtPatient: Controls.TextBox = ctrl "txtPatient" let synchronizeState () = state.PatientID <- txtPatient.Text let synchronizeView () = txtPatient.Text <- state.PatientID exit.Click.AddHandler(fun obj args -> mainWindow.Root.Close()) save.Click.AddHandler(fun obj args -> synchronizeState () if state.FilePath = "" then let dialog = SaveFileDialog(AddExtension = true, DefaultExt = Pia.extension, Filter = Pia.filter); let res = dialog.ShowDialog() if res.HasValue && res.Value then state.FilePath <- dialog.FileName state.Save() else state.Save()) load.Click.AddHandler(fun obj args -> // TODO: if current state not saved and not empty, ask to save it. let dialog = OpenFileDialog(Filter = Pia.filter) let res = dialog.ShowDialog() if res.HasValue && res.Value then state.FilePath <- dialog.FileName state.Load() synchronizeView ()) (*let txtPatient: Controls.TextBox = ctrl "txtPatient" txtPatient.TextChanged.AddHandler(fun obj args -> state.PatientID <- txtPatient.Text)*) (*saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ; saveFileDialog1.FilterIndex = 2 ; saveFileDialog1.RestoreDirectory = true ;*) // display mainWindow img mainWindow.Root.Show() app.Run()