Browse Source

Merge pull request #11 from ionite34/add-py-version-settings

pull/5/head
Ionite 2 years ago committed by GitHub
parent
commit
dea14188c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      StabilityMatrix/App.xaml.cs
  2. 1
      StabilityMatrix/MainWindow.xaml
  3. 12
      StabilityMatrix/MainWindow.xaml.cs
  4. 5
      StabilityMatrix/PyRunner.cs
  5. 8
      StabilityMatrix/SettingsPage.xaml
  6. 23
      StabilityMatrix/ViewModels/SettingsViewModel.cs

2
StabilityMatrix/App.xaml.cs

@ -6,6 +6,7 @@ using StabilityMatrix.Helper;
using StabilityMatrix.Services; using StabilityMatrix.Services;
using StabilityMatrix.ViewModels; using StabilityMatrix.ViewModels;
using Wpf.Ui.Contracts; using Wpf.Ui.Contracts;
using Wpf.Ui.Services;
namespace StabilityMatrix namespace StabilityMatrix
{ {
@ -24,6 +25,7 @@ namespace StabilityMatrix
serviceCollection.AddTransient<InstallPage>(); serviceCollection.AddTransient<InstallPage>();
serviceCollection.AddTransient<MainWindowViewModel>(); serviceCollection.AddTransient<MainWindowViewModel>();
serviceCollection.AddSingleton<SettingsViewModel>(); serviceCollection.AddSingleton<SettingsViewModel>();
serviceCollection.AddSingleton<IContentDialogService, ContentDialogService>();
serviceCollection.AddSingleton<ISettingsManager, SettingsManager>(); serviceCollection.AddSingleton<ISettingsManager, SettingsManager>();
serviceCollection.AddRefitClient<IGithubApi>(); serviceCollection.AddRefitClient<IGithubApi>();

1
StabilityMatrix/MainWindow.xaml

@ -60,5 +60,6 @@
Command="{Binding GoAdvancedModeCommand}" Command="{Binding GoAdvancedModeCommand}"
VerticalAlignment="Bottom" Margin="16" FontSize="14"/> VerticalAlignment="Bottom" Margin="16" FontSize="14"/>
</Grid> </Grid>
<ContentPresenter x:Name="RootContentDialog" Grid.Row="1" />
</Grid> </Grid>
</ui:FluentWindow> </ui:FluentWindow>

12
StabilityMatrix/MainWindow.xaml.cs

@ -2,6 +2,7 @@ using System.Diagnostics;
using System.Windows; using System.Windows;
using StabilityMatrix.ViewModels; using StabilityMatrix.ViewModels;
using Wpf.Ui.Contracts; using Wpf.Ui.Contracts;
using Wpf.Ui.Controls.Navigation;
using Wpf.Ui.Controls.Window; using Wpf.Ui.Controls.Window;
namespace StabilityMatrix namespace StabilityMatrix
@ -11,18 +12,27 @@ namespace StabilityMatrix
/// </summary> /// </summary>
public partial class MainWindow : FluentWindow public partial class MainWindow : FluentWindow
{ {
private readonly IPageService pageService;
private readonly ISettingsManager settingsManager;
private readonly IContentDialogService contentDialogService;
private readonly MainWindowViewModel mainWindowViewModel; private readonly MainWindowViewModel mainWindowViewModel;
public MainWindow(IPageService pageService, MainWindowViewModel mainWindowViewModel) public MainWindow(IPageService pageService, ISettingsManager settingsManager,
IContentDialogService contentDialogService, MainWindowViewModel mainWindowViewModel)
{ {
InitializeComponent(); InitializeComponent();
this.pageService = pageService;
this.settingsManager = settingsManager;
this.contentDialogService = contentDialogService;
this.mainWindowViewModel = mainWindowViewModel; this.mainWindowViewModel = mainWindowViewModel;
DataContext = mainWindowViewModel; DataContext = mainWindowViewModel;
RootNavigation.Navigating += (_, _) => Debug.WriteLine("Navigating"); RootNavigation.Navigating += (_, _) => Debug.WriteLine("Navigating");
RootNavigation.SetPageService(pageService); RootNavigation.SetPageService(pageService);
contentDialogService.SetContentPresenter(RootContentDialog);
} }
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)

5
StabilityMatrix/PyRunner.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -114,8 +115,8 @@ internal static class PyRunner
{ {
using (Py.GIL()) using (Py.GIL())
{ {
dynamic result = PythonEngine.Eval(code); var result = PythonEngine.Eval(code);
return result.ToString(); return result.ToString(CultureInfo.InvariantCulture);
} }
}); });
} }

8
StabilityMatrix/SettingsPage.xaml

@ -37,6 +37,14 @@
</StackPanel> </StackPanel>
</ui:Card> </ui:Card>
<ui:Card Margin="8">
<StackPanel Orientation="Vertical" HorizontalAlignment="Left">
<TextBlock Text="Embedded Python" FontWeight="Bold" FontSize="16" Margin="0,8" />
<!-- Add a button to show messagebox for python version -->
<Button Margin="8" Content="Check Version Info" Command="{Binding PythonVersionCommand}"/>
</StackPanel>
</ui:Card>
<ui:Card Margin="8"> <ui:Card Margin="8">
<StackPanel Orientation="Vertical" HorizontalAlignment="Left"> <StackPanel Orientation="Vertical" HorizontalAlignment="Left">
<TextBlock Text="Some Other Setting" FontWeight="Bold" FontSize="16" Margin="0,8" /> <TextBlock Text="Some Other Setting" FontWeight="Bold" FontSize="16" Margin="0,8" />

23
StabilityMatrix/ViewModels/SettingsViewModel.cs

@ -1,12 +1,16 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using StabilityMatrix.Helper; using StabilityMatrix.Helper;
using Wpf.Ui.Appearance; using Wpf.Ui.Appearance;
using Wpf.Ui.Contracts;
using Wpf.Ui.Controls.ContentDialogControl;
namespace StabilityMatrix.ViewModels; namespace StabilityMatrix.ViewModels;
@ -21,10 +25,12 @@ public partial class SettingsViewModel : ObservableObject
"System", "System",
}; };
private string selectedTheme; private string selectedTheme;
private readonly IContentDialogService contentDialogService;
public SettingsViewModel(ISettingsManager settingsManager) public SettingsViewModel(ISettingsManager settingsManager, IContentDialogService contentDialogService)
{ {
this.settingsManager = settingsManager; this.settingsManager = settingsManager;
this.contentDialogService = contentDialogService;
SelectedTheme = settingsManager.Settings.Theme; SelectedTheme = settingsManager.Settings.Theme;
} }
@ -61,6 +67,19 @@ public partial class SettingsViewModel : ObservableObject
[ObservableProperty] [ObservableProperty]
public string testProperty; public string testProperty;
public AsyncRelayCommand PythonVersionCommand => new(async () =>
{
// Get python version
await PyRunner.Initialize();
var result = await PyRunner.Eval("str(__import__('sys').version_info)");
// Show dialog box
var dialog = contentDialogService.CreateDialog();
dialog.Title = "Python version info";
dialog.Content = result;
dialog.PrimaryButtonText = "Ok";
await dialog.ShowAsync();
});
public async Task OnLoaded() public async Task OnLoaded()
{ {
SelectedTheme = string.IsNullOrWhiteSpace(settingsManager.Settings.Theme) SelectedTheme = string.IsNullOrWhiteSpace(settingsManager.Settings.Theme)

Loading…
Cancel
Save