Skip to content

Commit

Permalink
Create DataTemplate for Weights, ToolTip looks good, but general info…
Browse files Browse the repository at this point in the history
… is a mess;

DataTemplate stored in App.xaml because i didnt found the way to store it in separate file, as it can be stored in dictionary, but resources in dictionary must have x:Key, which isn't suitable
  • Loading branch information
Neakita committed Sep 28, 2023
1 parent a0f7608 commit 6e5ab30
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 8 deletions.
57 changes: 56 additions & 1 deletion SightKeeper.Avalonia/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
x:Class="SightKeeper.Avalonia.App"
xmlns:materialIcons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
xmlns:local="clr-namespace:SightKeeper.Avalonia"
xmlns:model="clr-namespace:SightKeeper.Domain.Model;assembly=SightKeeper.Domain.Model"
RequestedThemeVariant="Dark">

<Application.Resources>
Expand All @@ -20,9 +21,63 @@
<materialIcons:MaterialIconStyles />
<StyleInclude Source="avares://SightKeeper.Avalonia/Assets/Styles.axaml"/>
</Application.Styles>

<Application.DataTemplates>
<local:ViewLocator/>
<DataTemplate DataType="model:Weights">
<Panel Background="Transparent">
<TextBlock>
<Run Text="{Binding CreationDate, StringFormat=d}"/>
<Run Text="|"
Foreground="DarkGray"/>
<Run Text="{Binding Size}"/>
<Run Text="|"
Foreground="DarkGray"/>
<Run Text="{Binding Epoch}"/>
<LineBreak/>
<Run Text="{Binding BoundingLoss, StringFormat=0.##}"/>
<Run Text="|"
Foreground="DarkGray"/>
<Run Text="{Binding ClassificationLoss, StringFormat=0.##}"/>
<Run Text="|"
Foreground="DarkGray"/>
<Run Text="{Binding DeformationLoss, StringFormat=0.##}"/>
</TextBlock>
<ToolTip.Tip>
<TextBlock>
<Run Text="Creation date:"
Foreground="DarkGray"/>
<Run Text="{Binding CreationDate, StringFormat=F}"/>
<LineBreak/>
<Run Text="Size:"
Foreground="DarkGray"/>
<Run Text="{Binding Size}"/>
<LineBreak/>
<Run Text="Epoch:"
Foreground="DarkGray"/>
<Run Text="{Binding Epoch}"/>
<LineBreak/>
<Run Text="Losses:"
Foreground="DarkGray"/>
<LineBreak/>
<Run Text=" "/>
<Run Text="Bounding"
Foreground="DarkGray"/>
<Run Text="{Binding BoundingLoss, StringFormat=0.##}"/>
<LineBreak/>
<Run Text=" "/>
<Run Text="Classification"
Foreground="DarkGray"/>
<Run Text="{Binding ClassificationLoss, StringFormat=0.##}"/>
<LineBreak/>
<Run Text=" "/>
<Run Text="Deformation"
Foreground="DarkGray"/>
<Run Text="{Binding DeformationLoss, StringFormat=0.##}"/>
</TextBlock>
</ToolTip.Tip>
</Panel>
</DataTemplate>
</Application.DataTemplates>

</Application>
1 change: 1 addition & 0 deletions SightKeeper.Avalonia/AppBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using SightKeeper.Application.Training;
using SightKeeper.Avalonia.Misc;
using SightKeeper.Avalonia.ViewModels.Annotating;
using SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating;
using SightKeeper.Avalonia.ViewModels.Dialogs;
using SightKeeper.Avalonia.ViewModels.Dialogs.DataSet;
using SightKeeper.Avalonia.ViewModels.Elements;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Reactive.Disposables;
using SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating;
using SightKeeper.Avalonia.ViewModels.Elements;
using SightKeeper.Commons;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using CommunityToolkit.Diagnostics;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
Expand All @@ -11,9 +12,9 @@
using SightKeeper.Domain.Model;
using SightKeeper.Domain.Model.Detector;

namespace SightKeeper.Avalonia.ViewModels.Annotating;
namespace SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating;

