Skip to content

Commit

Permalink
Merge pull request #160 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
Updating master
  • Loading branch information
maxwellfundi authored Jun 27, 2017
2 parents 790c011 + cda915b commit 834b80a
Show file tree
Hide file tree
Showing 48 changed files with 2,766 additions and 1,876 deletions.
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-minimal
1 change: 1 addition & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-minimal
1 change: 1 addition & 0 deletions docs/foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

158 changes: 89 additions & 69 deletions instat/clsInstatOptions.vb
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
Imports System.Threading
' Instat-R
' Copyright (C) 2015
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License k
' along with this program. If not, see <http://www.gnu.org/licenses/>.

Imports System.Threading
Imports System.Globalization
Imports unvell.ReoGrid
Imports RDotNet

'Serializable allows the class to be exported as a file
<Serializable()> Public Class InstatOptions
Public bIncludeRDefaultParameters As Boolean
Public fntOutput, fntScript, fntComment, fntEditor As Font
Public clrOutput, clrScript, clrComment, clrEditor As Color
Public strComment, strLanguageCultureCode As String
Public strWorkingDirectory As String
' Nullable allows us to have integers and booleans with value = Nothing
' Needed so we can check if variable has been specified, not just has default value
Public bIncludeRDefaultParameters As Nullable(Of Boolean)
Public iPreviewRows As Nullable(Of Integer)
Public iMaxRows As Nullable(Of Integer)
Public iMaxCols As Nullable(Of Integer)
Expand All @@ -23,55 +39,29 @@ Imports RDotNet
Public bShowSignifStars As Nullable(Of Boolean)
Public bChangeDataFrame As Nullable(Of Boolean)

'Factory defaults
Private DEFAULTbIncludeRDefaultParameters As Boolean = False
Private DEFAULTbCommandsinOutput As Boolean = True
Private DEFAULTbIncludeCommentDefault As Boolean = True
Private DEFAULTfntOutput As Font = New Font(FontFamily.GenericMonospace, 11, FontStyle.Regular)
Private DEFAULTclrOutput As Color = Color.Blue
Private DEFAULTfntComment As Font = New Font(FontFamily.GenericSansSerif, 11, FontStyle.Regular)
Private DEFAULTclrComment As Color = Color.Green
Private DEFAULTfntScript As Font = New Font(FontFamily.GenericSansSerif, 11, FontStyle.Regular)
Private DEFAULTclrScript As Color = Color.Black
Private DEFAULTfntEditor As Font = New Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)
Private DEFAULTclrEditor As Color = Color.Black
Private DEFAULTiPreviewRows As Integer = 10
Private DEFAULTiMaxRows As Integer = 1000
Private DEFAULTiMaxCols As Integer = 30
Private DEFAULTstrComment As String = "code generated by the dialog"
Private DEFAULTstrGraphDisplayOption As String = "view_output_window"
Private DEFAULTbChangeDataFrame As Boolean = False
'TODO is this sensible?
Private DEFAULTstrLanguageCultureCode As String = Thread.CurrentThread.CurrentCulture.Name
Private DEFAULTstrWorkingDirectory As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Private DEFAULTlstColourPalette As List(Of Color) = ({Color.Aqua, Color.Gray, Color.LightGreen, Color.AliceBlue, Color.Maroon, Color.Green, Color.LightPink, Color.LightSkyBlue, Color.Brown, Color.MediumPurple, Color.White}).ToList
Private DEFAULTiDigits As Integer = 4
Private DEFAULTbShowSignifStars As Boolean = False

