Your suggestion is quite what I meant, Paul, however
I can't figure out why the following approach does not work (yet)
I
basically made a new object MyTextEditor, inside it I have a
StyledTextCtrl which I tried to set up for autocomplete (maybe there is
the mistake).
Inside the dForm, I include the MyTextEditor as the Editor for each column. All
seems to work, except for the autocomplete...
import os
import inspect
import dabo
import wx
import wx.grid
dabo.ui.loadUI("wx")
import dabo.dEvents as dEvents
import sys
import keyword
class MyTextEditor(wx.grid.PyGridCellEditor):
def __init__(self):
wx.grid.PyGridCellEditor.__init__(self)
def Create(self, parent, id, evtHandler):
self._tc = wx.stc.StyledTextCtrl(parent, id)
self.SetControl(self._tc)
self._tc.SetKeyWords(0, "banaan kiwi appel appelbloesem appelspijs
appelnogiets")
self._tc.autoComplete = True
self._tc.autoCompleteIncludeMagic = True
self._tc.autoCompleteIncludeSingle = True
self._tc.autoCompleteIncludeDouble = True
self._tc.autoCompleteCaseInsensitive = True
self._tc.AutoCompSetIgnoreCase(True)
self._tc.AutoCompSetAutoHide(True)
#self._tc.AutoCompStops(' .,;:([)]}\'"\\<>%^&+-=*/|`')
# Do we want to automatically pop up command argument help?
self._tc.autoCallTip = True
self._tc.SetWrapMode(True)
self._tc.SetUseVerticalScrollBar(False)
self._tc.SetUseHorizontalScrollBar(False)
self._tc.autoAutoComplete=True
#self._tc.SetWrapMode(False)
if evtHandler:
self._tc.PushEventHandler(evtHandler)
def SetSize(self, rect):
self._tc.SetDimensions(rect.x, rect.y, rect.width+2, rect.height+2,
wx.SIZE_ALLOW_MINUS_ONE)
def BeginEdit(self, row, col, grid):
self.startValue = grid.GetTable().GetValue(row, col)
self._tc.SetText(self.startValue)
self._tc.SetFocus()
def EndEdit(self, row, col, grid):
changed = False
val = self._tc.GetText()
if val != self.startValue:
changed = True
grid.GetTable().SetValue(row, col, val) # update the table
self.startValue = ''
self._tc.SetText('')
return changed
def StartingKey(self, evt):
key = evt.GetKeyCode()
ch = None
if key in (wx.WXK_NUMPAD0, wx.WXK_NUMPAD1, wx.WXK_NUMPAD2,
wx.WXK_NUMPAD3, wx.WXK_NUMPAD4, wx.WXK_NUMPAD5,
wx.WXK_NUMPAD6, wx.WXK_NUMPAD7, wx.WXK_NUMPAD8,
wx.WXK_NUMPAD9):
ch = ch = chr(ord('0') + key - wx.WXK_NUMPAD0)
elif key < 256 and key >= 0 and chr(key) in string.printable:
ch = chr(key)
print 'key="%s" ch="%s" shift="%s"' % (key,ch,evt.ShiftDown())
if not evt.ShiftDown():
ch = ch.lower()
if ch is not None:
# For this example, replace the text. Normally we would append it.
#self._tc.AppendText(ch)
self._tc.SetText(ch)
else:
evt.Skip()
def Reset(self):
self._tc.SetText(self.startValue)
def Destroy(self):
self.base_Destroy()
def Clone(self):
return MyTextEditor()
class dForm_9755569939(dabo.ui.dForm):
def __init__(self, parent=None, attProperties={u'code-ID':
u'dForm-top', u'CxnFile': u'./oww.cnxml', u'Caption': u'Dabo Class
Designer', u'Top': u'25', u'Height': u'550', u'Width': u'570',
'NameBase': u'dForm', u'CxnName': u'[EMAIL PROTECTED]', u'Left': u'35'},
*args, **kwargs):
super(dForm_9755569939, self).__init__(parent=parent,
attProperties=attProperties, *args, **kwargs)
self.Sizer = None
parentStack = []
sizerDict = {}
currParent = self
currSizer = None
sizerDict[currParent] = []
obj = dabo.ui.dSizer(Orientation='Vertical')
if currSizer:
currSizer.append(obj)
currSizer.setItemProps(obj, {})
if currSizer:
sizerDict[currParent].append(currSizer)
currSizer = obj
if not currParent.Sizer:
currParent.Sizer = obj
obj = dabo.ui.dPanel(currParent, attProperties={})
if currSizer:
currSizer.append(obj)
currSizer.setItemProps(obj, {'Proportion': 1, 'HAlign': 'Center',
'VAlign': 'Middle', 'Expand': True})
parentStack.append(currParent)
sizerDict[currParent].append(currSizer)
currParent = obj
currSizer = None
if not sizerDict.has_key(currParent):
sizerDict[currParent] = []
obj = dabo.ui.dSizer(Orientation='Vertical')
if currSizer:
currSizer.append(obj)
currSizer.setItemProps(obj, {})
if currSizer:
sizerDict[currParent].append(currSizer)
currSizer = obj
if not currParent.Sizer:
currParent.Sizer = obj
obj = self.getCustControlClass('dGrid_9754569795')(currParent)
if currSizer:
currSizer.append(obj)
currSizer.setItemProps(obj, {'Proportion': 1, 'Expand': True})
parentStack.append(currParent)
sizerDict[currParent].append(currSizer)
currParent = obj
sizerDict[currParent] = []
col = dabo.ui.dColumn(obj, attProperties={u'Caption': u'id',
u'Order': u'0', u'Editable': u'True', u'DataField': u'id', u'Width':
u'108'})
col.CustomEditorClass = MyTextEditor
obj.addColumn(col)
col = dabo.ui.dColumn(obj, attProperties={u'Caption':
u'omschrijving', u'Order': u'10', u'Editable': u'True', u'DataField':
u'omschrijving', u'Width': u'108'})
col.CustomEditorClass = MyTextEditor
obj.addColumn(col)
col = dabo.ui.dColumn(obj, attProperties={u'Caption':
u'prijs_incl_btw', u'Order': u'20', u'Editable': u'True', u'DataField':
u'prijs_incl_btw', u'Width': u'108'})
col.CustomEditorClass = MyTextEditor
obj.addColumn(col)
col = dabo.ui.dColumn(obj, attProperties={u'Caption':
u'productnaam', u'Order': u'30', u'Editable': u'True', u'DataField':
u'productnaam', u'Width': u'108'})
col.CustomEditorClass = MyTextEditor
obj.addColumn(col)
currParent = parentStack.pop()
if not sizerDict.has_key(currParent):
sizerDict[currParent] = []
currSizer = None
else:
try:
currSizer = sizerDict[currParent].pop()
except (KeyError, IndexError):
pass
obj = dabo.ui.dPanel(currParent, attProperties={})
if currSizer:
currSizer.append(obj)
currSizer.setItemProps(obj, {'Proportion': 0})
obj = dabo.ui.dSizer(Orientation='Horizontal')
if currSizer:
currSizer.append(obj)
currSizer.setItemProps(obj, {'Expand': True})
if currSizer:
sizerDict[currParent].append(currSizer)
currSizer = obj
if not currParent.Sizer:
currParent.Sizer = obj
obj = self.getCustControlClass('dButton_9749569813')(currParent)
if currSizer:
currSizer.append(obj)
currSizer.setItemProps(obj, {'HAlign': 'Center', 'VAlign':
'Middle'})
obj = self.getCustControlClass('dButton_9750569847')(currParent)
if currSizer:
currSizer.append(obj)
currSizer.setItemProps(obj, {'HAlign': 'Center', 'VAlign':
'Middle'})
obj = dabo.ui.dButton(currParent, attProperties={u'Caption': u'Button',
'NameBase': u'dButton2'})
if currSizer:
currSizer.append(obj)
currSizer.setItemProps(obj, {'HAlign': 'Center', 'VAlign':
'Middle'})
if sizerDict[currParent]:
try:
currSizer = sizerDict[currParent].pop()
except (KeyError, IndexError):
pass
else:
currSizer = None
if sizerDict[currParent]:
try:
currSizer = sizerDict[currParent].pop()
except (KeyError, IndexError):
pass
else:
currSizer = None
currParent = parentStack.pop()
if not sizerDict.has_key(currParent):
sizerDict[currParent] = []
currSizer = None
else:
try:
currSizer = sizerDict[currParent].pop()
except (KeyError, IndexError):
pass
if sizerDict[currParent]:
try:
currSizer = sizerDict[currParent].pop()
except (KeyError, IndexError):
pass
else:
currSizer = None
def createBizobjs(self):
class Product_TabelBizobj(dabo.biz.dBizobj):
def afterInit(self):
self.DataSource = "product_tabel"
self.KeyField = "id"
self.addFrom("product_tabel")
self.addField("prijs_incl_btw")
self.addField("productnaam")
self.addField("id")
self.addField("omschrijving")
def validateRecord(self):
"""Returning anything other than an empty string from
this method will prevent the data from being saved.
"""
ret = ""
# Add your business rules here.
return ret
product_tabelBizobj = Product_TabelBizobj(self.Connection)
self.addBizobj(product_tabelBizobj)
self.requery()
def getCustControlClass(self, clsName):
# Define the classes, and return the matching class
class dGrid_9754569795(dabo.ui.dGrid):
def __init__(self, parent=None, attProperties={u'code-ID':
u'dGrid-dPanel', u'SelectionMode': u'Cell', u'DataSource':
u'product_tabel'}, *args, **kwargs):
dabo.ui.dGrid.__init__(self, parent=parent,
attProperties=attProperties, *args, **kwargs)
class dButton_9749569813(dabo.ui.dButton):
def __init__(self, parent=None, attProperties={u'code-ID':
u'dButton-dPanel', u'Caption': u'New'}, *args, **kwargs):
dabo.ui.dButton.__init__(self, parent=parent,
attProperties=attProperties, *args, **kwargs)
def onHit(self, evt):
self.Form.new()
class dButton_9750569847(dabo.ui.dButton):
def __init__(self, parent=None, attProperties={u'code-ID':
u'dButton-dPanel-495', u'Caption': u'Save', 'NameBase': u'dButton1'},
*args, **kwargs):
dabo.ui.dButton.__init__(self, parent=parent,
attProperties=attProperties, *args, **kwargs)
def onHit(self, evt):
self.Form.save()
return eval(clsName)
def main():
app = dabo.dApp()
curdir = os.getcwd()
# Get the current location's path
fname = inspect.getfile(main)
pth = os.path.split(fname)[0]
if pth:
# Switch to that path
os.chdir(pth)
app.MainFormClass = dForm_9755569939
app.start()
# Return to the original location
os.chdir(curdir)
if __name__ == '__main__':
main()
__
Freagel.
> Date: Tue, 5 Aug 2008 15:10:34 -0500
> From: [EMAIL PROTECTED]
> To: [email protected]
> Subject: Re: [dabo-users] On the fly auto-complete linked to database
>
> fv sdfsaer wrote:
> > I really want database completion.
> >
> -----------------------------------------------------------
> I've been working on such.
>
> Thanks to Ed and Paul and the rest of the list the past few days, I have
> this working the way I want.
>
> Please excuse my lack of Python and Dabo skill and knowledge but maybe
> this will give you some direction.
>
> I have a table in PostgreSQL the ILIKE in the setWhereClause below is a
> case-insensitive match.
>
> I have a form.
> On that form I have
> -------------------------------------------------------------
> TEXTBOX1 TEXTBOX2
>
> LISTBOX (Could be list control or grid)
>
> Sizer with the Record detail.
> Label Textbox
> Label Textbox
> Label Textbox
> etc.
> -------------------------------------------------------------
> I used the data control wizard in class designer to auto generate
> the labels and textboxes in this field.
> They are bound to the bizObj in the wizard.
> So when you click on a list selection it will update
> these fields.
>
> I have a onMouseLeftUp and a onMouseLeftDoubleClick.
> The onMouseLeftUp is while I am browsing for a record.
> The onMouseDoubleClick is when I want to process what I have selected.
>
> -----------------------------------------------------
> TEXTBOX1 is what you want to auto browse(complete).
> regID = txtGenericName
>
> TEXTBOX2 is disabled but will contain table primary key.
> regID = txtGENERICID
>
> LISTBOX regID lstbxGenericProduct
>
> The 2 Text Boxes are not bound to a database.
>
> Watch for email line wrap in the code below.
>
> In the following example bizGenericProduct is defined as:
> ---------------------------------------------------------
> Publicalchemy_Generic_ProductBizobj(dabo.biz.dBizobj):
> def afterInit(self):
> self.DataSource = "public.alchemy_generic_product"
> self.KeyField = "genericproductid"
> self.addFrom("public.alchemy_generic_product")
> self.addField("genericproductid")
> self.addField("synonym")
> self.addField("name")
>
> def validateRecord(self):
> """Returning anything other than an empty string from
> this method will prevent the data from being saved.
> """
> ret = ""
> # Add your business rules here.
> return ret
>
> publicalchemy_generic_productBizobj =
> Publicalchemy_Generic_ProductBizobj(self.Connection)
> self.addBizobj(publicalchemy_generic_productBizobj)
>
>
>
> TEXTBOX1 method as follows:
> ----------------------------
> def onKeyUp(self, evt):
> # print self.Value
> if self.Value <> None:
> bizGenericProduct =
> self.Form.getBizobj("public.alchemy_generic_product")
> bizGenericProduct.setWhereClause("name ilike '%%%s%%'" %
> self.Value)
> bizGenericProduct.setOrderByClause("name")
> bizGenericProduct.requery()
> dsGenericProduct =
> bizGenericProduct.getDataSet(flds=("genericproductid", "name"))
> # print dsGenericProduct
> if dsGenericProduct:
> self.Form.lstbxGenericProductName.Choices =
> [rec["name"] for rec in
> dsGenericProduct]
> self.Form.lstbxGenericProductName.Keys =
> [rec["genericproductid"]
> for rec in dsGenericProduct]
> else:
> self.Form.lstbxGenericProductName.Keys = [""]
> self.Form.lstbxGenericProductName.Choices = [""]
> self.Form.lstbxGenericProductName.refresh()
>
> LISTBOX method as follows:
> --------------------------
>
> def onMouseLeftDoubleClick(self, evt):
> self.Form.txtGenericName.Value = self.Value
> self.ValueMode = "Key"
> self.Form.txtGenericID.Value = self.Value
> self.ValueMode = "String"
> self.Form.refresh()
>
> try:
> cNum = str(int(self.Form.txtGenericID.Value))
> except:
> cNum = 0
>
> if cNum <> 0:
> bizCompanyZ =
> self.Form.getBizobj("public.alchemy_generic_product")
> abc = bizCompanyZ.seek(self.Form.txtGenericID.Value,
> "genericproductid")
> self.Form.update()
> # Add other code processing selection here
>
> ---------------------------------------------------------------------------
> def onMouseLeftUp(self, evt):
> self.Form.txtGenericName.Value = self.Value
> self.ValueMode = "Key"
> self.Form.txtGenericID.Value = self.Value
> self.ValueMode = "String"
> self.Form.refresh()
>
> try:
> cNum = str(int(self.Form.txtGenericID.Value))
> except:
> cNum = 0
>
> if cNum <> 0:
> bizCompanyZ =
> self.Form.getBizobj("public.alchemy_generic_product")
> abc = bizCompanyZ.seek(self.Form.txtGenericID.Value,
> "genericproductid")
> self.Form.update()
> --------------------------------------------------------------------------
>
> See if this is similiar to what you are asking for.
> I will try to answer your questions.
>
>
> Paul McNary
> [EMAIL PROTECTED]
>
>
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/%(messageid)s