I'm stuck, TextCtrl jumps to bottom of table

I have a simple open dbf file to
textctrl. I’m not able to append the entire dbf to the control. I only see the
last row.

I’ve tried implementing
GetSelection, CallAfter and Windows Styles to display the entire db. Any advice
would be greatly

appreciated.

2.8.12.1 (msw-unicode) on Windows7

attached is a 38 row dbf

import os
import sys
import wx
import datetime
from mx import DateTime
from xlwt import Workbook, easyxf
from dbfpy import dbf
import dbfpy.dbf
from dbf import *

class MainFrame(wx.Frame):
def init(self):
#Start the frame
wx.Frame.init(self,None,wx.ID_ANY,title=‘hello world’)
#Declare Sizers
self.hbox = wx.BoxSizer()
self.vbox= wx.BoxSizer(wx.VERTICAL)
#TextCtrl
self.menu = wx.MenuBar()
self.file = wx.Menu()

 self.SetMenuBar(self.menu)

 self.menu.Append(self.file,'&File')
 self.openitem = self.file.Append(wx.ID_ANY,'Open')
 self.Bind(wx.EVT_MENU,self.openevent,self.openitem)

 self.background = wx.Panel(self)
 self.text = wx.TextCtrl(self.background,style=wx.PROCESS_ENTER)
 self.text.Bind(wx.EVT_TEXT_ENTER,self.transevent)
 self.dbtext = wx.TextCtrl(self.background,style = wx.TE_MULTILINE|wx.TE_RICH|wx.TE_NOHIDESEL)

 #Button
 self.buthello = wx.Button(self.background,wx.ID_ANY,label = 'Export')
 self.buthello.Bind(wx.EVT_LEFT_DOWN,self.transevent)
 #Setting up the sizers

 self.hbox.Add(self.text,proportion = 1,border=0)
 self.hbox.Add(self.buthello,proportion =0,border=0)

 self.vbox.Add(self.hbox,proportion = 0,flag = wx.EXPAND,border=0)
 self.vbox.Add(self.dbtext,proportion=1,flag = wx.EXPAND,border=0)

 self.background.SetSizer(self.vbox)
 self.Show()
 wx.CallAfter(self.dbtext, None)

def openevent(self,event):
self.dirname=""
dlg = wx.FileDialog(self, “Choose a file to open”, self.dirname, “”, “.”, wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.filename = dlg.GetFilename()
self.dirname = dlg.GetDirectory()

        self.pathname = dlg.GetPath()
        f = open(os.path.join(self.dirname, self.filename), 'r')
        db = dbf.Dbf(self.pathname)
        for text in db:
            font1 = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Courier New')
            self.dbtext.SetFont(font1)

            self.dbtext.SetLabel(f.read())
            self.dbtext.GetSelection()
            self.dbtext.AppendText(str(text))
        f.close
    dlg.Destroy()

def transevent(self,event):
pass

app = wx.App(redirect=False)
frame = MainFrame()
app.MainLoop()

address38.dbf (7.63 KB)

georgemccown@gmail.com wrote:

I have a simple open dbf file to textctrl. I'm not able to append the
entire dbf to the control. I only see the last row.

I've tried implementing GetSelection, CallAfter and Windows Styles to
display the entire db. Any advice would be greatly

appreciated.

2.8.12.1 (msw-unicode) on Windows7

self.pathname = dlg.GetPath()
f = open(os.path.join(self.dirname, self.filename), 'r')
db = dbf.Dbf(self.pathname)
for text in db:
font1 = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Courier New')
self.dbtext.SetFont(font1)

self.dbtext.SetLabel(f.read())
self.dbtext.GetSelection()
self.dbtext.AppendText(str(text))
f.close

SetLabel in 2.8 is basically the same as SetValue, so after the first time that you iterate through that loop (and so the current position of the file pointer in f is at the end of the file) then you are first going to set the value to "" and then appending whatever is in text. Take out that SetLabel and it will probably do what you want.

···

--
Robin Dunn
Software Craftsman

I did. I’m thinking the AppendText holds all the file. These two corrected the append.

            self.dbtext.AppendText(f.read())
            self.dbtext.WriteText(str(text))
···

On Wednesday, July 17, 2013 9:59:38 PM UTC-5, Robin Dunn wrote:

george...@gmail.com wrote:

I have a simple open dbf file to textctrl. I’m not able to append the

entire dbf to the control. I only see the last row.

I’ve tried implementing GetSelection, CallAfter and Windows Styles to

display the entire db. Any advice would be greatly

appreciated.

2.8.12.1 (msw-unicode) on Windows7

self.pathname = dlg.GetPath()

f = open(os.path.join(self.dirname, self.filename), ‘r’)

db = dbf.Dbf(self.pathname)

for text in db:

font1 = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u’Courier New’)

self.dbtext.SetFont(font1)

self.dbtext.SetLabel(f.read())

self.dbtext.GetSelection()

self.dbtext.AppendText(str(text))

f.close

SetLabel in 2.8 is basically the same as SetValue, so after the first
time that you iterate through that loop (and so the current position of
the file pointer in f is at the end of the file) then you are first
going to set the value to “” and then appending whatever is in text.
Take out that SetLabel and it will probably do what you want.


Robin Dunn

Software Craftsman

http://wxPython.org