Skip to content

Commit

Permalink
Merge pull request #63 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
Updating master
  • Loading branch information
berylwaswa authored Sep 20, 2023
2 parents c9e470e + 281fc85 commit a8c9cbb
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 187 deletions.
14 changes: 4 additions & 10 deletions instat/clsRLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -824,15 +824,8 @@ Public Class RLink
End If
ElseIf iCallType = 5 Then
'else if script comes from script window
Dim bSuccess As Boolean = Evaluate(strScript, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride)

'if not an assignment operation, then capture the output
If Not strScript.Contains("<-") AndAlso bSuccess Then
Dim strScriptAsSingleLine As String = strScript.Replace(vbCrLf, String.Empty)
strScriptAsSingleLine = strScriptAsSingleLine.Replace(vbCr, String.Empty)
strScriptAsSingleLine = strScriptAsSingleLine.Replace(vbLf, String.Empty)
strOutput = GetFileOutput("view_object_data(object = " & strScriptAsSingleLine & " , object_format = 'text' )", bSilent, bSeparateThread, bShowWaitDialogOverride)
End If
'wrap command inside view_object_data just incase there is an output object
strOutput = GetFileOutput("view_object_data(object = " & strScript & " , object_format = 'text' )", bSilent, bSeparateThread, bShowWaitDialogOverride)
Else
'else if script output should not be ignored or not stored as an object or variable

Expand Down Expand Up @@ -883,7 +876,8 @@ Public Class RLink
Dim expTemp As RDotNet.SymbolicExpression
Dim strNewAssignedToScript As String = ConstructAssignTo(strTempAssignTo, strScript)
Evaluate(strNewAssignedToScript, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride)
expTemp = GetSymbol(strTempAssignTo, bSilent:=bSilent)
'get file path. If not found then silently return nothing
expTemp = GetSymbol(strTempAssignTo, bSilent:=True)
Evaluate("rm(" & strTempAssignTo & ")", bSilent:=True)
If expTemp IsNot Nothing Then
'get the file path name, check if it exists and whether it has contents
Expand Down
37 changes: 19 additions & 18 deletions instat/dlgRownamesOrNumbers.vb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ Public Class dlgRowNamesOrNumbers
Private clsGetRowNamesFunction As New RFunction
Private clsSetRowNamesFunction As New RFunction
Private clsAddKeyFunction As New RFunction
Private clsAsNumericFunction As New RFunction
Private clsDummyFunction As New RFunction
Private clsGetVectorFunction As New RFunction
Private clsHmiscFunction As New RFunction


Private Sub dlgRowNamesOrNumbers_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If bFirstLoad Then
Expand All @@ -33,7 +35,6 @@ Public Class dlgRowNamesOrNumbers

If bReset Then
SetDefaults()
IdentifyKey()
End If
SetRCodeForControls(bReset)
bReset = False
Expand Down Expand Up @@ -66,7 +67,7 @@ Public Class dlgRowNamesOrNumbers
ucrPnlOverallOptions.AddParameterValuesCondition(rdoResetintoPositiveIntegers, "checked_rdo", "reset_row")
ucrPnlOverallOptions.AddParameterValuesCondition(rdoSortbyRowNames, "checked_rdo", "sort_row")

ucrPnlOverallOptions.AddToLinkedControls({ucrNewColumnName, ucrChkMakeColumnIntoKey}, {rdoCopyRowNamesIntoFirstColumn}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True)
ucrPnlOverallOptions.AddToLinkedControls({ucrNewColumnName, ucrChkMakeColumnIntoKey}, {rdoCopyRowNamesIntoFirstColumn}, bNewLinkedHideIfParameterMissing:=True)
ucrPnlOverallOptions.AddToLinkedControls(ucrReceiverRowNames, {rdoSetRowNamesFromColumn}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True)
ucrPnlOverallOptions.AddToLinkedControls(ucrPnlSortOptions, {rdoSortbyRowNames}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True)
ucrPnlOverallOptions.AddToLinkedControls(ucrChkAsNumeric, {rdoSortbyRowNames}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True)
Expand All @@ -92,7 +93,7 @@ Public Class dlgRowNamesOrNumbers
ucrChkMakeColumnIntoKey.SetText("Make the Column a Key for the Data Frame")
ucrChkMakeColumnIntoKey.AddParameterValuesCondition(True, "add_key", "TRUE")
ucrChkMakeColumnIntoKey.AddParameterValuesCondition(False, "add_key", "FALSE")
IdentifyKey()

'ucrNewColumnName
ucrNewColumnName.SetIsComboBox()
ucrNewColumnName.SetPrefix("row")
Expand All @@ -106,25 +107,31 @@ Public Class dlgRowNamesOrNumbers
clsAddKeyFunction = New RFunction
clsDummyFunction = New RFunction
clsSetRowNamesFunction = New RFunction
clsAsNumericFunction = New RFunction
clsGetVectorFunction = New RFunction
clsHmiscFunction = New RFunction


