23 |
<holder>Intevation GmbH</holder> |
<holder>Intevation GmbH</holder> |
24 |
</copyright> |
</copyright> |
25 |
<revhistory> |
<revhistory> |
26 |
|
<!-- comment this first revision out when releasing a real version --> |
27 |
|
<!-- |
28 |
|
<revision> |
29 |
|
<revnumber>CVS version $Id$</revnumber> |
30 |
|
<date></date> |
31 |
|
<revremark>Under development.</revremark> |
32 |
|
</revision> |
33 |
|
--> |
34 |
|
<revision> |
35 |
|
<revnumber>1.0pre2</revnumber> |
36 |
|
<date>29-Aug-2003</date> |
37 |
|
<revremark> |
38 |
|
Corresponds to Thuban development release 0.8.1. |
39 |
|
New: chapter on extensions. |
40 |
|
</revremark> |
41 |
|
</revision> |
42 |
<revision> |
<revision> |
43 |
<revnumber>1.0pre1</revnumber> |
<revnumber>1.0pre1</revnumber> |
44 |
<date>08-Aug-2003</date> |
<date>08-Aug-2003</date> |
45 |
<revremark>Corresponds to Thuban development release 0.8.1</revremark> |
<revremark>Corresponds to Thuban development release 0.8.1.</revremark> |
46 |
</revision> |
</revision> |
47 |
</revhistory> |
</revhistory> |
48 |
|
|
247 |
|
|
248 |
<section><title>Adding and Removing Layers</title> |
<section><title>Adding and Removing Layers</title> |
249 |
<para> |
<para> |
250 |
There are two types of layers that can be added to a map: shape layers |
There are two types of layers that can be added to a map: Shape layers |
251 |
and image layers. Shape layers are stored in Shapefile format, a |
and image layers. Shape layers are stored in Shapefile format, a |
252 |
standard file format for storing geographic objects. These |
widely used file format for storing geographic objects. These |
253 |
files have the extension ``.shp''. Associated with |
files have the extension ``.shp''. Associated with |
254 |
the shape file is a database file which stores attributes for |
the shape file is a database file which stores attributes for |
255 |
each shape in the shape file. This file, in dBase format, |
each shape in the Shape file. This file, in dBase format, |
256 |
has the extension ``.dbf''. Both files must have the same base name. |
has the extension ``.dbf''. Both files must have the same base name. |
257 |
For example, if there is a shape file named roads.shp there must |
For example, if there is a shape file named roads.shp there must |
258 |
also be a file roads.dbf. |
also be a file roads.dbf. |
263 |
<guimenu>Map</guimenu> |
<guimenu>Map</guimenu> |
264 |
<guimenuitem>Add Layer</guimenuitem> |
<guimenuitem>Add Layer</guimenuitem> |
265 |
</menuchoice>. |
</menuchoice>. |
266 |
Thuban will load all files with the same base name, so it doesn't |
Initially, only the ``.shp'' files are shown which is enough for the |
267 |
matter if the shape file or database file is selected. |
selection. However, if you switch to display all files and select one |
268 |
|
of the associated files (e.g. ``.dbf''), Thuban will recognize the base |
269 |
|
name and load the corresponding Shape file. |
270 |
|
</para> |
271 |
|
<para> |
272 |
|
The file dialog for Shape files allows to select multiple files. |
273 |
|
Use the shift-button together with the left mouse button to extend |
274 |
|
the selection. |
275 |
</para> |
</para> |
276 |
|
|
277 |
<para> |
<para> |
1235 |
</section> |
</section> |
1236 |
</chapter> |
</chapter> |
1237 |
|
|
1238 |
|
<chapter><title>Extensions</title> |
1239 |
|
<para> |
1240 |
|
Thuban is designed to be extensible. The term Extension is used as a |
1241 |
|
general term for anything that extends Thuban. |
1242 |
|
This chapter introduces into some oppportunities how to add and |
1243 |
|
handle extra functionality developed by your own or third parties. |
1244 |
|
</para> |
1245 |
|
|
1246 |
|
<section><title>Add personal extensions via thubanstart.py</title> |
1247 |
|
<para> |
1248 |
|
After Thuban has been started for the first time, a directory |
1249 |
|
.thuban is created within your home directory. |
1250 |
|
There you can add a file thubanstart.py which will be imported |
1251 |
|
by Thuban at start-up. It is recommended to add only import-statements |
1252 |
|
to this file to keep the actual code of extensions separate. |
1253 |
|
</para> |
1254 |
|
<para> |
1255 |
|
The modules to import must either be found though the environment |
1256 |
|
variable PYTHONPATH or directly be placed into the .thuban-directory. |
1257 |
|
</para> |
1258 |
|
<para> |
1259 |
|
As an example, copy the file examples/simple_extensions/hello_world.py |
1260 |
|
of the Thuban source code into the .thuban-directory of your home |
1261 |
|
directory. Now add add the statement import hello_world to the |
1262 |
|
file thubanstart.py and run Thuban. You will notice an additional |
1263 |
|
menu <menuchoice><guimenu>Extensions</guimenu></menuchoice> where |
1264 |
|
the new item for the Hello-World extension is placed - select it |
1265 |
|
to see the Hello-World message. |
1266 |
|
</para> |
1267 |
|
</section> |
1268 |
|
|
1269 |
|
<section><title>Writing simple extensions</title> |
1270 |
|
<para> |
1271 |
|
Writing an extension for Thuban basically means to |
1272 |
|
implement the extra functionality in Python with all of the |
1273 |
|
Thuban classes, methods and variables available. |
1274 |
|
</para> |
1275 |
|
<para> |
1276 |
|
All classes and their methods are documented in the source code |
1277 |
|
(see their doc-strings). Here is an example from |
1278 |
|
Thuban/Model/layer.py that describes some of the methods |
1279 |
|
of a Layer object: |
1280 |
|
</para> |
1281 |
|
<programlisting> |
1282 |
|
<![CDATA[ |
1283 |
|
class BaseLayer(TitledObject, Modifiable): |
1284 |
|
|
1285 |
|
"""Base class for the layers.""" |
1286 |
|
|
1287 |
|
def __init__(self, title, visible = True, projection = None): |
1288 |
|
"""Initialize the layer. |
1289 |
|
|
1290 |
|
title -- the title |
1291 |
|
visible -- boolean. If true the layer is visible. |
1292 |
|
""" |
1293 |
|
TitledObject.__init__(self, title) |
1294 |
|
Modifiable.__init__(self) |
1295 |
|
self.visible = visible |
1296 |
|
self.projection = projection |
1297 |
|
|
1298 |
|
def Visible(self): |
1299 |
|
"""Return true if layer is visible""" |
1300 |
|
return self.visible |
1301 |
|
|
1302 |
|
def SetVisible(self, visible): |
1303 |
|
"""Set the layer's visibility.""" |
1304 |
|
self.visible = visible |
1305 |
|
self.issue(LAYER_VISIBILITY_CHANGED, self) |
1306 |
|
|
1307 |
|
def HasClassification(self): |
1308 |
|
"""Determine if this layer support classifications.""" |
1309 |
|
... |
1310 |
|
]]> |
1311 |
|
</programlisting> |
1312 |
|
<para> |
1313 |
|
This example intends to give you an impression of the |
1314 |
|
source-code-level documentation. |
1315 |
|
You have to make yourself familiar with |
1316 |
|
the Python programming language to understand some special |
1317 |
|
code elements. |
1318 |
|
</para> |
1319 |
|
<section><title>hello_world.py</title> |
1320 |
|
<para> |
1321 |
|
Traditionally, the first example should welcome the world. |
1322 |
|
Most of the code handles the frame for integrating a menu |
1323 |
|
item into Thuban while the actual raising of a message |
1324 |
|
is done in a single line. |
1325 |
|
</para> |
1326 |
|
<programlisting> |
1327 |
|
<![CDATA[ |
1328 |
|
# Copyright (C) 2003 by Intevation GmbH |
1329 |
|
# Authors: |
1330 |
|
# Jan-Oliver Wagner <[email protected]> |
1331 |
|
# |
1332 |
|
# This program is free software under the GPL (>=v2) |
1333 |
|
# Read the file COPYING coming with Thuban for details. |
1334 |
|
|
1335 |
|
""" |
1336 |
|
Extend Thuban with a sample Hello World to demonstrate simple |
1337 |
|
extensions. |
1338 |
|
""" |
1339 |
|
|
1340 |
|
__version__ = '$Revision$' |
1341 |
|
|
1342 |
|
# use _() already now for all strings that may later be translated |
1343 |
|
from Thuban import _ |
1344 |
|
|
1345 |
|
# Thuban has named commands which can be registered in the central |
1346 |
|
# instance registry. |
1347 |
|
from Thuban.UI.command import registry, Command |
1348 |
|
|
1349 |
|
# The instance of the main menu of the Thuban application |
1350 |
|
# See Thuban/UI/menu.py for the API of the Menu class |
1351 |
|
from Thuban.UI.mainwindow import main_menu |
1352 |
|
|
1353 |
|
def hello_world_dialog(context): |
1354 |
|
"""Just raise a simple dialog to greet the world. |
1355 |
|
|
1356 |
|
context -- The Thuban context. |
1357 |
|
""" |
1358 |
|
context.mainwindow.RunMessageBox(_('Hello World'), _('Hello World!')) |
1359 |
|
|
1360 |
|
|
1361 |
|
# create a new command and register it |
1362 |
|
registry.Add(Command('hello_world', _('Hello World'), hello_world_dialog, |
1363 |
|
helptext = _('Welcome everyone on this planet'))) |
1364 |
|
|
1365 |
|
# find the extensions menu (create it anew if not found) |
1366 |
|
extensions_menu = main_menu.find_menu('extensions') |
1367 |
|
if extensions_menu is None: |
1368 |
|
extensions_menu = main_menu.InsertMenu('extensions', _('E&xtensions')) |
1369 |
|
|
1370 |
|
# finally bind the new command with an entry in the extensions menu |
1371 |
|
extensions_menu.InsertItem('hello_world') |
1372 |
|
]]> |
1373 |
|
</programlisting> |
1374 |
|
</section> |
1375 |
|
<section><title>Registering a Command</title> |
1376 |
|
<para> |
1377 |
|
Mainly, our new function has to be registered to the Thuban |
1378 |
|
framework in order to connect it to the menu. A registered |
1379 |
|
command can also be connected to e.g. a toolbar button. |
1380 |
|
</para> |
1381 |
|
<para> |
1382 |
|
The instances and classes for this are imported at the beginning. |
1383 |
|
Any code not inside a method or class is directly executed when |
1384 |
|
the source-code module is imported. Therefore, the second |
1385 |
|
part of this example consist of the plain statements to create a new |
1386 |
|
Command and to add it to the menu. |
1387 |
|
</para> |
1388 |
|
<para> |
1389 |
|
By convention, it looks for a menu registered as ``extensions'' to |
1390 |
|
insert the new command. If it does not exist yet, it gets created. |
1391 |
|
It is advisable to copy this code for any of your extensions. |
1392 |
|
</para> |
1393 |
|
</section> |
1394 |
|
<section><title>The Thuban context</title> |
1395 |
|
<para> |
1396 |
|
A registered command that is called, always receives the |
1397 |
|
Thuban context. This instance provides our method with |
1398 |
|
hook references to all important components of the Thuban |
1399 |
|
application. |
1400 |
|
</para> |
1401 |
|
<para> |
1402 |
|
In the example hello_world.py, our function uses the |
1403 |
|
mainwindow component which offers a method to raise a |
1404 |
|
message dialog. In total there are three hooks: |
1405 |
|
<itemizedlist> |
1406 |
|
<listitem> |
1407 |
|
<para>application: |
1408 |
|
This object is the instance of the Thuban Application class. |
1409 |
|
Except maybe for loading or savinf sessions, you will not |
1410 |
|
need this object for a simple extension. |
1411 |
|
See Thuban/UI/application.py for the API. |
1412 |
|
</para> |
1413 |
|
</listitem> |
1414 |
|
<listitem> |
1415 |
|
<para>session: |
1416 |
|
The instance of the current session. It manages the sessions' |
1417 |
|
map and tables. You can set and remove the map or tables. |
1418 |
|
In may also get the map object. However, you should know that |
1419 |
|
internally it is already prepared to handle many maps. |
1420 |
|
Therfore, currently you would always receive a list with exactlty |
1421 |
|
one element. In the future, if there are more than one map, |
1422 |
|
you will not know which one is the currently display one and |
1423 |
|
therefore you should use the mainwindow as hook to find |
1424 |
|
the currently displayed map. |
1425 |
|
See Thuban/Model/session.py for the API. |
1426 |
|
</para> |
1427 |
|
</listitem> |
1428 |
|
<listitem> |
1429 |
|
<para> |
1430 |
|
mainwindow: The mainwindow object is central to manage various |
1431 |
|
GUI things such as the Legend sub-window. Most notably, |
1432 |
|
you get access to the canvas which is the window part where |
1433 |
|
the map is drawn. The canvas knows, which map it currently |
1434 |
|
draws and therefore you get the current map via |
1435 |
|
context.mainwindow.canvas.Map(). |
1436 |
|
See Thuban/UI/mainwindow.py for the API. |
1437 |
|
</para> |
1438 |
|
</listitem> |
1439 |
|
</itemizedlist> |
1440 |
|
</para> |
1441 |
|
</section> |
1442 |
|
</section> |
1443 |
|
</chapter> |
1444 |
|
|
1445 |
<chapter><title>Trouble Shooting</title> |
<chapter><title>Trouble Shooting</title> |
1446 |
<para> |
<para> |
1447 |
Here are a few problems that users have encountered when first using Thuban. |
Here are a few problems that users have encountered when first using Thuban. |