Skip to content

Instantly share code, notes, and snippets.

@jquast
Last active October 12, 2015 16:27
Show Gist options
  • Save jquast/4054337 to your computer and use it in GitHub Desktop.
Save jquast/4054337 to your computer and use it in GitHub Desktop.
win32 lotus notes gui for views
import wx
import lotus
mypass = 'xxxxxxxxxx'
lotus.session.Initialize(mypass)
# from 2005 ... no guarantees here ..
def repstring(str, replace, wth='_'):
newstr = ''
for ch in str:
if ch == replace:
newstr += wth
else:
newstr += ch
return newstr
def sanestring(string):
newstring = ''
try:
for ch in string:
newstring += chr(ord(ch) & 0177)
except:
print string
return newstring
class MyPreviewFrame(wx.Frame):
def __init__(self, parent, title, data):
wx.Frame.__init__(self, parent, -1, title,
size=(600, 400))
self.panel = wx.Panel(self)
txt_dump = wx.TextCtrl(self.panel, -1, '', size=(
595, 375), style=wx.TE_MULTILINE | wx.TE_DONTWRAP)
txt_dump.Clear()
for line in data:
txt_dump.WriteText(line + '\n')
class MyViewFrame(wx.Frame):
def __init__(self, parent, title, server, db):
wx.Frame.__init__(self, parent, -1, title,
pos=(0, 0), size=(490, 330))
self.parent = parent
panel = wx.Panel(self)
db = lotus.session.GetDatabase(server, db)
self.l = []
if not db:
return
for v in db.Views:
self.l.append(sanestring(v.Name))
self.lb1 = wx.ListBox(
panel, -1, pos=(0, 0), size=(400, 300), choices=self.l)
btn_OK = wx.Button(panel, -1, "&OK", pos=(405, 4))
btn_CANCEL = wx.Button(panel, -1, "&Cancel", pos=(405, 30))
self.Bind(wx.EVT_BUTTON, self.OkExit, btn_OK)
self.Bind(wx.EVT_BUTTON, self.Exit, btn_CANCEL)
def Exit(self, evt):
self.Close()
def OkExit(self, evt):
nv = self.l[self.lb1.GetSelection()]
self.parent.txt_v.SetValue(nv)
self.parent.myview = nv
self.Close()
class MyDBFrame(wx.Frame):
def __init__(self, parent, title, dbserver):
wx.Frame.__init__(self, parent, -1, title,
pos=(0, 0), size=(490, 330))
self.parent = parent
panel = wx.Panel(self)
self.l = []
dbdir = lotus.session.GetDbDirectory(dbserver)
for db in lotus.iterateDatabases(dbdir):
self.l.append(str(db) + ':' + str(db.Title))
self.l.sort()
self.lb1 = wx.ListBox(
panel, -1, pos=(0, 0), size=(400, 300), choices=self.l)
btn_OK = wx.Button(panel, -1, "&OK", pos=(405, 4))
btn_CANCEL = wx.Button(panel, -1, "&Cancel", pos=(405, 30))
self.Bind(wx.EVT_BUTTON, self.OkExit, btn_OK)
self.Bind(wx.EVT_BUTTON, self.Exit, btn_CANCEL)
def Exit(self, evt):
self.Close()
def OkExit(self, evt):
self.parent.txt_db.SetValue(
self.l[self.lb1.GetSelection()].split(':')[0])
self.Close()
class MyMainFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title)
# defaults
self.path = 'c:\\'
self.filename = 'c:\\default.cfg'
self.title = title
self.myserver = 'ZZZZZZZZZZZZZZZZZZZZZZ'
self.mydb = 'select a database'
self.myview = 'select a view'
self.delimiter = ','
self.recfilename = 'c:\\records.csv'
#menu
menuBar = wx.MenuBar()
menu = wx.Menu()
menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit program")
menu.Append(wx.ID_SAVE, "&Save\tAlt-S", "Save current configuration")
menu.Append(wx.ID_OPEN, "&Load\tAlt-L", "Load configuration")
self.Bind(wx.EVT_MENU, self.Exit, id=wx.ID_EXIT)
self.Bind(wx.EVT_MENU, self.Save, id=wx.ID_SAVE)
self.Bind(wx.EVT_MENU, self.Load, id=wx.ID_OPEN)
menuBar.Append(menu, "&File")
self.SetMenuBar(menuBar)
#status bar
self.CreateStatusBar()
# panel
self.panel = wx.Panel(self)
# input textctrl's
self.txt_d = wx.TextCtrl(self.panel, -1, self.delimiter, size=(15, -1))
self.txt_s = wx.TextCtrl(self.panel, -1, self.myserver, size=(125, -1))
self.txt_db = wx.TextCtrl(self.panel, -1, self.mydb, size=(125, -1))
self.txt_v = wx.TextCtrl(self.panel, -1, self.myview, size=(125, -1))
# buttons
btn_selectDB = wx.Button(self.panel, -1, "Select &Database")
btn_selectView = wx.Button(self.panel, -1, "Select &View")
btn_preview = wx.Button(self.panel, -1, "&Preview")
btn_saverec = wx.Button(self.panel, -1, "&Save Records")
# bind
self.Bind(wx.EVT_BUTTON, self.SelectDB, btn_selectDB)
self.Bind(wx.EVT_BUTTON, self.SelectView, btn_selectView)
self.Bind(wx.EVT_BUTTON, self.Preview, btn_preview)
self.Bind(wx.EVT_BUTTON, self.SaveRecords, btn_saverec)
# layout grid
gs = wx.GridSizer(5, 3, 5, 5)
gs.Add((wx.StaticText(
self.panel, -1, "domino server")), 0, wx.ALIGN_RIGHT)
gs.Add((self.txt_s), 0, wx.ALIGN_LEFT)
gs.Add((0, 0))
gs.Add((wx.StaticText(self.panel, -1, "database")), 0, wx.ALIGN_RIGHT)
gs.Add((self.txt_db), 0, wx.ALIGN_LEFT)
gs.Add((btn_selectDB), 0)
gs.Add((wx.StaticText(self.panel, -1, "view")), 0, wx.ALIGN_RIGHT)
gs.Add((self.txt_v), 0, wx.ALIGN_LEFT)
gs.Add((btn_selectView), 0)
gs.Add((wx.StaticText(self.panel, -1, "delimiter")), 0, wx.ALIGN_RIGHT)
gs.Add((self.txt_d), 0, wx.ALIGN_LEFT)
gs.Add((0, 0))
gs.Add((btn_preview), 0)
gs.Add((btn_saverec), 0)
gs.Add((0, 0))
gs.Fit(self)
self.panel.SetSizer(gs)
self.panel.Layout()
self.ReadFile()
def Busy(self):
self.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
def UnBusy(self):
self.SetCursor(wx.NullCursor)
def SelectDB(self, evt):
self.Busy()
self.SetStatusText('retrieving databases')
frame = MyDBFrame(self, "Select Database", self.txt_s.GetValue())
frame.Show(True)
self.SetStatusText('')
self.UnBusy()
def Load(self, evt):
dlg = wx.FileDialog(self.panel, "Open configuration file",
self.path, self.filename,
"Config Files (*.cfg)|*.cfg",
wx.OPEN | wx.HIDE_READONLY)
if dlg.ShowModal() == wx.ID_OK:
self.filename = dlg.GetPath()
self.ReadFile()
self.SetTitle(self.title + ' -- ' + self.filename)
dlg.Destroy()
def Save(self, evt):
dlg = wx.FileDialog(self.panel, "Save configuration file",
self.path, self.filename,
"Config Files (*.cfg)|*.cfg",
wx.SAVE | wx.HIDE_READONLY)
if dlg.ShowModal() == wx.ID_OK:
self.filename = dlg.GetPath()
self.WriteFile()
self.SetTitle(self.title + ' -- ' + self.filename)
dlg.Destroy()
def SaveRecords(self, evt):
dlg = wx.FileDialog(self.panel, "Save Records to file",
self.path, repstring(self.myview, '\\') + '.csv',
"CSV files (*.csv)|*.csv| "
"Text Files (*.txt)|*.txt",
wx.SAVE | wx.HIDE_READONLY)
if dlg.ShowModal() == wx.ID_OK:
self.recfilename = dlg.GetPath()
self.WriteRecords()
dlg.Destroy()
def ReadFile(self):
try:
fd = open(self.filename, 'r')
self.myserver = fd.readline()[:-1]
self.mydb = fd.readline()[:-1]
self.myview = fd.readline()[:-1]
self.delimiter = fd.readline()[:-1]
fd.close()
self.txt_s.SetValue(self.myserver)
self.txt_db.SetValue(self.mydb)
self.txt_v.SetValue(self.myview)
self.txt_d.SetValue(self.delimiter)
except:
pass
def WriteFile(self):
fd = open(self.filename, 'w')
fd.write(self.txt_s.GetValue() + '\n')
fd.write(self.txt_db.GetValue() + '\n')
fd.write(self.txt_v.GetValue() + '\n')
fd.write(self.txt_d.GetValue() + '\n')
fd.close()
def WriteRecords(self):
fd = open(self.recfilename, 'w')
for line in self.GetRecords():
fd.write(line + '\n')
fd.close()
def GetRecords(self):
self.SetStatusText('retrieving records')
delimiter = self.txt_d.GetValue()
dbserver = self.txt_s.GetValue()
dbname = self.txt_db.GetValue()
dbview = self.txt_v.GetValue()
db = lotus.session.GetDatabase(dbserver, dbname)
view = db.GetView(dbview)
lines = []
header = ''
for cValue in view.Columns:
for ch in cValue.Title:
header += chr(ord(ch) & 0177)
header += delimiter
lines.append(header[:-len(delimiter)])
for doc in lotus.iterateDocuments(view):
line = ''
for cValue in doc.ColumnValues:
if(isinstance(cValue, type(()))
or isinstance(cValue, type([]))):
# sub-delimited field
for subValue in cValue:
line += str(subValue) + ';'
line = line[:-1]
elif (isinstance(cValue, type(0))
or isinstance(cValue, type(0.0))):
# number
line += str(cValue)
elif (isinstance(cValue, type(''))
or isinstance(cValue, type(u''))):
# standard str or unicode
for ch in sanestring(cValue):
if ch != delimiter:
line += chr(ord(ch) & 0177)
else:
line += str(cValue)
line += delimiter
lines.append(line[:-len(delimiter)])
self.SetStatusText('')
return lines
def Preview(self, evt):
self.Busy()
frame = MyPreviewFrame(self, "Preview window", self.GetRecords())
frame.Show(True)
self.UnBusy()
def SelectView(self, evt):
self.Busy()
self.SetStatusText('retrieving views')
frame = MyViewFrame(self, "Select View",
self.txt_s.GetValue(), self.txt_db.GetValue())
frame.Show(True)
self.SetStatusText('')
self.UnBusy()
def Exit(self, evt):
self.Close()
class MyApp(wx.App):
def OnInit(self):
frame = MyMainFrame(None, "NotesView utility")
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp(False)
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment