Rana/Developers guide

From OpenStreetMap Wiki
Jump to navigation Jump to search

Access it using self.get(key, default) and self.set(key, value)

Using pyrender on localhost as the tile image server (same data for routing and rendering)

Modules

All possible functionality is put into modules, which are loaded on startup (it scans through the module directory loading anything with a mod_something.py filename)

For a list and description of each, see: Rana/Modules

To use another module, access it with self.m.get('moduleName', None) and check the return value! (modules are not guaranteed to be loaded)

Messages

These are used to send data, event notifications, etc. between modules. Each message is a string (typically :-separated). Messages can set data, be routed to specific modules, and they can be bound to mouseclicks in a particular region of screen.

For a list and description of each, see: Rana/Messages

Beginning of message:

  • set:optionName:optionValue - set the specified option
  • toggle:optionName - toggle the specified option
  • moduleName:someMessage - route message to the named module
  • *:someMessage - route message to all modules

Multiple messages can be sent in the same string, use the | character to separate messages.

Actions are messages that are stored to send in response to some event (e.g. a mouse click).

Data

All configuration options and data are stored in a global dictionary (hash). Most data is text, but it's not required (yet)

For a list and description of each, see: Rana/Data

Use self.set("data_name", "value") and self.get("data_name", "default_value") rather than accessing the dictionary directly (because the messaging module may get smarter later, and support things like notification when certain values change)

Adding a module

  1. Copy an existing module or the example module
  2. Change the author and copyright date in the header
  3. Describe the module in 2 places - the header, and the doc text at the beginning of your class
  4. Change the name of the main class
  5. Change getModule() to return your main class
  6. Write your code. You can override any of the functions in base_module.py and your functions will be called at the appropriate time

Drawing on the map

See drawoverlay function in mod_route for sample code

Drawing an overlay

See mod_buttons for sample code

Adding a menu

May be easier to modify mod_menu instead?

Responding to messages

Handle the handleMessage() function