Skip to content

Commit

Permalink
Merge branch 'master' into AAA_ForSesame
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianCollinss committed Aug 11, 2024
2 parents 6343c5c + 51ef9bf commit 8a2ca0d
Show file tree
Hide file tree
Showing 113 changed files with 449 additions and 201 deletions.
5 changes: 4 additions & 1 deletion ApsimNG/Presenters/CLEM/ActivityLedgerGridPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ public void Attach(object model, object view, ExplorerPresenter explorerPresente
public void Refresh()
{
// now get report model to create data as we need to generate the HTML report independent of ApsimNG
Grid.DataSource = (ModelReport as ReportActivitiesPerformed).CreateDataTable(dataStore, Path.GetDirectoryName(this.explorerPresenter.ApsimXFile.FileName), Utility.Configuration.Settings.DarkTheme);
Grid.DataSource = !Utility.Configuration.Settings.ThemeRestartRequired ?
(ModelReport as ReportActivitiesPerformed).CreateDataTable(dataStore, Path.GetDirectoryName(this.explorerPresenter.ApsimXFile.FileName), Utility.Configuration.Settings.DarkTheme) :
(ModelReport as ReportActivitiesPerformed).CreateDataTable(dataStore, Path.GetDirectoryName(this.explorerPresenter.ApsimXFile.FileName), !Utility.Configuration.Settings.DarkTheme);

this.Grid.LockLeftMostColumns(1); // lock activity name.
}

Expand Down
60 changes: 38 additions & 22 deletions ApsimNG/Presenters/CLEM/LabourAllocationPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,32 +125,13 @@ private string CreateHTML()

// Start building table
// apply theme based settings
if (!Utility.Configuration.Settings.DarkTheme)
if (!Utility.Configuration.Settings.ThemeRestartRequired)
{
// light theme
htmlString = htmlString.Replace("[FontColor]", "#000000");
htmlString = htmlString.Replace("[GridColor]", "Black");
htmlString = htmlString.Replace("[WarningBackground]", "#FFFFFA");
htmlString = htmlString.Replace("[MessageBackground]", "#FAFAFF");
htmlString = htmlString.Replace("[DisabledColour]", "#cccccc");
htmlString = htmlString.Replace("[TableBackground]", "background-color: white;");
htmlString = htmlString.Replace("[ContDefaultBack]", "#FAFAFA");
htmlString = htmlString.Replace("[ContDefaultBanner]", "#000");
htmlString = htmlString.Replace("[HeaderFontColor]", "white");

htmlString = !Utility.Configuration.Settings.DarkTheme ? ModifyHTMLStyle(htmlString, false) : ModifyHTMLStyle(htmlString, true);
}
else
{
// dark theme
htmlString = htmlString.Replace("[FontColor]", "#E5E5E5");
htmlString = htmlString.Replace("[GridColor]", "#888");
htmlString = htmlString.Replace("[WarningBackground]", "rgba(255, 102, 0, 0.4)");
htmlString = htmlString.Replace("[MessageBackground]", "rgba(100, 149, 237, 0.4)");
htmlString = htmlString.Replace("[DisabledColour]", "#666666");
htmlString = htmlString.Replace("[TableBackground]", "background-color: rgba(50, 50, 50, 0.5);");
htmlString = htmlString.Replace("[ContDefaultBack]", "#282828");
htmlString = htmlString.Replace("[ContDefaultBanner]", "#686868");
htmlString = htmlString.Replace("[HeaderFontColor]", "#333333");
htmlString = !Utility.Configuration.Settings.DarkTheme ? ModifyHTMLStyle(htmlString, true) : ModifyHTMLStyle(htmlString, false);
}

// get CLEM Zone
Expand Down Expand Up @@ -276,6 +257,8 @@ private string CreateHTML()
}
}



