todo.py :  » IDE » PIDA » pida-0.6beta3 » pida-plugins » todo » 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 » IDE » PIDA 
PIDA » pida 0.6beta3 » pida plugins » todo » todo.py
# -*- coding: utf-8 -*- 

# Copyright (c) 2007 The PIDA Project

#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:

#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.

#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.


from kiwi.ui.objectlist import ObjectList,Column

# PIDA Imports
from pida.core.service import Service
from pida.core.features import FeaturesConfig
from pida.core.commands import CommandsConfig
from pida.core.events import EventsConfig
from pida.core.actions import ActionsConfig
from pida.core.actions import (TYPE_NORMAL,TYPE_MENUTOOL,TYPE_RADIO
                               TYPE_REMEMBER_TOGGLE)

from pida.ui.views import PidaView,WindowConfig

from pida.utils.gthreads import GeneratorTask,gcall

# locale
from pida.core.locale import Locale
locale = Locale('todo')
_ = locale.gettext

class TodoItem(object):

    def __init__(self, todo, line, marker):
        self.todo = todo
        self.line = line
        self.marker = marker

class TodoView(PidaView):

    key = 'todo.list'

    label_text = _('TODO')
    icon_name =  'accessories-text-editor'

    def create_ui(self):
        self.todo_list = ObjectList(
            [
                Column('line', sorted=True),
                Column('todo'),
                Column('marker'),
            ]
        )
        self.todo_list.connect('double-click', self._on_todo_double_click)
        self.add_main_widget(self.todo_list)
        self.todo_list.show_all()

    def clear_items(self):
        gcall(self.todo_list.clear)

    def add_item(self, todo, line, marker):
        self.todo_list.append(TodoItem(todo, line, marker))

    def _on_todo_double_click(self, olist, item):
        self.svc.boss.editor.cmd('goto_line', line=item.line)

    def can_be_closed(self):
        self.svc.get_action('show_todo').set_active(False)


#XXX Banana

class TodoActionsConfig(ActionsConfig):

    def create_actions(self):
        #XXX: blah
        TodoWindowConfig.action = self.create_action(
            'show_todo',
            TYPE_REMEMBER_TOGGLE,
            _('Todo Viewer'),
            _('Show the Todo Viewer'),
            'accessories-text-editor',
            self.on_show_todo,
            '<Shift><Control>d',
        )

    def on_show_todo(self, action):
        if action.get_active():
            self.svc.show_todo()
        else:
            self.svc.hide_todo()

class TodoEventsConfig(EventsConfig):

    def subscribe_all_foreign(self):
        self.subscribe_foreign('buffer', 'document-changed',
                                     self.on_document_changed)
        self.subscribe_foreign('buffer', 'document-saved',
                                     self.on_document_changed)

    def on_document_changed(self, document):
        self.svc.set_current_document(document)

class TodoWindowConfig(WindowConfig):
    key = TodoView.key
    label_text = TodoView.label_text

class TodoFeaturesConfig(FeaturesConfig):
    def subscribe_all_foreign(self):
        self.subscribe_foreign('window', 'window-config',
            TodoWindowConfig)

# Service class
class Todo(Service):
    """Describe your Service Here""" 

    actions_config = TodoActionsConfig
    events_config = TodoEventsConfig
    features_config = TodoFeaturesConfig

    _markers = ['TODO', 'XXX', 'FIXME']

    def start(self):
        self._current = None
        self._view = TodoView(self)

    def show_todo(self):
        self.boss.cmd('window', 'add_view', paned='Plugin', view=self._view)

    def hide_todo(self):
        self.boss.cmd('window','remove_view', view=self._view)

    def check_current(self):
        for row in self.check_document(self._current):
            yield row

    def check_document(self, document):
        """Check the given lines for TODO messages."""
        self._view.clear_items()
        if not document or not document.lines:
            return
        for i, line in enumerate(document.lines):
            for marker in self._markers:
                if marker in line:
                    pre, post = line.split(marker, 1)
                    todo = post.strip().strip(':').strip()
                    yield (todo, i + 1, marker)

    def add_todo_item(self, todo, line, marker):
        self._view.add_item(todo, line, marker)

    def set_current_document(self, document):
        self._current = document
        if self._current is not None:
            task = GeneratorTask(self.check_current, self.add_todo_item)
            task.start()

    def stop(self):
        if self.get_action('show_todo').get_active():
            self.hide_todo()


# Required Service attribute for service loading
Service = Todo



# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.