Skip to content

Commit 6dfee2a

Browse files
committed
Basic UI
1 parent 2edcb1f commit 6dfee2a

File tree

94 files changed

+13287
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+13287
-0
lines changed

DemoApp.sln

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36221.1 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoApp", "DemoApp\DemoApp.csproj", "{61004604-80B3-4E50-99F2-5377453ABE6A}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
9+
ProjectSection(SolutionItems) = preProject
10+
Directory.Build.props = Directory.Build.props
11+
EndProjectSection
12+
EndProject
13+
Global
14+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
15+
Debug|Any CPU = Debug|Any CPU
16+
Release|Any CPU = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
19+
{61004604-80B3-4E50-99F2-5377453ABE6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{61004604-80B3-4E50-99F2-5377453ABE6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{61004604-80B3-4E50-99F2-5377453ABE6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
22+
{61004604-80B3-4E50-99F2-5377453ABE6A}.Release|Any CPU.Build.0 = Release|Any CPU
23+
EndGlobalSection
24+
GlobalSection(SolutionProperties) = preSolution
25+
HideSolutionNode = FALSE
26+
EndGlobalSection
27+
GlobalSection(ExtensibilityGlobals) = postSolution
28+
SolutionGuid = {46369911-B2F4-4D3A-BC20-6B2C407535CA}
29+
EndGlobalSection
30+
EndGlobal

DemoApp/App.xaml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<Application x:Class="DemoApp.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:System="clr-namespace:System;assembly=mscorlib"
5+
xmlns:local="clr-namespace:DemoApp"
6+
xmlns:CommonControls="clr-namespace:TensorStack.WPF.Controls;assembly=TensorStack.WPF"
7+
xmlns:Extractors="clr-namespace:TensorStack.Extractors.Common;assembly=TensorStack.Extractors"
8+
xmlns:TextGeneration="clr-namespace:TensorStack.TextGeneration.Common;assembly=TensorStack.TextGeneration"
9+
xmlns:StableDiffusion="clr-namespace:TensorStack.StableDiffusion.Enums;assembly=TensorStack.StableDiffusion"
10+
ShutdownMode="OnMainWindowClose">
11+
<Application.Resources>
12+
13+
14+
<ResourceDictionary>
15+
16+
<!--DemoApp-->
17+
<BitmapImage x:Key="BackgroundGradient" UriSource="pack://application:,,,/DemoApp;component/Images/Background.jpeg" />
18+
19+
<ObjectDataProvider x:Key="EarlyStopping" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
20+
<ObjectDataProvider.MethodParameters>
21+
<x:Type TypeName="TextGeneration:EarlyStopping"/>
22+
</ObjectDataProvider.MethodParameters>
23+
</ObjectDataProvider>
24+
25+
<ObjectDataProvider x:Key="BackgroundMode" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
26+
<ObjectDataProvider.MethodParameters>
27+
<x:Type TypeName="Extractors:BackgroundMode"/>
28+
</ObjectDataProvider.MethodParameters>
29+
</ObjectDataProvider>
30+
31+
32+
<ObjectDataProvider x:Key="SchedulerType" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
33+
<ObjectDataProvider.MethodParameters>
34+
<x:Type TypeName="StableDiffusion:SchedulerType"/>
35+
</ObjectDataProvider.MethodParameters>
36+
</ObjectDataProvider>
37+
38+
39+
<Style x:Key="BorderPanel" TargetType="{x:Type Border}">
40+
<Setter Property="Padding" Value="4"/>
41+
<Setter Property="Background" Value="#15000000"/>
42+
<Setter Property="BorderBrush" Value="{StaticResource ControlDarkerBorderBrush}"/>
43+
<Setter Property="BorderThickness" Value="1"/>
44+
<Setter Property="CornerRadius" Value="0"/>
45+
</Style>
46+
47+
48+
<Style x:Key="ImageDropZoneStyle" TargetType="{x:Type Border}">
49+
<Setter Property="AllowDrop" Value="False"/>
50+
<Setter Property="BorderBrush" Value="Transparent"/>
51+
<Setter Property="BorderThickness" Value="1"/>
52+
<Style.Triggers>
53+
<MultiDataTrigger>
54+
<MultiDataTrigger.Conditions>
55+
<Condition Binding="{Binding IsDragDrop, RelativeSource={RelativeSource AncestorType=CommonControls:ViewControl}}" Value="True" />
56+
<Condition Binding="{Binding DragDropType, RelativeSource={RelativeSource AncestorType=CommonControls:ViewControl}}" Value="Image" />
57+
</MultiDataTrigger.Conditions>
58+
<MultiDataTrigger.Setters>
59+
<Setter Property="AllowDrop" Value="True"/>
60+
<Setter Property="BorderBrush" Value="{StaticResource AccentColour2}"/>
61+
</MultiDataTrigger.Setters>
62+
</MultiDataTrigger>
63+
</Style.Triggers>
64+
</Style>
65+
66+
67+
<Style x:Key="VideoDropZoneStyle" TargetType="{x:Type Border}">
68+
<Setter Property="AllowDrop" Value="False"/>
69+
<Setter Property="BorderBrush" Value="Transparent"/>
70+
<Setter Property="BorderThickness" Value="1"/>
71+
<Style.Triggers>
72+
<MultiDataTrigger>
73+
<MultiDataTrigger.Conditions>
74+
<Condition Binding="{Binding IsDragDrop, RelativeSource={RelativeSource AncestorType=CommonControls:ViewControl}}" Value="True" />
75+
<Condition Binding="{Binding DragDropType, RelativeSource={RelativeSource AncestorType=CommonControls:ViewControl}}" Value="Video" />
76+
</MultiDataTrigger.Conditions>
77+
<MultiDataTrigger.Setters>
78+
<Setter Property="AllowDrop" Value="True"/>
79+
<Setter Property="BorderBrush" Value="{StaticResource AccentColour2}"/>
80+
</MultiDataTrigger.Setters>
81+
</MultiDataTrigger>
82+
</Style.Triggers>
83+
</Style>
84+
85+
86+
87+
88+
89+
<Style x:Key="ToggleButtonBasic" TargetType="{x:Type ToggleButton}">
90+
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
91+
<Setter Property="Background" Value="{StaticResource ComboBoxBackground}"/>
92+
<Setter Property="BorderBrush" Value="{StaticResource ComboBoxBorder}"/>
93+
<Setter Property="Foreground" Value="{StaticResource ButtonForeground}"/>
94+
<Setter Property="BorderThickness" Value="0"/>
95+
<Setter Property="HorizontalContentAlignment" Value="Center"/>
96+
<Setter Property="VerticalContentAlignment" Value="Center"/>
97+
<Setter Property="Padding" Value="1"/>
98+
<Setter Property="Template">
99+
<Setter.Value>
100+
<ControlTemplate TargetType="{x:Type ToggleButton}">
101+
<Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" SnapsToDevicePixels="true">
102+
<ContentPresenter x:Name="contentPresenter" Opacity="0.7" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
103+
</Border>
104+
<ControlTemplate.Triggers>
105+
<Trigger Property="Button.IsDefaulted" Value="true">
106+
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ButtonBorderDefault}"/>
107+
</Trigger>
108+
<Trigger Property="IsMouseOver" Value="true">
109+
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ButtonBorderMouseOver}"/>
110+
<Setter Property="ContentPresenter.Opacity" TargetName="contentPresenter" Value="1"/>
111+
</Trigger>
112+
113+
<Trigger Property="IsEnabled" Value="false">
114+
<Setter Property="Opacity" Value="0.3" />
115+
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ButtonBorderDisabled}"/>
116+
<Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource ButtonForegroundDisabled}"/>
117+
</Trigger>
118+
<Trigger Property="IsChecked" Value="false">
119+
<Setter Property="ContentPresenter.Opacity" TargetName="contentPresenter" Value="1"/>
120+
</Trigger>
121+
</ControlTemplate.Triggers>
122+
</ControlTemplate>
123+
</Setter.Value>
124+
</Setter>
125+
</Style>
126+
127+
128+
129+
130+
131+
132+
133+
134+
135+
136+
137+
138+
<!--TensorStack.WPF-->
139+
<ResourceDictionary.MergedDictionaries>
140+
<ResourceDictionary Source="pack://application:,,,/TensorStack.WPF;component/ThemeDefault.xaml" />
141+
</ResourceDictionary.MergedDictionaries>
142+
143+
</ResourceDictionary>
144+
145+
146+
</Application.Resources>
147+
</Application>

