mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 23:46:30 +00:00
reuse VirtualizingWrapPanel for display Dataset Explorer
This commit is contained in:
@@ -1,30 +1,55 @@
|
||||
using System.Windows;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using Azaion.Annotator.DTO;
|
||||
|
||||
namespace Azaion.Annotator;
|
||||
|
||||
public partial class DatasetExplorer : Window
|
||||
public partial class DatasetExplorer
|
||||
{
|
||||
private CancellationTokenSource _cancellationTokenSource;
|
||||
private readonly Config _config;
|
||||
|
||||
public DatasetExplorer(IGalleryManager galleryManager)
|
||||
public ObservableCollection<ThumbnailDto> ThumbnailsDtos { get; set; } = new();
|
||||
|
||||
public DatasetExplorer(Config config)
|
||||
{
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
_config = config;
|
||||
|
||||
InitializeComponent();
|
||||
Loaded += (sender, args) =>
|
||||
{
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
while (!_cancellationTokenSource.Token.IsCancellationRequested)
|
||||
{
|
||||
await galleryManager.RefreshThumbnails(_cancellationTokenSource.Token);
|
||||
await Task.Delay(30000, _cancellationTokenSource.Token);
|
||||
}
|
||||
});
|
||||
};
|
||||
DataContext = this;
|
||||
Loaded += async (sender, args) => await LoadThumbnails();
|
||||
|
||||
Closing += (sender, args) => _cancellationTokenSource.Cancel();
|
||||
Closing += (sender, args) =>
|
||||
{
|
||||
args.Cancel = true;
|
||||
Visibility = Visibility.Hidden;
|
||||
};
|
||||
}
|
||||
|
||||
private async Task LoadThumbnails()
|
||||
{
|
||||
if (!Directory.Exists(_config.ThumbnailsDirectory))
|
||||
return;
|
||||
|
||||
var thumbnails = Directory.GetFiles(_config.ThumbnailsDirectory, "*.jpg");
|
||||
|
||||
foreach (var thumbnail in thumbnails)
|
||||
{
|
||||
var name = Path.GetFileNameWithoutExtension(thumbnail)[..^Config.ThumbnailPrefix.Length];
|
||||
var imageName = Path.Combine(_config.ImagesDirectory, name);
|
||||
foreach (var imageFormat in _config.ImageFormats)
|
||||
{
|
||||
imageName = $"{imageName}.{imageFormat}";
|
||||
if (File.Exists(imageName))
|
||||
break;
|
||||
}
|
||||
|
||||
ThumbnailsDtos.Add(new ThumbnailDto
|
||||
{
|
||||
ThumbnailPath = thumbnail,
|
||||
ImagePath = imageName,
|
||||
LabelPath = Path.Combine(_config.LabelsDirectory, $"{name}.txt"),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user