/[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 235 - (hide annotations)
Tue Jul 23 10:56:29 2002 UTC (22 years, 7 months ago) by bh
Original Path: trunk/thuban/Thuban/UI/application.py
File MIME type: text/x-python
File size: 4409 byte(s)
* Thuban/UI/mainwindow.py (MainWindow.__init__): Change the
parameter list a bit to allow setting the window title and the
initial message in the status bar. Update the callers.

* Thuban/UI/application.py (ThubanApplication.OnInit)
(ThubanApplication.CreateMainWindow): Put the mainwindow
instantiation into a separate method so that it can be overridden
by a subclass.

1 bh 189 # Copyright (C) 2001, 2002 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     from Thuban.Model.session import create_empty_session
23     from Thuban.Model.save import save_session
24     from Thuban.Model.load import load_session
25    
26     import view
27     import tree
28     from interactor import Interactor
29 bh 215 import mainwindow
30 bh 6
31     from messages import SESSION_CHANGED
32    
33    
34    
35     class ThubanApplication(wxApp, Publisher):
36    
37     """
38     Thuban's application class.
39    
40     All wxWindows programs have to have an instance of an application
41     class derived from wxApp. In Thuban the application class holds
42     references to the main window, the session and the interactor.
43     """
44    
45     def OnInit(self):
46 bh 189 self.read_startup_files()
47 bh 6 self.interactor = Interactor(None)
48 bh 235 top = self.CreateMainWindow()
49 bh 6 top.Show(true)
50     self.top = top
51     self.SetTopWindow(top)
52     self.session = None
53     self.create_session()
54     return true
55    
56 bh 189 def read_startup_files(self):
57     """Read the startup files."""
58     # for now the startup file is ~/.thuban/thubanstart.py
59     dir =os.path.expanduser("~/.thuban")
60     if os.path.isdir(dir):
61     sys.path.append(dir)
62     try:
63     import thubanstart
64     except ImportError:
65     tb = sys.exc_info()[2]
66     try:
67     if tb.tb_next is not None:
68     # The ImportError exception was raised from
69     # inside the thubanstart module.
70     sys.stderr.write("Cannot import the thubanstart"
71     "module\n")
72     traceback.print_exc(None, sys.stderr)
73     else:
74     # There's no thubanstart module.
75     sys.stderr.write("No thubanstart module available\n")
76     finally:
77     # make sure we delete the traceback object,
78     # otherwise there's be circular references involving
79     # the current stack frame
80     del tb
81     except:
82     sys.stderr.write("Cannot import the thubanstart module\n")
83     traceback.print_exc(None, sys.stderr)
84     else:
85     # There's no .thuban directory
86     sys.stderr.write("No ~/.thuban directory\n")
87    
88 bh 235 def CreateMainWindow(self):
89     """Create and return the main window for the application.
90    
91     Override this in subclasses to instantiate the Thuban mainwindow
92     with different parameters or to use a different class for the
93     main window.
94    
95     when this method is called by OnInit self.interactor (to be used
96     for the interactor argument of the standard Thuban main window
97     class) has already been instantiated.
98     """
99     msg = ("This is the wxPython-based Graphical User Interface"
100     " for exploring geographic data")
101     return mainwindow.MainWindow(NULL, -1, "Thuban", self, self.interactor,
102     initial_message = msg)
103    
104 bh 219 def Session(self):
105     """Return the application's session object"""
106     return self.session
107    
108 bh 6 def SetSession(self, session):
109 bh 219 """Make session the new session.
110    
111     Issue SESSION_CHANGED.
112     """
113 bh 6 oldsession = self.session
114     self.session = session
115     self.issue(SESSION_CHANGED)
116     self.interactor.SetSession(session)
117     self.set_map()
118     if oldsession is not None:
119     oldsession.Destroy()
120    
121     def create_session(self):
122     # Create a simple default session
123     self.SetSession(create_empty_session())
124    
125     def OpenSession(self, filename):
126     session = load_session(filename)
127     session.SetFilename(filename)
128     session.UnsetModified()
129     self.SetSession(session)
130    
131     def SaveSession(self):
132     save_session(self.session, self.session.filename)
133    
134     def set_map(self):
135     if self.session.HasMaps():
136     self.top.SetMap(self.session.Maps()[0])
137     else:
138     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