ucrNewColumnName.Reset()
ucrSelectorRowNames.Reset()
ucrBase.clsRsyntax.lstAfterCodes.Clear()

clsDummyFunction.AddParameter("checked_rdo", "copy_row", iPosition:=1)
clsDummyFunction.AddParameter("add_key", "FALSE", iPosition:=2)
clsDummyFunction.AddParameter("add_key", "TRUE", iPosition:=2)

clsAddKeyFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_key")

clsAsNumericFunction.SetRCommand("as.numeric")
clsAsNumericFunction.AddParameter("x", clsRFunctionParameter:=clsGetRowNamesFunction, iPosition:=0)
clsGetVectorFunction.SetRCommand("what=c")
clsGetVectorFunction.AddParameter("vector", Chr(34) & "vector" & Chr(34), bIncludeArgumentName:=False)

clsHmiscFunction.SetPackageName("Hmisc")
clsHmiscFunction.SetRCommand("all.is.numeric")
clsHmiscFunction.AddParameter("row", clsRFunctionParameter:=clsGetRowNamesFunction, bIncludeArgumentName:=False, iPosition:=0)
clsHmiscFunction.AddParameter("vector", clsRFunctionParameter:=clsGetVectorFunction, bIncludeArgumentName:=False, iPosition:=1)

clsGetRowNamesFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_row_names")
clsGetRowNamesFunction.SetAssignTo(strTemp:=ucrNewColumnName.GetText(), strTempDataframe:=ucrSelectorRowNames.ucrAvailableDataFrames.cboAvailableDataFrames.Text, strTempColumn:=ucrNewColumnName.GetText())

clsSetRowNamesFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$set_row_names")

ucrBase.clsRsyntax.SetBaseRFunction(clsGetRowNamesFunction)
End Sub

Expand All @@ -137,9 +144,9 @@ Public Class dlgRowNamesOrNumbers
ucrChkMakeColumnIntoKey.SetRCode(clsDummyFunction, bReset)
ucrPnlOverallOptions.SetRCode(clsDummyFunction, bReset)
ucrNewColumnName.AddAdditionalRCode(clsGetRowNamesFunction, bReset)
ucrNewColumnName.SetRCode(clsAsNumericFunction, bReset)
ucrNewColumnName.SetRCode(clsHmiscFunction, bReset)
ucrChkAsNumeric.SetRCode(ucrBase.clsRsyntax.clsBaseFunction, bReset)
IdentifyKey()

End Sub

Private Sub TestOKEnabled()
Expand All @@ -165,7 +172,7 @@ Public Class dlgRowNamesOrNumbers
Else
ucrSelectorRowNames.SetVariablesVisible(False)
If rdoCopyRowNamesIntoFirstColumn.Checked Then
ucrBase.clsRsyntax.SetBaseRFunction(clsAsNumericFunction)
ucrBase.clsRsyntax.SetBaseRFunction(clsHmiscFunction)
clsDummyFunction.AddParameter("checked_rdo", "copy_row", iPosition:=1)
ElseIf rdoResetintoPositiveIntegers.Checked Then
ucrBase.clsRsyntax.SetBaseRFunction(clsSetRowNamesFunction)
Expand All @@ -190,13 +197,8 @@ Public Class dlgRowNamesOrNumbers
End If
End Sub

Private Sub IdentifyKey()
ucrChkMakeColumnIntoKey.Checked = Not frmMain.clsRLink.IsVariablesMetadata(ucrSelectorRowNames.ucrAvailableDataFrames.cboAvailableDataFrames.Text, "Is_Key")
End Sub

Private Sub ucrChkMakeColumnIntoKey_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkMakeColumnIntoKey.ControlValueChanged
AddRemoveKeyFromAfterCodes()
IdentifyKey()
End Sub

Private Sub ucrNewColumnName_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrNewColumnName.ControlValueChanged
Expand All @@ -210,6 +212,5 @@ Public Class dlgRowNamesOrNumbers
End Sub

Private Sub ucrSelectorRowNames_DataFrameChanged() Handles ucrSelectorRowNames.DataFrameChanged
IdentifyKey()
End Sub
End Class
206 changes: 126 additions & 80 deletions instat/frmMain.vb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ Public Class frmMain
InitializeComponent()

' Add any initialization after the InitializeComponent() call.

'set controls layout
SetupInitialLayout()

clsOutputLogger = New clsOutputLogger
clsRLink = New RLink(clsOutputLogger)
If RuntimeInformation.IsOSPlatform(OSPlatform.Windows) Then
Expand Down Expand Up @@ -128,8 +132,6 @@ Public Class frmMain

