I am working on an IDE for a specific language. One of the features that I want to implement is syntax high-lighting.

The way I plan to go about it:
When the user presses a key, a function is called with the entire line that the user is editing
as an argument. This function will parse the argument and return a value with proper
highlighting.

Anyway, the issue I am running into right now is that I am unable to determine a line
number that the use is editing. I have a TextCtrl (editor) created on line 21 with a method (self.OnWrite) bound
to it via the EVT_CHAR event.

I was unable to get the line information from the event, so I searched the TextCtrl
attributes -- I am unable to find it there either.

Simply stated: How can I get the current line number that a user is editing in a TextCtrl.

Full Source Code:

#mSLIDE
import wx

#CONSTANTS
#Version Number
mSLIDE_VERSION='.1'

#Set up IDs for Menubar
ID_F_NEW=101
ID_F_OPEN=102
ID_F_SAVE=103
ID_F_SAVEAS=104
ID_F_PRINT=105
ID_F_EXIT=106
ID_H_ABOUT=201

class MainWindow(wx.Frame):
    def __init__(self,parent,id,title):
        wx.Frame.__init__(self,parent,wx.ID_ANY,title,size=(400,400),style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
        #Create the text control
        self.editor=wx.TextCtrl(self,1,style=wx.TE_MULTILINE)
        #Statusbar
        self.CreateStatusBar()
        #Menubar
        filemenu=wx.Menu()
        filemenu.Append(ID_F_NEW,'&New','Create new script')
        filemenu.Append(ID_F_OPEN,'&Open...','Open script')
        filemenu.Append(ID_F_SAVE,'&Save','Save script')
        filemenu.Append(ID_F_SAVEAS,'Save &As...','Save script as...')
        filemenu.AppendSeparator()
        filemenu.Append(ID_F_PRINT,'&Print','Print script')
        filemenu.AppendSeparator()
        filemenu.Append(ID_F_EXIT,'E&xit','Close mSLIDE')
        helpmenu=wx.Menu()
        helpmenu.Append(ID_H_ABOUT,'A&bout...','Information about mSLIDE')
        menubar=wx.MenuBar()
        menubar.Append(filemenu,'&File')
        menubar.Append(helpmenu,'&Help')
        self.SetMenuBar(menubar)
        #Event Handlers
        self.Bind(wx.EVT_MENU,self.OnExit,id=ID_F_EXIT)
        self.Bind(wx.EVT_MENU,self.OnAbout,id=ID_H_ABOUT)
        self.editor.Bind(wx.EVT_CHAR,self.OnWrite)
        #Show the frame
        self.Show(True)
        
    def OnAbout(self,event):
        d=wx.MessageDialog(self,'(mSLIDE) '+mSLIDE_VERSION,wx.OK|wx.ICON_INFORMATION)
        d.ShowModal()
        d.Destroy()
    def OnExit(self,event):
        self.Close(True)
    def OnWrite(self,event):
        event.Skip() #HELP
        
app=wx.PySimpleApp()
frame=MainWindow(None,-1,'mSLIDE')
app.MainLoop()

You could probably use GetInsertionPoint, along with GetRange, eg

line_number = len( self.editor.GetRange( 0, self.editor.GetInsertionPoint() ).split("\n") )

Thank you for your help. This completely solves my issue.

This question has already been answered. Start a new discussion instead.