Hi Terry,

Thanks for the fix. I see you also updated the encoding for the Quit button 
("TERMINATING SERVER"). I thought I might be spending an afternoon learning 
how to use git diff :) Maybe soon....
I have updated the docstring using the instructions from this thread and 
attached the file. Please feel free to change any terminology or style if 
required.

Regards
Lewis

On Saturday, February 3, 2018 at 3:38:49 AM UTC+11, Terry Brown wrote:
>
>
> I've made the necessary changes in 
> https://github.com/leo-editor/leo-editor/commit/9057d5b 
>
> Cheers -Terry 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.
#@+leo-ver=5-thin
#@+node:tbrown.20091214233510.5347: * @file geotag.py
'''  

A web app to obtain geotagging location data, and tag nodes with latitude and longitude.

There are 3 commands available via Alt-X or from the plugin's submenu. 

`geotag-open-server-page`

- Opens a browser web app to view the Geotagger map.

`geotag-tag-node`

- Sets Leo to wait for a geotag to be sent from the geotagging web app.  **IMPORTANT** this blocks (stops leo) until it gets a response (i.e. 
  you click 'Send' in the geotagging web app.)  So you should (a) save 
  your outline before using it, and (b) do geotag-open-server-page, so 
  the web app. is available.

`geotag-show-node`

- show the node's location/geotag data in the map.

There are 2 buttons in the browser web App: 
[Send]  [Quit]

Usage
------

Issue the `geotag-open-server-page` command to open the web app. 

In Leo create a node associated with a place.
>From the node, issue the `geotag-tag-node` command. 

In the browser window, set the map pin to desired location.
Click the [Send] button to send coordinate information to leo, where it's stored in the headline of the @LatLng child node. 

To close the server, click [Quit]

'''

#@@language python
#@@tabwidth -4

#@+<< imports >>
#@+node:tbrown.20091214233510.5349: ** << imports >>
import leo.core.leoGlobals as g

from leo.plugins.pygeotag import pygeotag

import socket
#@-<< imports >>
__version__ = "0.1"

#@+others
#@+node:tbrown.20091214233510.5351: ** init
def init():
    '''Return True if the plugin has loaded successfully.'''
    if not hasattr(g, 'pygeotag'):
        try:
            g.pygeotag = pygeotag.PyGeoTag(synchronous=True)
            g.pygeotag.start_server()
            g.registerHandler('after-create-leo-frame',onCreate)
            g.registerHandler('end1',onQuit)
            g.plugin_signon(__name__)
        except socket.error:
            g.es('Geotag plugin init failed, perhaps port in use')
    return True
#@+node:tbrown.20091214233510.5352: ** onCreate
def onCreate (tag,key):

    c = key.get('c')

    geotag_Controller(c)
#@+node:tbrown.20101103145611.5658: ** onQuit
def onQuit(tag,key):
    g.pygeotag.stop_server()
#@+node:tbrown.20091214233510.5353: ** class geotag_Controller
class geotag_Controller(object):

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

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

        self.c = c
        c.geotag = self
    #@+node:tbrown.20091215204347.11403: *3* getAttr
    @staticmethod
    def getAttr(p):
        for nd in p.children():
            if nd.h.startswith('@LatLng '):
                break
        else:
            nd = p.insertAsLastChild()
        return nd
    #@+node:tbrown.20091214233510.5356: *3* 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()
    #@-others
#@+node:tbrown.20091214233510.5357: ** cmd_open_server_page (gettag_Controller)
@g.command('geotag-open-server-page')
def cmd_OpenServerPage(event):
    # c = event.get('c')
    g.pygeotag.open_server_page()
    # g.pygeotag.callback = c.geotag.callback

#@+node:tbrown.20091214233510.5358: ** cmd_tag_node (gettag_Controller)
@g.command('geotag-tag-node')
def cmd_TagNode(event):
    c = event.get('c')
    data = g.pygeotag.get_position({'description':c.p.h})
    c.geotag.callback(data)
#@+node:tbrown.20091215204347.11402: ** cmd_show_node (gettag_Controller)
@g.command('geotag-show-node')
def cmd_ShowNode(event):
    c = event.get('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)
#@-others
#@-leo

Reply via email to