Programaticly moving cursor in multi-line edit control
"Igor Kaplan" <[email protected]> Thu, 14 Aug 2008 06:49:06 -0400
| Newsgroups | gmane.comp.python.windows-ce |
|---|---|
| Message-ID | <[email protected]> |
Hi Alexandre, Thanks a lot for your reply. I'll try to attach the source file to this message, however not sure if this mailing list allows attachments, so I have uploaded it also to my ftp side: ftp://ftp.uliy.com/pub/python/te.py I tried to run this file on the smartphone and on PocketPc, the same result. Was playing with OnOpen method detaching the Edit control from the frame, adding the text and attaching it again, still the same, cursor does not move. Would so much appreciate any comments. Igor. From: Alexandre Delattre <[email protected]> Subject: Re: [PythonCE] Programaticly moving cursor in multi-line edit control To: [email protected] Message-ID: <[email protected]> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Igor, From what you say, I don't see what you could have done wrong. can you send me the full source code so I can give a try ? Alexandre _______________________________________________ PythonCE mailing list [email protected] http://mail.python.org/mailman/listinfo/pythonce
te.py
(text/plain, 6.8 KB)
import ppygui as gui
import os
import rdebug
class MainFrame(gui.CeFrame):
# subclass to create our own main frame type
keyFlag = 0
filename = ''
defaultFolder = ''
startSelection = 0
endSelection = 0
def __init__(self):
gui.CeFrame.__init__(self, title="Text edit", menu="menu", action=("Clear", self.onClear))
self.MainMenu = gui.Menu()
self.FileMenu = gui.PopupMenu()
self.TextMenu = gui.PopupMenu()
self.EditMenu = gui.PopupMenu()
self.navigateMenu = gui.PopupMenu()
self.FileMenu.append("New", self.OnNew)
self.FileMenu.append("Open...", self.OnOpen)
self.FileMenu.append("Save", self.OnSave)
self.FileMenu.append("Save As...", self.OnSaveAs)
self.SymbolsMenu = gui.PopupMenu()
self.SymbolsMenu.append("''", self.OnApostrophi)
self.SymbolsMenu.append('[]', self.OnBrackets)
self.SymbolsMenu.append('<', self.OnLess)
self.SymbolsMenu.append('>', self.OnGreater)
self.SymbolsMenu.append('{}', self.OnBraces)
self.SymbolsMenu.append('=', self.OnEquals)
self.TextMenu.append_menu('Symbols', self.SymbolsMenu)
self.TextMenu.append("Cursor pos", self.OnCursorPosition)
self.EditMenu.append("Start Selection", self.OnStartSelection)
self.EditMenu.append("End Selection", self.OnEndSelection)
self.EditMenu.append("Select line", self.OnSelectLine)
self.EditMenu.append("Copy", self.OnCopy)
self.EditMenu.append("Paste", self.OnPaste)
self.EditMenu.append("Delete", self.OnDeleteSelection)
self.navigateMenu.append("Start of file", self.OnStartOfFile)
self.navigateMenu.append("End of file", self.OnEndOfFile)
self.navigateMenu.append("Home", self.OnHome)
self.navigateMenu.append("End", self.OnEnd)
self.cb_menu.append_menu("File", self.FileMenu)
self.cb_menu.append_menu("Edit", self.EditMenu)
self.cb_menu.append_menu("Navigate", self.navigateMenu)
self.cb_menu.append_menu("Text", self.TextMenu)
self.cb_menu.append("Exit", self.onExit)
self.text_entry = gui.Edit(self, multiline=True)
sizer = gui.VBox(border=(0,0,0,0), spacing=0)
sizer.add(self.text_entry)
self.sizer = sizer
self.text_entry.text = ""
self.text_entry.focus()
def onClear(self, x):
self.text_entry.text = ""
self.text_entry.bringtofront()
def onExit(self, x):
self.close()
def OnNew(self, x):
self.text_entry.text = ""
self.filename = 'untitled'
print "Window title: "+self.texte
self.text = U'Untitled'
def OnOpen(self, x):
self.filename = gui.FileDialog.open()
self.text = 'Please wait...'
fl = open(self.filename, 'r')
l = fl.readlines()
self.text_entry = None
self.text_entry = gui.Edit(self, multiline=True)
for i in l:
self.text_entry.append(i)
sizer = gui.VBox(border=(0,0,0,0), spacing=0)
sizer.add(self.text_entry)
self.sizer = sizer
fl.close()
l = []
self.defaultFolder = os.path.split(self.filename)[0]
self.text_entry.selection = 0, 0
self.text = self.filename
self.text_entry.update()
self.text_entry.focus()
def OnSave(self, x):
if self.filename == '':
self.filename = 'unnamed.txt'
if self.defaultFolder == '':
self.defaultFolder = '.'
self.filename = os.path.join(self.defaultFolder, self.filename)
fl = open(self.filename, "w")
fl.write(self.text_entry.text)
fl.close()
self.text_entry.focus()
def OnSaveAs(self, x):
self.filename = gui.FileDialog.save()
fl = open(self.filename, 'w')
fl.write(self.text_entry.text)
fl.close()
self.text_entry.focus()
def OnApostrophi(self, x):
selection = self.text_entry.selection
pos = selection[0]
self.text_entry.text = self.text_entry.text[:pos] + "''" + self.text_entry.text[pos:]
self.text_entry.selection = (selection[0]+2, selection[1]+2)
def OnBrackets(self, x):
selection = self.text_entry.selection
pos = selection[0]
self.text_entry.text = self.text_entry.text[:pos] + "[]" + self.text_entry.text[pos:]
self.text_entry.selection = (selection[0]+2, selection[1]+2)
def OnBraces(self, x):
selection = self.text_entry.selection
pos = selection[0]
self.text_entry.text = self.text_entry.text[:pos] + "{}" + self.text_entry.text[pos:]
self.text_entry.selection = (selection[0]+2, selection[1]+2)
def OnLess(self, x):
selection = self.text_entry.selection
pos = selection[0]
self.text_entry.text = self.text_entry.text[:pos] + "<" + self.text_entry.text[pos:]
self.text_entry.selection = (selection[0]+1, selection[1]+1)
def OnGreater(self, x):
selection = self.text_entry.selection
pos = selection[0]
self.text_entry.text = self.text_entry.text[:pos] + ">" + self.text_entry.text[pos:]
self.text_entry.selection = (selection[0]+1, selection[1]+1)
def OnEquals(self, x):
selection = self.text_entry.selection
pos = selection[0]
self.text_entry.text = self.text_entry.text[:pos] + "=" + self.text_entry.text[pos:]
self.text_entry.selection = (selection[0]+1, selection[1]+1)
def OnStartSelection(self, x):
self.startSelection = self.text_entry.selection[0]
self.text_entry.focus()
def OnEndSelection(self, x):
self.endSelection = self.text_entry.selection[0]
self.text_entry.selection = (self.startSelection, self.endSelection)
self.text_entry.focus()
def OnSelectLine(self, x):
start = self.text_entry.line_index(-1)
end = self.text_entry.line_index(-1) + self.text_entry.line_length(-1)
self.text_entry.selection = (start, end)
self.text_entry.focus()
def OnCopy(self, x):
self.text_entry.copy()
self.text_entry.focus()
def OnPaste(self, x):
self.text_entry.paste()
self.text_entry.focus()
def OnDeleteSelection(self, x):
self.text_entry.cut()
self.text_entry.focus()
def OnStartOfFile(self, x):
self.text_entry.selection = (0, 0)
self.text_entry.update()
self.text_entry.focus()
def OnEndOfFile(self, x):
eof = len(self.text_entry.text)
self.text_entry.selection = (eof, eof)
self.text_entry.focus()
def OnHome(self, x):
i = self.text_entry.line_index(-1)
self.text_entry.selection = (i, i)
self.text_entry.focus()
def OnEnd(self, x):
i = self.text_entry.line_index(-1) + self.text_entry.line_length(-1)
self.text_entry.selection = (i, i)
self.text_entry.focus()
def OnCursorPosition(self, x):
line = self.text_entry.line_from_char(-1)+1
col = self.text_entry.selection[0] - self.text_entry.line_index(-1)+1
msg = "Line: "+str(line) + " Col: " + str(col)
gui.Message.ok("Cursor position", msg)
self.text_entry.focus()
if __name__ == '__main__':
#rdebug.set_std('igor.txt', 'igor.err')
app = gui.Application()
app.mainframe = MainFrame()
app.run()
app.mainframe.text_entry.focus()