def OnFileOpen(self, evt):
# This gives us a string suitable for the file dialog based on
# the file handlers that are loaded
wildcard, types = rt.RichTextBuffer.GetExtWildcard(save=False)
dlg = wx.FileDialog(self, "Choose a filename",
wildcard=wildcard,
style=wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
if path:
fileType = types[dlg.GetFilterIndex()]
self.rtc.LoadFile(path, fileType)
dlg.Destroy()
用上面代码为什么获得的wildcard只有.txt,只能打开.txt文档?
----------------------
Double行动:
原帖分数:30
加分:30
6 个解决方案
#1
你还希望打开什么文档?
#2
你可以自己指定类型:wildcard = "All files (*.*)|*.*"
#3
wildcard, types = rt.RichTextBuffer.GetExtWildcard(save=False)
我想知道为什么这个函数返回的wildcard只有*.txt呢?
我想知道为什么这个函数返回的wildcard只有*.txt呢?
#4
默认的吧,如果你装了demo,可以看看RichTextCtrl.py源码,初始化时调用几次rt.RichTextBuffer.AddHandler,所以open文件时有其它的格式可选,摘录一段代码如下,你把带AddHandler函数的那三行全注释掉后,open时就像你的情况只一个.txt格式。
def AddRTCHandlers(self):
# make sure we haven't already added them.
if rt.RichTextBuffer.FindHandlerByType(rt.RICHTEXT_TYPE_HTML) is not None:
return
# This would normally go in your app's OnInit method. I'm
# not sure why these file handlers are not loaded by
# default by the C++ richtext code, I guess it's so you
# can change the name or extension if you wanted...
rt.RichTextBuffer.AddHandler(rt.RichTextHTMLHandler())
rt.RichTextBuffer.AddHandler(rt.RichTextXMLHandler())
# ...like this
rt.RichTextBuffer.AddHandler(rt.RichTextXMLHandler(name="Other XML",
ext="ox",
type=99))
# This is needed for the view as HTML option since we tell it
# to store the images in the memory file system.
wx.FileSystem.AddHandler(wx.MemoryFSHandler())
#5
如果我要加载.lua文件,但并没有对应的handler,要怎么做呢?
#6
听过有个第三方模块是把wx.RichTextCtrl保存成rtf文件,你网搜一下,看看是咋实现的...
#1
你还希望打开什么文档?
#2
你可以自己指定类型:wildcard = "All files (*.*)|*.*"
#3
wildcard, types = rt.RichTextBuffer.GetExtWildcard(save=False)
我想知道为什么这个函数返回的wildcard只有*.txt呢?
我想知道为什么这个函数返回的wildcard只有*.txt呢?
#4
默认的吧,如果你装了demo,可以看看RichTextCtrl.py源码,初始化时调用几次rt.RichTextBuffer.AddHandler,所以open文件时有其它的格式可选,摘录一段代码如下,你把带AddHandler函数的那三行全注释掉后,open时就像你的情况只一个.txt格式。
def AddRTCHandlers(self):
# make sure we haven't already added them.
if rt.RichTextBuffer.FindHandlerByType(rt.RICHTEXT_TYPE_HTML) is not None:
return
# This would normally go in your app's OnInit method. I'm
# not sure why these file handlers are not loaded by
# default by the C++ richtext code, I guess it's so you
# can change the name or extension if you wanted...
rt.RichTextBuffer.AddHandler(rt.RichTextHTMLHandler())
rt.RichTextBuffer.AddHandler(rt.RichTextXMLHandler())
# ...like this
rt.RichTextBuffer.AddHandler(rt.RichTextXMLHandler(name="Other XML",
ext="ox",
type=99))
# This is needed for the view as HTML option since we tell it
# to store the images in the memory file system.
wx.FileSystem.AddHandler(wx.MemoryFSHandler())
#5
如果我要加载.lua文件,但并没有对应的handler,要怎么做呢?
#6
听过有个第三方模块是把wx.RichTextCtrl保存成rtf文件,你网搜一下,看看是咋实现的...