/[thuban]/trunk/thuban/Examples/simple_extensions/simple_command.py
ViewVC logotype

Annotation of /trunk/thuban/Examples/simple_extensions/simple_command.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 208 - (hide annotations)
Tue Jul 9 14:57:03 2002 UTC (22 years, 8 months ago) by bh
File MIME type: text/x-python
File size: 2016 byte(s)
* Examples/simple_extensions/simple_tool.xpm,
Examples/simple_extensions/simple_tool.py,
Examples/simple_extensions/simple_command.py,
Examples/simple_extensions/README: Simple examples showing how to
add new commands and tools.

1 bh 208 # Copyright (C) 2002 by Intevation GmbH
2     # Authors:
3     # Bernhard Herzog <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with Thuban for details.
7    
8     """
9     Extend thuban with a simple command.
10     """
11    
12     __version__ = "$Revision$"
13    
14     # First import some things we need later.
15     import os
16     from Thuban.UI.command import registry, Command
17     import Thuban.UI.mainwindow
18    
19     # a function implementing a command. Such a function is called with one
20     # argument describing the context in which it is invoked. Currently the
21     # context is the mainwindow object.
22     def simple_command(context):
23     print "simple_command: Main window", context
24     print "simple_command: Map", context.canvas.Map()
25    
26     # Add the command to the registry. A command is represented by a Command
27     # instance which is instantiated with four parameters here, the name of
28     # the command, it's title, the function to call when the command is
29     # invoked by the user and a help text to show in the statusbar.
30     #
31     # The name is used internally to identify commands. The title is
32     # displayed in the menus.
33     registry.Add(Command("simple_command", "Simple Command", simple_command,
34     helptext = "Simple Command"))
35    
36     # The main menu is defined by the main_menu object in
37     # Thuban.UI.mainwindow. This object has a few methods to add new menus
38     # and menu items.
39     #
40     # InsertMenu creates a new submenu in the menu, parameters are its name
41     # and title which have the same meanings as for a command. The return
42     # value is a menu object for the new submenu which has the same methods
43     # as main_menu.
44     menu = Thuban.UI.mainwindow.main_menu.InsertMenu("examples", "&Examples")
45    
46     # In the new menu we can add new items with InsertItem which takes the
47     # name of a command as parameter or with InsertSeparator to add a
48     # separator. We can also use InsertMenu to add submenus, of course. We
49     # add the command twice here to demonstrate separators.
50     menu.InsertItem("simple_command")
51     menu.InsertSeparator()
52     menu.InsertItem("simple_command")

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26