| 1 |
# FunctionSelector v0.04 script for glimmer |
| 2 |
# last edit by Andreas Motl<andreas.motl@ilo.de> |
| 3 |
# and Sebastian Utz<su@tunemedia.de> 2002-11-01 |
| 4 |
# |
| 5 |
#ToDo: |
| 6 |
# - Bug: FunctionList doesn't refresh on new opened files by its own |
| 7 |
# - tune regex for more languages |
| 8 |
# |
| 9 |
|
| 10 |
import glimmer |
| 11 |
import string |
| 12 |
import re |
| 13 |
import sys |
| 14 |
import os |
| 15 |
sys.argv=[] |
| 16 |
sys.argv.append("null") |
| 17 |
from gtk import * |
| 18 |
import _gtk |
| 19 |
import _gnome |
| 20 |
import _gnomeui |
| 21 |
from gnome.ui import * |
| 22 |
import gnome.config |
| 23 |
|
| 24 |
global row_number |
| 25 |
|
| 26 |
row_number = [] |
| 27 |
|
| 28 |
# --------------------------------------------------------- |
| 29 |
# some regular expressions to scan for |
| 30 |
# class/function/sub/packages signatures |
| 31 |
# in source code |
| 32 |
prefix_pattern = '^[|\s]*' |
| 33 |
sigpart = '\s+([\w|:]+?)\s*' |
| 34 |
regex_universal=re.compile(prefix_pattern + '(?:\w+?)\*??' + sigpart + '\(.*?\)[\s|:|{]*$') |
| 35 |
regex_perl=re.compile(prefix_pattern + '(?:package|sub)' + sigpart + '[;|{]$') |
| 36 |
|
| 37 |
def get_functionNameFromLine(str): |
| 38 |
for regex in (regex_universal, regex_perl): |
| 39 |
match=regex.search(str) |
| 40 |
if match: |
| 41 |
str = match.group(1) |
| 42 |
return str |
| 43 |
|
| 44 |
def get_allFunctionNames(content): |
| 45 |
names=[] |
| 46 |
lines=string.split(content, "\n") |
| 47 |
count=1 |
| 48 |
for line in lines: |
| 49 |
funcname=get_functionNameFromLine(line) |
| 50 |
if funcname: |
| 51 |
names.append((funcname, count)) |
| 52 |
count=count+1 |
| 53 |
return names |
| 54 |
|
| 55 |
# --------------------------------------------------------- |
| 56 |
|
| 57 |
def get_current_text(): |
| 58 |
start = 0 |
| 59 |
end = glimmer.buffer_size() |
| 60 |
str = glimmer.get_text(start, end) |
| 61 |
return str |
| 62 |
|
| 63 |
def functionlist_init (): |
| 64 |
title = "Functions:" |
| 65 |
functionlist.set_column_title(0, title) |
| 66 |
functionlist.clear() |
| 67 |
|
| 68 |
def functionlist_append(label): |
| 69 |
listentry=[] |
| 70 |
listentry.append(label) |
| 71 |
listentry.append("") |
| 72 |
functionlist.append(listentry) |
| 73 |
|
| 74 |
def our_main(): |
| 75 |
global row_number |
| 76 |
gettext = get_current_text() |
| 77 |
if gettext: |
| 78 |
entries=get_allFunctionNames(gettext) |
| 79 |
functionlist_init() |
| 80 |
row_number=[] |
| 81 |
for entry in entries: |
| 82 |
label=entry[0] |
| 83 |
rownum=entry[1] |
| 84 |
functionlist_append(label) |
| 85 |
row_number.append(rownum) |
| 86 |
|
| 87 |
def select_row_callback(clist, row, col, event, data): |
| 88 |
import glimmer |
| 89 |
import string |
| 90 |
global row_number |
| 91 |
num = row_number[row] |
| 92 |
glimmer.move_to_line(num) |
| 93 |
glimmer.move_to(glimmer.line_start()) |
| 94 |
del glimmer |
| 95 |
del string |
| 96 |
|
| 97 |
|
| 98 |
def close_function_selector(button, citem, fbox): |
| 99 |
citem.destroy() |
| 100 |
glimmer.remove_paned_object("FunctionSelector") |
| 101 |
|
| 102 |
|
| 103 |
def refresh_function_selector(refresh): |
| 104 |
our_main() |
| 105 |
|
| 106 |
def callback_change(): |
| 107 |
our_main() |
| 108 |
|
| 109 |
functionbox = GtkVBox(FALSE, 0) |
| 110 |
functionbox.show() |
| 111 |
titleframe = GtkFrame() |
| 112 |
functionbox.pack_start(titleframe, FALSE, FALSE, 2) |
| 113 |
titleframe.show() |
| 114 |
buttonbox = GtkHBox(FALSE, 0) |
| 115 |
titleframe.add(buttonbox) |
| 116 |
buttonbox.show() |
| 117 |
optionsbutton = GtkButton() |
| 118 |
optionsbutton.set_relief(RELIEF_NONE) |
| 119 |
buttonbox.pack_start(optionsbutton, FALSE, FALSE, 2) |
| 120 |
optionsbutton.show() |
| 121 |
optionsbuttonbox = GtkHBox(FALSE, 0) |
| 122 |
optionsbutton.add(optionsbuttonbox) |
| 123 |
optionsbuttonbox.pack_start(GtkLabel("Refresh List"), FALSE, FALSE, 0) |
| 124 |
optionsbuttonbox.show_all() |
| 125 |
|
| 126 |
_gtk.gtk_signal_connect(optionsbutton._o, "clicked", refresh_function_selector) |
| 127 |
closebutton = GtkButton() |
| 128 |
closebutton.set_relief(RELIEF_NONE) |
| 129 |
closebutton.add(GnomeStock("Close")) |
| 130 |
closebutton.set_usize(22, 22) |
| 131 |
buttonbox.pack_end(closebutton, FALSE, FALSE, 2) |
| 132 |
closebutton.show_all() |
| 133 |
functionwindow = GtkScrolledWindow() |
| 134 |
functionbox.pack_start(functionwindow, TRUE, TRUE, 2) |
| 135 |
functionwindow.set_usize(130, 500) |
| 136 |
functionwindow.show() |
| 137 |
functionlist = GtkCList(1) |
| 138 |
functionwindow.add(functionlist) |
| 139 |
functionlist.show() |
| 140 |
#functionlist.column_titles_show(1) |
| 141 |
#functionlist.set_column_title(0, "Functions:") |
| 142 |
glimmer.add_paned_object(functionbox._o, "FunctionSelector", 0) |
| 143 |
our_main() |
| 144 |
checkitem = GtkCheckMenuItem("Function Selector") |
| 145 |
checkitem.set_active(TRUE) |
| 146 |
checkitem.show() |
| 147 |
glimmer.add_widget_to_menu("_View/Status Bar", checkitem._o) |
| 148 |
|
| 149 |
glimmer.register_signal_hook("open-file", callback_change) |
| 150 |
|
| 151 |
glimmer.register_signal_hook("change-file", callback_change) |
| 152 |
|
| 153 |
args = (checkitem, functionbox, ) |
| 154 |
_gtk.gtk_signal_connect(closebutton._o, "clicked", close_function_selector, args) |
| 155 |
args = (None, ) |
| 156 |
_gtk.gtk_signal_connect(functionlist._o, "select_row", select_row_callback, args) |