/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/application.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Thuban/UI/application.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 401 - (hide annotations)
Tue Feb 11 15:19:21 2003 UTC (22 years ago) by bh
Original Path: trunk/thuban/Thuban/UI/application.py
File MIME type: text/x-python
File size: 7262 byte(s)
(ThubanApplication.OnInit): Call the
new splash_screen method to determine whether the application
should display a splash screen. If it displays a splash screen do
not immediately show the main window.
(ThubanApplication.splash_screen): New method to create a splash
screen.
(ThubanApplication.ShowMainWindow): New. Show the main window.
Needed so the splash screen can display the mainwindow

1 bh 401 # Copyright (C) 2001, 2002, 2003 by Intevation GmbH
2 bh 6 # Authors:
3     # Jan-Oliver Wagner <[email protected]>
4 bh 189 # Bernhard Herzog <[email protected]>
5 bh 6 #
6     # This program is free software under the GPL (>=v2)
7     # Read the file COPYING coming with Thuban for details.
8    
9     """
10     Thuban's application object.
11     """
12    
13     __version__ = "$Revision$"
14    
15 bh 189 import sys, os
16     import traceback
17    
18 bh 6 from wxPython.wx import *
19    
20     from Thuban.Lib.connector import Publisher
21    
22 jan 374 from Thuban import _
23 bh 6 from Thuban.Model.session import create_empty_session
24     from Thuban.Model.save import save_session
25     from Thuban.Model.load import load_session
26 bh 242 from Thuban.Model.messages import MAPS_CHANGED
27 bh 6
28     import view
29     import tree
30     from interactor import Interactor
31 bh 215 import mainwindow
32 bh 6
33     from messages import SESSION_CHANGED
34    
35    
36    
37     class ThubanApplication(wxApp, Publisher):
38    
39     """
40     Thuban's application class.
41    
42     All wxWindows programs have to have an instance of an application
43     class derived from wxApp. In Thuban the application class holds
44     references to the main window, the session and the interactor.
45     """
46    
47     def OnInit(self):
48 bh 401 self.splash = self.splash_screen()
49     if self.splash is not None:
50     self.splash.Show()
51 bh 189 self.read_startup_files()
52 bh 6 self.interactor = Interactor(None)
53 bh 401 self.top = self.CreateMainWindow()
54     self.SetTopWindow(self.top)
55     if self.splash is None:
56     self.ShowMainWindow()
57 bh 6 self.session = None
58     self.create_session()
59     return true
60    
61 bh 251 def OnExit(self):
62     """Clean up code.
63    
64     Extend this in derived classes if needed.
65     """
66     self.session.Destroy()
67     self.interactor.Destroy()
68     Publisher.Destroy(self)
69    
70     def MainLoop(self):
71     """Call the inherited MainLoop method and then call OnExit.
72    
73     In wxPython OnExit isn't called automatically, unfortunately, so
74     we do it here.
75     """
76     wxApp.MainLoop(self)
77     self.OnExit()
78    
79 bh 189 def read_startup_files(self):
80     """Read the startup files."""
81     # for now the startup file is ~/.thuban/thubanstart.py
82     dir =os.path.expanduser("~/.thuban")
83     if os.path.isdir(dir):
84     sys.path.append(dir)
85     try:
86     import thubanstart
87     except ImportError:
88     tb = sys.exc_info()[2]
89     try:
90     if tb.tb_next is not None:
91     # The ImportError exception was raised from
92     # inside the thubanstart module.
93 jan 374 sys.stderr.write(_("Cannot import the thubanstart"
94     "module\n"))
95 bh 189 traceback.print_exc(None, sys.stderr)
96     else:
97     # There's no thubanstart module.
98 jan 374 sys.stderr.write(_("No thubanstart module available\n"))
99 bh 189 finally:
100     # make sure we delete the traceback object,
101     # otherwise there's be circular references involving
102     # the current stack frame
103     del tb
104     except:
105 jan 374 sys.stderr.write(_("Cannot import the thubanstart module\n"))
106 bh 189 traceback.print_exc(None, sys.stderr)
107     else:
108     # There's no .thuban directory
109 jan 374 sys.stderr.write(_("No ~/.thuban directory\n"))
110 bh 189
111 bh 401 def splash_screen(self):
112     """Create and return a splash screen.
113    
114     This method is called by OnInit to determine whether the
115     application should have a splashscreen. If the application
116     should display a splash screen override this method in a derived
117     class and have it create and return the wxSplashScreen instance.
118     The implementation of this method in the derived class should
119     also arranged for ShowMainWindow to be called.
120    
121     The default implementation simply returns None so that no splash
122     screen is shown and ShowMainWindow will be called automatically.
123     """
124     return None
125    
126     def ShowMainWindow(self):
127     """Show the main window
128    
129     Normally this method is automatically called by OnInit to show
130     the main window. However, if the splash_screen method has
131     returned a splashscreen it is expected that the derived class
132     also arranges for ShowMainWindow to be called at the appropriate
133     time.
134     """
135     self.top.Show(true)
136    
137 bh 235 def CreateMainWindow(self):
138     """Create and return the main window for the application.
139    
140     Override this in subclasses to instantiate the Thuban mainwindow
141     with different parameters or to use a different class for the
142     main window.
143    
144     when this method is called by OnInit self.interactor (to be used
145     for the interactor argument of the standard Thuban main window
146     class) has already been instantiated.
147     """
148 jan 374 msg = (_("This is the wxPython-based Graphical User Interface"
149     " for exploring geographic data"))
150 bh 235 return mainwindow.MainWindow(NULL, -1, "Thuban", self, self.interactor,
151     initial_message = msg)
152    
153 bh 219 def Session(self):
154     """Return the application's session object"""
155     return self.session
156    
157 bh 6 def SetSession(self, session):
158 bh 219 """Make session the new session.
159    
160 bh 242 Issue SESSION_CHANGED after self.session has become the new
161     session. After the session has been assigned call
162     self.subscribe_session() with the new session and
163     self.unsubscribe_session with the old one.
164 bh 219 """
165 bh 6 oldsession = self.session
166     self.session = session
167 bh 242 self.subscribe_session(self.session)
168 bh 6 self.issue(SESSION_CHANGED)
169     self.interactor.SetSession(session)
170 bh 242 self.maps_changed()
171 bh 6 if oldsession is not None:
172 bh 242 self.unsubscribe_session(oldsession)
173 bh 6 oldsession.Destroy()
174    
175 bh 242 def subscribe_session(self, session):
176     """Subscribe to some of the sessions channels.
177    
178     Extend this method in derived classes if you need additional
179     channels.
180     """
181     session.Subscribe(MAPS_CHANGED, self.maps_changed)
182    
183     def unsubscribe_session(self, session):
184     """Unsubscribe from the sessions channels.
185    
186     Extend this method in derived classes if you subscribed to
187     additional channels in subscribe_session().
188     """
189     session.Unsubscribe(MAPS_CHANGED, self.maps_changed)
190    
191 bh 6 def create_session(self):
192 bh 242 """Create a default session.
193    
194     Override this method in derived classes to instantiate the
195     session differently or to use a different session class. Don't
196     subscribe to channels here yet. Do that in the
197     subscribe_session() method.
198     """
199 bh 6 self.SetSession(create_empty_session())
200    
201     def OpenSession(self, filename):
202     session = load_session(filename)
203     session.SetFilename(filename)
204     session.UnsetModified()
205     self.SetSession(session)
206    
207     def SaveSession(self):
208     save_session(self.session, self.session.filename)
209    
210 bh 242 def maps_changed(self, *args):
211 bh 6 if self.session.HasMaps():
212     self.top.SetMap(self.session.Maps()[0])
213     else:
214     self.top.SetMap(None)

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26