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