Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add tutorial menu #315

Merged
merged 10 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build-component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ jobs:
cp ./PYTHON_PACKAGE_LICENSES ./Release/PYTHON_PACKAGE_LICENSES.txt
cp ./Tunny/bin/Debug/net48 ./Release/Tunny -recurse
cp ./TT-DesignExplorer/server/bin/Debug/net48/TT-DesignExplorer.zip ./Release/Tunny/Lib/TT-DesignExplorer.zip
cp ./Examples ./Release/Tunny/Examples -recurse

- name: Upload release build of plugin as artefact
uses: actions/upload-artifact@v4
with:
name: Tunny
path: |
./Release
retention-days: 7
retention-days: 1
compression-level: 9
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"dotnet.defaultSolution": "Tunny.sln",
"cSpell.words": [
"HITL",
"hovertemplate",
"showlegend",
"yaxis",
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Please see [here](https://github.com/hrntsm/Tunny/releases) for the data release

### Added

for new features.
- Feature to open tutorial files in the menu.

### Changed

Expand Down
3 changes: 2 additions & 1 deletion Tunny.Core/Util/TEnvVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ namespace Tunny.Core.Util
public static class TEnvVariables
{
public static Version Version { get; } = Assembly.GetExecutingAssembly().GetName().Version;
public static string DefaultStoragePath { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "fish.log");
public static string TunnyEnvPath { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".tunny_env");
public static string LogPath { get; } = Path.Combine(TunnyEnvPath, "logs");
public static string DesignExplorerPath { get; } = Path.Combine(TunnyEnvPath, "TT-DesignExplorer");
public static string OptimizeSettingsPath { get; } = Path.Combine(TunnyEnvPath, "settings.json");
public static string DefaultStoragePath { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "fish.log");
public static string PythonPath { get; } = Path.Combine(TunnyEnvPath, "python");
public static string ComponentFolder { get; } = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
public static string ExampleDirPath { get; } = Path.Combine(ComponentFolder, "Examples", "Grasshopper");
public static Version OldStorageVersion { get; } = new Version("0.9.1");
public static IntPtr GrasshopperWindowHandle { get; set; }

Expand Down
76 changes: 68 additions & 8 deletions Tunny/UI/LoadingInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
{
public class LoadingInstruction : GH_AssemblyPriority, IDisposable
{
private ToolStripMenuItem _tutorialStripMenuItem;
private ToolStripMenuItem _tunnyHelpStripMenuItem;
private ToolStripMenuItem _optunaDashboardToolStripMenuItem;
private ToolStripMenuItem _pythonInstallStripMenuItem;
private ToolStripMenuItem _ttDesignExplorerToolStripMenuItem;
private ToolStripMenuItem _aboutTunnyStripMenuItem;

public override GH_LoadingInstruction PriorityLoad()
{
Expand Down Expand Up @@ -72,20 +75,64 @@
private void AddTunnyMenuItems(ToolStripItemCollection dropDownItems)
{
TLog.MethodStart();
_tunnyHelpStripMenuItem = new ToolStripMenuItem("Help", null, TunnyHelpStripMenuItem_Click, "TunnyHelpStripMenuItem");
_optunaDashboardToolStripMenuItem = new ToolStripMenuItem("Run optuna-dashboard...", Resource.optuna_dashboard, OptunaDashboardToolStripMenuItem_Click, "OptunaDashboardToolStripMenuItem");
_tunnyHelpStripMenuItem = new ToolStripMenuItem("Help", null, null, "TunnyHelpStripMenuItem");
_tutorialStripMenuItem = new ToolStripMenuItem("Tutorial Files", null, null, "TutorialStripMenuItem");
_optunaDashboardToolStripMenuItem = new ToolStripMenuItem("Run Optuna Dashboard...", Resource.optuna_dashboard, OptunaDashboardToolStripMenuItem_Click, "OptunaDashboardToolStripMenuItem");
_pythonInstallStripMenuItem = new ToolStripMenuItem("Install Python...", null, PythonInstallStripMenuItem_Click, "PythonInstallStripMenuItem");
var ttDesignExplorerToolStripMenuItem = new ToolStripMenuItem("Run TT DesignExplorer...", Resource.TTDesignExplorer, TTDesignExplorerToolStripMenuItem_Click, "TTDesignExplorerToolStripMenuItem");
var aboutTunnyStripMenuItem = new ToolStripMenuItem("About...", Resource.TunnyIcon, AboutTunnyStripMenuItem_Click, "AboutTunnyStripMenuItem");
_ttDesignExplorerToolStripMenuItem = new ToolStripMenuItem("Run TT DesignExplorer...", Resource.TTDesignExplorer, TTDesignExplorerToolStripMenuItem_Click, "TTDesignExplorerToolStripMenuItem");
_aboutTunnyStripMenuItem = new ToolStripMenuItem("About...", Resource.TunnyIcon, AboutTunnyStripMenuItem_Click, "AboutTunnyStripMenuItem");

SetHelpDropDownItems();
SetTutorialDropDownItems();

dropDownItems.AddRange(new ToolStripItem[] {
_tunnyHelpStripMenuItem,
_tutorialStripMenuItem,
new ToolStripSeparator(),
_optunaDashboardToolStripMenuItem,
ttDesignExplorerToolStripMenuItem,
_ttDesignExplorerToolStripMenuItem,
new ToolStripSeparator(),
_pythonInstallStripMenuItem,
new ToolStripSeparator(),
aboutTunnyStripMenuItem
_aboutTunnyStripMenuItem
});
}

private void SetTutorialDropDownItems()
{
TLog.MethodStart();
var optExample = new ToolStripMenuItem("Optimization", null, null, "TutorialOptimizationStripMenuItem");
var hitlExample = new ToolStripMenuItem("Human-in-the-loop", null, null, "TutorialHITLStripMenuItem");
string[] optFiles = Directory.GetFiles(Path.Combine(TEnvVariables.ExampleDirPath, "Optimization"), "*.gh");
string[] hitlFiles = Directory.GetFiles(Path.Combine(TEnvVariables.ExampleDirPath, "Human-in-the-loop"), "*.gh");

SetMenuItemsFromFilePath(optExample, optFiles);
SetMenuItemsFromFilePath(hitlExample, hitlFiles);

_tutorialStripMenuItem.DropDownItems.AddRange(new[] { optExample, hitlExample });
}

private static void SetMenuItemsFromFilePath(ToolStripMenuItem menuItem, string[] filePaths)
{
TLog.MethodStart();
for (int i = 0; i < filePaths.Length; i++)
{
string file = filePaths[i];
string fileName = Path.GetFileNameWithoutExtension(file);
var optItem = new ToolStripMenuItem("0" + i + " " + fileName, null, (sender, e) =>

Check notice on line 122 in Tunny/UI/LoadingInstruction.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Tunny/UI/LoadingInstruction.cs#L122

'sender' is not used. Use discard parameter instead.
{
Grasshopper.Instances.DocumentServer.AddDocument(file, makeActive: true);
}, fileName);
menuItem.DropDownItems.Add(optItem);
}
}

private void SetHelpDropDownItems()
{
TLog.MethodStart();
_tunnyHelpStripMenuItem.DropDownItems.AddRange(new[]{
new ToolStripMenuItem("Tunny Document", null, TunnyDocumentPageStripMenuItem_Click, "TunnyDocumentStripMenuItem"),
new ToolStripMenuItem("Optuna Sampler Document", null, OptunaSamplerPageStripMenuItem_Click, "OptunaTutorialStripMenuItem")
});
}

Expand Down Expand Up @@ -125,16 +172,26 @@
settings.Serialize(TEnvVariables.OptimizeSettingsPath);
}

private void TunnyHelpStripMenuItem_Click(object sender, EventArgs e)
private void TunnyDocumentPageStripMenuItem_Click(object sender, EventArgs e)
{
TLog.MethodStart();
TLog.Debug("TunnyHelpStripMenuItem Clicked");
TLog.Debug("TunnyDocumentPageStripMenuItem Clicked");
var browser = new Process();
browser.StartInfo.FileName = $@"https://tunny-docs.deno.dev/";
browser.StartInfo.UseShellExecute = true;
browser.Start();
}

private void OptunaSamplerPageStripMenuItem_Click(object sender, EventArgs e)
{
TLog.MethodStart();
TLog.Debug("OptunaSamplerPageStripMenuItem Clicked");
var browser = new Process();
browser.StartInfo.FileName = $@"https://optuna.readthedocs.io/en/stable/reference/samplers/index.html";
browser.StartInfo.UseShellExecute = true;
browser.Start();
}

private void OptunaDashboardToolStripMenuItem_Click(object sender, EventArgs e)
{
TLog.MethodStart();
Expand Down Expand Up @@ -211,8 +268,11 @@
{
TLog.MethodStart();
_tunnyHelpStripMenuItem.Dispose();
_tutorialStripMenuItem.Dispose();
_optunaDashboardToolStripMenuItem.Dispose();
_pythonInstallStripMenuItem.Dispose();
_ttDesignExplorerToolStripMenuItem.Dispose();
_aboutTunnyStripMenuItem.Dispose();
GC.SuppressFinalize(this);
}
}
Expand Down
Loading