File: infoframe.py

package info (click to toggle)
wxwindows2.4 2.4.5.1.1
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 59,920 kB
  • ctags: 97,489
  • sloc: cpp: 610,307; ansic: 111,957; python: 103,357; makefile: 3,676; sh: 3,391; lex: 192; yacc: 128; xml: 95; pascal: 74
file content (95 lines) | stat: -rw-r--r-- 3,172 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

from wxPython.wx import *
from wxPython.lib.infoframe import *

#----------------------------------------------------------------------

class MyFrame(wxFrame):
    def __init__(self,output):
        wxFrame.__init__(self,None,-1,"Close me...",size=(300,100))
        menubar = wxMenuBar()
        menu = wxMenu()
        mID = wxNewId()
        menu.Append(mID,"&Enable output","Display output frame")
        EVT_MENU(self,mID,output.EnableOutput)
        mID = wxNewId()
        menu.Append(mID,"&Disable output","Close output frame")
        EVT_MENU(self,mID,output.DisableOutput)
        menubar.Append(menu,"&Output")
        self.SetMenuBar(menubar)
        output.SetParent(self)
        output.SetOtherMenuBar(menubar,menuname="Output")
        EVT_CLOSE(self,self.OnClose)
        EVT_TIMER(self, -1, self.OnTimer)

        self.timer = wxTimer(self, -1)
        self.timer.Start(1000)

        self.save_stdout = sys.stdout
        sys.stdout = self.output = output
        print "Hello!"

    def OnClose(self,event):
        sys.stdout = self.save_stdout
        self.output.close()
        self.timer.Stop()
        self.timer = None
        self.Destroy()

    def OnTimer(self, evt):
        print "This was printed with \"print\""


#----------------------------------------------------------------------

from wxPython.lib import infoframe
overview = infoframe.__doc__

def runTest(frame, nb, log):
    """
    This method is used by the wxPython Demo Framework for integrating
    this demo with the rest.
    """
    win = MyFrame(wxPyInformationalMessagesFrame())
    frame.otherWin = win
    win.Show(1)

#----------------------------------------------------------------------

if __name__ == "__main__":
##     class MyFrame(wxFrame):
##         def __init__(self,output):
##             wxFrame.__init__(self,None,-1,"Close me...",size=(300,100))
##             EVT_CLOSE(self,self.OnClose)
##             menubar = wxMenuBar()
##             menu = wxMenu()
##             mID = wxNewId()
##             menu.Append(mID,"&Enable output","Display output frame")
##             EVT_MENU(self,mID,output.EnableOutput)
##             mID = wxNewId()
##             menu.Append(mID,"&Disable output","Close output frame")
##             EVT_MENU(self,mID,output.DisableOutput)
##             menubar.Append(menu,"&Output")
##             self.SetMenuBar(menubar)
##             output.SetOtherMenuBar(menubar,menuname="Output")

##         def OnClose(self,event):
##             if isinstance(sys.stdout,wxPyInformationalMessagesFrame):
##                 sys.stdout.close()
##             self.Destroy()

    class MyApp(wxApp):
        outputWindowClass = wxPyInformationalMessagesFrame
        def OnInit(self):
            frame = MyFrame(self.stdioWin)
            frame.Show(True)
            self.SetTopWindow(frame)
            if isinstance(sys.stdout,wxPyInformationalMessagesFrame):
                sys.stdout.SetParent(frame)
                #self.redirectStdio(None)# this is done automatically
                # by the MyApp(1) call below
            print "Starting.\n",
            return True

    app = MyApp(1)
    app.MainLoop()