Randy Syring avatar Randy Syring committed 97e3e47

initial commit

Comments (0)

Files changed (9)

+syntax: glob
+*.pyc
+*.egg-info
+*.komodo*
+global-exclude *.pyc
+include *.rst
+global-include *.png
+Changelog
+---------
+
+0.1.0 released ???
+==========================
+
+- ???

launchytomboyplugin/__init__.py

+import os.path as osp
+
+import launchy
+import launchytomboyplugin.lib as plib
+
+class Tomboy(launchy.Plugin):
+    def __init__(self):
+        launchy.Plugin.__init__(self)
+        self.tbl = plib.TomboyLib()
+        self.name = self.tbl.name
+        self.hash = launchy.hash(self.name)
+        self.icon = self.tbl.icon
+        self.tbl.debug_info()
+
+    def init(self):
+        pass
+
+    def getID(self):
+        return self.hash
+
+    def getName(self):
+        return self.name
+
+    def getIcon(self):
+         return self.icon
+
+    def getLabels(self, inputDataList):
+        pass
+
+    def getResults(self, inputDataList, resultsList):
+        pass
+
+    def getCatalog(self, resultsList):
+        self.tbl.debug('Adding Tomboy items to catalog')
+        resultsList.push_back( launchy.CatItem(
+            "Tomboy.NewNote",
+            "Tomboy New Note",
+            self.getID(),
+            self.tbl.new_note_icon
+        ))
+
+        resultsList.push_back( launchy.CatItem(
+            "Tomboy.Search",
+            "Tomboy Search Notes",
+            self.getID(),
+            self.tbl.icon
+        ))
+
+        count = 0
+        for title in self.tbl.note_titles:
+            resultsList.push_back( launchy.CatItem(
+                'Tomboy.Note.' + title,
+                title,
+                self.getID(),
+                self.icon
+            ))
+            count += 1
+        self.tbl.debug('Added {0} notes to catalog'.format(count))
+
+    def launchItem(self, inputDataList, catItemOrig):
+        catItem = inputDataList[-1].getTopResult()
+        self.tbl.debug('Asked to launch:', catItem.fullPath)
+        if catItem.fullPath == 'Tomboy.NewNote':
+            self.tbl.new_note()
+        elif catItem.fullPath == 'Tomboy.Search':
+            self.tbl.search_notes()
+        elif catItem.fullPath.startswith('Tomboy.Note.'):
+            title = catItem.fullPath.replace('Tomboy.Note.', '', 1)
+            self.tbl.launch_note(title)
+        else:
+            self.tbl.error('don\'t know how to launch:', catItem.fullPath)
Add a comment to this file

launchytomboyplugin/icons/notebook-new.png

Added
New image
Add a comment to this file

launchytomboyplugin/icons/tomboy.png

Added
New image

launchytomboyplugin/lib.py