ucrOutput.SetLogger(clsOutputLogger)

SetToDefaultLayout()

'---------------------------------------
'set up R-Instat options (settings)
'load any saved options if available
Expand Down Expand Up @@ -218,6 +220,114 @@ Public Class frmMain
isMaximised = True 'Need to get the windowstate when the application is loaded
End Sub

Private Sub SetupInitialLayout()
'splOverall has 2 panels
'splOverall.Panel1 contains splExtraWindows
'splOverall.Panel2 contains splDataOutput

'splExtraWindows has 2 panels
'splExtraWindows.Panel1 contains splMetadata
'splExtraWindows.Panel2 contains script window

'splMetadata has 2 panels
'splMetadata.Panel1 contains data frame
'splMetadata.Panel2 contains column metadata

'splDataOutput has 2 panels
'splDataOutput.Panel1 contains data viewer window
'splDataOutput.Panel2 contains output window

'collaspe all the panels initially (on application startup)
splOverall.Panel1Collapsed = True
splOverall.Panel2Collapsed = True

splExtraWindows.Panel1Collapsed = True
splExtraWindows.Panel2Collapsed = True

splMetadata.Panel1Collapsed = True
splMetadata.Panel2Collapsed = True

splDataOutput.Panel1Collapsed = True
splDataOutput.Panel2Collapsed = True

SetToDefaultLayout()
End Sub

Private Sub SetToDefaultLayout()
splOverall.SplitterDistance = splOverall.Height / 4
splDataOutput.SplitterDistance = splDataOutput.Width / 2
splExtraWindows.SplitterDistance = splExtraWindows.Width / 2
splMetadata.SplitterDistance = splMetadata.Width / 2

mnuViewDataView.Checked = True
mnuViewOutput.Checked = True
mnuViewDataFrameMetadata.Checked = False
mnuViewColumnMetadata.Checked = False
mnuViewLogScript.Checked = False
mnuViewSwapDataAndMetadata.Checked = False
mnuColumnMetadat.Checked = False
mnuDataFrameMetadat.Checked = False

mnuTbDataView.Checked = True
mnuOutputWindow.Checked = True
mnuLogScript.Checked = False
UpdateLayout()
End Sub

Public Sub UpdateLayout()

If Not mnuViewDataView.Checked _
AndAlso Not mnuViewOutput.Checked _
AndAlso Not mnuViewColumnMetadata.Checked _
AndAlso Not mnuViewDataFrameMetadata.Checked _
AndAlso Not mnuViewLogScript.Checked _
AndAlso Not mnuViewSwapDataAndMetadata.Checked Then
splOverall.Hide()
Else
splOverall.Show()

'determine splOverall contents visibility

'-------------------------------
'determine splOverall.Panel1 and it's contents visibility

If mnuViewColumnMetadata.Checked OrElse mnuViewDataFrameMetadata.Checked OrElse mnuViewLogScript.Checked Then
'expand panel 1
splOverall.Panel1Collapsed = False
'change splOverall.Panel1Collapsed contents visibilty
If mnuViewColumnMetadata.Checked OrElse mnuViewDataFrameMetadata.Checked Then
splMetadata.Panel1Collapsed = Not mnuViewColumnMetadata.Checked
splMetadata.Panel2Collapsed = Not mnuViewDataFrameMetadata.Checked
splExtraWindows.Panel1Collapsed = False
Else
splExtraWindows.Panel1Collapsed = True
End If
'expand panel 2 based on log script menu item checked status
splExtraWindows.Panel2Collapsed = Not mnuViewLogScript.Checked
Else
splOverall.Panel1Collapsed = True
End If
'-------------------------------

'-------------------------------
'determine splOverall.Panel2 and it's contents visibility

If mnuViewDataView.Checked OrElse mnuViewOutput.Checked Then
splDataOutput.Panel1Collapsed = Not mnuViewDataView.Checked
splDataOutput.Panel2Collapsed = Not mnuViewOutput.Checked
splOverall.Panel2Collapsed = False
Else
splOverall.Panel2Collapsed = True
End If
'-------------------------------


End If
mnuTbDataView.Checked = mnuViewDataView.Checked
mnuOutputWindow.Checked = mnuViewOutput.Checked
mnuLogScript.Checked = mnuViewLogScript.Checked
End Sub

Private Function GetSavedRInstatOptions() As InstatOptions
Dim clsInstatOptions As InstatOptions = Nothing
Dim strFilePath As String = Path.Combine(strAppDataPath, strInstatOptionsFile)
Expand Down Expand Up @@ -426,29 +536,21 @@ Public Class frmMain
End If
End Sub



Private Sub SetToDefaultLayout()
splOverall.SplitterDistance = splOverall.Height / 4
splDataOutput.SplitterDistance = splDataOutput.Width / 2
splExtraWindows.SplitterDistance = splExtraWindows.Width / 2
splMetadata.SplitterDistance = splMetadata.Width / 2

