Saving Configurations to Files

This commit is contained in:
Jordan Wages 2018-07-05 02:00:37 -05:00
parent 5083716c05
commit 50eb034ac9
9 changed files with 133 additions and 19 deletions

View File

@ -13,7 +13,7 @@
<StackPanel HorizontalAlignment="Center">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Height="128">
<ContentControl VerticalAlignment="Center" Template="{StaticResource ButterflowUIIcon}" />
<TextBox VerticalAlignment="Center" Text="{x:Static loc:Localization.Title}" FontSize="64" FontFamily="Segoe UI Black" />
<TextBlock VerticalAlignment="Center" Text="{x:Static loc:Localization.Title}" FontSize="64" FontFamily="Segoe UI Black" />
</StackPanel>
<TextBlock Text="{x:Static loc:Localization.AboutWindowDescription}" TextAlignment="Center" />
<Separator Margin="0,15" />

View File

@ -7,6 +7,7 @@ using System.Threading.Tasks;
namespace butterflow_ui
{
/// <summary> A butterflow video subregion. Represents a snippet of a video on which butterflow will act. </summary>
[Serializable]
public class ButterflowSubregion : PropertyChangedAlerter
{
#region Members
@ -111,6 +112,11 @@ namespace butterflow_ui
{
return this.identifier;
}
private set
{
this.identifier = value;
OnPropertyChanged();
}
}
#endregion

View File

@ -39,11 +39,6 @@
<ContentControl Template="{StaticResource SaveIcon}" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Name="menuSaveConfigurationAs" Header="{x:Static loc:Localization.SaveAsMenuItem}" Click="menuSaveConfigurationAs_Click">
<MenuItem.Icon>
<ContentControl Template="{StaticResource SaveAsIcon}" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>
<MenuItem Header="{x:Static loc:Localization.EditMenu}">
<MenuItem Name="menuCopyArguments" Header="{x:Static loc:Localization.CopyArgumentsMenu}" Click="btnCopyArguments_Click">
@ -127,7 +122,7 @@
<Label Content="{x:Static loc:Localization.ProcessLabel}" />
</StackPanel>
</Button>
<Button Grid.Row="1" Name="btnCancel" ToolTip="{x:Static loc:Localization.CancelTooltip}" IsEnabled="{Binding ButterflowWrapper.IsRunning, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=PropertyChanged}" Click="btnProcess_Click">
<Button Grid.Row="1" Name="btnCancel" ToolTip="{x:Static loc:Localization.CancelTooltip}" IsEnabled="{Binding ButterflowWrapper.IsRunning, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=PropertyChanged}" Click="btnCancel_Click">
<StackPanel Orientation="Horizontal">
<ContentControl MaxWidth="16" HorizontalAlignment="Center" Template="{StaticResource CancelIcon}" />
<Label Content="{x:Static loc:Localization.CancelLabel}" />

View File

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
@ -45,6 +46,7 @@ namespace butterflow_ui
public MainWindow()
{
this.ButterflowWrapper.ParsedConsoleOutputRecieved += ButterflowWrapper_ParsedConsoleOutputRecieved;
this.OptionsConfiguration.AddConstantCallProperty("CommandLineOutput");
InitializeComponent();
}
@ -313,6 +315,14 @@ namespace butterflow_ui
this.ButterflowWrapper.Run(this.OptionsConfiguration);
}
/// <summary> Event handler. Called by btnCancel for click events. </summary>
/// <param name="sender"> Source of the event. </param>
/// <param name="e"> Routed event information. </param>
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
this.ButterflowWrapper.Cancel();
}
/// <summary> Event handler. Called by btnRemoveSubregion for click events. </summary>
/// <param name="sender"> Source of the event. </param>
/// <param name="e"> Routed event information. </param>
@ -340,7 +350,19 @@ namespace butterflow_ui
/// <param name="e"> Routed event information. </param>
private void menuOpen_Click(object sender, RoutedEventArgs e)
{
var ofd = new OpenFileDialog();
ofd.Filter = "ButterflowUI Configuration|*.bui";
var result = ofd.ShowDialog(this);
if (result.HasValue && result.Value)
{
var binaryFormatter = new BinaryFormatter();
var file = binaryFormatter.Deserialize(ofd.OpenFile());
if(file is OptionsConfigurationFile)
{
this.OptionsConfiguration.LoadFile((OptionsConfigurationFile)file);
}
}
}
/// <summary> Event handler. Called by menuSaveConfiguration for click events. </summary>
@ -348,15 +370,15 @@ namespace butterflow_ui
/// <param name="e"> Routed event information. </param>
private void menuSaveConfiguration_Click(object sender, RoutedEventArgs e)
{
var sfd = new SaveFileDialog();
sfd.Filter = "ButterflowUI Configuration|*.bui";
}
/// <summary> Event handler. Called by menuSaveConfigurationAs for click events. </summary>
/// <param name="sender"> Source of the event. </param>
/// <param name="e"> Routed event information. </param>
private void menuSaveConfigurationAs_Click(object sender, RoutedEventArgs e)
{
var result = sfd.ShowDialog(this);
if (result.HasValue && result.Value)
{
var binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(sfd.OpenFile(), this.OptionsConfiguration.ToFile());
}
}
/// <summary> Event handler. Called by menuButterflowGithub for click events. </summary>

View File

