Building the First View
Adding
the following methods to your COMBookSet
allows you to load a data file, see how many transactions
the BookSet contains, and then build a view that
displays a Journal, a listing of all the transactions in date order:
# more methods for COMBookSet - must be named in _public_methods_
def load(self, filename):
self.__BookSet.load(str(filename))
def count(self):
# return number of transactions
return len(self.__BookSet)
def getTransactionString(self, index):
return self.__BookSet[index].asString()In load, you perform a
str(filename) operation to convert the Unicode
filename from COM into an ordinary Python string. Then pass the
request to the delegate Python BookSet instance.
Most methods follow this pattern, doing any necessary transformations
of arguments on the way in and out and passing the real work onto the
delegate.
Now you need to open files. This is the VB code for the File → Open menu option (generated by one of VB’s Wizards and so is somewhat verbose):
Private Sub mnuFileOpen_Click()
Dim sFile As String
With dlgCommonDialog
.DialogTitle = "Open"
.CancelError = False
'ToDo: set the flags and attributes of the common dialog control
.Filter = "Doubletalk Journal Files (*.dtj)|*.dtj"
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If
sFile = .FileName
End With
BookServer.Load sFile
'display something helpful in the Journal caption
frmJournal.Caption = sFile & ", " & BookServer.count & " Transactions"
End SubThe only line of interest here is in ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access