private string TableRowHTML(IModel model)
{
// create row
Expand Down Expand Up @@ -515,5 +498,38 @@ public void Detach()
{
}

private static string ModifyHTMLStyle(string htmlString, bool isDarkMode )
{
string reformattedHTML = htmlString;
if ( isDarkMode )
{
// dark theme
reformattedHTML = reformattedHTML.Replace("[FontColor]", "#E5E5E5");
reformattedHTML = reformattedHTML.Replace("[GridColor]", "#888");
reformattedHTML = reformattedHTML.Replace("[WarningBackground]", "rgba(255, 102, 0, 0.4)");
reformattedHTML = reformattedHTML.Replace("[MessageBackground]", "rgba(100, 149, 237, 0.4)");
reformattedHTML = reformattedHTML.Replace("[DisabledColour]", "#666666");
reformattedHTML = reformattedHTML.Replace("[TableBackground]", "background-color: rgba(50, 50, 50, 0.5);");
reformattedHTML = reformattedHTML.Replace("[ContDefaultBack]", "#282828");
reformattedHTML = reformattedHTML.Replace("[ContDefaultBanner]", "#686868");
reformattedHTML = reformattedHTML.Replace("[HeaderFontColor]", "#333333");
}
else
{
// light theme
reformattedHTML = reformattedHTML.Replace("[FontColor]", "#000000");
reformattedHTML = reformattedHTML.Replace("[GridColor]", "Black");
reformattedHTML = reformattedHTML.Replace("[WarningBackground]", "#FFFFFA");
reformattedHTML = reformattedHTML.Replace("[MessageBackground]", "#FAFAFF");
reformattedHTML = reformattedHTML.Replace("[DisabledColour]", "#cccccc");
reformattedHTML = reformattedHTML.Replace("[TableBackground]", "background-color: white;");
reformattedHTML = reformattedHTML.Replace("[ContDefaultBack]", "#FAFAFA");
reformattedHTML = reformattedHTML.Replace("[ContDefaultBanner]", "#000");
reformattedHTML = reformattedHTML.Replace("[HeaderFontColor]", "white");
}

return reformattedHTML;
}

}
}
57 changes: 36 additions & 21 deletions ApsimNG/Presenters/CLEM/MessagePresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,31 +246,13 @@ private string CreateHTML()
"\n</style>\n</head>\n<body>";

// apply theme based settings
if (!Utility.Configuration.Settings.DarkTheme)
if (!Utility.Configuration.Settings.ThemeRestartRequired)
{
// light theme
htmlString = htmlString.Replace("[FontColor]", "#000000");

htmlString = htmlString.Replace("[ContError]", "#FFFAFA");
htmlString = htmlString.Replace("[ContWarn]", "#FFFFFA");
htmlString = htmlString.Replace("[ContMessage]", "#FAFAFF");
htmlString = htmlString.Replace("[ContOK]", "#FAFFFF");
// values
htmlString = htmlString.Replace("[ValueSetBack]", "#e8fbfc");
htmlString = htmlString.Replace("[ValueSetFont]", "#000000");
htmlString = !Utility.Configuration.Settings.DarkTheme ? ModifyHTMLStyle(htmlString, false) : ModifyHTMLStyle(htmlString, true);
}
else
{
// dark theme
htmlString = htmlString.Replace("[FontColor]", "#E5E5E5");

htmlString = htmlString.Replace("[ContError]", "#490000");
htmlString = htmlString.Replace("[ContWarn]", "#A35D00");
htmlString = htmlString.Replace("[ContMessage]", "#030028");
htmlString = htmlString.Replace("[ContOK]", "#0C440C");
// values
htmlString = htmlString.Replace("[ValueSetBack]", "#49adc4");
htmlString = htmlString.Replace("[ValueSetFont]", "#0e2023");
htmlString = !Utility.Configuration.Settings.DarkTheme ? ModifyHTMLStyle(htmlString, true) : ModifyHTMLStyle(htmlString, false);

}

Expand Down Expand Up @@ -442,5 +424,38 @@ public void Detach()
{
}

