简体   繁体   中英

wxpython text editor status bar update

I am using wxpython for Python 2.7. I am working on a text editor, but have encountered a problem with the status bar.

I want my status bar to have Line xx, Column xx . However, I have only found a way to update it using a key press, for when the user is typing. I also want the user to be able to click around and see their cursor position within the text editor. I have tried self.control.Bind(wx.EVT_LEFT_DOWN, self.UpdateLineCol) . When I run this, it seems to have rebound the left mouse button, so I can't click around.

My UpdateLineCol code is as follows:

def UpdateLineCol(self, e):
    line = self.control.GetCurrentLine() + 1
    col = self.control.GetColumn(self.control.GetCurrentPos())
    stat = 'Line %s, Column %s' % (line, col)
    self.StatusBar.SetStatusText(stat, 0)

How can I bind the left mouse button to update the status bar but also let me click around with the cursor?

You need to call event.Skip() to allow normal processing to happen after your function.

def UpdateLineCol(self, e):
    line = self.control.GetCurrentLine() + 1
    col = self.control.GetColumn(self.control.GetCurrentPos())
    stat = 'Line %s, Column %s' % (line, col)
    self.StatusBar.SetStatusText(stat, 0)
    e.Skip()

See: https://wxpython.org/docs/api/wx.MouseEvent-class.html

EVT_LEFT_DOWN Left mouse button down event. The handler of this event should normally call event.Skip() to allow the default processing to take place as otherwise the window under mouse wouldn't get the focus.

edit: Your traceback:

  File "editor.py", line 211, in <module>
    frame = MainWindow(None, 'Avix')
  File "editor.py", line 103, in __init__
    self.UpdateLineCol(self)
  File "editor.py", line 208, in UpdateLineCol
    e.Skip()
  AttributeError: 'MainWindow' object has no attribute 'Skip'

specifies self.UpdateLineCol(self) what happened to self.UpdateLineCol(self,e) You are calling this function without the event as a parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM