def create_view(): global frame global app app = wx.App(False) frame = wx.Frame(None) view = WXTextView(frame, -1) view.model = text
def on_char(self, event): keycode = event.GetKeyCode() ctrl = event.ControlDown() shift = event.ShiftDown() if keycode == wx.WXK_RETURN and shift and not ctrl: try: self.execute() except NotFound: pass else: _WXTextView.on_char(self, event)
def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0): _WXTextView.__init__(self, parent, id=id, pos=pos, size=size, style=style)
def insert(self, i, textmodel): needscell = True try: i0, cell = self.find_cell() if not (i == i0 or i == i0 + len(cell)): needscell = False except NotFound: pass try: find_cell(textmodel.texel, 0) hascell = True except NotFound: hascell = False if needscell and not hascell: cell = Cell([], []) info = self.model.insert(i, mk_textmodel(cell)) i = i + 1 _WXTextView.insert(self, i, textmodel)
import sys sys.path.insert(0, '..') from textmodel import TextModel from wxtextview import WXTextView import wx model = TextModel(u'Hello World!') model.set_properties(6, 11, fontsize=14) model.set_properties(6, 11, bgcolor='yellow') app = wx.App() frame = wx.Frame(None) view = WXTextView(frame, -1) view.model = model view.cursor = 5 view.selection = 0, 5 frame.Show() app.MainLoop()
model.set_properties(0, 11, bgcolor='yellow') instructions = """ You can edit this text as you like. Undo is ctrl-z and redo ctrl-r. The second window displays exactly the same text and follows the changes. """ model.insert(len(model), TextModel(instructions)) # display the texmodel in a view frame = wx.Frame(None) view = WXTextView(frame) view.model = model frame.Show() # set cursor and selection view.index = 5 view.selection = 0, 5 # display the same textmodel in a second view frame2 = wx.Frame(None) view2 = WXTextView(frame2) view2.model = model frame2.Show() app.MainLoop()
# colorize demo import sys sys.path.insert(0, '..') sys.path.insert(0, '../../textmodel') from textmodel import TextModel from wxtextview import WXTextView import wx app = wx.App(redirect = False) frame = wx.Frame(None) win = wx.Panel(frame) view = WXTextView(win) box = wx.BoxSizer(wx.VERTICAL) box.Add(view, 1, wx.ALL|wx.GROW, 1) win.SetSizer(box) win.SetAutoLayout(True) from textmodel.textmodel import pycolorize filename = '../wxtextview/textview.py' rawtext = open(filename).read() model = pycolorize(rawtext) view.set_model(model) frame.Show() app.MainLoop()
# colorize demo import sys sys.path.insert(0, '..') from textmodel import TextModel from wxtextview import WXTextView import wx app = wx.App(redirect=False) frame = wx.Frame(None) win = wx.Panel(frame, -1) view = WXTextView(win, -1, style=wx.SUNKEN_BORDER) box = wx.BoxSizer(wx.VERTICAL) box.Add(view, 1, wx.ALL | wx.GROW, 1) win.SetSizer(box) win.SetAutoLayout(True) from textmodel.textmodel import pycolorize filename = '../wxtextview/textview.py' rawtext = open(filename).read() model = pycolorize(rawtext) view.set_model(model) frame.Show() app.MainLoop()
import sys sys.path.insert(0, '..') sys.path.insert(0, '../../textmodel') from textmodel import TextModel from wxtextview import WXTextView import wx model = TextModel(u'Hello World!') model.set_properties(6, 11, fontsize=14) model.set_properties(6, 11, bgcolor='yellow') app = wx.App() frame = wx.Frame(None) view = WXTextView(frame, -1) view.model = model view.index = 5 view.selection = 0, 5 frame.Show() app.MainLoop()