Public Sub New(Optional bSetOptions As Boolean = True)
'TODO Is this sensible to do in constructor?
bIncludeRDefaultParameters = DEFAULTbIncludeRDefaultParameters
bCommandsinOutput = DEFAULTbCommandsinOutput
bIncludeCommentDefault = DEFAULTbIncludeCommentDefault
fntOutput = DEFAULTfntOutput
clrOutput = DEFAULTclrOutput
fntComment = DEFAULTfntComment
clrComment = DEFAULTclrComment
fntScript = DEFAULTfntScript
clrScript = DEFAULTclrScript
fntEditor = DEFAULTfntEditor
clrEditor = DEFAULTclrEditor
iPreviewRows = DEFAULTiPreviewRows
iMaxRows = DEFAULTiMaxRows
iMaxCols = DEFAULTiMaxCols
strComment = DEFAULTstrComment
strGraphDisplayOption = DEFAULTstrGraphDisplayOption
'TODO is this sensible?
strLanguageCultureCode = DEFAULTstrLanguageCultureCode
strWorkingDirectory = DEFAULTstrWorkingDirectory
SetColorPalette(DEFAULTlstColourPalette)
iDigits = DEFAULTiDigits
bShowSignifStars = DEFAULTbShowSignifStars
bIncludeRDefaultParameters = clsInstatOptionsDefaults.DEFAULTbIncludeRDefaultParameters
bCommandsinOutput = clsInstatOptionsDefaults.DEFAULTbCommandsinOutput
bIncludeCommentDefault = clsInstatOptionsDefaults.DEFAULTbIncludeCommentDefault
fntOutput = clsInstatOptionsDefaults.DEFAULTfntOutput
clrOutput = clsInstatOptionsDefaults.DEFAULTclrOutput
fntComment = clsInstatOptionsDefaults.DEFAULTfntComment
clrComment = clsInstatOptionsDefaults.DEFAULTclrComment
fntScript = clsInstatOptionsDefaults.DEFAULTfntScript
clrScript = clsInstatOptionsDefaults.DEFAULTclrScript
fntEditor = clsInstatOptionsDefaults.DEFAULTfntEditor
clrEditor = clsInstatOptionsDefaults.DEFAULTclrEditor
iPreviewRows = clsInstatOptionsDefaults.DEFAULTiPreviewRows
iMaxRows = clsInstatOptionsDefaults.DEFAULTiMaxRows
iMaxCols = clsInstatOptionsDefaults.DEFAULTiMaxCols
strComment = clsInstatOptionsDefaults.DEFAULTstrComment
strGraphDisplayOption = clsInstatOptionsDefaults.DEFAULTstrGraphDisplayOption
strLanguageCultureCode = clsInstatOptionsDefaults.DEFAULTstrLanguageCultureCode
strWorkingDirectory = clsInstatOptionsDefaults.DEFAULTstrWorkingDirectory
lstColourPalette = clsInstatOptionsDefaults.DEFAULTlstColourPalette
iDigits = clsInstatOptionsDefaults.DEFAULTiDigits
bShowSignifStars = clsInstatOptionsDefaults.DEFAULTbShowSignifStars
If bSetOptions Then
SetOptions()
End If
Expand All @@ -81,103 +71,121 @@ Imports RDotNet
If fntOutput IsNot Nothing AndAlso clrOutput <> Color.Empty Then
SetFormatOutput(fntOutput, clrOutput)
Else
SetFormatOutput(DEFAULTfntOutput, DEFAULTclrOutput)
SetFormatOutput(clsInstatOptionsDefaults.DEFAULTfntOutput, clsInstatOptionsDefaults.DEFAULTclrOutput)
End If

If fntComment IsNot Nothing AndAlso clrComment <> Color.Empty Then
SetFormatComment(fntComment, clrComment)
Else
SetFormatComment(DEFAULTfntComment, DEFAULTclrComment)
SetFormatComment(clsInstatOptionsDefaults.DEFAULTfntComment, clsInstatOptionsDefaults.DEFAULTclrComment)
End If

If fntScript IsNot Nothing AndAlso clrScript <> Color.Empty Then
SetFormatScript(fntScript, clrScript)
Else
SetFormatScript(DEFAULTfntScript, DEFAULTclrScript)
SetFormatScript(clsInstatOptionsDefaults.DEFAULTfntScript, clsInstatOptionsDefaults.DEFAULTclrScript)
End If

If fntEditor IsNot Nothing AndAlso clrEditor <> Color.Empty Then
SetFormatEditor(fntEditor, clrEditor)
Else
SetFormatEditor(DEFAULTfntEditor, DEFAULTclrEditor)
SetFormatEditor(clsInstatOptionsDefaults.DEFAULTfntEditor, clsInstatOptionsDefaults.DEFAULTclrEditor)
End If

If iPreviewRows.HasValue Then
SetPreviewRows(iPreviewRows)
Else
SetPreviewRows(DEFAULTiPreviewRows)
SetPreviewRows(clsInstatOptionsDefaults.DEFAULTiPreviewRows)
End If

If iMaxRows.HasValue Then
SetMaxRows(iMaxRows)
Else
SetMaxRows(DEFAULTiMaxRows)
SetMaxRows(clsInstatOptionsDefaults.DEFAULTiMaxRows)
End If

If iMaxRows.HasValue Then
If iMaxCols.HasValue Then
SetMaxCols(iMaxCols)
Else
SetMaxCols(DEFAULTiMaxCols)
SetMaxCols(clsInstatOptionsDefaults.DEFAULTiMaxCols)
End If

If bCommandsinOutput.HasValue Then
SetCommandInOutpt(bCommandsinOutput)
Else
SetCommandInOutpt(DEFAULTbCommandsinOutput)
SetCommandInOutpt(clsInstatOptionsDefaults.DEFAULTbCommandsinOutput)
End If