private static string ModifyHTMLStyle(string htmlString, bool isDarkMode )
{
string reformattedHTML = htmlString;
if ( isDarkMode )
{
// dark theme
reformattedHTML = reformattedHTML.Replace("[FontColor]", "#E5E5E5");

reformattedHTML = reformattedHTML.Replace("[ContError]", "#490000");
reformattedHTML = reformattedHTML.Replace("[ContWarn]", "#A35D00");
reformattedHTML = reformattedHTML.Replace("[ContMessage]", "#030028");
reformattedHTML = reformattedHTML.Replace("[ContOK]", "#0C440C");
// values
reformattedHTML = reformattedHTML.Replace("[ValueSetBack]", "#49adc4");
reformattedHTML = reformattedHTML.Replace("[ValueSetFont]", "#0e2023");
}
else
{
// light theme
reformattedHTML = reformattedHTML.Replace("[FontColor]", "#000000");

reformattedHTML = reformattedHTML.Replace("[ContError]", "#FFFAFA");
reformattedHTML = reformattedHTML.Replace("[ContWarn]", "#FFFFFA");
reformattedHTML = reformattedHTML.Replace("[ContMessage]", "#FAFAFF");
reformattedHTML = reformattedHTML.Replace("[ContOK]", "#FAFFFF");
// values
reformattedHTML = reformattedHTML.Replace("[ValueSetBack]", "#e8fbfc");
reformattedHTML = reformattedHTML.Replace("[ValueSetFont]", "#000000");
}

return reformattedHTML;
}

}
}
16 changes: 3 additions & 13 deletions ApsimNG/Presenters/GraphPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private void DrawOnView(SeriesDefinition definition)
{
try
{
System.Drawing.Color colour = GetColour(definition.Colour);
System.Drawing.Color colour = definition.Colour;

// Create the series and populate it with data.
if (definition.Type == SeriesType.Bar)
Expand Down Expand Up @@ -431,16 +431,6 @@ private void DrawOnView(SeriesDefinition definition)
}
}

private System.Drawing.Color GetColour(System.Drawing.Color colour)
{
// If dark theme is active, and colour is black, use white instead.
// This won't help at all if the colour is a dark grey.
if (Utility.Configuration.Settings.DarkTheme && colour.R == 0 && colour.G == 0 && colour.B == 0)
return System.Drawing.Color.White;

return colour;
}

/// <summary>Draws the specified series definition on the view.</summary>
/// <param name="annotations">The list of annotations</param>
private void DrawOnView(IEnumerable<IAnnotation> annotations)
Expand Down Expand Up @@ -506,7 +496,7 @@ private void DrawOnView(IEnumerable<IAnnotation> annotations)
textAnnotation.textRotation,
AxisPosition.Bottom,
AxisPosition.Left,
GetColour(textAnnotation.colour));
textAnnotation.colour);
}
else if (annotation is LineAnnotation lineAnnotation)
{
Expand All @@ -517,7 +507,7 @@ private void DrawOnView(IEnumerable<IAnnotation> annotations)
lineAnnotation.y2,
lineAnnotation.type,
lineAnnotation.thickness,
GetColour(lineAnnotation.colour),
lineAnnotation.colour,
lineAnnotation.InFrontOfSeries,
lineAnnotation.ToolTip);
}
Expand Down
3 changes: 3 additions & 0 deletions ApsimNG/Utility/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class Configuration
/// <summary>The configuration file</summary>
private string configurationFile = null;

public bool ThemeRestartRequired = false;

/// <summary>The location for the form</summary>
public Point MainFormLocation { get; set; }

Expand Down Expand Up @@ -374,6 +376,7 @@ private void OnDarkThemeToggled()
{

EditorStyleName = DarkTheme ? "Adwaita-dark" : "Adwaita";
ThemeRestartRequired = !ThemeRestartRequired;

}
}
Expand Down
7 changes: 6 additions & 1 deletion ApsimNG/Utility/ConfigurationConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ public static Configuration DoConvert(string fileName)

XmlSerializer serializer = new XmlSerializer(typeof(Configuration), typeof(Configuration).GetNestedTypes());
using (XmlReader reader = new XmlNodeReader(document))
return serializer.Deserialize(reader) as Configuration;
{
Configuration configurationSettings = serializer.Deserialize(reader) as Configuration;
// reset to false as this should be false at the beginning of every APSIM launch.
configurationSettings.ThemeRestartRequired = false;
return configurationSettings;
}
}