public sealed partial class AutoAnnotationViewModel : ViewModel
public sealed partial class AutoAnnotationViewModel : ViewModel, IAutoAnnotationViewModel
{
public IReadOnlyCollection<Weights> Weights => _selectedDataSetViewModel.Weights;

Expand Down Expand Up @@ -62,6 +63,7 @@ public AutoAnnotationViewModel(Detector detector, SelectedScreenshotViewModel se
private readonly SelectedScreenshotViewModel _selectedScreenshotViewModel;
private readonly SelectedDataSetViewModel _selectedDataSetViewModel;

ICommand IAutoAnnotationViewModel.AnnotateCommand => AnnotateCommand;
[RelayCommand(CanExecute = nameof(CanAnnotate))]
private async Task Annotate(CancellationToken cancellationToken)
{
Expand All @@ -74,7 +76,8 @@ private async Task Annotate(CancellationToken cancellationToken)
ClearCommand.NotifyCanExecuteChanged();
}
private bool CanAnnotate() => SelectedWeights != null && _selectedScreenshotViewModel.Value != null && !AutoAnnotatingEnabled;


ICommand IAutoAnnotationViewModel.ClearCommand => ClearCommand;
[RelayCommand(CanExecute = nameof(CanClear))]
private void Clear()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using SightKeeper.Domain.Model;
using SightKeeper.Domain.Model.Common;

namespace SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating;

public sealed class FakeAutoAnnotationViewModel : IAutoAnnotationViewModel
{
public IReadOnlyCollection<Weights> Weights { get; }
public float ProbabilityThreshold { get; set; }
public float IoU { get; set; }
public Weights? SelectedWeights { get; set; }
public bool AutoAnnotatingEnabled { get; set; }
public ICommand ClearCommand => FakeViewModel.CommandSubstitute;
public ICommand AnnotateCommand => FakeViewModel.CommandSubstitute;

public FakeAutoAnnotationViewModel()
{
DataSet dataSet = new("");
dataSet.WeightsLibrary.CreateWeights(Array.Empty<byte>(), Array.Empty<byte>(), ModelSize.Nano, 100, 1.123f, 0.2345f, 2.3456f, Enumerable.Empty<Asset>());
dataSet.WeightsLibrary.CreateWeights(Array.Empty<byte>(), Array.Empty<byte>(), ModelSize.Small, 200, 0.623f, 0.6445f, 0.3646f, Enumerable.Empty<Asset>());
Weights = dataSet.WeightsLibrary.Weights;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using System.Windows.Input;
using SightKeeper.Domain.Model;

namespace SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating;

public interface IAutoAnnotationViewModel
{
IReadOnlyCollection<Weights> Weights { get; }
float ProbabilityThreshold { get; set; }
float IoU { get; set; }
Weights? SelectedWeights { get; set; }
bool AutoAnnotatingEnabled { get; set; }

ICommand ClearCommand { get; }
ICommand AnnotateCommand { get; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using NSubstitute;
using SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating;
using SightKeeper.Avalonia.ViewModels.Elements;
using SightKeeper.Domain.Model;
using SightKeeper.Domain.Services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating;
using SightKeeper.Avalonia.ViewModels.Elements;

namespace SightKeeper.Avalonia.ViewModels.Annotating;
Expand Down
9 changes: 6 additions & 3 deletions SightKeeper.Avalonia/Views/Annotating/AutoAnnotation.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:annotatingViewModels="clr-namespace:SightKeeper.Avalonia.ViewModels.Annotating"
xmlns:icons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
xmlns:autoAnnotatingViewModels="clr-namespace:SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating"
mc:Ignorable="d" d:DesignWidth="250"
x:Class="SightKeeper.Avalonia.Views.Annotating.AutoAnnotation"
x:DataType="annotatingViewModels:AutoAnnotationViewModel">
x:DataType="autoAnnotatingViewModels:IAutoAnnotationViewModel">
<Design.DataContext>
<autoAnnotatingViewModels:FakeAutoAnnotationViewModel/>
</Design.DataContext>
<StackPanel>
<ComboBox ItemsSource="{Binding Weights}"
SelectedItem="{Binding SelectedWeights}"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Avalonia.ReactiveUI;
using SightKeeper.Avalonia.ViewModels.Annotating;
using SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating;

namespace SightKeeper.Avalonia.Views.Annotating;

Expand Down

0 comments on commit 6e5ab30

Please sign in to comment.