Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit f14ad49

Browse files
committed
Configuration file builder added to UI
1 parent b9b9b97 commit f14ad49

26 files changed

+1451
-61
lines changed

OnnxStack.UI/App.xaml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
xmlns:userControls="clr-namespace:OnnxStack.UI.UserControls"
88
xmlns:behaviors="clr-namespace:OnnxStack.UI.Behaviors"
99
xmlns:models="clr-namespace:OnnxStack.UI.Models"
10+
xmlns:coreConfig="clr-namespace:OnnxStack.Core.Config;assembly=OnnxStack.Core"
11+
xmlns:onnxEnums="clr-namespace:Microsoft.ML.OnnxRuntime;assembly=Microsoft.ML.OnnxRuntime"
1012
xmlns:converters="clr-namespace:OnnxStack.UI.Converters">
1113
<Application.Resources>
1214

13-
<BitmapImage x:Key="LoadingImage" UriSource="/Images/loading.gif" />
1415
<BitmapImage x:Key="PlaceholderImage" UriSource="/Images/placeholder.png" />
1516
<Storyboard x:Key="LoadingAnimation">
1617
<DoubleAnimation Storyboard.TargetProperty="(Image.RenderTransform).(RotateTransform.Angle)" To="360" Duration="0:0:1" RepeatBehavior="Forever" />
@@ -27,6 +28,9 @@
2728
<converters:InverseBoolConverter x:Key="InverseBoolConverter" />
2829
<converters:BooleanToHiddenConverter x:Key="BooleanToHiddenConverter" />
2930
<converters:InverseBooleanToHiddenConverter x:Key="InverseBooleanToHiddenConverter" />
31+
<converters:NullVisibilityConverter x:Key="NullVisibilityConverter" />
32+
<converters:InverseNullVisibilityConverter x:Key="InverseNullVisibilityConverter" />
33+
<converters:DiffuserVisibilityConverter x:Key="DiffuserVisibilityConverter" />
3034

3135
<ObjectDataProvider x:Key="SchedulerType" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
3236
<ObjectDataProvider.MethodParameters>
@@ -65,6 +69,19 @@
6569
</ObjectDataProvider>
6670

6771

72+
<ObjectDataProvider x:Key="ExecutionProviderType" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
73+
<ObjectDataProvider.MethodParameters>
74+
<x:Type TypeName="coreConfig:ExecutionProvider"/>
75+
</ObjectDataProvider.MethodParameters>
76+
</ObjectDataProvider>
77+
78+
<ObjectDataProvider x:Key="ExecutionModeType" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
79+
<ObjectDataProvider.MethodParameters>
80+
<x:Type TypeName="onnxEnums:ExecutionMode"/>
81+
</ObjectDataProvider.MethodParameters>
82+
</ObjectDataProvider>
83+
84+
6885
<!--TODO: Style dictionary for themeing-->
6986
<Style TargetType="{x:Type TextBox}">
7087
<Setter Property="Height" Value="24" />
@@ -77,7 +94,23 @@
7794

7895
</Style>
7996

80-
97+
<Style x:Key="SplitTabControl" TargetType="{x:Type TabControl}" >
98+
<Setter Property="Template">
99+
<Setter.Value>
100+
<ControlTemplate TargetType="TabControl">
101+
<Grid>
102+
<Grid.RowDefinitions>
103+
<RowDefinition Height="Auto"/>
104+
<RowDefinition Height="*"/>
105+
</Grid.RowDefinitions>
106+
<DockPanel Grid.Row="0" IsItemsHost="True" >
107+
</DockPanel>
108+
<ContentPresenter Grid.Row="1" ContentSource="SelectedContent"/>
109+
</Grid>
110+
</ControlTemplate>
111+
</Setter.Value>
112+
</Setter>
113+
</Style>
81114

82115

83116
<Style x:Key="ImageResultListBoxItem" TargetType="ListBoxItem">

OnnxStack.UI/App.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public App()
3636

3737
// Add Windows
3838
builder.Services.AddSingleton<MainWindow>();
39+
builder.Services.AddTransient<MessageDialog>();
40+
builder.Services.AddTransient<TextInputDialog>();
3941
builder.Services.AddTransient<CropImageDialog>();
4042
builder.Services.AddSingleton<IDialogService, DialogService>();
4143

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using OnnxStack.StableDiffusion.Config;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Globalization;
5+
using System.Linq;
6+
using System.Windows;
7+
using System.Windows.Data;
8+
9+
namespace OnnxStack.UI.Converters
10+
{
11+
public class DiffuserVisibilityConverter : IMultiValueConverter
12+
{
13+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
14+
{
15+
if (values.Length == 2 && values[0] is List<DiffuserType> viewTypes && values[1] is List<DiffuserType> modelTypes)
16+
{
17+
return viewTypes.Any(modelTypes.Contains) ? Visibility.Visible : Visibility.Hidden;
18+
}
19+
20+
return Visibility.Hidden;
21+
}
22+
23+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
24+
{
25+
throw new NotImplementedException();
26+
}
27+
}
28+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Data;
5+
6+
namespace OnnxStack.UI.Converters
7+
{
8+
[ValueConversion(typeof(object), typeof(bool))]
9+
public class InverseNullVisibilityConverter : IValueConverter
10+
{
11+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
12+
{
13+
return value == null ? Visibility.Visible : Visibility.Collapsed;
14+
}
15+
16+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
17+
{
18+
throw new NotImplementedException();
19+
}
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Data;
5+
6+
namespace OnnxStack.UI.Converters
7+
{
8+
[ValueConversion(typeof(object), typeof(bool))]
9+
public class NullVisibilityConverter : IValueConverter
10+
{
11+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
12+
{
13+
return value == null ? Visibility.Collapsed : Visibility.Visible;
14+
}
15+
16+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
17+
{
18+
throw new NotImplementedException();
19+
}
20+
}
21+
}

OnnxStack.UI/Dialogs/CropImageDialog.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
xmlns:userControls="clr-namespace:OnnxStack.UI.UserControls"
88
mc:Ignorable="d"
99
Name="UI"
10+
Icon="/Images/Icon.png"
1011
Title="Crop Image"
1112
SizeToContent="WidthAndHeight"
1213
WindowStartupLocation="CenterScreen"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<Window x:Class="OnnxStack.UI.Dialogs.MessageDialog"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
mc:Ignorable="d"
7+
Name="UI"
8+
Icon="/Images/Icon.png"
9+
SizeToContent="WidthAndHeight"
10+
WindowStartupLocation="CenterScreen"
11+
MinWidth="400" MaxWidth="400">
12+
<DockPanel DataContext="{Binding ElementName=UI}" Margin="15">
13+
<StackPanel DockPanel.Dock="Top">
14+
<TextBlock Text="{Binding Message}" TextAlignment="Center" TextWrapping="Wrap" />
15+
</StackPanel>
16+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,20,0,0" Height="30">
17+
<Button Content="Ok" Command="{Binding OkCommand}" Width="100">
18+
<Button.Style>
19+
<Style TargetType="{x:Type Button}">
20+
<Setter Property="Visibility" Value="Collapsed" />
21+
<Style.Triggers>
22+
<DataTrigger Binding="{Binding DialogType, ElementName=UI}" Value="Ok">
23+
<Setter Property="Visibility" Value="Visible" />
24+
</DataTrigger>
25+
</Style.Triggers>
26+
</Style>
27+
</Button.Style>
28+
</Button>
29+
<UniformGrid Columns="2">
30+
<Button Content="Yes" Command="{Binding YesCommand}" Width="100"/>
31+
<Button Content="No" Command="{Binding NoCommand}"/>
32+
<UniformGrid.Style>
33+
<Style TargetType="{x:Type UniformGrid}">
34+
<Setter Property="Visibility" Value="Collapsed" />
35+
<Style.Triggers>
36+
<DataTrigger Binding="{Binding DialogType, ElementName=UI}" Value="YesNo">
37+
<Setter Property="Visibility" Value="Visible" />
38+
</DataTrigger>
39+
</Style.Triggers>
40+
</Style>
41+
</UniformGrid.Style>
42+
</UniformGrid>
43+
</StackPanel>
44+
</DockPanel>
45+
</Window>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using OnnxStack.UI.Commands;
2+
using System.ComponentModel;
3+
using System.Runtime.CompilerServices;
4+
using System.Threading.Tasks;
5+
using System.Windows;
6+
7+
namespace OnnxStack.UI.Dialogs
8+
{
9+
/// <summary>
10+
/// Interaction logic for MessageDialog.xaml
11+
/// </summary>
12+
public partial class MessageDialog : Window, INotifyPropertyChanged
13+
{
14+
private string _message;
15+
private MessageDialogType _dialogType;
16+
17+
public MessageDialog()
18+
{
19+
OkCommand = new AsyncRelayCommand(Ok);
20+
NoCommand = new AsyncRelayCommand(No);
21+
YesCommand = new AsyncRelayCommand(Yes);
22+
InitializeComponent();
23+
}
24+
25+
public AsyncRelayCommand OkCommand { get; }
26+
public AsyncRelayCommand NoCommand { get; }
27+
public AsyncRelayCommand YesCommand { get; }
28+
29+
public string Message
30+
{
31+
get { return _message; }
32+
set { _message = value; NotifyPropertyChanged(); }
33+
}
34+
35+
public MessageDialogType DialogType
36+
{
37+
get { return _dialogType; }
38+
set { _dialogType = value; NotifyPropertyChanged(); }
39+
}
40+
41+
public bool ShowDialog(string title, string message, MessageDialogType dialogType = MessageDialogType.Ok)
42+
{
43+
Title = title;
44+
Message = message;
45+
DialogType = dialogType;
46+
return ShowDialog() ?? false;
47+
}
48+
49+
private Task Ok()
50+
{
51+
DialogResult = true;
52+
return Task.CompletedTask;
53+
}
54+
55+
private Task No()
56+
{
57+
DialogResult = false;
58+
return Task.CompletedTask;
59+
}
60+
61+
private Task Yes()
62+
{
63+
DialogResult = true;
64+
return Task.CompletedTask;
65+
}
66+
67+
public enum MessageDialogType
68+
{
69+
Ok,
70+
YesNo
71+
}
72+
73+
#region INotifyPropertyChanged
74+
public event PropertyChangedEventHandler PropertyChanged;
75+
public void NotifyPropertyChanged([CallerMemberName] string property = "")
76+
{
77+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
78+
}
79+
#endregion
80+
}
81+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Window x:Class="OnnxStack.UI.Dialogs.TextInputDialog"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
mc:Ignorable="d"
7+
Name="UI"
8+
Icon="/Images/Icon.png"
9+
SizeToContent="WidthAndHeight"
10+
WindowStartupLocation="CenterScreen"
11+
MinWidth="400">
12+
<DockPanel DataContext="{Binding ElementName=UI}" Margin="15">
13+
<StackPanel DockPanel.Dock="Top">
14+
<TextBlock Text="{Binding ErrorMessage}" FontSize="13" FontWeight="DemiBold" HorizontalAlignment="Center" Foreground="Red" Margin="0,10">
15+
<TextBlock.Style>
16+
<Style TargetType="{x:Type TextBlock}">
17+
<Setter Property="Visibility" Value="Visible" />
18+
<Style.Triggers>
19+
<DataTrigger Binding="{Binding ErrorMessage.Length, ElementName=UI}" Value="0">
20+
<Setter Property="Visibility" Value="Collapsed" />
21+
</DataTrigger>
22+
</Style.Triggers>
23+
</Style>
24+
</TextBlock.Style>
25+
</TextBlock>
26+
<TextBlock Text="{Binding FieldName}"/>
27+
<TextBox Text="{Binding TextResult, UpdateSourceTrigger=PropertyChanged}" />
28+
</StackPanel>
29+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,20,0,0">
30+
<UniformGrid Columns="2" Height="30">
31+
<Button Content="Cancel" Command="{Binding CancelCommand}" Width="100"/>
32+
<Button Content="Ok" Command="{Binding SaveCommand}"/>
33+
</UniformGrid>
34+
</StackPanel>
35+
</DockPanel>
36+
</Window>

0 commit comments

Comments
 (0)