/[thuban]/branches/WIP-pyshapelib-bramz/Doc/manual/thuban-manual.xml
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Doc/manual/thuban-manual.xml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1544  
changed lines
  Added in v.1624

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26