DemoApp/App.xaml.cs

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
using DemoApp.Services;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using Microsoft.Extensions.Hosting;
4+
using System;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Threading;
8+
using TensorStack.WPF;
9+
10+
namespace DemoApp
11+
{
12+
/// <summary>
13+
/// Interaction logic for App.xaml
14+
/// </summary>
15+
public partial class App : Application
16+
{
17+
private readonly IHost _appHost;
18+
19+
public App()
20+
{
21+
RegisterExceptionHandlers();
22+
23+
var builder = Host.CreateApplicationBuilder();
24+
25+
var configuration = Json.Load<Settings>("Settings.json");
26+
configuration.Initialize();
27+
28+
// Add WPFCommon
29+
builder.Services.AddWPFCommon<MainWindow, Settings>(configuration);
30+
31+
// Services
32+
builder.Services.AddSingleton<IMediaService, MediaService>();
33+
builder.Services.AddSingleton<IHistoryService, HistoryService>();
34+
builder.Services.AddSingleton<IUpscaleService, UpscaleService>();
35+
builder.Services.AddSingleton<IExtractorService, ExtractorService>();
36+
builder.Services.AddSingleton<IDiffusionService, DiffusionService>();
37+
builder.Services.AddSingleton<IDetectService, DetectService>();
38+
builder.Services.AddSingleton<ITextService, TextService>();
39+
builder.Services.AddSingleton<IInterpolationService, InterpolationService>();
40+
41+
_appHost = builder.Build();
42+
43+
// Initialize WPFCommon
44+
_appHost.Services.UseWPFCommon();
45+
}
46+
47+
48+
/// <summary>
49+
/// Application startup.
50+
/// </summary>
51+
/// <returns>Task.</returns>
52+
private Task AppStartup()
53+
{
54+
MainWindow = _appHost.Services.GetMainWindow();
55+
MainWindow.Show();
56+
return Task.CompletedTask;
57+
}
58+
59+
60+
/// <summary>
61+
/// Application shutdown.
62+
/// </summary>
63+
private async Task AppShutdown()
64+
{
65+
using (_appHost)
66+
{
67+
await _appHost.StopAsync();
68+
DeregisterExceptionHandlers();
69+
}
70+
}
71+
72+
73+
/// <summary>
74+
/// Raises the <see cref="E:System.Windows.Application.Startup" /> event.
75+
/// </summary>
76+
/// <param name="e">A <see cref="T:System.Windows.StartupEventArgs" /> that contains the event data.</param>
77+
protected override async void OnStartup(StartupEventArgs e)
78+
{
79+
var historyService = _appHost.Services.GetRequiredService<IHistoryService>();
80+
await historyService.InitializeAsync();
81+
await AppStartup();
82+
base.OnStartup(e);
83+
}
84+
85+
86+
/// <summary>
87+
/// Raises the <see cref="E:System.Windows.Application.SessionEnding" /> event.
88+
/// </summary>
89+
/// <param name="e">A <see cref="T:System.Windows.SessionEndingCancelEventArgs" /> that contains the event data.</param>
90+
protected override async void OnSessionEnding(SessionEndingCancelEventArgs e)
91+
{
92+
await AppShutdown();
93+
base.OnSessionEnding(e);
94+
}
95+
96+
97+
/// <summary>
98+
/// Raises the <see cref="E:System.Windows.Application.Exit" /> event.
99+
/// </summary>
100+
/// <param name="e">An <see cref="T:System.Windows.ExitEventArgs" /> that contains the event data.</param>
101+
protected async override void OnExit(ExitEventArgs e)
102+
{
103+
await AppShutdown();
104+
base.OnExit(e);
105+
}
106+
107+
108+
/// <summary>
109+
/// Registers the exception handlers.
110+
/// </summary>
111+
private void RegisterExceptionHandlers()
112+
{
113+
DispatcherUnhandledException += OnDispatcherException;
114+
AppDomain.CurrentDomain.UnhandledException += OnAppDomainException;
115+
TaskScheduler.UnobservedTaskException += OnTaskSchedulerException;
116+
}
117+
118+
119+
/// <summary>
120+
/// Deregisters the exception handlers.
121+
/// </summary>
122+
private void DeregisterExceptionHandlers()
123+
{
124+
DispatcherUnhandledException -= OnDispatcherException;
125+
AppDomain.CurrentDomain.UnhandledException -= OnAppDomainException;
126+
TaskScheduler.UnobservedTaskException -= OnTaskSchedulerException;
127+
}
128+
129+
130+
/// <summary>
131+
/// Handles the <see cref="E:DispatcherException" /> event.
132+
/// </summary>
133+
/// <param name="sender">The sender.</param>
134+
/// <param name="e">The <see cref="DispatcherUnhandledExceptionEventArgs"/> instance containing the event data.</param>
135+
private void OnDispatcherException(object sender, DispatcherUnhandledExceptionEventArgs e)
136+
{
137+
ShowExceptionMessage(e.Exception);
138+
139+
// Prevent application from crashing
140+
e.Handled = true;
141+
}
142+
143+
144+
/// <summary>
145+
/// Handles the <see cref="E:AppDomainException" /> event.
146+
/// </summary>
147+
/// <param name="sender">The sender.</param>
148+
/// <param name="e">The <see cref="UnhandledExceptionEventArgs"/> instance containing the event data.</param>
149+
private void OnAppDomainException(object sender, UnhandledExceptionEventArgs e)
150+
{
151+
if (e.ExceptionObject is Exception ex)
152+
{
153+
ShowExceptionMessage(ex);
154+
}
155+
}
156+
157+
158+
/// <summary>
159+
/// Handles the <see cref="E:TaskSchedulerException" /> event.
160+
/// </summary>
161+
/// <param name="sender">The sender.</param>
162+
/// <param name="e">The <see cref="UnobservedTaskExceptionEventArgs"/> instance containing the event data.</param>
163+
private void OnTaskSchedulerException(object sender, UnobservedTaskExceptionEventArgs e)
164+
{
165+
ShowExceptionMessage(e.Exception);
166+
167+
// Prevent application from crashing
168+
e.SetObserved();
169+
}
170+
171+
172+
private void ShowExceptionMessage(Exception ex)
173+
{
174+
MessageBox.Show($"An unexpected error occurred:\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
175+
}
176+
}
177+
178+
}

DemoApp/AssemblyInfo.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]

DemoApp/Common/DetectItem.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace DemoApp.Common
2+
{
3+
public class DetectItem : HistoryItem
4+
{
5+
public string Model { get; init; }
6+
public int Width { get; init; }
7+
public int Height { get; init; }
8+
}
9+
}

0 commit comments

Comments
 (0)