Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用wxpython时,如何在StyledTextCtrl中创建可用的多个游标?_Python_Wxpython_Wxstyledtextctrl - Fatal编程技术网

使用wxpython时,如何在StyledTextCtrl中创建可用的多个游标?

使用wxpython时,如何在StyledTextCtrl中创建可用的多个游标?,python,wxpython,wxstyledtextctrl,Python,Wxpython,Wxstyledtextctrl,我想将多光标功能添加到我的wxpython应用程序中。我正在使用StyledTextCtrl作为文本控件。我已经让它看起来像多个光标,见下图。但是,当我键入文本时,前两个光标刚好消失,文本被插入到最后一个光标位置。有人能帮我吗?我已经附上了我的代码 C:\Windows\system32>python --version Python 3.7.0 C:\Windows\system32>pip list Package Version ----------- -------

我想将多光标功能添加到我的wxpython应用程序中。我正在使用
StyledTextCtrl
作为文本控件。我已经让它看起来像多个光标,见下图。但是,当我键入文本时,前两个光标刚好消失,文本被插入到最后一个光标位置。有人能帮我吗?我已经附上了我的代码

C:\Windows\system32>python --version
Python 3.7.0

C:\Windows\system32>pip list
Package     Version
----------- ---------
altgraph    0.15
cffi        1.11.5
future      0.16.0
macholib    1.9
pefile      2017.11.5
pip         18.0
pycparser   2.18
PyInstaller 3.3.1
pypiwin32   223
Pypubsub    4.0.0
PyQt5       5.11.2
PyQt5-sip   4.19.12
pyqtdeploy  2.1
pyqtkeybind 0.0.3
pywin32     223
setuptools  39.0.1
six         1.11.0
wxPython    4.0.3
xcffib      0.6.0

C:\Windows\system32>


更新: 我想要实现的是一个多光标编辑功能,它存在于许多流行的编辑器中。见下图:


代码中似乎没有插入符号或光标定位的引用。你想用这个“多光标”的想法实现什么?嗨@RolfofSaxony,我更新了我的问题并描述了我的意图。self.SetAdditionalSelectionTyping(True)哇,非常感谢Rolf!它起作用了。
import wx
import wx.stc as stc


class MyEditor(stc.StyledTextCtrl):
    def __init__(self, parent, size=wx.DefaultSize, style=0):
        stc.StyledTextCtrl.__init__(self, parent, size=size, style=style)
        self.SetCaretLineVisible(True)

        font = wx.Font(20, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, 'Courier New')
        self.StyleSetFont(stc.STC_STYLE_DEFAULT, font)

        self.SetText(
            # @formatter:off
"""aaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbb
cccccccccccccccccc
dddddddddddddddddd
eeeeeeeeeeeeeeeeee
ffffffffffffffffff
gggggggggggggggggg""")
# @formatter:on
        self.SetCaretWidth(20)
        self.SetScrollWidth(1100)
        self.SetCaretForeground('red')

    def test(self, event):
        self.SetSelection(0, 0)
        self.AddSelection(3, 10)
        self.AddSelection(20, 40)
        self.SetFocus()

class MyFrame(wx.Frame):
    def __init__(self, parent):
        super(MyFrame, self).__init__(parent)
        self.InitUI()

    def InitUI(self):
        panel = wx.Panel(self)

        main_sizer = wx.BoxSizer(wx.VERTICAL)
        self._elements_sizer = main_sizer
        self._elements_panel = panel

        editor = MyEditor(panel, style=wx.ALIGN_CENTER)
        main_sizer.Add(editor, 1, wx.EXPAND | wx.ALL, 10)
        self._editor = editor


        ##################################################
        buttons_panel = wx.Panel(panel)
        buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)

        b3 = wx.Button(buttons_panel, label="b3")
        b3.Bind(wx.EVT_BUTTON, editor.test)
        buttons_sizer.Add(b3, 0, wx.ALL & (~wx.TOP) & (~wx.BOTTOM) & (~wx.LEFT), 10)

        buttons_panel.SetSizer(buttons_sizer)

        main_sizer.Add(buttons_panel, 0, wx.ALL & (~wx.TOP) & (~wx.Bottom), 10)
        ###################################################

        self.SetSize(1200, 600)
        panel.SetSizerAndFit(main_sizer)

        self.SetTitle("test")

        self.Show(True)


if __name__ == '__main__':
    app = wx.App()
    MyFrame(None)
    app.MainLoop()