Ich hab echt keine Idee was das sein koennte, danke fuer die Hilfe!
Hier der Sourcecode:
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wx
import sys
import copy
print "Using wxPython %s" % wx.__version__
if int(wx.__version__.split(".")[1]) < 4:
print "Get a newer version of wxPython"
if not "win" in sys.platform.lower():
win = False
import wx.html
else:
Warning("Don't click into the browser window, it will cause a bug!\
\nClicking links will cause it as well!")
import wx.lib.iewin
win = True
def NotImplemented(event=None):
dlg = wx.MessageDialog(None, "This feature is not yet implemented", "Feature not available", wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
def Warning(text, event=None):
dlg = wx.MessageDialog(None, text, "WARNING", wx.OK | wx.ICON_WARNING)
dlg.ShowModal()
class MyFrame(wx.Frame):
def __init__(self):
self.filename = ""
self.opencopy = ""
# begin wxGlade: MyFrame.__init__
wx.Frame.__init__(self, parent=None, id=-1, title="wxHTML - The on-the-fly HTML editor!", pos=(0, 0), size=(800, 600))
if win:
Warning("Don't click into the browser window, it will cause a bug!\
\nClicking links will cause it as well!")
else:
Warning("Non-windows systems may have worse HTML parsing, sorry")
self.window_1 = wx.SplitterWindow(self, -1, style=wx.SP_3D|wx.SP_BORDER)
self.text_ctrl_1 = wx.TextCtrl(self.window_1, -1, "", style=wx.TE_MULTILINE)
if win:
self.window_2 = wx.lib.iewin.IEHtmlWindow(self.window_1, -1)
self.window_2.LoadString("")
else:
self.window_2 = wx.html.HtmlWindow(self.window_1, -1)
self.text_ctrl_1.Bind(wx.EVT_TEXT, self.ChangeText)
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.__do_layout()
self.__doMenus()
self.SetSize((800, 600))
#self.window_2.GoBack()
# end wxGlade
self.window_2.Bind(wx.EVT_SET_FOCUS, self.OnBrowserFocus)
def OnBrowserFocus(self, evt=None):
print "Browser got focus"
self.text_ctrl_1.SetFocus()
def OpenUrl(self, evt=None):
NotImplemented()
pass
def OnBack(self, evt=None):
#self.window_2.GoBack()
self.ChangeText()
#self.text_ctrl_1.SetFocus()
def ChangeText(self, evt=None):
#self.window_2.SetPage(self.text_ctrl_1.GetValue())
if win:
self.window_2.LoadString(self.text_ctrl_1.GetValue())
else:
self.window_2.SetPage(self.text_ctrl_1.GetValue())
self.text_ctrl_1.SetFocus()
def __doMenus(self):
""" Menu things starting """
menuBar = wx.MenuBar()
menu1 = wx.Menu()
menu1itmes = list()
menu1itmes.append(menu1.Append(-1, "&Open"))
menu1itmes.append(menu1.Append(-1, "&Save"))
menu1itmes.append(menu1.Append(-1, "E&xit"))
menu3 = wx.Menu()
menu3itmes = list()
menu3itmes.append(menu3.Append(-1, "&Back to your HTML"))
menu3itmes.append(menu3.Append(-1, "Open &Url"))
menu2 = wx.Menu()
menu2itmes = list()
menu2itmes.append(menu2.Append(-1, "&About"))
menuBar.Append(menu1, "&File")
menuBar.Append(menu2, "&Help")
menuBar.Append(menu3, "&Browser")
self.Bind(wx.EVT_MENU, self.OnOpen, menu1itmes[0])
self.Bind(wx.EVT_MENU, self.OnSave, menu1itmes[1])
self.Bind(wx.EVT_MENU, self.OnClose, menu1itmes[2])
self.Bind(wx.EVT_MENU, self.OnAbout, menu2itmes[0])
self.Bind(wx.EVT_MENU, self.OnBack, menu3itmes[0])
self.Bind(wx.EVT_MENU, self.OpenUrl, menu3itmes[1])
self.SetMenuBar(menuBar)
""" Menu things done """
def OnClose(self, evt=None):
if self.opencopy != self.text_ctrl_1.GetValue():
self.OnSave(text="You have unsaved changes")
self.Destroy()
def OnAbout(self, evt=None):
pass
def OnSave(self, event=None, text=None):
if not text:
text = "Choose file to save"
else:
text = text
wildcard = "HTML files (*.html)|*.html|" \
"HTML files (*.htm)|*.htm|" \
"All files (*)|*|"
filedia = wx.FileDialog (self
#,wildcard=wildcard
, message=text,
style=wx.OVERWRITE_PROMPT | wx.SAVE,
defaultFile=self.filename)
ret = filedia.ShowModal()
print ret
if ret != wx.ID_OK:
return False
#fo = codecs.open(self.filedia.GetPath(), "w", "utf-8")
fo = open(filedia.GetPath(), "w")
fo.write(self.text_ctrl_1.GetValue())
filedia.Destroy()
def OnOpen(self, event=None):
wildcard = "HTML files (*.html)|*.html|" \
"HTML files (*.htm)|*.htm|" \
"All files (*)|*|"
filedia = wx.FileDialog(self, message="Choose the file to open",
#wildcard=wildcard
)
if not filedia.ShowModal() == wx.ID_OK:
return False
value = open(filedia.GetPath()).read()
self.text_ctrl_1.SetValue(value)
self.opencopy = copy.copy(value)
self.filename = filedia.GetFilename()
filedia.Destroy()
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
self.window_1.SplitVertically(self.text_ctrl_1, self.window_2)
sizer_1.Add(self.window_1, 1, wx.EXPAND, 0)
self.SetAutoLayout(True)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
sizer_1.SetSizeHints(self)
#self.Layout()
# end wxGlade
# end of class MyFrame
if __name__ == "__main__":
app = wx.PySimpleApp(0)
frame_1 = MyFrame()
frame_1.Show()
app.SetTopWindow(frame_1)
app.MainLoop()
