mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 21:16:30 +00:00
gallery manager WIP
This commit is contained in:
@@ -27,6 +27,7 @@ public partial class MainWindow
|
||||
private readonly IConfigRepository _configRepository;
|
||||
private readonly HelpWindow _helpWindow;
|
||||
private readonly ILogger<MainWindow> _logger;
|
||||
private CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
public ObservableCollection<AnnotationClass> AnnotationClasses { get; set; } = new();
|
||||
private bool _suspendLayout;
|
||||
@@ -34,6 +35,10 @@ public partial class MainWindow
|
||||
private readonly TimeSpan _thresholdBefore = TimeSpan.FromMilliseconds(100);
|
||||
private readonly TimeSpan _thresholdAfter = TimeSpan.FromMilliseconds(300);
|
||||
private readonly Config _config;
|
||||
private readonly DatasetExplorer _datasetExplorer;
|
||||
|
||||
private ObservableCollection<MediaFileInfo> AllMediaFiles { get; set; } = new();
|
||||
private ObservableCollection<MediaFileInfo> FilteredMediaFiles { get; set; } = new();
|
||||
|
||||
public IntervalTree<TimeSpan, List<YoloLabel>> Annotations { get; set; } = new();
|
||||
|
||||
@@ -42,6 +47,7 @@ public partial class MainWindow
|
||||
FormState formState,
|
||||
IConfigRepository configRepository,
|
||||
HelpWindow helpWindow,
|
||||
DatasetExplorer datasetExplorer,
|
||||
ILogger<MainWindow> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -52,6 +58,7 @@ public partial class MainWindow
|
||||
_configRepository = configRepository;
|
||||
_config = _configRepository.Get();
|
||||
_helpWindow = helpWindow;
|
||||
_datasetExplorer = datasetExplorer;
|
||||
_logger = logger;
|
||||
|
||||
VideoView.Loaded += VideoView_Loaded;
|
||||
@@ -115,12 +122,16 @@ public partial class MainWindow
|
||||
|
||||
_mediaPlayer.Playing += async (sender, args) =>
|
||||
{
|
||||
if (_formState.CurrentMrl == _mediaPlayer.Media?.Mrl)
|
||||
return; //already loaded all the info
|
||||
|
||||
_formState.CurrentMrl = _mediaPlayer.Media?.Mrl ?? "";
|
||||
uint vw = 0, vh = 0;
|
||||
_mediaPlayer.Size(0, ref vw, ref vh);
|
||||
_formState.CurrentVideoSize = new Size(vw, vh);
|
||||
_formState.CurrentVideoLength = TimeSpan.FromMilliseconds(_mediaPlayer.Length);
|
||||
|
||||
await Dispatcher.Invoke(async () => await ReloadAnnotations());
|
||||
await Dispatcher.Invoke(async () => await ReloadAnnotations(_cancellationTokenSource.Token));
|
||||
if (_formState.CurrentMedia?.MediaType != MediaTypes.Image)
|
||||
return;
|
||||
|
||||
@@ -195,7 +206,7 @@ public partial class MainWindow
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ReloadAnnotations()
|
||||
public async Task ReloadAnnotations(CancellationToken cancellationToken)
|
||||
{
|
||||
_formState.AnnotationResults.Clear();
|
||||
Annotations.Clear();
|
||||
@@ -211,12 +222,7 @@ public partial class MainWindow
|
||||
var name = Path.GetFileNameWithoutExtension(file.Name);
|
||||
var time = _formState.GetTime(name)!.Value;
|
||||
|
||||
var str = await File.ReadAllTextAsync(file.FullName);
|
||||
var annotations = str.Split(Environment.NewLine).Select(YoloLabel.Parse)
|
||||
.Where(ann => ann != null)
|
||||
.ToList();
|
||||
|
||||
await AddAnnotation(time, annotations!);
|
||||
await AddAnnotation(time, await YoloLabel.ReadFromFile(file.FullName, cancellationToken));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,11 +277,11 @@ public partial class MainWindow
|
||||
HasAnnotations = labelNames.ContainsKey(Path.GetFileNameWithoutExtension(x.Name).Replace(" ", ""))
|
||||
});
|
||||
|
||||
var mediaFiles = videoFiles.Concat(imageFiles).ToList();
|
||||
LvFiles.ItemsSource = new ObservableCollection<MediaFileInfo>(mediaFiles);
|
||||
AllMediaFiles = new ObservableCollection<MediaFileInfo>(videoFiles.Concat(imageFiles).ToList());
|
||||
LvFiles.ItemsSource = AllMediaFiles;
|
||||
TbFolder.Text = _config.VideosDirectory;
|
||||
|
||||
BlinkHelp(mediaFiles.Count == 0
|
||||
BlinkHelp(AllMediaFiles.Count == 0
|
||||
? HelpTexts.HelpTextsDict[HelpTextEnum.Initial]
|
||||
: HelpTexts.HelpTextsDict[HelpTextEnum.PlayVideo]);
|
||||
}
|
||||
@@ -296,9 +302,9 @@ public partial class MainWindow
|
||||
// AnnotationClasses.Add(new AnnotationClass(AnnotationClasses.Count));
|
||||
// LvClasses.SelectedIndex = AnnotationClasses.Count - 1;
|
||||
// }
|
||||
private void OpenFolderItemClick(object sender, RoutedEventArgs e) => OpenFolder();
|
||||
private void OpenFolderButtonClick(object sender, RoutedEventArgs e) => OpenFolder();
|
||||
private void OpenFolder()
|
||||
private async void OpenFolderItemClick(object sender, RoutedEventArgs e) => await OpenFolder();
|
||||
private async void OpenFolderButtonClick(object sender, RoutedEventArgs e) => await OpenFolder();
|
||||
private async Task OpenFolder()
|
||||
{
|
||||
var dlg = new CommonOpenFileDialog
|
||||
{
|
||||
@@ -309,11 +315,26 @@ public partial class MainWindow
|
||||
if (dlg.ShowDialog() != CommonFileDialogResult.Ok)
|
||||
return;
|
||||
|
||||
if (!string.IsNullOrEmpty(dlg.FileName))
|
||||
if (!string.IsNullOrEmpty(dlg.FileName))
|
||||
{
|
||||
_config.VideosDirectory = dlg.FileName;
|
||||
|
||||
await SaveUserSettings();
|
||||
}
|
||||
|
||||
ReloadFiles();
|
||||
}
|
||||
private void TbFilter_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
FilteredMediaFiles = new ObservableCollection<MediaFileInfo>(AllMediaFiles.Where(x => x.Name.ToLower().Contains(TbFilter.Text.ToLower())).ToList());
|
||||
LvFiles.ItemsSource = FilteredMediaFiles;
|
||||
}
|
||||
|
||||
private void OpenDataExplorerItemClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_datasetExplorer.Show();
|
||||
_datasetExplorer.Activate();
|
||||
}
|
||||
|
||||
|
||||
private void PlayClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
@@ -354,4 +375,3 @@ public partial class MainWindow
|
||||
|
||||
private void Thumb_OnDragCompleted(object sender, DragCompletedEventArgs e) => _ = SaveUserSettings();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user