1
0
Fork 0
mirror of https://github.com/wagesj45/butterflow-ui.git synced 2024-12-22 09:12:42 -06:00

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">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Height="128"> <StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Height="128">
<ContentControl VerticalAlignment="Center" Template="{StaticResource ButterflowUIIcon}" /> <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> </StackPanel>
<TextBlock Text="{x:Static loc:Localization.AboutWindowDescription}" TextAlignment="Center" /> <TextBlock Text="{x:Static loc:Localization.AboutWindowDescription}" TextAlignment="Center" />
<Separator Margin="0,15" /> <Separator Margin="0,15" />

View file

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

View file

@ -39,11 +39,6 @@
<ContentControl Template="{StaticResource SaveIcon}" /> <ContentControl Template="{StaticResource SaveIcon}" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem Name="menuSaveConfigurationAs" Header="{x:Static loc:Localization.SaveAsMenuItem}" Click="menuSaveConfigurationAs_Click">
<MenuItem.Icon>
<ContentControl Template="{StaticResource SaveAsIcon}" />
</MenuItem.Icon>
</MenuItem>
</MenuItem> </MenuItem>
<MenuItem Header="{x:Static loc:Localization.EditMenu}"> <MenuItem Header="{x:Static loc:Localization.EditMenu}">
<MenuItem Name="menuCopyArguments" Header="{x:Static loc:Localization.CopyArgumentsMenu}" Click="btnCopyArguments_Click"> <MenuItem Name="menuCopyArguments" Header="{x:Static loc:Localization.CopyArgumentsMenu}" Click="btnCopyArguments_Click">
@ -127,7 +122,7 @@
<Label Content="{x:Static loc:Localization.ProcessLabel}" /> <Label Content="{x:Static loc:Localization.ProcessLabel}" />
</StackPanel> </StackPanel>
</Button> </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"> <StackPanel Orientation="Horizontal">
<ContentControl MaxWidth="16" HorizontalAlignment="Center" Template="{StaticResource CancelIcon}" /> <ContentControl MaxWidth="16" HorizontalAlignment="Center" Template="{StaticResource CancelIcon}" />
<Label Content="{x:Static loc:Localization.CancelLabel}" /> <Label Content="{x:Static loc:Localization.CancelLabel}" />

View file

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
@ -45,6 +46,7 @@ namespace butterflow_ui
public MainWindow() public MainWindow()
{ {
this.ButterflowWrapper.ParsedConsoleOutputRecieved += ButterflowWrapper_ParsedConsoleOutputRecieved; this.ButterflowWrapper.ParsedConsoleOutputRecieved += ButterflowWrapper_ParsedConsoleOutputRecieved;
this.OptionsConfiguration.AddConstantCallProperty("CommandLineOutput");
InitializeComponent(); InitializeComponent();
} }
@ -313,6 +315,14 @@ namespace butterflow_ui
this.ButterflowWrapper.Run(this.OptionsConfiguration); 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> /// <summary> Event handler. Called by btnRemoveSubregion for click events. </summary>
/// <param name="sender"> Source of the event. </param> /// <param name="sender"> Source of the event. </param>
/// <param name="e"> Routed event information. </param> /// <param name="e"> Routed event information. </param>
@ -340,7 +350,19 @@ namespace butterflow_ui
/// <param name="e"> Routed event information. </param> /// <param name="e"> Routed event information. </param>
private void menuOpen_Click(object sender, RoutedEventArgs e) 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> /// <summary> Event handler. Called by menuSaveConfiguration for click events. </summary>
@ -348,15 +370,15 @@ namespace butterflow_ui
/// <param name="e"> Routed event information. </param> /// <param name="e"> Routed event information. </param>
private void menuSaveConfiguration_Click(object sender, RoutedEventArgs e) private void menuSaveConfiguration_Click(object sender, RoutedEventArgs e)
{ {
var sfd = new SaveFileDialog();
sfd.Filter = "ButterflowUI Configuration|*.bui";
} var result = sfd.ShowDialog(this);
if (result.HasValue && result.Value)
/// <summary> Event handler. Called by menuSaveConfigurationAs for click events. </summary> {
/// <param name="sender"> Source of the event. </param> var binaryFormatter = new BinaryFormatter();
/// <param name="e"> Routed event information. </param> binaryFormatter.Serialize(sfd.OpenFile(), this.OptionsConfiguration.ToFile());
private void menuSaveConfigurationAs_Click(object sender, RoutedEventArgs e) }
{
} }
/// <summary> Event handler. Called by menuButterflowGithub for click events. </summary> /// <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> /// <summary> The butterflow options configuration. Contians all the options necessary to run butterflow and process a video. </summary>
[Serializable]
public class OptionsConfiguration : PropertyChangedAlerter public class OptionsConfiguration : PropertyChangedAlerter
{ {
#region Members #region Members
@ -25,6 +24,7 @@ namespace butterflow_ui
private const FlowFilterType DEFAULT_FLOW_FILTER_TYPE = FlowFilterType.box; private const FlowFilterType DEFAULT_FLOW_FILTER_TYPE = FlowFilterType.box;
/// <summary> An input interpreter used for converting string values to numeric values. </summary> /// <summary> An input interpreter used for converting string values to numeric values. </summary>
[NonSerialized]
private InputInterpreter interpreter = new InputInterpreter(); private InputInterpreter interpreter = new InputInterpreter();
/// <summary> The aspect ratio used for calculating heights when the aspect ratio is locked. </summary> /// <summary> The aspect ratio used for calculating heights when the aspect ratio is locked. </summary>
private decimal aspectRatio = 0; private decimal aspectRatio = 0;
@ -394,8 +394,6 @@ namespace butterflow_ui
this.smoothDerivativeStandardDeviation = DEFAULT_SMOOTH_DERIVATIVE_STANDARD_DEVIATION; this.smoothDerivativeStandardDeviation = DEFAULT_SMOOTH_DERIVATIVE_STANDARD_DEVIATION;
this.flowFilterType = DEFAULT_FLOW_FILTER_TYPE; this.flowFilterType = DEFAULT_FLOW_FILTER_TYPE;
AddConstantCallProperty("CommandLineOutput");
this.subregions.CollectionChanged += Subregions_CollectionChanged; ; this.subregions.CollectionChanged += Subregions_CollectionChanged; ;
} }
@ -431,6 +429,51 @@ namespace butterflow_ui
OnPropertyChanged("CommandLineOutput"); 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> /// <summary> Converts this object to a butterflow options. </summary>
/// <returns> This object as a string. </returns> /// <returns> This object as a string. </returns>
public string ToButterflowArguments() 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> /// <summary> Gets or sets the supported languages. </summary>
/// <value> The supported languages. </value> /// <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 #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> /// <summary> Adds a property that will always be called when any property is updated.. </summary>
/// <param name="name"> The name of the property. </param> /// <param name="name"> The name of the property. </param>
public void AddConstantCallProperty(string name) 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))) if (!this.alwaysCall.Any(c => c.Equals(name, StringComparison.OrdinalIgnoreCase)))
{ {
this.alwaysCall.Add(name); this.alwaysCall.Add(name);

View file

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