python-demo.py 1008 Bytes
Newer Older
1 2 3
# This file is a small demo for the planner/python integration. Copy
# it under ~/.gnome2/planner/python/ and restart planner. You'll
# notice a new entry in the file->import menu.
4 5 6 7
#

ui_string = """
<ui>
8 9 10 11 12
  <menubar name='MenuBar'>
    <menu action='File'>
      <menu action='Import'>
        <placeholder  name='Import placeholder'>
          <menuitem action='Python import'/>
13 14 15 16 17 18 19 20 21
        </placeholder>
      </menu>
    </menu>
  </menubar>
</ui>
"""

def import_python(*args):
    action = args[0]
22
    print 'Activated the action:', action.get_name()
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
    project = window.get_project()
    t1 = planner.Task()
    t1.set_name('Python demo')
    t1.set_property('work', 8*60*60)
    project.insert_task(task=t1)


python_actions = [
    ('Python import', None, '_Python', None, 'Python demo', import_python),
    ]

group = gtk.ActionGroup('PythonImport')
group.add_actions(python_actions)

ui = window.get_ui_manager()
38
ui.insert_action_group(group, 0)
39 40 41 42
ui.add_ui_from_string(ui_string)
ui.ensure_update()