@ -11,7 +11,6 @@ namespace butterflow_ui
{
/// <summary> The butterflow options configuration. Contians all the options necessary to run butterflow and process a video. </summary>
[Serializable]
public class OptionsConfiguration : PropertyChangedAlerter
{
#region Members
@ -25,6 +24,7 @@ namespace butterflow_ui
private const FlowFilterType DEFAULT_FLOW_FILTER_TYPE = FlowFilterType.box;
/// <summary> An input interpreter used for converting string values to numeric values. </summary>
[NonSerialized]
private InputInterpreter interpreter = new InputInterpreter();
/// <summary> The aspect ratio used for calculating heights when the aspect ratio is locked. </summary>
private decimal aspectRatio = 0;
@ -394,8 +394,6 @@ namespace butterflow_ui
this.smoothDerivativeStandardDeviation = DEFAULT_SMOOTH_DERIVATIVE_STANDARD_DEVIATION;
this.flowFilterType = DEFAULT_FLOW_FILTER_TYPE;
AddConstantCallProperty("CommandLineOutput");
this.subregions.CollectionChanged += Subregions_CollectionChanged; ;
}
@ -431,6 +429,51 @@ namespace butterflow_ui
OnPropertyChanged("CommandLineOutput");
}
/// <summary> Converts this object to a <seealso cref="OptionsConfigurationFile"/>. </summary>
/// <returns> This object as an OptionsConfigurationFile. </returns>
public OptionsConfigurationFile ToFile()
{
var file = new OptionsConfigurationFile()
{
FastPyramid = this.fastPyramid,
FlowFilterType = this.flowFilterType,
Iterations = this.iterations,
KeepAudio = this.keepAudio,
KeepSubregions = this.keepSubRegions,
Levels = this.levels,
LockAspectRatio = this.lockAspectRatio,
LosslessQuality = this.losslessQuality,
PixelNeighborhood = this.pixelNeighborhood,
PlaybackRate = this.playbackRate,
PyramidScale = this.pyramidScale,
SmoothDerivativeStandardDeviation = this.smoothDerivativeStandardDeviation,
SmoothMotion = this.smoothMotion,
WindowSize = this.windowSize
};
return file;
}
/// <summary> Loads an option configuration file's contents into the <seealso cref="OptionsConfiguration"/>. </summary>
/// <param name="file"> The file to load. </param>
public void LoadFile(OptionsConfigurationFile file)
{
this.FastPyramid = file.FastPyramid;
this.FlowFilterType = file.FlowFilterType;
this.Iterations = file.Iterations.ToString();
this.KeepAudio = file.KeepAudio;
this.KeepSubregions = file.KeepSubregions;
this.Levels = file.Levels.ToString();
this.LockAspectRatio = file.LockAspectRatio;
this.LosslessQuality = file.LosslessQuality;
this.PixelNeighborhood = file.PixelNeighborhood.ToString();
this.PlaybackRate = file.PlaybackRate;
this.PyramidScale = file.PyramidScale.ToString();
this.SmoothDerivativeStandardDeviation = file.SmoothDerivativeStandardDeviation.ToString();
this.SmoothMotion = file.SmoothMotion;
this.WindowSize = file.WindowSize.ToString();
}
/// <summary> Converts this object to a butterflow options. </summary>
/// <returns> This object as a string. </returns>
public string ToButterflowArguments()

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace butterflow_ui
{
/// <summary> An options configuration file. </summary>
[Serializable]
public class OptionsConfigurationFile
{
#region Properties
public string PlaybackRate { get; set; }
public bool KeepAudio { get; set; }
public bool KeepSubregions { get; set; }
public bool LosslessQuality { get; set; }
public bool SmoothMotion { get; set; }
public bool LockAspectRatio { get; set; }
public bool FastPyramid { get; set; }
public decimal PyramidScale { get; set; }
public int Levels { get; set; }
public int WindowSize { get; set; }
public int Iterations { get; set; }
public int PixelNeighborhood { get; set; }
public decimal SmoothDerivativeStandardDeviation { get; set; }
public FlowFilterType FlowFilterType { get; set; }
#endregion
}
}

View File

@ -23,7 +23,11 @@ namespace butterflow_ui
/// <summary> Gets or sets the supported languages. </summary>
/// <value> The supported languages. </value>
public List<CultureInfo> SupportedLanguages { get; set; } = new List<CultureInfo>(new[] { CultureInfo.CreateSpecificCulture("en-US"), CultureInfo.CreateSpecificCulture("es-ES") });
public List<CultureInfo> SupportedLanguages { get; set; } = new List<CultureInfo>(new[]
{
CultureInfo.CreateSpecificCulture("en-US"),
CultureInfo.CreateSpecificCulture("es-ES")
});
#endregion

View File

@ -42,10 +42,21 @@ namespace butterflow_ui
}
}
protected virtual void OnAllPropertiesChanged()
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(string.Empty));
}
/// <summary> Adds a property that will always be called when any property is updated.. </summary>
/// <param name="name"> The name of the property. </param>
public void AddConstantCallProperty(string name)
{
if(this.alwaysCall == null)
{
// This item has been deserialized and the list needs to be reinitialized.
this.alwaysCall = new List<string>();
}
if (!this.alwaysCall.Any(c => c.Equals(name, StringComparison.OrdinalIgnoreCase)))
{
this.alwaysCall.Add(name);

View File

@ -68,6 +68,7 @@
</Compile>
<Compile Include="FlowFilterType.cs" />
<Compile Include="InverseBoolConverter.cs" />
<Compile Include="OptionsConfigurationFile.cs" />
<Compile Include="OptionsWindow.xaml.cs">
<DependentUpon>OptionsWindow.xaml</DependentUpon>
</Compile>