/[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 2410 - (hide annotations)
Sat Nov 20 21:57:43 2004 UTC (20 years, 3 months ago) by jan
File MIME type: text/x-python
File size: 2397 byte(s)
Some more comments, minor changes.

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