/[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 224 - (hide annotations)
Thu Jul 18 13:04:06 2002 UTC (22 years, 7 months ago) by bh
File MIME type: text/x-python
File size: 2221 byte(s)
	* Examples/simple_extensions/simple_command.py (simple_command):
	Handle the new context implementation. Update the comments about
	the context.

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 bh 224 # argument describing the context in which it is invoked. The context is
21     # an object with a few public attributes for the application object, the
22     # session and the main window.
23 bh 208 def simple_command(context):
24 bh 224 print "simple_command: Application", context.application
25     print "simple_command: Session", context.session
26     print "simple_command: Main window", context.mainwindow
27     print "simple_command: Map", context.mainwindow.canvas.Map()
28 bh 208
29     # Add the command to the registry. A command is represented by a Command
30     # instance which is instantiated with four parameters here, the name of
31     # the command, it's title, the function to call when the command is
32     # invoked by the user and a help text to show in the statusbar.
33     #
34     # The name is used internally to identify commands. The title is
35     # displayed in the menus.
36     registry.Add(Command("simple_command", "Simple Command", simple_command,
37     helptext = "Simple Command"))
38    
39     # The main menu is defined by the main_menu object in
40     # Thuban.UI.mainwindow. This object has a few methods to add new menus
41     # and menu items.
42     #
43     # InsertMenu creates a new submenu in the menu, parameters are its name
44     # and title which have the same meanings as for a command. The return
45     # value is a menu object for the new submenu which has the same methods
46     # as main_menu.
47     menu = Thuban.UI.mainwindow.main_menu.InsertMenu("examples", "&Examples")
48    
49     # In the new menu we can add new items with InsertItem which takes the
50     # name of a command as parameter or with InsertSeparator to add a
51     # separator. We can also use InsertMenu to add submenus, of course. We
52     # add the command twice here to demonstrate separators.
53     menu.InsertItem("simple_command")
54     menu.InsertSeparator()
55     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