rope-qickfix / ropeide / helpactions.py

import os.path
import sys

import Tkinter

import rope
import ropeide.core
from rope.base import project
from ropeide.extension import SimpleAction
from ropeide.menubar import MenuAddress


def show_about_dialog(context):
    toplevel = Tkinter.Toplevel()
    toplevel.title('About Ropeide')
    text = '%s - version %s\n' % (rope.INFO, rope.VERSION)
    text += '%s - version %s\n\n%s\n' % \
         (ropeide.INFO, ropeide.VERSION, ropeide.COPYRIGHT)
    label = Tkinter.Label(toplevel, text=text, height=16, width=70,
                          justify=Tkinter.LEFT, relief=Tkinter.GROOVE)
    def ok():
        toplevel.destroy()
    def show_gpl():
        show_copying(context)
        toplevel.destroy()
    label.grid(row=0, column=0, columnspan=2)
    ok_button = Tkinter.Button(toplevel, text='OK', command=ok, width=20)
    gpl_button = Tkinter.Button(toplevel, text='Show GNU GPL',
                                command=show_gpl, width=20)
    gpl_button.grid(row=1, column=0)
    ok_button.grid(row=1, column=1)
    ok_button.focus_set()
    toplevel.bind('<Escape>', lambda event: ok())
    toplevel.bind('<Control-g>', lambda event: ok())
    toplevel.bind('<Return>', lambda event: ok())

def show_doc(context, name):
    rope_package = (os.path.dirname(sys.modules['ropeide'].__file__))
    # Checking whether rope is installed or not
    no_project = project.get_no_project()
    if 'docs' in os.listdir(rope_package):
        root = rope_package
    else:
        root = os.path.dirname(rope_package)
    resource = no_project.get_resource(root + '/' + name)
    editor_manager = context.get_core().get_editor_manager()
    editor_manager.get_resource_editor(resource, readonly=True)

def show_readme(context):
    show_doc(context, 'README.txt')

def show_features(context):
    show_doc(context, 'docs/index.txt')

def show_overview(context):
    show_doc(context, 'docs/overview.txt')

def show_tutorial(context):
    show_doc(context, 'docs/tutorial.txt')

def show_contributing(context):
    show_doc(context, 'docs/contributing.txt')

def show_library(context):
    show_doc(context, 'docs/library.txt')

def show_copying(context):
    show_doc(context, 'COPYING')


core = ropeide.core.Core.get_core()
core.add_menu_cascade(MenuAddress(['Help'], 'h'), ['all', 'none'])
actions = []

actions.append(SimpleAction('readme', show_readme, 'C-h r',
                            MenuAddress(['Help', 'Readme'], 'r')))
actions.append(SimpleAction('features', show_features, 'C-h f',
                            MenuAddress(['Help', 'Features'], 'f')))
actions.append(SimpleAction('overview', show_overview, 'C-h o',
                            MenuAddress(['Help', 'Overview'], 'o')))
actions.append(SimpleAction('tutorial', show_tutorial, 'C-h t',
                            MenuAddress(['Help', 'Tutorial'], 't')))

actions.append(SimpleAction('contributing', show_contributing, 'C-h c',
                            MenuAddress(['Help', 'Contributing'], 'n', 1)))
actions.append(SimpleAction('library', show_library, 'C-h l',
                            MenuAddress(['Help', 'Using Rope As A Library'],
                                        'l', 1)))

actions.append(SimpleAction('about', show_about_dialog, 'C-h a',
                            MenuAddress(['Help', 'About Rope'], 'a', 2)))

for action in actions:
    core.register_action(action)
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.