+import glob
+from os import environ as ose
+import os.path as osp
+import subprocess
+import sys
+import xml.etree.cElementTree as et
+
+BASE_DIR = osp.dirname(__file__)
+ICON_DIR = osp.join(BASE_DIR, 'icons')
+TOMBOY_ICON_PATH = osp.join(ICON_DIR, 'tomboy.png')
+NEWNOTE_ICON_PATH = osp.join(ICON_DIR, 'notebook-new.png')
+
+class TomboyLib(object):
+    def __init__(self):
+        self.name = "Tomboy"
+        self.icon = TOMBOY_ICON_PATH
+        self.new_note_icon = NEWNOTE_ICON_PATH
+
+    def debug(self, *msg):
+        if ose.get('LAUNCHY_TOMBOY_DEBUG'):
+            sys.stdout.write('TOMBOY - ' + ' '.join(map(str, msg)) + '\n')
+
+    def error(self, *msg):
+        sys.stderr.write('TOMBOY - ' + ' '.join(map(str, msg)) + '\n')
+
+    @property
+    def tomboy_notes_dir(self):
+        if ose.get('TOMBOY_PATH'):
+            return ose.get('TOMBOY_PATH')
+        return osp.join(ose.get('APPDATA'), 'Tomboy', 'notes')
+
+    @property
+    def tomboy_exe_path(self):
+        tp_path = ose.get('TOMBOY_PROGRAM_PATH')
+        if not tp_path:
+            pf_path = ose.get('ProgramFiles(x86)')
+            if not pf_path:
+                pf_path = ose.get('ProgramFiles')
+            if not pf_path:
+                self.error('Can\'t get tomboy path environment variables: '
+                           '"TOMBOY_PROGRAM_PATH", "ProgramFiles(x86)", or "ProgramFiles"')
+            tp_path = osp.join(pf_path, 'Tomboy', 'Tomboy.exe')
+        if not osp.isfile(tp_path):
+            self.error('Tomboy.exe not found at', tp_path, '.  Set TOMBOY_PROGRAM_PATH environment variable and restart Launchy.')
+        return tp_path
+
+    @property
+    def note_paths(self):
+        glob_pattern = osp.join(self.tomboy_notes_dir, '*.note')
+        return glob.glob(glob_pattern)
+
+    @property
+    def note_titles(self):
+        for fpath in self.note_paths:
+            root = et.parse(fpath).getroot()
+            title = root.find('{http://beatniksoftware.com/tomboy}title')
+            if title is not None:
+                yield title.text
+
+    def launch_note(self, note_title):
+        self.tomboy_exec('--open-note', note_title)
+
+    def new_note(self):
+        self.tomboy_exec('--new-note')
+
+    def search_notes(self):
+        self.tomboy_exec()
+
+    def debug_info(self):
+        self.debug('Name:', self.name)
+        self.debug('Icon dir:', self.icon)
+        self.debug('Tomboy exe path:', self.tomboy_exe_path)
+        self.debug('Notes dir:', self.tomboy_notes_dir)
+        self.debug( 'Note count:', len(self.note_paths))
+        for title in self.note_titles:
+            self.debug('First note:', title)
+            break
+
+    def debug_actions(self):
+        for title in self.note_titles:
+            self.launch_note(title)
+            break
+        self.new_note()
+
+    def tomboy_exec(self, *tomboyargs):
+        args = [self.tomboy_exe_path]
+        args.extend(tomboyargs)
+        self.debug('executing tomboy', args)
+        proc = subprocess.Popen(
+            args,
+            stdin=subprocess.PIPE,
+            stderr=subprocess.PIPE,
+            stdout=subprocess.PIPE,
+            )
+        stdout, stderr = proc.communicate()
+        self.debug('cmd return code: ', proc.returncode)
+        self.debug('cmd stdout: ', stdout)
+        self.debug('cmd stderr: ', stderr)
+
+if __name__ == '__main__':
+    ose['LAUNCHY_TOMBOY_DEBUG'] = '1'
+    tbl = TomboyLib()
+    tbl.debug_info()
+    tbl.debug_actions()
+Introduction
+---------------
+
+Launchy Tomboy Plugin
+
+Requirements
+------------
+
+I have tested this setup with:
+
+- Windows 7
+- Python 2.7
+- `Launchy <http://www.launchy.net/>`_: 2.6 Beta 2
+- `Tomboy <http://projects.gnome.org/tomboy/>`_: 1.11.2
+- `PyLaunchy <http://pylaunchy.sourceforge.net/docs/>`_: 0.9
+
+Installation
+------------
+
+- Make sure the above requirements are installed
+- install this package using pip, easy_install, or the .exe installer
+- create a file like the one below:
+
+    # this file should reside at
+    # <Launchy program dir>\plugins\python\pytomboy.py
+    from os import environ as ose
+    import launchy
+
+    # uncomment this line if you want debug messages from LaunchyTomboyPlugin
+    # to go to <Launch program dir>\plugins\python\stdout.txt
+    #ose['LAUNCHY_TOMBOY_DEBUG'] = '1'
+
+    from launchytomboyplugin import Tomboy
+
+    launchy.registerPlugin(Tomboy)
+    print 'Tomboy plugin registered'
+
+- start or restart Launchy
+
+Environment Variables
+---------------------
+
+- LAUNCHY_TOMBOY_DEBUG: set to enable debug info in the stdout.txt (see below)
+- TOMBOY_PROGRAM_PATH: set to the full path to Tomboy.exe if your Tomboy install
+  is in a non-standard location.
+
+Log Files
+---------
+
+Keep theses files in mind when trying to troubleshoot problems:
+
+- <Launch program dir>\plugins\python\stdout.txt
+- <Launch program dir>\plugins\python\stderr.txt
+
+Using the Plugin
+----------------
+
+This plugin inserts two static items into the Launchy catalog:
+
+- Tomboy New Note
+- Tomboy Search Notes
+
+It will also index the title of every Tomboy note and make it available as an
+item in the Launchy catalog.  So if you have a note with a title of "ToDo List"
+typing "ToDo List" in Launchy should bring up that item.  Hitting enter will
+open the corresponding Tomboy note.
+
+Note: the plugin rebuilds the list of note titles whenever Launchy rebuilds its
+catalog.  The auto-refresh time period can be set in Launchy options.  A manual
+refresh of the catalog can also be triggered, see Launchy docs for more info.
+
+Questions & Comments
+---------------------
+
+Please visit: http://groups.google.com/group/blazelibs
+
+Source Code
+-----------
+
+http://bitbucket.org/rsyring/launchytomboyplugin
+
+The `Launch Tomboy Plugin HG tip <http://bitbucket.org/rsyring/launchytomboyplugin/get/tip.zip#egg=LaunchyTomboyPlugin-dev>`_
+is installable via `easy_install` with ``easy_install LaunchyTomboyPlugin==dev``
+or pip with ``pip install LaunchyTomboyPlugin==dev``.
+import sys, os
+from setuptools import setup, find_packages
+
+cdir = os.path.abspath(os.path.dirname(__file__))
+README = open(os.path.join(cdir, 'readme.rst')).read()
+CHANGELOG = open(os.path.join(cdir, 'changelog.rst')).read()
+
+setup(
+    name = "LaunchyTomboyPlugin",
+    version = '0.1',
+    description = "A plugin for Launchy to put Tomboy note titles in the catalog",
+    long_description= '\n\n'.join((README, CHANGELOG)),
+    author = "Randy Syring",
+    author_email = "rsyring@gmail.com",
+    url='http://bitbucket.org/rsyring/launchytomboyplugin',
+    classifiers=[
+        'Development Status :: 4 - Beta',
+        'Intended Audience :: End Users/Desktop',
+        'License :: OSI Approved :: BSD License',
+        'Operating System :: Microsoft :: Windows',
+        'Programming Language :: Python :: 2.7',
+      ],
+    license='BSD',
+    packages=['launchytomboyplugin'],
+    zip_safe=False,
+)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.