X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d14a1e28567de23c586bc80017073d0c39f8d18f..d19a83a5ac67c97c208e28289bbf4adaee6b4134:/wxPython/wx/lib/infoframe.py?ds=sidebyside diff --git a/wxPython/wx/lib/infoframe.py b/wxPython/wx/lib/infoframe.py index b6d16fe2eb..b1352b437d 100644 --- a/wxPython/wx/lib/infoframe.py +++ b/wxPython/wx/lib/infoframe.py @@ -1,3 +1,9 @@ +# 12/20/2003 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o wxPyInformationalMessagesFrame -> PyInformationalMessagesFrame +# o dummy_wxPyInformationalMessagesFrame -> dummy_PyInformationalMessagesFrame +# + """ infoframe.py Released under wxWindows license etc. @@ -30,7 +36,7 @@ Typical usage: from wxPython.lib.infoframe import * ... # ... modify your wxApp as follows: class myApp(wxApp): - outputWindowClass = wxPyInformationalMessagesFrame + outputWindowClass = PyInformationalMessagesFrame ... If you're running on Linux, you'll also have to supply an argument 1 to your constructor of myApp to redirect stdout/stderr to this window (it's done @@ -39,7 +45,7 @@ automatically for you on Windows). If you don't want to redirect stdout/stderr, but use the class directly: do it this way: - InformationalMessagesFrame = wxPyInformationalMessagesFrame\ + InformationalMessagesFrame = PyInformationalMessagesFrame\ ([options from progname (default ""), txt (default "informational messages"]) @@ -117,61 +123,60 @@ write() which displays it's argument. All (well, most) of this is made clear by the example code at the end of this file, which is run if the file is run by itself; otherwise, see the appropriate "stub" file in the wxPython demo. - + """ -from wxPython.wx import * -import sys, tempfile, os +import os +import sys +import tempfile -class _MyStatusBar(wxStatusBar): - def __init__(self, parent,callbacks=None,useopenbutton=0): - wxStatusBar.__init__(self, parent, -1, style=wxTAB_TRAVERSAL) +import wx + +class _MyStatusBar(wx.StatusBar): + def __init__(self, parent, callbacks=None, useopenbutton=0): + wx.StatusBar.__init__(self, parent, -1, style=wx.TAB_TRAVERSAL) self.SetFieldsCount(3) self.SetStatusText("",0) - ID = wxNewId() - self.button1 = wxButton(self,ID,"Dismiss", - style=wxTAB_TRAVERSAL) - EVT_BUTTON(self,ID,self.OnButton1) + self.button1 = wx.Button(self, -1, "Dismiss", style=wx.TAB_TRAVERSAL) + self.Bind(wx.EVT_BUTTON, self.OnButton1, self.button1) - ID = wxNewId() if not useopenbutton: - self.button2 = wxButton(self,ID,"Close File", - style=wxTAB_TRAVERSAL) + self.button2 = wx.Button(self, -1, "Close File", style=wx.TAB_TRAVERSAL) else: - self.button2 = wxButton(self,ID,"Open New File", - style=wxTAB_TRAVERSAL) - EVT_BUTTON(self,ID,self.OnButton2) + self.button2 = wx.Button(self, -1, "Open New File", style=wx.TAB_TRAVERSAL) + + self.Bind(wx.EVT_BUTTON, self.OnButton2, self.button2) self.useopenbutton = useopenbutton self.callbacks = callbacks # figure out how tall to make the status bar - dc = wxClientDC(self) + dc = wx.ClientDC(self) dc.SetFont(self.GetFont()) (w,h) = dc.GetTextExtent('X') h = int(h * 1.8) - self.SetSize(wxSize(100, h)) + self.SetSize((100, h)) self.OnSize("dummy") - EVT_SIZE(self,self.OnSize) + self.Bind(wx.EVT_SIZE, self.OnSize) # reposition things... def OnSize(self, event): self.CalculateSizes() rect = self.GetFieldRect(1) - self.button1.SetPosition(wxPoint(rect.x+5, rect.y+2)) - self.button1.SetSize(wxSize(rect.width-10, rect.height-4)) + self.button1.SetPosition((rect.x+5, rect.y+2)) + self.button1.SetSize((rect.width-10, rect.height-4)) rect = self.GetFieldRect(2) - self.button2.SetPosition(wxPoint(rect.x+5, rect.y+2)) - self.button2.SetSize(wxSize(rect.width-10, rect.height-4)) + self.button2.SetPosition((rect.x+5, rect.y+2)) + self.button2.SetSize((rect.width-10, rect.height-4)) # widths........ def CalculateSizes(self): - dc = wxClientDC(self.button1) + dc = wx.ClientDC(self.button1) dc.SetFont(self.button1.GetFont()) (w1,h) = dc.GetTextExtent(self.button1.GetLabel()) - dc = wxClientDC(self.button2) + dc = wx.ClientDC(self.button2) dc.SetFont(self.button2.GetFont()) (w2,h) = dc.GetTextExtent(self.button2.GetLabel()) @@ -185,6 +190,7 @@ class _MyStatusBar(wxStatusBar): self.button2.SetLabel ("Close File") elif self.callbacks[1] (): self.button2.SetLabel ("Open New File") + self.useopenbutton = 1 - self.useopenbutton self.OnSize("") self.button2.Refresh(True) @@ -192,7 +198,7 @@ class _MyStatusBar(wxStatusBar): -class wxPyInformationalMessagesFrame: +class PyInformationalMessagesFrame: def __init__(self, progname="", text="informational messages", @@ -217,6 +223,7 @@ class wxPyInformationalMessagesFrame: self.title = "%s %s" % (progname,text) self.parent = None # use the SetParent method if desired... self.softspace = 1 # of rather limited use + if dir: self.SetOutputDirectory(dir) @@ -239,11 +246,15 @@ class wxPyInformationalMessagesFrame: f = None - def write(self,string): - if not wxThread_IsMain(): + def write(self, string): + if not wx.Thread_IsMain(): # Aquire the GUI mutex before making GUI calls. Mutex is released # when locker is deleted at the end of this function. - locker = wxMutexGuiLocker() + # + # TODO: This should be updated to use wx.CallAfter similarly to how + # PyOnDemandOutputWindow.write was so it is not necessary + # to get the gui mutex + locker = wx.MutexGuiLocker() if self.Enabled: if self.f: @@ -257,10 +268,11 @@ class wxPyInformationalMessagesFrame: move = 0 if not self.frame: - self.frame = wxFrame(self.parent, -1, self.title, size=(450, 300), - style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE) - self.text = wxTextCtrl(self.frame, -1, "", - style = wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH) + self.frame = wx.Frame(self.parent, -1, self.title, size=(450, 300), + style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE) + + self.text = wx.TextCtrl(self.frame, -1, "", + style = wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_RICH) self.frame.sb = _MyStatusBar(self.frame, callbacks=[self.DisableOutput, @@ -270,7 +282,7 @@ class wxPyInformationalMessagesFrame: "nofile")) self.frame.SetStatusBar(self.frame.sb) self.frame.Show(True) - EVT_CLOSE(self.frame, self.OnCloseWindow) + self.frame.Bind(wx.EVT_CLOSE, self.OnCloseWindow) if hasattr(self,"nofile"): self.text.AppendText( @@ -284,6 +296,7 @@ class wxPyInformationalMessagesFrame: else: tempfile.tempdir = self.dir filename = os.path.abspath(tempfile.mktemp ()) + self.text.AppendText( "Please close this window (or select the " "'Dismiss' button below) when desired. By " @@ -389,10 +402,10 @@ class wxPyInformationalMessagesFrame: def OpenNewFile(self): self.CloseFile() - dlg = wxFileDialog(self.frame, + dlg = wx.FileDialog(self.frame, "Choose a new log file", self.dir,"","*", - wxSAVE | wxHIDE_READONLY | wxOVERWRITE_PROMPT) - if dlg.ShowModal() == wxID_CANCEL: + wx.SAVE | wx.HIDE_READONLY | wx.OVERWRITE_PROMPT) + if dlg.ShowModal() == wx.ID_CANCEL: dlg.Destroy() return 0 else: @@ -434,7 +447,7 @@ class wxPyInformationalMessagesFrame: def flush(self): if self.text: self.text.SetInsertionPointEnd() - wxYield() + wx.Yield() def __call__(self,* args): @@ -449,7 +462,7 @@ class wxPyInformationalMessagesFrame: -class Dummy_wxPyInformationalMessagesFrame: +class Dummy_PyInformationalMessagesFrame: def __init__(self,progname=""): self.softspace = 1 def __call__(self,*args):