geotag.py :  » Development » Leo » Leo-4.7.1-final » leo » plugins » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » Leo 
Leo » Leo 4.7.1 final » leo » plugins » geotag.py
#@+leo-ver=4-thin
#@+node:tbrown.20091214233510.5347:@thin geotag.py
#@<< docstring >>
#@+node:tbrown.20091214233510.5348:<< docstring >>
'''

geotag.py - Tag nodes with lat/long. info
=========================================


'''
#@-node:tbrown.20091214233510.5348:<< docstring >>
#@nl

#@@language python
#@@tabwidth -4

#@<< imports >>
#@+node:tbrown.20091214233510.5349:<< imports >>
import leo.core.leoGlobals as g
from leo.core import leoPlugins
from leo.plugins.pygeotag import pygeotag
#@-node:tbrown.20091214233510.5349:<< imports >>
#@nl
__version__ = "0.1"
#@<< version history >>
#@+node:tbrown.20091214233510.5350:<< version history >>
#@@killcolor

#@+at 
#@nonl
# Use and distribute under the same terms as leo itself.
# 
# 0.1 TNB
#   - initial version
#@-at
#@nonl
#@-node:tbrown.20091214233510.5350:<< version history >>
#@nl

#@+others
#@+node:tbrown.20091214233510.5351:init
def init():

    leoPlugins.registerHandler('after-create-leo-frame',onCreate)
    g.plugin_signon(__name__)

    g.pygeotag = pygeotag.PyGeoTag(synchronous=True)
    g.pygeotag.start_server()

    return True
#@-node:tbrown.20091214233510.5351:init
#@+node:tbrown.20091214233510.5352:onCreate
def onCreate (tag,key):

    c = key.get('c')

    geotag_Controller(c)
#@-node:tbrown.20091214233510.5352:onCreate
#@+node:tbrown.20091214233510.5353:class geotag_Controller
class geotag_Controller:

    '''A per-commander class that manages geotagging.'''

    #@    @+others
    #@+node:tbrown.20091214233510.5354:__init__
    def __init__ (self, c):

        self.c = c
        c.geotag = self
    #@-node:tbrown.20091214233510.5354:__init__
    #@+node:tbrown.20091214233510.5355:__del__
    def __del__(self):
        for i in self.handlers:
            leoPlugins.unregisterHandler(i[0], i[1])
    #@-node:tbrown.20091214233510.5355:__del__
    #@+node:tbrown.20091215204347.11403:getAttr
    @staticmethod
    def getAttr(p):
        for nd in p.children():
            if nd.h.startswith('@LatLng '):
                break
        else:
            nd = p.insertAsLastChild()
        return nd
    #@nonl
    #@-node:tbrown.20091215204347.11403:getAttr
    #@+node:tbrown.20091214233510.5356:callback
    def callback(self, data):

        c = self.c
        p = c.p

        nd = self.getAttr(p)



        nd.h = '@LatLng %(lat)f %(lng)f %(zoom)d %(maptype)s  %(description)s ' % data
        c.setChanged(True)
        if hasattr(c, 'attribEditor'):
            c.attribEditor.updateEditorInt()
        c.redraw()
    #@-node:tbrown.20091214233510.5356:callback
    #@-others
#@-node:tbrown.20091214233510.5353:class geotag_Controller
#@+node:tbrown.20091214233510.5357:cmd_open_server_page
def cmd_OpenServerPage(c):
    g.pygeotag.open_server_page()
    # g.pygeotag.callback = c.geotag.callback

#@-node:tbrown.20091214233510.5357:cmd_open_server_page
#@+node:tbrown.20091214233510.5358:cmd_tag_node
def cmd_TagNode(c):
    data = g.pygeotag.get_position({'description':c.p.h})
    c.geotag.callback(data)
#@-node:tbrown.20091214233510.5358:cmd_tag_node
#@+node:tbrown.20091215204347.11402:cmd_show_node
def cmd_ShowNode(c):
    nd = geotag_Controller.getAttr(c.p)
    try:
        txt = nd.h.split(None, 5)
        what = 'dummy', 'lat', 'lng', 'zoom', 'maptype', 'description'
        data = dict(zip(what, txt))
        data['lat'] = float(data['lat'])
        data['lng'] = float(data['lng'])
        if 'zoom' in data:
            data['zoom'] = int(data['zoom'])
        if 'description' not in data or not data['description'].strip():
            data['description'] = c.p.h
    except (ValueError,TypeError):
        data = {'description':c.p.h}
    g.pygeotag.show_position(data)
#@-node:tbrown.20091215204347.11402:cmd_show_node
#@-others
#@nonl
#@-node:tbrown.20091214233510.5347:@thin geotag.py
#@-leo
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.