If strComment IsNot Nothing Then
SetComment(strComment)
Else
SetComment(DEFAULTstrComment)
SetComment(clsInstatOptionsDefaults.DEFAULTstrComment)
End If

If strGraphDisplayOption IsNot Nothing Then
SetGraphDisplayOption(strGraphDisplayOption)
Else
SetGraphDisplayOption(DEFAULTstrGraphDisplayOption)
SetGraphDisplayOption(clsInstatOptionsDefaults.DEFAULTstrGraphDisplayOption)
End If

If strLanguageCultureCode IsNot Nothing Then
SetLanguageCultureCode(strLanguageCultureCode)
Else
SetLanguageCultureCode(DEFAULTstrLanguageCultureCode)
SetLanguageCultureCode(clsInstatOptionsDefaults.DEFAULTstrLanguageCultureCode)
End If

If strWorkingDirectory IsNot Nothing Then
SetWorkingDirectory(strWorkingDirectory)
Else
SetWorkingDirectory(DEFAULTstrWorkingDirectory)
SetWorkingDirectory(clsInstatOptionsDefaults.DEFAULTstrWorkingDirectory)
End If

If iDigits.HasValue Then
SetDigits(iDigits)
Else
SetDigits(DEFAULTiDigits)
SetDigits(clsInstatOptionsDefaults.DEFAULTiDigits)
End If

If bShowSignifStars.HasValue Then
SetSignifStars(bShowSignifStars)
Else
SetSignifStars(DEFAULTbShowSignifStars)
SetSignifStars(clsInstatOptionsDefaults.DEFAULTbShowSignifStars)
End If

If bChangeDataFrame.HasValue Then
SetChangeDataFrame(bChangeDataFrame)
Else
SetChangeDataFrame(DEFAULTbChangeDataFrame)
SetChangeDataFrame(clsInstatOptionsDefaults.DEFAULTbChangeDataFrame)
End If

If bIncludeCommentDefault.HasValue Then
SetIncludeCommentByDefault(bIncludeCommentDefault)
Else
SetIncludeCommentByDefault(clsInstatOptionsDefaults.DEFAULTbIncludeCommentDefault)
End If

If bIncludeRDefaultParameters.HasValue Then
SetIncludeRDefaultParameters(bIncludeRDefaultParameters)
Else
SetIncludeRDefaultParameters(clsInstatOptionsDefaults.DEFAULTbIncludeRDefaultParameters)
End If

If lstColourPalette IsNot Nothing Then
SetColorPalette(lstColourPalette)
Else
SetColorPalette(clsInstatOptionsDefaults.DEFAULTlstColourPalette)
End If
End Sub

Public Sub SetMaxRows(iRows As Integer)
If iRows <> iMaxRows Then
If (iMaxRows.HasValue AndAlso iRows <> iMaxRows) OrElse Not iMaxRows.HasValue Then
iMaxRows = iRows
frmMain.clsGrids.SetMaxRows(iMaxRows)
End If
End Sub

Public Sub SetMaxCols(iCols As Integer)
If iCols <> iMaxCols Then
If (iMaxCols.HasValue AndAlso iCols <> iMaxCols) OrElse Not iMaxCols.HasValue Then
iMaxCols = iCols
frmMain.clsGrids.SetMaxCols(iMaxCols)
End If
Expand Down Expand Up @@ -269,14 +277,16 @@ Imports RDotNet
Public Sub SetDigits(iNewDigits As Integer)
Dim clsOptionsFunction As New RFunction
Dim clsGetOptionFunction As New RFunction
Dim expCurrDigits As SymbolicExpression

If iNewDigits > 22 OrElse iNewDigits < 0 Then
MsgBox("Cannot set digits to: " & iNewDigits & ". Digits must be an integer between 0 and 22.", MsgBoxStyle.Critical, "Error setting digits")
Else
iDigits = iNewDigits
clsGetOptionFunction.SetRCommand("getOption")
clsGetOptionFunction.AddParameter("x", Chr(34) & "digits" & Chr(34))
If frmMain.clsRLink.RunInternalScriptGetValue(clsGetOptionFunction.ToScript()).AsInteger(0) <> iDigits Then
expCurrDigits = frmMain.clsRLink.RunInternalScriptGetValue(clsGetOptionFunction.ToScript(), bSilent:=True)
If (expCurrDigits IsNot Nothing AndAlso expCurrDigits.Type <> Internals.SymbolicExpressionType.Null AndAlso expCurrDigits.AsInteger(0) <> iDigits) OrElse expCurrDigits Is Nothing Then
clsOptionsFunction.SetRCommand("options")
clsOptionsFunction.AddParameter("digits", iDigits)
frmMain.clsRLink.RunScript(clsOptionsFunction.ToScript(), strComment:="Option: Number of digits to display")
Expand All @@ -287,12 +297,14 @@ Imports RDotNet
Public Sub SetSignifStars(bShowStars As Boolean)
Dim clsOptionsFunction As New RFunction
Dim clsGetOptionsFunction As New RFunction
Dim expCurrStars As SymbolicExpression

