~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/gui_thread/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T. Chen (new)
  • Date: 2005-03-16 02:15:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050316021529-xrjlowsejs0cijig
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
    Allows interpreter and GUI windows to co-exist peacefully.
 
3
 
 
4
    gui_thread runs wxPython in a back ground thread and allows you 
 
5
    to create and manipulate wxPython windows from the command line.
 
6
 
 
7
    NEW WAY:
 
8
    An example usage follows::
 
9
           >> import gui_thread
 
10
           >> gui_thread.start()
 
11
           >> from gui_thread.examples import SimpleFrame
 
12
           >> a = SimpleFrame()
 
13
           >> a.Show(1)
 
14
           # a window with a button should pop up...
 
15
           >> a.SetTitle('bob')
 
16
           >> a.GetTitle()
 
17
           'bob'
 
18
           >> a.GetSize()
 
19
           (350,200)
 
20
           >> a.Blue()
 
21
           # window button should have turned blue.
 
22
           >> b = SimpleFrame()
 
23
           >> b.Show(1)
 
24
           # a 2nd window appears
 
25
 
 
26
    OLD WAY:
 
27
    An example usage follows::
 
28
           >> import gui_thread
 
29
           >> gui_thread.start(use_main=1)
 
30
           <wait several seconds while wxPython starts>
 
31
           wxPython imported           
 
32
           >> from gui_thread.examples import SimpleFrame
 
33
           >> prxyMyFrame = gui_thread.register(SimpleFrame)
 
34
           >> a = prxyMyFrame()
 
35
           >> a.Show(1)
 
36
           # a window with a button should pop up...
 
37
           >> a.SetTitle('bob')
 
38
           >> a.GetTitle()
 
39
           'bob'
 
40
           >> a.GetSize()
 
41
           (350,200)
 
42
           >> a.Blue()
 
43
           # window button should have turned blue.
 
44
           >> b = prxyMyFrame()
 
45
           >> b.Show(1)
 
46
           # a 2nd window appears
 
47
        
 
48
        Modules based on gui_thread will also run in wxPython applications
 
49
        without modification.  So, by using gui_thread, you can create
 
50
        viewers for common objects that are usable from the standard
 
51
        python interpreter, PythonWin (on MS), and wxPython applications.
 
52
        Since Tkinter and wxPython currently do not coexist well together,
 
53
        IDLE is not compatible with gui_thread.        
 
54
        
 
55
        gui_thread should always be the first module you import into an 
 
56
        application, unless it is a wxPython app.  In that case, it can
 
57
        be imported at any time.  When using it in interactive mode, make
 
58
        wait until the "wxPython Imported" message appears before importing
 
59
        any other modules that use wxPython.
 
60
"""
 
61
 
 
62
# New hooks for importing wxPython to its own thread
 
63
from wxPython_thread import wxPython_thread
 
64
 
 
65
_use_main = 0
 
66
def start(extra=None,use_main=0):
 
67
    global _use_main
 
68
    _use_main = use_main
 
69
    if _use_main:
 
70
        import main
 
71
        main.start(extra)
 
72
    else:
 
73
        wxPython_thread()
 
74
    return
 
75
 
 
76
def start_up(src_modname,dst_modname,extra=None):
 
77
    global _use_main
 
78
    if _use_main:
 
79
        import main
 
80
        main.start_up(src_modname,dst_modname,extra)
 
81
    return
 
82
 
 
83
def register(wx_class):
 
84
    global _use_main
 
85
    if _use_main:
 
86
        import main
 
87
        return main.register(wx_class)
 
88
    return wx_class