/// <summary>
Expand Down
28 changes: 28 additions & 0 deletions ApsimNG/Utility/SettingsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace UserInterface.Views
/// </summary>
public class SettingsDialog : Dialog
{
private Window parentWindow = null;
private PropertyView propertyEditor;
Dictionary<Guid, PropertyInfo> properties = new Dictionary<Guid, PropertyInfo>();
List<KeyValuePair<PropertyInfo, object>> pendingChanges = new List<KeyValuePair<PropertyInfo, object>>();
Expand All @@ -38,6 +39,7 @@ public SettingsDialog(Window parent) : base("Settings",
box = ContentArea;

box.PackStart(propertyEditor.MainWidget, true, true, 0);
parentWindow = parent;
propertyEditor.MainWidget.ShowAll();
propertyEditor.PropertyChanged += OnPropertyChanged;
Refresh();
Expand Down Expand Up @@ -143,6 +145,32 @@ private void ApplyChange(PropertyInfo property, object newValue)
if (newValue != null && newValue.GetType() != property.PropertyType)
newValue = ReflectionUtilities.StringToObject(property.PropertyType, newValue.ToString(), CultureInfo.CurrentCulture);
property.SetValue(Configuration.Settings, newValue);
if (property.Name.Equals("DarkTheme"))
{
ShowMsgDialog("Theme will be applied on next restart.",
"Restart Required",
Gtk.MessageType.Info,
ButtonsType.Ok,
parentWindow);
}
}

/// <summary>Show a message in a dialog box</summary>
/// <param name="message">The message.</param>
/// <param name="title">Title of the dialog.</param>
/// <param name="msgType">Message type (info, warning, error, ...).</param>
/// <param name="buttonType">Type of buttons to be shown in the dialog.</param>
/// <param name="errorLevel">The error level.</param>
/// <param name="masterWindow">The main window.</param>
public int ShowMsgDialog(string message, string title, Gtk.MessageType msgType, Gtk.ButtonsType buttonType, Window masterWindow)
{
MessageDialog md = new Gtk.MessageDialog(masterWindow, Gtk.DialogFlags.Modal,
msgType, buttonType, message);
md.Title = title;
md.WindowPosition = WindowPosition.Center;
int result = md.Run();
md.Dispose();
return result;
}
}
}
5 changes: 4 additions & 1 deletion ApsimNG/Views/DirectedGraphView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ private void OnDrawingAreaExpose(object sender, DrawnArgs args)
if (isDrawingArc)
arcs.Add(tempArc);

DirectedGraphRenderer.DarkMode = Configuration.Settings.DarkTheme;
// Account for change in theme.
if (!Configuration.Settings.ThemeRestartRequired)
DirectedGraphRenderer.DarkMode = Configuration.Settings.DarkTheme;
else DirectedGraphRenderer.DarkMode = !Configuration.Settings.DarkTheme;
DirectedGraphRenderer.Draw(drawingContext, arcs, nodes, selectionRectangle);

if (isDrawingArc)
Expand Down
5 changes: 4 additions & 1 deletion ApsimNG/Views/EditorView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,10 @@ private void InitialiseWidget()
StyleScheme style = StyleSchemeManager.Default.GetScheme(Configuration.Settings.EditorStyleName);
if (style == null)
{
string defaultStyle = Configuration.Settings.DarkTheme ? defaultDarkStyle : defaultLightStyle;
string defaultStyle = "";
if (!Configuration.Settings.ThemeRestartRequired)
defaultStyle = Configuration.Settings.DarkTheme ? defaultDarkStyle : defaultLightStyle;
else defaultStyle = Configuration.Settings.DarkTheme ? defaultLightStyle : defaultDarkStyle;
style = StyleSchemeManager.Default.GetScheme(defaultStyle);
}
if (style != null)
Expand Down
17 changes: 13 additions & 4 deletions ApsimNG/Views/GraphView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,19 @@ protected override void Initialise(ViewBase ownerView, GLib.Object gtkControl)
captionLabel.Text = null;
captionEventBox.ButtonPressEvent += OnCaptionLabelDoubleClick;
}
Color foreground = Utility.Configuration.Settings.DarkTheme ? Color.White : Color.Black;
ForegroundColour = Utility.Colour.ToOxy(foreground);
if (!Utility.Configuration.Settings.DarkTheme)
BackColor = Utility.Colour.ToOxy(Color.White);

Color foregroundColor = Color.Gray;
if (!Configuration.Settings.ThemeRestartRequired)
foregroundColor = Configuration.Settings.DarkTheme ? Color.White : Color.Black;
else foregroundColor = Configuration.Settings.DarkTheme ? Color.Black : Color.White;
ForegroundColour = Colour.ToOxy(foregroundColor);

Color backgroundColor = Color.Gray;
if (!Configuration.Settings.ThemeRestartRequired)
backgroundColor = Configuration.Settings.DarkTheme ? Color.FromArgb(255,48,48,48) : Color.White;
else backgroundColor = Configuration.Settings.DarkTheme ? Color.White : Color.FromArgb(255,48,48,48);
BackColor = Colour.ToOxy(backgroundColor);

mainWidget.Destroyed += _mainWidget_Destroyed;

// Not sure why but Oxyplot fonts are not scaled correctly on .net core on high DPI screens.
Expand Down
Loading

0 comments on commit 8a2ca0d

Please sign in to comment.