bShowSignifStars = bShowStars
clsGetOptionsFunction.SetRCommand("getOption")
clsGetOptionsFunction.AddParameter("x", Chr(34) & "show.signif.stars" & Chr(34))
clsOptionsFunction.SetRCommand("options")
If frmMain.clsRLink.RunInternalScriptGetValue(clsGetOptionsFunction.ToScript()).AsLogical(0) <> bShowSignifStars Then
expCurrStars = frmMain.clsRLink.RunInternalScriptGetValue(clsGetOptionsFunction.ToScript(), bSilent:=True)
If (expCurrStars IsNot Nothing AndAlso expCurrStars.Type <> Internals.SymbolicExpressionType.Null AndAlso expCurrStars.AsLogical(0) <> bShowSignifStars) OrElse expCurrStars Is Nothing Then
If bShowSignifStars Then
clsOptionsFunction.AddParameter("show.signif.stars", "TRUE")
Else
Expand All @@ -305,4 +317,12 @@ Imports RDotNet
Public Sub SetChangeDataFrame(bNewChange As Boolean)
bChangeDataFrame = bNewChange
End Sub

Public Sub SetIncludeCommentByDefault(bNewInclude As Boolean)
bIncludeCommentDefault = bNewInclude
End Sub

Public Sub SetIncludeRDefaultParameters(bNewInclude As Boolean)
bIncludeRDefaultParameters = bNewInclude
End Sub
End Class
41 changes: 41 additions & 0 deletions instat/clsInstatOptionsDefaults.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
' Instat-R
' Copyright (C) 2015
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License k
' along with this program. If not, see <http://www.gnu.org/licenses/>.

Public Class clsInstatOptionsDefaults
Public Shared ReadOnly DEFAULTbIncludeRDefaultParameters As Boolean = False
Public Shared ReadOnly DEFAULTbCommandsinOutput As Boolean = True
Public Shared ReadOnly DEFAULTbIncludeCommentDefault As Boolean = True
Public Shared ReadOnly DEFAULTfntOutput As Font = New Font(FontFamily.GenericMonospace, 11, FontStyle.Regular)
Public Shared ReadOnly DEFAULTclrOutput As Color = Color.Blue
Public Shared ReadOnly DEFAULTfntComment As Font = New Font(FontFamily.GenericSansSerif, 11, FontStyle.Regular)
Public Shared ReadOnly DEFAULTclrComment As Color = Color.Green
Public Shared ReadOnly DEFAULTfntScript As Font = New Font(FontFamily.GenericSansSerif, 11, FontStyle.Regular)
Public Shared ReadOnly DEFAULTclrScript As Color = Color.Black
Public Shared ReadOnly DEFAULTfntEditor As Font = New Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)
Public Shared ReadOnly DEFAULTclrEditor As Color = Color.Black
Public Shared ReadOnly DEFAULTiPreviewRows As Integer = 10
Public Shared ReadOnly DEFAULTiMaxRows As Integer = 1000
Public Shared ReadOnly DEFAULTiMaxCols As Integer = 30
Public Shared ReadOnly DEFAULTstrComment As String = "code generated by the dialog"
Public Shared ReadOnly DEFAULTstrGraphDisplayOption As String = "view_output_window"
Public Shared ReadOnly DEFAULTbChangeDataFrame As Boolean = False
'TODO is this sensible?
Public Shared ReadOnly DEFAULTstrLanguageCultureCode As String = Threading.Thread.CurrentThread.CurrentCulture.Name
Public Shared ReadOnly DEFAULTstrWorkingDirectory As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Public Shared ReadOnly DEFAULTlstColourPalette As List(Of Color) = ({Color.Aqua, Color.Gray, Color.LightGreen, Color.AliceBlue, Color.Maroon, Color.Green, Color.LightPink, Color.LightSkyBlue, Color.Brown, Color.MediumPurple, Color.White}).ToList
Public Shared ReadOnly DEFAULTiDigits As Integer = 4
Public Shared ReadOnly DEFAULTbShowSignifStars As Boolean = False
End Class
Loading

0 comments on commit 834b80a

Please sign in to comment.