mnuViewDataView.Checked = True
mnuViewOutput.Checked = True
mnuViewDataFrameMetadata.Checked = False
mnuViewColumnMetadata.Checked = False
mnuViewLogScript.Checked = False
mnuViewSwapDataAndMetadata.Checked = False
mnuColumnMetadat.Checked = False
mnuDataFrameMetadat.Checked = False

mnuTbDataView.Checked = True
mnuOutputWindow.Checked = True
mnuLogScript.Checked = False
UpdateLayout()
Private Sub UpdateSwapDataAndMetadata()
If mnuViewSwapDataAndMetadata.Checked Then
splDataOutput.Panel1.Controls.Add(ucrColumnMeta)
splMetadata.Panel1.Controls.Add(ucrDataViewer)
mnuViewColumnMetadata.Text = "Data View"
mnuViewDataView.Text = "Column Metadata"
Else
splDataOutput.Panel1.Controls.Add(ucrDataViewer)
splMetadata.Panel1.Controls.Add(ucrColumnMeta)
mnuViewColumnMetadata.Text = "Column Metadata"
mnuViewDataView.Text = "Data View"
End If
End Sub


Public Sub SaveInstatOptions(strFilePath As String)
Dim serializer As New BinaryFormatter()

Expand Down Expand Up @@ -550,62 +652,6 @@ Public Class frmMain
dlgName.ShowDialog()
End Sub

Public Sub UpdateLayout()
If Not mnuViewDataView.Checked _
AndAlso Not mnuViewOutput.Checked _
AndAlso Not mnuViewColumnMetadata.Checked _
AndAlso Not mnuViewDataFrameMetadata.Checked _
AndAlso Not mnuViewLogScript.Checked _
AndAlso Not mnuViewSwapDataAndMetadata.Checked Then
splOverall.Hide()
Else
splOverall.Show()
If mnuViewDataView.Checked OrElse mnuViewOutput.Checked Then
splOverall.Panel2Collapsed = False
splDataOutput.Panel1Collapsed = Not mnuViewDataView.Checked
splDataOutput.Panel2Collapsed = Not mnuViewOutput.Checked
Else
splOverall.Panel2Collapsed = True
End If
If mnuViewColumnMetadata.Checked _
OrElse mnuViewDataFrameMetadata.Checked _
OrElse mnuViewLogScript.Checked Then
splOverall.Panel1Collapsed = False
If mnuViewColumnMetadata.Checked OrElse mnuViewDataFrameMetadata.Checked Then
splExtraWindows.Panel1Collapsed = False
splMetadata.Panel1Collapsed = Not mnuViewColumnMetadata.Checked
splMetadata.Panel2Collapsed = Not mnuViewDataFrameMetadata.Checked
Else
splExtraWindows.Panel1Collapsed = True
End If
If mnuViewLogScript.Checked Then
splExtraWindows.Panel2Collapsed = False
Else
splExtraWindows.Panel2Collapsed = True
End If
Else
splOverall.Panel1Collapsed = True
End If
End If
mnuTbDataView.Checked = mnuViewDataView.Checked
mnuOutputWindow.Checked = mnuViewOutput.Checked
mnuLogScript.Checked = mnuViewLogScript.Checked
End Sub

Private Sub UpdateSwapDataAndMetadata()
If mnuViewSwapDataAndMetadata.Checked Then
splDataOutput.Panel1.Controls.Add(ucrColumnMeta)
splMetadata.Panel1.Controls.Add(ucrDataViewer)
mnuViewColumnMetadata.Text = "Data View"
mnuViewDataView.Text = "Column Metadata"
Else
splDataOutput.Panel1.Controls.Add(ucrDataViewer)
splMetadata.Panel1.Controls.Add(ucrColumnMeta)
mnuViewColumnMetadata.Text = "Column Metadata"
mnuViewDataView.Text = "Data View"
End If
End Sub

Private Sub mnuWindowDataFrame_Click(sender As Object, e As EventArgs) Handles mnuViewDataFrameMetadata.Click
mnuViewDataFrameMetadata.Checked = Not mnuViewDataFrameMetadata.Checked
mnuDataFrameMetadat.Checked = mnuViewDataFrameMetadata.Checked
Expand Down Expand Up @@ -640,7 +686,7 @@ Public Class frmMain
End Sub

Private Sub mnuPrepareSheetColumnMetadata_Click(sender As Object, e As EventArgs) Handles mnuViewColumnMetadata.Click
mnuViewColumnMetadata.Checked = True
mnuViewColumnMetadata.Checked = Not mnuViewColumnMetadata.Checked
UpdateLayout()
End Sub

Expand Down
Loading

0 comments on commit a8c9cbb

Please sign in to comment.